netgen/libsrc/meshing/localh.cpp

850 lines
20 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#include <mystdlib.h>
#include "meshing.hpp"
namespace netgen
{
2010-09-23 20:07:12 +06:00
GradingBox :: GradingBox (const double * ax1, const double * ax2)
{
h2 = 0.5 * (ax2[0] - ax1[0]);
for (int i = 0; i < 3; i++)
2009-01-13 04:40:13 +05:00
xmid[i] = 0.5 * (ax1[i] + ax2[i]);
2010-09-23 20:07:12 +06:00
for (int i = 0; i < 8; i++)
childs[i] = NULL;
father = NULL;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
flags.cutboundary = 0;
flags.isinner = 0;
flags.oldcell = 0;
flags.pinner = 0;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
hopt = 2 * h2;
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
BlockAllocator GradingBox :: ball(sizeof (GradingBox));
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void * GradingBox :: operator new(size_t)
{
return ball.Alloc();
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void GradingBox :: operator delete (void * p)
{
ball.Free (p);
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void GradingBox :: DeleteChilds()
{
for (int i = 0; i < 8; i++)
if (childs[i])
{
childs[i]->DeleteChilds();
delete childs[i];
childs[i] = NULL;
}
}
2009-01-13 04:40:13 +05:00
2014-12-02 18:23:36 +05:00
LocalH :: LocalH (Point<3> pmin, Point<3> pmax, double agrading, int adimension)
: dimension(adimension)
2010-09-23 20:07:12 +06:00
{
double x1[3], x2[3];
double hmax;
2009-01-13 04:40:13 +05:00
2014-12-02 18:23:36 +05:00
boundingbox = Box<3> (pmin, pmax);
2010-09-23 20:07:12 +06:00
grading = agrading;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
// a small enlargement, non-regular points
double val = 0.0879;
2014-12-02 18:23:36 +05:00
for (int i = 0; i < dimension; i++)
2009-01-13 04:40:13 +05:00
{
2014-12-02 18:23:36 +05:00
x1[i] = (1 + val * (i+1)) * pmin(i) - val * (i+1) * pmax(i);
x2[i] = 1.1 * pmax(i) - 0.1 * pmin(i);
2009-01-13 04:40:13 +05:00
}
2014-12-02 18:23:36 +05:00
for (int i = dimension; i < 3; i++)
x1[i] = x2[i] = 0;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
hmax = x2[0] - x1[0];
2014-12-02 18:23:36 +05:00
for (int i = 1; i < dimension; i++)
hmax = max2(x2[i]-x1[i], hmax);
2009-01-13 04:40:13 +05:00
2014-12-02 18:23:36 +05:00
for (int i = 0; i < dimension; i++)
2010-09-23 20:07:12 +06:00
x2[i] = x1[i] + hmax;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
root = new GradingBox (x1, x2);
boxes.Append (root);
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
LocalH :: ~LocalH ()
{
root->DeleteChilds();
delete root;
}
void LocalH :: Delete ()
{
root->DeleteChilds();
}
2014-12-02 18:23:36 +05:00
void LocalH :: SetH (Point<3> p, double h)
2010-09-23 20:07:12 +06:00
{
2014-12-02 18:23:36 +05:00
if (dimension == 2)
2010-09-23 20:07:12 +06:00
{
2014-12-02 18:23:36 +05:00
if (fabs (p(0) - root->xmid[0]) > root->h2 ||
fabs (p(1) - root->xmid[1]) > root->h2)
return;
if (GetH(p) <= 1.2 * h) return;
GradingBox * box = root;
GradingBox * nbox = root;
GradingBox * ngb;
int childnr;
double x1[3], x2[3];
while (nbox)
{
box = nbox;
childnr = 0;
if (p(0) > box->xmid[0]) childnr += 1;
if (p(1) > box->xmid[1]) childnr += 2;
nbox = box->childs[childnr];
};
while (2 * box->h2 > h)
{
childnr = 0;
if (p(0) > box->xmid[0]) childnr += 1;
if (p(1) > box->xmid[1]) childnr += 2;
double h2 = box->h2;
if (childnr & 1)
{
x1[0] = box->xmid[0];
x2[0] = x1[0]+h2; // box->x2[0];
}
else
{
x2[0] = box->xmid[0];
x1[0] = x2[0]-h2; // box->x1[0];
}
if (childnr & 2)
{
x1[1] = box->xmid[1];
x2[1] = x1[1]+h2; // box->x2[1];
}
else
{
x2[1] = box->xmid[1];
x1[1] = x2[1]-h2; // box->x1[1];
}
x1[2] = x2[2] = 0;
ngb = new GradingBox (x1, x2);
box->childs[childnr] = ngb;
ngb->father = box;
boxes.Append (ngb);
box = box->childs[childnr];
}
box->hopt = h;
double hbox = 2 * box->h2; // box->x2[0] - box->x1[0];
double hnp = h + grading * hbox;
Point<3> np;
for (int i = 0; i < 2; i++)
{
np = p;
np(i) = p(i) + hbox;
SetH (np, hnp);
np(i) = p(i) - hbox;
SetH (np, hnp);
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
}
2009-01-13 04:40:13 +05:00
2014-12-02 18:23:36 +05:00
else
2010-09-23 20:07:12 +06:00
{
2014-12-02 18:23:36 +05:00
if (fabs (p(0) - root->xmid[0]) > root->h2 ||
fabs (p(1) - root->xmid[1]) > root->h2 ||
fabs (p(2) - root->xmid[2]) > root->h2)
return;
if (GetH(p) <= 1.2 * h) return;
GradingBox * box = root;
GradingBox * nbox = root;
GradingBox * ngb;
int childnr;
double x1[3], x2[3];
while (nbox)
{
box = nbox;
childnr = 0;
if (p(0) > box->xmid[0]) childnr += 1;
if (p(1) > box->xmid[1]) childnr += 2;
if (p(2) > box->xmid[2]) childnr += 4;
nbox = box->childs[childnr];
};
while (2 * box->h2 > h)
{
childnr = 0;
if (p(0) > box->xmid[0]) childnr += 1;
if (p(1) > box->xmid[1]) childnr += 2;
if (p(2) > box->xmid[2]) childnr += 4;
double h2 = box->h2;
if (childnr & 1)
{
x1[0] = box->xmid[0];
x2[0] = x1[0]+h2; // box->x2[0];
}
else
{
x2[0] = box->xmid[0];
x1[0] = x2[0]-h2; // box->x1[0];
}
if (childnr & 2)
{
x1[1] = box->xmid[1];
x2[1] = x1[1]+h2; // box->x2[1];
}
else
{
x2[1] = box->xmid[1];
x1[1] = x2[1]-h2; // box->x1[1];
}
if (childnr & 4)
{
x1[2] = box->xmid[2];
x2[2] = x1[2]+h2; // box->x2[2];
}
else
{
x2[2] = box->xmid[2];
x1[2] = x2[2]-h2; // box->x1[2];
}
ngb = new GradingBox (x1, x2);
box->childs[childnr] = ngb;
ngb->father = box;
boxes.Append (ngb);
box = box->childs[childnr];
}
box->hopt = h;
double hbox = 2 * box->h2; // box->x2[0] - box->x1[0];
double hnp = h + grading * hbox;
Point<3> np;
for (int i = 0; i < 3; i++)
{
np = p;
np(i) = p(i) + hbox;
SetH (np, hnp);
np(i) = p(i) - hbox;
SetH (np, hnp);
}
2010-09-23 20:07:12 +06:00
}
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
2014-12-02 18:23:36 +05:00
double LocalH :: GetH (Point<3> x) const
2010-09-23 20:07:12 +06:00
{
const GradingBox * box = root;
2014-12-02 18:23:36 +05:00
if (dimension == 2)
2010-09-23 20:07:12 +06:00
{
2014-12-02 18:23:36 +05:00
while (1)
{
int childnr = 0;
if (x(0) > box->xmid[0]) childnr += 1;
if (x(1) > box->xmid[1]) childnr += 2;
if (box->childs[childnr])
box = box->childs[childnr];
else
return box->hopt;
}
2010-09-23 20:07:12 +06:00
}
2014-12-02 18:23:36 +05:00
else
{
while (1)
{
int childnr = 0;
if (x(0) > box->xmid[0]) childnr += 1;
if (x(1) > box->xmid[1]) childnr += 2;
if (x(2) > box->xmid[2]) childnr += 4;
if (box->childs[childnr])
box = box->childs[childnr];
else
return box->hopt;
}
}
2010-09-23 20:07:12 +06:00
}
/// minimal h in box (pmin, pmax)
2014-12-02 18:23:36 +05:00
double LocalH :: GetMinH (Point<3> pmin, Point<3> pmax) const
2010-09-23 20:07:12 +06:00
{
2014-12-02 18:23:36 +05:00
Point<3> pmin2, pmax2;
for (int j = 0; j < 3; j++)
if (pmin(j) < pmax(j))
{ pmin2(j) = pmin(j); pmax2(j) = pmax(j); }
2010-09-23 20:07:12 +06:00
else
2014-12-02 18:23:36 +05:00
{ pmin2(j) = pmax(j); pmax2(j) = pmin(j); }
2010-09-23 20:07:12 +06:00
return GetMinHRec (pmin2, pmax2, root);
}
double LocalH :: GetMinHRec (const Point3d & pmin, const Point3d & pmax,
const GradingBox * box) const
{
2014-12-02 18:23:36 +05:00
if (dimension == 2)
{
double h2 = box->h2;
if (pmax.X() < box->xmid[0]-h2 || pmin.X() > box->xmid[0]+h2 ||
pmax.Y() < box->xmid[1]-h2 || pmin.Y() > box->xmid[1]+h2)
return 1e8;
double hmin = 2 * box->h2; // box->x2[0] - box->x1[0];
for (int i = 0; i < 8; i++)
if (box->childs[i])
hmin = min2 (hmin, GetMinHRec (pmin, pmax, box->childs[i]));
return hmin;
}
else
{
double h2 = box->h2;
if (pmax.X() < box->xmid[0]-h2 || pmin.X() > box->xmid[0]+h2 ||
pmax.Y() < box->xmid[1]-h2 || pmin.Y() > box->xmid[1]+h2 ||
pmax.Z() < box->xmid[2]-h2 || pmin.Z() > box->xmid[2]+h2)
return 1e8;
double hmin = 2 * box->h2; // box->x2[0] - box->x1[0];
for (int i = 0; i < 8; i++)
if (box->childs[i])
hmin = min2 (hmin, GetMinHRec (pmin, pmax, box->childs[i]));
return hmin;
}
2010-09-23 20:07:12 +06:00
}
2009-01-13 04:40:13 +05:00
2014-12-02 18:23:36 +05:00
2010-09-23 20:07:12 +06:00
void LocalH :: CutBoundaryRec (const Point3d & pmin, const Point3d & pmax,
GradingBox * box)
{
double h2 = box->h2;
2014-12-02 18:23:36 +05:00
if (dimension == 2)
{
if (pmax.X() < box->xmid[0]-h2 || pmin.X() > box->xmid[0]+h2 ||
pmax.Y() < box->xmid[1]-h2 || pmin.Y() > box->xmid[1]+h2)
return;
}
else
{
if (pmax.X() < box->xmid[0]-h2 || pmin.X() > box->xmid[0]+h2 ||
pmax.Y() < box->xmid[1]-h2 || pmin.Y() > box->xmid[1]+h2 ||
pmax.Z() < box->xmid[2]-h2 || pmin.Z() > box->xmid[2]+h2)
return;
}
2009-01-13 04:40:13 +05:00
2020-10-25 20:31:47 +05:00
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;
2010-09-23 20:07:12 +06:00
for (int i = 0; i < 8; i++)
if (box->childs[i])
CutBoundaryRec (pmin, pmax, box->childs[i]);
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void LocalH :: FindInnerBoxes (AdFront3 * adfront,
int (*testinner)(const Point3d & p1))
{
2014-12-02 18:23:36 +05:00
static int timer = NgProfiler::CreateTimer ("LocalH::FindInnerBoxes");
NgProfiler::RegionTimer reg (timer);
2010-09-23 20:07:12 +06:00
int nf = adfront->GetNF();
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int i = 0; i < boxes.Size(); i++)
boxes[i] -> flags.isinner = 0;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
root->flags.isinner = 0;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
Point3d rpmid(root->xmid[0], root->xmid[1], root->xmid[2]);
Vec3d rv(root->h2, root->h2, root->h2);
Point3d rx2 = rpmid + rv;
2011-05-13 17:41:53 +06:00
// Point3d rx1 = rpmid - rv;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
root->flags.pinner = !adfront->SameSide (rpmid, rx2);
2014-12-02 18:23:36 +05:00
2010-09-23 20:07:12 +06:00
if (testinner)
(*testout) << "inner = " << root->flags.pinner << " =?= "
<< testinner(Point3d(root->xmid[0], root->xmid[1], root->xmid[2])) << endl;
2014-12-02 18:23:36 +05:00
2019-07-09 13:39:16 +05:00
NgArray<int> faceinds(nf);
NgArray<Box3d> faceboxes(nf);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int i = 1; i <= nf; i++)
{
faceinds.Elem(i) = i;
adfront->GetFaceBoundingBox(i, faceboxes.Elem(i));
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (root->childs[i], adfront, faceboxes, faceinds, nf);
}
void LocalH ::
FindInnerBoxesRec2 (GradingBox * box,
class AdFront3 * adfront,
2019-07-09 13:39:16 +05:00
NgArray<Box3d> & faceboxes,
NgArray<int> & faceinds, int nfinbox)
2010-09-23 20:07:12 +06:00
{
if (!box) return;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
GradingBox * father = box -> father;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
Point3d c(box->xmid[0], box->xmid[1], box->xmid[2]);
Vec3d v(box->h2, box->h2, box->h2);
Box3d boxc(c-v, c+v);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
Point3d fc(father->xmid[0], father->xmid[1], father->xmid[2]);
Vec3d fv(father->h2, father->h2, father->h2);
Box3d fboxc(fc-fv, fc+fv);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
Box3d boxcfc(c,fc);
2009-01-13 04:40:13 +05:00
2019-07-09 21:00:12 +05:00
NgArrayMem<int, 100> faceused;
NgArrayMem<int, 100> faceused2;
NgArrayMem<int, 100> facenotused;
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
/*
faceused.SetSize(0);
facenotused.SetSize(0);
faceused2.SetSize(0);
*/
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int j = 1; j <= nfinbox; j++)
{
// adfront->GetFaceBoundingBox (faceinds.Get(j), facebox);
const Box3d & facebox = faceboxes.Get(faceinds.Get(j));
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
if (boxc.Intersect (facebox))
faceused.Append(faceinds.Get(j));
else
facenotused.Append(faceinds.Get(j));
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
if (boxcfc.Intersect (facebox))
faceused2.Append (faceinds.Get(j));
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int j = 1; j <= faceused.Size(); j++)
faceinds.Elem(j) = faceused.Get(j);
for (int j = 1; j <= facenotused.Size(); j++)
faceinds.Elem(j+faceused.Size()) = facenotused.Get(j);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
if (!father->flags.cutboundary)
{
box->flags.isinner = father->flags.isinner;
box->flags.pinner = father->flags.pinner;
}
else
{
Point3d cf(father->xmid[0], father->xmid[1], father->xmid[2]);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
if (father->flags.isinner)
box->flags.pinner = 1;
else
{
if (adfront->SameSide (c, cf, &faceused2))
box->flags.pinner = father->flags.pinner;
else
box->flags.pinner = 1 - father->flags.pinner;
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
if (box->flags.cutboundary)
box->flags.isinner = 0;
else
box->flags.isinner = box->flags.pinner;
}
// cout << "faceused: " << faceused.Size() << ", " << faceused2.Size() << ", " << facenotused.Size() << endl;
int nf = faceused.Size();
for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (box->childs[i], adfront, faceboxes, faceinds, nf);
}
void LocalH :: FindInnerBoxesRec ( int (*inner)(const Point3d & p),
GradingBox * box)
{
if (box->flags.cutboundary)
{
for (int i = 0; i < 8; i++)
if (box->childs[i])
FindInnerBoxesRec (inner, box->childs[i]);
}
else
{
if (inner (box->PMid()))
SetInnerBoxesRec (box);
}
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void LocalH :: FindInnerBoxes (AdFront2 * adfront,
int (*testinner)(const Point<2> & p1))
{
2020-10-25 20:31:47 +05:00
static Timer t("LocalH::FindInnerBoxes 2d"); RegionTimer reg (t);
static Timer trec("LocalH::FindInnerBoxes 2d - rec");
static Timer tinit("LocalH::FindInnerBoxes 2d - init");
2010-09-23 20:07:12 +06:00
2020-10-25 20:31:47 +05:00
/*
tinit.Start();
2010-09-23 20:07:12 +06:00
for (int i = 0; i < boxes.Size(); i++)
boxes[i] -> flags.isinner = 0;
2020-10-25 20:31:47 +05:00
tinit.Stop();
*/
2010-09-23 20:07:12 +06:00
root->flags.isinner = 0;
2020-10-25 20:31:47 +05:00
root->flags.cutboundary = true;
2010-09-23 20:07:12 +06:00
2014-08-20 01:58:36 +06:00
Point<2> rpmid(root->xmid[0], root->xmid[1]); // , root->xmid[2]);
2010-09-23 20:07:12 +06:00
Vec<2> rv(root->h2, root->h2);
Point<2> rx2 = rpmid + rv;
2011-05-13 17:41:53 +06:00
// Point<2> rx1 = rpmid - rv;
2010-09-23 20:07:12 +06:00
root->flags.pinner = !adfront->SameSide (rpmid, rx2);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
if (testinner)
(*testout) << "inner = " << root->flags.pinner << " =?= "
<< testinner(rpmid) << endl;
2014-12-02 18:23:36 +05:00
int nf = adfront->GetNFL();
Array<int> faceinds(nf);
Array<Box<2>> faceboxes(nf);
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int i = 0; i < nf; i++)
{
faceinds[i] = i;
const FrontLine & line = adfront->GetLine(i);
Point<3> p1 = adfront->GetPoint (line.L().I1());
Point<3> p2 = adfront->GetPoint (line.L().I2());
faceboxes[i].Set (Point<2> (p1(0), p1(1)));
faceboxes[i].Add (Point<2> (p2(0), p2(1)));
2010-09-23 20:07:12 +06:00
}
2020-10-25 20:31:47 +05:00
RegionTimer regrc(trec);
2010-09-23 20:07:12 +06:00
for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (root->childs[i], adfront, faceboxes, faceinds); // , nf);
2010-09-23 20:07:12 +06:00
}
void LocalH ::
FindInnerBoxesRec2 (GradingBox * box,
class AdFront2 * adfront,
FlatArray<Box<2>> faceboxes,
FlatArray<int> faceinds) // , int nfinbox)
2010-09-23 20:07:12 +06:00
{
if (!box) return;
2009-01-13 04:40:13 +05:00
GradingBox * father = box -> father;
2010-09-23 20:07:12 +06:00
if (!father->flags.cutboundary)
{
box->flags.isinner = father->flags.isinner;
box->flags.pinner = father->flags.pinner;
2020-10-25 20:31:47 +05:00
box->flags.cutboundary = false;
2010-09-23 20:07:12 +06:00
}
else
{
2010-09-23 20:07:12 +06:00
if (father->flags.isinner)
2014-12-02 18:23:36 +05:00
{
2020-10-25 20:31:47 +05:00
cout << "how is this possible ???" << endl;
2014-12-02 18:23:36 +05:00
box->flags.pinner = 1;
}
2010-09-23 20:07:12 +06:00
else
{
Point<2> c(box->xmid[0], box->xmid[1]);
Point<2> fc(father->xmid[0], father->xmid[1]);
Box<2> boxcfc(c,fc);
// reorder: put faces cutting boxcfc first:
int iused = 0;
int inotused = faceinds.Size()-1;
while (iused <= inotused)
{
while ( (iused <= inotused) && boxcfc.Intersect (faceboxes[faceinds[iused]]))
iused++;
while ( (iused <= inotused) && !boxcfc.Intersect (faceboxes[faceinds[inotused]]))
inotused--;
if (iused < inotused)
{
Swap (faceinds[iused], faceinds[inotused]);
iused++;
inotused--;
}
}
// bool sameside = adfront->SameSide (c2d, cf2d, &faceused2);
auto sub = faceinds.Range(0, iused);
bool sameside = adfront->SameSide (c, fc, &sub);
2014-12-02 18:23:36 +05:00
if (sameside)
2010-09-23 20:07:12 +06:00
box->flags.pinner = father->flags.pinner;
else
box->flags.pinner = 1 - father->flags.pinner;
}
if (box->flags.cutboundary)
box->flags.isinner = 0;
else
box->flags.isinner = box->flags.pinner;
}
2009-01-13 04:40:13 +05:00
int iused = 0;
if (faceinds.Size())
{
Point<2> c(box->xmid[0], box->xmid[1]); // box->xmid[2]);
Vec<2> v(box->h2, box->h2);
Box<2> boxc(c-v, c+v);
// reorder again: put faces cutting boxc first:
int inotused = faceinds.Size()-1;
while (iused <= inotused)
{
while ( (iused <= inotused) && boxc.Intersect (faceboxes[faceinds[iused]]))
iused++;
while ( (iused <= inotused) && !boxc.Intersect (faceboxes[faceinds[inotused]]))
inotused--;
if (iused < inotused)
{
Swap (faceinds[iused], faceinds[inotused]);
iused++;
inotused--;
}
}
}
2020-10-25 20:31:47 +05:00
if (box->flags.isinner || box->flags.cutboundary)
for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (box->childs[i], adfront, faceboxes, faceinds.Range(0,iused));
2010-09-23 20:07:12 +06:00
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void LocalH :: FindInnerBoxesRec ( int (*inner)(const Point<2> & p),
GradingBox * box)
{
if (box->flags.cutboundary)
{
for (int i = 0; i < 8; i++)
if (box->childs[i])
FindInnerBoxesRec (inner, box->childs[i]);
}
else
{
Point<2> p2d(box->PMid()(0), box->PMid()(1));
if (inner (p2d))
SetInnerBoxesRec (box);
}
}
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
void LocalH :: SetInnerBoxesRec (GradingBox * box)
{
box->flags.isinner = 1;
for (int i = 0; i < 8; i++)
if (box->childs[i])
ClearFlagsRec (box->childs[i]);
}
2020-10-25 20:31:47 +05:00
void LocalH :: ClearRootFlags ()
{
root->flags.cutboundary = false;
root->flags.isinner = false;
}
2010-09-23 20:07:12 +06:00
void LocalH :: ClearFlagsRec (GradingBox * box)
{
box->flags.cutboundary = 0;
box->flags.isinner = 0;
for (int i = 0; i < 8; i++)
if (box->childs[i])
ClearFlagsRec (box->childs[i]);
}
void LocalH :: WidenRefinement ()
{
for (int i = 0; i < boxes.Size(); i++)
{
double h = boxes[i]->hopt;
Point3d c = boxes[i]->PMid();
2009-01-13 04:40:13 +05:00
2010-09-23 20:07:12 +06:00
for (int i1 = -1; i1 <= 1; i1++)
for (int i2 = -1; i2 <= 1; i2++)
for (int i3 = -1; i3 <= 1; i3++)
SetH (Point3d (c.X() + i1 * h,
c.Y() + i2 * h,
c.Z() + i3 * h), 1.001 * h);
}
}
2009-01-13 04:40:13 +05:00
2020-10-25 20:31:47 +05:00
void LocalH :: GetInnerPoints (NgArray<Point<3> > & points) const
2010-09-23 20:07:12 +06:00
{
2020-10-25 20:31:47 +05:00
static Timer t("GetInnerPoints"); RegionTimer reg(t);
2014-12-02 18:23:36 +05:00
if (dimension == 2)
{
2020-10-25 20:31:47 +05:00
GetInnerPointsRec (root, points);
/*
2014-12-02 18:23:36 +05:00
for (int i = 0; i < boxes.Size(); i++)
if (boxes[i] -> flags.isinner && boxes[i] -> HasChilds())
points.Append ( boxes[i] -> PMid() );
2020-10-25 20:31:47 +05:00
*/
2014-12-02 18:23:36 +05:00
}
else
{
for (int i = 0; i < boxes.Size(); i++)
if (boxes[i] -> flags.isinner)
points.Append ( boxes[i] -> PMid() );
}
2010-09-23 20:07:12 +06:00
}
2009-01-13 04:40:13 +05:00
2020-10-25 20:31:47 +05:00
void LocalH :: GetInnerPointsRec (const GradingBox * box, NgArray<Point<3> > & points) const
{
if (box -> flags.isinner && box -> HasChilds())
points.Append ( box -> PMid() );
2009-01-13 04:40:13 +05:00
2020-10-25 20:31:47 +05:00
if (box->flags.isinner || box->flags.cutboundary)
for (int i = 0; i < 8; i++)
if (box->childs[i])
GetInnerPointsRec (box->childs[i], points);
}
2019-07-09 13:39:16 +05:00
void LocalH :: GetOuterPoints (NgArray<Point<3> > & points)
2010-09-23 20:07:12 +06:00
{
for (int i = 0; i < boxes.Size(); i++)
if (!boxes[i]->flags.isinner && !boxes[i]->flags.cutboundary)
points.Append ( boxes[i] -> PMid());
}
void LocalH :: Convexify ()
{
ConvexifyRec (root);
}
void LocalH :: ConvexifyRec (GradingBox * box)
{
Point<3> center = box -> PMid();
double size = 2 * box->h2; // box->x2[0] - box->x1[0];
double dx = 0.6 * size;
double maxh = box->hopt;
for (int i = 0; i < 3; i++)
{
Point<3> hp = center;
hp(i) += dx;
maxh = max2 (maxh, GetH(hp));
hp(i) = center(i)-dx;
maxh = max2 (maxh, GetH(hp));
}
if (maxh < 0.95 * box->hopt)
SetH (center, maxh);
for (int i = 0; i < 8; i++)
if (box->childs[i])
ConvexifyRec (box->childs[i]);
}
void LocalH :: PrintMemInfo (ostream & ost) const
{
ost << "LocalH: " << boxes.Size() << " boxes of " << sizeof(GradingBox)
<< " bytes = " << boxes.Size()*sizeof(GradingBox) << " bytes" << endl;
}
2009-01-13 04:40:13 +05:00
}