mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
unique ptrs in Mesh
This commit is contained in:
parent
b03705c37d
commit
c900e0380b
@ -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)
|
||||
|
@ -1308,7 +1308,7 @@ namespace netgen
|
||||
|
||||
// NgLock mem_lock (mem_mutex,1);
|
||||
|
||||
mesh.coarsemesh = new Mesh;
|
||||
mesh.coarsemesh = make_unique<Mesh>();
|
||||
*mesh.coarsemesh = mesh;
|
||||
|
||||
// #ifdef CURVEDELEMS_NEW
|
||||
@ -1317,8 +1317,8 @@ namespace netgen
|
||||
// #endif
|
||||
|
||||
|
||||
delete mesh.hpelements;
|
||||
mesh.hpelements = new NgArray<HPRefElement>;
|
||||
// delete mesh.hpelements;
|
||||
mesh.hpelements = make_unique<NgArray<HPRefElement>>();
|
||||
|
||||
NgArray<HPRefElement> & hpelements = *mesh.hpelements;
|
||||
|
||||
|
@ -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<CurvedElements> (*this);
|
||||
clusters = make_unique<AnisotropicClusters> (*this);
|
||||
ident = make_unique<Identifications> (*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<ParallelMeshTopology> (*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<Identifications> (*this);
|
||||
topology = MeshTopology (*this);
|
||||
delete curvedelems;
|
||||
curvedelems = new CurvedElements (*this);
|
||||
delete clusters;
|
||||
clusters = new AnisotropicClusters (*this);
|
||||
curvedelems = make_unique<CurvedElements> (*this);
|
||||
clusters = make_unique<AnisotropicClusters> (*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<ParallelMeshTopology> (*this);
|
||||
#endif
|
||||
|
||||
lock.UnLock();
|
||||
@ -1571,9 +1569,9 @@ namespace netgen
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -1643,12 +1641,14 @@ namespace netgen
|
||||
// surfacesonnode.SetSize (GetNP());
|
||||
TABLE<int,PointIndex::BASE> 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<int> (GetNSE()/4 + 1);
|
||||
@ -1656,8 +1656,8 @@ namespace netgen
|
||||
*/
|
||||
|
||||
if (dimension == 3)
|
||||
surfelementht = new INDEX_3_CLOSED_HASHTABLE<int> (3*GetNSE() + 1);
|
||||
segmentht = new INDEX_2_CLOSED_HASHTABLE<int> (3*GetNSeg() + 1);
|
||||
surfelementht = make_unique<INDEX_3_CLOSED_HASHTABLE<int>> (3*GetNSE() + 1);
|
||||
segmentht = make_unique<INDEX_2_CLOSED_HASHTABLE<int>> (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<LocalH> (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<BoxTree<3>> (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<BoxTree<3>> (box);
|
||||
|
||||
for (ElementIndex ei = 0; ei < ne; ei++)
|
||||
{
|
||||
|
@ -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<int,PointIndex::BASE> surfacesonnode;
|
||||
/// 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
|
||||
NgArray<Element2d> openelements;
|
||||
@ -64,7 +66,7 @@ namespace netgen
|
||||
/**
|
||||
Representation of local mesh-size h
|
||||
*/
|
||||
LocalH * lochfunc;
|
||||
unique_ptr<LocalH> lochfunc;
|
||||
///
|
||||
double hglob;
|
||||
///
|
||||
@ -98,24 +100,24 @@ namespace netgen
|
||||
NgArray<string*> cd3names;
|
||||
|
||||
/// Periodic surface, close surface, etc. identifications
|
||||
Identifications * ident;
|
||||
unique_ptr<Identifications> ident;
|
||||
|
||||
|
||||
/// number of vertices (if < 0, use np)
|
||||
int numvertices;
|
||||
|
||||
/// geometric search tree for interval intersection search
|
||||
BoxTree<3> * elementsearchtree;
|
||||
unique_ptr<BoxTree<3>> 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<CurvedElements> curvedelems;
|
||||
|
||||
/// nodes identified by close points
|
||||
class AnisotropicClusters * clusters;
|
||||
unique_ptr<AnisotropicClusters> 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<ParallelMeshTopology> paralleltop;
|
||||
#endif
|
||||
|
||||
|
||||
@ -170,8 +171,8 @@ namespace netgen
|
||||
public:
|
||||
|
||||
// store coarse mesh before hp-refinement
|
||||
NgArray<HPRefElement> * hpelements;
|
||||
Mesh * coarsemesh;
|
||||
unique_ptr<NgArray<HPRefElement>> hpelements;
|
||||
unique_ptr<Mesh> 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]; }
|
||||
|
@ -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<Element2d>(0);
|
||||
self.opensegments = NgArray<Segment>(0);
|
||||
self.numvertices = 0;
|
||||
self.mlbetweennodes = NgArray<PointIndices<2>,PointIndex::BASE> (0);
|
||||
self.mlparentelement = NgArray<int>(0);
|
||||
self.mlparentsurfaceelement = NgArray<int>(0);
|
||||
self.curvedelems = new CurvedElements (self);
|
||||
self.clusters = new AnisotropicClusters (self);
|
||||
self.ident = new Identifications (self);
|
||||
self.curvedelems = make_unique<CurvedElements> (self);
|
||||
self.clusters = make_unique<AnisotropicClusters> (self);
|
||||
self.ident = make_unique<Identifications> (self);
|
||||
self.topology = MeshTopology(*this);
|
||||
self.topology.Update();
|
||||
self.BuildElementSearchTree();
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user