EdgeIndex and FaceIndex

This commit is contained in:
Joachim Schoeberl 2025-01-07 16:41:37 +01:00
parent 5642d435e1
commit 0a1fd5a2e2
5 changed files with 96 additions and 53 deletions

View File

@ -116,7 +116,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const
ret.edges.num = 1; ret.edges.num = 1;
ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr); ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr);
*/ */
ret.edges.Assign ( FlatArray<T_EDGE2> (1, const_cast<T_EDGE2*>( mesh->GetTopology().GetSegmentElementEdgesPtr (nr)))); ret.edges.Assign ( FlatArray<T_EDGE2> (1, const_cast<T_EDGE2*>((const int*) mesh->GetTopology().GetSegmentElementEdgesPtr (nr))));
/* /*
ret.faces.num = 0; 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.num = MeshTopology::GetNEdges (el.GetType());
ret.edges.ptr = mesh->GetTopology().GetSurfaceElementEdgesPtr (nr); 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.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr); ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr);
*/ */
ret.faces.Assign ( { 1, const_cast<int*>(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) });
// ret.faces.Assign ( { 1, const_cast<int*>(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) });
ret.faces.Assign ( { 1, (int*)(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) });
if (mesh->GetDimension() == 3) if (mesh->GetDimension() == 3)
{ {
ret.facets.num = ret.faces.Size(); 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.num = MeshTopology::GetNEdges (el.GetType());
ret.edges.ptr = mesh->GetTopology().GetElementEdgesPtr (nr); 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.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = mesh->GetTopology().GetElementFacesPtr (nr); 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.num = ret.faces.Size();
ret.facets.base = 0; ret.facets.base = 0;

View File

@ -2148,9 +2148,13 @@ namespace netgen
} }
// for (int i = 1; i <= nse; i++) // for (int i = 1; i <= nse; i++)
/*
for (SurfaceElementIndex sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{ {
const Element2d & el = mesh[sei]; const Element2d & el = mesh[sei];
*/
for (const Element2d & el : mesh.SurfaceElements())
{
if (el.GetType() == TRIG || if (el.GetType() == TRIG ||
el.GetType() == TRIG6) el.GetType() == TRIG6)
{ {
@ -2175,9 +2179,13 @@ namespace netgen
} }
if(mesh.GetDimension() == 2) if(mesh.GetDimension() == 2)
{ {
/*
for (SegmentIndex j=0; j<mesh.GetNSeg(); j++) for (SegmentIndex j=0; j<mesh.GetNSeg(); j++)
{ {
auto seg = mesh[j]; auto seg = mesh[j];
*/
for (const Segment & seg : mesh.LineSegments())
{
for (auto map : idmaps) for (auto map : idmaps)
{ {
if (seg[0].IsValid() && seg[1].IsValid() && (*map)[seg[0]].IsValid() && (*map)[seg[1]].IsValid()) if (seg[0].IsValid() && seg[1].IsValid() && (*map)[seg[0]].IsValid() && (*map)[seg[1]].IsValid())
@ -2574,11 +2582,14 @@ namespace netgen
/*
for (auto ei : mesh.VolumeElements().Range()) for (auto ei : mesh.VolumeElements().Range())
{ {
const Element & el = mesh[ei]; const Element & el = mesh[ei];
*/
for (const Element & el : mesh.VolumeElements())
{
//int pos = elements_before[el[0]]->Pos(el); //int pos = elements_before[el[0]]->Pos(el);
//int elnum = (pos >= 0) ? (*markedelts_num[el[0]])[pos] : -1; //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]; const Element2d & el = mesh[sei];
*/
for (const Element2d & el : mesh.SurfaceElements())
{
/* /*
for(int k=0; k<3; k++) for(int k=0; k<3; k++)
auxind3[k] = el[k]; auxind3[k] = el[k];

View File

@ -210,7 +210,7 @@ private:
Mat<3> hdxdxi; Mat<3> hdxdxi;
Vec<3> hcoefs[10]; // enough for second order tets Vec<3> hcoefs[10]; // enough for second order tets
void SetEdges (FlatArray<int> edges) void SetEdges (FlatArray<T_EDGE> edges)
{ {
nedges = edges.Size(); nedges = edges.Size();
for (int i = 0; i < edges.Size(); i++) for (int i = 0; i < edges.Size(); i++)
@ -220,7 +220,7 @@ private:
auto GetEdges() const auto GetEdges() const
{ return FlatArray(nedges, edgenrs); } { return FlatArray(nedges, edgenrs); }
void SetFaces (FlatArray<int> faces) void SetFaces (FlatArray<T_FACE> faces)
{ {
nfaces = faces.Size(); nfaces = faces.Size();
for (int i = 0; i < faces.Size(); i++) for (int i = 0; i < faces.Size(); i++)
@ -250,7 +250,7 @@ private:
NgArrayMem<int,4> edgenrs; NgArrayMem<int,4> edgenrs;
int facenr; int facenr;
void SetEdges (FlatArray<int> edges) void SetEdges (FlatArray<T_EDGE> edges)
{ {
edgenrs.SetSize(edges.Size()); edgenrs.SetSize(edges.Size());
for (int i = 0; i < edges.Size(); i++) for (int i = 0; i < edges.Size(); i++)

View File

@ -174,7 +174,7 @@ namespace netgen
public: public:
constexpr Index (t_invalid inv) : i(long(BASE)-1) { ; } constexpr Index (t_invalid inv) : i(long(BASE)-1) { ; }
// private: // protected:
constexpr operator T () const { return i; } constexpr operator T () const { return i; }
explicit constexpr operator T& () { return i; } explicit constexpr operator T& () { return i; }
public: public:
@ -200,16 +200,16 @@ namespace netgen
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
constexpr auto operator+ (Index<T,TIndex,Base> ind, int i) { TIndex res(ind); res += i; return res; } constexpr auto operator+ (Index<T,TIndex,Base> ind, int i) { Index<T,TIndex,Base> res(ind); return res += i; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
constexpr auto operator+ (Index<T,TIndex,Base> ind, size_t i) { TIndex res(ind); res += i; return res; } constexpr auto operator+ (Index<T,TIndex,Base> ind, size_t i) { Index<T,TIndex,Base> res(ind); return res += i; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
constexpr TIndex operator+ (int i, Index<T,TIndex,Base> ind) { TIndex res(ind); res += i; return res; } constexpr TIndex operator+ (int i, Index<T,TIndex,Base> ind) { return ind+i; } // Indexx<T,TIndex,Base> res(ind); return res += i;
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
inline TIndex operator+ (size_t i, Index<T,TIndex,Base> ind) { TIndex res(ind); res += i; return res; } inline TIndex operator+ (size_t i, Index<T,TIndex,Base> ind) { return ind+i; } // TIndex res(ind); res += i; return res; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
constexpr inline auto operator- (Index<T,TIndex,Base> ind, int i) { TIndex res(ind); res -= i; return res; } constexpr inline auto operator- (Index<T,TIndex,Base> ind, int i) { Index<T,TIndex,Base> res(ind); return res -= i; }
// template <typename T, typename TIndex, int Base> // template <typename T, typename TIndex, int Base>
// constexpr inline auto operator- (Index<T,TIndex,Base> pa, Index<T,TIndex,Base> pb) { return pa.i-pb.i; } // constexpr inline auto operator- (Index<T,TIndex,Base> pa, Index<T,TIndex,Base> pb) { return pa.i-pb.i; }
@ -228,10 +228,18 @@ namespace netgen
inline bool operator!= (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i != b.i; } inline bool operator!= (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i != b.i; }
template <typename T, typename TIndex, int Base>
inline void SetInvalid (Index<T,TIndex,Base> & id) { id.Invalidate(); }
template <typename T, typename TIndex, int Base>
inline bool IsInvalid (const Index<T,TIndex,Base> & id) { return !id.IsValid(); }
class PointIndex : public Index<int,PointIndex,1> class PointIndex : public Index<int,PointIndex,1>
{ {
public: public:
using Index::Index; using Index::Index;
template <int N> friend class PointIndices;
}; };
} }
@ -473,17 +481,17 @@ namespace netgen
inline bool operator>= (Index<int, SurfaceElementIndex,0> ei1, int s) { return int(ei1) >= int(s); }; inline bool operator>= (Index<int, SurfaceElementIndex,0> ei1, int s) { return int(ei1) >= int(s); };
*/ */
inline void SetInvalid (SurfaceElementIndex & id) { id = -1; } // inline void SetInvalid (SurfaceElementIndex & id) { id.Invalidate(); }
inline bool IsInvalid (SurfaceElementIndex & id) { return id == -1; } // inline bool IsInvalid (SurfaceElementIndex & id) { return !id.IsValid(); }
inline istream & operator>> (istream & ist, SurfaceElementIndex & pi) inline istream & operator>> (istream & ist, SurfaceElementIndex & pi)
{ {
int i; ist >> i; pi = i; return ist; 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<int, SegmentIndex,0> ei1, int s) { return int(ei1) < int(s); }; inline bool operator< (Index<int, SegmentIndex,0> ei1, int s) { return int(ei1) < int(s); };
*/ */
inline void SetInvalid (SegmentIndex & id) { id = -1; } // inline void SetInvalid (SegmentIndex & id) { id = -1; }
inline bool IsInvalid (SegmentIndex & id) { return id == -1; } // inline bool IsInvalid (SegmentIndex & id) { return id == -1; }
inline istream & operator>> (istream & ist, SegmentIndex & pi) inline istream & operator>> (istream & ist, SegmentIndex & pi)
@ -510,9 +518,9 @@ namespace netgen
int i; ist >> i; pi = i; return ist; 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));
} }

View File

@ -16,9 +16,23 @@
namespace netgen namespace netgen
{ {
typedef int T_EDGE; // typedef int T_EDGE;
typedef int T_FACE; // typedef int T_FACE;
class EdgeIndex : public Index<int,EdgeIndex,0>
{
public:
using Index::Index;
};
class FaceIndex : public Index<int,FaceIndex,0>
{
public:
using Index::Index;
};
typedef EdgeIndex T_EDGE;
typedef FaceIndex T_FACE;
class MeshTopology class MeshTopology
{ {
@ -33,12 +47,12 @@ class MeshTopology
Array<std::array<PointIndex,2>> edge2vert; Array<std::array<PointIndex,2>> edge2vert;
Array<std::array<PointIndex,4>> face2vert; Array<std::array<PointIndex,4>> face2vert;
Array<std::array<T_EDGE,12>, ElementIndex> edges; Array<std::array<EdgeIndex,12>, ElementIndex> edges;
Array<std::array<T_FACE,6>, ElementIndex> faces; Array<std::array<FaceIndex,6>, ElementIndex> faces;
Array<std::array<T_EDGE,4>, SurfaceElementIndex> surfedges; Array<std::array<EdgeIndex,4>, SurfaceElementIndex> surfedges;
Array<T_EDGE> segedges; Array<EdgeIndex,SegmentIndex> segedges;
Array<T_FACE> surffaces; Array<FaceIndex,SurfaceElementIndex> surffaces;
// Array<INDEX_2, SurfaceElementIndex> surf2volelement; // Array<INDEX_2, SurfaceElementIndex> surf2volelement;
Array<std::array<ElementIndex,2>, SurfaceElementIndex> surf2volelement; Array<std::array<ElementIndex,2>, SurfaceElementIndex> surf2volelement;
Array<SurfaceElementIndex> face2surfel; Array<SurfaceElementIndex> face2surfel;
@ -89,9 +103,9 @@ public:
inline static const ELEMENT_FACE * GetFaces0 (ELEMENT_TYPE et); inline static const ELEMENT_FACE * GetFaces0 (ELEMENT_TYPE et);
[[deprecated("use GetEdge(SegmentIndex) instead")]] [[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")]] [[deprecated("use GetEdge(SegmentIndex) instead")]]
void GetSegmentEdge (int segnr, int & enr, int & orient) const; void GetSegmentEdge (int segnr, int & enr, int & orient) const;
@ -103,8 +117,8 @@ public:
void GetElementFaces (int elnr, NgArray<int> & faces, bool withorientation) const; void GetElementFaces (int elnr, NgArray<int> & faces, bool withorientation) const;
// definition in meshclass.hpp // definition in meshclass.hpp
inline FlatArray<T_EDGE> GetEdges (ElementIndex elnr) const; inline FlatArray<EdgeIndex> GetEdges (ElementIndex elnr) const;
inline FlatArray<T_FACE> GetFaces (ElementIndex elnr) const; inline FlatArray<FaceIndex> GetFaces (ElementIndex elnr) const;
// [[deprecated("use GetElementEdge instead")]] // [[deprecated("use GetElementEdge instead")]]
@ -157,8 +171,8 @@ public:
[[deprecated("use GetEdge -> FlatArray instead")]] [[deprecated("use GetEdge -> FlatArray instead")]]
void GetEdges (SurfaceElementIndex elnr, NgArray<int> & edges) const; void GetEdges (SurfaceElementIndex elnr, NgArray<int> & edges) const;
inline FlatArray<T_EDGE> GetEdges (SurfaceElementIndex elnr) const; inline FlatArray<EdgeIndex> GetEdges (SurfaceElementIndex elnr) const;
// { return FlatArray<T_EDGE>(GetNEdges ( (*mesh)[elnr].GetType()), &surfedges[elnr][0]); } // { return FlatArray<EdgeIndex>(GetNEdges ( (*mesh)[elnr].GetType()), &surfedges[elnr][0]); }
int GetFace (SurfaceElementIndex elnr) const int GetFace (SurfaceElementIndex elnr) const
{ return surffaces[elnr]; } { return surffaces[elnr]; }
@ -167,31 +181,27 @@ public:
int GetNSurfedges() const {return surfedges.Size();} int GetNSurfedges() const {return surfedges.Size();}
[[deprecated("use GetEdges(ElementIndex) instead")]] [[deprecated("use GetEdges(ElementIndex) instead")]]
const T_EDGE * GetElementEdgesPtr (int elnr) const { return &edges[IndexBASE<ElementIndex>()+elnr][0]; } const EdgeIndex * GetElementEdgesPtr (int elnr) const { return &edges[IndexBASE<ElementIndex>()+elnr][0]; }
const T_EDGE * GetSurfaceElementEdgesPtr (int selnr) const { return &surfedges[selnr][0]; } const EdgeIndex * GetSurfaceElementEdgesPtr (int selnr) const { return &surfedges[selnr][0]; }
const T_EDGE * GetSegmentElementEdgesPtr (int selnr) const { return &segedges[selnr]; } const EdgeIndex * GetSegmentElementEdgesPtr (int selnr) const { return &segedges[selnr]; }
const T_FACE * GetElementFacesPtr (int elnr) const { return &faces[IndexBASE<ElementIndex>()+elnr][0]; } const FaceIndex * GetElementFacesPtr (int elnr) const { return &faces[IndexBASE<ElementIndex>()+elnr][0]; }
const T_FACE * GetSurfaceElementFacesPtr (int selnr) const { return &surffaces[selnr]; } const FaceIndex * GetSurfaceElementFacesPtr (int selnr) const { return &surffaces[selnr]; }
void GetSurface2VolumeElement (int selnr, int & elnr1, int & elnr2) const void GetSurface2VolumeElement (int selnr, int & elnr1, int & elnr2) const
{ {
elnr1 = surf2volelement[selnr-1][0]+1; elnr1 = surf2volelement[SurfaceElementIndex::Base() + selnr-1][0]+1 - ElementIndex::Base();
elnr2 = surf2volelement[selnr-1][1]+1; elnr2 = surf2volelement[SurfaceElementIndex::Base() + selnr-1][1]+1 - ElementIndex::Base();
} }
std::array<ElementIndex,2> GetSurface2VolumeElement (SurfaceElementIndex sei) std::array<ElementIndex,2> GetSurface2VolumeElement (SurfaceElementIndex sei)
{ {
return surf2volelement[sei]; return surf2volelement[sei];
/*
return { ElementIndex( surf2volelement[sei][0] - 1),
ElementIndex( surf2volelement[sei][1] - 1) };
*/
} }
[[deprecated("use GetSurfaceEleement -> SurfaceElementIndex")]] [[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]; } SurfaceElementIndex GetFace2SurfaceElement (int fnr) const { return face2surfel[fnr]; }
SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; } SegmentIndex GetSegmentOfEdge(int edgenr) const { return edge2segment[edgenr-1]; }