Delaunay2d also for small sub-domains

This commit is contained in:
Joachim Schöberl 2020-10-25 16:31:47 +01:00
parent 11557838a4
commit de83f0ca14
5 changed files with 125 additions and 21 deletions

View File

@ -687,7 +687,7 @@ namespace netgen
t_points.Stop(); t_points.Stop();
if(mp.delaunay2d && cnt>100) if(mp.delaunay2d && cnt>1)
meshing.Delaunay(*mesh, domnr, mp); meshing.Delaunay(*mesh, domnr, mp);
else else
{ {
@ -707,6 +707,8 @@ namespace netgen
mesh->SetMaterial (domnr, material); mesh->SetMaterial (domnr, material);
} }
mesh->Compress();
mp.quad = hquad; mp.quad = hquad;

View File

@ -206,7 +206,7 @@ public:
const FrontLine & GetLine (int nr) { return lines[nr]; } const FrontLine & GetLine (int nr) { return lines[nr]; }
const FrontPoint2 & GetPoint (int nr) { return points[nr]; } const FrontPoint2 & GetPoint (int nr) { return points[nr]; }
const auto & GetLines () const { return lines; }
/// ///
int SelectBaseLine (Point<3> & p1, Point<3> & p2, int SelectBaseLine (Point<3> & p1, Point<3> & p2,

View File

@ -454,8 +454,14 @@ namespace netgen
bool changed; bool changed;
do do
{ {
mesh.LocalHFunction().ClearFlags(); static Timer tcf("clear flags");
tcf.Start();
// mesh.LocalHFunction().ClearFlags();
mesh.LocalHFunction().ClearRootFlags();
tcf.Stop();
static Timer tcut("tcut");
tcut.Start();
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);
@ -469,7 +475,7 @@ namespace netgen
mesh.LocalHFunction().CutBoundary (bbox); mesh.LocalHFunction().CutBoundary (bbox);
} }
tcut.Stop();
mesh.LocalHFunction().FindInnerBoxes (&adfront, NULL); mesh.LocalHFunction().FindInnerBoxes (&adfront, NULL);
@ -506,11 +512,11 @@ namespace netgen
{ {
int i = 0; int i = 0;
if (npoints.Size())
while (npoints.Size() % prims[i] == 0) i++; while (npoints.Size() % prims[i] == 0) i++;
prim = prims[i]; prim = prims[i];
} }
for (int i = 0; i < npoints.Size(); i++) for (int i = 0; i < npoints.Size(); i++)
{ {
size_t hi = (size_t(prim) * size_t(i)) % npoints.Size(); size_t hi = (size_t(prim) * size_t(i)) % npoints.Size();
@ -571,6 +577,7 @@ namespace netgen
npoints.SetSize(0); npoints.SetSize(0);
loch2.GetOuterPoints (npoints); loch2.GetOuterPoints (npoints);
/*
for (int i = 1; i <= npoints.Size(); i++) for (int i = 1; i <= npoints.Size(); i++)
{ {
if (meshbox.IsIn (npoints.Get(i))) if (meshbox.IsIn (npoints.Get(i)))
@ -579,7 +586,14 @@ namespace netgen
adfront.AddPoint (npoints.Get(i), gpnum); adfront.AddPoint (npoints.Get(i), gpnum);
} }
} }
*/
for (const Point<3> p : npoints)
if (meshbox.IsIn(p))
{
PointIndex gpnum = mesh.AddPoint (p);
adfront.AddPoint (p, gpnum);
}
timer4.Stop(); timer4.Stop();
} }
@ -589,6 +603,9 @@ namespace netgen
void Meshing2 :: Delaunay (Mesh & mesh, int domainnr, const MeshingParameters & mp) void Meshing2 :: Delaunay (Mesh & mesh, int domainnr, const MeshingParameters & mp)
{ {
static Timer timer("Meshing2::Delaunay"); static Timer timer("Meshing2::Delaunay");
static Timer t1("Meshing2::Delaunay1");
static Timer t2("Meshing2::Delaunay2");
static Timer t3("Meshing2::Delaunay3");
static Timer timer_addpoints("add points"); static Timer timer_addpoints("add points");
RegionTimer reg (timer); RegionTimer reg (timer);
@ -600,6 +617,7 @@ namespace netgen
auto last_point_blockfill = mesh.Points().Range().Next(); auto last_point_blockfill = mesh.Points().Range().Next();
t1.Start();
// Bounding box for starting trig in delaunay // Bounding box for starting trig in delaunay
Box<2> bbox (Box<2>::EMPTY_BOX); Box<2> bbox (Box<2>::EMPTY_BOX);
@ -615,10 +633,14 @@ namespace netgen
for (int i = 0; i < mesh.LockedPoints().Size(); i++) for (int i = 0; i < mesh.LockedPoints().Size(); i++)
bbox.Add (P2(mesh.Point (mesh.LockedPoints()[i]))); bbox.Add (P2(mesh.Point (mesh.LockedPoints()[i])));
t1.Stop();
t2.Start();
Array<PointIndex> old_points; Array<PointIndex> old_points;
BitArray add_point(mesh.Points().Size()+1); BitArray add_point(mesh.Points().Size()+1);
Array<PointIndex> addpoints;
add_point.Clear(); add_point.Clear();
/*
for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++) for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++)
{ {
const auto & s = mesh[si]; const auto & s = mesh[si];
@ -628,7 +650,28 @@ namespace netgen
add_point.SetBit(s[1]); add_point.SetBit(s[1]);
} }
} }
*/
/*
for (int i = 0; i < adfront.GetNFL(); i++)
{
const FrontLine & line = adfront.GetLine(i);
for (int j = 0; j < 2; j++)
add_point.SetBit (adfront.GetGlobalIndex (line.L()[j]))adfront.GetGlobalIndex (line.L()[j]));
}
*/
for (const auto & line : adfront.GetLines())
for (int j = 0; j < 2; j++)
{
PointIndex pnum = adfront.GetGlobalIndex (line.L()[j]);
if (!add_point.Test(pnum))
addpoints.Append(pnum);
add_point.SetBit (pnum);
}
t2.Stop();
t3.Start();
Mesh tempmesh; Mesh tempmesh;
tempmesh.AddFaceDescriptor (FaceDescriptor (1, 1, 0, 0)); tempmesh.AddFaceDescriptor (FaceDescriptor (1, 1, 0, 0));
tempmesh.AddFaceDescriptor (FaceDescriptor (2, 1, 0, 0)); tempmesh.AddFaceDescriptor (FaceDescriptor (2, 1, 0, 0));
@ -637,8 +680,11 @@ namespace netgen
Array<PointIndex, PointIndex> compress; Array<PointIndex, PointIndex> compress;
Array<PointIndex, PointIndex> icompress(mesh.Points().Size()); Array<PointIndex, PointIndex> icompress(mesh.Points().Size());
/*
for(auto pi : mesh.Points().Range()) for(auto pi : mesh.Points().Range())
if(add_point.Test(pi)) if(add_point.Test(pi))
*/
for (PointIndex pi : addpoints)
{ {
icompress[pi] = tempmesh.AddPoint(mesh[pi]); icompress[pi] = tempmesh.AddPoint(mesh[pi]);
compress.Append(pi); compress.Append(pi);
@ -649,7 +695,7 @@ namespace netgen
icompress[pi] = tempmesh.AddPoint(mesh[pi]); icompress[pi] = tempmesh.AddPoint(mesh[pi]);
compress.Append(pi); compress.Append(pi);
} }
t3.Stop();
// DelaunayMesh adds surrounding trig (don't add the last 3 points to delaunay AGAIN! // DelaunayMesh adds surrounding trig (don't add the last 3 points to delaunay AGAIN!
auto tempmesh_points = tempmesh.Points().Range(); auto tempmesh_points = tempmesh.Points().Range();
@ -676,7 +722,10 @@ namespace netgen
timer_addpoints.Stop(); timer_addpoints.Stop();
static Timer taddseg("addseg");
taddseg.Start();
/*
for (auto seg : mesh.LineSegments()) for (auto seg : mesh.LineSegments())
{ {
if ( seg.domin == domainnr || seg.domout == domainnr ) if ( seg.domin == domainnr || seg.domout == domainnr )
@ -690,6 +739,18 @@ namespace netgen
tempmesh.AddSegment(seg); tempmesh.AddSegment(seg);
} }
} }
*/
for (const auto & line : adfront.GetLines())
{
Segment seg;
for (int j = 0; j < 2; j++)
seg[j] = icompress [adfront.GetGlobalIndex (line.L()[j])];
seg.domin = domainnr;
seg.domout = 0;
tempmesh.AddSegment(seg);
}
taddseg.Stop();
for (auto & trig : dmesh.GetElements()) for (auto & trig : dmesh.GetElements())
{ {
@ -883,7 +944,7 @@ namespace netgen
} }
} }
mesh.Compress(); // mesh.Compress(); // don't compress whole mesh after every sub-domain
} }
} }

View File

@ -381,7 +381,12 @@ namespace netgen
return; return;
} }
box->flags.cutboundary = 1; if (!box->flags.cutboundary)
for (int i = 0; i < 8; i++)
if (box->childs[i])
box->childs[i]->flags.cutboundary = false;
box->flags.cutboundary = true;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
if (box->childs[i]) if (box->childs[i])
CutBoundaryRec (pmin, pmax, box->childs[i]); CutBoundaryRec (pmin, pmax, box->childs[i]);
@ -547,13 +552,19 @@ namespace netgen
void LocalH :: FindInnerBoxes (AdFront2 * adfront, void LocalH :: FindInnerBoxes (AdFront2 * adfront,
int (*testinner)(const Point<2> & p1)) int (*testinner)(const Point<2> & p1))
{ {
static int timer = NgProfiler::CreateTimer ("LocalH::FindInnerBoxes 2d"); static Timer t("LocalH::FindInnerBoxes 2d"); RegionTimer reg (t);
NgProfiler::RegionTimer reg (timer); static Timer trec("LocalH::FindInnerBoxes 2d - rec");
static Timer tinit("LocalH::FindInnerBoxes 2d - init");
/*
tinit.Start();
for (int i = 0; i < boxes.Size(); i++) for (int i = 0; i < boxes.Size(); i++)
boxes[i] -> flags.isinner = 0; boxes[i] -> flags.isinner = 0;
tinit.Stop();
*/
root->flags.isinner = 0; root->flags.isinner = 0;
root->flags.cutboundary = true;
Point<2> rpmid(root->xmid[0], root->xmid[1]); // , root->xmid[2]); Point<2> rpmid(root->xmid[0], root->xmid[1]); // , root->xmid[2]);
Vec<2> rv(root->h2, root->h2); Vec<2> rv(root->h2, root->h2);
@ -583,6 +594,7 @@ namespace netgen
faceboxes[i].Add (Point<2> (p2(0), p2(1))); faceboxes[i].Add (Point<2> (p2(0), p2(1)));
} }
RegionTimer regrc(trec);
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (root->childs[i], adfront, faceboxes, faceinds); // , nf); FindInnerBoxesRec2 (root->childs[i], adfront, faceboxes, faceinds); // , nf);
} }
@ -602,11 +614,13 @@ namespace netgen
{ {
box->flags.isinner = father->flags.isinner; box->flags.isinner = father->flags.isinner;
box->flags.pinner = father->flags.pinner; box->flags.pinner = father->flags.pinner;
box->flags.cutboundary = false;
} }
else else
{ {
if (father->flags.isinner) if (father->flags.isinner)
{ {
cout << "how is this possible ???" << endl;
box->flags.pinner = 1; box->flags.pinner = 1;
} }
else else
@ -673,6 +687,8 @@ namespace netgen
} }
} }
if (box->flags.isinner || box->flags.cutboundary)
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (box->childs[i], adfront, faceboxes, faceinds.Range(0,iused)); FindInnerBoxesRec2 (box->childs[i], adfront, faceboxes, faceinds.Range(0,iused));
} }
@ -720,6 +736,13 @@ namespace netgen
ClearFlagsRec (box->childs[i]); ClearFlagsRec (box->childs[i]);
} }
void LocalH :: ClearRootFlags ()
{
root->flags.cutboundary = false;
root->flags.isinner = false;
}
void LocalH :: ClearFlagsRec (GradingBox * box) void LocalH :: ClearFlagsRec (GradingBox * box)
{ {
box->flags.cutboundary = 0; box->flags.cutboundary = 0;
@ -746,13 +769,17 @@ namespace netgen
} }
} }
void LocalH :: GetInnerPoints (NgArray<Point<3> > & points) void LocalH :: GetInnerPoints (NgArray<Point<3> > & points) const
{ {
static Timer t("GetInnerPoints"); RegionTimer reg(t);
if (dimension == 2) if (dimension == 2)
{ {
GetInnerPointsRec (root, points);
/*
for (int i = 0; i < boxes.Size(); i++) for (int i = 0; i < boxes.Size(); i++)
if (boxes[i] -> flags.isinner && boxes[i] -> HasChilds()) if (boxes[i] -> flags.isinner && boxes[i] -> HasChilds())
points.Append ( boxes[i] -> PMid() ); points.Append ( boxes[i] -> PMid() );
*/
} }
else else
{ {
@ -763,6 +790,17 @@ namespace netgen
} }
void LocalH :: GetInnerPointsRec (const GradingBox * box, NgArray<Point<3> > & points) const
{
if (box -> flags.isinner && box -> HasChilds())
points.Append ( box -> PMid() );
if (box->flags.isinner || box->flags.cutboundary)
for (int i = 0; i < 8; i++)
if (box->childs[i])
GetInnerPointsRec (box->childs[i], points);
}
void LocalH :: GetOuterPoints (NgArray<Point<3> > & points) void LocalH :: GetOuterPoints (NgArray<Point<3> > & points)
{ {

View File

@ -121,11 +121,14 @@ namespace netgen
void ClearFlags () void ClearFlags ()
{ ClearFlagsRec(root); } { ClearFlagsRec(root); }
void ClearRootFlags ();
/// widen refinement zone /// widen refinement zone
void WidenRefinement (); void WidenRefinement ();
/// get points in inner elements /// get points in inner elements
void GetInnerPoints (NgArray<Point<3> > & points); void GetInnerPoints (NgArray<Point<3> > & points) const;
void GetInnerPointsRec (const GradingBox * box, NgArray<Point<3> > & points) const;
/// get points in outer closure /// get points in outer closure
void GetOuterPoints (NgArray<Point<3> > & points); void GetOuterPoints (NgArray<Point<3> > & points);