Mesh 3d domains in parallel

To get consistent results, copy the LocalH tree in BlockFillLocalH
This commit is contained in:
Matthias Hochsteger 2021-06-11 17:57:45 +02:00
parent 5e3505b897
commit 97623db219
5 changed files with 453 additions and 384 deletions

View File

@ -91,6 +91,45 @@ namespace netgen
delete root;
}
unique_ptr<LocalH> LocalH :: Copy ()
{
static Timer t("LocalH::Copy"); RegionTimer rt(t);
auto lh = make_unique<LocalH>(boundingbox, grading, dimension);
std::map<GradingBox*, GradingBox*> mapping;
lh->boxes.SetSize(boxes.Size());
for(auto i : boxes.Range())
{
lh->boxes[i] = new GradingBox();
auto & bnew = *lh->boxes[i];
auto & b = *boxes[i];
bnew.xmid[0] = b.xmid[0];
bnew.xmid[1] = b.xmid[1];
bnew.xmid[2] = b.xmid[2];
bnew.h2 = b.h2;
bnew.hopt = b.hopt;
bnew.flags = b.flags;
mapping[&b] = &bnew;
}
for(auto i : boxes.Range())
{
auto & bnew = *lh->boxes[i];
auto & b = *boxes[i];
for(auto k : Range(8))
{
if(b.childs[k])
bnew.childs[k] = mapping[b.childs[k]];
}
if(b.father)
bnew.father = mapping[b.father];
}
lh->root = mapping[root];
return lh;
}
void LocalH :: Delete ()
{
root->DeleteChilds();

View File

@ -98,6 +98,8 @@ namespace netgen
~LocalH();
///
unique_ptr<LocalH> Copy();
///
void Delete();
///
void DoArchive(Archive& ar);

View File

@ -10,80 +10,29 @@ namespace netgen
extern const char * pyramidrules2[];
extern const char * hexrules[];
// extern double teterrpow;
MESHING3_RESULT MeshVolume (const MeshingParameters & c_mp, Mesh& mesh3d)
void MeshDomain(Mesh & mesh3d, const MeshingParameters & c_mp, int k)
{
static Timer t("MeshVolume"); RegionTimer reg(t);
MeshingParameters mp = c_mp; // copy mp to change them here
int oldne;
int meshed;
NgArray<INDEX_2> connectednodes;
if (!mesh3d.HasLocalHFunction()) mesh3d.CalcLocalH(mp.grading);
mesh3d.Compress();
// mesh3d.PrintMemInfo (cout);
if (mp.checkoverlappingboundary)
if (mesh3d.CheckOverlappingBoundary())
throw NgException ("Stop meshing since boundary mesh is overlapping");
int nonconsist = 0;
for (int k = 1; k <= mesh3d.GetNDomains(); k++)
{
int oldne;
int meshed;
if(mp.only3D_domain_nr && mp.only3D_domain_nr !=k)
continue;
PrintMessage (3, "Check subdomain ", k, " / ", mesh3d.GetNDomains());
mesh3d.FindOpenElements(k);
/*
bool res = mesh3d.CheckOverlappingBoundary();
if (res)
{
PrintError ("Surface is overlapping !!");
nonconsist = 1;
}
*/
bool res = (mesh3d.CheckConsistentBoundary() != 0);
if (res)
{
PrintError ("Surface mesh not consistent");
nonconsist = 1;
}
}
if (nonconsist)
{
PrintError ("Stop meshing since surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
double globmaxh = mp.maxh;
for (int k = 1; k <= mesh3d.GetNDomains(); k++)
{
if(mp.only3D_domain_nr && mp.only3D_domain_nr !=k)
continue;
return;
if (multithread.terminate)
break;
return;
PrintMessage (2, "");
PrintMessage (1, "Meshing subdomain ", k, " of ", mesh3d.GetNDomains());
(*testout) << "Meshing subdomain " << k << endl;
mp.maxh = min2 (globmaxh, mesh3d.MaxHDomain(k));
mp.maxh = min2 (mp.maxh, mesh3d.MaxHDomain(k));
mesh3d.CalcSurfacesOfNode();
mesh3d.FindOpenElements(k);
if (!mesh3d.GetNOpenElements())
continue;
return;
@ -311,9 +260,85 @@ namespace netgen
PrintMessage (1, mesh3d.GetNP(), " points, ",
mesh3d.GetNE(), " elements");
{
if(mp.only3D_domain_nr && mp.only3D_domain_nr !=k)
return;
PrintMessage (3, "Check subdomain ", k, " / ", mesh3d.GetNDomains());
mesh3d.FindOpenElements(k);
bool res = (mesh3d.CheckConsistentBoundary() != 0);
if (res)
{
PrintError ("Surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
}
}
mp.maxh = globmaxh;
void MergeMeshes( Mesh & mesh, FlatArray<Mesh> meshes, PointIndex first_new_pi )
{
static Timer t("MergeMeshes"); RegionTimer rt(t);
for(auto & m : meshes)
{
Array<PointIndex, PointIndex> pmap(m.Points().Size());
for(auto pi : Range(PointIndex(PointIndex::BASE), first_new_pi))
pmap[pi] = pi;
for (auto pi : Range(first_new_pi, m.Points().Range().Next()))
pmap[pi] = mesh.AddPoint(m[pi]);
for ( auto el : m.VolumeElements() )
{
for (auto i : Range(el.GetNP()))
el[i] = pmap[el[i]];
mesh.AddVolumeElement(el);
}
}
}
// extern double teterrpow;
MESHING3_RESULT MeshVolume (const MeshingParameters & mp, Mesh& mesh3d)
{
static Timer t("MeshVolume"); RegionTimer reg(t);
if (!mesh3d.HasLocalHFunction()) mesh3d.CalcLocalH(mp.grading);
mesh3d.Compress();
// mesh3d.PrintMemInfo (cout);
if (mp.checkoverlappingboundary)
if (mesh3d.CheckOverlappingBoundary())
throw NgException ("Stop meshing since boundary mesh is overlapping");
if(task_manager)
{
Array<Mesh> meshes(mesh3d.GetNDomains()-1);
auto first_new_pi = mesh3d.Points().Range().Next();
for(auto & m : meshes)
{
m = mesh3d;
m.SetLocalH(mesh3d.GetLocalH());
}
ParallelFor(Range(1, mesh3d.GetNDomains()+1), [&](int k)
{
if(k==1)
MeshDomain(mesh3d, mp, k);
else
MeshDomain(meshes[k-2], mp, k);
});
MergeMeshes(mesh3d, meshes, first_new_pi);
}
else
for (int k = 1; k <= mesh3d.GetNDomains(); k++)
MeshDomain(mesh3d, mp, k);
MeshQuality3d (mesh3d);

View File

@ -1144,10 +1144,13 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
if (mp.maxh < maxh) maxh = mp.maxh;
auto loch_ptr = mesh.LocalHFunction().Copy();
auto & loch = *loch_ptr;
bool changed;
do
{
mesh.LocalHFunction().ClearFlags();
loch.ClearFlags();
for (int i = 1; i <= adfront->GetNF(); i++)
{
@ -1161,21 +1164,21 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
double filld = filldist * bbox.Diam();
bbox.Increase (filld);
mesh.LocalHFunction().CutBoundary (bbox); // .PMin(), bbox.PMax());
loch.CutBoundary (bbox); // .PMin(), bbox.PMax());
}
// locadfront = adfront;
mesh.LocalHFunction().FindInnerBoxes (adfront, NULL);
loch.FindInnerBoxes (adfront, NULL);
npoints.SetSize(0);
mesh.LocalHFunction().GetInnerPoints (npoints);
loch.GetInnerPoints (npoints);
changed = false;
for (int i = 1; i <= npoints.Size(); i++)
{
if (mesh.LocalHFunction().GetH(npoints.Get(i)) > 1.5 * maxh)
if (loch.GetH(npoints.Get(i)) > 1.5 * maxh)
{
mesh.LocalHFunction().SetH (npoints.Get(i), maxh);
loch.SetH (npoints.Get(i), maxh);
changed = true;
}
}

View File

@ -82,13 +82,13 @@
],
"angles_trig": [
24.858,
104.73
107.08
],
"ne1d": 181,
"ne2d": 313,
"ne3d": 506,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 13, 25, 47, 64, 85, 94, 100, 51, 17]",
"total_badness": 650.35553401
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 13, 28, 45, 66, 88, 88, 95, 57, 18]",
"total_badness": 650.55380342
}
],
"boxcyl.geo": [
@ -1840,9 +1840,9 @@
],
"ne1d": 174,
"ne2d": 1190,
"ne3d": 5113,
"quality_histogram": "[0, 0, 15, 128, 183, 43, 57, 114, 124, 184, 294, 387, 492, 590, 635, 626, 528, 418, 234, 61]",
"total_badness": 8982.334633
"ne3d": 5073,
"quality_histogram": "[0, 0, 15, 128, 183, 44, 57, 112, 124, 171, 322, 373, 483, 622, 623, 558, 526, 429, 240, 63]",
"total_badness": 8929.8790628
},
{
"angles_tet": [
@ -1865,14 +1865,14 @@
169.26
],
"angles_trig": [
8.6573,
161.61
8.6562,
161.62
],
"ne1d": 132,
"ne2d": 812,
"ne3d": 2514,
"quality_histogram": "[0, 0, 7, 63, 69, 154, 134, 117, 148, 199, 247, 286, 257, 214, 177, 162, 120, 92, 45, 23]",
"total_badness": 5239.4475113
"ne3d": 2498,
"quality_histogram": "[0, 0, 7, 63, 69, 153, 138, 115, 153, 201, 253, 273, 267, 201, 164, 161, 120, 95, 44, 21]",
"total_badness": 5225.1671437
},
{
"angles_tet": [
@ -1885,39 +1885,39 @@
],
"ne1d": 174,
"ne2d": 1190,
"ne3d": 5067,
"quality_histogram": "[0, 0, 14, 117, 182, 41, 52, 114, 110, 155, 268, 313, 495, 590, 645, 645, 535, 485, 238, 68]",
"total_badness": 8750.9467413
"ne3d": 4995,
"quality_histogram": "[0, 0, 14, 117, 182, 40, 52, 109, 106, 145, 275, 310, 458, 591, 622, 604, 541, 495, 267, 67]",
"total_badness": 8621.0579835
},
{
"angles_tet": [
12.76,
147.23
14.607,
144.88
],
"angles_trig": [
15.824,
16.508,
143.02
],
"ne1d": 248,
"ne2d": 2320,
"ne3d": 16409,
"quality_histogram": "[0, 0, 0, 0, 0, 4, 20, 55, 119, 192, 288, 630, 958, 1489, 2106, 2552, 2926, 2613, 1913, 544]",
"total_badness": 21635.781365
"ne3d": 16414,
"quality_histogram": "[0, 0, 0, 0, 0, 4, 22, 61, 107, 178, 334, 607, 1066, 1532, 2200, 2498, 2897, 2655, 1737, 516]",
"total_badness": 21736.358053
},
{
"angles_tet": [
18.203,
17.436,
144.68
],
"angles_trig": [
17.821,
130.51
127.08
],
"ne1d": 418,
"ne2d": 5958,
"ne3d": 102414,
"quality_histogram": "[0, 0, 0, 0, 0, 1, 4, 6, 45, 124, 368, 1028, 2576, 5782, 10622, 16119, 21223, 22353, 16809, 5354]",
"total_badness": 125921.99427
"ne3d": 100894,
"quality_histogram": "[0, 0, 0, 0, 0, 1, 5, 7, 34, 114, 369, 997, 2522, 5452, 10512, 15927, 20701, 21949, 16958, 5346]",
"total_badness": 123900.96306
}
],
"ortho.geo": [
@ -2092,8 +2092,8 @@
"period.geo": [
{
"angles_tet": [
13.348,
152.73
14.261,
145.23
],
"angles_trig": [
15.314,
@ -2101,9 +2101,9 @@
],
"ne1d": 344,
"ne2d": 1118,
"ne3d": 3303,
"quality_histogram": "[0, 0, 0, 0, 1, 3, 19, 28, 60, 79, 167, 274, 340, 411, 474, 453, 427, 342, 172, 53]",
"total_badness": 4787.3615998
"ne3d": 3285,
"quality_histogram": "[0, 0, 0, 0, 1, 2, 16, 26, 56, 87, 157, 264, 331, 405, 486, 454, 436, 340, 173, 51]",
"total_badness": 4744.2301558
},
{
"angles_tet": [
@ -2133,12 +2133,12 @@
"ne2d": 566,
"ne3d": 1302,
"quality_histogram": "[0, 0, 0, 1, 4, 17, 29, 39, 64, 86, 116, 123, 148, 143, 127, 134, 119, 83, 58, 11]",
"total_badness": 2151.3920824
"total_badness": 2151.3920827
},
{
"angles_tet": [
15.291,
144.92
15.577,
142.87
],
"angles_trig": [
15.314,
@ -2146,39 +2146,39 @@
],
"ne1d": 344,
"ne2d": 1118,
"ne3d": 3261,
"quality_histogram": "[0, 0, 0, 0, 1, 2, 14, 23, 49, 62, 156, 225, 323, 419, 476, 458, 421, 385, 185, 62]",
"total_badness": 4648.2224319
"ne3d": 3240,
"quality_histogram": "[0, 0, 0, 0, 1, 2, 15, 22, 54, 65, 154, 226, 315, 404, 494, 459, 406, 383, 179, 61]",
"total_badness": 4628.23351
},
{
"angles_tet": [
21.808,
142.31
21.896,
143.75
],
"angles_trig": [
23.022,
128.64
23.103,
123.18
],
"ne1d": 480,
"ne2d": 2248,
"ne3d": 11618,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 8, 29, 90, 215, 539, 874, 1483, 1964, 2225, 2201, 1553, 437]",
"total_badness": 14695.782197
"ne3d": 11666,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 1, 4, 25, 100, 251, 514, 914, 1518, 1994, 2234, 2110, 1565, 436]",
"total_badness": 14784.15449
},
{
"angles_tet": [
22.578,
141.63
21.617,
142.69
],
"angles_trig": [
22.146,
120.55
122.89
],
"ne1d": 820,
"ne2d": 6206,
"ne3d": 68494,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 8, 53, 159, 556, 1496, 3478, 6612, 10914, 14587, 15239, 11731, 3661]",
"total_badness": 83666.140475
"ne3d": 68535,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 1, 5, 42, 157, 567, 1545, 3554, 6751, 10948, 14379, 15271, 11665, 3650]",
"total_badness": 83784.962076
}
],
"plane.stl": [
@ -2760,24 +2760,24 @@
],
"ne1d": 74,
"ne2d": 412,
"ne3d": 1681,
"quality_histogram": "[0, 0, 0, 0, 0, 5, 5, 17, 18, 30, 48, 94, 133, 194, 249, 242, 240, 204, 159, 43]",
"total_badness": 2334.8383469
"ne3d": 1688,
"quality_histogram": "[0, 0, 0, 0, 0, 5, 5, 17, 18, 31, 48, 98, 133, 190, 250, 259, 245, 198, 142, 49]",
"total_badness": 2349.0686154
},
{
"angles_tet": [
25.029,
138.94
24.909,
140.9
],
"angles_trig": [
22.069,
127.5
21.973,
127.7
],
"ne1d": 122,
"ne2d": 1076,
"ne3d": 14037,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 3, 24, 84, 179, 418, 822, 1431, 2256, 2852, 2929, 2328, 711]",
"total_badness": 17344.477334
"ne3d": 14075,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 3, 28, 68, 192, 457, 844, 1466, 2272, 2839, 2856, 2353, 697]",
"total_badness": 17420.850186
}
],
"square.in2d": [
@ -3156,13 +3156,13 @@
],
"angles_trig": [
14.916,
130.79
132.02
],
"ne1d": 690,
"ne2d": 1670,
"ne3d": 5168,
"quality_histogram": "[0, 0, 1, 0, 0, 8, 30, 37, 106, 198, 284, 368, 447, 559, 691, 708, 596, 539, 460, 136]",
"total_badness": 7457.2380943
"ne3d": 5169,
"quality_histogram": "[0, 0, 1, 0, 1, 7, 31, 35, 107, 196, 275, 376, 451, 556, 687, 707, 599, 545, 457, 138]",
"total_badness": 7455.986288
},
{
"angles_tet": [
@ -3191,8 +3191,8 @@
"ne1d": 512,
"ne2d": 866,
"ne3d": 2373,
"quality_histogram": "[0, 0, 0, 5, 9, 17, 44, 69, 124, 143, 189, 210, 313, 383, 339, 233, 138, 87, 46, 24]",
"total_badness": 3943.0636847
"quality_histogram": "[0, 0, 0, 5, 9, 17, 44, 69, 124, 143, 189, 211, 313, 381, 339, 234, 138, 87, 46, 24]",
"total_badness": 3943.062114
},
{
"angles_tet": [
@ -3201,13 +3201,13 @@
],
"angles_trig": [
14.916,
130.79
132.02
],
"ne1d": 690,
"ne2d": 1670,
"ne3d": 5111,
"quality_histogram": "[0, 0, 1, 0, 0, 3, 21, 38, 107, 192, 269, 348, 432, 542, 664, 707, 611, 564, 471, 141]",
"total_badness": 7317.6330225
"ne3d": 5117,
"quality_histogram": "[0, 0, 1, 0, 0, 3, 22, 36, 106, 193, 265, 351, 428, 546, 668, 707, 609, 567, 474, 141]",
"total_badness": 7321.564248
},
{
"angles_tet": [
@ -3220,24 +3220,24 @@
],
"ne1d": 1050,
"ne2d": 3784,
"ne3d": 17749,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 3, 14, 35, 69, 180, 557, 1402, 2124, 2373, 2627, 2696, 2716, 2280, 673]",
"total_badness": 23160.553922
"ne3d": 17750,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 3, 14, 35, 68, 188, 555, 1411, 2124, 2368, 2623, 2700, 2707, 2279, 675]",
"total_badness": 23168.68937
},
{
"angles_tet": [
15.34,
149.42
14.338,
149.44
],
"angles_trig": [
20.032,
19.234,
129.78
],
"ne1d": 1722,
"ne2d": 10022,
"ne3d": 85138,
"quality_histogram": "[0, 0, 0, 0, 0, 3, 49, 1423, 714, 399, 655, 1222, 2404, 5670, 9020, 13424, 16402, 16956, 12744, 4053]",
"total_badness": 108990.18852
"ne3d": 84843,
"quality_histogram": "[0, 0, 0, 0, 0, 2, 47, 1403, 696, 390, 665, 1234, 2433, 5392, 8824, 13169, 16695, 17000, 12791, 4102]",
"total_badness": 108464.06506
}
],
"twobricks.geo": [
@ -3318,18 +3318,18 @@
},
{
"angles_tet": [
28.752,
130.07
28.509,
131.79
],
"angles_trig": [
25.5,
109.19
27.418,
108.8
],
"ne1d": 186,
"ne2d": 334,
"ne3d": 596,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 21, 35, 49, 93, 105, 118, 99, 54, 17]",
"total_badness": 770.34262233
"ne3d": 589,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 20, 31, 52, 90, 109, 114, 101, 59, 8]",
"total_badness": 760.70063244
}
],
"twocubes.geo": [
@ -3410,18 +3410,18 @@
},
{
"angles_tet": [
28.752,
130.07
28.509,
131.79
],
"angles_trig": [
25.5,
109.19
27.418,
108.8
],
"ne1d": 186,
"ne2d": 334,
"ne3d": 596,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 21, 35, 49, 93, 105, 118, 99, 54, 17]",
"total_badness": 770.34262233
"ne3d": 589,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 20, 31, 52, 90, 109, 114, 101, 59, 8]",
"total_badness": 760.70063244
}
],
"twocyl.geo": [