simplify edge/face-id types (just an int)

This commit is contained in:
Joachim Schoeberl 2021-11-06 15:52:35 +01:00
parent 6ae645ce33
commit 50398c18c4
10 changed files with 97 additions and 86 deletions

View File

@ -42,6 +42,7 @@ namespace netgen
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 <typename T>
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

View File

@ -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;

View File

@ -3,7 +3,7 @@
extern double CalcTotalBad (const Mesh::T_POINTS & points,
const Array<Element> & elements,
const Array<Element, ElementIndex> & elements,
const MeshingParameters & mp);
@ -54,7 +54,7 @@ public:
double CalcTotalBad (const Mesh::T_POINTS & points,
const Array<Element> & elements)
const Array<Element, ElementIndex> & elements)
{
return netgen::CalcTotalBad (points, elements, mp);
}
@ -121,7 +121,7 @@ class JacobianPointFunction : public MinFunction
{
public:
Mesh::T_POINTS & points;
const Array<Element> & elements;
const Array<Element, ElementIndex> & elements;
TABLE<INDEX> elementsonpoint;
PointIndex actpind;
@ -130,7 +130,7 @@ public:
public:
JacobianPointFunction (Mesh::T_POINTS & apoints,
const Array<Element> & aelements);
const Array<Element, ElementIndex> & aelements);
virtual ~JacobianPointFunction () { ; }
virtual void SetPointIndex (PointIndex aactpind);
virtual double Func (const Vector & x) const;

View File

@ -25,10 +25,8 @@ namespace netgen
class Mesh
{
public:
typedef ::netgen::T_POINTS T_POINTS;
// typedef NgArray<Element, 0, size_t> T_VOLELEMENTS;
// typedef NgArray<Element2d, 0, SurfaceElementIndex> T_SURFELEMENTS;
// typedef NgArray<Element2d, 0, size_t> T_SURFELEMENTS;
// typedef Array<MeshPoint, PointIndex> T_POINTS;
typedef netgen::T_POINTS T_POINTS;
private:
/// point coordinates
@ -42,7 +40,7 @@ namespace netgen
/// surface elements, 2d-inner elements
Array<Element2d, SurfaceElementIndex> surfelements;
/// volume elements
Array<Element> volelements;
Array<Element, ElementIndex> volelements;
/// points will be fixed forever
Array<PointIndex> 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); }

View File

@ -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; }

View File

@ -602,7 +602,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
ExportArray<Element,size_t>(m);
ExportArray<Element,ElementIndex>(m);
ExportArray<Element2d,SurfaceElementIndex>(m);
ExportArray<Segment,SegmentIndex>(m);
ExportArray<Element0d>(m);
@ -825,7 +825,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def_property("dim", &Mesh::GetDimension, &Mesh::SetDimension)
.def("Elements3D",
static_cast<Array<Element>&(Mesh::*)()> (&Mesh::VolumeElements),
static_cast<Array<Element,ElementIndex>&(Mesh::*)()> (&Mesh::VolumeElements),
py::return_value_policy::reference)
.def("Elements2D",

View File

@ -303,7 +303,7 @@ namespace netgen
{
public:
Mesh::T_POINTS & points;
const Array<Element> & elements;
const Array<Element, ElementIndex> & elements;
Table<int, PointIndex> &elementsonpoint;
bool own_elementsonpoint;
const MeshingParameters & mp;
@ -312,7 +312,7 @@ namespace netgen
public:
PointFunction (Mesh::T_POINTS & apoints,
const Array<Element> & aelements,
const Array<Element, ElementIndex> & 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<Element> & aelements,
const Array<Element, ElementIndex> & aelements,
const MeshingParameters & amp)
: points(apoints), elements(aelements), elementsonpoint(* new Table<int,PointIndex>()), own_elementsonpoint(true), mp(amp)
{
@ -494,7 +494,7 @@ namespace netgen
DenseMatrix m;
public:
CheapPointFunction (Mesh::T_POINTS & apoints,
const Array<Element> & aelements,
const Array<Element, ElementIndex> & 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<Element> & aelements,
const Array<Element, ElementIndex> & 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<Element> & aelements)
const Array<Element, ElementIndex> & aelements)
: points(apoints), elements(aelements), elementsonpoint(apoints.Size())
{
for (int i = 0; i < elements.Size(); i++)

View File

@ -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<int> & 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<int> & 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;

View File

@ -15,6 +15,7 @@
namespace netgen
{
/*
struct T_EDGE
{
// int orient:1;
@ -26,6 +27,11 @@ struct T_FACE
// int forient:3;
int fnr; // 0-based
};
*/
typedef int T_EDGE;
typedef int T_FACE;
/*
template <typename T, int S>
@ -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<int> & edges) const;
int GetFace (SurfaceElementIndex elnr) const
{ return surffaces[elnr].fnr; }
{ return surffaces[elnr]; }
int GetSurfaceElementEdges (int elnr, int * edges, int * orient) const;

View File

@ -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;
}