some more 0-based arrays

This commit is contained in:
Joachim Schoeberl 2025-01-05 15:33:48 +01:00
parent 1ebc6a0e81
commit b1e840f7d8
9 changed files with 46 additions and 35 deletions

View File

@ -328,7 +328,7 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<2> Ngx_Mesh :: GetNode<2> (int n
Ng_Node<2> node; Ng_Node<2> node;
node.vertices.ptr = (const int*)mesh->GetTopology().GetFaceVerticesPtr(nr); node.vertices.ptr = (const int*)mesh->GetTopology().GetFaceVerticesPtr(nr);
node.vertices.nv = (node.vertices.ptr[3]+1 == PointIndex::BASE) ? 3 : 4; node.vertices.nv = (node.vertices.ptr[3]+1 == PointIndex::BASE) ? 3 : 4;
node.surface_el = mesh->GetTopology().GetFace2SurfaceElement (nr+1)-1; node.surface_el = mesh->GetTopology().GetFace2SurfaceElement (nr);
return node; return node;
} }

View File

@ -1571,10 +1571,11 @@ int Ng_GetSurfaceElement_Face (int selnr, int * orient)
{ {
if (mesh->GetDimension() == 3) if (mesh->GetDimension() == 3)
{ {
SurfaceElementIndex sei = selnr-1;
const MeshTopology & topology = mesh->GetTopology(); const MeshTopology & topology = mesh->GetTopology();
if (orient) if (orient)
*orient = topology.GetSurfaceElementFaceOrientation (selnr); *orient = topology.GetSurfaceElementFaceOrientation (selnr);
return topology.GetSurfaceElementFace (selnr); return topology.GetFace(sei);
} }
return -1; return -1;
} }
@ -2343,7 +2344,7 @@ int Ng_GetElementClosureNodes (int dim, int elementnr, int nodeset, int * nodes)
if (nodeset & 4) // Faces if (nodeset & 4) // Faces
{ {
int face = mesh->GetTopology().GetSurfaceElementFace (elementnr+1); int face = mesh->GetTopology().GetFace (SurfaceElementIndex(elementnr))+1;
nodes[cnt++] = 2; nodes[cnt++] = 2;
nodes[cnt++] = face-1; nodes[cnt++] = face-1;
} }

View File

@ -1326,7 +1326,7 @@ int Ngx_Mesh::GetSurfaceElement_Face (int selnr, int * orient) const
const MeshTopology & topology = mesh->GetTopology(); const MeshTopology & topology = mesh->GetTopology();
if (orient) if (orient)
*orient = topology.GetSurfaceElementFaceOrientation (selnr+1); *orient = topology.GetSurfaceElementFaceOrientation (selnr+1);
return topology.GetSurfaceElementFace (selnr+1)-1; return topology.GetFace (SurfaceElementIndex(selnr));
} }
return -1; return -1;
} }

View File

@ -215,7 +215,7 @@ namespace netgen
// Check if the face is a surface element (boundary face) // Check if the face is a surface element (boundary face)
// if not, add the current volume element and the corresponding face into // if not, add the current volume element and the corresponding face into
// the owner list // the owner list
int surfelem = meshtopo.GetFace2SurfaceElement(absfacenr); int surfelem = meshtopo.GetFace2SurfaceElement1(absfacenr);
if(!surfelem) if(!surfelem)
{ {
// If it is a new face which has not been listed before, // If it is a new face which has not been listed before,

View File

@ -152,7 +152,7 @@ namespace netgen
NgArrayMem<int,9> nnums; // , ednums; NgArrayMem<int,9> nnums; // , ednums;
for (SurfaceElementIndex i_ : myrange) for (SurfaceElementIndex i_ : myrange)
{ {
int i = i_+1; // int i = i_+1;
const Element2d & el = mesh[i_]; // .SurfaceElement(i); const Element2d & el = mesh[i_]; // .SurfaceElement(i);
ELEMENT_TYPE typ = el.GetType(); ELEMENT_TYPE typ = el.GetType();
@ -160,7 +160,7 @@ namespace netgen
auto ednums = top.GetEdges (i_); auto ednums = top.GetEdges (i_);
// cout << "ednums = " << ednums << endl; // cout << "ednums = " << ednums << endl;
int fanum = top.GetSurfaceElementFace (i); int fanum = top.GetFace(i_)+1;
int elnv = top.GetNVertices (typ); int elnv = top.GetNVertices (typ);
int elned = ednums.Size(); int elned = ednums.Size();

View File

@ -1278,7 +1278,7 @@ namespace netgen
with MPI and an interior surface element between volume elements assigned to different with MPI and an interior surface element between volume elements assigned to different
procs, only one of them has the surf-el procs, only one of them has the surf-el
**/ **/
SurfaceElementIndex sei = top.GetFace2SurfaceElement (f+1)-1; SurfaceElementIndex sei = top.GetFace2SurfaceElement(f);
if (sei != SurfaceElementIndex(-1)) { if (sei != SurfaceElementIndex(-1)) {
PointGeomInfo gi = mesh[sei].GeomInfoPi(1); PointGeomInfo gi = mesh[sei].GeomInfoPi(1);
// use improved initial guess // use improved initial guess
@ -1680,7 +1680,7 @@ namespace netgen
*/ */
info.SetEdges (top.GetEdges(SurfaceElementIndex(elnr))); info.SetEdges (top.GetEdges(SurfaceElementIndex(elnr)));
info.facenr = top.GetSurfaceElementFace (elnr+1)-1; info.facenr = top.GetFace(elnr);
for (int i = 0; i < info.edgenrs.Size(); i++) for (int i = 0; i < info.edgenrs.Size(); i++)
info.ndof += edgecoeffsindex[info.edgenrs[i]+1] - edgecoeffsindex[info.edgenrs[i]]; info.ndof += edgecoeffsindex[info.edgenrs[i]+1] - edgecoeffsindex[info.edgenrs[i]];
info.ndof += facecoeffsindex[info.facenr+1] - facecoeffsindex[info.facenr]; info.ndof += facecoeffsindex[info.facenr+1] - facecoeffsindex[info.facenr];
@ -1763,7 +1763,7 @@ namespace netgen
info.edgenrs[i]--; info.edgenrs[i]--;
*/ */
info.SetEdges(top.GetEdges(SurfaceElementIndex(elnr))); info.SetEdges(top.GetEdges(SurfaceElementIndex(elnr)));
info.facenr = top.GetSurfaceElementFace (elnr+1)-1; info.facenr = top.GetFace(elnr);
bool firsttry = true; bool firsttry = true;
@ -4211,7 +4211,7 @@ namespace netgen
info.edgenrs[i]--; info.edgenrs[i]--;
*/ */
info.SetEdges(top.GetEdges(elnr)); info.SetEdges(top.GetEdges(elnr));
info.facenr = top.GetSurfaceElementFace (elnr+1)-1; info.facenr = top.GetFace (elnr);
bool firsttry = true; bool firsttry = true;

View File

@ -99,7 +99,7 @@ namespace netgen
//(*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]+1); faces[i] = topology.GetFace2SurfaceElement(faces[i])+1;
//(*testout) << "surfel " << faces << endl; //(*testout) << "surfel " << faces << endl;

View File

@ -1228,8 +1228,8 @@ namespace netgen
face2surfel.SetSize (nfa); face2surfel.SetSize (nfa);
face2surfel = 0; face2surfel = 0;
for (int i = 1; i <= nse; i++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
face2surfel[GetSurfaceElementFace(i)-1] = i; face2surfel[GetFace(sei)] = sei;
/* /*
cout << "build table complete" << endl; cout << "build table complete" << endl;
@ -1243,7 +1243,8 @@ namespace netgen
surf2volelement.SetSize (nse); surf2volelement.SetSize (nse);
surf2volelement = INDEX_2(0,0); // surf2volelement = INDEX_2(0,0);
surf2volelement = { ElementIndex::INVALID, ElementIndex::INVALID };
(*tracer) ("Topology::Update build surf2vol", false); (*tracer) ("Topology::Update build surf2vol", false);
// for (int i = 0; i < ne; i++) // for (int i = 0; i < ne; i++)
@ -1252,13 +1253,12 @@ namespace netgen
for (int j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
{ {
// int fnum = (faces.Get(i)[j]+7) / 8; // int fnum = (faces.Get(i)[j]+7) / 8;
int fnum = faces[i][j]+1; int fnum = faces[i][j];
if (fnum > 0 && face2surfel[fnum-1]) if (fnum >= 0 && face2surfel[fnum].IsValid())
{ {
int sel = face2surfel[fnum-1]; SurfaceElementIndex sel = face2surfel[fnum];
surf2volelement[sel-1][1] = surf2volelement[sel][1] = surf2volelement[sel][0];
surf2volelement[sel-1][0]; surf2volelement[sel][0] = i; // +1;
surf2volelement[sel-1][0] = i+1;
} }
}}); }});
(*tracer) ("Topology::Update build surf2vol", true); (*tracer) ("Topology::Update build surf2vol", true);
@ -1296,8 +1296,12 @@ namespace netgen
AsAtomic(face_els[f])++; AsAtomic(face_els[f])++;
}, TasksPerThread(4)); }, TasksPerThread(4));
/*
for (int i = 1; i <= nse; i++) for (int i = 1; i <= nse; i++)
face_surfels[GetSurfaceElementFace (i)-1]++; face_surfels[GetSurfaceElementFace1 (i)-1]++;
*/
for (auto sei : Range(mesh->SurfaceElements()))
face_surfels[GetFace(sei)]++;
(*tracer) ("Topology::Update count face_els", true); (*tracer) ("Topology::Update count face_els", true);
@ -2019,12 +2023,12 @@ namespace netgen
*/ */
/*
int MeshTopology :: GetSurfaceElementFace (int elnr) const int MeshTopology :: GetSurfaceElementFace (int elnr) const
{ {
return surffaces[elnr-1]+1; return surffaces[elnr-1]+1;
} }
/*
int MeshTopology :: GetFace (SurfaceElementIndex elnr) const int MeshTopology :: GetFace (SurfaceElementIndex elnr) const
{ {
return surffaces[elnr].fnr; return surffaces[elnr].fnr;
@ -2400,10 +2404,11 @@ namespace netgen
} }
} }
int surfel = GetFace2SurfaceElement(fnr); SurfaceElementIndex surfel = GetFace2SurfaceElement(fnr);
if (surfel != 0) if (!surfel.IsValid())
{ {
GetSurfaceElementEdges (surfel, fedges); // GetSurfaceElementEdges (surfel, fedges);
GetEdges (surfel, fedges);
return; return;
} }
} }

View File

@ -16,7 +16,6 @@
namespace netgen namespace netgen
{ {
typedef int T_EDGE; typedef int T_EDGE;
typedef int T_FACE; typedef int T_FACE;
@ -40,8 +39,9 @@ class MeshTopology
Array<T_EDGE> segedges; Array<T_EDGE> segedges;
Array<T_FACE> surffaces; Array<T_FACE> surffaces;
Array<INDEX_2, SurfaceElementIndex> surf2volelement; // Array<INDEX_2, SurfaceElementIndex> surf2volelement;
Array<int> face2surfel; Array<std::array<ElementIndex,2>, SurfaceElementIndex> surf2volelement;
Array<SurfaceElementIndex> face2surfel;
Array<SegmentIndex> edge2segment; Array<SegmentIndex> edge2segment;
Table<ElementIndex, PointIndex> vert2element; Table<ElementIndex, PointIndex> vert2element;
@ -147,7 +147,8 @@ public:
[[deprecated("use GetEdges (SurfaceElementIndex) -> FlatArray")]] [[deprecated("use GetEdges (SurfaceElementIndex) -> FlatArray")]]
void GetSurfaceElementEdges (int elnr, NgArray<int> & edges) const; void GetSurfaceElementEdges (int elnr, NgArray<int> & edges) const;
int GetSurfaceElementFace (int elnr) const; [[deprecated("use GetFace(SurfaceElementIndex")]]
int GetSurfaceElementFace1 (int elnr) const { return surffaces[elnr-1]+1; }
[[deprecated("orientation is outdated")]] [[deprecated("orientation is outdated")]]
void GetSurfaceElementEdgeOrientations (int elnr, NgArray<int> & eorient) const; void GetSurfaceElementEdgeOrientations (int elnr, NgArray<int> & eorient) const;
// [[deprecated("orientation is outdated")]] // [[deprecated("orientation is outdated")]]
@ -176,18 +177,22 @@ public:
void GetSurface2VolumeElement (int selnr, int & elnr1, int & elnr2) const void GetSurface2VolumeElement (int selnr, int & elnr1, int & elnr2) const
{ {
elnr1 = surf2volelement[selnr-1][0]; elnr1 = surf2volelement[selnr-1][0]+1;
elnr2 = surf2volelement[selnr-1][1]; elnr2 = surf2volelement[selnr-1][1]+1;
} }
std::array<ElementIndex,2> GetSurface2VolumeElement (SurfaceElementIndex sei) std::array<ElementIndex,2> GetSurface2VolumeElement (SurfaceElementIndex sei)
{ {
return surf2volelement[sei];
/*
return { ElementIndex( surf2volelement[sei][0] - 1), return { ElementIndex( surf2volelement[sei][0] - 1),
ElementIndex( surf2volelement[sei][1] - 1) }; ElementIndex( surf2volelement[sei][1] - 1) };
*/
} }
[[deprecated("use GetSurfaceEleement -> SurfaceElementIndex")]]
int GetFace2SurfaceElement (int fnr) const { return face2surfel[fnr-1]; } int GetFace2SurfaceElement1 (int fnr) const { return face2surfel[fnr-1]+1; }
SurfaceElementIndex GetFace2SurfaceElement (int fnr) const { return face2surfel[fnr]; }
SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; } SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; }