From fd0421d573e42dd72a3de85cd133326b55f23d48 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sun, 29 Dec 2024 17:23:35 +0100 Subject: [PATCH] more ngcore arrays --- libsrc/core/hashtable.hpp | 12 ++++---- libsrc/meshing/meshing3.cpp | 48 ++++++++++++++++++----------- libsrc/meshing/meshing3.hpp | 6 ++-- libsrc/meshing/parser3.cpp | 5 +-- libsrc/meshing/ruler3.cpp | 61 +++++++++++++++++++------------------ 5 files changed, 75 insertions(+), 57 deletions(-) diff --git a/libsrc/core/hashtable.hpp b/libsrc/core/hashtable.hpp index 0add45f0..af27155c 100644 --- a/libsrc/core/hashtable.hpp +++ b/libsrc/core/hashtable.hpp @@ -300,7 +300,7 @@ namespace ngcore template - NETGEN_INLINE size_t HashValue2 (const IVec & ind, size_t mask) + NETGEN_INLINE constexpr size_t HashValue2 (const IVec & ind, size_t mask) { IVec lind = ind; size_t sum = 0; @@ -311,14 +311,14 @@ namespace ngcore /// hash value of 1 int template - NETGEN_INLINE size_t HashValue2 (const IVec<1,TI> & ind, size_t mask) + NETGEN_INLINE constexpr size_t HashValue2 (const IVec<1,TI> & ind, size_t mask) { return ind[0] & mask; } /// hash value of 2 int template - NETGEN_INLINE size_t HashValue2 (const IVec<2,TI> & ind, size_t mask) + NETGEN_INLINE constexpr size_t HashValue2 (const IVec<2,TI> & ind, size_t mask) { IVec<2,size_t> lind = ind; return (113*lind[0]+lind[1]) & mask; @@ -326,17 +326,17 @@ namespace ngcore /// hash value of 3 int template - NETGEN_INLINE size_t HashValue2 (const IVec<3,TI> & ind, size_t mask) + NETGEN_INLINE constexpr size_t HashValue2 (const IVec<3,TI> & ind, size_t mask) { IVec<3,size_t> lind = ind; return (113*lind[0]+59*lind[1]+lind[2]) & mask; } - NETGEN_INLINE size_t HashValue2 (size_t ind, size_t mask) + NETGEN_INLINE constexpr size_t HashValue2 (size_t ind, size_t mask) { return ind & mask; } - NETGEN_INLINE size_t HashValue2 (int ind, size_t mask) + NETGEN_INLINE constexpr size_t HashValue2 (int ind, size_t mask) { return size_t(ind) & mask; } diff --git a/libsrc/meshing/meshing3.cpp b/libsrc/meshing/meshing3.cpp index 80ed0225..57e19d49 100644 --- a/libsrc/meshing/meshing3.cpp +++ b/libsrc/meshing/meshing3.cpp @@ -31,6 +31,7 @@ Meshing3 :: Meshing3 (const string & rulefilename) canuse.SetSize (rules.Size()); ruleused.SetSize (rules.Size()); + /* for (int i = 1; i <= rules.Size(); i++) { problems.Elem(i) = new char[255]; @@ -38,6 +39,11 @@ Meshing3 :: Meshing3 (const string & rulefilename) canuse.Elem(i) = 0; ruleused.Elem(i) = 0; } + */ + + foundmap = 0; + canuse = 0; + ruleused = 0; } @@ -53,6 +59,7 @@ Meshing3 :: Meshing3 (const char ** rulep) canuse.SetSize (rules.Size()); ruleused.SetSize (rules.Size()); + /* for (int i = 0; i < rules.Size(); i++) { problems[i] = new char[255]; @@ -60,16 +67,22 @@ Meshing3 :: Meshing3 (const char ** rulep) canuse[i] = 0; ruleused[i] = 0; } + */ + foundmap = 0; + canuse = 0; + ruleused = 0; } Meshing3 :: ~Meshing3 () { // delete adfront; + /* for (int i = 0; i < rules.Size(); i++) { delete [] problems[i]; delete rules[i]; } + */ } @@ -184,12 +197,13 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) Array locpoints; // local points Array locfaces; // local faces Array pindex; // mapping from local to front point numbering - Array allowpoint; // point is allowed ? + Array allowpoint; // point is allowed (0/1/2) ? Array findex; // mapping from local to front face numbering //INDEX_2_HASHTABLE connectedpairs(100); // connecgted pairs for prism meshing Array plainpoints; // points in reference coordinates - NgArray delpoints, delfaces; // points and lines to be deleted + // NgArray delpoints; // points to be deleted + NgArray delfaces; // lines to be deleted NgArray locelements; // new generated elements int j, oldnp, oldnf; @@ -378,9 +392,9 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) { (*testout) << "inner point found" << endl; - for(int i = 1; i <= groupfaces.Size(); i++) - adfront -> DeleteFace (groupfindex[i-1]); - + for(int i = 0; i < groupfaces.Size(); i++) + adfront -> DeleteFace (groupfindex[i]); + for(int i = 1; i <= groupfaces.Size(); i++) for (j = 1; j <= locfaces.Size(); j++) if (findex[j-1] == groupfindex[i-1]) @@ -469,12 +483,12 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) if (stat.cnttrials % 100 == 0) { (*testout) << "\n"; - for(int i = 1; i <= canuse.Size(); i++) - { - (*testout) << foundmap.Get(i) << "/" - << canuse.Get(i) << "/" - << ruleused.Get(i) << " map/can/use rule " << rules.Get(i)->Name() << "\n"; - } + for(int i : canuse.Range()) + { + (*testout) << foundmap[i] << "/" + << canuse[i] << "/" + << ruleused[i] << " map/can/use rule " << rules[i]->Name() << "\n"; + } (*testout) << endl; } @@ -545,8 +559,8 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) if (found) - ruleused.Elem(found)++; - + ruleused[found-1]++; + // plotstat->Plot(stat); @@ -710,7 +724,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) } locelements.SetSize (0); - delpoints.SetSize(0); + // delpoints.SetSize(0); delfaces.SetSize(0); if (stat.qualclass >= mp.giveuptol) @@ -719,9 +733,9 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) PrintMessage (5, ""); // line feed after statistics - for(int i = 1; i <= ruleused.Size(); i++) - (*testout) << setw(4) << ruleused.Get(i) - << " times used rule " << rules.Get(i) -> Name() << endl; + for(int i : ruleused.Range()) + (*testout) << setw(4) << ruleused[i] + << " times used rule " << rules[i] -> Name() << endl; if (!mp.baseelnp && adfront->Empty()) diff --git a/libsrc/meshing/meshing3.hpp b/libsrc/meshing/meshing3.hpp index 36f8c142..4b7e1082 100644 --- a/libsrc/meshing/meshing3.hpp +++ b/libsrc/meshing/meshing3.hpp @@ -24,11 +24,11 @@ class Meshing3 /// current state of front unique_ptr adfront; /// 3d generation rules - NgArray rules; + Array> rules; /// counts how often a rule is used - NgArray ruleused, canuse, foundmap; + Array ruleused, canuse, foundmap; /// describes, why a rule is not applied - NgArray problems; + Array problems; /// tolerance criterion double tolfak; public: diff --git a/libsrc/meshing/parser3.cpp b/libsrc/meshing/parser3.cpp index 0eeee374..bb18dad3 100644 --- a/libsrc/meshing/parser3.cpp +++ b/libsrc/meshing/parser3.cpp @@ -1014,14 +1014,15 @@ void Meshing3 :: LoadRules (const char * filename, const char ** prules) if (strcmp (buf, "rule") == 0) { - vnetrule * rule = new vnetrule; + // vnetrule * rule = new vnetrule; + auto rule = make_unique(); rule -> LoadRule(*ist); - rules.Append (rule); if (!rule->TestOk()) { PrintSysError ("Parser3d: Rule ", rules.Size(), " not ok"); exit (1); } + rules.Append (std::move(rule)); } else if (strcmp (buf, "tolfak") == 0) { diff --git a/libsrc/meshing/ruler3.cpp b/libsrc/meshing/ruler3.cpp index 73e3009e..959fe310 100644 --- a/libsrc/meshing/ruler3.cpp +++ b/libsrc/meshing/ruler3.cpp @@ -226,16 +226,17 @@ int Meshing3 :: ApplyRules // check each rule: // tstart.Stop(); // tloop.Start(); - for (int ri = 1; ri <= rules.Size(); ri++) + for (int rim = 0; rim < rules.Size(); rim++) { int base = (lfaces[0].GetNP() == 3) ? 100 : 200; NgProfiler::RegionTimer regx1(base); - NgProfiler::RegionTimer regx(base+ri); + NgProfiler::RegionTimer regx(base+rim+1); // sprintf (problems.Elem(ri), ""); - *problems.Elem(ri) = '\0'; + // *problems.Elem(ri) = '\0'; + problems[rim] = ""; - vnetrule * rule = rules.Get(ri); + vnetrule * rule = rules[rim].get(); if (rule->GetNP(1) != lfaces[0].GetNP()) continue; @@ -245,17 +246,17 @@ int Meshing3 :: ApplyRules if (rule->GetQuality() < 100) impossible = 0; if (testmode) - snprintf (problems.Elem(ri), 255, "Quality not ok"); + problems[rim] = "Quality not ok"; continue; } if (testmode) - snprintf (problems.Elem(ri), 255, "no mapping found"); + problems[rim] = "no mapping found"; loktestmode = testmode || rule->TestFlag ('t') || tolerance > 5; if (loktestmode) - (*testout) << "Rule " << ri << " = " << rule->Name() << endl; + (*testout) << "Rule " << rim+1 << " = " << rule->Name() << endl; pmap.SetSize (rule->GetNP()); fmapi.SetSize (rule->GetNF()); @@ -287,7 +288,7 @@ int Meshing3 :: ApplyRules int nfok = 2; NgProfiler::RegionTimer regfa(300); - NgProfiler::RegionTimer regx2(base+50+ri); + NgProfiler::RegionTimer regx2(base+50+rim+1); while (nfok >= 2) { @@ -419,7 +420,7 @@ int Meshing3 :: ApplyRules if (loktestmode) { (*testout) << "Faces Ok" << endl; - snprintf (problems.Elem(ri), 255, "Faces Ok"); + problems[rim] = "Faces Ok"; } int npok = 1; @@ -527,7 +528,7 @@ int Meshing3 :: ApplyRules for (auto pi : pmap) (*testout) << pi << " "; (*testout) << endl; - snprintf (problems.Elem(ri), 255, "mapping found"); + problems[rim] = "mapping found"; (*testout) << rule->GetNP(1) << " = " << lfaces[0].GetNP() << endl; } @@ -594,10 +595,7 @@ int Meshing3 :: ApplyRules if (ok) - { - foundmap.Elem(ri)++; - } - + foundmap[rim]++; @@ -642,7 +640,7 @@ int Meshing3 :: ApplyRules if (!rule->ConvexFreeZone()) { ok = 0; - snprintf (problems.Elem(ri), 255, "Freezone not convex"); + problems[rim] = "Freezone not convex"; if (loktestmode) (*testout) << "Freezone not convex" << endl; @@ -674,8 +672,7 @@ int Meshing3 :: ApplyRules { (*testout) << "Point " << i << " in Freezone" << endl; - snprintf (problems.Elem(ri), 255, - "locpoint %d in Freezone", int(i)); + problems[rim] = "locpoint " + ToString(i) + " in Freezone"; } ok = 0; break; @@ -788,10 +785,9 @@ int Meshing3 :: ApplyRules << lpoints[lfacei.PNum(4)] << endl; - snprintf (problems.Elem(ri), 255, "triangle (%d, %d, %d) in Freezone", - int(lfaces[i-1].PNum(1)), - int(lfaces[i-1].PNum(2)), - int(lfaces[i-1].PNum(3))); + problems[rim] = "triangle ("+ToString(lfaces[i-1].PNum(1))+", " + + ToString(lfaces[i-1].PNum(2)) + ", " + + ToString(lfaces[i-1].PNum(3)) + ") in Freezone"; } hc = 0; @@ -817,7 +813,7 @@ int Meshing3 :: ApplyRules // << " - " << pmap.Get (rule->GetPointNr(k, 3)) << " ) " // << endl; - strcpy (problems.Elem(ri), "other"); + problems[rim] = "other"; } } } @@ -831,10 +827,17 @@ int Meshing3 :: ApplyRules << lfaces[i-1].PNum(2) << " - " << lfaces[i-1].PNum(3) << endl; + /* snprintf (problems.Elem(ri), 255, "triangle (%d, %d, %d) in Freezone", int (lfaces[i-1].PNum(1)), int (lfaces[i-1].PNum(2)), int (lfaces[i-1].PNum(3))); + */ + problems[rim] = "triangle (" + + ToString(lfaces[i-1].PNum(1))+", " + + ToString(lfaces[i-1].PNum(2)) + ", " + + ToString(lfaces[i-1].PNum(3)) + ") in Freezone"; + } ok = 0; } @@ -858,7 +861,7 @@ int Meshing3 :: ApplyRules if (loktestmode) { (*testout) << "Rule ok" << endl; - snprintf (problems.Elem(ri), 255, "Rule ok, err = %f", err); + problems[rim] = "Rule ok, err = "+ToString(err); } @@ -923,7 +926,7 @@ int Meshing3 :: ApplyRules { if (loktestmode) { - snprintf (problems.Elem(ri), 255, "Orientation wrong"); + problems[rim] = "Orientation wrong"; (*testout) << "Orientation wrong ("<< n*v3 << ")" << endl; } ok = 0; @@ -940,7 +943,7 @@ int Meshing3 :: ApplyRules { (*testout) << "Newpoint " << lpoints[pmap.Get(i)] << " outside convex hull" << endl; - snprintf (problems.Elem(ri), 255, "newpoint outside convex hull"); + problems[rim] = "newpoint outside convex hull"; } ok = 0; @@ -1015,7 +1018,7 @@ int Meshing3 :: ApplyRules { ok = 0; if (loktestmode) - snprintf (problems.Elem(ri), 255, "oldlen < newlen"); + problems[rim] = "oldlen < newlen"; } } @@ -1028,7 +1031,7 @@ int Meshing3 :: ApplyRules if (ok && teterr < tolerance) { - canuse.Elem(ri) ++; + canuse[rim] ++; /* (*testout) << "can use rule " << rule->Name() << ", err = " << teterr << endl; @@ -1037,7 +1040,7 @@ int Meshing3 :: ApplyRules (*testout) << endl; */ - if (strcmp (problems.Elem(ri), "other") == 0) + if (problems[rim] == "other") { if (teterr < minother) minother = teterr; @@ -1058,7 +1061,7 @@ int Meshing3 :: ApplyRules if (loktestmode) (*testout) << "use rule" << endl; - found = ri; + found = rim+1; minteterr = teterr; if (testmode)