reuse netrules, implant adfront into meshing class

This commit is contained in:
Joachim Schöberl 2019-07-28 21:31:05 +02:00
parent 321bee9b02
commit 168df170ec
4 changed files with 87 additions and 65 deletions

View File

@ -81,12 +81,12 @@ namespace netgen
Box<3> bbox ( Box<3>::EMPTY_BOX ); Box<3> bbox ( Box<3>::EMPTY_BOX );
double maxh = 0; double maxh = 0;
for (int i = 0; i < adfront->GetNFL(); i++) for (int i = 0; i < adfront.GetNFL(); i++)
{ {
const FrontLine & line = adfront->GetLine (i); const FrontLine & line = adfront.GetLine (i);
const Point<3> & p1 = adfront->GetPoint(line.L().I1()); const Point<3> & p1 = adfront.GetPoint(line.L().I1());
const Point<3> & p2 = adfront->GetPoint(line.L().I2()); const Point<3> & p2 = adfront.GetPoint(line.L().I2());
maxh = max (maxh, Dist (p1, p2)); maxh = max (maxh, Dist (p1, p2));
@ -115,12 +115,12 @@ namespace netgen
{ {
mesh.LocalHFunction().ClearFlags(); mesh.LocalHFunction().ClearFlags();
for (int i = 0; i < adfront->GetNFL(); i++) for (int i = 0; i < adfront.GetNFL(); i++)
{ {
const FrontLine & line = adfront->GetLine(i); const FrontLine & line = adfront.GetLine(i);
Box<3> bbox (adfront->GetPoint (line.L().I1())); Box<3> bbox (adfront.GetPoint (line.L().I1()));
bbox.Add (adfront->GetPoint (line.L().I2())); bbox.Add (adfront.GetPoint (line.L().I2()));
double filld = filldist * bbox.Diam(); double filld = filldist * bbox.Diam();
@ -130,7 +130,7 @@ namespace netgen
} }
mesh.LocalHFunction().FindInnerBoxes (adfront, NULL); mesh.LocalHFunction().FindInnerBoxes (&adfront, NULL);
npoints.SetSize(0); npoints.SetSize(0);
mesh.LocalHFunction().GetInnerPoints (npoints); mesh.LocalHFunction().GetInnerPoints (npoints);
@ -162,14 +162,14 @@ namespace netgen
if (meshbox.IsIn (npoints.Get(i))) if (meshbox.IsIn (npoints.Get(i)))
{ {
PointIndex gpnum = mesh.AddPoint (npoints.Get(i)); PointIndex gpnum = mesh.AddPoint (npoints.Get(i));
adfront->AddPoint (npoints.Get(i), gpnum); adfront.AddPoint (npoints.Get(i), gpnum);
if (debugparam.slowchecks) if (debugparam.slowchecks)
{ {
(*testout) << npoints.Get(i) << endl; (*testout) << npoints.Get(i) << endl;
Point<2> p2d (npoints.Get(i)(0), npoints.Get(i)(1)); Point<2> p2d (npoints.Get(i)(0), npoints.Get(i)(1));
if (!adfront->Inside(p2d)) if (!adfront.Inside(p2d))
{ {
cout << "add outside point" << endl; cout << "add outside point" << endl;
(*testout) << "outside" << endl; (*testout) << "outside" << endl;
@ -187,29 +187,29 @@ namespace netgen
loch2.ClearFlags(); loch2.ClearFlags();
for (int i = 0; i < adfront->GetNFL(); i++) for (int i = 0; i < adfront.GetNFL(); i++)
{ {
const FrontLine & line = adfront->GetLine(i); const FrontLine & line = adfront.GetLine(i);
Box<3> bbox (adfront->GetPoint (line.L().I1())); Box<3> bbox (adfront.GetPoint (line.L().I1()));
bbox.Add (adfront->GetPoint (line.L().I2())); bbox.Add (adfront.GetPoint (line.L().I2()));
loch2.SetH (bbox.Center(), bbox.Diam()); loch2.SetH (bbox.Center(), bbox.Diam());
} }
for (int i = 0; i < adfront->GetNFL(); i++) for (int i = 0; i < adfront.GetNFL(); i++)
{ {
const FrontLine & line = adfront->GetLine(i); const FrontLine & line = adfront.GetLine(i);
Box<3> bbox (adfront->GetPoint (line.L().I1())); Box<3> bbox (adfront.GetPoint (line.L().I1()));
bbox.Add (adfront->GetPoint (line.L().I2())); bbox.Add (adfront.GetPoint (line.L().I2()));
bbox.Increase (filldist * bbox.Diam()); bbox.Increase (filldist * bbox.Diam());
loch2.CutBoundary (bbox); loch2.CutBoundary (bbox);
} }
loch2.FindInnerBoxes (adfront, NULL); loch2.FindInnerBoxes (&adfront, NULL);
// outer points : smooth mesh-grading // outer points : smooth mesh-grading
npoints.SetSize(0); npoints.SetSize(0);
@ -220,7 +220,7 @@ namespace netgen
if (meshbox.IsIn (npoints.Get(i))) if (meshbox.IsIn (npoints.Get(i)))
{ {
PointIndex gpnum = mesh.AddPoint (npoints.Get(i)); PointIndex gpnum = mesh.AddPoint (npoints.Get(i));
adfront->AddPoint (npoints.Get(i), gpnum); adfront.AddPoint (npoints.Get(i), gpnum);
} }
} }
@ -257,11 +257,11 @@ namespace netgen
// face bounding box: // face bounding box:
Box<3> bbox (Box<3>::EMPTY_BOX); Box<3> bbox (Box<3>::EMPTY_BOX);
for (int i = 0; i < adfront->GetNFL(); i++) for (int i = 0; i < adfront.GetNFL(); i++)
{ {
const FrontLine & line = adfront->GetLine(i); const FrontLine & line = adfront.GetLine(i);
bbox.Add (Point<3> (adfront->GetPoint (line.L()[0]))); bbox.Add (Point<3> (adfront.GetPoint (line.L()[0])));
bbox.Add (Point<3> (adfront->GetPoint (line.L()[1]))); bbox.Add (Point<3> (adfront.GetPoint (line.L()[1])));
} }
for (int i = 0; i < mesh.LockedPoints().Size(); i++) for (int i = 0; i < mesh.LockedPoints().Size(); i++)
@ -402,7 +402,7 @@ namespace netgen
if (trig[0] < 0) continue; if (trig[0] < 0) continue;
Point<3> c = Center (mesh[trig[0]], mesh[trig[1]], mesh[trig[2]]); Point<3> c = Center (mesh[trig[0]], mesh[trig[1]], mesh[trig[2]]);
if (!adfront->Inside (Point<2> (c(0),c(1)))) continue; if (!adfront.Inside (Point<2> (c(0),c(1)))) continue;
Vec<3> n = Cross (mesh[trig[1]]-mesh[trig[0]], Vec<3> n = Cross (mesh[trig[1]]-mesh[trig[0]],
mesh[trig[2]]-mesh[trig[0]]); mesh[trig[2]]-mesh[trig[0]]);

View File

@ -19,16 +19,33 @@ namespace netgen
// static int qualclass; // static int qualclass;
static Array<unique_ptr<netrule>> global_trig_rules;
static Array<unique_ptr<netrule>> global_quad_rules;
Meshing2 :: Meshing2 (const MeshingParameters & mp, const Box<3> & aboundingbox) Meshing2 :: Meshing2 (const MeshingParameters & mp, const Box<3> & aboundingbox)
: adfront(aboundingbox), boundingbox(aboundingbox)
{ {
static Timer t("Mesing2::Meshing2"); RegionTimer r(t); static Timer t("Mesing2::Meshing2"); RegionTimer r(t);
boundingbox = aboundingbox;
LoadRules (NULL, mp.quad); 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<netrule>(rule));
}
else
{
for (auto i : globalrules.Range())
rules.Append (globalrules[i].get());
}
// LoadRules ("rules/quad.rls"); // LoadRules ("rules/quad.rls");
// LoadRules ("rules/triangle.rls"); // LoadRules ("rules/triangle.rls");
adfront = new AdFront2(boundingbox);
// adfront = new AdFront2(boundingbox);
starttime = GetTime(); starttime = GetTime();
maxarea = -1; maxarea = -1;
@ -37,9 +54,11 @@ namespace netgen
Meshing2 :: ~Meshing2 () Meshing2 :: ~Meshing2 ()
{ {
delete adfront; // delete adfront;
/*
for (int i = 0; i < rules.Size(); i++) for (int i = 0; i < rules.Size(); i++)
delete rules[i]; delete rules[i];
*/
} }
void Meshing2 :: AddPoint (const Point3d & p, PointIndex globind, void Meshing2 :: AddPoint (const Point3d & p, PointIndex globind,
@ -47,7 +66,7 @@ namespace netgen
bool pointonsurface) bool pointonsurface)
{ {
//(*testout) << "add point " << globind << endl; //(*testout) << "add point " << globind << endl;
adfront ->AddPoint (p, globind, mgi, pointonsurface); adfront.AddPoint (p, globind, mgi, pointonsurface);
} }
void Meshing2 :: AddBoundaryElement (int i1, int i2, void Meshing2 :: AddBoundaryElement (int i1, int i2,
@ -58,7 +77,7 @@ namespace netgen
{ {
PrintSysError ("addboundaryelement: illegal geominfo"); PrintSysError ("addboundaryelement: illegal geominfo");
} }
adfront -> AddLine (i1-1, i2-1, gi1, gi2); adfront. AddLine (i1-1, i2-1, gi1, gi2);
} }
@ -341,7 +360,7 @@ namespace netgen
const char * savetask = multithread.task; const char * savetask = multithread.task;
multithread.task = "Surface meshing"; multithread.task = "Surface meshing";
adfront ->SetStartFront (); adfront.SetStartFront ();
int plotnexttrial = 999; int plotnexttrial = 999;
@ -350,7 +369,7 @@ namespace netgen
NgProfiler::StopTimer (ts3); NgProfiler::StopTimer (ts3);
while (!adfront ->Empty() && !multithread.terminate) while (!adfront.Empty() && !multithread.terminate)
{ {
NgProfiler::RegionTimer reg1 (timer1); NgProfiler::RegionTimer reg1 (timer1);
@ -393,7 +412,7 @@ namespace netgen
mpgeominfo.SetSize(0); mpgeominfo.SetSize(0);
nfaces = adfront->GetNFL(); nfaces = adfront.GetNFL();
trials ++; trials ++;
@ -410,7 +429,7 @@ namespace netgen
} }
int baselineindex = adfront -> SelectBaseLine (p1, p2, blgeominfo1, blgeominfo2, qualclass); int baselineindex = adfront. SelectBaseLine (p1, p2, blgeominfo1, blgeominfo2, qualclass);
found = 1; found = 1;
@ -427,7 +446,7 @@ namespace netgen
double hinner = (3 + qualclass) * max2 (his, hshould); double hinner = (3 + qualclass) * max2 (his, hshould);
adfront ->GetLocals (baselineindex, locpoints, mpgeominfo, loclines, adfront.GetLocals (baselineindex, locpoints, mpgeominfo, loclines,
pindex, lindex, 2*hinner); pindex, lindex, 2*hinner);
@ -441,7 +460,7 @@ namespace netgen
if (qualclass > mp.giveuptol2d) if (qualclass > mp.giveuptol2d)
{ {
PrintMessage (3, "give up with qualclass ", qualclass); PrintMessage (3, "give up with qualclass ", qualclass);
PrintMessage (3, "number of frontlines = ", adfront->GetNFL()); PrintMessage (3, "number of frontlines = ", adfront.GetNFL());
// throw NgException ("Give up 2d meshing"); // throw NgException ("Give up 2d meshing");
break; break;
} }
@ -457,8 +476,8 @@ namespace netgen
morerisc = 0; morerisc = 0;
PointIndex gpi1 = adfront -> GetGlobalIndex (pindex.Get(loclines[0].I1())); PointIndex gpi1 = adfront. GetGlobalIndex (pindex.Get(loclines[0].I1()));
PointIndex gpi2 = adfront -> GetGlobalIndex (pindex.Get(loclines[0].I2())); PointIndex gpi2 = adfront. GetGlobalIndex (pindex.Get(loclines[0].I2()));
debugflag = debugflag =
@ -580,7 +599,7 @@ namespace netgen
if (IsLineVertexOnChart (locpoints.Get(loclines.Get(i).I1()), if (IsLineVertexOnChart (locpoints.Get(loclines.Get(i).I1()),
locpoints.Get(loclines.Get(i).I2()), locpoints.Get(loclines.Get(i).I2()),
innerp, innerp,
adfront->GetLineGeomInfo (lindex.Get(i), innerp))) adfront.GetLineGeomInfo (lindex.Get(i), innerp)))
// pgeominfo.Get(loclines.Get(i).I(innerp)))) // pgeominfo.Get(loclines.Get(i).I(innerp))))
{ {
@ -759,7 +778,7 @@ namespace netgen
{ {
multithread.drawing = 1; multithread.drawing = 1;
glrender(1); glrender(1);
cout << "qualclass 100, nfl = " << adfront->GetNFL() << endl; cout << "qualclass 100, nfl = " << adfront.GetNFL() << endl;
} }
*/ */
@ -819,7 +838,7 @@ namespace netgen
// for (i = 1; i <= oldnl; i++) // for (i = 1; i <= oldnl; i++)
// adfront -> ResetClass (lindex[i]); // adfront. ResetClass (lindex[i]);
/* /*
@ -948,7 +967,7 @@ namespace netgen
for (j = 1; j <= 2; j++) for (j = 1; j <= 2; j++)
{ {
upgeominfo.Elem(loclines.Get(dellines.Get(i)).I(j)) = upgeominfo.Elem(loclines.Get(dellines.Get(i)).I(j)) =
adfront -> GetLineGeomInfo (lindex.Get(dellines.Get(i)), j); adfront. GetLineGeomInfo (lindex.Get(dellines.Get(i)), j);
} }
*/ */
@ -1146,7 +1165,7 @@ namespace netgen
// cout << "overlap !!!" << endl; // cout << "overlap !!!" << endl;
#endif #endif
for (int k = 1; k <= 5; k++) for (int k = 1; k <= 5; k++)
adfront -> IncrementClass (lindex.Get(1)); adfront. IncrementClass (lindex.Get(1));
found = 0; found = 0;
@ -1180,10 +1199,10 @@ namespace netgen
int nlgpi2 = loclines.Get(i).I2(); int nlgpi2 = loclines.Get(i).I2();
if (nlgpi1 <= pindex.Size() && nlgpi2 <= pindex.Size()) if (nlgpi1 <= pindex.Size() && nlgpi2 <= pindex.Size())
{ {
nlgpi1 = adfront->GetGlobalIndex (pindex.Get(nlgpi1)); nlgpi1 = adfront.GetGlobalIndex (pindex.Get(nlgpi1));
nlgpi2 = adfront->GetGlobalIndex (pindex.Get(nlgpi2)); nlgpi2 = adfront.GetGlobalIndex (pindex.Get(nlgpi2));
int exval = adfront->ExistsLine (nlgpi1, nlgpi2); int exval = adfront.ExistsLine (nlgpi1, nlgpi2);
if (exval) if (exval)
{ {
cout << "ERROR: new line exits, val = " << exval << endl; cout << "ERROR: new line exits, val = " << exval << endl;
@ -1212,8 +1231,8 @@ namespace netgen
int tpi2 = locelements.Get(i).PNumMod (j+1); int tpi2 = locelements.Get(i).PNumMod (j+1);
if (tpi1 <= pindex.Size() && tpi2 <= pindex.Size()) if (tpi1 <= pindex.Size() && tpi2 <= pindex.Size())
{ {
tpi1 = adfront->GetGlobalIndex (pindex.Get(tpi1)); tpi1 = adfront.GetGlobalIndex (pindex.Get(tpi1));
tpi2 = adfront->GetGlobalIndex (pindex.Get(tpi2)); tpi2 = adfront.GetGlobalIndex (pindex.Get(tpi2));
if (doubleedge.Used (INDEX_2(tpi1, tpi2))) if (doubleedge.Used (INDEX_2(tpi1, tpi2)))
{ {
@ -1242,7 +1261,7 @@ namespace netgen
for (int i = oldnp+1; i <= locpoints.Size(); i++) for (int i = oldnp+1; i <= locpoints.Size(); i++)
{ {
PointIndex globind = mesh.AddPoint (locpoints.Get(i)); PointIndex globind = mesh.AddPoint (locpoints.Get(i));
pindex.Elem(i) = adfront -> AddPoint (locpoints.Get(i), globind); pindex.Elem(i) = adfront. AddPoint (locpoints.Get(i), globind);
} }
for (int i = oldnl+1; i <= loclines.Size(); i++) for (int i = oldnl+1; i <= loclines.Size(); i++)
@ -1272,7 +1291,7 @@ namespace netgen
cout << "new el: illegal geominfo" << endl; cout << "new el: illegal geominfo" << endl;
} }
adfront -> AddLine (pindex.Get(loclines.Get(i).I1()), adfront. AddLine (pindex.Get(loclines.Get(i).I1()),
pindex.Get(loclines.Get(i).I2()), pindex.Get(loclines.Get(i).I2()),
upgeominfo.Get(loclines.Get(i).I1()), upgeominfo.Get(loclines.Get(i).I1()),
upgeominfo.Get(loclines.Get(i).I2())); upgeominfo.Get(loclines.Get(i).I2()));
@ -1297,7 +1316,7 @@ namespace netgen
{ {
mtri.PNum(j) = mtri.PNum(j) =
locelements.Elem(i).PNum(j) = locelements.Elem(i).PNum(j) =
adfront -> GetGlobalIndex (pindex.Get(locelements.Get(i).PNum(j))); adfront. GetGlobalIndex (pindex.Get(locelements.Get(i).PNum(j)));
} }
@ -1376,7 +1395,7 @@ namespace netgen
} }
for (int i = 1; i <= dellines.Size(); i++) for (int i = 1; i <= dellines.Size(); i++)
adfront -> DeleteLine (lindex.Get(dellines.Get(i))); adfront. DeleteLine (lindex.Get(dellines.Get(i)));
// rname = rules.Get(rulenr)->Name(); // rname = rules.Get(rulenr)->Name();
#ifdef MYGRAPH #ifdef MYGRAPH
@ -1399,7 +1418,7 @@ namespace netgen
if ( debugparam.haltsuccess || debugflag ) if ( debugparam.haltsuccess || debugflag )
{ {
// adfront -> PrintOpenSegments (*testout); // adfront. PrintOpenSegments (*testout);
cout << "success of rule" << rules.Get(rulenr)->Name() << endl; cout << "success of rule" << rules.Get(rulenr)->Name() << endl;
multithread.drawing = 1; multithread.drawing = 1;
multithread.testmode = 1; multithread.testmode = 1;
@ -1421,7 +1440,7 @@ namespace netgen
(*testout) << "locpoints " << endl; (*testout) << "locpoints " << endl;
for (int i = 1; i <= pindex.Size(); i++) for (int i = 1; i <= pindex.Size(); i++)
(*testout) << adfront->GetGlobalIndex (pindex.Get(i)) << endl; (*testout) << adfront.GetGlobalIndex (pindex.Get(i)) << endl;
(*testout) << "old number of lines = " << oldnl << endl; (*testout) << "old number of lines = " << oldnl << endl;
for (int i = 1; i <= loclines.Size(); i++) for (int i = 1; i <= loclines.Size(); i++)
@ -1432,7 +1451,7 @@ namespace netgen
int hi = 0; int hi = 0;
if (loclines.Get(i).I(j) >= 1 && if (loclines.Get(i).I(j) >= 1 &&
loclines.Get(i).I(j) <= pindex.Size()) loclines.Get(i).I(j) <= pindex.Size())
hi = adfront->GetGlobalIndex (pindex.Get(loclines.Get(i).I(j))); hi = adfront.GetGlobalIndex (pindex.Get(loclines.Get(i).I(j)));
(*testout) << hi << " "; (*testout) << hi << " ";
} }
@ -1451,7 +1470,7 @@ namespace netgen
} }
else else
{ {
adfront -> IncrementClass (lindex.Get(1)); adfront. IncrementClass (lindex.Get(1));
if ( debugparam.haltnosuccess || debugflag ) if ( debugparam.haltnosuccess || debugflag )
{ {
@ -1484,7 +1503,7 @@ namespace netgen
int hi = 0; int hi = 0;
if (loclines.Get(i).I(j) >= 1 && if (loclines.Get(i).I(j) >= 1 &&
loclines.Get(i).I(j) <= pindex.Size()) loclines.Get(i).I(j) <= pindex.Size())
hi = adfront->GetGlobalIndex (pindex.Get(loclines.Get(i).I(j))); hi = adfront.GetGlobalIndex (pindex.Get(loclines.Get(i).I(j)));
(*testout) << hi << " "; (*testout) << hi << " ";
} }
@ -1523,7 +1542,7 @@ namespace netgen
PrintMessage (3, "Surface meshing done"); PrintMessage (3, "Surface meshing done");
adfront->PrintOpenSegments (*testout); adfront.PrintOpenSegments (*testout);
multithread.task = savetask; multithread.task = savetask;
@ -1531,7 +1550,7 @@ namespace netgen
EndMesh (); EndMesh ();
if (!adfront->Empty()) if (!adfront.Empty())
return MESHING2_GIVEUP; return MESHING2_GIVEUP;
return MESHING2_OK; return MESHING2_OK;

View File

@ -29,7 +29,7 @@ derive from Meshing2, and replace transformation.
class Meshing2 class Meshing2
{ {
/// the current advancing front /// the current advancing front
AdFront2 * adfront; AdFront2 adfront;
/// rules for mesh generation /// rules for mesh generation
NgArray<netrule*> rules; NgArray<netrule*> rules;
/// statistics /// statistics

View File

@ -579,6 +579,8 @@ void Meshing2 :: LoadRules (const char * filename, bool quad)
exit (1); exit (1);
} }
Timer t("Parsing rules");
t.Start();
while (!ist->eof()) while (!ist->eof())
{ {
buf[0] = 0; buf[0] = 0;
@ -597,6 +599,7 @@ void Meshing2 :: LoadRules (const char * filename, bool quad)
//(*testout) << "loop" << endl; //(*testout) << "loop" << endl;
} }
//(*testout) << "POS3" << endl; //(*testout) << "POS3" << endl;
t.Stop();
delete ist; delete ist;
//delete [] tr1; //delete [] tr1;