From 07191d6e1b9d032334178e1f7f6e080c04c0e456 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 14 Dec 2024 20:21:18 +0100 Subject: [PATCH] more PointIndex, fix range-check --- libsrc/meshing/adfront3.cpp | 6 ++++-- libsrc/meshing/bisect.cpp | 33 +++++++++++++++++---------------- libsrc/meshing/meshclass.hpp | 16 +++++++++------- libsrc/meshing/ruler3.hpp | 2 +- libsrc/meshing/topology.hpp | 2 +- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/libsrc/meshing/adfront3.cpp b/libsrc/meshing/adfront3.cpp index bcf9a67b..f1622f68 100644 --- a/libsrc/meshing/adfront3.cpp +++ b/libsrc/meshing/adfront3.cpp @@ -635,9 +635,11 @@ int AdFront3 :: GetLocals (int fstind, // if (pind.IsValid() && pind <= connectedpairs->Size ()) if (connectedpairs->Range().Contains(pind)) { - for (j = 1; j <= connectedpairs->EntrySize(pind); j++) + // for (int j = 1; j <= connectedpairs->EntrySize(pind); j++) + for (auto j : (*connectedpairs)[pind].Range()) { - PointIndex oi = connectedpairs->Get(pind, j); + //PointIndex oi = connectedpairs->Get(pind, j); + PointIndex oi = (*connectedpairs)[pind][j]; PointIndex other = invpindex[oi]; // if (other >= 1 && other <= pindex.Size() && if (pindex.Range().Contains(other) && diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 3e659695..a80a8be9 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -373,7 +373,7 @@ namespace netgen for (j = 0; j < ned; j++) { - INDEX_2 i2(el.PNum(tip[j][0]), el.PNum(tip[j][1])); + PointIndices<2> i2(el.PNum(tip[j][0]), el.PNum(tip[j][1])); i2.Sort(); //(*testout) << "edge " << i2 << endl; if (!edgenumber.Used(i2)) @@ -428,7 +428,7 @@ namespace netgen for (j = 0; j < ned; j++) { - INDEX_2 i2(el.PNum(tip[j][0]), el.PNum(tip[j][1])); + PointIndices<2> i2(el.PNum(tip[j][0]), el.PNum(tip[j][1])); i2.Sort(); if (!edgenumber.Used(i2)) { @@ -490,10 +490,10 @@ namespace netgen for (j = 0; j < 3; j++) { - INDEX_2 e1 (el.PNum(pairs[j][0]), - el.PNum(pairs[j][1])); - INDEX_2 e2 (el.PNum(pairs[j][2]), - el.PNum(pairs[j][3])); + PointIndices<2> e1 (el.PNum(pairs[j][0]), + el.PNum(pairs[j][1])); + PointIndices<2> e2 (el.PNum(pairs[j][2]), + el.PNum(pairs[j][3])); e1.Sort(); e2.Sort(); @@ -525,7 +525,7 @@ namespace netgen for(i = 0; i < el2d.GetNP(); i++) { - INDEX_2 e1(el2d[i], el2d[(i+1) % el2d.GetNP()]); + PointIndices<2> e1(el2d[i], el2d[(i+1) % el2d.GetNP()]); e1.Sort(); INDEX_2 e2; @@ -759,7 +759,7 @@ namespace netgen for (j = 0; j < ned; j++) { - INDEX_2 i2(el.PNum(tip[j][0]), el.PNum(tip[j][1])); + PointIndices<2> i2(el.PNum(tip[j][0]), el.PNum(tip[j][1])); i2.Sort(); if (!edgenumber.Used(i2)) { @@ -819,10 +819,10 @@ namespace netgen for (j = 0; j < 3; j++) { - INDEX_2 e1 (el.PNum(pairs[j][0]), - el.PNum(pairs[j][1])); - INDEX_2 e2 (el.PNum(pairs[j][2]), - el.PNum(pairs[j][3])); + PointIndices<2> e1 (el.PNum(pairs[j][0]), + el.PNum(pairs[j][1])); + PointIndices<2> e2 (el.PNum(pairs[j][2]), + el.PNum(pairs[j][3])); e1.Sort(); e2.Sort(); @@ -874,7 +874,7 @@ namespace netgen for (int i = 0; i < 3; i++) for (int j = i+1; j < 4; j++) { - INDEX_2 i2(mt.pnums[i], mt.pnums[j]); + PointIndices<2> i2(mt.pnums[i], mt.pnums[j]); i2.Sort(); int hval = edgenumber.Get(i2); if (hval > val) @@ -894,7 +894,7 @@ namespace netgen for (int j = i+1; j < 4; j++) if (i != k && j != k) { - INDEX_2 i2(mt.pnums[i], mt.pnums[j]); + PointIndices<2> i2(mt.pnums[i], mt.pnums[j]); i2.Sort(); int hval = edgenumber.Get(i2); if (hval > val) @@ -973,7 +973,8 @@ namespace netgen bool identified = true; mi.np = el.GetNP(); - int min1(0),min2(0); + // int min1(0),min2(0); + PointIndex min1(PointIndex::INVALID), min2(PointIndex::INVALID); for(int j = 0; identified && j < mi.np; j++) { mi.pnums[j] = el[j]; @@ -999,7 +1000,7 @@ namespace netgen int val = 0; for (int i = 0; i < mi.np; i++) { - INDEX_2 i2(mi.pnums[i], mi.pnums[(i+1)%mi.np]); + PointIndices<2> i2(mi.pnums[i], mi.pnums[(i+1)%mi.np]); i2.Sort(); int hval = edgenumber.Get(i2); if (hval > val) diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index c3a241cd..31d0fb01 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -269,17 +269,19 @@ namespace netgen auto GetNP () const { return points.Size(); } // [[deprecated("Use Point(PointIndex) instead of int !")]] - MeshPoint & Point(int i) + MeshPoint & Point(int i) // 1-based { // return points.Elem(i); - return Point (PointIndex(i+PointIndex::BASE-1)); - } + // return Point (PointIndex(i+PointIndex::BASE-1)); + return Point (PointIndex(IndexBASE()+i-1)); + } MeshPoint & Point(PointIndex pi) { return points[pi]; } // [[deprecated("Use Point(PointIndex) instead of int !")]] const MeshPoint & Point(int i) const { // return points.Get(i); - return Point (PointIndex(i+PointIndex::BASE-1)); + // return Point (PointIndex(i+PointIndex::BASE-1)); + return Point (PointIndex(IndexBASE()+i-1)); } const MeshPoint & Point(PointIndex pi) const { return points[pi]; } @@ -551,8 +553,8 @@ namespace netgen { if(!boundaryedges) const_cast(this)->BuildBoundaryEdges(); - - INDEX_2 i2 (pi1, pi2); + + PointIndices<2> i2(pi1, pi2); i2.Sort(); return boundaryedges->Used (i2); } @@ -571,7 +573,7 @@ namespace netgen SegmentIndex SegmentNr (PointIndex pi1, PointIndex pi2) const { - INDEX_2 i2 (pi1, pi2); + PointIndices<2> i2(pi1, pi2); i2.Sort(); return segmentht->Get (i2); } diff --git a/libsrc/meshing/ruler3.hpp b/libsrc/meshing/ruler3.hpp index 03a3ad82..0879163c 100644 --- a/libsrc/meshing/ruler3.hpp +++ b/libsrc/meshing/ruler3.hpp @@ -172,7 +172,7 @@ public: int GetNP (int fn) const { return faces.Get(fn).GetNP(); } /// - int GetPointNr (int fn, int endp) const + PointIndex GetPointNr (int fn, int endp) const { return faces.Get(fn).PNum(endp); } /// int GetPointNrMod (int fn, int endp) const diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index e97b5f23..ccf47ce4 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -148,7 +148,7 @@ public: ELEMENT_TYPE GetFaceType (int fnr) const // { return (face2vert.Get(fnr)[3] == 0) ? TRIG : QUAD; } - { return (face2vert[fnr-1][3] == 0) ? TRIG : QUAD; } + { return (!face2vert[fnr-1][3].IsValid()) ? TRIG : QUAD; } void GetSurfaceElementEdges (int elnr, NgArray & edges) const; int GetSurfaceElementFace (int elnr) const;