unique ptrs in Mesh

This commit is contained in:
Joachim Schöberl 2019-08-09 09:02:50 +02:00
parent b03705c37d
commit c900e0380b
7 changed files with 95 additions and 90 deletions

View File

@ -433,9 +433,9 @@ void WriteSTLExtFormat (const Mesh & mesh,
for (int i = 0; i < faceSei.Size(); i++) for (int i = 0; i < faceSei.Size(); i++)
{ {
*outfile << "facet normal "; *outfile << "facet normal ";
const Point3d& p1 = mesh.Point(mesh.SurfaceElement(faceSei[i]).PNum(1)); const Point3d& p1 = mesh.Point(mesh[faceSei[i]].PNum(1));
const Point3d& p2 = mesh.Point(mesh.SurfaceElement(faceSei[i]).PNum(2)); const Point3d& p2 = mesh.Point(mesh[faceSei[i]].PNum(2));
const Point3d& p3 = mesh.Point(mesh.SurfaceElement(faceSei[i]).PNum(3)); const Point3d& p3 = mesh.Point(mesh[faceSei[i]].PNum(3));
Vec3d normal = Cross(p2-p1,p3-p1); Vec3d normal = Cross(p2-p1,p3-p1);
if (normal.Length() != 0) if (normal.Length() != 0)

View File

@ -1308,7 +1308,7 @@ namespace netgen
// NgLock mem_lock (mem_mutex,1); // NgLock mem_lock (mem_mutex,1);
mesh.coarsemesh = new Mesh; mesh.coarsemesh = make_unique<Mesh>();
*mesh.coarsemesh = mesh; *mesh.coarsemesh = mesh;
// #ifdef CURVEDELEMS_NEW // #ifdef CURVEDELEMS_NEW
@ -1317,8 +1317,8 @@ namespace netgen
// #endif // #endif
delete mesh.hpelements; // delete mesh.hpelements;
mesh.hpelements = new NgArray<HPRefElement>; mesh.hpelements = make_unique<NgArray<HPRefElement>>();
NgArray<HPRefElement> & hpelements = *mesh.hpelements; NgArray<HPRefElement> & hpelements = *mesh.hpelements;

View File

@ -11,13 +11,13 @@ namespace netgen
Mesh :: Mesh () Mesh :: Mesh ()
: topology(*this), surfarea(*this) : topology(*this), surfarea(*this)
{ {
boundaryedges = NULL; boundaryedges = nullptr;
surfelementht = NULL; surfelementht = nullptr;
segmentht = NULL; segmentht = nullptr;
lochfunc = NULL; lochfunc = nullptr;
// mglevels = 1; // mglevels = 1;
elementsearchtree = NULL; elementsearchtree = nullptr;
elementsearchtreets = NextTimeStamp(); elementsearchtreets = NextTimeStamp();
majortimestamp = timestamp = NextTimeStamp(); majortimestamp = timestamp = NextTimeStamp();
hglob = 1e10; hglob = 1e10;
@ -25,9 +25,9 @@ namespace netgen
numvertices = -1; numvertices = -1;
dimension = 3; dimension = 3;
curvedelems = new CurvedElements (*this); curvedelems = make_unique<CurvedElements> (*this);
clusters = new AnisotropicClusters (*this); clusters = make_unique<AnisotropicClusters> (*this);
ident = new Identifications (*this); ident = make_unique<Identifications> (*this);
hpelements = NULL; hpelements = NULL;
coarsemesh = NULL; coarsemesh = NULL;
@ -41,23 +41,23 @@ namespace netgen
// this->comm = netgen :: ng_comm; // this->comm = netgen :: ng_comm;
#ifdef PARALLEL #ifdef PARALLEL
paralleltop = new ParallelMeshTopology (*this); paralleltop = make_unique<ParallelMeshTopology> (*this);
#endif #endif
} }
Mesh :: ~Mesh() Mesh :: ~Mesh()
{ {
delete lochfunc; // delete lochfunc;
delete boundaryedges; // delete boundaryedges;
delete surfelementht; // delete surfelementht;
delete segmentht; // delete segmentht;
delete curvedelems; // delete curvedelems;
delete clusters; // delete clusters;
delete ident; // delete ident;
delete elementsearchtree; // delete elementsearchtree;
delete coarsemesh; // delete coarsemesh;
delete hpelements; // delete hpelements;
for (int i = 0; i < materials.Size(); i++) for (int i = 0; i < materials.Size(); i++)
delete materials[i]; delete materials[i];
@ -72,9 +72,9 @@ namespace netgen
for (int i = 0; i < cd2names.Size(); i++) for (int i = 0; i < cd2names.Size(); i++)
delete cd2names[i]; delete cd2names[i];
#ifdef PARALLEL // #ifdef PARALLEL
delete paralleltop; // delete paralleltop;
#endif // #endif
} }
void Mesh :: SetCommunicator(NgMPI_Comm acomm) void Mesh :: SetCommunicator(NgMPI_Comm acomm)
@ -133,19 +133,18 @@ namespace netgen
lockedpoints.SetSize(0); lockedpoints.SetSize(0);
// surfacesonnode.SetSize(0); // surfacesonnode.SetSize(0);
delete boundaryedges; // delete boundaryedges;
boundaryedges = NULL; boundaryedges = nullptr;
segmentht = nullptr;
surfelementht = nullptr;
openelements.SetSize(0); openelements.SetSize(0);
facedecoding.SetSize(0); facedecoding.SetSize(0);
delete ident; ident = make_unique<Identifications> (*this);
ident = new Identifications (*this);
topology = MeshTopology (*this); topology = MeshTopology (*this);
delete curvedelems; curvedelems = make_unique<CurvedElements> (*this);
curvedelems = new CurvedElements (*this); clusters = make_unique<AnisotropicClusters> (*this);
delete clusters;
clusters = new AnisotropicClusters (*this);
for ( int i = 0; i < bcnames.Size(); i++ ) for ( int i = 0; i < bcnames.Size(); i++ )
if ( bcnames[i] ) delete bcnames[i]; if ( bcnames[i] ) delete bcnames[i];
@ -153,8 +152,7 @@ namespace netgen
if (cd2names[i]) delete cd2names[i]; if (cd2names[i]) delete cd2names[i];
#ifdef PARALLEL #ifdef PARALLEL
delete paralleltop; paralleltop = make_unique<ParallelMeshTopology> (*this);
paralleltop = new ParallelMeshTopology (*this);
#endif #endif
lock.UnLock(); lock.UnLock();
@ -1571,9 +1569,9 @@ namespace netgen
void Mesh :: BuildBoundaryEdges(void) void Mesh :: BuildBoundaryEdges(void)
{ {
delete boundaryedges; // delete boundaryedges;
boundaryedges = new INDEX_2_CLOSED_HASHTABLE<int> boundaryedges = make_unique<INDEX_2_CLOSED_HASHTABLE<int>>
(3 * (GetNSE() + GetNOpenElements()) + GetNSeg() + 1); (3 * (GetNSE() + GetNOpenElements()) + GetNSeg() + 1);
@ -1643,12 +1641,14 @@ namespace netgen
// surfacesonnode.SetSize (GetNP()); // surfacesonnode.SetSize (GetNP());
TABLE<int,PointIndex::BASE> surfacesonnode(GetNP()); TABLE<int,PointIndex::BASE> surfacesonnode(GetNP());
delete boundaryedges; // delete boundaryedges;
boundaryedges = NULL; // boundaryedges = NULL;
boundaryedges = nullptr;
delete surfelementht; // delete surfelementht;
// surfelementht = nullptr;
surfelementht = nullptr; surfelementht = nullptr;
delete segmentht; // delete segmentht;
/* /*
surfelementht = new INDEX_3_HASHTABLE<int> (GetNSE()/4 + 1); surfelementht = new INDEX_3_HASHTABLE<int> (GetNSE()/4 + 1);
@ -1656,8 +1656,8 @@ namespace netgen
*/ */
if (dimension == 3) if (dimension == 3)
surfelementht = new INDEX_3_CLOSED_HASHTABLE<int> (3*GetNSE() + 1); surfelementht = make_unique<INDEX_3_CLOSED_HASHTABLE<int>> (3*GetNSE() + 1);
segmentht = new INDEX_2_CLOSED_HASHTABLE<int> (3*GetNSeg() + 1); segmentht = make_unique<INDEX_2_CLOSED_HASHTABLE<int>> (3*GetNSeg() + 1);
if (dimension == 3) if (dimension == 3)
/* /*
@ -2582,8 +2582,7 @@ namespace netgen
Point<3> pmin2 = c - Vec<3> (d, d, d); Point<3> pmin2 = c - Vec<3> (d, d, d);
Point<3> pmax2 = c + Vec<3> (d, d, d); Point<3> pmax2 = c + Vec<3> (d, d, d);
delete lochfunc; lochfunc = make_unique<LocalH> (pmin2, pmax2, grading, dimension);
lochfunc = new LocalH (pmin2, pmax2, grading, dimension);
} }
void Mesh :: RestrictLocalH (const Point3d & p, double hloc) void Mesh :: RestrictLocalH (const Point3d & p, double hloc)
@ -3522,11 +3521,12 @@ namespace netgen
bool overlap = 0; bool overlap = 0;
bool incons_layers = 0; bool incons_layers = 0;
/*
for (i = 1; i <= GetNSE(); i++) for (i = 1; i <= GetNSE(); i++)
SurfaceElement(i).badel = 0; SurfaceElement(i).badel = 0;
*/
for (Element2d & el : SurfaceElements())
el.badel = false;
for (i = 1; i <= GetNSE(); i++) for (i = 1; i <= GetNSE(); i++)
{ {
@ -4321,8 +4321,7 @@ namespace netgen
PrintMessage (4, "Rebuild element searchtree"); PrintMessage (4, "Rebuild element searchtree");
delete elementsearchtree; elementsearchtree = nullptr;
elementsearchtree = NULL;
int ne = (dimension == 2) ? GetNSE() : GetNE(); int ne = (dimension == 2) ? GetNSE() : GetNE();
if (dimension == 3 && !GetNE() && GetNSE()) if (dimension == 3 && !GetNE() && GetNSE())
@ -4337,7 +4336,7 @@ namespace netgen
box.Add (points[surfelements[sei].PNums()]); box.Add (points[surfelements[sei].PNums()]);
box.Increase (1.01 * box.Diam()); box.Increase (1.01 * box.Diam());
elementsearchtree = new BoxTree<3> (box); elementsearchtree = make_unique<BoxTree<3>> (box);
for (SurfaceElementIndex sei = 0; sei < ne; sei++) for (SurfaceElementIndex sei = 0; sei < ne; sei++)
{ {
@ -4352,7 +4351,7 @@ namespace netgen
box.Add (points[volelements[ei].PNums()]); box.Add (points[volelements[ei].PNums()]);
box.Increase (1.01 * box.Diam()); box.Increase (1.01 * box.Diam());
elementsearchtree = new BoxTree<3> (box); elementsearchtree = make_unique<BoxTree<3>> (box);
for (ElementIndex ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
{ {

View File

@ -17,7 +17,9 @@ namespace netgen
RESTRICTH_SURFACEELEMENT, RESTRICTH_POINT, RESTRICTH_SEGMENT }; RESTRICTH_SURFACEELEMENT, RESTRICTH_POINT, RESTRICTH_SEGMENT };
class HPRefElement; class HPRefElement;
class CurvedElements;
class AnisotropicClusters;
class ParallelMeshTopology;
/// 2d/3d mesh /// 2d/3d mesh
class Mesh class Mesh
@ -48,11 +50,11 @@ namespace netgen
/// surface indices at boundary nodes /// surface indices at boundary nodes
// TABLE<int,PointIndex::BASE> surfacesonnode; // TABLE<int,PointIndex::BASE> surfacesonnode;
/// boundary edges (1..normal bedge, 2..segment) /// boundary edges (1..normal bedge, 2..segment)
INDEX_2_CLOSED_HASHTABLE<int> * boundaryedges; unique_ptr<INDEX_2_CLOSED_HASHTABLE<int>> boundaryedges;
/// ///
INDEX_2_CLOSED_HASHTABLE<int> * segmentht; unique_ptr<INDEX_2_CLOSED_HASHTABLE<int>> segmentht;
/// ///
INDEX_3_CLOSED_HASHTABLE<int> * surfelementht; unique_ptr<INDEX_3_CLOSED_HASHTABLE<int>> surfelementht;
/// faces of rest-solid /// faces of rest-solid
NgArray<Element2d> openelements; NgArray<Element2d> openelements;
@ -64,7 +66,7 @@ namespace netgen
/** /**
Representation of local mesh-size h Representation of local mesh-size h
*/ */
LocalH * lochfunc; unique_ptr<LocalH> lochfunc;
/// ///
double hglob; double hglob;
/// ///
@ -98,24 +100,24 @@ namespace netgen
NgArray<string*> cd3names; NgArray<string*> cd3names;
/// Periodic surface, close surface, etc. identifications /// Periodic surface, close surface, etc. identifications
Identifications * ident; unique_ptr<Identifications> ident;
/// number of vertices (if < 0, use np) /// number of vertices (if < 0, use np)
int numvertices; int numvertices;
/// geometric search tree for interval intersection search /// geometric search tree for interval intersection search
BoxTree<3> * elementsearchtree; unique_ptr<BoxTree<3>> elementsearchtree;
/// time stamp for tree /// time stamp for tree
mutable int elementsearchtreets; mutable int elementsearchtreets;
/// element -> face, element -> edge etc ... /// element -> face, element -> edge etc ...
MeshTopology topology; MeshTopology topology;
/// methods for high order elements /// methods for high order elements
class CurvedElements * curvedelems; unique_ptr<CurvedElements> curvedelems;
/// nodes identified by close points /// nodes identified by close points
class AnisotropicClusters * clusters; unique_ptr<AnisotropicClusters> clusters;
/// space dimension (2 or 3) /// space dimension (2 or 3)
int dimension; int dimension;
@ -145,8 +147,7 @@ namespace netgen
#ifdef PARALLEL #ifdef PARALLEL
/// connection to parallel meshes /// connection to parallel meshes
class ParallelMeshTopology * paralleltop; unique_ptr<ParallelMeshTopology> paralleltop;
#endif #endif
@ -170,8 +171,8 @@ namespace netgen
public: public:
// store coarse mesh before hp-refinement // store coarse mesh before hp-refinement
NgArray<HPRefElement> * hpelements; unique_ptr<NgArray<HPRefElement>> hpelements;
Mesh * coarsemesh; unique_ptr<Mesh> coarsemesh;
/// number of refinement levels /// number of refinement levels
@ -307,13 +308,13 @@ namespace netgen
auto GetNSE () const { return surfelements.Size(); } auto GetNSE () const { return surfelements.Size(); }
[[deprecated("Use SurfaceElement(SurfaceElementIndex) instead of int !")]] // [[deprecated("Use SurfaceElement(SurfaceElementIndex) instead of int !")]]
Element2d & SurfaceElement(int i) { return surfelements[i-1]; } Element2d & SurfaceElement(int i) { return surfelements[i-1]; }
[[deprecated("Use SurfaceElement(SurfaceElementIndex) instead of int !")]] // [[deprecated("Use SurfaceElement(SurfaceElementIndex) instead of int !")]]
const Element2d & SurfaceElement(int i) const { return surfelements[i-1]; } const Element2d & SurfaceElement(int i) const { return surfelements[i-1]; }
[[deprecated("Use mesh[](SurfaceElementIndex) instead !")]] // [[deprecated("Use mesh[](SurfaceElementIndex) instead !")]]
Element2d & SurfaceElement(SurfaceElementIndex i) { return surfelements[i]; } Element2d & SurfaceElement(SurfaceElementIndex i) { return surfelements[i]; }
[[deprecated("Use mesh[](SurfaceElementIndex) instead !")]] // [[deprecated("Use mesh[](SurfaceElementIndex) instead !")]]
const Element2d & SurfaceElement(SurfaceElementIndex i) const { return surfelements[i]; } const Element2d & SurfaceElement(SurfaceElementIndex i) const { return surfelements[i]; }
const Element2d & operator[] (SurfaceElementIndex ei) const const Element2d & operator[] (SurfaceElementIndex ei) const
@ -338,9 +339,9 @@ namespace netgen
Element & VolumeElement(int i) { return volelements[i-1]; } Element & VolumeElement(int i) { return volelements[i-1]; }
// [[deprecated("Use VolumeElement(ElementIndex) instead of int !")]] // [[deprecated("Use VolumeElement(ElementIndex) instead of int !")]]
const Element & VolumeElement(int i) const { return volelements[i-1]; } const Element & VolumeElement(int i) const { return volelements[i-1]; }
[[deprecated("Use mesh[](VolumeElementIndex) instead !")]] // [[deprecated("Use mesh[](VolumeElementIndex) instead !")]]
Element & VolumeElement(ElementIndex i) { return volelements[i]; } Element & VolumeElement(ElementIndex i) { return volelements[i]; }
[[deprecated("Use mesh[](VolumeElementIndex) instead !")]] // [[deprecated("Use mesh[](VolumeElementIndex) instead !")]]
const Element & VolumeElement(ElementIndex i) const { return volelements[i]; } const Element & VolumeElement(ElementIndex i) const { return volelements[i]; }
const Element & operator[] (ElementIndex ei) const { return volelements[ei]; } const Element & operator[] (ElementIndex ei) const { return volelements[ei]; }

View File

@ -759,19 +759,24 @@ namespace netgen
ptr = nullptr; ptr = nullptr;
} }
}; };
cleanup_ptr(self.boundaryedges); /*
cleanup_ptr(self.boundaryedges); cleanup_ptr(self.boundaryedges);
cleanup_ptr(self.segmentht); cleanup_ptr(self.segmentht);
cleanup_ptr(self.surfelementht); cleanup_ptr(self.surfelementht);
*/
self.boundaryedges = nullptr;
self.segmentht = nullptr;
self.surfelementht = nullptr;
self.openelements = NgArray<Element2d>(0); self.openelements = NgArray<Element2d>(0);
self.opensegments = NgArray<Segment>(0); self.opensegments = NgArray<Segment>(0);
self.numvertices = 0; self.numvertices = 0;
self.mlbetweennodes = NgArray<PointIndices<2>,PointIndex::BASE> (0); self.mlbetweennodes = NgArray<PointIndices<2>,PointIndex::BASE> (0);
self.mlparentelement = NgArray<int>(0); self.mlparentelement = NgArray<int>(0);
self.mlparentsurfaceelement = NgArray<int>(0); self.mlparentsurfaceelement = NgArray<int>(0);
self.curvedelems = new CurvedElements (self); self.curvedelems = make_unique<CurvedElements> (self);
self.clusters = new AnisotropicClusters (self); self.clusters = make_unique<AnisotropicClusters> (self);
self.ident = new Identifications (self); self.ident = make_unique<Identifications> (self);
self.topology = MeshTopology(*this); self.topology = MeshTopology(*this);
self.topology.Update(); self.topology.Update();
self.BuildElementSearchTree(); self.BuildElementSearchTree();

View File

@ -361,7 +361,7 @@ namespace netgen
mesh.VolumeElements().SetAllocSize(8*oldne); mesh.VolumeElements().SetAllocSize(8*oldne);
for (ElementIndex ei = 0; ei < oldne; ei++) for (ElementIndex ei = 0; ei < oldne; ei++)
{ {
const Element & el = mesh.VolumeElement(ei); const Element & el = mesh[ei];
switch (el.GetType()) switch (el.GetType())
{ {
case TET: case TET:

View File

@ -458,23 +458,23 @@ int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, const MeshingParam
// was commented: // was commented:
for (int i = 1; i <= mesh.GetNSE(); i++) for (SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++)
if (mesh.SurfaceElement(i).BadElement()) if (mesh[sei].BadElement())
{ {
for (int j = 1; j <= 3; j++) for (int j = 1; j <= 3; j++)
{ {
refpts.Append (mesh.Point (mesh.SurfaceElement(i).PNum(j))); refpts.Append (mesh.Point (mesh[sei].PNum(j)));
refh.Append (mesh.GetH (refpts.Last()) / 2); refh.Append (mesh.GetH (refpts.Last()) / 2);
} }
mesh.DeleteSurfaceElement(i); mesh.Delete(sei);
} }
// delete wrong oriented element // delete wrong oriented element
for (int i = 1; i <= mesh.GetNSE(); i++) for (SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++)
{ {
const Element2d & el = mesh.SurfaceElement(i); const Element2d & el = mesh[sei];
if (!el.PNum(1)) if (el.IsDeleted()) continue;
continue; if (!el.PNum(1).IsValid()) continue;
Vec3d n = Cross (Vec3d (mesh.Point(el.PNum(1)), Vec3d n = Cross (Vec3d (mesh.Point(el.PNum(1)),
mesh.Point(el.PNum(2))), mesh.Point(el.PNum(2))),
@ -483,9 +483,9 @@ int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, const MeshingParam
Vec3d ng = geom.GetTriangle(el.GeomInfoPi(1).trignum).Normal(); Vec3d ng = geom.GetTriangle(el.GeomInfoPi(1).trignum).Normal();
if (n * ng < 0) if (n * ng < 0)
{ {
refpts.Append (mesh.Point (mesh.SurfaceElement(i).PNum(1))); refpts.Append (mesh.Point (mesh[sei].PNum(1)));
refh.Append (mesh.GetH (refpts.Last()) / 2); refh.Append (mesh.GetH (refpts.Last()) / 2);
mesh.DeleteSurfaceElement(i); mesh.Delete(sei);
} }
} }
// end comments // end comments