diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 4a9c4a2a..5a579ed9 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -10,15 +10,19 @@ namespace netgen { - NgArray specpoints; - static NgArray spoints; + NgArray global_specpoints; // for visualization + //static NgArray spoints; + #define TCL_OK 0 #define TCL_ERROR 1 - static void FindPoints (CSGeometry & geom, Mesh & mesh) + static void FindPoints (CSGeometry & geom, + NgArray & specpoints, + NgArray & spoints, + Mesh & mesh) { PrintMessage (1, "Start Findpoints"); @@ -48,7 +52,13 @@ namespace netgen PrintMessage (2, "Analyze spec points"); spc.AnalyzeSpecialPoints (geom, spoints, specpoints); - + + { + static mutex mut; + lock_guard guard(mut); + global_specpoints = specpoints; + } + PrintMessage (5, "done"); (*testout) << specpoints.Size() << " special points:" << endl; @@ -67,7 +77,10 @@ namespace netgen - static void FindEdges (CSGeometry & geom, Mesh & mesh, MeshingParameters & mparam, + static void FindEdges (CSGeometry & geom, Mesh & mesh, + NgArray & specpoints, + NgArray & spoints, + MeshingParameters & mparam, const bool setmeshsize = false) { EdgeCalculation ec (geom, specpoints, mparam); @@ -669,6 +682,10 @@ namespace netgen int CSGGenerateMesh (CSGeometry & geom, shared_ptr & mesh, MeshingParameters & mparam) { + NgArray specpoints; + NgArray spoints; + + if (mesh && mesh->GetNSE() && !geom.GetNSolids()) { @@ -705,7 +722,7 @@ namespace netgen } spoints.SetSize(0); - FindPoints (geom, *mesh); + FindPoints (geom, specpoints, spoints, *mesh); PrintMessage (5, "find points done"); @@ -723,7 +740,7 @@ namespace netgen if (mparam.perfstepsstart <= MESHCONST_MESHEDGES) { - FindEdges (geom, *mesh, mparam, true); + FindEdges (geom, *mesh, specpoints, spoints, mparam, true); if (multithread.terminate) return TCL_OK; #ifdef LOG_STREAM (*logout) << "Edges meshed" << endl @@ -740,16 +757,16 @@ namespace netgen mesh->CalcLocalH(mparam.grading); mesh->DeleteMesh(); - FindPoints (geom, *mesh); + FindPoints (geom, specpoints, spoints, *mesh); if (multithread.terminate) return TCL_OK; - FindEdges (geom, *mesh, mparam, true); + FindEdges (geom, *mesh, specpoints, spoints, mparam, true); if (multithread.terminate) return TCL_OK; mesh->DeleteMesh(); - FindPoints (geom, *mesh); + FindPoints (geom, specpoints, spoints, *mesh); if (multithread.terminate) return TCL_OK; - FindEdges (geom, *mesh, mparam); + FindEdges (geom, *mesh, specpoints, spoints, mparam); if (multithread.terminate) return TCL_OK; } } diff --git a/libsrc/csg/specpoin.cpp b/libsrc/csg/specpoin.cpp index 835645d6..6eca64ba 100644 --- a/libsrc/csg/specpoin.cpp +++ b/libsrc/csg/specpoin.cpp @@ -21,7 +21,7 @@ namespace netgen { - NgArray > boxes; + NgArray > boxes; // for visualizaton void ProjectToEdge (const Surface * f1, const Surface * f2, Point<3> & hp); @@ -64,7 +64,7 @@ namespace netgen } - static NgArray numprim_hist; + // static NgArray numprim_hist; SpecialPointCalculation :: SpecialPointCalculation () { @@ -75,8 +75,8 @@ namespace netgen CalcSpecialPoints (const CSGeometry & ageometry, NgArray & apoints) { - static int timer = NgProfiler::CreateTimer ("CSG: find special points"); - NgProfiler::RegionTimer reg (timer); + // static int timer = NgProfiler::CreateTimer ("CSG: find special points"); + // NgProfiler::RegionTimer reg (timer); geometry = &ageometry; @@ -100,8 +100,8 @@ namespace netgen box.CalcDiamCenter(); PrintMessage (3, "main-solids: ", geometry->GetNTopLevelObjects()); - numprim_hist.SetSize (geometry->GetNSurf()+1); - numprim_hist = 0; + // numprim_hist.SetSize (geometry->GetNSurf()+1); + // numprim_hist = 0; for (int i = 0; i < geometry->GetNTopLevelObjects(); i++) { @@ -161,10 +161,12 @@ namespace netgen PrintMessage (3, "Found points ", apoints.Size()); + /* for (int i = 0; i < boxesinlevel.Size(); i++) (*testout) << "level " << i << " has " << boxesinlevel[i] << " boxes" << endl; (*testout) << "numprim_histogramm = " << endl << numprim_hist << endl; + */ } @@ -184,8 +186,8 @@ namespace netgen if (multithread.terminate) { - *testout << "boxes = " << boxes << endl; - *testout << "boxesinlevel = " << boxesinlevel << endl; + // *testout << "boxes = " << boxes << endl; + // *testout << "boxesinlevel = " << boxesinlevel << endl; throw NgException ("Meshing stopped"); } @@ -215,12 +217,13 @@ namespace netgen // static int cntbox = 0; // cntbox++; - + /* if (level <= boxesinlevel.Size()) boxesinlevel.Elem(level)++; else boxesinlevel.Append (1); - + */ + /* numprim = sol -> NumPrimitives(); sol -> GetSurfaceIndices (locsurf); @@ -233,7 +236,7 @@ namespace netgen (*testout) << "numprim = " << numprim << endl; #endif - numprim_hist[numprim]++; + // numprim_hist[numprim]++; Point<3> p = box.Center(); diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index f34e9289..4178e4bb 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -18,7 +18,9 @@ namespace netgen /* *********************** Draw Geometry **************** */ extern shared_ptr mesh; - extern NgArray specpoints; + extern NgArray global_specpoints; + NgArray & specpoints = global_specpoints; + extern NgArray > boxes; diff --git a/libsrc/general/optmem.cpp b/libsrc/general/optmem.cpp index a9c5e440..0b84decb 100644 --- a/libsrc/general/optmem.cpp +++ b/libsrc/general/optmem.cpp @@ -28,6 +28,7 @@ namespace netgen BlockAllocator :: ~BlockAllocator () { + lock_guard guard(block_allocator_mutex); // cout << "****************** delete BlockAllocator " << endl; for (int i = 0; i < bablocks.Size(); i++) delete [] bablocks[i]; diff --git a/libsrc/gprim/adtree.cpp b/libsrc/gprim/adtree.cpp index 2f5ac117..a3ecdf28 100644 --- a/libsrc/gprim/adtree.cpp +++ b/libsrc/gprim/adtree.cpp @@ -400,23 +400,23 @@ namespace netgen const float * bmax, NgArray & pis) const { - static NgArray stack(1000); - static NgArray stackdir(1000); + ArrayMem stack(1000); + ArrayMem stackdir(1000); ADTreeNode3 * node; int dir, stacks; - stack.SetSize (1000); - stackdir.SetSize(1000); + // stack.SetSize (1000); + // stackdir.SetSize(1000); pis.SetSize(0); - stack.Elem(1) = root; - stackdir.Elem(1) = 0; - stacks = 1; + stack[0] = root; + stackdir[0] = 0; + stacks = 0; - while (stacks) + while (stacks >= 0) { - node = stack.Get(stacks); - dir = stackdir.Get(stacks); + node = stack[stacks]; + dir = stackdir[stacks]; stacks--; if (node->pi != -1) @@ -436,14 +436,14 @@ namespace netgen if (node->left && bmin[dir] <= node->sep) { stacks++; - stack.Elem(stacks) = node->left; - stackdir.Elem(stacks) = ndir; + stack[stacks] = node->left; + stackdir[stacks] = ndir; } if (node->right && bmax[dir] >= node->sep) { stacks++; - stack.Elem(stacks) = node->right; - stackdir.Elem(stacks) = ndir; + stack[stacks] = node->right; + stackdir[stacks] = ndir; } } } diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index edf4770d..0bc6b6c6 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -46,17 +46,22 @@ namespace netgen static Timer t("Mesing2::Meshing2"); RegionTimer r(t); auto & globalrules = mp.quad ? global_quad_rules : global_trig_rules; - if (!globalrules.Size()) - { - LoadRules (NULL, mp.quad); - for (auto * rule : rules) - globalrules.Append (unique_ptr(rule)); - } - else - { - for (auto i : globalrules.Range()) - rules.Append (globalrules[i].get()); - } + + { + static mutex mut; + lock_guard guard(mut); + if (!globalrules.Size()) + { + LoadRules (NULL, mp.quad); + for (auto * rule : rules) + globalrules.Append (unique_ptr(rule)); + } + else + { + for (auto i : globalrules.Range()) + rules.Append (globalrules[i].get()); + } + } // LoadRules ("rules/quad.rls"); // LoadRules ("rules/triangle.rls");