From a5ce9915d1211041ce543528e1c904fb90d635ba Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 28 Dec 2024 22:58:44 +0100 Subject: [PATCH] compare PointIndex only with PointIndex --- libsrc/core/python_ngcore.hpp | 10 ++++--- libsrc/csg/edgeflw.cpp | 30 +++++++++---------- libsrc/csg/genmesh.cpp | 2 +- libsrc/csg/singularref.cpp | 4 +-- libsrc/csg/vscsg.cpp | 3 +- libsrc/geom2d/genmesh2d.cpp | 4 +-- libsrc/interface/nginterface.cpp | 11 ++++--- libsrc/interface/writediffpack.cpp | 6 ++-- libsrc/meshing/boundarylayer.cpp | 7 +++-- libsrc/meshing/boundarylayer.hpp | 1 + libsrc/meshing/boundarylayer2d.cpp | 2 +- libsrc/meshing/boundarylayer_limiter.hpp | 37 +++++++++++++++--------- libsrc/meshing/meshtype.hpp | 13 +++------ libsrc/meshing/parallelmesh.cpp | 2 +- libsrc/meshing/paralleltop.cpp | 2 +- libsrc/meshing/ruler3.cpp | 2 +- libsrc/meshing/topology.cpp | 30 +++++++++---------- libsrc/meshing/validate.cpp | 21 +++++++------- libsrc/visualization/meshdoc.cpp | 27 +++++++++-------- libsrc/visualization/meshdoc.hpp | 4 +-- libsrc/visualization/vsmesh.cpp | 4 +-- libsrc/visualization/vssolution.cpp | 19 ++++++------ libsrc/visualization/vssolution.hpp | 2 +- tests/catch/array.cpp | 8 ++--- 24 files changed, 135 insertions(+), 116 deletions(-) diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index c8ad53ac..2ce84481 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -319,8 +319,9 @@ namespace ngcore .def ("__getitem__", [](TFlat & self, TIND i) -> T& { - static constexpr int base = IndexBASE(); - if (i < base || i >= self.Size()+base) + // static constexpr int base = IndexBASE(); + auto reli = i - IndexBASE(); + if (reli < 0 || reli >= self.Size()) throw py::index_error(); return self[i]; }, @@ -328,8 +329,9 @@ namespace ngcore .def ("__setitem__", [](TFlat & self, TIND i, T val) -> T& { - static constexpr int base = IndexBASE(); - if (i < base || i >= self.Size()+base) + // static constexpr int base = IndexBASE(); + auto reli = i - IndexBASE(); + if (reli < 0 || reli >= self.Size()) throw py::index_error(); self[i] = val; return self[i]; diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index 26d5172d..fe57471f 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -567,7 +567,7 @@ namespace netgen { // int i, j; SegmentIndex si; - PointIndex pi; + // PointIndex pi; NgArray osedges(cntedge); INDEX_2_HASHTABLE osedgesht (cntedge+1); @@ -610,7 +610,7 @@ namespace netgen for (int i = 1; i <= osedgesht.GetNBags(); i++) for (int j = 1; j <= osedgesht.GetBagSize(i); j++) { - INDEX_2 i2; + PointIndices<2> i2; int val; osedgesht.GetData (i, j, i2, val); @@ -619,8 +619,8 @@ namespace netgen Vec<3> v = p2 - p1; double vlen = v.Length(); v /= vlen; - for (pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) if (pi != i2.I1() && pi != i2.I2()) { @@ -1371,8 +1371,8 @@ namespace netgen lastpi = PointIndex::INVALID; /* - for (pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) if (Dist (mesh[pi], p) < 1e-6) { lastpi = pi; @@ -1414,8 +1414,8 @@ namespace netgen if (i == ne) { /* - for (pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) if (Dist(mesh[pi], np) < 1e-6) thispi = pi; */ @@ -1539,8 +1539,8 @@ namespace netgen // generate initial point Point<3> p = edgepoints[0]; PointIndex pi1 = PointIndex::INVALID; - for (pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) if (Dist (mesh[pi], p) < 1e-6*geometry.MaxSize()) { @@ -1557,8 +1557,8 @@ namespace netgen p = edgepoints.Last(); PointIndex pi2 = PointIndex::INVALID; - for (pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) if (Dist (mesh[pi], p) < 1e-6*geometry.MaxSize()) { @@ -1646,7 +1646,7 @@ namespace netgen Mesh & mesh) { int k; - PointIndex pi; + // PointIndex pi; double size = geometry.MaxSize(); @@ -1660,8 +1660,8 @@ namespace netgen PointIndex frompi = PointIndex::INVALID; PointIndex topi = PointIndex::INVALID; - for (pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) { if (Dist2 (mesh[pi], fromp) <= 1e-16*size) frompi = pi; diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 70d3f514..4aa292cf 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -443,7 +443,7 @@ namespace netgen meshing.SetStartTime (starttime); double eps = 1e-8 * geom.MaxSize(); - for (PointIndex pi = PointIndex::BASE; pi < noldp+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); pi < noldp+IndexBASE(); pi++) { // if(surf->PointOnSurface(mesh[pi])) meshing.AddPoint (mesh[pi], pi, NULL, diff --git a/libsrc/csg/singularref.cpp b/libsrc/csg/singularref.cpp index 8dc1b7e5..e58957d7 100644 --- a/libsrc/csg/singularref.cpp +++ b/libsrc/csg/singularref.cpp @@ -153,8 +153,8 @@ void SingularPoint :: FindPoints (class Mesh & mesh) NgArray surfk, surf; - for (PointIndex pi = PointIndex::BASE; - pi < mesh.GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); + pi < mesh.GetNP()+IndexBASE(); pi++) { if (mesh[pi].Type() != FIXEDPOINT) continue; const Point<3> p = mesh[pi]; diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index 2e397ecf..2e764b57 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -472,7 +472,8 @@ namespace netgen box = Box3d (Point3d (0,0,0), Point3d (1,1,1)); } - if (zoomall == 2 && ((vispar.centerpoint >= 1 && vispar.centerpoint <= mesh->GetNP()) || + if (zoomall == 2 && ((vispar.centerpoint-IndexBASE() >= 0 && + vispar.centerpoint-IndexBASE() < mesh->GetNP()) || vispar.use_center_coords)) { if (vispar.use_center_coords) diff --git a/libsrc/geom2d/genmesh2d.cpp b/libsrc/geom2d/genmesh2d.cpp index cd3def6c..1b0f3a3a 100644 --- a/libsrc/geom2d/genmesh2d.cpp +++ b/libsrc/geom2d/genmesh2d.cpp @@ -465,8 +465,8 @@ namespace netgen PointIndex mpi(0); Point<2> gp = geometry.GetPoint(i); Point<3> gp3(gp(0), gp(1), 0); - for (PointIndex pi = PointIndex::BASE; - pi < mesh->GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); + pi < mesh->GetNP()+IndexBASE(); pi++) if (Dist2(gp3, (*mesh)[pi]) < mindist) { mpi = pi; diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 1e96cfdd..cf3c580e 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -507,7 +507,7 @@ NG_ELEMENT_TYPE Ng_GetSurfaceElement (int ei, int * epi, int * np) { const Segment & seg = mesh->LineSegment (ei); - if (seg[2] < 0) + if (!seg[2].IsValid()) { epi[0] = seg[0]; epi[1] = seg[1]; @@ -866,7 +866,7 @@ NG_ELEMENT_TYPE Ng_GetSegment (int ei, int * epi, int * np) epi[0] = seg[0]; epi[1] = seg[1]; - if (seg[2] < 0) + if (!seg[2].IsValid()) { if (np) *np = 2; return NG_SEGM; @@ -1945,8 +1945,10 @@ int Ng_GetVertex_Elements( int vnr, int* elems ) } ///// Added by Roman Stainko .... -int Ng_GetVertex_SurfaceElements( int vnr, int* elems ) +int Ng_GetVertex_SurfaceElements( int vnr_, int* elems ) { + PointIndex vnr = vnr_ + IndexBASE()-1; + switch (mesh->GetDimension()) { case 3: @@ -1994,8 +1996,9 @@ int Ng_GetVertex_NElements( int vnr ) } ///// Added by Roman Stainko .... -int Ng_GetVertex_NSurfaceElements( int vnr ) +int Ng_GetVertex_NSurfaceElements( int vnr_ ) { + PointIndex vnr = vnr_ + IndexBASE()-1; switch (mesh->GetDimension()) { case 3: diff --git a/libsrc/interface/writediffpack.cpp b/libsrc/interface/writediffpack.cpp index 54fe840d..9c481ba9 100644 --- a/libsrc/interface/writediffpack.cpp +++ b/libsrc/interface/writediffpack.cpp @@ -92,7 +92,8 @@ void WriteDiffPackFormat (const Mesh & mesh, } - for (int i = 1; i <= np; i++) + // for (int i = 1; i <= np; i++) + for (PointIndex i : mesh.Points().Range()) { const Point3d & p = mesh.Point(i); @@ -244,7 +245,8 @@ void WriteDiffPackFormat (const Mesh & mesh, " - the boundary indicators that are set (ON) if any.\n" "#\n"; - for (i = 1; i <= np; i++) + // for (i = 1; i <= np; i++) + for (PointIndex i : mesh.Points().Range()) { const Point3d & p = mesh.Point(i); diff --git a/libsrc/meshing/boundarylayer.cpp b/libsrc/meshing/boundarylayer.cpp index ec92bc9b..645fa672 100644 --- a/libsrc/meshing/boundarylayer.cpp +++ b/libsrc/meshing/boundarylayer.cpp @@ -259,7 +259,7 @@ void MergeAndAddSegments (Mesh& mesh, FlatArray segments, FlatArray i2(seg[0], seg[1]); i2.Sort(); if (!already_added.Used(i2)) { @@ -297,6 +297,7 @@ BoundaryLayerTool::BoundaryLayerTool(Mesh& mesh_, segments = mesh.LineSegments(); np = mesh.GetNP(); + npi = IndexBASE()+np; ne = mesh.GetNE(); nse = mesh.GetNSE(); nseg = segments.Size(); @@ -626,7 +627,9 @@ void BoundaryLayerTool ::InsertNewElements( }; // insert new points - for (PointIndex pi = 1; pi <= np; pi++) + // for (PointIndex pi = 1; pi <= np; pi++) + for (PointIndex pi = IndexBASE(); + pi < IndexBASE()+np; pi++) { if (growthvectors[pi].Length2() != 0) { diff --git a/libsrc/meshing/boundarylayer.hpp b/libsrc/meshing/boundarylayer.hpp index 3646e4fb..7e51d16c 100644 --- a/libsrc/meshing/boundarylayer.hpp +++ b/libsrc/meshing/boundarylayer.hpp @@ -58,6 +58,7 @@ public: Array new_mat_nrs; BitArray moved_surfaces; int np, nseg, nse, ne; + PointIndex npi; // IndexBASE+np double total_height; Array point_types; diff --git a/libsrc/meshing/boundarylayer2d.cpp b/libsrc/meshing/boundarylayer2d.cpp index 794f805e..c732f6ae 100644 --- a/libsrc/meshing/boundarylayer2d.cpp +++ b/libsrc/meshing/boundarylayer2d.cpp @@ -283,7 +283,7 @@ namespace netgen } { - FaceDescriptor new_fd(0, 0, 0, -1); + FaceDescriptor new_fd(0, 0, 0, -1); new_fd.SetBCProperty(new_domain); // int new_fd_index = mesh.AddFaceDescriptor(new_fd); diff --git a/libsrc/meshing/boundarylayer_limiter.hpp b/libsrc/meshing/boundarylayer_limiter.hpp index d30c5445..f79ff9ae 100644 --- a/libsrc/meshing/boundarylayer_limiter.hpp +++ b/libsrc/meshing/boundarylayer_limiter.hpp @@ -85,14 +85,16 @@ struct GrowthVectorLimiter double GetLimit (PointIndex pi) { - if (pi <= tool.np) + // if (pi <= tool.np) + if (pi < tool.npi) return limits[pi]; return limits[map_from[pi]]; } bool SetLimit (PointIndex pi, double new_limit) { - double& limit = (pi <= tool.np) ? limits[pi] : limits[map_from[pi]]; + // double& limit = (pi <= tool.np) ? limits[pi] : limits[map_from[pi]]; + double& limit = (pi < tool.npi) ? limits[pi] : limits[map_from[pi]]; if (limit <= new_limit) return false; limit = new_limit; @@ -101,7 +103,8 @@ struct GrowthVectorLimiter bool ScaleLimit (PointIndex pi, double factor) { - double& limit = (pi <= tool.np) ? limits[pi] : limits[map_from[pi]]; + // double& limit = (pi <= tool.np) ? limits[pi] : limits[map_from[pi]]; + double& limit = (pi < tool.npi) ? limits[pi] : limits[map_from[pi]]; return SetLimit(pi, limit * factor); } @@ -115,7 +118,8 @@ struct GrowthVectorLimiter Point<3> GetPoint (PointIndex pi_to, double shift = 1., bool apply_limit = false) { - if (pi_to <= tool.np || tool.growth_vector_map.count(pi_to) == 0) + // if (pi_to <= tool.np || tool.growth_vector_map.count(pi_to) == 0) + if (pi_to < tool.npi || tool.growth_vector_map.count(pi_to) == 0) return mesh[pi_to]; return mesh[pi_to] + GetVector(pi_to, shift, apply_limit); @@ -286,7 +290,8 @@ struct GrowthVectorLimiter RegionTimer reg(t); if (factor == 0.0) return; - for (PointIndex pi : IntRange(tool.np, mesh.GetNP())) + // for (PointIndex pi : IntRange(tool.np, mesh.GetNP())) + for (PointIndex pi : mesh.Points().Range().Modify(tool.np,0)) { // auto pi_from = map_from[pi]; std::set pis; @@ -331,7 +336,8 @@ struct GrowthVectorLimiter auto np = sel.GetNP(); for (auto i : Range(np)) { - if (sel[i] > tool.np) + // if (sel[i] > tool.np) + if (sel[i] >= tool.npi) return false; if (tool.mapto[sel[i]].Size() == 0) return false; @@ -428,6 +434,7 @@ struct GrowthVectorLimiter Intersection_ isIntersectingTrig (PointIndex pi_from, PointIndex pi_to, SurfaceElementIndex sei, double shift = 0.0) { + // JS: where is that GetSeg function ? return isIntersectingTrig(GetSeg(pi_from, pi_to), GetTrig(sei, shift)); } @@ -460,7 +467,8 @@ struct GrowthVectorLimiter } template - void FindTreeIntersections (double trig_shift, double seg_shift, TFunc f, BitArray* relevant_points = nullptr) + void FindTreeIntersections (double trig_shift, double seg_shift, TFunc f, + TBitArray * relevant_points = nullptr) { static Timer t("GrowthVectorLimiter::FindTreeIntersections"); RegionTimer rt(t); @@ -469,7 +477,7 @@ struct GrowthVectorLimiter // int counter = 0; for (auto i : IntRange(tool.np, np_new)) { - PointIndex pi_to = i + PointIndex::BASE; + PointIndex pi_to = i + IndexBASE(); PointIndex pi_from = map_from[pi_to]; if (!pi_from.IsValid()) throw Exception("Point not mapped"); @@ -558,7 +566,8 @@ struct GrowthVectorLimiter PointIndex pi_max_limit = PointIndex::INVALID; for (PointIndex pi : {tri[0], tri[1], tri[2], tri2[0], tri2[1], tri2[2]}) - if (pi > tool.np && (!pi_max_limit.IsValid() || GetLimit(pi) > GetLimit(pi_max_limit))) + // if (pi > tool.np && (!pi_max_limit.IsValid() || GetLimit(pi) > GetLimit(pi_max_limit))) + if (pi >= tool.npi && (!pi_max_limit.IsValid() || GetLimit(pi) > GetLimit(pi_max_limit))) pi_max_limit = map_from[pi]; if (!pi_max_limit.IsValid()) @@ -623,8 +632,8 @@ struct GrowthVectorLimiter double seg_shift = safety; size_t limit_counter = 1; - BitArray relevant_points, relevant_points_next; - relevant_points.SetSize(mesh.Points().Size() + 1); + TBitArray relevant_points, relevant_points_next; + relevant_points.SetSize(mesh.Points().Size() + 1); relevant_points_next.SetSize(mesh.Points().Size() + 1); relevant_points.Set(); @@ -647,7 +656,8 @@ struct GrowthVectorLimiter for (auto pi : sel.PNums()) { relevant_points_next.SetBit(pi); - if (pi >= tool.np) + // if (pi >= tool.np) // was this correct (JS) ? + if (pi >= tool.npi) relevant_points_next.SetBit(map_from[pi]); else relevant_points_next.SetBit(map_from[pi]); @@ -656,7 +666,8 @@ struct GrowthVectorLimiter for (auto pi : sel.PNums()) { - if (pi >= tool.np) + //if (pi >= tool.np) // was this correct (JS) ? + if (pi >= tool.npi) return; if (tool.mapto[pi].Size() == 0) return; diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index de93b229..1d41d938 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -229,13 +229,11 @@ namespace netgen friend constexpr PointIndex operator+ (size_t, PointIndex); friend constexpr PointIndex operator- (PointIndex, int); friend constexpr int operator- (PointIndex, PointIndex); - /* friend bool operator< (PointIndex a, PointIndex b); friend bool operator> (PointIndex a, PointIndex b); friend bool operator>= (PointIndex a, PointIndex b); friend constexpr bool operator== (PointIndex a, PointIndex b); friend constexpr bool operator!= (PointIndex a, PointIndex b); - */ public: constexpr PointIndex (t_invalid inv) : i(long(PointIndex::BASE)-1) { ; } @@ -266,15 +264,12 @@ namespace netgen constexpr inline PointIndex operator+ (int i, PointIndex pi) { return PointIndex(pi.i+i); } constexpr inline PointIndex operator+ (size_t i, PointIndex pi) { return PointIndex(pi.i+i); } constexpr inline PointIndex operator- (PointIndex pi, int i) { return PointIndex(pi.i-i); } - constexpr inline int operator- (PointIndex pa, PointIndex pb) { return PointIndex(pa.i-pb.i); } - - /* - inline bool operator< (PointIndex a, PointIndex b) { return a.i < b.i; } - inline bool operator> (PointIndex a, PointIndex b) { return a.i > b.i; } - inline bool operator>= (PointIndex a, PointIndex b) { return a.i >= b.i; } + constexpr inline int operator- (PointIndex pa, PointIndex pb) { return pa.i-pb.i; } + inline bool operator< (PointIndex a, PointIndex b) { return a.i-b.i < 0; } + inline bool operator> (PointIndex a, PointIndex b) { return a.i-b.i > 0; } + inline bool operator>= (PointIndex a, PointIndex b) { return a.i-b.i >= 0; } inline constexpr bool operator== (PointIndex a, PointIndex b) { return a.i == b.i; } inline constexpr bool operator!= (PointIndex a, PointIndex b) { return a.i != b.i; } - */ } namespace ngcore diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index 826e2f7d..43cc1a71 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -1161,7 +1161,7 @@ namespace netgen seg.domin = seg.surfnr1; seg.domout = seg.surfnr2; - if ( seg.pnums[0] >0 && seg.pnums[1] > 0 ) + if ( seg.pnums[0].IsValid() && seg.pnums[1].IsValid() ) { paralleltop-> SetLoc2Glob_Segm ( segi, globsegi ); diff --git a/libsrc/meshing/paralleltop.cpp b/libsrc/meshing/paralleltop.cpp index 17968129..2352d48a 100644 --- a/libsrc/meshing/paralleltop.cpp +++ b/libsrc/meshing/paralleltop.cpp @@ -436,7 +436,7 @@ namespace netgen for (int dist : GetDistantProcs(pi)) dest2vert.Add (dist, pi); - for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); pi < newnv+IndexBASE(); pi++) if (auto [v1,v2] = mesh.mlbetweennodes[pi]; v1.IsValid()) { auto procs1 = GetDistantProcs(v1); diff --git a/libsrc/meshing/ruler3.cpp b/libsrc/meshing/ruler3.cpp index 54d5b315..b8d08f5b 100644 --- a/libsrc/meshing/ruler3.cpp +++ b/libsrc/meshing/ruler3.cpp @@ -457,7 +457,7 @@ int Meshing3 :: ApplyRules if (locpi.IsValid()) pused[locpi]--; - while (!ok && locpi < lpoints.Size()-1+PointIndex::BASE) + while (!ok && locpi < lpoints.Size()-1+IndexBASE()) { ok = 1; locpi++; diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index fc178b9f..eb12900c 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -513,8 +513,8 @@ namespace netgen auto end = r.Next(); // INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); ngcore::ClosedHashTable v2eht(2*max_edge_on_vertex+10); - for (PointIndex v = begin+PointIndex::BASE; - v < end+PointIndex::BASE; v++) + for (PointIndex v = begin+IndexBASE(); + v < end+IndexBASE(); v++) { v2eht.DeleteData(); for (int ednr : vert2edge[v]) @@ -553,7 +553,7 @@ namespace netgen // INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); // NgArray vertex2; - // for (PointIndex v = PointIndex::BASE; v < nv+PointIndex::BASE; v++) + // for (PointIndex v = IndexBASE(); v < nv+IndexBASE(); v++) ParallelForRange (mesh->GetNV(), // Points().Size(), @@ -565,8 +565,8 @@ namespace netgen ngcore::ClosedHashTable v2eht(2*max_edge_on_vertex+10); Array vertex2; - for (PointIndex v = begin+PointIndex::BASE; - v < end+PointIndex::BASE; v++) + for (PointIndex v = begin+IndexBASE(); + v < end+IndexBASE(); v++) { int ned = cnt[v]; v2eht.DeleteData(); @@ -659,8 +659,8 @@ namespace netgen { auto verts = edge2vert[i]; // 2 vertices of edge - if (verts[0] >= mesh->mlbetweennodes.Size()+PointIndex::BASE || - verts[1] >= mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (verts[0] >= mesh->mlbetweennodes.Size()+IndexBASE() || + verts[1] >= mesh->mlbetweennodes.Size()+IndexBASE()) continue; auto pa0 = mesh->mlbetweennodes[verts[0]]; // two parent vertices of v0 @@ -960,7 +960,7 @@ namespace netgen for (int j = 0; j < 3; j++) { PointIndex v = f3[j]; - if (v >= mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (v >= mesh->mlbetweennodes.Size()+IndexBASE()) continue; auto pa = mesh->mlbetweennodes[v]; @@ -991,7 +991,7 @@ namespace netgen for (int j = 0; j < 3; j++) { PointIndex v = f3[j]; - if (v >= mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (v >= mesh->mlbetweennodes.Size()+IndexBASE()) continue; auto pa = mesh->mlbetweennodes[v]; @@ -1031,7 +1031,7 @@ namespace netgen int max_face_on_vertex = 0; - for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++) + for (PointIndex i = IndexBASE(); i < nv+IndexBASE(); i++) { int onv = vert2oldface[i].Size() + vert2element[i].Size() + vert2surfelement[i].Size(); max_face_on_vertex = max (onv, max_face_on_vertex); @@ -1335,7 +1335,7 @@ namespace netgen << endl; (*testout) << "pos = "; for (int j = 0; j < 4; j++) - if (face2vert[i][j] >= 1) + if (face2vert[i][j].IsValid()) (*testout) << (*mesh)[(PointIndex)face2vert[i][j]] << " "; (*testout) << endl; @@ -1400,10 +1400,10 @@ namespace netgen for (int k = 0; k < 3; k++) { PointIndex vb = f3[k]; - if (vb >= mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (vb >= mesh->mlbetweennodes.Size()+IndexBASE()) continue; auto parents = mesh->mlbetweennodes[vb]; - if (parents[0] >= PointIndex::BASE) + if (parents[0] >= IndexBASE()) all_vert_coarse = false; } if (all_vert_coarse) continue; @@ -1415,7 +1415,7 @@ namespace netgen for (int k = 0; k < 3; k++) { PointIndex vb = f3[k]; // assume vb as the new bisect vert - if (vb >= mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (vb >= mesh->mlbetweennodes.Size()+IndexBASE()) continue; auto parents = mesh->mlbetweennodes[vb]; @@ -1552,7 +1552,7 @@ namespace netgen for (int k = 0; k < 3; k++) { PointIndex vb = f3[k]; // assume vb as the new bisect vert - if (vb >= mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (vb >= mesh->mlbetweennodes.Size()+IndexBASE()) continue; auto parents = mesh->mlbetweennodes[vb]; diff --git a/libsrc/meshing/validate.cpp b/libsrc/meshing/validate.cpp index c4214cc7..d0283112 100644 --- a/libsrc/meshing/validate.cpp +++ b/libsrc/meshing/validate.cpp @@ -20,11 +20,11 @@ namespace netgen { backup[i] = new Point<3>(mesh.Point(i+1)); - if(isnewpoint.Test(i+PointIndex::BASE) && - mesh.mlbetweennodes[i+PointIndex::BASE][0] > 0) + if(isnewpoint.Test(i+IndexBASE()) && + mesh.mlbetweennodes[i+IndexBASE()][0].IsValid()) { - mesh.Point(i+1) = Center(mesh.Point(mesh.mlbetweennodes[i+PointIndex::BASE][0]), - mesh.Point(mesh.mlbetweennodes[i+PointIndex::BASE][1])); + mesh.Point(i+1) = Center(mesh.Point(mesh.mlbetweennodes[i+IndexBASE()][0]), + mesh.Point(mesh.mlbetweennodes[i+IndexBASE()][1])); } } for (ElementIndex i = 0; i < mesh.GetNE(); i++) @@ -254,15 +254,16 @@ namespace netgen *should[i] = mesh.Point(i+1); - for(int i=0; i(); i < IndexBASE()+np; i++) { - if(isnewpoint.Test(i+PointIndex::BASE) && + if(isnewpoint.Test(i) && //working_points.Test(i+PointIndex::BASE) && - mesh.mlbetweennodes[i+PointIndex::BASE][0] > 0) - *can[i] = Center(*can[mesh.mlbetweennodes[i+PointIndex::BASE][0]-IndexBASE()], - *can[mesh.mlbetweennodes[i+PointIndex::BASE][1]-IndexBASE()]); + mesh.mlbetweennodes[i][0].IsValid()) + *can[i-IndexBASE()] = Center(*can[mesh.mlbetweennodes[i][0]-IndexBASE()], + *can[mesh.mlbetweennodes[i][1]-IndexBASE()]); else - *can[i] = mesh.Point(i+1); + *can[i-IndexBASE()] = mesh[i]; } diff --git a/libsrc/visualization/meshdoc.cpp b/libsrc/visualization/meshdoc.cpp index d0993272..1a2fb5c5 100644 --- a/libsrc/visualization/meshdoc.cpp +++ b/libsrc/visualization/meshdoc.cpp @@ -94,7 +94,7 @@ void VisualSceneMeshDoctor :: DrawScene () glPopName(); - if (selpoint > 0 && selpoint <= mesh->GetNP()) + if (selpoint-IndexBASE() >= 0 && selpoint-IndexBASE() < mesh->GetNP()) { GLfloat matcolblue[] = { 0, 0, 1, 1 }; @@ -376,8 +376,8 @@ void VisualSceneMeshDoctor :: BuildScene (int zoomall) const Point3d & p1 = mesh->Point(seg[0]); const Point3d & p2 = mesh->Point(seg[1]); - if (edgedist.Get(seg[0]) <= markedgedist && - edgedist.Get(seg[1]) <= markedgedist) + if (edgedist[seg[0]] <= markedgedist && + edgedist[seg[1]] <= markedgedist) { glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcolseledge); @@ -518,8 +518,7 @@ void VisualSceneMeshDoctor :: UpdateTables () edgedist.SetSize(mesh->GetNP()); int i, changed; - for (i = 1; i <= mesh->GetNP(); i++) - edgedist.Elem(i) = 10000; + edgedist = 10000; for (i = 1; i <= mesh->GetNSeg(); i++) { @@ -527,8 +526,8 @@ void VisualSceneMeshDoctor :: UpdateTables () if ( (seg[0] == selpoint && seg[1] == selpoint2) || (seg[1] == selpoint && seg[0] == selpoint2) ) { - edgedist.Elem(selpoint) = 1; - edgedist.Elem(selpoint2) = 1; + edgedist[selpoint] = 1; + edgedist[selpoint2] = 1; } } @@ -540,17 +539,17 @@ void VisualSceneMeshDoctor :: UpdateTables () { const Segment & seg = mesh->LineSegment(i); - int edist = min2 (edgedist.Get(seg[0]), edgedist.Get(seg[1])); + int edist = min2 (edgedist[seg[0]], edgedist[seg[1]]); edist++; - if (edgedist.Get(seg[0]) > edist) + if (edgedist[seg[0]] > edist) { - edgedist.Elem(seg[0]) = edist; + edgedist[seg[0]] = edist; changed = 1; } - if (edgedist.Get(seg[1]) > edist) + if (edgedist[seg[1]] > edist) { - edgedist.Elem(seg[1]) = edist; + edgedist[seg[1]] = edist; changed = 1; } } @@ -561,8 +560,8 @@ void VisualSceneMeshDoctor :: UpdateTables () int VisualSceneMeshDoctor :: IsSegmentMarked (int segnr) const { const Segment & seg = mesh->LineSegment(segnr); - return (edgedist.Get(seg[0]) <= markedgedist && - edgedist.Get(seg[1]) <= markedgedist); + return (edgedist[seg[0]] <= markedgedist && + edgedist[seg[1]] <= markedgedist); } } diff --git a/libsrc/visualization/meshdoc.hpp b/libsrc/visualization/meshdoc.hpp index 7fce2772..9e3bd9de 100644 --- a/libsrc/visualization/meshdoc.hpp +++ b/libsrc/visualization/meshdoc.hpp @@ -9,10 +9,10 @@ class VisualSceneMeshDoctor : public VisualScene int edgelist; int selelement, locpi; - int selpoint, selpoint2; + PointIndex selpoint, selpoint2; // for edgemarking: - NgArray edgedist; + Array edgedist; int markedgedist; diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index f73a4cce..0e45aa12 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -292,11 +292,11 @@ namespace netgen center.Y() = vispar.centery; center.Z() = vispar.centerz; } - else if (selpoint >= 1 && zoomall==2) + else if (selpoint-IndexBASE() >= 1 && zoomall==2) center = mesh->Point (selpoint); else if (marker && zoomall==2) center = *marker; - else if (vispar.centerpoint >= 1 && zoomall==2) + else if (vispar.centerpoint-IndexBASE() >= 0 && zoomall==2) center = mesh->Point (vispar.centerpoint); else center = Center (pmin, pmax); diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 4634e46e..446488df 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -232,7 +232,7 @@ namespace netgen << "DATASET UNSTRUCTURED_GRID\n\n"; surf_ost << "POINTS " << mesh->GetNP() << " float\n"; - for (PointIndex pi = PointIndex::BASE; pi < mesh->GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); pi < mesh->GetNP()+IndexBASE(); pi++) { const MeshPoint & mp = (*mesh)[pi]; surf_ost << mp(0) << " " << mp(1) << " " << mp(2) << "\n"; @@ -275,7 +275,7 @@ namespace netgen << "DATASET UNSTRUCTURED_GRID\n\n"; ost << "POINTS " << mesh->GetNP() << " float\n"; - for (PointIndex pi = PointIndex::BASE; pi < mesh->GetNP()+PointIndex::BASE; pi++) + for (PointIndex pi = IndexBASE(); pi < mesh->GetNP()+IndexBASE(); pi++) { const MeshPoint & mp = (*mesh)[pi]; ost << mp(0) << " " << mp(1) << " " << mp(2) << "\n"; @@ -3891,12 +3891,13 @@ namespace netgen return def; } - void VisualSceneSolution :: GetPointDeformation (int pnum, Point<3> & p, + void VisualSceneSolution :: GetPointDeformation (PointIndex pnum, Point<3> & p, SurfaceElementIndex elnr) const { shared_ptr mesh = GetMesh(); - - p = mesh->Point (pnum+1); + auto pnum_ = pnum-IndexBASE(); + + p = mesh->Point (pnum); if (deform && vecfunction != -1) { const SolData * vsol = soldata[vecfunction]; @@ -3904,15 +3905,15 @@ namespace netgen Vec<3> v(0,0,0); if (vsol->soltype == SOL_NODAL) { - v = Vec3d(vsol->data[pnum * vsol->dist], - vsol->data[pnum * vsol->dist+1], - vsol->data[pnum * vsol->dist+2]); + v = Vec3d(vsol->data[pnum_ * vsol->dist], + vsol->data[pnum_ * vsol->dist+1], + vsol->data[pnum_ * vsol->dist+2]); } else if (vsol->soltype == SOL_SURFACE_NONCONTINUOUS) { const Element2d & el = (*mesh)[elnr]; for (int j = 0; j < el.GetNP(); j++) - if (el[j] == pnum+1) + if (el[j] == pnum) { int base = (4*elnr+j-1) * vsol->dist; v = Vec3d(vsol->data[base], diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index 011ec53f..479455b6 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -319,7 +319,7 @@ private: Vec<3> GetDeformation (ElementIndex elnr, const Point<3> & p) const; Vec<3> GetSurfDeformation (SurfaceElementIndex selnr, int facetnr, double lam1, double lam2) const; - void GetPointDeformation (int pnum, Point<3> & p, SurfaceElementIndex elnr = -1) const; + void GetPointDeformation (PointIndex pnum, Point<3> & p, SurfaceElementIndex elnr = -1) const; public: /// draw elements (build lists) diff --git a/tests/catch/array.cpp b/tests/catch/array.cpp index c21aa800..63011533 100644 --- a/tests/catch/array.cpp +++ b/tests/catch/array.cpp @@ -70,12 +70,12 @@ TEST_CASE("Array") // pointindex is still 1 based Array piarray(2); - i = 1; + netgen::PointIndex pi = IndexBASE(); for(auto j : Range(piarray)) - CHECK(j == i++); - i = 1; + CHECK(j == pi++); + pi = IndexBASE(); for(auto j : piarray.Range()) - CHECK(j == i++); + CHECK(j == pi++); // a class can implement index_type and Size as well. ClsWithIndexType clsi(3); CHECK(typeid(Range(clsi)) == typeid(T_Range));