From b981d45069a6b0f8c6e926dfad342dd40fc5f092 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Wed, 16 Oct 2024 19:32:43 +0200 Subject: [PATCH] enable periodic + closesurface identification on same boundaries --- libsrc/csg/identify.cpp | 36 ++++++++++++++++----------------- libsrc/csg/zrefine.cpp | 17 ++++++++-------- libsrc/general/hashtabl.hpp | 28 ++++++++++++++++++++++--- libsrc/meshing/meshclass.cpp | 4 ++-- libsrc/meshing/meshfunc.cpp | 4 ++-- libsrc/meshing/meshtype.cpp | 10 ++------- libsrc/meshing/meshtype.hpp | 4 ++-- libsrc/visualization/vsmesh.cpp | 9 +++++---- 8 files changed, 65 insertions(+), 47 deletions(-) diff --git a/libsrc/csg/identify.cpp b/libsrc/csg/identify.cpp index 08e7c027..41f03eff 100644 --- a/libsrc/csg/identify.cpp +++ b/libsrc/csg/identify.cpp @@ -396,15 +396,15 @@ void PeriodicIdentification :: IdentifyFaces (class Mesh & mesh) if (side == 1) { - if (mesh.GetIdentifications().Get (seg1[0], seg2[0]) && - mesh.GetIdentifications().Get (seg1[1], seg2[1])) + if (mesh.GetIdentifications().Used (seg1[0], seg2[0]) && + mesh.GetIdentifications().Used (seg1[1], seg2[1])) { foundother = 1; break; } - if (mesh.GetIdentifications().Get (seg1[0], seg2[1]) && - mesh.GetIdentifications().Get (seg1[1], seg2[0])) + if (mesh.GetIdentifications().Used (seg1[0], seg2[1]) && + mesh.GetIdentifications().Used (seg1[1], seg2[0])) { foundother = 1; break; @@ -412,15 +412,15 @@ void PeriodicIdentification :: IdentifyFaces (class Mesh & mesh) } else { - if (mesh.GetIdentifications().Get (seg2[0], seg1[0]) && - mesh.GetIdentifications().Get (seg2[1], seg1[1])) + if (mesh.GetIdentifications().Used (seg2[0], seg1[0]) && + mesh.GetIdentifications().Used (seg2[1], seg1[1])) { foundother = 1; break; } - if (mesh.GetIdentifications().Get (seg2[0], seg1[1]) && - mesh.GetIdentifications().Get (seg2[1], seg1[0])) + if (mesh.GetIdentifications().Used (seg2[0], seg1[1]) && + mesh.GetIdentifications().Used (seg2[1], seg1[0])) { foundother = 1; break; @@ -1168,15 +1168,15 @@ void CloseSurfaceIdentification :: IdentifyFaces (class Mesh & mesh) if (side == 1) { - if (mesh.GetIdentifications().Get (seg1[0], seg2[0]) && - mesh.GetIdentifications().Get (seg1[1], seg2[1])) + if (mesh.GetIdentifications().Used (seg1[0], seg2[0]) && + mesh.GetIdentifications().Used (seg1[1], seg2[1])) { foundother = 1; break; } - if (mesh.GetIdentifications().Get (seg1[0], seg2[1]) && - mesh.GetIdentifications().Get (seg1[1], seg2[0])) + if (mesh.GetIdentifications().Used (seg1[0], seg2[1]) && + mesh.GetIdentifications().Used (seg1[1], seg2[0])) { foundother = 1; break; @@ -1184,15 +1184,15 @@ void CloseSurfaceIdentification :: IdentifyFaces (class Mesh & mesh) } else { - if (mesh.GetIdentifications().Get (seg2[0], seg1[0]) && - mesh.GetIdentifications().Get (seg2[1], seg1[1])) + if (mesh.GetIdentifications().Used (seg2[0], seg1[0]) && + mesh.GetIdentifications().Used (seg2[1], seg1[1])) { foundother = 1; break; } - if (mesh.GetIdentifications().Get (seg2[0], seg1[1]) && - mesh.GetIdentifications().Get (seg2[1], seg1[0])) + if (mesh.GetIdentifications().Used (seg2[0], seg1[1]) && + mesh.GetIdentifications().Used (seg2[1], seg1[0])) { foundother = 1; break; @@ -1650,8 +1650,8 @@ BuildSurfaceElements (NgArray & segs, { const Segment & s1 = segs.Get(i1); const Segment & s2 = segs.Get(i2); - if (mesh.GetIdentifications().Get (s1[0], s2[1]) && - mesh.GetIdentifications().Get (s1[1], s2[0])) + if (mesh.GetIdentifications().Used (s1[0], s2[1]) && + mesh.GetIdentifications().Used (s1[1], s2[0])) { Element2d el(QUAD); el.PNum(1) = s1[0]; diff --git a/libsrc/csg/zrefine.cpp b/libsrc/csg/zrefine.cpp index 30594d5b..7af6d71f 100644 --- a/libsrc/csg/zrefine.cpp +++ b/libsrc/csg/zrefine.cpp @@ -121,7 +121,7 @@ namespace netgen { INDEX_2 edge(el.PNum(j), el.PNum(k)); edge.Sort(); - if (mesh.GetIdentifications().GetSymmetric (el.PNum(j), el.PNum(k))) + if (mesh.GetIdentifications().UsedSymmetric (el.PNum(j), el.PNum(k))) { int pi3 = 1, pi4 = 1; while (pi3 == j || pi3 == k) pi3++; @@ -157,8 +157,8 @@ namespace netgen INDEX_2 edge2(pi2, pi3); edge1.Sort(); edge2.Sort(); - if (mesh.GetIdentifications().GetSymmetric (pi1, pi4) && - mesh.GetIdentifications().GetSymmetric (pi2, pi3)) + if (mesh.GetIdentifications().UsedSymmetric (pi1, pi4) && + mesh.GetIdentifications().UsedSymmetric (pi2, pi3)) { //int p3 = el.PNum(pi3); //int p4 = el.PNum(pi4); @@ -186,7 +186,7 @@ namespace netgen INDEX_2 edge(el.PNum(j), el.PNum(k)); edge.Sort(); - if (mesh.GetIdentifications().GetSymmetric (el.PNum(j), el.PNum(k))) + if (mesh.GetIdentifications().UsedSymmetric (el.PNum(j), el.PNum(k))) { int pi3 = 6-j-k; int p3 = el.PNum(pi3); @@ -261,15 +261,16 @@ namespace netgen // if (mesh.GetIdentifications().HasIdentifiedPoints()) { - INDEX_2_HASHTABLE & identpts = + auto & identpts = mesh.GetIdentifications().GetIdentifiedPoints (); for (i = 1; i <= identpts.GetNBags(); i++) for (j = 1; j <= identpts.GetBagSize(i); j++) { - INDEX_2 pair; - int idnr; - identpts.GetData(i, j, pair, idnr); + INDEX_3 pair; + int dummy; + identpts.GetData(i, j, pair, dummy); + auto idnr = pair[2]; const CloseSurfaceIdentification * csid = dynamic_cast (geom->identifications.Get(idnr)); diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index ce13a7b7..110e4df4 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -414,9 +414,14 @@ public: int BagNr() const { return bagnr; } int Pos() const { return pos; } - void operator++ (int) + Iterator operator++ (int) + { + Iterator it(ht, bagnr, pos); + ++(*this); + return it; + } + Iterator& operator++() { - // cout << "begin Operator ++: bagnr = " << bagnr << " - pos = " << pos << endl; pos++; while (bagnr < ht.GetNBags() && pos == ht.GetBagSize(bagnr+1)) @@ -424,7 +429,12 @@ public: pos = 0; bagnr++; } - // cout << "end Operator ++: bagnr = " << bagnr << " - pos = " << pos << endl; + return *this; + } + + std::pair operator*() + { + return std::make_pair(ht.hash[bagnr][pos], ht.cont[bagnr][pos]); } bool operator != (int i) const @@ -446,6 +456,18 @@ public: return GetNBags(); } + Iterator begin () const + { + Iterator it(*this, 0, -1); + it++; + return it; + } + + int end() const + { + return GetNBags(); + } + void GetData (const Iterator & it, INDEX_3 & ahash, T & acont) const { diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index adad7339..00958203 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -6406,9 +6406,9 @@ namespace netgen mapped_points = false; // Add new points - for(auto [p1p2, idnr] : identpts) + for(auto [p1p2, dummy] : identpts) { - if(idnr != nr) + if(p1p2[2] != nr) continue; auto& ipts = inserted_points[{p1p2.I1(), p1p2.I2()}]; auto p1 = Point(p1p2.I1()); diff --git a/libsrc/meshing/meshfunc.cpp b/libsrc/meshing/meshfunc.cpp index 1111c491..b47ce478 100644 --- a/libsrc/meshing/meshfunc.cpp +++ b/libsrc/meshing/meshfunc.cpp @@ -560,8 +560,8 @@ namespace netgen el.SetIndex(m_.domain); mesh.AddVolumeElement(el); } - for(const auto& [p1p2, idnr] : m.GetIdentifications().GetIdentifiedPoints()) - mesh.GetIdentifications().Add(pmap[p1p2[0]], pmap[p1p2[1]], idnr); + for(const auto& [p1p2, dummy] : m.GetIdentifications().GetIdentifiedPoints()) + mesh.GetIdentifications().Add(pmap[p1p2[0]], pmap[p1p2[1]], p1p2[2]); for(auto i : Range(m.GetIdentifications().GetMaxNr())) { mesh.GetIdentifications().SetType(i+1, m.GetIdentifications().GetType(i+1)); diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index 7f49d334..5dfebfc7 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -2825,14 +2825,8 @@ namespace netgen Array Identifications :: GetPairs () const { Array pairs; - for (auto i : IntRange(1, identifiedpoints.GetNBags()+1)) - for (auto j : IntRange(1, identifiedpoints.GetBagSize(i)+1)) - { - INDEX_2 i2; - int nr; - identifiedpoints.GetData (i, j, i2, nr); - pairs.Append ({i2.I1(), i2.I2(), nr}); - } + for(auto [i3, dummy] : identifiedpoints_nr) + pairs.Append(i3); return pairs; } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 178dd471..c874e6fb 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1619,9 +1619,9 @@ namespace netgen // bool HasIdentifiedPoints() const { return identifiedpoints != nullptr; } /// - INDEX_2_HASHTABLE & GetIdentifiedPoints () + INDEX_3_HASHTABLE & GetIdentifiedPoints () { - return identifiedpoints; + return identifiedpoints_nr; } bool Used (PointIndex pi1, PointIndex pi2) diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index b1f3971d..17139387 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -858,16 +858,17 @@ namespace netgen { // if (mesh->GetIdentifications().HasIdentifiedPoints()) { - INDEX_2_HASHTABLE & idpts = + auto & idpts = mesh->GetIdentifications().GetIdentifiedPoints(); for (int i = 1; i <= idpts.GetNBags(); i++) for (int j = 1; j <= idpts.GetBagSize(i); j++) { - INDEX_2 pts; - int val; + INDEX_3 pts; + int dummy, val; - idpts.GetData (i, j, pts, val); + idpts.GetData (i, j, pts, dummy); + val = pts[2]; const Point3d & p1 = mesh->Point(pts.I1()); const Point3d & p2 = mesh->Point(pts.I2());