thread-safe CSG crosspoints and edges

This commit is contained in:
Joachim Schoeberl 2021-06-21 05:22:00 +02:00
parent b51df253fd
commit 30d708f487
6 changed files with 76 additions and 48 deletions

View File

@ -10,15 +10,19 @@
namespace netgen
{
NgArray<SpecialPoint> specpoints;
static NgArray<MeshPoint> spoints;
NgArray<SpecialPoint> global_specpoints; // for visualization
//static NgArray<MeshPoint> spoints;
#define TCL_OK 0
#define TCL_ERROR 1
static void FindPoints (CSGeometry & geom, Mesh & mesh)
static void FindPoints (CSGeometry & geom,
NgArray<SpecialPoint> & specpoints,
NgArray<MeshPoint> & spoints,
Mesh & mesh)
{
PrintMessage (1, "Start Findpoints");
@ -49,6 +53,12 @@ namespace netgen
PrintMessage (2, "Analyze spec points");
spc.AnalyzeSpecialPoints (geom, spoints, specpoints);
{
static mutex mut;
lock_guard<mutex> 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<SpecialPoint> & specpoints,
NgArray<MeshPoint> & 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> & mesh, MeshingParameters & mparam)
{
NgArray<SpecialPoint> specpoints;
NgArray<MeshPoint> 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;
}
}

View File

@ -21,7 +21,7 @@
namespace netgen
{
NgArray<Box<3> > boxes;
NgArray<Box<3> > boxes; // for visualizaton
void ProjectToEdge (const Surface * f1, const Surface * f2, Point<3> & hp);
@ -64,7 +64,7 @@ namespace netgen
}
static NgArray<int> numprim_hist;
// static NgArray<int> numprim_hist;
SpecialPointCalculation :: SpecialPointCalculation ()
{
@ -75,8 +75,8 @@ namespace netgen
CalcSpecialPoints (const CSGeometry & ageometry,
NgArray<MeshPoint> & 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,11 +217,12 @@ namespace netgen
// static int cntbox = 0;
// cntbox++;
/*
if (level <= boxesinlevel.Size())
boxesinlevel.Elem(level)++;
else
boxesinlevel.Append (1);
*/
/*
numprim = sol -> NumPrimitives();
@ -233,7 +236,7 @@ namespace netgen
(*testout) << "numprim = " << numprim << endl;
#endif
numprim_hist[numprim]++;
// numprim_hist[numprim]++;
Point<3> p = box.Center();

View File

@ -18,7 +18,9 @@ namespace netgen
/* *********************** Draw Geometry **************** */
extern shared_ptr<Mesh> mesh;
extern NgArray<SpecialPoint> specpoints;
extern NgArray<SpecialPoint> global_specpoints;
NgArray<SpecialPoint> & specpoints = global_specpoints;
extern NgArray<Box<3> > boxes;

View File

@ -28,6 +28,7 @@ namespace netgen
BlockAllocator :: ~BlockAllocator ()
{
lock_guard<mutex> guard(block_allocator_mutex);
// cout << "****************** delete BlockAllocator " << endl;
for (int i = 0; i < bablocks.Size(); i++)
delete [] bablocks[i];

View File

@ -400,23 +400,23 @@ namespace netgen
const float * bmax,
NgArray<int> & pis) const
{
static NgArray<ADTreeNode3*> stack(1000);
static NgArray<int> stackdir(1000);
ArrayMem<ADTreeNode3*, 1000> stack(1000);
ArrayMem<int, 1000> 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;
}
}
}

View File

@ -46,6 +46,10 @@ namespace netgen
static Timer t("Mesing2::Meshing2"); RegionTimer r(t);
auto & globalrules = mp.quad ? global_quad_rules : global_trig_rules;
{
static mutex mut;
lock_guard<mutex> guard(mut);
if (!globalrules.Size())
{
LoadRules (NULL, mp.quad);
@ -57,6 +61,7 @@ namespace netgen
for (auto i : globalrules.Range())
rules.Append (globalrules[i].get());
}
}
// LoadRules ("rules/quad.rls");
// LoadRules ("rules/triangle.rls");