boundingBox has mag() and span() methods - use them

This commit is contained in:
Mark Olesen
2008-12-31 17:58:23 +01:00
parent 172b862c47
commit dcc82bf77b
25 changed files with 106 additions and 123 deletions

View File

@ -93,7 +93,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
// the size of the block.
boundBox bb(blockCells[blockPlabel].points(blockFaces, blockPoints));
const scalar mergeSqrDist = SMALL*magSqr(bb.max() - bb.min());
const scalar mergeSqrDist = SMALL*magSqr(bb.span());
// This is an N^2 algorithm

View File

@ -177,9 +177,9 @@ int main(int argc, char *argv[])
const boundBox& bb = mesh.globalData().bb();
const vector span(bb.max() - bb.min());
const vector span = bb.span();
const scalar minDim = min(span[0], min(span[1], span[2]));
const scalar mergeDim = 1E-4*minDim;
const scalar mergeDim = 1E-4 * minDim;
Pout<< "Mesh bounding box:" << bb << nl
<< " with span:" << span << nl

View File

@ -55,7 +55,7 @@ using namespace Foam;
scalar getMergeDistance(const polyMesh& mesh, const scalar mergeTol)
{
const boundBox& meshBb = mesh.bounds();
scalar mergeDist = mergeTol*mag(meshBb.max() - meshBb.min());
scalar mergeDist = mergeTol * meshBb.mag();
scalar writeTol = std::pow
(
scalar(10.0),

View File

@ -20,7 +20,7 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry)
// Min length
scalar minDistSqr = magSqr(1e-6*(globalBb.max() - globalBb.min()));
scalar minDistSqr = magSqr(1e-6 * globalBb.span());
// Non-empty directions
const Vector<label> validDirs = (mesh.directions() + Vector<label>::one)/2;

View File

@ -471,7 +471,7 @@ int main(int argc, char *argv[])
bb.min() = min(bb.min(), domainBb.min());
bb.max() = max(bb.max(), domainBb.max());
}
const scalar mergeDist = mergeTol*mag(bb.max() - bb.min());
const scalar mergeDist = mergeTol * bb.mag();
Info<< "Overall mesh bounding box : " << bb << nl
<< "Relative tolerance : " << mergeTol << nl
@ -533,15 +533,14 @@ int main(int argc, char *argv[])
// Find geometrically shared points/faces.
autoPtr<faceCoupleInfo> couples =
determineCoupledFaces
(
fullMatch,
procI,
masterMesh,
meshToAdd,
mergeDist
);
autoPtr<faceCoupleInfo> couples = determineCoupledFaces
(
fullMatch,
procI,
masterMesh,
meshToAdd,
mergeDist
);
// Add elements to mesh

View File

@ -244,7 +244,8 @@ scalar getMergeDistance
{
mergeTol = readScalar(IStringStream(args.options()["mergeTol"])());
}
scalar writeTol =
scalar writeTol =
Foam::pow(scalar(10.0), -scalar(IOstream::defaultPrecision()));
Info<< "Merge tolerance : " << mergeTol << nl
@ -263,7 +264,7 @@ scalar getMergeDistance
<< exit(FatalError);
}
scalar mergeDist = mergeTol*mag(bb.max() - bb.min());
scalar mergeDist = mergeTol * bb.mag();
Info<< "Overall meshes bounding box : " << bb << nl
<< "Relative tolerance : " << mergeTol << nl
@ -276,26 +277,15 @@ scalar getMergeDistance
void printMeshData(Ostream& os, const polyMesh& mesh)
{
os << "Number of points: "
<< mesh.points().size() << nl
<< " edges: "
<< mesh.edges().size() << nl
<< " faces: "
<< mesh.faces().size() << nl
<< " internal faces: "
<< mesh.faceNeighbour().size() << nl
<< " cells: "
<< mesh.cells().size() << nl
<< " boundary patches: "
<< mesh.boundaryMesh().size() << nl
<< " point zones: "
<< mesh.pointZones().size() << nl
<< " face zones: "
<< mesh.faceZones().size() << nl
<< " cell zones: "
<< mesh.cellZones().size() << nl;
os << "Number of points: " << mesh.points().size() << nl
<< " edges: " << mesh.edges().size() << nl
<< " faces: " << mesh.faces().size() << nl
<< " internal faces: " << mesh.faceNeighbour().size() << nl
<< " cells: " << mesh.cells().size() << nl
<< " boundary patches: " << mesh.boundaryMesh().size() << nl
<< " point zones: " << mesh.pointZones().size() << nl
<< " face zones: " << mesh.faceZones().size() << nl
<< " cell zones: " << mesh.cellZones().size() << nl;
}
@ -308,7 +298,7 @@ void writeDecomposition
)
{
Info<< "Writing wanted cell distribution to volScalarField " << name
<< " for postprocessing purposes." << nl << endl;
<< " for postprocessing purposes." << nl << endl;
volScalarField procCells
(

View File

@ -325,7 +325,7 @@ int main(int argc, char *argv[])
Pout<< " " << min << " .. " << min+dist << " : "
<< 1.0/surf.size() * binCount[binI]
<< endl;
min += dist;
min += dist;
}
Pout<< endl;
@ -408,10 +408,10 @@ int main(int argc, char *argv[])
const pointField& localPoints = surf.localPoints();
const boundBox bb(localPoints);
scalar smallDim = 1E-6*mag(bb.max() - bb.min());
scalar smallDim = 1E-6 * bb.mag();
Pout<< "Checking for points less than 1E-6 of bounding box ("
<< bb.max() - bb.min() << " meter) apart."
Pout<< "Checking for points less than 1E-6 of bounding box ("
<< bb.span() << " meter) apart."
<< endl;
// Sort points
@ -495,7 +495,7 @@ int main(int argc, char *argv[])
nSingleEdges++;
}
}
label nMultEdges = 0;
forAll(eFaces, edgeI)
{
@ -654,7 +654,7 @@ int main(int argc, char *argv[])
}
Pout<< endl;
}
Pout<< "End\n" << endl;

View File

@ -202,8 +202,7 @@ int main(int argc, char *argv[])
// Get search box. Anything not within this box will not be considered.
const boundBox& meshBb = mesh.globalData().bb();
const vector searchSpan(searchTol*(meshBb.max() - meshBb.min()));
const vector searchSpan = searchTol * meshBb.span();
Info<< "All boundary faces further away than " << searchTol
<< " of mesh bounding box " << meshBb
@ -217,7 +216,7 @@ int main(int argc, char *argv[])
{
Info<< " " << mesh.boundaryMesh()[patchI].name() << '\t'
<< mesh.boundaryMesh()[patchI].size() << endl;
}
}
Info<< endl;
@ -309,7 +308,7 @@ int main(int argc, char *argv[])
{
Info<< " " << mesh.boundaryMesh()[patchI].name() << '\t'
<< mesh.boundaryMesh()[patchI].size() << endl;
}
}
Info<< endl;
@ -318,7 +317,7 @@ int main(int argc, char *argv[])
// Write resulting mesh
Info << "Writing modified mesh to time " << runTime.value() << endl;
mesh.write();
}
}
Info<< "End\n" << endl;

View File

@ -98,26 +98,37 @@ public:
// Access
//- Minimum describing the bounding box
const point& min() const
{
return min_;
}
//- Maximum describing the bounding box
const point& max() const
{
return max_;
}
//- Minimum describing the bounding box, non-const access
point& min()
{
return min_;
}
//- Maximum describing the bounding box, non-const access
point& max()
{
return max_;
}
//- The bounding box span (from minimum to maximum)
vector span() const
{
return (max_ - min_);
}
//- The magnitude of the bounding box span
scalar mag() const
{
return ::Foam::mag(max_ - min_);

View File

@ -663,7 +663,7 @@ Foam::pointField Foam::globalMeshData::geometricSharedPoints() const
combineReduce(sharedPoints, plusEqOp<pointField>());
// Merge tolerance
scalar tolDim = matchTol_*mag(bb_.max() - bb_.min());
scalar tolDim = matchTol_ * bb_.mag();
// And see how many are unique
labelList pMap;
@ -731,7 +731,7 @@ void Foam::globalMeshData::updateMesh()
// Bounding box (does communication)
bb_ = boundBox(mesh_.points(), true);
scalar tolDim = matchTol_*mag(bb_.max() - bb_.min());
scalar tolDim = matchTol_ * bb_.mag();
if (debug)
{

View File

@ -46,10 +46,8 @@ License
namespace Foam
{
defineTypeNameAndDebug(autoHexMeshDriver, 0);
} // End namespace Foam
defineTypeNameAndDebug(autoHexMeshDriver, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -59,7 +57,7 @@ Foam::scalar Foam::autoHexMeshDriver::getMergeDistance(const scalar mergeTol)
const
{
const boundBox& meshBb = mesh_.bounds();
scalar mergeDist = mergeTol*mag(meshBb.max() - meshBb.min());
scalar mergeDist = mergeTol * meshBb.mag();
scalar writeTol = std::pow
(
scalar(10.0),
@ -118,7 +116,7 @@ Foam::scalar Foam::autoHexMeshDriver::getMergeDistance(const scalar mergeTol)
//
// if (hasSurface)
// {
// const point outsidePt(2*overallBb.max() - overallBb.min());
// const point outsidePt = 2 * overallBb.span();
//
// //Info<< "Using point " << outsidePt << " to orient shells" << endl;
//

View File

@ -193,7 +193,7 @@ void Foam::shellSurfaces::orient()
if (hasSurface)
{
const point outsidePt(2*overallBb.max() - overallBb.min());
const point outsidePt = 2 * overallBb.span();
//Info<< "Using point " << outsidePt << " to orient shells" << endl;

View File

@ -4375,8 +4375,7 @@ void Foam::hexRef8::distribute(const mapDistributePolyMesh& map)
void Foam::hexRef8::checkMesh() const
{
const boundBox& meshBb = mesh_.globalData().bb();
const scalar smallDim = 1E-6*mag(meshBb.max() - meshBb.min());
const scalar smallDim = 1E-6 * mesh_.globalData().bb().mag();
if (debug)
{

View File

@ -224,10 +224,8 @@ void Foam::displacementSBRStressFvMotionSolver::updateMesh
);
// Note: boundBox does reduce
const boundBox bb0(points0_, true);
const vector span0(bb0.max()-bb0.min());
const boundBox bb(points, true);
const vector span(bb.max()-bb.min());
const vector span0 = boundBox(points0_, true).span();
const vector span = boundBox(points, true).span();
vector scaleFactors(cmptDivide(span0, span));

View File

@ -433,10 +433,8 @@ void Foam::displacementInterpolationFvMotionSolver::updateMesh
);
// Note: boundBox does reduce
const boundBox bb0(points0_, true);
const vector span0(bb0.max()-bb0.min());
const boundBox bb(points, true);
const vector span(bb.max()-bb.min());
const vector span0 = boundBox(points0_, true).span();
const vector span = boundBox(points, true).span();
vector scaleFactors(cmptDivide(span0, span));
@ -445,7 +443,7 @@ void Foam::displacementInterpolationFvMotionSolver::updateMesh
forAll(newPoints0, pointI)
{
label oldPointI = mpm.pointMap()[pointI];
if (oldPointI >= 0)
{
label masterPointI = mpm.reversePointMap()[oldPointI];

View File

@ -166,7 +166,7 @@ Foam::displacementLaplacianFvMotionSolver::
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::tmp<Foam::pointField>
Foam::tmp<Foam::pointField>
Foam::displacementLaplacianFvMotionSolver::curPoints() const
{
volPointInterpolation::New(fvMesh_).interpolate
@ -272,10 +272,8 @@ void Foam::displacementLaplacianFvMotionSolver::updateMesh
);
// Note: boundBox does reduce
const boundBox bb0(points0_, true);
const vector span0(bb0.max()-bb0.min());
const boundBox bb(points, true);
const vector span(bb.max()-bb.min());
const vector span0 = boundBox(points0_, true).span();
const vector span = boundBox(points, true).span();
vector scaleFactors(cmptDivide(span0, span));
@ -284,7 +282,7 @@ void Foam::displacementLaplacianFvMotionSolver::updateMesh
forAll(newPoints0, pointI)
{
label oldPointI = mpm.pointMap()[pointI];
if (oldPointI >= 0)
{
label masterPointI = mpm.reversePointMap()[oldPointI];

View File

@ -169,12 +169,12 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate
{
const polyMesh& mesh = patch().boundaryMesh().mesh()();
//const scalar deltaT = mesh.time().deltaT().value();
// const scalar deltaT = mesh.time().deltaT().value();
// Construct large enough vector in direction of projectDir so
// we're guaranteed to hit something.
const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min());
const scalar projectLen = mesh.bounds().mag();
// For case of fixed projection vector:
vector projectVec;
@ -307,7 +307,7 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate
rightHit
);
}
List<pointIndexHit> leftHit;
{
labelList leftSurf;

View File

@ -243,7 +243,7 @@ void Foam::directMappedPolyPatch::findSamples
nearInfo = boundaryTree().findNearest
(
sample,
magSqr(patchBb.max()-patchBb.min())
magSqr(patchBb.span())
);
if (!nearInfo.hit())

View File

@ -220,7 +220,7 @@ Foam::label Foam::treeDataTriSurface::getVolumeType
max
(
Foam::sqr(GREAT),
Foam::magSqr(treeBb.max() - treeBb.min())
Foam::magSqr(treeBb.span())
)
);

View File

@ -100,8 +100,8 @@ Foam::label Foam::meshSearch::findNearestCellTree(const point& location) const
{
const indexedOctree<treeDataPoint>& tree = cellCentreTree();
scalar span = mag(tree.bb().max() - tree.bb().min());
scalar span = tree.bb().mag();
pointIndexHit info = tree.findNearest(location, Foam::sqr(span));
if (!info.hit())
@ -177,7 +177,7 @@ Foam::label Foam::meshSearch::findNearestFaceTree(const point& location) const
// Search nearest cell centre.
const indexedOctree<treeDataPoint>& tree = cellCentreTree();
scalar span = mag(tree.bb().max() - tree.bb().min());
scalar span = tree.bb().mag();
// Search with decent span
pointIndexHit info = tree.findNearest(location, Foam::sqr(span));
@ -803,7 +803,7 @@ Foam::label Foam::meshSearch::findNearestBoundaryFace
{
const indexedOctree<treeDataFace>& tree = boundaryTree();
scalar span = mag(tree.bb().max() - tree.bb().min());
scalar span = tree.bb().mag();
pointIndexHit info = boundaryTree().findNearest
(

View File

@ -436,18 +436,18 @@ inline Foam::treeBoundBox Foam::treeBoundBox::extend
{
treeBoundBox bb(*this);
vector span(bb.max() - bb.min());
vector newSpan = bb.span();
// Make 3D
scalar magSpan = Foam::mag(span);
scalar minSpan = s * Foam::mag(newSpan);
for (direction dir = 0; dir < vector::nComponents; dir++)
{
span[dir] = Foam::max(s*magSpan, span[dir]);
newSpan[dir] = Foam::max(minSpan, newSpan[dir]);
}
bb.min() -= cmptMultiply(s*rndGen.vector01(), span);
bb.max() += cmptMultiply(s*rndGen.vector01(), span);
bb.min() -= cmptMultiply(s * rndGen.vector01(), newSpan);
bb.max() += cmptMultiply(s * rndGen.vector01(), newSpan);
return bb;
}

View File

@ -637,7 +637,7 @@ Foam::booleanSurface::booleanSurface
combinedPoints[combinedPointI++] = subSurf2.points()[pointI];
}
}
//
// patches
@ -895,7 +895,7 @@ Foam::booleanSurface::booleanSurface
}
else
{
// Is intersection.
// Is intersection.
combinedTri[fp] =
tri[fp]
- cutSurf2.nSurfacePoints()
@ -905,7 +905,7 @@ Foam::booleanSurface::booleanSurface
combinedTri.region() = patchMap2[tri.region()];
}
// Now we have surface in combinedFaces and combinedPoints. Use
// booleanOp to determine which part of what to keep.
@ -931,7 +931,7 @@ Foam::booleanSurface::booleanSurface
if (booleanOp == booleanSurface::ALL)
{
// Special case: leave surface multiply connected
faceMap_.setSize(combinedSurf.size());
label combinedFaceI = 0;
@ -952,11 +952,7 @@ Foam::booleanSurface::booleanSurface
// Get outside point.
treeBoundBox bb(combinedSurf.localPoints());
point outsidePoint = 2 * bb.max() - bb.min();
point outsidePoint = 2 * treeBoundBox(combinedSurf.localPoints()).span();
//
// Linear search for nearest point on surface.
@ -978,7 +974,7 @@ Foam::booleanSurface::booleanSurface
pts[f[1]],
pts[f[2]]
).nearestPoint(outsidePoint);
if (curHit.distance() < minHit.distance())
{
minHit = curHit;

View File

@ -233,7 +233,7 @@ void Foam::orientedSurface::propagateOrientation
labelList changedFaces(1, nearestFaceI);
// List of edges that were changed in the last iteration.
labelList changedEdges;
while(true)
{
changedEdges = faceToEdge(s, changedFaces);
@ -337,9 +337,7 @@ Foam::orientedSurface::orientedSurface
:
triSurface(surf)
{
treeBoundBox bb(localPoints());
point outsidePoint = 2 * bb.max() - bb.min();
point outsidePoint = 2 * treeBoundBox(localPoints()).span();
orient(*this, outsidePoint, orientOutside);
}

View File

@ -33,23 +33,26 @@ License
namespace Foam
{
//! @cond fileScope
inline label rep
(
const label i,
const label j,
const label k,
const labelList& nn
)
{
return (k + j*nn[2] + i*nn[1]*nn[2]);
}
//! @endcond fileScope
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline label rep
(
const label i,
const label j,
const label k,
const labelList& nn
)
{
return (k + j*nn[2] + i*nn[1]*nn[2]);
}
// from fvMesh
Kmesh::Kmesh(const fvMesh& mesh)
Foam::Kmesh::Kmesh(const fvMesh& mesh)
:
vectorField(mesh.V().size()),
NN(vector::dim)
@ -58,10 +61,10 @@ Kmesh::Kmesh(const fvMesh& mesh)
const scalar twoPi = 2.0*pi;
boundBox box = mesh.bounds();
L = box.max() - box.min();
L = box.span();
vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
vector cellL = 2*(box.max() - cornerCellCentre);
vector cellL = 2 * (box.max() - cornerCellCentre);
vector rdeltaByL;
label nTot = 1;
@ -108,8 +111,4 @@ Kmesh::Kmesh(const fvMesh& mesh)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -62,7 +62,7 @@ void cubeRootVolDelta::calcDelta()
{
boundBox bb(mesh().points(), false);
thickness = (bb.max() - bb.min())[dir];
thickness = bb.span()[dir];
}
}