From bee6c6bf906fb2fb6682e8d21fd0534b3f8a2407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 22 Mar 2016 07:22:56 +0100 Subject: [PATCH] consistent vertex->elements (1D/2D/3D) tables --- libsrc/include/nginterface_v2.hpp | 21 +++++++++ libsrc/interface/nginterface.cpp | 18 +++++--- libsrc/interface/nginterface_v2.cpp | 34 +++++++++++++++ libsrc/meshing/boundarylayer.cpp | 6 +-- libsrc/meshing/topology.cpp | 66 ++++++++++++++++------------- libsrc/meshing/topology.hpp | 13 +++--- 6 files changed, 114 insertions(+), 44 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 0a5faf61..cf6e4c6c 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -100,6 +100,27 @@ namespace netgen template class Ng_Node; + template <> + class Ng_Node<0> + { + class Ng_Elements + { + public: + int ne; + const int * ptr; + + int Size() const { return ne; } + int operator[] (int i) const { return ptr[i]; } + }; + + + public: + Ng_Elements elements; + }; + + + + template <> class Ng_Node<1> { diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 244dd814..2ed31f5f 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -1573,12 +1573,15 @@ int Ng_GetNVertexElements (int vnr) case 2: return mesh->GetTopology().GetVertexSurfaceElements(vnr).Size(); case 1: + return mesh->GetTopology().GetVertexSegments(vnr).Size(); + /* { int cnt = 0; for (SegmentIndex i = 0; i < mesh->GetNSeg(); i++) if ( ((*mesh)[i][0] == vnr) || ((*mesh)[i][1] == vnr) ) cnt++; return cnt; } + */ default: cerr << "error: mesh->GetDimension() gives " << mesh->GetDimension() << endl; @@ -1598,17 +1601,22 @@ void Ng_GetVertexElements (int vnr, int * els) } case 2: { - FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); - for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]; + FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; } case 1: { + FlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); + for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; + break; + /* int cnt = 0; for (SegmentIndex i = 0; i < mesh->GetNSeg(); i++) if ( ((*mesh)[i][0] == vnr) || ((*mesh)[i][1] == vnr) ) els[cnt++] = i+1; break; + */ } } } @@ -1894,11 +1902,11 @@ int Ng_GetVertex_SurfaceElements( int vnr, int* elems ) case 3: { const MeshTopology& topology = mesh->GetTopology(); - ArrayMem indexArray; + ArrayMem indexArray; topology.GetVertexSurfaceElements( vnr, indexArray ); for( int i=0; iGetTopology(); - ArrayMem indexArray; + ArrayMem indexArray; topology.GetVertexSurfaceElements( vnr, indexArray ); return indexArray.Size(); } diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index dc78cfa5..ee146afe 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -612,6 +612,40 @@ namespace netgen return mesh->GetTopology().GetNFaces(); } + template <> DLL_HEADER Ng_Node<0> Ngx_Mesh :: GetNode<0> (int vnr) const + { + Ng_Node<0> node; + vnr++; + switch (mesh->GetDimension()) + { + case 3: + { + FlatArray ia = mesh->GetTopology().GetVertexElements(vnr); + node.elements.ne = ia.Size(); + node.elements.ptr = (int*)&ia[0]; + break; + } + case 2: + { + FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + node.elements.ne = ia.Size(); + node.elements.ptr = (int*)&ia[0]; + break; + } + case 1: + { + FlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); + node.elements.ne = ia.Size(); + node.elements.ptr = (int*)&ia[0]; + break; + } + default: + ; + } + return node; + } + + template <> DLL_HEADER Ng_Node<1> Ngx_Mesh :: GetNode<1> (int nr) const { Ng_Node<1> node; diff --git a/libsrc/meshing/boundarylayer.cpp b/libsrc/meshing/boundarylayer.cpp index 643f0922..5749268c 100644 --- a/libsrc/meshing/boundarylayer.cpp +++ b/libsrc/meshing/boundarylayer.cpp @@ -323,9 +323,9 @@ namespace netgen // boundary layer list if(!surfid.Contains(mesh[sej].si)) { - int pnt_commelem = 0; - Array pnt1_elems; - Array pnt2_elems; + SurfaceElementIndex pnt_commelem = 0; + Array pnt1_elems; + Array pnt2_elems; meshtopo.GetVertexSurfaceElements(segpair_p1,pnt1_elems); diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index af026856..83cec174 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -126,28 +126,28 @@ namespace netgen cnt[el[j]]++; } - vert2surfelement = new TABLE (cnt); + vert2surfelement = new 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+1); + vert2surfelement->AddSave (el[j], sei); } cnt = 0; - for (int i = 1; i <= nseg; i++) + for (SegmentIndex si = 0; si < nseg; si++) { - const Segment & seg = mesh.LineSegment(i); + const Segment & seg = mesh.LineSegment(si); cnt[seg[0]]++; cnt[seg[1]]++; } - vert2segment = new TABLE (cnt); - for (int i = 1; i <= nseg; i++) + vert2segment = new TABLE (cnt); + for (SegmentIndex si = 0; si < nseg; si++) { - const Segment & seg = mesh.LineSegment(i); - vert2segment->AddSave (seg[0], i); - vert2segment->AddSave (seg[1], i); + const Segment & seg = mesh.LineSegment(si); + vert2segment->AddSave (seg[0], si); + vert2segment->AddSave (seg[1], si); } if (buildedges) @@ -243,7 +243,7 @@ namespace netgen for (int j = 0; j < (*vert2surfelement)[i].Size(); j++) { - int elnr = (*vert2surfelement)[i][j]; + SurfaceElementIndex elnr = (*vert2surfelement)[i][j]; const Element2d & el = mesh.SurfaceElement (elnr); int neledges = GetNEdges (el.GetType()); @@ -265,7 +265,7 @@ namespace netgen for (int j = 0; j < (*vert2segment)[i].Size(); j++) { - int elnr = (*vert2segment)[i][j]; + SegmentIndex elnr = (*vert2segment)[i][j]; const Segment & el = mesh.LineSegment (elnr); INDEX_2 edge(el[0], el[1]); @@ -316,7 +316,7 @@ namespace netgen for (int j = 0; j < (*vert2surfelement)[i].Size(); j++) { - int elnr = (*vert2surfelement)[i][j]; + SurfaceElementIndex elnr = (*vert2surfelement)[i][j]; const Element2d & el = mesh.SurfaceElement (elnr); int neledges = GetNEdges (el.GetType()); @@ -334,15 +334,14 @@ namespace netgen int edgenum = edgenr[edge.I2()]; // if (edgedir) edgenum *= -1; // surfedges.Elem(elnr)[k] = edgenum; - surfedges.Elem(elnr)[k].nr = edgenum-1; - surfedges.Elem(elnr)[k].orient = edgedir; - + surfedges[elnr][k].nr = edgenum-1; + surfedges[elnr][k].orient = edgedir; } } for (int j = 0; j < (*vert2segment)[i].Size(); j++) { - int elnr = (*vert2segment)[i][j]; + SegmentIndex elnr = (*vert2segment)[i][j]; const Segment & el = mesh.LineSegment (elnr); INDEX_2 edge(el[0], el[1]); @@ -357,8 +356,8 @@ namespace netgen if (edgedir) edgenum *= -1; segedges.Elem(elnr) = edgenum; */ - segedges.Elem(elnr).nr = edgenum-1; - segedges.Elem(elnr).orient = edgedir; + segedges[elnr].nr = edgenum-1; + segedges[elnr].orient = edgedir; } } } @@ -875,7 +874,7 @@ namespace netgen for (int j = 0; j < (*vert2surfelement)[v].Size(); j++) { - int elnr = (*vert2surfelement)[v][j]; + SurfaceElementIndex elnr = (*vert2surfelement)[v][j]; // cout << "surfelnr = " << elnr << endl; const Element2d & el = mesh.SurfaceElement (elnr); @@ -926,8 +925,8 @@ namespace netgen } // surffaces.Elem(elnr) = 8*(facenum-1)+facedir+1; - surffaces.Elem(elnr).fnr = facenum-1; - surffaces.Elem(elnr).forient = facedir; + surffaces[elnr].fnr = facenum-1; + surffaces[elnr].forient = facedir; } else @@ -979,8 +978,8 @@ namespace netgen } // surffaces.Elem(elnr) = 8*(facenum-1)+facedir+1; - surffaces.Elem(elnr).fnr = facenum-1; - surffaces.Elem(elnr).forient = facedir; + surffaces[elnr].fnr = facenum-1; + surffaces[elnr].forient = facedir; } } @@ -1673,16 +1672,23 @@ namespace netgen return FlatArray (0,0); } - FlatArray MeshTopology :: GetVertexSurfaceElements (int vnr) const + FlatArray MeshTopology :: GetVertexSurfaceElements (int vnr) const { if (vert2surfelement) return (*vert2surfelement)[vnr]; - return FlatArray (0,0); + return FlatArray (0,0); + } + + FlatArray MeshTopology :: GetVertexSegments (int vnr) const + { + if (vert2segment) + return (*vert2segment)[vnr]; + return FlatArray (0,0); } void MeshTopology :: GetVertexSurfaceElements( int vnr, - Array& elements ) const + Array & elements ) const { if (vert2surfelement) { @@ -1719,7 +1725,7 @@ namespace netgen void MeshTopology :: - GetSegmentVolumeElements ( int segnr, Array & volels ) const + GetSegmentVolumeElements ( int segnr, Array & volels ) const { int v1, v2; GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); @@ -1730,15 +1736,15 @@ namespace netgen for ( int eli1=1; eli1 <= volels1.Size(); eli1++) if ( volels2.Contains( volels1.Elem(eli1) ) ) - volels.Append ( volels1.Elem(eli1)+1 ); + volels.Append ( volels1.Elem(eli1) ); } void MeshTopology :: - GetSegmentSurfaceElements (int segnr, Array & els) const + GetSegmentSurfaceElements (int segnr, Array & els) const { int v1, v2; GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); - Array els1, els2; + Array els1, els2; GetVertexSurfaceElements ( v1, els1 ); GetVertexSurfaceElements ( v2, els2 ); els.SetSize(0); diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index f6e82541..dd63bb3c 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -44,8 +44,8 @@ class MeshTopology Array surf2volelement; Array face2surfel; TABLE *vert2element; - TABLE *vert2surfelement; - TABLE *vert2segment; + TABLE *vert2surfelement; + TABLE *vert2segment; int timestamp; public: int GetNSurfedges() const {return surfedges.Size();} @@ -135,14 +135,15 @@ public: void GetVertexElements (int vnr, Array & elements) const; FlatArray GetVertexElements (int vnr) const; - void GetVertexSurfaceElements( int vnr, Array& elements ) const; - FlatArray GetVertexSurfaceElements (int vnr) const; + void GetVertexSurfaceElements( int vnr, Array& elements ) const; + FlatArray GetVertexSurfaceElements (int vnr) const; + FlatArray GetVertexSegments (int vnr) const; int GetVerticesEdge ( int v1, int v2) const; - void GetSegmentVolumeElements ( int segnr, Array & els ) const; - void GetSegmentSurfaceElements ( int segnr, Array & els ) const; + void GetSegmentVolumeElements ( int segnr, Array & els ) const; + void GetSegmentSurfaceElements ( int segnr, Array & els ) const; };