From 50398c18c4e4cab151d7baac7edca93ee99d9e11 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 6 Nov 2021 15:52:35 +0100 Subject: [PATCH] simplify edge/face-id types (just an int) --- libsrc/include/nginterface_v2.hpp | 10 +++-- libsrc/include/nginterface_v2_impl.hpp | 28 ++++++------- libsrc/meshing/improve3.hpp | 8 ++-- libsrc/meshing/meshclass.hpp | 11 +++--- libsrc/meshing/meshtype.hpp | 2 +- libsrc/meshing/python_mesh.cpp | 4 +- libsrc/meshing/smoothing3.cpp | 12 +++--- libsrc/meshing/topology.cpp | 54 +++++++++++++------------- libsrc/meshing/topology.hpp | 36 ++++++++++------- libsrc/occ/occgeom.cpp | 18 ++++----- 10 files changed, 97 insertions(+), 86 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 7b7507f5..6c70a9ef 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -41,7 +41,8 @@ namespace netgen // extern DLL_HEADER NgMPI_Comm ng_comm; static constexpr int POINTINDEX_BASE = 1; - + + /* struct T_EDGE2 { // int orient:1; @@ -54,6 +55,9 @@ namespace netgen // int nr:29; // 0-based int nr; // 0-based }; + */ + typedef int T_EDGE2; + typedef int T_FACE2; template class Ng_Buffer @@ -114,7 +118,7 @@ namespace netgen const T_EDGE2 * ptr; size_t Size() const { return num; } - int operator[] (size_t i) const { return ptr[i].nr; } + int operator[] (size_t i) const { return ptr[i]; } }; class Ng_Faces @@ -124,7 +128,7 @@ namespace netgen const T_FACE2 * ptr; size_t Size() const { return num; } - int operator[] (size_t i) const { return ptr[i].nr; } + int operator[] (size_t i) const { return ptr[i]; } }; class Ng_Facets diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 351a0d30..a7ef0748 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -28,8 +28,10 @@ NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (size_t nr) const template <> NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<2> (size_t nr) const { - int ind = (*mesh)[SurfaceElementIndex(nr)].GetIndex(); - return mesh->GetFaceDescriptor(ind).BCProperty(); + // int ind = (*mesh)[SurfaceElementIndex(nr)].GetIndex(); + // return mesh->GetFaceDescriptor(ind).BCProperty(); + const Element2d & el = (*mesh)[SurfaceElementIndex(nr)]; + return mesh->GetFaceDescriptor(el).BCProperty(); } template <> @@ -106,7 +108,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const ret.vertices.ptr = (int*)&(el[0]); ret.edges.num = 1; - ret.edges.ptr = (T_EDGE2*)mesh->GetTopology().GetSegmentElementEdgesPtr (nr); + ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr); ret.faces.num = 0; ret.faces.ptr = NULL; @@ -121,7 +123,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const { ret.facets.num = 1; ret.facets.base = 0; - ret.facets.ptr = (int*)ret.edges.ptr; + ret.facets.ptr = ret.edges.ptr; } else { @@ -139,12 +141,11 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const template <> NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const { - // const Element2d & el = mesh->SurfaceElement (SurfaceElementIndex (nr)); const Element2d & el = mesh->SurfaceElements()[nr]; Ng_Element ret; ret.type = NG_ELEMENT_TYPE(el.GetType()); - const FaceDescriptor & fd = mesh->GetFaceDescriptor(el.GetIndex()); + const FaceDescriptor & fd = mesh->GetFaceDescriptor(el); // .GetIndex()); ret.index = fd.BCProperty(); if (mesh->GetDimension() == 3) ret.mat = &fd.GetBCName(); @@ -157,22 +158,22 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const ret.vertices.ptr = (int*)&(el[0]); ret.edges.num = MeshTopology::GetNEdges (el.GetType()); - ret.edges.ptr = (T_EDGE2*)mesh->GetTopology().GetSurfaceElementEdgesPtr (nr); + ret.edges.ptr = mesh->GetTopology().GetSurfaceElementEdgesPtr (nr); ret.faces.num = MeshTopology::GetNFaces (el.GetType()); - ret.faces.ptr = (T_FACE2*)mesh->GetTopology().GetSurfaceElementFacesPtr (nr); + ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr); if (mesh->GetDimension() == 3) { ret.facets.num = ret.faces.num; ret.facets.base = 0; - ret.facets.ptr = (int*)ret.faces.ptr; + ret.facets.ptr = ret.faces.ptr; } else { ret.facets.num = ret.edges.num; ret.facets.base = 0; - ret.facets.ptr = (int*)ret.edges.ptr; + ret.facets.ptr = ret.edges.ptr; } ret.is_curved = el.IsCurved(); return ret; @@ -181,7 +182,6 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const template <> NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const { - // const Element & el = mesh->VolumeElement (ElementIndex (nr)); const Element & el = mesh->VolumeElements()[nr]; Ng_Element ret; @@ -195,14 +195,14 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const ret.vertices.ptr = (int*)&(el[0]); ret.edges.num = MeshTopology::GetNEdges (el.GetType()); - ret.edges.ptr = (T_EDGE2*)mesh->GetTopology().GetElementEdgesPtr (nr); + ret.edges.ptr = mesh->GetTopology().GetElementEdgesPtr (nr); ret.faces.num = MeshTopology::GetNFaces (el.GetType()); - ret.faces.ptr = (T_FACE2*)mesh->GetTopology().GetElementFacesPtr (nr); + ret.faces.ptr = mesh->GetTopology().GetElementFacesPtr (nr); ret.facets.num = ret.faces.num; ret.facets.base = 0; - ret.facets.ptr = (int*)ret.faces.ptr; + ret.facets.ptr = ret.faces.ptr; ret.is_curved = el.IsCurved(); return ret; diff --git a/libsrc/meshing/improve3.hpp b/libsrc/meshing/improve3.hpp index b518a910..3caa2a57 100644 --- a/libsrc/meshing/improve3.hpp +++ b/libsrc/meshing/improve3.hpp @@ -3,7 +3,7 @@ extern double CalcTotalBad (const Mesh::T_POINTS & points, - const Array & elements, + const Array & elements, const MeshingParameters & mp); @@ -54,7 +54,7 @@ public: double CalcTotalBad (const Mesh::T_POINTS & points, - const Array & elements) + const Array & elements) { return netgen::CalcTotalBad (points, elements, mp); } @@ -121,7 +121,7 @@ class JacobianPointFunction : public MinFunction { public: Mesh::T_POINTS & points; - const Array & elements; + const Array & elements; TABLE elementsonpoint; PointIndex actpind; @@ -130,7 +130,7 @@ public: public: JacobianPointFunction (Mesh::T_POINTS & apoints, - const Array & aelements); + const Array & aelements); virtual ~JacobianPointFunction () { ; } virtual void SetPointIndex (PointIndex aactpind); virtual double Func (const Vector & x) const; diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 1a6b9e80..8a2a8166 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -25,10 +25,8 @@ namespace netgen class Mesh { public: - typedef ::netgen::T_POINTS T_POINTS; - // typedef NgArray T_VOLELEMENTS; - // typedef NgArray T_SURFELEMENTS; - // typedef NgArray T_SURFELEMENTS; + // typedef Array T_POINTS; + typedef netgen::T_POINTS T_POINTS; private: /// point coordinates @@ -42,7 +40,7 @@ namespace netgen /// surface elements, 2d-inner elements Array surfelements; /// volume elements - Array volelements; + Array volelements; /// points will be fixed forever Array lockedpoints; @@ -711,6 +709,9 @@ namespace netgen int GetNFD () const { return facedecoding.Size(); } + const FaceDescriptor & GetFaceDescriptor (const Element2d & el) const + { return facedecoding[el.GetIndex()-1]; } + const FaceDescriptor & GetFaceDescriptor (int i) const { return facedecoding[i-1]; } // { return facedecoding.Get(i); } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index dde2e7fc..d211b700 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -245,7 +245,7 @@ namespace netgen constexpr ElementIndex (int ai) : i(ai) { ; } ElementIndex & operator= (const ElementIndex & ai) { i = ai.i; return *this; } ElementIndex & operator= (int ai) { i = ai; return *this; } - operator int () const { return i; } + constexpr operator int () const { return i; } ElementIndex operator++ (int) { return ElementIndex(i++); } ElementIndex operator-- (int) { return ElementIndex(i--); } ElementIndex & operator++ () { ++i; return *this; } diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 60debf52..0d2af562 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -602,7 +602,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) - ExportArray(m); + ExportArray(m); ExportArray(m); ExportArray(m); ExportArray(m); @@ -825,7 +825,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def_property("dim", &Mesh::GetDimension, &Mesh::SetDimension) .def("Elements3D", - static_cast&(Mesh::*)()> (&Mesh::VolumeElements), + static_cast&(Mesh::*)()> (&Mesh::VolumeElements), py::return_value_policy::reference) .def("Elements2D", diff --git a/libsrc/meshing/smoothing3.cpp b/libsrc/meshing/smoothing3.cpp index a5787cb1..99c18839 100644 --- a/libsrc/meshing/smoothing3.cpp +++ b/libsrc/meshing/smoothing3.cpp @@ -303,7 +303,7 @@ namespace netgen { public: Mesh::T_POINTS & points; - const Array & elements; + const Array & elements; Table &elementsonpoint; bool own_elementsonpoint; const MeshingParameters & mp; @@ -312,7 +312,7 @@ namespace netgen public: PointFunction (Mesh::T_POINTS & apoints, - const Array & aelements, + const Array & aelements, const MeshingParameters & amp); PointFunction (const PointFunction & pf); virtual ~PointFunction () { if(own_elementsonpoint) delete &elementsonpoint; } @@ -333,7 +333,7 @@ namespace netgen { } PointFunction :: PointFunction (Mesh::T_POINTS & apoints, - const Array & aelements, + const Array & aelements, const MeshingParameters & amp) : points(apoints), elements(aelements), elementsonpoint(* new Table()), own_elementsonpoint(true), mp(amp) { @@ -494,7 +494,7 @@ namespace netgen DenseMatrix m; public: CheapPointFunction (Mesh::T_POINTS & apoints, - const Array & aelements, + const Array & aelements, const MeshingParameters & amp); virtual void SetPointIndex (PointIndex aactpind); virtual double PointFunctionValue (const Point<3> & pp) const; @@ -503,7 +503,7 @@ namespace netgen CheapPointFunction :: CheapPointFunction (Mesh::T_POINTS & apoints, - const Array & aelements, + const Array & aelements, const MeshingParameters & amp) : PointFunction (apoints, aelements, amp) { @@ -990,7 +990,7 @@ int WrongOrientation (const Mesh::T_POINTS & points, const Element & el) JacobianPointFunction :: JacobianPointFunction (Mesh::T_POINTS & apoints, - const Array & aelements) + const Array & aelements) : points(apoints), elements(aelements), elementsonpoint(apoints.Size()) { for (int i = 0; i < elements.Size(); i++) diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index a54f6ec1..3b6e5583 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -462,12 +462,12 @@ namespace netgen ParallelFor (ne, [this](auto i) { for (auto & e : edges[i]) - e.nr = -1; + e = -1; }); ParallelFor (nse, [this](auto i) { for (auto & e : surfedges[i]) - e.nr = -1; + e = -1; }); @@ -621,15 +621,15 @@ namespace netgen switch (element_dim) { case 3: - edges[elnr][loc_edge].nr = edgenum; + edges[elnr][loc_edge] = edgenum; // edges[elnr][loc_edge].orient = edgedir; break; case 2: - surfedges[elnr][loc_edge].nr = edgenum; + surfedges[elnr][loc_edge] = edgenum; // surfedges[elnr][loc_edge].orient = edgedir; break; case 1: - segedges[elnr].nr = edgenum; + segedges[elnr] = edgenum; edge2segment[edgenum] = elnr; // segedges[elnr].orient = edgedir; break; @@ -992,7 +992,7 @@ namespace netgen for (int elnr = 0; elnr < ne; elnr++) for (int j = 0; j < 6; j++) - faces[elnr][j].fnr = -1; + faces[elnr][j] = -1; int max_face_on_vertex = 0; @@ -1158,12 +1158,12 @@ namespace netgen int facenum = vert2face.Get(face); if (volume) { - faces[elnr][j].fnr = facenum; + faces[elnr][j] = facenum; // faces[elnr][j].forient = facedir; } else { - surffaces[elnr].fnr = facenum; + surffaces[elnr] = facenum; // surffaces[elnr].forient = facedir; } }); @@ -1454,7 +1454,7 @@ namespace netgen for (int j = 0; j < 6; j++) { // int fnum = (faces.Get(i)[j]+7) / 8; - int fnum = faces[i][j].fnr+1; + int fnum = faces[i][j]+1; if (fnum > 0 && face2surfel.Elem(fnum)) { int sel = face2surfel.Elem(fnum); @@ -2005,7 +2005,7 @@ namespace netgen int ned = GetNEdges (mesh->VolumeElement(elnr).GetType()); eledges.SetSize (ned); for (int i = 0; i < ned; i++) - eledges[i] = edges.Get(elnr)[i].nr+1; + eledges[i] = edges.Get(elnr)[i]+1; // eledges[i] = abs (edges.Get(elnr)[i]); } void MeshTopology :: GetElementFaces (int elnr, NgArray & elfaces, bool withorientation) const @@ -2014,7 +2014,7 @@ namespace netgen elfaces.SetSize (nfa); for (auto i : Range(nfa)) - elfaces[i] = faces.Get(elnr)[i].fnr+1; + elfaces[i] = faces.Get(elnr)[i]+1; if(withorientation) { @@ -2072,8 +2072,8 @@ namespace netgen eledges[i] = abs (edges.Get(elnr)[i]); orient[i] = (edges.Get(elnr)[i] > 0 ) ? 1 : -1; */ - if (edges.Get(elnr)[i].nr == -1) return i; - eledges[i] = edges.Get(elnr)[i].nr+1; + if (edges.Get(elnr)[i] == -1) return i; + eledges[i] = edges.Get(elnr)[i]+1; // orient[i] = edges.Get(elnr)[i].orient ? -1 : 1; orient[i] = GetElementEdgeOrientation(elnr, i) ? -1 : 1; } @@ -2084,8 +2084,8 @@ namespace netgen { // if (!edges.Get(elnr)[i]) return i; // eledges[i] = abs (edges.Get(elnr)[i]); - if (edges.Get(elnr)[i].nr == -1) return i; - eledges[i] = edges.Get(elnr)[i].nr+1; + if (edges.Get(elnr)[i] == -1) return i; + eledges[i] = edges.Get(elnr)[i]+1; } } @@ -2128,8 +2128,8 @@ namespace netgen elfaces[i] = (faces.Get(elnr)[i]-1) / 8 + 1; orient[i] = (faces.Get(elnr)[i]-1) % 8; */ - if (faces.Get(elnr)[i].fnr == -1) return i; - elfaces[i] = faces.Get(elnr)[i].fnr+1; + if (faces.Get(elnr)[i] == -1) return i; + elfaces[i] = faces.Get(elnr)[i]+1; // orient[i] = faces.Get(elnr)[i].forient; orient[i] = GetElementFaceOrientation (elnr, i); } @@ -2140,8 +2140,8 @@ namespace netgen { // if (!faces.Get(elnr)[i]) return i; // elfaces[i] = (faces.Get(elnr)[i]-1) / 8 + 1; - if (faces.Get(elnr)[i].fnr == -1) return i; - elfaces[i] = faces.Get(elnr)[i].fnr+1; + if (faces.Get(elnr)[i] == -1) return i; + elfaces[i] = faces.Get(elnr)[i]+1; } } return 6; @@ -2153,7 +2153,7 @@ namespace netgen eledges.SetSize (ned); for (int i = 0; i < ned; i++) // eledges[i] = abs (surfedges.Get(elnr)[i]); - eledges[i] = surfedges.Get(elnr)[i].nr+1; + eledges[i] = surfedges.Get(elnr)[i]+1; } void MeshTopology :: GetEdges (SurfaceElementIndex elnr, NgArray & eledges) const @@ -2162,12 +2162,12 @@ namespace netgen eledges.SetSize (ned); for (int i = 0; i < ned; i++) // eledges[i] = abs (surfedges[elnr][i])-1; - eledges[i] = surfedges[elnr][i].nr; + eledges[i] = surfedges[elnr][i]; } int MeshTopology :: GetSurfaceElementFace (int elnr) const { - return surffaces.Get(elnr).fnr+1; + return surffaces.Get(elnr)+1; } /* @@ -2210,8 +2210,8 @@ namespace netgen eledges[i] = abs (surfedges.Get(elnr)[i]); orient[i] = (surfedges.Get(elnr)[i] > 0 ) ? 1 : -1; */ - if (surfedges.Get(elnr)[i].nr == -1) return i; - eledges[i] = surfedges.Get(elnr)[i].nr+1; + if (surfedges.Get(elnr)[i] == -1) return i; + eledges[i] = surfedges.Get(elnr)[i]+1; // orient[i] = (surfedges.Get(elnr)[i].orient) ? -1 : 1; orient[i] = GetSurfaceElementEdgeOrientation(elnr, i) ? -1 : 1; @@ -2225,8 +2225,8 @@ namespace netgen if (!surfedges.Get(elnr)[i]) return i; eledges[i] = abs (surfedges.Get(elnr)[i]); */ - if (surfedges.Get(elnr)[i].nr == -1) return i; - eledges[i] = surfedges.Get(elnr)[i].nr+1; + if (surfedges.Get(elnr)[i] == -1) return i; + eledges[i] = surfedges.Get(elnr)[i]+1; } } return 4; @@ -2238,7 +2238,7 @@ namespace netgen if (orient) orient[0] = segedges.Get(elnr) > 0 ? 1 : -1; */ - eledges[0] = segedges.Get(elnr).nr+1; + eledges[0] = segedges.Get(elnr)+1; if (orient) // orient[0] = segedges.Get(elnr).orient ? -1 : 1; orient[0] = GetSegmentEdgeOrientation(elnr) ? -1 : 1; diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index 054afd70..9447c545 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -15,17 +15,23 @@ namespace netgen { -struct T_EDGE -{ - // int orient:1; - int nr; // 0-based -}; - -struct T_FACE -{ - // int forient:3; - int fnr; // 0-based -}; + /* + struct T_EDGE + { + // int orient:1; + int nr; // 0-based + }; + + struct T_FACE + { + // int forient:3; + int fnr; // 0-based + }; + */ + + typedef int T_EDGE; + typedef int T_FACE; + /* template @@ -111,12 +117,12 @@ public: inline static const ELEMENT_FACE * GetFaces1 (ELEMENT_TYPE et); inline static const ELEMENT_FACE * GetFaces0 (ELEMENT_TYPE et); - int GetSegmentEdge (int segnr) const { return segedges[segnr-1].nr+1; } - int GetEdge (SegmentIndex segnr) const { return segedges[segnr].nr; } + int GetSegmentEdge (int segnr) const { return segedges[segnr-1]+1; } + int GetEdge (SegmentIndex segnr) const { return segedges[segnr]; } void GetSegmentEdge (int segnr, int & enr, int & orient) const { - enr = segedges.Get(segnr).nr+1; + enr = segedges.Get(segnr)+1; // orient = segedges.Get(segnr).orient; orient = GetSegmentEdgeOrientation(segnr); } @@ -153,7 +159,7 @@ public: int GetSurfaceElementFaceOrientation (int elnr) const; void GetEdges (SurfaceElementIndex elnr, NgArray & edges) const; int GetFace (SurfaceElementIndex elnr) const - { return surffaces[elnr].fnr; } + { return surffaces[elnr]; } int GetSurfaceElementEdges (int elnr, int * edges, int * orient) const; diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index c39d882b..3f9c4671 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -181,29 +181,29 @@ namespace netgen (*testout) << endl; - cout << "Highest entry in topology hierarchy: " << endl; + cout << IM(3) << "Highest entry in topology hierarchy: " << endl; if (count) - cout << count << " composite solid(s)" << endl; + cout << IM(3) << count << " composite solid(s)" << endl; else if (geom->somap.Extent()) - cout << geom->somap.Extent() << " solid(s)" << endl; + cout << IM(3) << geom->somap.Extent() << " solid(s)" << endl; else if (geom->shmap.Extent()) - cout << geom->shmap.Extent() << " shells(s)" << endl; + cout << IM(3) << geom->shmap.Extent() << " shells(s)" << endl; else if (geom->fmap.Extent()) - cout << geom->fmap.Extent() << " face(s)" << endl; + cout << IM(3) << geom->fmap.Extent() << " face(s)" << endl; else if (geom->wmap.Extent()) - cout << geom->wmap.Extent() << " wire(s)" << endl; + cout << IM(3) << geom->wmap.Extent() << " wire(s)" << endl; else if (geom->emap.Extent()) - cout << geom->emap.Extent() << " edge(s)" << endl; + cout << IM(3) << geom->emap.Extent() << " edge(s)" << endl; else if (geom->vmap.Extent()) - cout << geom->vmap.Extent() << " vertices(s)" << endl; + cout << IM(3) << geom->vmap.Extent() << " vertices(s)" << endl; else - cout << "no entities" << endl; + cout << IM(3) << "no entities" << endl; }