changed: use shared pointers in 3D LR ASM

- same as in 2D
- difficult to keep track of which pointers to delete or not.
  now it's simple: you never delete a bare pointer.
This commit is contained in:
Arne Morten Kvarving 2016-08-19 11:30:05 +02:00 committed by Knut Morten Okstad
parent fd3b040348
commit 2562a61d4c
3 changed files with 18 additions and 19 deletions

View File

@ -83,7 +83,6 @@ void LR::getGaussPointParameters (const LR::LRSpline* lrspline, RealArray& uGP,
ASMunstruct::~ASMunstruct () ASMunstruct::~ASMunstruct ()
{ {
if (geo) delete geo;
} }

View File

@ -56,18 +56,18 @@ ASMu3D::ASMu3D (const ASMu3D& patch, unsigned char n_f)
bool ASMu3D::read (std::istream& is) bool ASMu3D::read (std::istream& is)
{ {
if (shareFE) return true; if (shareFE) return true;
if (lrspline) delete lrspline; lrspline.reset();
// read inputfile as either an LRSpline file directly or a tensor product B-spline and convert // read inputfile as either an LRSpline file directly or a tensor product B-spline and convert
char firstline[256]; char firstline[256];
is.getline(firstline, 256); is.getline(firstline, 256);
if(strncmp(firstline, "# LRSPLINE", 10) == 0) { if(strncmp(firstline, "# LRSPLINE", 10) == 0) {
lrspline = new LR::LRSplineVolume(); lrspline.reset(new LR::LRSplineVolume());
is >> *lrspline; is >> *lrspline;
} else { // probably a SplineVolume, so we'll read that and convert } else { // probably a SplineVolume, so we'll read that and convert
tensorspline = new Go::SplineVolume(); tensorspline = new Go::SplineVolume();
is >> *tensorspline; is >> *tensorspline;
lrspline = new LR::LRSplineVolume(tensorspline); lrspline.reset(new LR::LRSplineVolume(tensorspline));
} }
// Eat white-space characters to see if there is more data to read // Eat white-space characters to see if there is more data to read
@ -81,20 +81,18 @@ bool ASMu3D::read (std::istream& is)
if (!is.good() && !is.eof()) if (!is.good() && !is.eof())
{ {
std::cerr <<" *** ASMu3D::read: Failure reading spline data"<< std::endl; std::cerr <<" *** ASMu3D::read: Failure reading spline data"<< std::endl;
delete lrspline; lrspline.reset();
lrspline = 0;
return false; return false;
} }
else if (lrspline->dimension() < 3) else if (lrspline->dimension() < 3)
{ {
std::cerr <<" *** ASMu3D::read: Invalid spline volume patch, dim=" std::cerr <<" *** ASMu3D::read: Invalid spline volume patch, dim="
<< lrspline->dimension() << std::endl; << lrspline->dimension() << std::endl;
delete lrspline; lrspline.reset();
lrspline = 0;
return false; return false;
} }
geo = lrspline; geo = lrspline.get();
return true; return true;
} }
@ -114,9 +112,8 @@ void ASMu3D::clear (bool retainGeometry)
if (!retainGeometry) { if (!retainGeometry) {
// Erase spline data // Erase spline data
if (!shareFE) { if (!shareFE) {
delete lrspline; lrspline.reset();
delete tensorspline; delete tensorspline;
lrspline = nullptr;
} }
geo = nullptr; geo = nullptr;
tensorspline = nullptr; tensorspline = nullptr;
@ -157,8 +154,8 @@ bool ASMu3D::refine (int dir, const RealArray& xi)
} }
tensorspline->insertKnot(dir,extraKnots); tensorspline->insertKnot(dir,extraKnots);
if(lrspline) delete lrspline; lrspline.reset(new LR::LRSplineVolume(tensorspline));
geo = lrspline = new LR::LRSplineVolume(tensorspline); geo = lrspline.get();
return true; return true;
} }
@ -183,8 +180,8 @@ bool ASMu3D::uniformRefine (int dir, int nInsert)
} }
tensorspline->insertKnot(dir,extraKnots); tensorspline->insertKnot(dir,extraKnots);
if(lrspline) delete lrspline; lrspline.reset(new LR::LRSplineVolume(tensorspline));
geo = lrspline = new LR::LRSplineVolume(tensorspline); geo = lrspline.get();
return true; return true;
} }
@ -194,8 +191,8 @@ bool ASMu3D::raiseOrder (int ru, int rv, int rw)
if (shareFE) return true; if (shareFE) return true;
tensorspline->raiseOrder(ru,rv,rw); tensorspline->raiseOrder(ru,rv,rw);
delete lrspline; lrspline.reset(new LR::LRSplineVolume(tensorspline));
geo = lrspline = new LR::LRSplineVolume(tensorspline); geo = lrspline.get();
return true; return true;
} }

View File

@ -44,7 +44,7 @@ public:
virtual ~ASMu3D() {} virtual ~ASMu3D() {}
//! \brief Returns the spline volume representing the geometry of this patch. //! \brief Returns the spline volume representing the geometry of this patch.
LR::LRSplineVolume* getVolume() const { return lrspline; } LR::LRSplineVolume* getVolume() const { return lrspline.get(); }
// Methods for model generation and refinement // Methods for model generation and refinement
@ -299,6 +299,9 @@ public:
virtual bool evalSolution(Matrix& sField, const IntegrandBase& integrand, virtual bool evalSolution(Matrix& sField, const IntegrandBase& integrand,
const int* npe = 0, char project = '\0') const; const int* npe = 0, char project = '\0') const;
//! \brief Returns the spline volume representing the basis of this patch.
virtual const LR::LRSplineVolume* getBasis(int = 1) const { return lrspline.get(); }
public: public:
//! \brief Projects the secondary solution field onto the primary basis. //! \brief Projects the secondary solution field onto the primary basis.
//! \param[in] integrand Object with problem-specific data and methods //! \param[in] integrand Object with problem-specific data and methods
@ -395,7 +398,7 @@ public:
virtual size_t getNoBoundaryElms(char lIndex, char ldim) const; virtual size_t getNoBoundaryElms(char lIndex, char ldim) const;
protected: protected:
LR::LRSplineVolume* lrspline; //!< Pointer to the LR-spline volume object std::shared_ptr<LR::LRSplineVolume> lrspline; //!< Pointer to the LR-spline volume object
Go::SplineVolume* tensorspline; //!< Pointer to original tensor spline object Go::SplineVolume* tensorspline; //!< Pointer to original tensor spline object
// The tensor spline object is kept for backward compatability with the REFINE // The tensor spline object is kept for backward compatability with the REFINE