replace NgArray and TABLE with Array and Table

This commit is contained in:
Matthias Hochsteger 2021-05-10 11:18:47 +02:00
parent 4b53c63fba
commit c8406d3b10
6 changed files with 37 additions and 137 deletions

View File

@ -256,18 +256,18 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<0> Ngx_Mesh :: GetNode<0> (int v
{ {
case 3: case 3:
{ {
NgFlatArray<ElementIndex> ia = mesh->GetTopology().GetVertexElements(vnr); auto ia = mesh->GetTopology().GetVertexElements(vnr);
node.elements.ne = ia.Size(); node.elements.ne = ia.Size();
node.elements.ptr = (int*)&ia[0]; node.elements.ptr = (int*)&ia[0];
NgFlatArray<SurfaceElementIndex> bia = mesh->GetTopology().GetVertexSurfaceElements(vnr); auto bia = mesh->GetTopology().GetVertexSurfaceElements(vnr);
node.bnd_elements.ne = bia.Size(); node.bnd_elements.ne = bia.Size();
node.bnd_elements.ptr = (int*)&bia[0]; node.bnd_elements.ptr = (int*)&bia[0];
break; break;
} }
case 2: case 2:
{ {
NgFlatArray<SurfaceElementIndex> ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); auto ia = mesh->GetTopology().GetVertexSurfaceElements(vnr);
node.elements.ne = ia.Size(); node.elements.ne = ia.Size();
node.elements.ptr = (int*)&ia[0]; node.elements.ptr = (int*)&ia[0];

View File

@ -1641,13 +1641,13 @@ void Ng_GetVertexElements (int vnr, int * els)
{ {
case 3: case 3:
{ {
NgFlatArray<ElementIndex> ia = mesh->GetTopology().GetVertexElements(vnr); auto ia = mesh->GetTopology().GetVertexElements(vnr);
for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1;
break; break;
} }
case 2: case 2:
{ {
NgFlatArray<SurfaceElementIndex> ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); auto ia = mesh->GetTopology().GetVertexSurfaceElements(vnr);
for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1;
break; break;
} }
@ -1933,7 +1933,7 @@ int Ng_IsRunning()
int Ng_GetVertex_Elements( int vnr, int* elems ) int Ng_GetVertex_Elements( int vnr, int* elems )
{ {
const MeshTopology& topology = mesh->GetTopology(); const MeshTopology& topology = mesh->GetTopology();
NgArrayMem<ElementIndex,4> indexArray; ArrayMem<ElementIndex,4> indexArray;
topology.GetVertexElements( vnr, indexArray ); topology.GetVertexElements( vnr, indexArray );
for( int i=0; i<indexArray.Size(); i++ ) for( int i=0; i<indexArray.Size(); i++ )
@ -1950,7 +1950,7 @@ int Ng_GetVertex_SurfaceElements( int vnr, int* elems )
case 3: case 3:
{ {
const MeshTopology& topology = mesh->GetTopology(); const MeshTopology& topology = mesh->GetTopology();
NgArrayMem<SurfaceElementIndex,4> indexArray; ArrayMem<SurfaceElementIndex,4> indexArray;
topology.GetVertexSurfaceElements( vnr, indexArray ); topology.GetVertexSurfaceElements( vnr, indexArray );
for( int i=0; i<indexArray.Size(); i++ ) for( int i=0; i<indexArray.Size(); i++ )
@ -1982,7 +1982,7 @@ int Ng_GetVertex_SurfaceElements( int vnr, int* elems )
int Ng_GetVertex_NElements( int vnr ) int Ng_GetVertex_NElements( int vnr )
{ {
const MeshTopology& topology = mesh->GetTopology(); const MeshTopology& topology = mesh->GetTopology();
NgArrayMem<ElementIndex,4> indexArray; ArrayMem<ElementIndex,4> indexArray;
topology.GetVertexElements( vnr, indexArray ); topology.GetVertexElements( vnr, indexArray );
return indexArray.Size(); return indexArray.Size();
@ -1996,7 +1996,7 @@ int Ng_GetVertex_NSurfaceElements( int vnr )
case 3: case 3:
{ {
const MeshTopology& topology = mesh->GetTopology(); const MeshTopology& topology = mesh->GetTopology();
NgArrayMem<SurfaceElementIndex,4> indexArray; ArrayMem<SurfaceElementIndex,4> indexArray;
topology.GetVertexSurfaceElements( vnr, indexArray ); topology.GetVertexSurfaceElements( vnr, indexArray );
return indexArray.Size(); return indexArray.Size();
} }

View File

@ -1289,9 +1289,7 @@ namespace netgen
if(mapto[pi].Size() == 0) if(mapto[pi].Size() == 0)
continue; continue;
auto pnew = mapto[pi].Last(); auto pnew = mapto[pi].Last();
NgArray<SurfaceElementIndex> old_els; for(auto old_sei : meshtopo.GetVertexSurfaceElements( pi ))
meshtopo.GetVertexSurfaceElements( pi, old_els);
for(auto old_sei : old_els)
{ {
if(mesh[old_sei].GetIndex() == domain) if(mesh[old_sei].GetIndex() == domain)
{ {

View File

@ -628,7 +628,7 @@ namespace netgen
bool has_ided_sels = false; bool has_ided_sels = false;
if(GetNE() && has_periodic) //we can only have identified surf-els if we have vol-els (right?) if(GetNE() && has_periodic) //we can only have identified surf-els if we have vol-els (right?)
{ {
NgArray<SurfaceElementIndex, 0> os1, os2; Array<SurfaceElementIndex> os1, os2;
for(SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) for(SurfaceElementIndex sei = 0; sei < GetNSE(); sei++)
{ {
if(ided_sel[sei]!=-1) continue; if(ided_sel[sei]!=-1) continue;
@ -647,7 +647,7 @@ namespace netgen
os2.Append(GetTopology().GetVertexSurfaceElements(ided2[l])); os2.Append(GetTopology().GetVertexSurfaceElements(ided2[l]));
for (int m = 0; m<os1.Size(); m++) { for (int m = 0; m<os1.Size(); m++) {
if(!os2.Contains(os1[m])) { if(!os2.Contains(os1[m])) {
os1.Delete(m); os1.DeleteElement(m);
m--; m--;
} }
} }

View File

@ -404,94 +404,9 @@ namespace netgen
vertex to surface element vertex to surface element
vertex to segment vertex to segment
*/ */
cnt = 0;
/*
for (ElementIndex ei = 0; ei < ne; ei++)
{
const Element & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++)
cnt[el[j]]++;
}
*/
ParallelForRange
(ne, [&] (IntRange r)
{
for (ElementIndex ei : r)
{
const Element & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++)
AsAtomic(cnt[el[j]])++;
}
});
vert2element = TABLE<ElementIndex,PointIndex::BASE> (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]])++;
}
});
vert2element = mesh->CreatePoint2ElementTable();
vert2surfelement = mesh->CreatePoint2SurfaceElementTable(0);
vert2surfelement = TABLE<SurfaceElementIndex,PointIndex::BASE> (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 !!!
*/
cnt = 0; cnt = 0;
for (SegmentIndex si = 0; si < nseg; si++) for (SegmentIndex si = 0; si < nseg; si++)
@ -1606,7 +1521,7 @@ namespace netgen
(*testout) << (*mesh)[(PointIndex)face2vert[i].I(j+1)] << " "; (*testout) << (*mesh)[(PointIndex)face2vert[i].I(j+1)] << " ";
(*testout) << endl; (*testout) << endl;
NgFlatArray<ElementIndex> vertels = GetVertexElements (face2vert[i].I(1)); FlatArray<ElementIndex> vertels = GetVertexElements (face2vert[i].I(1));
for (int k = 0; k < vertels.Size(); k++) for (int k = 0; k < vertels.Size(); k++)
{ {
int elfaces[10], orient[10]; int elfaces[10], orient[10];
@ -2522,7 +2437,7 @@ namespace netgen
// GetVertexElements (pi[0], els); // GetVertexElements (pi[0], els);
NgFlatArray<ElementIndex> els = GetVertexElements (pi[0]); FlatArray<ElementIndex> els = GetVertexElements (pi[0]);
// 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++)
@ -2614,15 +2529,10 @@ namespace netgen
*/ */
void MeshTopology :: GetVertexElements (int vnr, NgArray<ElementIndex> & elements) const void MeshTopology :: GetVertexElements (int vnr, Array<ElementIndex> & elements) const
{ {
if (vert2element.Size()) if (vert2element.Size())
{ elements = vert2element[vnr];
int ne = vert2element.EntrySize(vnr);
elements.SetSize(ne);
for (int i = 1; i <= ne; i++)
elements.Elem(i) = vert2element.Get(vnr, i);
}
} }
/* /*
@ -2649,22 +2559,16 @@ namespace netgen
*/ */
void MeshTopology :: GetVertexSurfaceElements( int vnr, void MeshTopology :: GetVertexSurfaceElements( int vnr,
NgArray<SurfaceElementIndex> & elements ) const Array<SurfaceElementIndex> & elements ) const
{ {
if (vert2surfelement.Size()) if (vert2surfelement.Size())
{ elements = vert2surfelement[vnr];
int i;
int ne = vert2surfelement.EntrySize(vnr);
elements.SetSize(ne);
for (i = 1; i <= ne; i++)
elements.Elem(i) = vert2surfelement.Get(vnr, i);
}
} }
int MeshTopology :: GetVerticesEdge ( int v1, int v2 ) const int MeshTopology :: GetVerticesEdge ( int v1, int v2 ) const
{ {
NgArray<ElementIndex> elements_v1; Array<ElementIndex> elements_v1;
NgArray<int> elementedges; NgArray<int> elementedges;
GetVertexElements ( v1, elements_v1); GetVertexElements ( v1, elements_v1);
int edv1, edv2; int edv1, edv2;
@ -2690,14 +2594,13 @@ namespace netgen
{ {
int v1, v2; int v1, v2;
GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 );
NgArray<ElementIndex> volels1, volels2; auto volels1 = GetVertexElements ( v1 );
GetVertexElements ( v1, volels1 ); auto volels2 = GetVertexElements ( v2 );
GetVertexElements ( v2, volels2 );
volels.SetSize(0); volels.SetSize(0);
for ( int eli1=1; eli1 <= volels1.Size(); eli1++) for ( auto volel1 : volels1 )
if ( volels2.Contains( volels1.Elem(eli1) ) ) if ( volels2.Contains( volel1 ) )
volels.Append ( volels1.Elem(eli1) ); volels.Append ( volel1 );
} }
void MeshTopology :: void MeshTopology ::
@ -2705,14 +2608,13 @@ namespace netgen
{ {
int v1, v2; int v1, v2;
GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 );
NgArray<SurfaceElementIndex> els1, els2; auto els1 = GetVertexSurfaceElements ( v1 );
GetVertexSurfaceElements ( v1, els1 ); auto els2 = GetVertexSurfaceElements ( v2 );
GetVertexSurfaceElements ( v2, els2 );
els.SetSize(0); els.SetSize(0);
for ( int eli1=1; eli1 <= els1.Size(); eli1++) for ( auto el1 : els1 )
if ( els2.Contains( els1.Elem(eli1) ) ) if ( els2.Contains( el1 ) )
els.Append ( els1.Elem(eli1) ); els.Append ( el1 );
} }

View File

@ -65,8 +65,8 @@ class MeshTopology
NgArray<INDEX_2> surf2volelement; NgArray<INDEX_2> surf2volelement;
NgArray<int> face2surfel; NgArray<int> face2surfel;
Array<SegmentIndex> edge2segment; Array<SegmentIndex> edge2segment;
TABLE<ElementIndex,PointIndex::BASE> vert2element; Table<ElementIndex, PointIndex> vert2element;
TABLE<SurfaceElementIndex,PointIndex::BASE> vert2surfelement; Table<SurfaceElementIndex, PointIndex> vert2surfelement;
TABLE<SegmentIndex,PointIndex::BASE> vert2segment; TABLE<SegmentIndex,PointIndex::BASE> vert2segment;
TABLE<int,PointIndex::BASE> vert2pointelement; TABLE<int,PointIndex::BASE> vert2pointelement;
int timestamp; int timestamp;
@ -175,12 +175,12 @@ public:
SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; } SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; }
void GetVertexElements (int vnr, NgArray<ElementIndex> & elements) const; void GetVertexElements (int vnr, Array<ElementIndex> & elements) const;
NgFlatArray<ElementIndex> GetVertexElements (int vnr) const FlatArray<ElementIndex> GetVertexElements (int vnr) const
{ return vert2element[vnr]; } { return vert2element[vnr]; }
void GetVertexSurfaceElements( int vnr, NgArray<SurfaceElementIndex>& elements ) const; void GetVertexSurfaceElements( int vnr, Array<SurfaceElementIndex>& elements ) const;
NgFlatArray<SurfaceElementIndex> GetVertexSurfaceElements(PointIndex vnr) const FlatArray<SurfaceElementIndex> GetVertexSurfaceElements(PointIndex vnr) const
{ return vert2surfelement[vnr]; } { return vert2surfelement[vnr]; }
NgFlatArray<SegmentIndex> GetVertexSegments (int vnr) const NgFlatArray<SegmentIndex> GetVertexSegments (int vnr) const