diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index d732285e..60779d68 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -116,7 +116,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const ret.edges.num = 1; ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr); */ - ret.edges.Assign ( FlatArray (1, const_cast( mesh->GetTopology().GetSegmentElementEdgesPtr (nr)))); + ret.edges.Assign ( FlatArray (1, const_cast((const int*) mesh->GetTopology().GetSegmentElementEdgesPtr (nr)))); /* ret.faces.num = 0; @@ -172,12 +172,19 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const ret.edges.num = MeshTopology::GetNEdges (el.GetType()); ret.edges.ptr = mesh->GetTopology().GetSurfaceElementEdgesPtr (nr); */ - ret.edges.Assign (mesh->GetTopology().GetEdges (SurfaceElementIndex(nr))); + + // ret.edges.Assign (mesh->GetTopology().GetEdges (SurfaceElementIndex(nr))); + auto hedges = mesh->GetTopology().GetEdges (SurfaceElementIndex(nr)); + ret.edges.Assign ( { hedges.Size(), (int*)hedges.Data() } ); + /* ret.faces.num = MeshTopology::GetNFaces (el.GetType()); ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr); */ - ret.faces.Assign ( { 1, const_cast(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) }); + + // ret.faces.Assign ( { 1, const_cast(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) }); + ret.faces.Assign ( { 1, (int*)(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) }); + if (mesh->GetDimension() == 3) { ret.facets.num = ret.faces.Size(); @@ -214,13 +221,18 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const ret.edges.num = MeshTopology::GetNEdges (el.GetType()); ret.edges.ptr = mesh->GetTopology().GetElementEdgesPtr (nr); */ - ret.edges.Assign (mesh->GetTopology().GetEdges (ElementIndex(nr))); + // ret.edges.Assign (mesh->GetTopology().GetEdges (ElementIndex(nr))); + auto hedges = mesh->GetTopology().GetEdges (ElementIndex(nr)); + ret.edges.Assign ( { hedges.Size(), (int*)hedges.Data() } ); + /* ret.faces.num = MeshTopology::GetNFaces (el.GetType()); ret.faces.ptr = mesh->GetTopology().GetElementFacesPtr (nr); */ - ret.faces.Assign (mesh->GetTopology().GetFaces (ElementIndex(nr))); + // ret.faces.Assign (mesh->GetTopology().GetFaces (ElementIndex(nr))); + auto hfaces = mesh->GetTopology().GetFaces (ElementIndex(nr)); + ret.faces.Assign ( { hfaces.Size(), (int*)hfaces.Data() } ); ret.facets.num = ret.faces.Size(); ret.facets.base = 0; diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 2d7d9af1..a0dbb20f 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -2148,9 +2148,13 @@ namespace netgen } // for (int i = 1; i <= nse; i++) + /* for (SurfaceElementIndex sei = 0; sei < nse; sei++) { const Element2d & el = mesh[sei]; + */ + for (const Element2d & el : mesh.SurfaceElements()) + { if (el.GetType() == TRIG || el.GetType() == TRIG6) { @@ -2175,9 +2179,13 @@ namespace netgen } if(mesh.GetDimension() == 2) { + /* for (SegmentIndex j=0; jPos(el); //int elnum = (pos >= 0) ? (*markedelts_num[el[0]])[pos] : -1; @@ -2622,12 +2633,14 @@ namespace netgen } - - - for(SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++) + /* + for(SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++) { const Element2d & el = mesh[sei]; + */ + for (const Element2d & el : mesh.SurfaceElements()) + { /* for(int k=0; k<3; k++) auxind3[k] = el[k]; diff --git a/libsrc/meshing/curvedelems.hpp b/libsrc/meshing/curvedelems.hpp index a77391ca..91f6ce92 100644 --- a/libsrc/meshing/curvedelems.hpp +++ b/libsrc/meshing/curvedelems.hpp @@ -210,7 +210,7 @@ private: Mat<3> hdxdxi; Vec<3> hcoefs[10]; // enough for second order tets - void SetEdges (FlatArray edges) + void SetEdges (FlatArray edges) { nedges = edges.Size(); for (int i = 0; i < edges.Size(); i++) @@ -220,7 +220,7 @@ private: auto GetEdges() const { return FlatArray(nedges, edgenrs); } - void SetFaces (FlatArray faces) + void SetFaces (FlatArray faces) { nfaces = faces.Size(); for (int i = 0; i < faces.Size(); i++) @@ -250,7 +250,7 @@ private: NgArrayMem edgenrs; int facenr; - void SetEdges (FlatArray edges) + void SetEdges (FlatArray edges) { edgenrs.SetSize(edges.Size()); for (int i = 0; i < edges.Size(); i++) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index f2413a61..619b3e41 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -174,7 +174,7 @@ namespace netgen public: constexpr Index (t_invalid inv) : i(long(BASE)-1) { ; } - // private: + // protected: constexpr operator T () const { return i; } explicit constexpr operator T& () { return i; } public: @@ -200,16 +200,16 @@ namespace netgen template - constexpr auto operator+ (Index ind, int i) { TIndex res(ind); res += i; return res; } + constexpr auto operator+ (Index ind, int i) { Index res(ind); return res += i; } template - constexpr auto operator+ (Index ind, size_t i) { TIndex res(ind); res += i; return res; } + constexpr auto operator+ (Index ind, size_t i) { Index res(ind); return res += i; } template - constexpr TIndex operator+ (int i, Index ind) { TIndex res(ind); res += i; return res; } + constexpr TIndex operator+ (int i, Index ind) { return ind+i; } // Indexx res(ind); return res += i; template - inline TIndex operator+ (size_t i, Index ind) { TIndex res(ind); res += i; return res; } + inline TIndex operator+ (size_t i, Index ind) { return ind+i; } // TIndex res(ind); res += i; return res; } template - constexpr inline auto operator- (Index ind, int i) { TIndex res(ind); res -= i; return res; } + constexpr inline auto operator- (Index ind, int i) { Index res(ind); return res -= i; } // template // constexpr inline auto operator- (Index pa, Index pb) { return pa.i-pb.i; } @@ -228,10 +228,18 @@ namespace netgen inline bool operator!= (Index a, Index b) { return a.i != b.i; } + template + inline void SetInvalid (Index & id) { id.Invalidate(); } + template + inline bool IsInvalid (const Index & id) { return !id.IsValid(); } + + + class PointIndex : public Index { public: using Index::Index; + template friend class PointIndices; }; } @@ -473,17 +481,17 @@ namespace netgen inline bool operator>= (Index ei1, int s) { return int(ei1) >= int(s); }; */ - inline void SetInvalid (SurfaceElementIndex & id) { id = -1; } - inline bool IsInvalid (SurfaceElementIndex & id) { return id == -1; } + // inline void SetInvalid (SurfaceElementIndex & id) { id.Invalidate(); } + // inline bool IsInvalid (SurfaceElementIndex & id) { return !id.IsValid(); } inline istream & operator>> (istream & ist, SurfaceElementIndex & pi) { int i; ist >> i; pi = i; return ist; } - inline ostream & operator<< (ostream & ost, const SurfaceElementIndex & pi) + inline ostream & operator<< (ostream & ost, const SurfaceElementIndex & si) { - return (ost << int(pi)); + return ost << (si-IndexBASE(si)); } @@ -501,8 +509,8 @@ namespace netgen inline bool operator< (Index ei1, int s) { return int(ei1) < int(s); }; */ - inline void SetInvalid (SegmentIndex & id) { id = -1; } - inline bool IsInvalid (SegmentIndex & id) { return id == -1; } + // inline void SetInvalid (SegmentIndex & id) { id = -1; } + // inline bool IsInvalid (SegmentIndex & id) { return id == -1; } inline istream & operator>> (istream & ist, SegmentIndex & pi) @@ -510,10 +518,10 @@ namespace netgen int i; ist >> i; pi = i; return ist; } - inline ostream & operator<< (ostream & ost, const SegmentIndex & pi) + inline ostream & operator<< (ostream & ost, const SegmentIndex & si) { - return (ost << int(pi)); - } + return ost << (si - IndexBASE(si)); + } diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index 8a4d1fd0..6af79c3b 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -16,9 +16,23 @@ namespace netgen { - typedef int T_EDGE; - typedef int T_FACE; + // typedef int T_EDGE; + // typedef int T_FACE; + class EdgeIndex : public Index + { + public: + using Index::Index; + }; + + class FaceIndex : public Index + { + public: + using Index::Index; + }; + + typedef EdgeIndex T_EDGE; + typedef FaceIndex T_FACE; class MeshTopology { @@ -33,12 +47,12 @@ class MeshTopology Array> edge2vert; Array> face2vert; - Array, ElementIndex> edges; - Array, ElementIndex> faces; - Array, SurfaceElementIndex> surfedges; + Array, ElementIndex> edges; + Array, ElementIndex> faces; + Array, SurfaceElementIndex> surfedges; - Array segedges; - Array surffaces; + Array segedges; + Array surffaces; // Array surf2volelement; Array, SurfaceElementIndex> surf2volelement; Array face2surfel; @@ -89,9 +103,9 @@ public: inline static const ELEMENT_FACE * GetFaces0 (ELEMENT_TYPE et); [[deprecated("use GetEdge(SegmentIndex) instead")]] - T_EDGE GetSegmentEdge (int segnr) const { return segedges[segnr-1]+1; } + EdgeIndex GetSegmentEdge (int segnr) const { return segedges[segnr-1]+1; } - T_EDGE GetEdge (SegmentIndex segnr) const { return segedges[segnr]; } + EdgeIndex GetEdge (SegmentIndex segnr) const { return segedges[segnr]; } [[deprecated("use GetEdge(SegmentIndex) instead")]] void GetSegmentEdge (int segnr, int & enr, int & orient) const; @@ -103,8 +117,8 @@ public: void GetElementFaces (int elnr, NgArray & faces, bool withorientation) const; // definition in meshclass.hpp - inline FlatArray GetEdges (ElementIndex elnr) const; - inline FlatArray GetFaces (ElementIndex elnr) const; + inline FlatArray GetEdges (ElementIndex elnr) const; + inline FlatArray GetFaces (ElementIndex elnr) const; // [[deprecated("use GetElementEdge instead")]] @@ -157,8 +171,8 @@ public: [[deprecated("use GetEdge -> FlatArray instead")]] void GetEdges (SurfaceElementIndex elnr, NgArray & edges) const; - inline FlatArray GetEdges (SurfaceElementIndex elnr) const; - // { return FlatArray(GetNEdges ( (*mesh)[elnr].GetType()), &surfedges[elnr][0]); } + inline FlatArray GetEdges (SurfaceElementIndex elnr) const; + // { return FlatArray(GetNEdges ( (*mesh)[elnr].GetType()), &surfedges[elnr][0]); } int GetFace (SurfaceElementIndex elnr) const { return surffaces[elnr]; } @@ -167,31 +181,27 @@ public: int GetNSurfedges() const {return surfedges.Size();} [[deprecated("use GetEdges(ElementIndex) instead")]] - const T_EDGE * GetElementEdgesPtr (int elnr) const { return &edges[IndexBASE()+elnr][0]; } - const T_EDGE * GetSurfaceElementEdgesPtr (int selnr) const { return &surfedges[selnr][0]; } - const T_EDGE * GetSegmentElementEdgesPtr (int selnr) const { return &segedges[selnr]; } + const EdgeIndex * GetElementEdgesPtr (int elnr) const { return &edges[IndexBASE()+elnr][0]; } + const EdgeIndex * GetSurfaceElementEdgesPtr (int selnr) const { return &surfedges[selnr][0]; } + const EdgeIndex * GetSegmentElementEdgesPtr (int selnr) const { return &segedges[selnr]; } - const T_FACE * GetElementFacesPtr (int elnr) const { return &faces[IndexBASE()+elnr][0]; } - const T_FACE * GetSurfaceElementFacesPtr (int selnr) const { return &surffaces[selnr]; } + const FaceIndex * GetElementFacesPtr (int elnr) const { return &faces[IndexBASE()+elnr][0]; } + const FaceIndex * GetSurfaceElementFacesPtr (int selnr) const { return &surffaces[selnr]; } void GetSurface2VolumeElement (int selnr, int & elnr1, int & elnr2) const { - elnr1 = surf2volelement[selnr-1][0]+1; - elnr2 = surf2volelement[selnr-1][1]+1; + elnr1 = surf2volelement[SurfaceElementIndex::Base() + selnr-1][0]+1 - ElementIndex::Base(); + elnr2 = surf2volelement[SurfaceElementIndex::Base() + selnr-1][1]+1 - ElementIndex::Base(); } std::array GetSurface2VolumeElement (SurfaceElementIndex sei) { return surf2volelement[sei]; - /* - return { ElementIndex( surf2volelement[sei][0] - 1), - ElementIndex( surf2volelement[sei][1] - 1) }; - */ } [[deprecated("use GetSurfaceEleement -> SurfaceElementIndex")]] - int GetFace2SurfaceElement1 (int fnr) const { return face2surfel[fnr-1]+1; } + int GetFace2SurfaceElement1 (int fnr) const { return face2surfel[fnr-1]+1 - SurfaceElementIndex::Base(); } SurfaceElementIndex GetFace2SurfaceElement (int fnr) const { return face2surfel[fnr]; } SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; }