From c8406d3b1024ef42fa6408dbbce39737d8037e73 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 10 May 2021 11:18:47 +0200 Subject: [PATCH] replace NgArray and TABLE with Array and Table --- libsrc/include/nginterface_v2_impl.hpp | 6 +- libsrc/interface/nginterface.cpp | 12 +-- libsrc/meshing/boundarylayer.cpp | 4 +- libsrc/meshing/parallelmesh.cpp | 4 +- libsrc/meshing/topology.cpp | 136 ++++--------------------- libsrc/meshing/topology.hpp | 12 +-- 6 files changed, 37 insertions(+), 137 deletions(-) diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index cd9a6c4b..645eb080 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -256,18 +256,18 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<0> Ngx_Mesh :: GetNode<0> (int v { case 3: { - NgFlatArray ia = mesh->GetTopology().GetVertexElements(vnr); + auto ia = mesh->GetTopology().GetVertexElements(vnr); node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; - NgFlatArray bia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + auto bia = mesh->GetTopology().GetVertexSurfaceElements(vnr); node.bnd_elements.ne = bia.Size(); node.bnd_elements.ptr = (int*)&bia[0]; break; } case 2: { - NgFlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + auto ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index c6bdd3fc..5b329569 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -1641,13 +1641,13 @@ void Ng_GetVertexElements (int vnr, int * els) { case 3: { - NgFlatArray ia = mesh->GetTopology().GetVertexElements(vnr); + auto ia = mesh->GetTopology().GetVertexElements(vnr); for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; } case 2: { - NgFlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + auto ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; } @@ -1933,7 +1933,7 @@ int Ng_IsRunning() int Ng_GetVertex_Elements( int vnr, int* elems ) { const MeshTopology& topology = mesh->GetTopology(); - NgArrayMem indexArray; + ArrayMem indexArray; topology.GetVertexElements( vnr, indexArray ); for( int i=0; iGetTopology(); - NgArrayMem indexArray; + ArrayMem indexArray; topology.GetVertexSurfaceElements( vnr, indexArray ); for( int i=0; iGetTopology(); - NgArrayMem indexArray; + ArrayMem indexArray; topology.GetVertexElements( vnr, indexArray ); return indexArray.Size(); @@ -1996,7 +1996,7 @@ int Ng_GetVertex_NSurfaceElements( int vnr ) case 3: { const MeshTopology& topology = mesh->GetTopology(); - NgArrayMem indexArray; + ArrayMem indexArray; topology.GetVertexSurfaceElements( vnr, indexArray ); return indexArray.Size(); } diff --git a/libsrc/meshing/boundarylayer.cpp b/libsrc/meshing/boundarylayer.cpp index 3c4b3951..1b8071f5 100644 --- a/libsrc/meshing/boundarylayer.cpp +++ b/libsrc/meshing/boundarylayer.cpp @@ -1289,9 +1289,7 @@ namespace netgen if(mapto[pi].Size() == 0) continue; auto pnew = mapto[pi].Last(); - NgArray old_els; - meshtopo.GetVertexSurfaceElements( pi, old_els); - for(auto old_sei : old_els) + for(auto old_sei : meshtopo.GetVertexSurfaceElements( pi )) { if(mesh[old_sei].GetIndex() == domain) { diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index 76c8dabb..8295b842 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -628,7 +628,7 @@ namespace netgen bool has_ided_sels = false; if(GetNE() && has_periodic) //we can only have identified surf-els if we have vol-els (right?) { - NgArray os1, os2; + Array os1, os2; for(SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) { if(ided_sel[sei]!=-1) continue; @@ -647,7 +647,7 @@ namespace netgen os2.Append(GetTopology().GetVertexSurfaceElements(ided2[l])); for (int m = 0; m (cnt); - for (ElementIndex ei = 0; ei < ne; ei++) - { - const Element & el = (*mesh)[ei]; - for (int j = 0; j < el.GetNV(); j++) - vert2element.AddSave (el[j], ei); - } - - /* - ParallelForRange - (tm, ne, - [&] (size_t begin, size_t end) - { - for (ElementIndex ei = begin; ei < end; ei++) - { - const Element & el = (*mesh)[ei]; - for (int j = 0; j < el.GetNV(); j++) - vert2element.ParallelAdd (el[j], ei); - } - }); - requires sorting !!!! - */ - - cnt = 0; - /* - for (SurfaceElementIndex sei = 0; sei < nse; sei++) - { - const Element2d & el = (*mesh)[sei]; - for (int j = 0; j < el.GetNV(); j++) - cnt[el[j]]++; - } - */ - ParallelForRange - (nse, - [&] (IntRange r) - { - for (SurfaceElementIndex ei : r) - { - const Element2d & el = (*mesh)[ei]; - for (int j = 0; j < el.GetNV(); j++) - AsAtomic(cnt[el[j]])++; - } - }); - - - vert2surfelement = TABLE (cnt); - - for (SurfaceElementIndex sei = 0; sei < nse; sei++) - { - const Element2d & el = (*mesh)[sei]; - for (int j = 0; j < el.GetNV(); j++) - vert2surfelement.AddSave (el[j], sei); - } - /* - ParallelForRange - (tm, nse, - [&] (size_t begin, size_t end) - { - for (SurfaceElementIndex sei = begin; sei < end; sei++) - { - const Element2d & el = (*mesh)[sei]; - for (int j = 0; j < el.GetNV(); j++) - vert2surfelement.ParallelAdd (el[j], sei); - } - }); - requires sorting !!! - */ + vert2element = mesh->CreatePoint2ElementTable(); + vert2surfelement = mesh->CreatePoint2SurfaceElementTable(0); cnt = 0; for (SegmentIndex si = 0; si < nseg; si++) @@ -1606,7 +1521,7 @@ namespace netgen (*testout) << (*mesh)[(PointIndex)face2vert[i].I(j+1)] << " "; (*testout) << endl; - NgFlatArray vertels = GetVertexElements (face2vert[i].I(1)); + FlatArray vertels = GetVertexElements (face2vert[i].I(1)); for (int k = 0; k < vertels.Size(); k++) { int elfaces[10], orient[10]; @@ -2522,7 +2437,7 @@ namespace netgen // GetVertexElements (pi[0], els); - NgFlatArray els = GetVertexElements (pi[0]); + FlatArray els = GetVertexElements (pi[0]); // find one element having all vertices of the face for (int i = 0; i < els.Size(); i++) @@ -2614,15 +2529,10 @@ namespace netgen */ - void MeshTopology :: GetVertexElements (int vnr, NgArray & elements) const + void MeshTopology :: GetVertexElements (int vnr, Array & elements) const { if (vert2element.Size()) - { - int ne = vert2element.EntrySize(vnr); - elements.SetSize(ne); - for (int i = 1; i <= ne; i++) - elements.Elem(i) = vert2element.Get(vnr, i); - } + elements = vert2element[vnr]; } /* @@ -2649,22 +2559,16 @@ namespace netgen */ void MeshTopology :: GetVertexSurfaceElements( int vnr, - NgArray & elements ) const + Array & elements ) const { if (vert2surfelement.Size()) - { - int i; - int ne = vert2surfelement.EntrySize(vnr); - elements.SetSize(ne); - for (i = 1; i <= ne; i++) - elements.Elem(i) = vert2surfelement.Get(vnr, i); - } + elements = vert2surfelement[vnr]; } int MeshTopology :: GetVerticesEdge ( int v1, int v2 ) const { - NgArray elements_v1; + Array elements_v1; NgArray elementedges; GetVertexElements ( v1, elements_v1); int edv1, edv2; @@ -2690,14 +2594,13 @@ namespace netgen { int v1, v2; GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); - NgArray volels1, volels2; - GetVertexElements ( v1, volels1 ); - GetVertexElements ( v2, volels2 ); + auto volels1 = GetVertexElements ( v1 ); + auto volels2 = GetVertexElements ( v2 ); volels.SetSize(0); - for ( int eli1=1; eli1 <= volels1.Size(); eli1++) - if ( volels2.Contains( volels1.Elem(eli1) ) ) - volels.Append ( volels1.Elem(eli1) ); + for ( auto volel1 : volels1 ) + if ( volels2.Contains( volel1 ) ) + volels.Append ( volel1 ); } void MeshTopology :: @@ -2705,14 +2608,13 @@ namespace netgen { int v1, v2; GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); - NgArray els1, els2; - GetVertexSurfaceElements ( v1, els1 ); - GetVertexSurfaceElements ( v2, els2 ); + auto els1 = GetVertexSurfaceElements ( v1 ); + auto els2 = GetVertexSurfaceElements ( v2 ); els.SetSize(0); - for ( int eli1=1; eli1 <= els1.Size(); eli1++) - if ( els2.Contains( els1.Elem(eli1) ) ) - els.Append ( els1.Elem(eli1) ); + for ( auto el1 : els1 ) + if ( els2.Contains( el1 ) ) + els.Append ( el1 ); } diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index a9864a90..9ce2e47a 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -65,8 +65,8 @@ class MeshTopology NgArray surf2volelement; NgArray face2surfel; Array edge2segment; - TABLE vert2element; - TABLE vert2surfelement; + Table vert2element; + Table vert2surfelement; TABLE vert2segment; TABLE vert2pointelement; int timestamp; @@ -175,12 +175,12 @@ public: SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; } - void GetVertexElements (int vnr, NgArray & elements) const; - NgFlatArray GetVertexElements (int vnr) const + void GetVertexElements (int vnr, Array & elements) const; + FlatArray GetVertexElements (int vnr) const { return vert2element[vnr]; } - void GetVertexSurfaceElements( int vnr, NgArray& elements ) const; - NgFlatArray GetVertexSurfaceElements(PointIndex vnr) const + void GetVertexSurfaceElements( int vnr, Array& elements ) const; + FlatArray GetVertexSurfaceElements(PointIndex vnr) const { return vert2surfelement[vnr]; } NgFlatArray GetVertexSegments (int vnr) const