diff --git a/libsrc/interface/writeuser.cpp b/libsrc/interface/writeuser.cpp index 522aebe7..204c4262 100644 --- a/libsrc/interface/writeuser.cpp +++ b/libsrc/interface/writeuser.cpp @@ -433,9 +433,9 @@ void WriteSTLExtFormat (const Mesh & mesh, for (int i = 0; i < faceSei.Size(); i++) { *outfile << "facet normal "; - const Point3d& p1 = mesh.Point(mesh.SurfaceElement(faceSei[i]).PNum(1)); - const Point3d& p2 = mesh.Point(mesh.SurfaceElement(faceSei[i]).PNum(2)); - const Point3d& p3 = mesh.Point(mesh.SurfaceElement(faceSei[i]).PNum(3)); + const Point3d& p1 = mesh.Point(mesh[faceSei[i]].PNum(1)); + const Point3d& p2 = mesh.Point(mesh[faceSei[i]].PNum(2)); + const Point3d& p3 = mesh.Point(mesh[faceSei[i]].PNum(3)); Vec3d normal = Cross(p2-p1,p3-p1); if (normal.Length() != 0) diff --git a/libsrc/meshing/hprefinement.cpp b/libsrc/meshing/hprefinement.cpp index 765130db..8cbc2b1b 100644 --- a/libsrc/meshing/hprefinement.cpp +++ b/libsrc/meshing/hprefinement.cpp @@ -1308,7 +1308,7 @@ namespace netgen // NgLock mem_lock (mem_mutex,1); - mesh.coarsemesh = new Mesh; + mesh.coarsemesh = make_unique(); *mesh.coarsemesh = mesh; // #ifdef CURVEDELEMS_NEW @@ -1317,8 +1317,8 @@ namespace netgen // #endif - delete mesh.hpelements; - mesh.hpelements = new NgArray; + // delete mesh.hpelements; + mesh.hpelements = make_unique>(); NgArray & hpelements = *mesh.hpelements; diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 5f364cee..3fef3ee9 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -11,13 +11,13 @@ namespace netgen Mesh :: Mesh () : topology(*this), surfarea(*this) { - boundaryedges = NULL; - surfelementht = NULL; - segmentht = NULL; + boundaryedges = nullptr; + surfelementht = nullptr; + segmentht = nullptr; - lochfunc = NULL; + lochfunc = nullptr; // mglevels = 1; - elementsearchtree = NULL; + elementsearchtree = nullptr; elementsearchtreets = NextTimeStamp(); majortimestamp = timestamp = NextTimeStamp(); hglob = 1e10; @@ -25,9 +25,9 @@ namespace netgen numvertices = -1; dimension = 3; - curvedelems = new CurvedElements (*this); - clusters = new AnisotropicClusters (*this); - ident = new Identifications (*this); + curvedelems = make_unique (*this); + clusters = make_unique (*this); + ident = make_unique (*this); hpelements = NULL; coarsemesh = NULL; @@ -41,23 +41,23 @@ namespace netgen // this->comm = netgen :: ng_comm; #ifdef PARALLEL - paralleltop = new ParallelMeshTopology (*this); + paralleltop = make_unique (*this); #endif } Mesh :: ~Mesh() { - delete lochfunc; - delete boundaryedges; - delete surfelementht; - delete segmentht; - delete curvedelems; - delete clusters; - delete ident; - delete elementsearchtree; - delete coarsemesh; - delete hpelements; + // delete lochfunc; + // delete boundaryedges; + // delete surfelementht; + // delete segmentht; + // delete curvedelems; + // delete clusters; + // delete ident; + // delete elementsearchtree; + // delete coarsemesh; + // delete hpelements; for (int i = 0; i < materials.Size(); i++) delete materials[i]; @@ -72,9 +72,9 @@ namespace netgen for (int i = 0; i < cd2names.Size(); i++) delete cd2names[i]; -#ifdef PARALLEL - delete paralleltop; -#endif + // #ifdef PARALLEL + // delete paralleltop; + // #endif } void Mesh :: SetCommunicator(NgMPI_Comm acomm) @@ -133,19 +133,18 @@ namespace netgen lockedpoints.SetSize(0); // surfacesonnode.SetSize(0); - delete boundaryedges; - boundaryedges = NULL; + // delete boundaryedges; + boundaryedges = nullptr; + segmentht = nullptr; + surfelementht = nullptr; openelements.SetSize(0); facedecoding.SetSize(0); - delete ident; - ident = new Identifications (*this); + ident = make_unique (*this); topology = MeshTopology (*this); - delete curvedelems; - curvedelems = new CurvedElements (*this); - delete clusters; - clusters = new AnisotropicClusters (*this); + curvedelems = make_unique (*this); + clusters = make_unique (*this); for ( int i = 0; i < bcnames.Size(); i++ ) if ( bcnames[i] ) delete bcnames[i]; @@ -153,8 +152,7 @@ namespace netgen if (cd2names[i]) delete cd2names[i]; #ifdef PARALLEL - delete paralleltop; - paralleltop = new ParallelMeshTopology (*this); + paralleltop = make_unique (*this); #endif lock.UnLock(); @@ -1571,9 +1569,9 @@ namespace netgen void Mesh :: BuildBoundaryEdges(void) { - delete boundaryedges; + // delete boundaryedges; - boundaryedges = new INDEX_2_CLOSED_HASHTABLE + boundaryedges = make_unique> (3 * (GetNSE() + GetNOpenElements()) + GetNSeg() + 1); @@ -1643,12 +1641,14 @@ namespace netgen // surfacesonnode.SetSize (GetNP()); TABLE surfacesonnode(GetNP()); - delete boundaryedges; - boundaryedges = NULL; + // delete boundaryedges; + // boundaryedges = NULL; + boundaryedges = nullptr; - delete surfelementht; + // delete surfelementht; + // surfelementht = nullptr; surfelementht = nullptr; - delete segmentht; + // delete segmentht; /* surfelementht = new INDEX_3_HASHTABLE (GetNSE()/4 + 1); @@ -1656,8 +1656,8 @@ namespace netgen */ if (dimension == 3) - surfelementht = new INDEX_3_CLOSED_HASHTABLE (3*GetNSE() + 1); - segmentht = new INDEX_2_CLOSED_HASHTABLE (3*GetNSeg() + 1); + surfelementht = make_unique> (3*GetNSE() + 1); + segmentht = make_unique> (3*GetNSeg() + 1); if (dimension == 3) /* @@ -2582,8 +2582,7 @@ namespace netgen Point<3> pmin2 = c - Vec<3> (d, d, d); Point<3> pmax2 = c + Vec<3> (d, d, d); - delete lochfunc; - lochfunc = new LocalH (pmin2, pmax2, grading, dimension); + lochfunc = make_unique (pmin2, pmax2, grading, dimension); } void Mesh :: RestrictLocalH (const Point3d & p, double hloc) @@ -3522,11 +3521,12 @@ namespace netgen bool overlap = 0; bool incons_layers = 0; - - + /* for (i = 1; i <= GetNSE(); i++) SurfaceElement(i).badel = 0; - + */ + for (Element2d & el : SurfaceElements()) + el.badel = false; for (i = 1; i <= GetNSE(); i++) { @@ -4321,8 +4321,7 @@ namespace netgen PrintMessage (4, "Rebuild element searchtree"); - delete elementsearchtree; - elementsearchtree = NULL; + elementsearchtree = nullptr; int ne = (dimension == 2) ? GetNSE() : GetNE(); if (dimension == 3 && !GetNE() && GetNSE()) @@ -4337,7 +4336,7 @@ namespace netgen box.Add (points[surfelements[sei].PNums()]); box.Increase (1.01 * box.Diam()); - elementsearchtree = new BoxTree<3> (box); + elementsearchtree = make_unique> (box); for (SurfaceElementIndex sei = 0; sei < ne; sei++) { @@ -4352,7 +4351,7 @@ namespace netgen box.Add (points[volelements[ei].PNums()]); box.Increase (1.01 * box.Diam()); - elementsearchtree = new BoxTree<3> (box); + elementsearchtree = make_unique> (box); for (ElementIndex ei = 0; ei < ne; ei++) { diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 7eb4f849..665ed99c 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -17,8 +17,10 @@ namespace netgen RESTRICTH_SURFACEELEMENT, RESTRICTH_POINT, RESTRICTH_SEGMENT }; class HPRefElement; - - + class CurvedElements; + class AnisotropicClusters; + class ParallelMeshTopology; + /// 2d/3d mesh class Mesh { @@ -48,11 +50,11 @@ namespace netgen /// surface indices at boundary nodes // TABLE surfacesonnode; /// boundary edges (1..normal bedge, 2..segment) - INDEX_2_CLOSED_HASHTABLE * boundaryedges; + unique_ptr> boundaryedges; /// - INDEX_2_CLOSED_HASHTABLE * segmentht; + unique_ptr> segmentht; /// - INDEX_3_CLOSED_HASHTABLE * surfelementht; + unique_ptr> surfelementht; /// faces of rest-solid NgArray openelements; @@ -64,7 +66,7 @@ namespace netgen /** Representation of local mesh-size h */ - LocalH * lochfunc; + unique_ptr lochfunc; /// double hglob; /// @@ -98,24 +100,24 @@ namespace netgen NgArray cd3names; /// Periodic surface, close surface, etc. identifications - Identifications * ident; + unique_ptr ident; /// number of vertices (if < 0, use np) int numvertices; /// geometric search tree for interval intersection search - BoxTree<3> * elementsearchtree; + unique_ptr> elementsearchtree; /// time stamp for tree mutable int elementsearchtreets; /// element -> face, element -> edge etc ... MeshTopology topology; /// methods for high order elements - class CurvedElements * curvedelems; + unique_ptr curvedelems; /// nodes identified by close points - class AnisotropicClusters * clusters; + unique_ptr clusters; /// space dimension (2 or 3) int dimension; @@ -145,8 +147,7 @@ namespace netgen #ifdef PARALLEL /// connection to parallel meshes - class ParallelMeshTopology * paralleltop; - + unique_ptr paralleltop; #endif @@ -170,8 +171,8 @@ namespace netgen public: // store coarse mesh before hp-refinement - NgArray * hpelements; - Mesh * coarsemesh; + unique_ptr> hpelements; + unique_ptr coarsemesh; /// number of refinement levels @@ -307,13 +308,13 @@ namespace netgen 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]; } - [[deprecated("Use SurfaceElement(SurfaceElementIndex) instead of int !")]] + // [[deprecated("Use SurfaceElement(SurfaceElementIndex) instead of int !")]] 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]; } - [[deprecated("Use mesh[](SurfaceElementIndex) instead !")]] + // [[deprecated("Use mesh[](SurfaceElementIndex) instead !")]] const Element2d & SurfaceElement(SurfaceElementIndex i) const { return surfelements[i]; } const Element2d & operator[] (SurfaceElementIndex ei) const @@ -338,9 +339,9 @@ namespace netgen Element & VolumeElement(int i) { return volelements[i-1]; } // [[deprecated("Use VolumeElement(ElementIndex) instead of int !")]] 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]; } - [[deprecated("Use mesh[](VolumeElementIndex) instead !")]] + // [[deprecated("Use mesh[](VolumeElementIndex) instead !")]] const Element & VolumeElement(ElementIndex i) const { return volelements[i]; } const Element & operator[] (ElementIndex ei) const { return volelements[ei]; } diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index 85deabc0..8867dbc9 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -759,19 +759,24 @@ namespace netgen ptr = nullptr; } }; - cleanup_ptr(self.boundaryedges); + /* cleanup_ptr(self.boundaryedges); cleanup_ptr(self.segmentht); cleanup_ptr(self.surfelementht); + */ + self.boundaryedges = nullptr; + self.segmentht = nullptr; + self.surfelementht = nullptr; + self.openelements = NgArray(0); self.opensegments = NgArray(0); self.numvertices = 0; self.mlbetweennodes = NgArray,PointIndex::BASE> (0); self.mlparentelement = NgArray(0); self.mlparentsurfaceelement = NgArray(0); - self.curvedelems = new CurvedElements (self); - self.clusters = new AnisotropicClusters (self); - self.ident = new Identifications (self); + self.curvedelems = make_unique (self); + self.clusters = make_unique (self); + self.ident = make_unique (self); self.topology = MeshTopology(*this); self.topology.Update(); self.BuildElementSearchTree(); diff --git a/libsrc/meshing/refine.cpp b/libsrc/meshing/refine.cpp index 97c26d73..b15b53bf 100644 --- a/libsrc/meshing/refine.cpp +++ b/libsrc/meshing/refine.cpp @@ -361,7 +361,7 @@ namespace netgen mesh.VolumeElements().SetAllocSize(8*oldne); for (ElementIndex ei = 0; ei < oldne; ei++) { - const Element & el = mesh.VolumeElement(ei); + const Element & el = mesh[ei]; switch (el.GetType()) { case TET: diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index 0abca632..ac59051c 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -458,23 +458,23 @@ int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, const MeshingParam // was commented: - for (int i = 1; i <= mesh.GetNSE(); i++) - if (mesh.SurfaceElement(i).BadElement()) + for (SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++) + if (mesh[sei].BadElement()) { 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); } - mesh.DeleteSurfaceElement(i); + mesh.Delete(sei); } // 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); - if (!el.PNum(1)) - continue; + const Element2d & el = mesh[sei]; + if (el.IsDeleted()) continue; + if (!el.PNum(1).IsValid()) continue; Vec3d n = Cross (Vec3d (mesh.Point(el.PNum(1)), 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(); 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); - mesh.DeleteSurfaceElement(i); + mesh.Delete(sei); } } // end comments