ENH: cvMesh: speed up edge refinement

This commit is contained in:
laurence
2013-02-12 15:45:21 +00:00
parent 10042d2a0a
commit 15ba9ec7c5
4 changed files with 56 additions and 19 deletions

View File

@ -109,6 +109,11 @@ public:
// Query // Query
const Time& time() const
{
return runTime_;
}
//- Calculate and return the barycentric coordinates for //- Calculate and return the barycentric coordinates for
// interpolating quantities on the background mesh // interpolating quantities on the background mesh
void barycentricCoords void barycentricCoords

View File

@ -51,18 +51,18 @@ Foam::scalar Foam::controlMeshRefinement::calcFirstDerivative
} }
Foam::scalar Foam::controlMeshRefinement::calcSecondDerivative //Foam::scalar Foam::controlMeshRefinement::calcSecondDerivative
( //(
const Foam::point& a, // const Foam::point& a,
const scalar& cellSizeA, // const scalar& cellSizeA,
const Foam::point& midPoint, // const Foam::point& midPoint,
const scalar& cellSizeMid, // const scalar& cellSizeMid,
const Foam::point& b, // const Foam::point& b,
const scalar& cellSizeB // const scalar& cellSizeB
) const //) const
{ //{
return (cellSizeA - 2*cellSizeMid + cellSizeB)/magSqr((a - b)/2); // return (cellSizeA - 2*cellSizeMid + cellSizeB)/magSqr((a - b)/2);
} //}
bool Foam::controlMeshRefinement::detectEdge bool Foam::controlMeshRefinement::detectEdge
@ -77,15 +77,23 @@ bool Foam::controlMeshRefinement::detectEdge
Foam::point a(startPt); Foam::point a(startPt);
Foam::point b(endPt); Foam::point b(endPt);
// scalar cellSizeA = sizeControls_.cellSize(a);
// scalar cellSizeB = sizeControls_.cellSize(b);
Foam::point midPoint = (a + b)/2.0; Foam::point midPoint = (a + b)/2.0;
// scalar cellSizeMid = sizeControls_.cellSize(midPoint);
label nIterations = 0; label nIterations = 0;
while (true) while (true)
{ {
nIterations++; nIterations++;
if (magSqr(a - b) < tolSqr) if
(
magSqr(a - b) < tolSqr
)
{ {
pointFound.setPoint(midPoint); pointFound.setPoint(midPoint);
pointFound.setHit(); pointFound.setHit();
@ -95,9 +103,15 @@ bool Foam::controlMeshRefinement::detectEdge
// Split into two regions // Split into two regions
const scalar cellSizeA = sizeControls_.cellSize(a); scalar cellSizeA = sizeControls_.cellSize(a);
const scalar cellSizeB = sizeControls_.cellSize(b); scalar cellSizeB = sizeControls_.cellSize(b);
const scalar cellSizeMid = sizeControls_.cellSize(midPoint);
if (magSqr(cellSizeA - cellSizeB) < 1e-6)
{
return false;
}
scalar cellSizeMid = sizeControls_.cellSize(midPoint);
// Region 1 // Region 1
Foam::point midPoint1 = (a + midPoint)/2.0; Foam::point midPoint1 = (a + midPoint)/2.0;
@ -150,12 +164,16 @@ bool Foam::controlMeshRefinement::detectEdge
if (magSqr(secondDerivative1) > magSqr(secondDerivative2)) if (magSqr(secondDerivative1) > magSqr(secondDerivative2))
{ {
b = midPoint; b = midPoint;
// cellSizeB = cellSizeMid;
midPoint = midPoint1; midPoint = midPoint1;
// cellSizeMid = cellSizeMid1;
} }
else else
{ {
a = midPoint; a = midPoint;
// cellSizeA = cellSizeMid;
midPoint = midPoint2; midPoint = midPoint2;
// cellSizeMid = cellSizeMid2;
} }
} }
} }
@ -435,6 +453,8 @@ Foam::label Foam::controlMeshRefinement::refineMesh
DynamicList<Vb> verts(mesh_.number_of_vertices()); DynamicList<Vb> verts(mesh_.number_of_vertices());
label count = 0;
for for
( (
CellSizeDelaunay::Finite_edges_iterator eit = CellSizeDelaunay::Finite_edges_iterator eit =
@ -443,6 +463,14 @@ Foam::label Foam::controlMeshRefinement::refineMesh
++eit ++eit
) )
{ {
if (count % 10000 == 0)
{
Info<< count << " edges, inserted " << verts.size()
<< " Time = " << mesh_.time().elapsedCpuTime()
<< endl;
}
count++;
CellSizeDelaunay::Cell_handle c = eit->first; CellSizeDelaunay::Cell_handle c = eit->first;
CellSizeDelaunay::Vertex_handle vA = c->vertex(eit->second); CellSizeDelaunay::Vertex_handle vA = c->vertex(eit->second);
CellSizeDelaunay::Vertex_handle vB = c->vertex(eit->third); CellSizeDelaunay::Vertex_handle vB = c->vertex(eit->third);
@ -452,8 +480,8 @@ Foam::label Foam::controlMeshRefinement::refineMesh
mesh_.is_infinite(vA) mesh_.is_infinite(vA)
|| mesh_.is_infinite(vB) || mesh_.is_infinite(vB)
|| (vA->referred() && vB->referred()) || (vA->referred() && vB->referred())
|| (vA->referred() && vA->procIndex() > vB->procIndex()) || (vA->referred() && (vA->procIndex() > vB->procIndex()))
|| (vB->referred() && vB->procIndex() > vA->procIndex()) || (vB->referred() && (vB->procIndex() > vA->procIndex()))
) )
{ {
continue; continue;

View File

@ -82,7 +82,10 @@ class controlMeshRefinement
const scalar& cellSizeMid, const scalar& cellSizeMid,
const Foam::point& b, const Foam::point& b,
const scalar& cellSizeB const scalar& cellSizeB
) const; ) const
{
return (cellSizeA - 2*cellSizeMid + cellSizeB)/magSqr((a - b)/2);
}
bool detectEdge bool detectEdge

View File

@ -86,6 +86,7 @@ void Foam::conformationSurfaces::hasBoundedVolume
Info<< " Sum of all the surface normals (if near zero, surface is" Info<< " Sum of all the surface normals (if near zero, surface is"
<< " probably closed):" << nl << " probably closed):" << nl
<< " Note: Does not include baffle surfaces in calculation" << nl
<< " Sum = " << sum/totalTriangles << nl << " Sum = " << sum/totalTriangles << nl
<< " mag(Sum) = " << mag(sum)/totalTriangles << " mag(Sum) = " << mag(sum)/totalTriangles
<< endl; << endl;