From 780e72bf815db6f71888bdc02f0552b54c3ef63f Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Mon, 21 Jun 2021 08:36:14 +0200 Subject: [PATCH] copyable 2d rules --- libsrc/csg/genmesh.cpp | 2 +- libsrc/general/optmem.cpp | 2 +- libsrc/meshing/meshing2.cpp | 16 +++++++++++----- libsrc/meshing/meshing2.hpp | 2 +- libsrc/meshing/netrule2.cpp | 8 +++++--- libsrc/meshing/parser2.cpp | 17 ++++++++++------- libsrc/meshing/ruler2.cpp | 2 +- libsrc/meshing/ruler2.hpp | 8 ++++---- 8 files changed, 34 insertions(+), 23 deletions(-) diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 5a579ed9..be872b03 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -517,7 +517,7 @@ namespace netgen } if (multithread.terminate) return; - + for (SurfaceElementIndex sei = oldnf; sei < mesh.GetNSE(); sei++) mesh[sei].SetIndex (k); diff --git a/libsrc/general/optmem.cpp b/libsrc/general/optmem.cpp index 0b84decb..931fc52a 100644 --- a/libsrc/general/optmem.cpp +++ b/libsrc/general/optmem.cpp @@ -29,7 +29,7 @@ namespace netgen BlockAllocator :: ~BlockAllocator () { lock_guard guard(block_allocator_mutex); - // cout << "****************** delete BlockAllocator " << endl; + cout << "****************** delete BlockAllocator " << endl; for (int i = 0; i < bablocks.Size(); i++) delete [] bablocks[i]; bablocks.SetSize(0); diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index 0bc6b6c6..974f76b1 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -53,15 +53,21 @@ namespace netgen if (!globalrules.Size()) { LoadRules (NULL, mp.quad); - for (auto * rule : rules) - globalrules.Append (unique_ptr(rule)); + for (auto & rule : rules) + globalrules.Append (make_unique(*rule)); + rules.SetSize(0); } + /* else { for (auto i : globalrules.Range()) rules.Append (globalrules[i].get()); } + */ } + for (auto i : globalrules.Range()) + rules.Append (make_unique(*globalrules[i])); + // LoadRules ("rules/quad.rls"); // LoadRules ("rules/triangle.rls"); @@ -458,7 +464,7 @@ namespace netgen { (*testout) << foundmap.Get(i) << "/" << canuse.Get(i) << "/" - << ruleused.Get(i) << " map/can/use rule " << rules.Get(i)->Name() << "\n"; + << ruleused.Get(i) << " map/can/use rule " << rules[i-1]->Name() << "\n"; } (*testout) << "\n"; } @@ -1475,7 +1481,7 @@ namespace netgen if ( debugparam.haltsuccess || debugflag ) { // adfront.PrintOpenSegments (*testout); - cout << "success of rule" << rules.Get(rulenr)->Name() << endl; + cout << "success of rule" << rules[rulenr-1]->Name() << endl; multithread.drawing = 1; multithread.testmode = 1; multithread.pause = 1; @@ -1491,7 +1497,7 @@ namespace netgen } */ - (*testout) << "success of rule" << rules.Get(rulenr)->Name() << endl; + (*testout) << "success of rule" << rules[rulenr-1]->Name() << endl; (*testout) << "trials = " << trials << endl; (*testout) << "locpoints " << endl; diff --git a/libsrc/meshing/meshing2.hpp b/libsrc/meshing/meshing2.hpp index dfaa06ab..8eb233a4 100644 --- a/libsrc/meshing/meshing2.hpp +++ b/libsrc/meshing/meshing2.hpp @@ -31,7 +31,7 @@ class Meshing2 /// the current advancing front AdFront2 adfront; /// rules for mesh generation - NgArray rules; + Array> rules; /// statistics NgArray ruleused, canuse, foundmap; /// diff --git a/libsrc/meshing/netrule2.cpp b/libsrc/meshing/netrule2.cpp index a5c35761..dc916e23 100644 --- a/libsrc/meshing/netrule2.cpp +++ b/libsrc/meshing/netrule2.cpp @@ -13,11 +13,13 @@ netrule :: netrule () netrule :: ~netrule() { - delete [] name; + // delete [] name; + /* for(int i = 0; i < oldutofreearea_i.Size(); i++) delete oldutofreearea_i[i]; for(int i = 0; i < freezone_i.Size(); i++) delete freezone_i[i]; + */ } @@ -37,9 +39,9 @@ void netrule :: SetFreeZoneTransformation (const Vector & devp, int tolclass) if (tolclass <= oldutofreearea_i.Size()) { - oldutofreearea_i[tolclass-1] -> Mult (devp, devfree); + oldutofreearea_i[tolclass-1].Mult (devp, devfree); - auto& fzi = *freezone_i[tolclass-1]; + auto& fzi = freezone_i[tolclass-1]; for (int i = 0; i < fzs; i++) { transfreezone[i][0] = fzi[i][0] + devfree[2*i]; diff --git a/libsrc/meshing/parser2.cpp b/libsrc/meshing/parser2.cpp index eb8e76cf..a0fffaff 100644 --- a/libsrc/meshing/parser2.cpp +++ b/libsrc/meshing/parser2.cpp @@ -60,10 +60,13 @@ void netrule :: LoadRule (istream & ist) ist.get (buf, sizeof(buf), '"'); ist.get (ch); - // if(name != NULL) + // if(name != NULL) + /* delete [] name; name = new char[strlen (buf) + 1]; strcpy (name, buf); + */ + name = string(buf); //(*testout) << "name " << name << endl; // (*mycout) << "Rule " << name << " found." << endl; @@ -474,14 +477,14 @@ void netrule :: LoadRule (istream & ist) { double lam1 = 1.0/(i+1); - oldutofreearea_i[i] = new DenseMatrix (oldutofreearea.Height(), oldutofreearea.Width()); - DenseMatrix & mati = *oldutofreearea_i[i]; + oldutofreearea_i[i] = move(DenseMatrix (oldutofreearea.Height(), oldutofreearea.Width())); + DenseMatrix & mati = oldutofreearea_i[i]; for (j = 0; j < oldutofreearea.Height(); j++) for (int k = 0; k < oldutofreearea.Width(); k++) mati(j,k) = lam1 * oldutofreearea(j,k) + (1 - lam1) * oldutofreearealimit(j,k); - freezone_i[i] = new NgArray> (freezone.Size()); - auto& fzi = *freezone_i[i]; + freezone_i[i] = NgArray> (freezone.Size()); + auto& fzi = freezone_i[i]; for (int j = 0; j < freezone.Size(); j++) fzi[j] = freezonelimit[j] + lam1 * (freezone[j] - freezonelimit[j]); } @@ -589,12 +592,12 @@ void Meshing2 :: LoadRules (const char * filename, bool quad) if (strcmp (buf, "rule") == 0) { //(*testout) << "found rule" << endl; - netrule * rule = new netrule; + auto rule = make_unique(); //(*testout) << "fr1" << endl; rule -> LoadRule(*ist); //(*testout) << "fr2" << endl; - rules.Append (rule); + rules.Append (move(rule)); } //(*testout) << "loop" << endl; } diff --git a/libsrc/meshing/ruler2.cpp b/libsrc/meshing/ruler2.cpp index f744fb89..cafecd90 100644 --- a/libsrc/meshing/ruler2.cpp +++ b/libsrc/meshing/ruler2.cpp @@ -209,7 +209,7 @@ namespace netgen for (int ri = 1; ri <= rules.Size(); ri++) { // NgProfiler::RegionTimer reg(timers[ri-1]); - netrule * rule = rules.Get(ri); + netrule * rule = rules[ri-1].get(); #ifdef LOCDEBUG if (loctestmode) diff --git a/libsrc/meshing/ruler2.hpp b/libsrc/meshing/ruler2.hpp index d300c82d..3d9ca6af 100644 --- a/libsrc/meshing/ruler2.hpp +++ b/libsrc/meshing/ruler2.hpp @@ -21,7 +21,7 @@ private: /// int quality; /// - char * name; + string name; /// NgArray> points; /// @@ -29,7 +29,7 @@ private: /// NgArray> freezone, freezonelimit; /// - NgArray>*> freezone_i; + NgArray>> freezone_i; /// NgArray> transfreezone; @@ -44,7 +44,7 @@ private: /// DenseMatrix oldutonewu, oldutofreearea, oldutofreearealimit; /// - NgArray oldutofreearea_i; + NgArray oldutofreearea_i; /// MatrixFixWidth<3> freesetinequ; @@ -154,7 +154,7 @@ public: /// const DenseMatrix & GetOldUToFreeArea () const { return oldutofreearea; } /// - const char * Name () const { return name; } + const string & Name () const { return name; } /// void LoadRule (istream & ist);