make Topology a member of Mesh (rather then pointer) to reduce number of pointer dereferencing steps. This required move operators for Array and Table.

This commit is contained in:
Joachim Schöberl 2017-02-25 19:48:37 +01:00
parent c633035043
commit 90d4c94028
6 changed files with 131 additions and 110 deletions

View File

@ -267,6 +267,15 @@ namespace netgen
(*this)[i] = a2[i]; (*this)[i] = a2[i];
} }
/// array move
Array (Array && a2)
: FlatArray<T,BASE,TIND> (a2.size, a2.data), allocsize(a2.allocsize), ownmem(a2.ownmem)
{
a2.size = 0;
a2.data = nullptr;
a2.allocsize = 0;
a2.ownmem = false;
}
/// if responsible, deletes memory /// if responsible, deletes memory
@ -377,7 +386,15 @@ namespace netgen
return *this; return *this;
} }
Array & operator= (Array && a2)
{
Swap (data, a2.data);
Swap (size, a2.size);
Swap (allocsize, a2.allocsize);
Swap (ownmem, a2.ownmem);
return *this;
}
private: private:
/// resize array, at least to size minsize. copy contents /// resize array, at least to size minsize. copy contents

View File

@ -34,11 +34,25 @@ protected:
public: public:
/// ///
BASE_TABLE (BASE_TABLE && table2)
: data(move(table2.data)), oneblock(table2.oneblock)
{
table2.oneblock = nullptr;
}
BASE_TABLE (int size); BASE_TABLE (int size);
/// ///
BASE_TABLE (const FlatArray<int> & entrysizes, int elemsize); BASE_TABLE (const FlatArray<int> & entrysizes, int elemsize);
/// ///
~BASE_TABLE (); ~BASE_TABLE ();
BASE_TABLE & operator= (BASE_TABLE && table2)
{
data = move(table2.data);
Swap (oneblock, table2.oneblock);
return *this;
}
/// ///
void SetSize (int size); void SetSize (int size);
/// ///
@ -94,7 +108,7 @@ class TABLE : public BASE_TABLE
public: public:
/// Creates table. /// Creates table.
inline TABLE () : BASE_TABLE(0) { ; } inline TABLE () : BASE_TABLE(0) { ; }
/// Creates table of size size /// Creates table of size size
inline TABLE (int size) : BASE_TABLE (size) { ; } inline TABLE (int size) : BASE_TABLE (size) { ; }

View File

@ -7,7 +7,7 @@ namespace netgen
static mutex buildsearchtree_mutex; static mutex buildsearchtree_mutex;
Mesh :: Mesh () Mesh :: Mesh ()
: surfarea(*this) : surfarea(*this), topology(*this)
{ {
// volelements.SetName ("vol elements"); // volelements.SetName ("vol elements");
// surfelements.SetName ("surf elements"); // surfelements.SetName ("surf elements");
@ -27,7 +27,7 @@ namespace netgen
numvertices = -1; numvertices = -1;
dimension = 3; dimension = 3;
topology = new MeshTopology (*this); // topology = new MeshTopology (*this);
curvedelems = new CurvedElements (*this); curvedelems = new CurvedElements (*this);
clusters = new AnisotropicClusters (*this); clusters = new AnisotropicClusters (*this);
ident = new Identifications (*this); ident = new Identifications (*this);
@ -57,7 +57,7 @@ namespace netgen
delete segmentht; delete segmentht;
delete curvedelems; delete curvedelems;
delete clusters; delete clusters;
delete topology; // delete topology;
delete ident; delete ident;
delete elementsearchtree; delete elementsearchtree;
delete coarsemesh; delete coarsemesh;
@ -126,8 +126,9 @@ namespace netgen
delete ident; delete ident;
ident = new Identifications (*this); ident = new Identifications (*this);
delete topology; // delete topology;
topology = new MeshTopology (*this); // topology = new MeshTopology (*this);
topology = MeshTopology (*this);
delete curvedelems; delete curvedelems;
curvedelems = new CurvedElements (*this); curvedelems = new CurvedElements (*this);
delete clusters; delete clusters;
@ -1241,7 +1242,7 @@ namespace netgen
if (ntasks == 1) // sequential run only if (ntasks == 1) // sequential run only
{ {
topology -> Update(); topology.Update();
clusters -> Update(); clusters -> Update();
} }
@ -1481,7 +1482,7 @@ namespace netgen
CalcSurfacesOfNode (); CalcSurfacesOfNode ();
topology -> Update(); topology.Update();
clusters -> Update(); clusters -> Update();
SetNextMajorTimeStamp(); SetNextMajorTimeStamp();
@ -4878,12 +4879,12 @@ namespace netgen
//(*testout) << "velement " << velement << endl; //(*testout) << "velement " << velement << endl;
Array<int> faces; Array<int> faces;
topology->GetElementFaces(velement,faces); topology.GetElementFaces(velement,faces);
//(*testout) << "faces " << faces << endl; //(*testout) << "faces " << faces << endl;
for(int i=0; i<faces.Size(); i++) for(int i=0; i<faces.Size(); i++)
faces[i] = topology->GetFace2SurfaceElement(faces[i]); faces[i] = topology.GetFace2SurfaceElement(faces[i]);
//(*testout) << "surfel " << faces << endl; //(*testout) << "surfel " << faces << endl;
@ -4910,7 +4911,7 @@ namespace netgen
} }
Array<int> faces2; Array<int> faces2;
topology->GetElementFaces(velement,faces2); topology.GetElementFaces(velement,faces2);
/* /*
cout << "no matching surf element" << endl cout << "no matching surf element" << endl
<< "p = " << p << endl << "p = " << p << endl
@ -5709,7 +5710,7 @@ namespace netgen
void Mesh :: UpdateTopology (TaskManager tm) void Mesh :: UpdateTopology (TaskManager tm)
{ {
topology->Update(tm); topology.Update(tm);
clusters->Update(tm); clusters->Update(tm);
#ifdef PARALLEL #ifdef PARALLEL
if (paralleltop) if (paralleltop)

View File

@ -103,7 +103,7 @@ namespace netgen
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; class CurvedElements * curvedelems;
@ -687,7 +687,7 @@ namespace netgen
const MeshTopology & GetTopology () const const MeshTopology & GetTopology () const
{ return *topology; } { return topology; }
DLL_HEADER void UpdateTopology (TaskManager tm = &DummyTaskManager); DLL_HEADER void UpdateTopology (TaskManager tm = &DummyTaskManager);

View File

@ -44,23 +44,14 @@ namespace netgen
MeshTopology :: MeshTopology (const Mesh & amesh) MeshTopology :: MeshTopology (const Mesh & amesh)
: mesh(amesh) : mesh(&amesh)
{ {
buildedges = 1; buildedges = 1;
buildfaces = 1; buildfaces = 1;
vert2element = 0;
vert2surfelement = 0;
vert2segment = 0;
timestamp = -1; timestamp = -1;
} }
MeshTopology :: ~MeshTopology () MeshTopology :: ~MeshTopology () { ; }
{
delete vert2element;
delete vert2surfelement;
delete vert2segment;
delete vert2pointelement;
}
template <typename FUNC> template <typename FUNC>
void LoopOverEdges (const Mesh & mesh, MeshTopology & top, PointIndex v, void LoopOverEdges (const Mesh & mesh, MeshTopology & top, PointIndex v,
@ -350,13 +341,13 @@ namespace netgen
#endif #endif
if (timestamp > mesh.GetTimeStamp()) return; if (timestamp > mesh->GetTimeStamp()) return;
int ne = mesh.GetNE(); int ne = mesh->GetNE();
int nse = mesh.GetNSE(); int nse = mesh->GetNSE();
int nseg = mesh.GetNSeg(); int nseg = mesh->GetNSeg();
int np = mesh.GetNP(); int np = mesh->GetNP();
int nv = mesh.GetNV(); int nv = mesh->GetNV();
if (id == 0) if (id == 0)
PrintMessage (3, "Update mesh topology"); PrintMessage (3, "Update mesh topology");
@ -367,12 +358,7 @@ namespace netgen
(*testout) << "nseg = " << nseg << endl; (*testout) << "nseg = " << nseg << endl;
(*testout) << "np = " << np << endl; (*testout) << "np = " << np << endl;
(*testout) << "nv = " << nv << endl; (*testout) << "nv = " << nv << endl;
delete vert2element;
delete vert2surfelement;
delete vert2segment;
delete vert2pointelement;
Array<int,PointIndex::BASE> cnt(nv); Array<int,PointIndex::BASE> cnt(nv);
Array<int> vnums; Array<int> vnums;
@ -382,69 +368,67 @@ namespace netgen
vertex to surface element vertex to surface element
vertex to segment vertex to segment
*/ */
cnt = 0; cnt = 0;
for (ElementIndex ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
{ {
const Element & el = mesh[ei]; const Element & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++) for (int j = 0; j < el.GetNV(); j++)
cnt[el[j]]++; cnt[el[j]]++;
} }
vert2element = new TABLE<ElementIndex,PointIndex::BASE> (cnt); vert2element = TABLE<ElementIndex,PointIndex::BASE> (cnt);
for (ElementIndex ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
{ {
const Element & el = mesh[ei]; const Element & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++) for (int j = 0; j < el.GetNV(); j++)
vert2element->AddSave (el[j], ei); vert2element.AddSave (el[j], ei);
} }
cnt = 0; cnt = 0;
for (SurfaceElementIndex sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{ {
const Element2d & el = mesh[sei]; const Element2d & el = (*mesh)[sei];
for (int j = 0; j < el.GetNV(); j++) for (int j = 0; j < el.GetNV(); j++)
cnt[el[j]]++; cnt[el[j]]++;
} }
vert2surfelement = new TABLE<SurfaceElementIndex,PointIndex::BASE> (cnt); vert2surfelement = TABLE<SurfaceElementIndex,PointIndex::BASE> (cnt);
for (SurfaceElementIndex sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{ {
const Element2d & el = mesh[sei]; const Element2d & el = (*mesh)[sei];
for (int j = 0; j < el.GetNV(); j++) for (int j = 0; j < el.GetNV(); j++)
vert2surfelement->AddSave (el[j], sei); vert2surfelement.AddSave (el[j], sei);
} }
cnt = 0; cnt = 0;
for (SegmentIndex si = 0; si < nseg; si++) for (SegmentIndex si = 0; si < nseg; si++)
{ {
const Segment & seg = mesh.LineSegment(si); const Segment & seg = mesh->LineSegment(si);
cnt[seg[0]]++; cnt[seg[0]]++;
cnt[seg[1]]++; cnt[seg[1]]++;
} }
vert2segment = new TABLE<SegmentIndex,PointIndex::BASE> (cnt); vert2segment = TABLE<SegmentIndex,PointIndex::BASE> (cnt);
for (SegmentIndex si = 0; si < nseg; si++) for (SegmentIndex si = 0; si < nseg; si++)
{ {
const Segment & seg = mesh.LineSegment(si); const Segment & seg = mesh->LineSegment(si);
vert2segment->AddSave (seg[0], si); vert2segment.AddSave (seg[0], si);
vert2segment->AddSave (seg[1], si); vert2segment.AddSave (seg[1], si);
} }
cnt = 0; cnt = 0;
for (int pei = 0; pei < mesh.pointelements.Size(); pei++) for (int pei = 0; pei < mesh->pointelements.Size(); pei++)
{ {
const Element0d & pointel = mesh.pointelements[pei]; const Element0d & pointel = mesh->pointelements[pei];
cnt[pointel.pnum]++; cnt[pointel.pnum]++;
} }
vert2pointelement = new TABLE<int,PointIndex::BASE> (cnt); vert2pointelement = TABLE<int,PointIndex::BASE> (cnt);
for (int pei = 0; pei < mesh.pointelements.Size(); pei++) for (int pei = 0; pei < mesh->pointelements.Size(); pei++)
{ {
const Element0d & pointel = mesh.pointelements[pei]; const Element0d & pointel = mesh->pointelements[pei];
vert2pointelement->AddSave (pointel.pnum, pei); vert2pointelement.AddSave (pointel.pnum, pei);
} }
@ -477,15 +461,15 @@ namespace netgen
// ensure all coarse grid and intermediate level edges // ensure all coarse grid and intermediate level edges
cnt = 0; cnt = 0;
for (int i = mesh.mlbetweennodes.Begin(); i < mesh.mlbetweennodes.End(); i++) for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++)
{ {
INDEX_2 parents = Sort (mesh.mlbetweennodes[i]); INDEX_2 parents = Sort (mesh->mlbetweennodes[i]);
if (parents[0] >= PointIndex::BASE) cnt[parents[0]]++; if (parents[0] >= PointIndex::BASE) cnt[parents[0]]++;
} }
TABLE<int,PointIndex::BASE> vert2vertcoarse (cnt); TABLE<int,PointIndex::BASE> vert2vertcoarse (cnt);
for (int i = mesh.mlbetweennodes.Begin(); i < mesh.mlbetweennodes.End(); i++) for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++)
{ {
INDEX_2 parents = Sort (mesh.mlbetweennodes[i]); INDEX_2 parents = Sort (mesh->mlbetweennodes[i]);
if (parents[0] > PointIndex::BASE) vert2vertcoarse.AddSave (parents[0], parents[1]); if (parents[0] > PointIndex::BASE) vert2vertcoarse.AddSave (parents[0], parents[1]);
} }
@ -495,7 +479,7 @@ namespace netgen
for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++) for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++)
{ {
int onv = vert2edge[i].Size() + vert2vertcoarse[i].Size() + int onv = vert2edge[i].Size() + vert2vertcoarse[i].Size() +
4*(*vert2element)[i].Size() + 2*(*vert2surfelement)[i].Size() + (*vert2segment)[i].Size(); 4*(vert2element)[i].Size() + 2*(vert2surfelement)[i].Size() + (vert2segment)[i].Size();
max_edge_on_vertex = max (onv, max_edge_on_vertex); max_edge_on_vertex = max (onv, max_edge_on_vertex);
} }
@ -504,7 +488,7 @@ namespace netgen
cnt = 0; cnt = 0;
ParallelForRange ParallelForRange
(tm, mesh.Points().Size(), (tm, mesh->Points().Size(),
[&] (size_t begin, size_t end) [&] (size_t begin, size_t end)
{ {
INDEX_CLOSED_HASHTABLE<int> v2eht(2*max_edge_on_vertex+10); INDEX_CLOSED_HASHTABLE<int> v2eht(2*max_edge_on_vertex+10);
@ -527,7 +511,7 @@ namespace netgen
v2eht.Set (v2, 33); // some value v2eht.Set (v2, 33); // some value
} }
LoopOverEdges (mesh, *this, v, LoopOverEdges (*mesh, *this, v,
[&] (INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir) [&] (INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir)
{ {
if (!v2eht.Used (edge.I2())) if (!v2eht.Used (edge.I2()))
@ -542,7 +526,7 @@ namespace netgen
// accumulate number of edges // accumulate number of edges
int ned = edge2vert.Size(); int ned = edge2vert.Size();
for (auto v : mesh.Points().Range()) for (auto v : mesh->Points().Range())
{ {
auto hv = cnt[v]; auto hv = cnt[v];
cnt[v] = ned; cnt[v] = ned;
@ -556,7 +540,7 @@ namespace netgen
// for (PointIndex v = PointIndex::BASE; v < nv+PointIndex::BASE; v++) // for (PointIndex v = PointIndex::BASE; v < nv+PointIndex::BASE; v++)
ParallelForRange ParallelForRange
(tm, mesh.Points().Size(), (tm, mesh->Points().Size(),
[&] (size_t begin, size_t end) [&] (size_t begin, size_t end)
{ {
INDEX_CLOSED_HASHTABLE<int> v2eht(2*max_edge_on_vertex+10); INDEX_CLOSED_HASHTABLE<int> v2eht(2*max_edge_on_vertex+10);
@ -581,7 +565,7 @@ namespace netgen
vertex2.Append (v2); vertex2.Append (v2);
} }
LoopOverEdges (mesh, *this, v, LoopOverEdges (*mesh, *this, v,
[&](INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir) [&](INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir)
{ {
if (!v2eht.Used(edge.I2())) if (!v2eht.Used(edge.I2()))
@ -600,7 +584,7 @@ namespace netgen
ned++; ned++;
} }
LoopOverEdges (mesh, *this, v, LoopOverEdges (*mesh, *this, v,
[&](INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir) [&](INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir)
{ {
int edgenum = v2eht.Get(edge.I2()); int edgenum = v2eht.Get(edge.I2());
@ -661,7 +645,7 @@ namespace netgen
int max_face_on_vertex = 0; int max_face_on_vertex = 0;
for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++) for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++)
{ {
int onv = vert2oldface[i].Size() + (*vert2element)[i].Size() + (*vert2surfelement)[i].Size(); int onv = vert2oldface[i].Size() + vert2element[i].Size() + vert2surfelement[i].Size();
max_face_on_vertex = max (onv, max_face_on_vertex); max_face_on_vertex = max (onv, max_face_on_vertex);
} }
@ -680,7 +664,7 @@ namespace netgen
// for (auto v : mesh.Points().Range()) // for (auto v : mesh.Points().Range())
NgProfiler::StartTimer (timer2b1); NgProfiler::StartTimer (timer2b1);
ParallelForRange ParallelForRange
(tm, mesh.Points().Size(), (tm, mesh->Points().Size(),
[&] (size_t begin, size_t end) [&] (size_t begin, size_t end)
{ {
INDEX_3_CLOSED_HASHTABLE<int> vert2face(2*max_face_on_vertex+10); INDEX_3_CLOSED_HASHTABLE<int> vert2face(2*max_face_on_vertex+10);
@ -698,7 +682,7 @@ namespace netgen
vert2face.Set (face, 33); // something vert2face.Set (face, 33); // something
} }
int cnti = 0; int cnti = 0;
LoopOverFaces (mesh, *this, v, LoopOverFaces (*mesh, *this, v,
[&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir) [&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir)
{ {
INDEX_3 face(i4.I1(), i4.I2(), i4.I3()); INDEX_3 face(i4.I1(), i4.I2(), i4.I3());
@ -715,7 +699,7 @@ namespace netgen
// accumulate number of faces // accumulate number of faces
int nfa = oldnfa; int nfa = oldnfa;
for (auto v : mesh.Points().Range()) for (auto v : mesh->Points().Range())
{ {
auto hv = cnt[v]; auto hv = cnt[v];
cnt[v] = nfa; cnt[v] = nfa;
@ -726,7 +710,7 @@ namespace netgen
// for (auto v : mesh.Points().Range()) // for (auto v : mesh.Points().Range())
ParallelForRange ParallelForRange
(tm, mesh.Points().Size(), (tm, mesh->Points().Size(),
[&] (size_t begin, size_t end) [&] (size_t begin, size_t end)
{ {
INDEX_3_CLOSED_HASHTABLE<int> vert2face(2*max_face_on_vertex+10); INDEX_3_CLOSED_HASHTABLE<int> vert2face(2*max_face_on_vertex+10);
@ -746,7 +730,7 @@ namespace netgen
vert2face.Set (face, fnr); vert2face.Set (face, fnr);
} }
LoopOverFaces (mesh, *this, v, LoopOverFaces (*mesh, *this, v,
[&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir) [&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir)
{ {
INDEX_3 face(i4.I1(), i4.I2(), i4.I3()); INDEX_3 face(i4.I1(), i4.I2(), i4.I3());
@ -775,7 +759,7 @@ namespace netgen
} }
LoopOverFaces (mesh, *this, v, LoopOverFaces (*mesh, *this, v,
[&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir) [&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir)
{ {
INDEX_3 face(i4.I1(), i4.I2(), i4.I3()); INDEX_3 face(i4.I1(), i4.I2(), i4.I3());
@ -1149,10 +1133,10 @@ namespace netgen
{ {
// (*testout) << "is face of element " << vertels[k] << endl; // (*testout) << "is face of element " << vertels[k] << endl;
if (mesh.coarsemesh && mesh.hpelements->Size() == mesh.GetNE() ) if (mesh->coarsemesh && mesh->hpelements->Size() == mesh->GetNE() )
{ {
const HPRefElement & hpref_el = const HPRefElement & hpref_el =
(*mesh.hpelements) [ mesh[vertels[k]].hp_elnr]; (*mesh->hpelements) [ (*mesh)[vertels[k]].hp_elnr];
(*testout) << "coarse eleme = " << hpref_el.coarse_elnr << endl; (*testout) << "coarse eleme = " << hpref_el.coarse_elnr << endl;
} }
@ -1306,7 +1290,7 @@ namespace netgen
void MeshTopology :: GetElementEdges (int elnr, Array<int> & eledges) const void MeshTopology :: GetElementEdges (int elnr, Array<int> & eledges) const
{ {
int ned = GetNEdges (mesh.VolumeElement(elnr).GetType()); int ned = GetNEdges (mesh->VolumeElement(elnr).GetType());
eledges.SetSize (ned); eledges.SetSize (ned);
for (int i = 0; i < ned; i++) for (int i = 0; i < ned; i++)
eledges[i] = edges.Get(elnr)[i].nr+1; eledges[i] = edges.Get(elnr)[i].nr+1;
@ -1314,7 +1298,7 @@ namespace netgen
} }
void MeshTopology :: GetElementFaces (int elnr, Array<int> & elfaces, bool withorientation) const void MeshTopology :: GetElementFaces (int elnr, Array<int> & elfaces, bool withorientation) const
{ {
int nfa = GetNFaces (mesh.VolumeElement(elnr).GetType()); int nfa = GetNFaces (mesh->VolumeElement(elnr).GetType());
elfaces.SetSize (nfa); elfaces.SetSize (nfa);
if (!withorientation) if (!withorientation)
@ -1342,7 +1326,7 @@ namespace netgen
void MeshTopology :: GetElementEdgeOrientations (int elnr, Array<int> & eorient) const void MeshTopology :: GetElementEdgeOrientations (int elnr, Array<int> & eorient) const
{ {
int ned = GetNEdges (mesh.VolumeElement(elnr).GetType()); int ned = GetNEdges (mesh->VolumeElement(elnr).GetType());
eorient.SetSize (ned); eorient.SetSize (ned);
for (int i = 1; i <= ned; i++) for (int i = 1; i <= ned; i++)
// eorient.Elem(i) = (edges.Get(elnr)[i-1] > 0) ? 1 : -1; // eorient.Elem(i) = (edges.Get(elnr)[i-1] > 0) ? 1 : -1;
@ -1352,7 +1336,7 @@ namespace netgen
void MeshTopology :: GetElementFaceOrientations (int elnr, Array<int> & forient) const void MeshTopology :: GetElementFaceOrientations (int elnr, Array<int> & forient) const
{ {
int nfa = GetNFaces (mesh.VolumeElement(elnr).GetType()); int nfa = GetNFaces (mesh->VolumeElement(elnr).GetType());
forient.SetSize (nfa); forient.SetSize (nfa);
for (int i = 1; i <= nfa; i++) for (int i = 1; i <= nfa; i++)
// forient.Elem(i) = faces.Get(elnr)[i-1].forient; // forient.Elem(i) = faces.Get(elnr)[i-1].forient;
@ -1366,7 +1350,7 @@ namespace netgen
{ {
// int ned = GetNEdges (mesh.VolumeElement(elnr).GetType()); // int ned = GetNEdges (mesh.VolumeElement(elnr).GetType());
if (mesh.GetDimension()==3 || 1) if (mesh->GetDimension()==3 || 1)
{ {
if (orient) if (orient)
{ {
@ -1454,7 +1438,7 @@ namespace netgen
void MeshTopology :: GetSurfaceElementEdges (int elnr, Array<int> & eledges) const void MeshTopology :: GetSurfaceElementEdges (int elnr, Array<int> & eledges) const
{ {
int ned = GetNEdges (mesh.SurfaceElement(elnr).GetType()); int ned = GetNEdges (mesh->SurfaceElement(elnr).GetType());
eledges.SetSize (ned); eledges.SetSize (ned);
for (int i = 0; i < ned; i++) for (int i = 0; i < ned; i++)
// eledges[i] = abs (surfedges.Get(elnr)[i]); // eledges[i] = abs (surfedges.Get(elnr)[i]);
@ -1463,7 +1447,7 @@ namespace netgen
void MeshTopology :: GetEdges (SurfaceElementIndex elnr, Array<int> & eledges) const void MeshTopology :: GetEdges (SurfaceElementIndex elnr, Array<int> & eledges) const
{ {
int ned = GetNEdges (mesh[elnr].GetType()); int ned = GetNEdges ( (*mesh)[elnr].GetType());
eledges.SetSize (ned); eledges.SetSize (ned);
for (int i = 0; i < ned; i++) for (int i = 0; i < ned; i++)
// eledges[i] = abs (surfedges[elnr][i])-1; // eledges[i] = abs (surfedges[elnr][i])-1;
@ -1486,7 +1470,7 @@ namespace netgen
void MeshTopology :: void MeshTopology ::
GetSurfaceElementEdgeOrientations (int elnr, Array<int> & eorient) const GetSurfaceElementEdgeOrientations (int elnr, Array<int> & eorient) const
{ {
int ned = GetNEdges (mesh.SurfaceElement(elnr).GetType()); int ned = GetNEdges (mesh->SurfaceElement(elnr).GetType());
eorient.SetSize (ned); eorient.SetSize (ned);
for (int i = 0; i < ned; i++) for (int i = 0; i < ned; i++)
// eorient[i] = (surfedges.Get(elnr)[i] > 0) ? 1 : -1; // eorient[i] = (surfedges.Get(elnr)[i] > 0) ? 1 : -1;
@ -1504,7 +1488,7 @@ namespace netgen
int MeshTopology :: GetSurfaceElementEdges (int elnr, int * eledges, int * orient) const int MeshTopology :: GetSurfaceElementEdges (int elnr, int * eledges, int * orient) const
{ {
int i; int i;
if (mesh.GetDimension() == 3 || 1) if (mesh->GetDimension() == 3 || 1)
{ {
if (orient) if (orient)
{ {
@ -1554,7 +1538,7 @@ namespace netgen
int MeshTopology :: GetElementEdgeOrientation (int elnr, int locedgenr) const int MeshTopology :: GetElementEdgeOrientation (int elnr, int locedgenr) const
{ {
const Element & el = mesh.VolumeElement (elnr); const Element & el = mesh->VolumeElement (elnr);
const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType()); const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType());
int k = locedgenr; int k = locedgenr;
@ -1566,7 +1550,7 @@ namespace netgen
int MeshTopology :: GetElementFaceOrientation (int elnr, int locfacenr) const int MeshTopology :: GetElementFaceOrientation (int elnr, int locfacenr) const
{ {
const Element & el = mesh.VolumeElement (elnr); const Element & el = mesh->VolumeElement (elnr);
const ELEMENT_FACE * elfaces = MeshTopology::GetFaces0 (el.GetType()); const ELEMENT_FACE * elfaces = MeshTopology::GetFaces0 (el.GetType());
@ -1622,7 +1606,7 @@ namespace netgen
int MeshTopology :: GetSurfaceElementEdgeOrientation (int elnr, int locedgenr) const int MeshTopology :: GetSurfaceElementEdgeOrientation (int elnr, int locedgenr) const
{ {
const Element2d & el = mesh.SurfaceElement (elnr); const Element2d & el = mesh->SurfaceElement (elnr);
const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType()); const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType());
int k = locedgenr; int k = locedgenr;
@ -1633,7 +1617,7 @@ namespace netgen
int MeshTopology :: GetSurfaceElementFaceOrientation2 (int elnr) const int MeshTopology :: GetSurfaceElementFaceOrientation2 (int elnr) const
{ {
const Element2d & el = mesh.SurfaceElement (elnr); const Element2d & el = mesh->SurfaceElement (elnr);
const ELEMENT_FACE * elfaces = MeshTopology::GetFaces0 (el.GetType()); const ELEMENT_FACE * elfaces = MeshTopology::GetFaces0 (el.GetType());
@ -1687,7 +1671,7 @@ namespace netgen
int MeshTopology :: GetSegmentEdgeOrientation (int elnr) const int MeshTopology :: GetSegmentEdgeOrientation (int elnr) const
{ {
const Segment & el = mesh.LineSegment (elnr); const Segment & el = mesh->LineSegment (elnr);
const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType()); const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType());
int k = 0; int k = 0;
@ -1760,7 +1744,7 @@ namespace netgen
// find one element having all vertices of the face // find one element having all vertices of the face
for (int i = 0; i < els.Size(); i++) for (int i = 0; i < els.Size(); i++)
{ {
const Element & el = mesh[els[i]]; const Element & el = (*mesh)[els[i]];
int nref_faces = GetNFaces (el.GetType()); int nref_faces = GetNFaces (el.GetType());
const ELEMENT_FACE * ref_faces = GetFaces1 (el.GetType()); const ELEMENT_FACE * ref_faces = GetFaces1 (el.GetType());
int nfa_ref_edges = GetNEdges (GetFaceType(fnr)); int nfa_ref_edges = GetNEdges (GetFaceType(fnr));
@ -1849,12 +1833,12 @@ namespace netgen
void MeshTopology :: GetVertexElements (int vnr, Array<ElementIndex> & elements) const void MeshTopology :: GetVertexElements (int vnr, Array<ElementIndex> & elements) const
{ {
if (vert2element) if (vert2element.Size())
{ {
int ne = vert2element->EntrySize(vnr); int ne = vert2element.EntrySize(vnr);
elements.SetSize(ne); elements.SetSize(ne);
for (int i = 1; i <= ne; i++) for (int i = 1; i <= ne; i++)
elements.Elem(i) = vert2element->Get(vnr, i); elements.Elem(i) = vert2element.Get(vnr, i);
} }
} }
@ -1884,13 +1868,13 @@ namespace netgen
void MeshTopology :: GetVertexSurfaceElements( int vnr, void MeshTopology :: GetVertexSurfaceElements( int vnr,
Array<SurfaceElementIndex> & elements ) const Array<SurfaceElementIndex> & elements ) const
{ {
if (vert2surfelement) if (vert2surfelement.Size())
{ {
int i; int i;
int ne = vert2surfelement->EntrySize(vnr); int ne = vert2surfelement.EntrySize(vnr);
elements.SetSize(ne); elements.SetSize(ne);
for (i = 1; i <= ne; i++) for (i = 1; i <= ne; i++)
elements.Elem(i) = vert2surfelement->Get(vnr, i); elements.Elem(i) = vert2surfelement.Get(vnr, i);
} }
} }

View File

@ -38,7 +38,7 @@ struct T_FACE
class MeshTopology class MeshTopology
{ {
const Mesh & mesh; const Mesh * mesh;
bool buildedges; bool buildedges;
bool buildfaces; bool buildfaces;
@ -57,17 +57,22 @@ class MeshTopology
Array<T_FACE> surffaces; Array<T_FACE> surffaces;
Array<INDEX_2> surf2volelement; Array<INDEX_2> surf2volelement;
Array<int> face2surfel; Array<int> face2surfel;
TABLE<ElementIndex,PointIndex::BASE> *vert2element; TABLE<ElementIndex,PointIndex::BASE> vert2element;
TABLE<SurfaceElementIndex,PointIndex::BASE> *vert2surfelement; TABLE<SurfaceElementIndex,PointIndex::BASE> vert2surfelement;
TABLE<SegmentIndex,PointIndex::BASE> *vert2segment; TABLE<SegmentIndex,PointIndex::BASE> vert2segment;
TABLE<int,PointIndex::BASE> *vert2pointelement = nullptr; TABLE<int,PointIndex::BASE> vert2pointelement;
int timestamp; int timestamp;
public: public:
int GetNSurfedges() const {return surfedges.Size();} int GetNSurfedges() const {return surfedges.Size();}
MeshTopology () = default;
MeshTopology (const MeshTopology & top) = default;
MeshTopology (MeshTopology && top) = default;
MeshTopology (const Mesh & amesh); MeshTopology (const Mesh & amesh);
~MeshTopology (); ~MeshTopology ();
MeshTopology & operator= (const MeshTopology & top) = default;
MeshTopology & operator= (MeshTopology && top) = default;
void SetBuildEdges (bool be) void SetBuildEdges (bool be)
{ buildedges = be; } { buildedges = be; }
void SetBuildFaces (bool bf) void SetBuildFaces (bool bf)
@ -159,17 +164,17 @@ public:
void GetVertexElements (int vnr, Array<ElementIndex> & elements) const; void GetVertexElements (int vnr, Array<ElementIndex> & elements) const;
FlatArray<ElementIndex> GetVertexElements (int vnr) const FlatArray<ElementIndex> GetVertexElements (int vnr) const
{ return (*vert2element)[vnr]; } { return vert2element[vnr]; }
void GetVertexSurfaceElements( int vnr, Array<SurfaceElementIndex>& elements ) const; void GetVertexSurfaceElements( int vnr, Array<SurfaceElementIndex>& elements ) const;
FlatArray<SurfaceElementIndex> GetVertexSurfaceElements (int vnr) const FlatArray<SurfaceElementIndex> GetVertexSurfaceElements (int vnr) const
{ return (*vert2surfelement)[vnr]; } { return vert2surfelement[vnr]; }
FlatArray<SegmentIndex> GetVertexSegments (int vnr) const FlatArray<SegmentIndex> GetVertexSegments (int vnr) const
{ return (*vert2segment)[vnr]; } { return vert2segment[vnr]; }
FlatArray<int> GetVertexPointElements (int vnr) const FlatArray<int> GetVertexPointElements (int vnr) const
{ return (*vert2pointelement)[vnr]; } { return vert2pointelement[vnr]; }
int GetVerticesEdge ( int v1, int v2) const; int GetVerticesEdge ( int v1, int v2) const;
void GetSegmentVolumeElements ( int segnr, Array<ElementIndex> & els ) const; void GetSegmentVolumeElements ( int segnr, Array<ElementIndex> & els ) const;