delaunay meshing

This commit is contained in:
Joachim Schoeberl 2010-09-23 14:07:12 +00:00
parent b20dda8e4a
commit 834937c671
17 changed files with 967 additions and 682 deletions

View File

@ -228,6 +228,11 @@ namespace netgen
mparam.checkoverlap = 0;
/*
if (!mparam.quad)
meshing.Delaunay (*mesh, domnr, mparam);
else
*/
meshing.GenerateMesh (*mesh, h, domnr);
for (SurfaceElementIndex sei = oldnf; sei < mesh->GetNSE(); sei++)

View File

@ -197,6 +197,14 @@ protected:
Point<D> pmin, pmax;
public:
Box () { ; }
Box ( const Point<D> & p1)
{
for (int i = 0; i < D; i++)
pmin(i) = pmax(i) = p1(i);
}
Box ( const Point<D> & p1, const Point<D> & p2)
{
for (int i = 0; i < D; i++)

View File

@ -43,6 +43,7 @@ namespace netgen
{
Point3d p;
in >> p.X() >> p.Y() >> p.Z();
p.Z() *= 10;
mesh.AddPoint (p);
}

View File

@ -262,6 +262,7 @@ namespace netgen
if (det == 0)
{
(*myerr) << "CalcInverse: Matrix singular" << endl;
(*testout) << "CalcInverse: Matrix singular" << endl;
return;
}
@ -488,6 +489,7 @@ namespace netgen
if (max < 1e-20)
{
cerr << "Inverse matrix: matrix singular" << endl;
*testout << "Inverse matrix: matrix singular" << endl;
return;
}

View File

@ -16,9 +16,10 @@ clusters.hpp hprefinement.hpp improve3.hpp meshtype.hpp \
METASOURCES = AUTO
noinst_LTLIBRARIES = libmesh.la
libmesh_la_SOURCES = adfront2.cpp adfront3.cpp bisect.cpp boundarylayer.cpp \
clusters.cpp curvedelems.cpp delaunay.cpp geomsearch.cpp global.cpp \
hprefinement.cpp improve2.cpp improve2gen.cpp improve3.cpp localh.cpp \
meshclass.cpp meshfunc.cpp meshfunc2d.cpp meshing2.cpp meshing3.cpp \
clusters.cpp curvedelems.cpp delaunay.cpp delaunay2d.cpp \
geomsearch.cpp global.cpp hprefinement.cpp improve2.cpp \
improve2gen.cpp improve3.cpp localh.cpp meshclass.cpp \
meshfunc.cpp meshfunc2d.cpp meshing2.cpp meshing3.cpp \
meshtool.cpp meshtype.cpp msghandler.cpp netrule2.cpp \
netrule3.cpp parser2.cpp parser3.cpp prism2rls.cpp \
pyramid2rls.cpp pyramidrls.cpp quadrls.cpp refine.cpp \

View File

@ -8,7 +8,7 @@
namespace netgen
{
AdFront2::FrontPoint2 :: FrontPoint2 (const Point<3> & ap, PointIndex agi,
FrontPoint2 :: FrontPoint2 (const Point<3> & ap, PointIndex agi,
MultiPointGeomInfo * amgi, bool aonsurface)
{
p = ap;
@ -464,4 +464,45 @@ namespace netgen
ost << flush;
}
bool AdFront2 :: Inside (const Point<2> & p) const
{
int cnt;
Vec<2> n;
Vec<3> v1;
DenseMatrix a(2), ainv(2);
Vector b(2), u(2);
// random numbers:
n(0) = 0.123871;
n(1) = 0.15432;
cnt = 0;
for (int i = 0; i < lines.Size(); i++)
if (lines[i].Valid())
{
const Point<3> & p1 = points[lines[i].L().I1()].P();
const Point<3> & p2 = points[lines[i].L().I2()].P();
v1 = p2 - p1;
a(0, 0) = v1(0);
a(1, 0) = v1(1);
a(0, 1) = -n(0);
a(1, 1) = -n(1);
b(0) = p(0) - p1(0);
b(1) = p(1) - p1(1);
CalcInverse (a, ainv);
ainv.Mult (b, u);
if (u(0) >= 0 && u(0) <= 1 && u(1) > 0)
cnt++;
}
return ((cnt % 2) != 0);
}
}

View File

@ -13,8 +13,6 @@
Advancing front class for surfaces
*/
class AdFront2
{
///
class FrontPoint2
@ -163,6 +161,8 @@ class AdFront2
};
class AdFront2
{
///
Array<FrontPoint2> points; /// front points
@ -202,6 +202,11 @@ public:
}
///
int GetNFL () const { return nfl; }
const FrontLine & GetLine (int nr) { return lines[nr]; }
const FrontPoint2 & GetPoint (int nr) { return points[nr]; }
///
int SelectBaseLine (Point<3> & p1, Point<3> & p2,
const PointGeomInfo *& geominfo1,
@ -250,6 +255,18 @@ public:
{
return points[pi].GlobalIndex();
}
/// is Point p inside Surface (flat geometry only)
bool Inside (const Point<2> & p) const;
bool SameSide (const Point<2> & lp1, const Point<2> & lp2,
const Array<int> * testfaces = NULL) const
{
return Inside (lp1) == Inside (lp2);
}
///
void SetStartFront ();
///

View File

@ -772,7 +772,7 @@ void AdFront3 :: SetStartFront (int /* baseelnp */)
bool AdFront3 :: Inside (const Point<3> & p) const
{
int i, cnt;
int cnt;
Vec3d n, v1, v2;
DenseMatrix a(3), ainv(3);
Vector b(3), u(3);
@ -783,7 +783,7 @@ bool AdFront3 :: Inside (const Point<3> & p) const
n.Z() = -0.43989;
cnt = 0;
for (i = 1; i <= faces.Size(); i++)
for (int i = 1; i <= faces.Size(); i++)
if (faces.Get(i).Valid())
{
const Point<3> & p1 = points[faces.Get(i).Face().PNum(1)].P();
@ -827,36 +827,29 @@ bool AdFront3 :: Inside (const Point<3> & p) const
int AdFront3 :: SameSide (const Point<3> & lp1, const Point<3> & lp2,
const Array<int> * testfaces) const
{
int i, ii, cnt;
const Point<3> *line[2];
line[0] = &lp1;
line[1] = &lp2;
cnt = 0;
Point3d pmin(lp1);
Point3d pmax(lp1);
pmin.SetToMin (lp2);
pmax.SetToMax (lp2);
static Array<int> aprif;
ArrayMem<int, 100> aprif;
aprif.SetSize(0);
if (!testfaces)
facetree->GetIntersecting (pmin, pmax, aprif);
else
{
for (i = 1; i <= testfaces->Size(); i++)
for (int i = 1; i <= testfaces->Size(); i++)
aprif.Append (testfaces->Get(i));
}
// (*testout) << "test ss, p1,p2 = " << lp1 << lp2 << ", inters = " << aprif.Size() << endl;
// for (i = 1; i <= faces.Size(); i++)
for (ii = 1; ii <= aprif.Size(); ii++)
int cnt = 0;
for (int ii = 1; ii <= aprif.Size(); ii++)
{
i = aprif.Get(ii);
int i = aprif.Get(ii);
if (faces.Get(i).Valid())
{
@ -867,7 +860,6 @@ int AdFront3 :: SameSide (const Point<3> & lp1, const Point<3> & lp2,
if (IntersectTriangleLine (&tri[0], &line[0]))
cnt++;
}
}

View File

@ -0,0 +1,174 @@
#include <mystdlib.h>
#include "meshing.hpp"
// not yet working ....
namespace netgen
{
void Meshing2 :: BlockFillLocalH (Mesh & mesh, const MeshingParameters & mp)
{
double filldist = mp.filldist;
cout << "blockfill local h" << endl;
cout << "rel filldist = " << filldist << endl;
PrintMessage (3, "blockfill local h");
Array<Point<3> > npoints;
// adfront -> CreateTrees();
Box<3> bbox ( Box<3>::EMPTY_BOX );
double maxh = 0;
for (int i = 0; i < adfront->GetNFL(); i++)
{
const FrontLine & line = adfront->GetLine (i);
const Point<3> & p1 = adfront->GetPoint(line.L().I1());
const Point<3> & p2 = adfront->GetPoint(line.L().I2());
double hi = Dist (p1, p2);
if (hi > maxh) maxh = hi;
bbox.Add (p1);
bbox.Add (p2);
}
cout << "bbox = " << bbox << endl;
Point<3> mpc = bbox.Center();
bbox.Increase (bbox.Diam()/2);
Box<3> meshbox = bbox;
LocalH loch2 (bbox, 1);
if (mp.maxh < maxh) maxh = mp.maxh;
bool changed;
do
{
mesh.LocalHFunction().ClearFlags();
for (int i = 0; i < adfront->GetNFL(); i++)
{
const FrontLine & line = adfront->GetLine(i);
Box<3> bbox (adfront->GetPoint (line.L().I1()));
bbox.Add (adfront->GetPoint (line.L().I2()));
double filld = filldist * bbox.Diam();
bbox.Increase (filld);
mesh.LocalHFunction().CutBoundary (bbox);
}
mesh.LocalHFunction().FindInnerBoxes (adfront, NULL);
npoints.SetSize(0);
mesh.LocalHFunction().GetInnerPoints (npoints);
changed = false;
for (int i = 0; i < npoints.Size(); i++)
{
if (mesh.LocalHFunction().GetH(npoints[i]) > 1.5 * maxh)
{
mesh.LocalHFunction().SetH (npoints[i], maxh);
changed = true;
}
}
}
while (changed);
if (debugparam.slowchecks)
(*testout) << "Blockfill with points: " << endl;
*testout << "loch = " << mesh.LocalHFunction() << endl;
*testout << "npoints = " << endl << npoints << endl;
for (int i = 1; i <= npoints.Size(); i++)
{
if (meshbox.IsIn (npoints.Get(i)))
{
int gpnum = mesh.AddPoint (npoints.Get(i));
adfront->AddPoint (npoints.Get(i), gpnum);
if (debugparam.slowchecks)
{
(*testout) << npoints.Get(i) << endl;
Point<2> p2d (npoints.Get(i)(0), npoints.Get(i)(1));
if (!adfront->Inside(p2d))
{
cout << "add outside point" << endl;
(*testout) << "outside" << endl;
}
}
}
}
// find outer points
loch2.ClearFlags();
for (int i = 0; i < adfront->GetNFL(); i++)
{
const FrontLine & line = adfront->GetLine(i);
Box<3> bbox (adfront->GetPoint (line.L().I1()));
bbox.Add (adfront->GetPoint (line.L().I2()));
loch2.SetH (bbox.Center(), bbox.Diam());
}
for (int i = 0; i < adfront->GetNFL(); i++)
{
const FrontLine & line = adfront->GetLine(i);
Box<3> bbox (adfront->GetPoint (line.L().I1()));
bbox.Add (adfront->GetPoint (line.L().I2()));
bbox.Increase (filldist * bbox.Diam());
loch2.CutBoundary (bbox);
}
loch2.FindInnerBoxes (adfront, NULL);
npoints.SetSize(0);
loch2.GetOuterPoints (npoints);
for (int i = 1; i <= npoints.Size(); i++)
{
if (meshbox.IsIn (npoints.Get(i)))
{
int gpnum = mesh.AddPoint (npoints.Get(i));
adfront->AddPoint (npoints.Get(i), gpnum);
}
}
}
void Meshing2 :: Delaunay (Mesh & mesh, int domainnr, const MeshingParameters & mp)
{
cout << "2D Delaunay meshing (in progress)" << endl;
int oldnp = mesh.GetNP();
cout << "np, old = " << mesh.GetNP() << endl;
BlockFillLocalH (mesh, mp);
cout << "np, now = " << mesh.GetNP() << endl;
}
}

View File

@ -8,19 +8,8 @@ namespace netgen
GradingBox :: GradingBox (const double * ax1, const double * ax2)
{
h2 = 0.5 * (ax2[0] - ax1[0]);
for (int i = 0; i <= 2; i++)
{
/*
x1[i] = ax1[i];
x2[i] = ax2[i];
*/
for (int i = 0; i < 3; i++)
xmid[i] = 0.5 * (ax1[i] + ax2[i]);
}
/*
(*testout) << "new box: " << xmid[0] << "-" << xmid[1] << "-" << xmid[2]
<< " h = " << (x2[0] - x1[0]) << endl;
*/
for (int i = 0; i < 8; i++)
childs[i] = NULL;
@ -31,12 +20,10 @@ GradingBox :: GradingBox (const double * ax1, const double * ax2)
flags.oldcell = 0;
flags.pinner = 0;
// hopt = x2[0] - x1[0];
hopt = 2 * h2;
}
BlockAllocator GradingBox :: ball(sizeof (GradingBox));
void * GradingBox :: operator new(size_t)
@ -53,12 +40,9 @@ void GradingBox :: operator delete (void * p)
void GradingBox :: DeleteChilds()
{
int i;
for (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
if (childs[i])
{
childs[i]->DeleteChilds();
@ -72,32 +56,65 @@ LocalH :: LocalH (const Point3d & pmin, const Point3d & pmax, double agrading)
{
double x1[3], x2[3];
double hmax;
int i;
boundingbox = Box3d (pmin, pmax);
grading = agrading;
// a small enlargement, non-regular points
double val = 0.0879;
for (i = 1; i <= 3; i++)
for (int i = 1; i <= 3; i++)
{
x1[i-1] = (1 + val * i) * pmin.X(i) - val * i * pmax.X(i);
x2[i-1] = 1.1 * pmax.X(i) - 0.1 * pmin.X(i);
}
hmax = x2[0] - x1[0];
for (i = 1; i <= 2; i++)
for (int i = 1; i <= 2; i++)
if (x2[i] - x1[i] > hmax)
hmax = x2[i] - x1[i];
for (i = 0; i <= 2; i++)
for (int i = 0; i <= 2; i++)
x2[i] = x1[i] + hmax;
root = new GradingBox (x1, x2);
boxes.Append (root);
}
LocalH :: LocalH (const Box<3> & box, double agrading)
{
Point3d pmin = box.PMin();
Point3d pmax = box.PMax();
double x1[3], x2[3];
double hmax;
boundingbox = Box3d (pmin, pmax);
grading = agrading;
// a small enlargement, non-regular points
double val = 0.0879;
for (int i = 1; i <= 3; i++)
{
x1[i-1] = (1 + val * i) * pmin.X(i) - val * i * pmax.X(i);
x2[i-1] = 1.1 * pmax.X(i) - 0.1 * pmin.X(i);
}
hmax = x2[0] - x1[0];
for (int i = 1; i <= 2; i++)
if (x2[i] - x1[i] > hmax)
hmax = x2[i] - x1[i];
for (int i = 0; i <= 2; i++)
x2[i] = x1[i] + hmax;
root = new GradingBox (x1, x2);
boxes.Append (root);
}
LocalH :: ~LocalH ()
{
root->DeleteChilds();
@ -209,8 +226,7 @@ void LocalH :: SetH (const Point3d & p, double h)
double hnp = h + grading * hbox;
Point3d np;
int i;
for (i = 1; i <= 3; i++)
for (int i = 1; i <= 3; i++)
{
np = p;
np.X(i) = p.X(i) + hbox;
@ -219,20 +235,6 @@ void LocalH :: SetH (const Point3d & p, double h)
np.X(i) = p.X(i) - hbox;
SetH (np, hnp);
}
/*
Point3d np;
int i1, i2, i3;
for (i1 = -1; i1 <= 1; i1++)
for (i2 = -1; i2 <= 1; i2++)
for (i3 = -1; i3 <= 1; i3++)
{
np.X() = p.X() + hbox * i1;
np.Y() = p.Y() + hbox * i2;
np.Z() = p.Z() + hbox * i3;
SetH (np, hnp);
}
*/
}
@ -240,26 +242,20 @@ void LocalH :: SetH (const Point3d & p, double h)
double LocalH :: GetH (const Point3d & x) const
{
const GradingBox * box = root;
const GradingBox * nbox;
int childnr;
while (1)
{
childnr = 0;
int childnr = 0;
if (x.X() > box->xmid[0]) childnr += 1;
if (x.Y() > box->xmid[1]) childnr += 2;
if (x.Z() > box->xmid[2]) childnr += 4;
nbox = box->childs[childnr];
if (nbox)
box = nbox;
if (box->childs[childnr])
box = box->childs[childnr];
else
{
// (*testout) << "diam = " << (box->x2[0] - box->x1[0])
// << " h = " << box->hopt << endl;
return box->hopt;
}
}
}
/// minimal h in box (pmin, pmax)
@ -284,26 +280,12 @@ double LocalH :: GetMinHRec (const Point3d & pmin, const Point3d & pmax,
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;
/*
if (pmax.X() < box->x1[0] || pmin.X() > box->x2[0] ||
pmax.Y() < box->x1[1] || pmin.Y() > box->x2[1] ||
pmax.Z() < box->x1[2] || pmin.Z() > box->x2[2])
return 1e8;
*/
double hmin = 2 * box->h2; // box->x2[0] - box->x1[0];
int i;
for (i = 0; i <= 7; i++)
{
for (int i = 0; i < 8; i++)
if (box->childs[i])
{
double hi = GetMinHRec (pmin, pmax, box->childs[i]);
if (hi < hmin)
hmin = hi;
}
}
hmin = min2 (hmin, GetMinHRec (pmin, pmax, box->childs[i]));
return hmin;
}
@ -317,12 +299,7 @@ void LocalH :: CutBoundaryRec (const Point3d & pmin, const Point3d & pmax,
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;
/*
if (pmax.X() < box->x1[0] || pmin.X() > box->x2[0] ||
pmax.Y() < box->x1[1] || pmin.Y() > box->x2[1] ||
pmax.Z() < box->x1[2] || pmin.Z() > box->x2[2])
return;
*/
box->flags.cutboundary = 1;
for (int i = 0; i < 8; i++)
@ -333,15 +310,12 @@ void LocalH :: CutBoundaryRec (const Point3d & pmin, const Point3d & pmax,
void LocalH :: FindInnerBoxes ( // int (*sameside)(const Point3d & p1, const Point3d & p2),
AdFront3 * adfront,
void LocalH :: FindInnerBoxes (AdFront3 * adfront,
int (*testinner)(const Point3d & p1))
{
int i;
int nf = adfront->GetNF();
for (i = 0; i < boxes.Size(); i++)
for (int i = 0; i < boxes.Size(); i++)
boxes[i] -> flags.isinner = 0;
root->flags.isinner = 0;
@ -361,13 +335,13 @@ void LocalH :: FindInnerBoxes ( // int (*sameside)(const Point3d & p1, const Poi
Array<int> faceinds(nf);
Array<Box3d> faceboxes(nf);
for (i = 1; i <= nf; i++)
for (int i = 1; i <= nf; i++)
{
faceinds.Elem(i) = i;
adfront->GetFaceBoundingBox(i, faceboxes.Elem(i));
}
for (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (root->childs[i], adfront, faceboxes, faceinds, nf);
}
@ -380,8 +354,6 @@ FindInnerBoxesRec2 (GradingBox * box,
{
if (!box) return;
int i, j;
GradingBox * father = box -> father;
Point3d c(box->xmid[0], box->xmid[1], box->xmid[2]);
@ -394,16 +366,17 @@ FindInnerBoxesRec2 (GradingBox * box,
Box3d boxcfc(c,fc);
ArrayMem<int, 100> faceused;
ArrayMem<int, 100> faceused2;
ArrayMem<int, 100> facenotused;
static Array<int> faceused;
static Array<int> faceused2;
static Array<int> facenotused;
/*
faceused.SetSize(0);
facenotused.SetSize(0);
faceused2.SetSize(0);
*/
for (j = 1; j <= nfinbox; j++)
for (int j = 1; j <= nfinbox; j++)
{
// adfront->GetFaceBoundingBox (faceinds.Get(j), facebox);
const Box3d & facebox = faceboxes.Get(faceinds.Get(j));
@ -417,9 +390,9 @@ FindInnerBoxesRec2 (GradingBox * box,
faceused2.Append (faceinds.Get(j));
}
for (j = 1; j <= faceused.Size(); j++)
for (int j = 1; j <= faceused.Size(); j++)
faceinds.Elem(j) = faceused.Get(j);
for (j = 1; j <= facenotused.Size(); j++)
for (int j = 1; j <= facenotused.Size(); j++)
faceinds.Elem(j+faceused.Size()) = facenotused.Get(j);
@ -448,13 +421,33 @@ FindInnerBoxesRec2 (GradingBox * box,
box->flags.isinner = box->flags.pinner;
}
// cout << "faceused: " << faceused.Size() << ", " << faceused2.Size() << ", " << facenotused.Size() << endl;
int nf = faceused.Size();
for (i = 0; i < 8; i++)
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);
}
}
@ -464,36 +457,97 @@ FindInnerBoxesRec2 (GradingBox * box,
/*
void LocalH :: FindInnerBoxes ( // int (*sameside)(const Point3d & p1, const Point3d & p2),
AdFront3 * adfront,
int (*testinner)(const Point3d & p1))
void LocalH :: FindInnerBoxes (AdFront2 * adfront,
int (*testinner)(const Point<2> & p1))
{
int i;
for (i = 1; i <= boxes.Size(); i++)
boxes.Elem(i)->flags.isinner = 0;
int nf = adfront->GetNFL();
for (int i = 0; i < boxes.Size(); i++)
boxes[i] -> flags.isinner = 0;
root->flags.isinner = 0;
Point3d rpmid(root->xmid[0], root->xmid[1], root->xmid[2]);
Point3d rx2 = rpmid + Vec3d (root->h2, root->h2, root->h2);
Point<2> rpmid(root->xmid[0], root->xmid[1], root->xmid[2]);
Vec<2> rv(root->h2, root->h2);
Point<2> rx2 = rpmid + rv;
Point<2> rx1 = rpmid - rv;
root->flags.pinner = !adfront->SameSide (rpmid, rx2);
if (testinner)
(*testout) << "inner = " << root->flags.pinner << " =?= "
<< testinner(Point3d(root->xmid[0], root->xmid[1], root->xmid[2])) << endl;
<< testinner(rpmid) << endl;
Array<int> faceinds(nf);
Array<Box<3> > faceboxes(nf);
for (i = 2; i <= boxes.Size(); i++)
for (int i = 0; i < nf; i++)
{
GradingBox * box = boxes.Elem(i);
faceinds[i] = i;
// adfront->GetFaceBoundingBox(i, faceboxes.Elem(i));
const FrontLine & line = adfront->GetLine(i);
faceboxes[i].Set (adfront->GetPoint (line.L().I1()));
faceboxes[i].Add (adfront->GetPoint (line.L().I2()));
}
for (int i = 0; i < 8; i++)
FindInnerBoxesRec2 (root->childs[i], adfront, faceboxes, faceinds, nf);
}
void LocalH ::
FindInnerBoxesRec2 (GradingBox * box,
class AdFront2 * adfront,
Array<Box<3> > & faceboxes,
Array<int> & faceinds, int nfinbox)
{
if (!box) return;
GradingBox * father = box -> father;
Point3d c(box->xmid[0], box->xmid[1], box->xmid[2]);
Vec3d v(box->h2, box->h2, box->h2);
Point3d x1 = c-v;
Point3d x2 = c+v;
Box3d boxc(c-v, c+v);
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);
Box3d boxcfc(c,fc);
ArrayMem<int, 100> faceused;
ArrayMem<int, 100> faceused2;
ArrayMem<int, 100> facenotused;
for (int j = 1; j <= nfinbox; j++)
{
// adfront->GetFaceBoundingBox (faceinds.Get(j), facebox);
const Box3d & facebox = faceboxes.Get(faceinds.Get(j));
if (boxc.Intersect (facebox))
faceused.Append(faceinds.Get(j));
else
facenotused.Append(faceinds.Get(j));
if (boxcfc.Intersect (facebox))
faceused2.Append (faceinds.Get(j));
}
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);
if (!father->flags.cutboundary)
@ -509,7 +563,9 @@ void LocalH :: FindInnerBoxes ( // int (*sameside)(const Point3d & p1, const Poi
box->flags.pinner = 1;
else
{
if (adfront->SameSide (c, cf))
Point<2> c2d (c.X(), c.Y());
Point<2> cf2d (cf.X(), cf.Y());
if (adfront->SameSide (c2d, cf2d, &faceused2))
box->flags.pinner = father->flags.pinner;
else
box->flags.pinner = 1 - father->flags.pinner;
@ -520,30 +576,49 @@ void LocalH :: FindInnerBoxes ( // int (*sameside)(const Point3d & p1, const Poi
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);
}
// FindInnerBoxesRec (inner, root);
}
*/
void LocalH :: FindInnerBoxesRec ( int (*inner)(const Point3d & p),
void LocalH :: FindInnerBoxesRec ( int (*inner)(const Point<2> & p),
GradingBox * box)
{
int i;
if (box->flags.cutboundary)
{
for (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
if (box->childs[i])
FindInnerBoxesRec (inner, box->childs[i]);
}
else
{
if (inner (Point3d (box->xmid[0], box->xmid[1], box->xmid[2])))
Point<2> p2d(box->PMid()(0), box->PMid()(1));
if (inner (p2d))
SetInnerBoxesRec (box);
}
}
void LocalH :: SetInnerBoxesRec (GradingBox * box)
{
box->flags.isinner = 1;
@ -564,17 +639,10 @@ void LocalH :: ClearFlagsRec (GradingBox * box)
void LocalH :: WidenRefinement ()
{
int nb = boxes.Size();
int i;
// (*testout) << "old boxes: " << nb << endl;
for (i = 1; i <= nb; i++)
for (int i = 0; i < boxes.Size(); i++)
{
GradingBox * box = boxes.Get(i);
// double h = box->x2[0] - box->x1[0];
double h = box->hopt;
Point3d c(box->xmid[0], box->xmid[1], box->xmid[2]);
// (*testout) << " i = " << i
// << " c = " << c << " h = " << h << endl;
double h = boxes[i]->hopt;
Point3d c = boxes[i]->PMid();
for (int i1 = -1; i1 <= 1; i1++)
for (int i2 = -1; i2 <= 1; i2++)
@ -585,48 +653,20 @@ void LocalH :: WidenRefinement ()
}
}
void LocalH :: GetInnerPoints (Array<Point3d> & points)
void LocalH :: GetInnerPoints (Array<Point<3> > & points)
{
int i, nb = boxes.Size();
for (i = 1; i <= nb; i++)
{
GradingBox * box = boxes.Get(i);
/*
if (box->flags.pinner)
points.Append (box->randomip);
*/
// if (box->flags.pinner)
if (box->flags.isinner)
{
Point3d c(box->xmid[0], box->xmid[1], box->xmid[2]);
points.Append (c);
/*
cout << "add point " << c << "; h = " << box->hopt
<< "; max-min = " << (box->x2[0]-box->x1[0]) << endl;
*/
}
}
for (int i = 0; i < boxes.Size(); i++)
if (boxes[i] -> flags.isinner)
points.Append ( boxes[i] -> PMid() );
}
void LocalH :: GetOuterPoints (Array<Point3d> & points)
void LocalH :: GetOuterPoints (Array<Point<3> > & points)
{
int i, nb = boxes.Size();
for (i = 1; i <= nb; i++)
{
GradingBox * box = boxes.Get(i);
if (!box->flags.isinner &&
!box->flags.cutboundary)
{
Point3d c(box->xmid[0], box->xmid[1], box->xmid[2]);
points.Append (c);
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 ()
@ -636,38 +676,26 @@ void LocalH :: Convexify ()
void LocalH :: ConvexifyRec (GradingBox * box)
{
Point3d center(box->xmid[0], box->xmid[1], box->xmid[2]);
Point3d hp;
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;
int i;
for (i = 1; i <= 6; i++)
for (int i = 0; i < 3; i++)
{
hp = center;
switch (i)
{
case 1: hp.X() += dx; break;
case 2: hp.X() -= dx; break;
case 3: hp.Y() += dx; break;
case 4: hp.Y() -= dx; break;
case 5: hp.Z() += dx; break;
case 6: hp.Z() -= dx; break;
}
double hh = GetH (hp);
if (hh > maxh) maxh = hh;
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 (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
if (box->childs[i])
ConvexifyRec (box->childs[i]);
}

View File

@ -13,12 +13,6 @@
/// box for grading
class GradingBox
{
/*
/// xmin
float x1[3];
/// xmax
float x2[3];
*/
/// xmid
float xmid[3];
/// half edgelength
@ -30,6 +24,8 @@ class GradingBox
///
double hopt;
///
public:
struct
{
unsigned int cutboundary:1;
@ -37,14 +33,17 @@ class GradingBox
unsigned int oldcell:1;
unsigned int pinner:1;
} flags;
public:
///
GradingBox (const double * ax1, const double * ax2);
///
void DeleteChilds();
///
friend class LocalH;
Point<3> PMid() const { return Point<3> (xmid[0], xmid[1], xmid[2]); }
double H2() const { return h2; }
friend class LocalH;
static BlockAllocator ball;
void * operator new(size_t);
@ -53,6 +52,7 @@ public:
/**
Control of 3D mesh grading
*/
@ -70,6 +70,8 @@ public:
///
LocalH (const Point3d & pmin, const Point3d & pmax, double grading);
///
LocalH (const Box<3> & box, double grading);
///
~LocalH();
///
void Delete();
@ -83,14 +85,19 @@ public:
double GetMinH (const Point3d & pmin, const Point3d & pmax) const;
/// mark boxes intersecting with boundary-box
void CutBoundary (const Point3d & pmin, const Point3d & pmax)
{ CutBoundaryRec (pmin, pmax, root); }
// void CutBoundary (const Point3d & pmin, const Point3d & pmax)
// { CutBoundaryRec (pmin, pmax, root); }
void CutBoundary (const Box<3> & box)
{ CutBoundaryRec (box.PMin(), box.PMax(), root); }
/// find inner boxes
void FindInnerBoxes ( // int (*sameside)(const Point3d & p1, const Point3d & p2),
class AdFront3 * adfront,
void FindInnerBoxes (class AdFront3 * adfront,
int (*testinner)(const Point3d & p1));
void FindInnerBoxes (class AdFront2 * adfront,
int (*testinner)(const Point<2> & p1));
/// clears all flags
void ClearFlags ()
{ ClearFlagsRec(root); }
@ -99,10 +106,10 @@ public:
void WidenRefinement ();
/// get points in inner elements
void GetInnerPoints (Array<Point3d> & points);
void GetInnerPoints (Array<Point<3> > & points);
/// get points in outer closure
void GetOuterPoints (Array<Point3d> & points);
void GetOuterPoints (Array<Point<3> > & points);
///
void Convexify ();
@ -131,6 +138,18 @@ private:
Array<int> & finds, int nfinbox);
void FindInnerBoxesRec ( int (*inner)(const Point<2> & p),
GradingBox * box);
///
void FindInnerBoxesRec2 (GradingBox * box,
class AdFront2 * adfront,
Array<Box<3> > & faceboxes,
Array<int> & finds, int nfinbox);
///
void SetInnerBoxesRec (GradingBox * box);
@ -139,7 +158,26 @@ private:
///
void ConvexifyRec (GradingBox * box);
friend ostream & operator<< (ostream & ost, const LocalH & loch);
};
inline ostream & operator<< (ostream & ost, const GradingBox & box)
{
ost << "gradbox, pmid = " << box.PMid() << ", h2 = " << box.H2()
<< " cutbound = " << box.flags.cutboundary << " isinner = " << box.flags.isinner
<< endl;
return ost;
}
inline ostream & operator<< (ostream & ost, const LocalH & loch)
{
for (int i = 0; i < loch.boxes.Size(); i++)
ost << "box[" << i << "] = " << *(loch.boxes[i]);
return ost;
}
#endif

View File

@ -4365,7 +4365,7 @@ namespace netgen
if(el.GetType() == TET || el.GetType() == TET10)
if (el.GetType() == TET)
{
retval = (lam(0) > -eps &&
lam(1) > -eps &&

View File

@ -54,6 +54,10 @@ public:
///
MESHING2_RESULT GenerateMesh (Mesh & mesh, double gh, int facenr);
void Delaunay (Mesh & mesh, int domainnr, const MeshingParameters & mp);
void BlockFillLocalH (Mesh & mesh, const MeshingParameters & mp);
///
void AddPoint (const Point3d & p, PointIndex globind, MultiPointGeomInfo * mgi = NULL,
bool pointonsurface = true);

View File

@ -1082,7 +1082,7 @@ void Meshing3 :: BlockFill (Mesh & mesh, double gh)
}
/*
static const AdFront3 * locadfront;
static int TestInner (const Point3d & p)
{
@ -1092,62 +1092,45 @@ static int TestSameSide (const Point3d & p1, const Point3d & p2)
{
return locadfront->SameSide (p1, p2);
}
*/
void Meshing3 :: BlockFillLocalH (Mesh & mesh,
const MeshingParameters & mp)
{
int i, j;
double filldist = mp.filldist;
(*testout) << "blockfill local h" << endl;
(*testout) << "rel filldist = " << filldist << endl;
PrintMessage (3, "blockfill local h");
/*
(*mycout) << "boxes: " << mesh.LocalHFunction().GetNBoxes() << endl
<< "filldist = " << filldist << endl;
*/
Array<Point3d> npoints;
Array<Point<3> > npoints;
adfront -> CreateTrees();
Point3d mpmin, mpmax;
// mesh.GetBox (mpmin, mpmax);
bool firstp = 1;
Box<3> bbox ( Box<3>::EMPTY_BOX );
double maxh = 0;
for (i = 1; i <= adfront->GetNF(); i++)
for (int i = 1; i <= adfront->GetNF(); i++)
{
const MiniElement2d & el = adfront->GetFace(i);
for (j = 1; j <= 3; j++)
for (int j = 1; j <= 3; j++)
{
const Point3d & p1 = adfront->GetPoint (el.PNumMod(j));
const Point3d & p2 = adfront->GetPoint (el.PNumMod(j+1));
double hi = Dist (p1, p2);
if (hi > maxh)
{
maxh = hi;
//(*testout) << "reducing maxh to " << maxh << " because of " << p1 << " and " << p2 << endl;
}
if (hi > maxh) maxh = hi;
if (firstp)
{
mpmin = p1;
mpmax = p1;
firstp = 0;
}
else
{
mpmin.SetToMin (p1);
mpmax.SetToMax (p1);
}
bbox.Add (p1);
}
}
Point3d mpmin = bbox.PMin();
Point3d mpmax = bbox.PMax();
Point3d mpc = Center (mpmin, mpmax);
double d = max3(mpmax.X()-mpmin.X(),
mpmax.Y()-mpmin.Y(),
@ -1158,53 +1141,41 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
LocalH loch2 (mpmin, mpmax, 1);
if (mp.maxh < maxh) maxh = mp.maxh;
if (mp.maxh < maxh)
{
maxh = mp.maxh;
//(*testout) << "reducing maxh to " << maxh << " because of mp.maxh" << endl;
}
int changed;
bool changed;
do
{
mesh.LocalHFunction().ClearFlags();
for (i = 1; i <= adfront->GetNF(); i++)
for (int i = 1; i <= adfront->GetNF(); i++)
{
const MiniElement2d & el = adfront->GetFace(i);
Point3d pmin = adfront->GetPoint (el.PNum(1));
Point3d pmax = pmin;
for (j = 2; j <= 3; j++)
{
const Point3d & p = adfront->GetPoint (el.PNum(j));
pmin.SetToMin (p);
pmax.SetToMax (p);
Box<3> bbox (adfront->GetPoint (el[0]));
bbox.Add (adfront->GetPoint (el[1]));
bbox.Add (adfront->GetPoint (el[2]));
double filld = filldist * bbox.Diam();
bbox.Increase (filld);
mesh.LocalHFunction().CutBoundary (bbox); // .PMin(), bbox.PMax());
}
double filld = filldist * Dist (pmin, pmax);
pmin = pmin - Vec3d (filld, filld, filld);
pmax = pmax + Vec3d (filld, filld, filld);
// (*testout) << "cut : " << pmin << " - " << pmax << endl;
mesh.LocalHFunction().CutBoundary (pmin, pmax);
}
locadfront = adfront;
// locadfront = adfront;
mesh.LocalHFunction().FindInnerBoxes (adfront, NULL);
npoints.SetSize(0);
mesh.LocalHFunction().GetInnerPoints (npoints);
changed = 0;
for (i = 1; i <= npoints.Size(); i++)
changed = false;
for (int i = 1; i <= npoints.Size(); i++)
{
if (mesh.LocalHFunction().GetH(npoints.Get(i)) > 1.5 * maxh)
{
mesh.LocalHFunction().SetH (npoints.Get(i), maxh);
changed = 1;
changed = true;
}
}
}
@ -1212,7 +1183,7 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
if (debugparam.slowchecks)
(*testout) << "Blockfill with points: " << endl;
for (i = 1; i <= npoints.Size(); i++)
for (int i = 1; i <= npoints.Size(); i++)
{
if (meshbox.IsIn (npoints.Get(i)))
{
@ -1238,13 +1209,13 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
loch2.ClearFlags();
for (i = 1; i <= adfront->GetNF(); i++)
for (int i = 1; i <= adfront->GetNF(); i++)
{
const MiniElement2d & el = adfront->GetFace(i);
Point3d pmin = adfront->GetPoint (el.PNum(1));
Point3d pmax = pmin;
for (j = 2; j <= 3; j++)
for (int j = 2; j <= 3; j++)
{
const Point3d & p = adfront->GetPoint (el.PNum(j));
pmin.SetToMin (p);
@ -1254,13 +1225,13 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
loch2.SetH (Center (pmin, pmax), Dist (pmin, pmax));
}
for (i = 1; i <= adfront->GetNF(); i++)
for (int i = 1; i <= adfront->GetNF(); i++)
{
const MiniElement2d & el = adfront->GetFace(i);
Point3d pmin = adfront->GetPoint (el.PNum(1));
Point3d pmax = pmin;
for (j = 2; j <= 3; j++)
for (int j = 2; j <= 3; j++)
{
const Point3d & p = adfront->GetPoint (el.PNum(j));
pmin.SetToMin (p);
@ -1270,16 +1241,17 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh,
double filld = filldist * Dist (pmin, pmax);
pmin = pmin - Vec3d (filld, filld, filld);
pmax = pmax + Vec3d (filld, filld, filld);
loch2.CutBoundary (pmin, pmax);
// loch2.CutBoundary (pmin, pmax);
loch2.CutBoundary (Box<3> (pmin, pmax)); // pmin, pmax);
}
locadfront = adfront;
// locadfront = adfront;
loch2.FindInnerBoxes (adfront, NULL);
npoints.SetSize(0);
loch2.GetOuterPoints (npoints);
for (i = 1; i <= npoints.Size(); i++)
for (int i = 1; i <= npoints.Size(); i++)
{
if (meshbox.IsIn (npoints.Get(i)))
{

View File

@ -496,6 +496,8 @@ proc saveoptions { } {
puts $datei "stloptions.recalchopt ${stloptions.recalchopt}"
puts $datei "visoptions.subdivisions ${visoptions.subdivisions}"
puts $datei "visoptions.autoredraw ${visoptions.autoredraw}"
puts $datei "visoptions.autoredrawtime ${visoptions.autoredrawtime}"
# trafo options

View File

@ -66,7 +66,7 @@ int main (int argc, char ** argv)
Ng_Meshing_Parameters mp;
mp.maxh = 1.0e+6;
mp.fineness = 0.4;
mp.secondorder = 0;
mp.second_order = 0;
cout << "Initialise the STL Geometry structure...." << endl;
ng_res = Ng_STL_InitSTLGeometry(stl_geom);

View File

@ -63,7 +63,7 @@ int main (int argc, char ** argv)
Ng_Meshing_Parameters mp;
mp.maxh = 1e6;
mp.fineness = 1;
mp.secondorder = 0;
mp.second_order = 0;
cout << "start meshing" << endl;
Ng_GenerateVolumeMesh (mesh, &mp);