ENH: use simpler boundBox handling

- use default initialize boundBox instead of invertedBox
- reset() instead of assigning from invertedBox
- extend (three parameter version) and grow method
- inflate(Random) instead of extend + re-assigning
This commit is contained in:
Mark Olesen 2022-11-01 12:15:08 +01:00 committed by Andrew Heather
parent 1339c3357b
commit e5006a62d7
60 changed files with 189 additions and 353 deletions

View File

@ -53,20 +53,17 @@ int main(int argc, char *argv[])
const polyMesh::cellDecomposition decompMode = polyMesh::CELL_TETS; const polyMesh::cellDecomposition decompMode = polyMesh::CELL_TETS;
treeBoundBox meshBb(mesh.bounds()); treeBoundBox meshBb(mesh.bounds());
treeBoundBox shiftedBb(meshBb);
// Calculate typical cell related size to shift bb by. // Calculate typical cell related size to shift bb by.
scalar typDim = meshBb.avgDim()/(2.0*Foam::cbrt(scalar(mesh.nCells()))); scalar typDim = meshBb.avgDim()/(2.0*Foam::cbrt(scalar(mesh.nCells())));
treeBoundBox shiftedBb shiftedBb.max() += vector::uniform(typDim);
(
meshBb.min(),
meshBb.max() + vector(typDim, typDim, typDim)
);
Info<< "Mesh" << endl; Info<< "Mesh" << endl;
Info<< " bounding box : " << meshBb << endl; Info<< " bounding box : " << meshBb << endl;
Info<< " bounding box (shifted) : " << shiftedBb << endl; Info<< " bounding box (shifted) : " << shiftedBb << endl;
Info<< " typical dimension : " << shiftedBb.typDim() << endl; Info<< " typical dimension : " << shiftedBb.avgDim() << endl;
Info<< "Initialised mesh in " Info<< "Initialised mesh in "
<< runTime.cpuTimeIncrement() << " s" << endl; << runTime.cpuTimeIncrement() << " s" << endl;

View File

@ -890,11 +890,10 @@ int main(int argc, char *argv[])
const boundBox& bb = mesh.bounds(); const boundBox& bb = mesh.bounds();
const vector span = bb.span();
const scalar mergeDim = mergeTol * bb.minDim(); const scalar mergeDim = mergeTol * bb.minDim();
Info<< "Mesh bounding box : " << bb << nl Info<< "Mesh bounding box : " << bb << nl
<< " with span : " << span << nl << " with span : " << bb.span() << nl
<< "Merge distance : " << mergeDim << nl << "Merge distance : " << mergeDim << nl
<< endl; << endl;

View File

@ -577,7 +577,7 @@ bool Foam::backgroundMeshDecomposition::refineCell
// // weightEstimate += sampleVol/pow3(s); // // weightEstimate += sampleVol/pow3(s);
// } // }
// //
// if (sqr(spanScale_)*sqr(minCellSize) < magSqr(cellBb.span())) // if (sqr(spanScale_)*sqr(minCellSize) < cellBb.magSqr())
// { // {
// return true; // return true;
// } // }
@ -695,7 +695,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
Pstream::allGatherList(allBackgroundMeshBounds_); Pstream::allGatherList(allBackgroundMeshBounds_);
// find global bounding box // find global bounding box
globalBackgroundBounds_ = treeBoundBox(boundBox::invertedBox); globalBackgroundBounds_.reset();
forAll(allBackgroundMeshBounds_, proci) forAll(allBackgroundMeshBounds_, proci)
{ {
globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]); globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]);

View File

@ -1965,12 +1965,9 @@ void Foam::conformalVoronoiMesh::buildEdgeLocationTree
{ {
treeBoundBox overallBb treeBoundBox overallBb
( (
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4) geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4, ROOTVSMALL)
); );
overallBb.min() -= Foam::point::uniform(ROOTVSMALL);
overallBb.max() += Foam::point::uniform(ROOTVSMALL);
edgeLocationTreePtr_.reset edgeLocationTreePtr_.reset
( (
new dynamicIndexedOctree<dynamicTreeDataPoint> new dynamicIndexedOctree<dynamicTreeDataPoint>
@ -1992,12 +1989,9 @@ void Foam::conformalVoronoiMesh::buildSurfacePtLocationTree
{ {
treeBoundBox overallBb treeBoundBox overallBb
( (
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4) geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4, ROOTVSMALL)
); );
overallBb.min() -= Foam::point::uniform(ROOTVSMALL);
overallBb.max() += Foam::point::uniform(ROOTVSMALL);
surfacePtLocationTreePtr_.reset surfacePtLocationTreePtr_.reset
( (
new dynamicIndexedOctree<dynamicTreeDataPoint> new dynamicIndexedOctree<dynamicTreeDataPoint>

View File

@ -564,12 +564,9 @@ Foam::conformationSurfaces::conformationSurfaces
// Extend the global bounds to stop the bound box sitting on the surfaces // Extend the global bounds to stop the bound box sitting on the surfaces
// to be conformed to // to be conformed to
//globalBounds_ = globalBounds_.extend(rndGen, 1e-4); //globalBounds_.inflate(rndGen, 1e-4);
vector newSpan = 1e-4*globalBounds_.span(); globalBounds_.grow(1e-4*globalBounds_.span());
globalBounds_.min() -= newSpan;
globalBounds_.max() += newSpan;
// Look at all surfaces at determine whether the locationInMesh point is // Look at all surfaces at determine whether the locationInMesh point is
// inside or outside each, to establish a signature for the domain to be // inside or outside each, to establish a signature for the domain to be

View File

@ -122,11 +122,7 @@ int main(int argc, char *argv[])
// Extend // Extend
treeBoundBox bb = geometryToConformTo.globalBounds(); treeBoundBox bb = geometryToConformTo.globalBounds();
{ bb.grow(0.1*bb.span());
const vector smallVec = 0.1*bb.span();
bb.min() -= smallVec;
bb.max() += smallVec;
}
Info<< "Meshing to bounding box " << bb << nl << endl; Info<< "Meshing to bounding box " << bb << nl << endl;

View File

@ -871,17 +871,16 @@ Foam::label Foam::checkTopology
Info<< " " Info<< " "
<< setw(20) << "PointZone" << setw(20) << "PointZone"
<< setw(8) << "Points" << setw(8) << "Points"
<< "BoundingBox" << endl; << "BoundingBox" << nl;
for (const auto& zone : pointZones) for (const auto& zone : pointZones)
{ {
boundBox bb; boundBox bb
for (const label pointi : zone) (
{ mesh.points(),
bb.add(mesh.points()[pointi]); static_cast<const labelUList&>(zone),
} true // Reduce (global min/max)
);
bb.reduce(); // Global min/max
Info<< " " Info<< " "
<< setw(20) << zone.name() << setw(20) << zone.name()

View File

@ -4,10 +4,7 @@ Random rndGen(653213);
List<treeBoundBox> meshBb List<treeBoundBox> meshBb
( (
1, 1,
treeBoundBox treeBoundBox(coarseMesh.points()).extend(rndGen, 1e-3)
(
boundBox(coarseMesh.points(), false)
).extend(rndGen, 1e-3)
); );
// Dummy bounds dictionary // Dummy bounds dictionary

View File

@ -4,10 +4,7 @@ Random rndGen(653213);
List<treeBoundBox> meshBb List<treeBoundBox> meshBb
( (
1, 1,
treeBoundBox treeBoundBox(coarseMesh.points()).extend(rndGen, 1e-3)
(
boundBox(coarseMesh.points(), false)
).extend(rndGen, 1e-3)
); );
// Dummy bounds dictionary // Dummy bounds dictionary

View File

@ -178,12 +178,9 @@ void createBoundaryEdgeTrees
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
treeBoundBox bb treeBoundBox bb
( (
treeBoundBox(UList<point>(surf.localPoints())).extend(rndGen, 1e-4) treeBoundBox(surf.localPoints()).extend(rndGen, 1e-4, ROOTVSMALL)
); );
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
bEdgeTrees.set bEdgeTrees.set
( (
surfI, surfI,

View File

@ -193,10 +193,7 @@ int main(int argc, char *argv[])
meshBb[Pstream::myProcNo()] = List<treeBoundBox> meshBb[Pstream::myProcNo()] = List<treeBoundBox>
( (
1, 1,
treeBoundBox treeBoundBox(mesh.points()).extend(rndGen, 1e-3)
(
boundBox(mesh.points(), false)
).extend(rndGen, 1e-3)
); );
Pstream::allGatherList(meshBb); Pstream::allGatherList(meshBb);
} }
@ -243,7 +240,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
bbs = List<treeBoundBox>(1, treeBoundBox(boundBox::invertedBox)); bbs = List<treeBoundBox>(1, treeBoundBox::null());
} }
dictionary dict; dictionary dict;

View File

@ -195,10 +195,10 @@ void Foam::AABBTree<Type>::createBoxes
// Assign the objects to min or max bin // Assign the objects to min or max bin
DynamicList<label> minBinObjectIDs(objectIDs.size()); DynamicList<label> minBinObjectIDs(objectIDs.size());
treeBoundBox minBb(boundBox::invertedBox); treeBoundBox minBb;
DynamicList<label> maxBinObjectIDs(objectIDs.size()); DynamicList<label> maxBinObjectIDs(objectIDs.size());
treeBoundBox maxBb(boundBox::invertedBox); treeBoundBox maxBb;
for (const label objI : objectIDs) for (const label objI : objectIDs)
{ {

View File

@ -935,13 +935,10 @@ Foam::polyMesh::cellTree() const
{ {
if (!cellTreePtr_) if (!cellTreePtr_)
{ {
treeBoundBox overallBb(points());
Random rndGen(261782); Random rndGen(261782);
overallBb = overallBb.extend(rndGen, 1e-4); treeBoundBox overallBb(points());
overallBb.min() -= point::uniform(ROOTVSMALL); overallBb.inflate(rndGen, 1e-4, ROOTVSMALL);
overallBb.max() += point::uniform(ROOTVSMALL);
cellTreePtr_.reset cellTreePtr_.reset
( (

View File

@ -188,7 +188,7 @@ void Foam::PatchTools::calcBounds
bitSet pointUsed(points.size()); bitSet pointUsed(points.size());
nPoints = 0; nPoints = 0;
bb = boundBox::invertedBox; bb.reset();
for (const auto& f : p) for (const auto& f : p)
{ {

View File

@ -129,7 +129,7 @@ void Foam::polyMeshGeometry::updateCellCentresAndVols
// Estimate the cell centre and bounding box using the face centres // Estimate the cell centre and bounding box using the face centres
vector cEst(Zero); vector cEst(Zero);
boundBox bb(boundBox::invertedBox); boundBox bb;
for (const label facei : cFaces) for (const label facei : cFaces)
{ {

View File

@ -1924,24 +1924,15 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit(vectorField& result) const
// Remove duplicate points // Remove duplicate points
vectorField allPoints(nAllPoints, Zero); vectorField allPoints(nAllPoints, Zero);
boundBox bb(allPointsExt, false); const scalar tol = 0.001*treeBoundBox(allPointsExt).mag();
scalar tol = 0.001*mag(bb.max() - bb.min());
nAllPoints = 0; nAllPoints = 0;
forAll(allPointsExt, pI) for (const point& pt : allPointsExt)
{ {
bool duplicate = false; bool duplicate = false;
for (label i=0; i<nAllPoints; ++i) for (label i = 0; i < nAllPoints; ++i)
{ {
if if (pt.dist(allPoints[i]) < tol)
(
mag
(
allPoints[i]
- allPointsExt[pI]
)
< tol
)
{ {
duplicate = true; duplicate = true;
break; break;
@ -1950,7 +1941,7 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit(vectorField& result) const
if (!duplicate) if (!duplicate)
{ {
allPoints[nAllPoints++] = allPointsExt[pI]; allPoints[nAllPoints++] = pt;
} }
} }
@ -2069,8 +2060,7 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit(vectorField& result) const
procLsPoints[Pstream::myProcNo()] = locPoints; procLsPoints[Pstream::myProcNo()] = locPoints;
const boundBox bb(locPoints, false); tol = 0.001*treeBoundBox(locPoints).mag();
tol = 0.001*mag(bb.max() - bb.min());
} }
Pstream::allGatherList(procLsPoints); Pstream::allGatherList(procLsPoints);

View File

@ -626,7 +626,7 @@ turbulentDFSEMInletFvPatchVectorField
triCumulativeMagSf_(), triCumulativeMagSf_(),
sumTriMagSf_(Pstream::nProcs() + 1, Zero), sumTriMagSf_(Pstream::nProcs() + 1, Zero),
patchNormal_(Zero), patchNormal_(Zero),
patchBounds_(boundBox::invertedBox), patchBounds_(),
eddies_(Zero), eddies_(Zero),
v0_(Zero), v0_(Zero),
@ -709,7 +709,7 @@ turbulentDFSEMInletFvPatchVectorField
triCumulativeMagSf_(), triCumulativeMagSf_(),
sumTriMagSf_(Pstream::nProcs() + 1, Zero), sumTriMagSf_(Pstream::nProcs() + 1, Zero),
patchNormal_(Zero), patchNormal_(Zero),
patchBounds_(boundBox::invertedBox), patchBounds_(),
eddies_(), eddies_(),
v0_(Zero), v0_(Zero),

View File

@ -64,7 +64,7 @@ void Foam::functionObjects::fieldExtents::calcFieldExtents
auto extents = [this](const scalarField& mask, const vectorField& C) auto extents = [this](const scalarField& mask, const vectorField& C)
{ {
boundBox extents(boundBox::invertedBox); boundBox extents;
forAll(mask, i) forAll(mask, i)
{ {
if (mask[i] > 0.5) if (mask[i] > 0.5)
@ -77,7 +77,7 @@ void Foam::functionObjects::fieldExtents::calcFieldExtents
if (extents.empty()) if (extents.empty())
{ {
extents.add(point::zero); extents.reset(point::zero);
} }
return extents; return extents;
@ -97,7 +97,7 @@ void Foam::functionObjects::fieldExtents::calcFieldExtents
Log << " internal field: " << bb << nl; Log << " internal field: " << bb << nl;
file() << bb; file() << bb;
this->setResult(fieldName + "_internal_min" , bb.min()); this->setResult(fieldName + "_internal_min", bb.min());
this->setResult(fieldName + "_internal_max", bb.max()); this->setResult(fieldName + "_internal_max", bb.max());
} }

View File

@ -927,7 +927,7 @@ bool Foam::functionObjects::streamLineBase::read(const dictionary& dict)
} }
bounds_ = boundBox::invertedBox; bounds_.reset();
if (dict.readIfPresent("bounds", bounds_) && !bounds_.empty()) if (dict.readIfPresent("bounds", bounds_) && !bounds_.empty())
{ {
Info<< " clipping all segments to " << bounds_ << nl << endl; Info<< " clipping all segments to " << bounds_ << nl << endl;

View File

@ -152,8 +152,8 @@ bool Foam::functionObjects::energySpectrum::read(const dictionary& dict)
// Assume all cells are the same size... // Assume all cells are the same size...
boundBox cellBb(mesh_.cellBb(0)); boundBox cellBb(mesh_.cellBb(0));
const vector L(meshBb.max() - meshBb.min()); const vector L(meshBb.span());
const vector nCellXYZ(cmptDivide(L, cellBb.max() - cellBb.min())); const vector nCellXYZ(cmptDivide(L, cellBb.span()));
N_ = Vector<int> N_ = Vector<int>
( (
@ -163,7 +163,7 @@ bool Foam::functionObjects::energySpectrum::read(const dictionary& dict)
); );
// Check that the mesh is a structured box // Check that the mesh is a structured box
vector cellDx(cellBb.max() - cellBb.min()); vector cellDx(cellBb.span());
vector expectedMax(N_.x()*cellDx.x(), N_.y()*cellDx.y(), N_.z()*cellDx.z()); vector expectedMax(N_.x()*cellDx.x(), N_.y()*cellDx.y(), N_.z()*cellDx.z());
vector relativeSize(cmptDivide(L, expectedMax)); vector relativeSize(cmptDivide(L, expectedMax));
for (direction i = 0; i < 3; ++i) for (direction i = 0; i < 3; ++i)
@ -183,8 +183,8 @@ bool Foam::functionObjects::energySpectrum::read(const dictionary& dict)
// Map into i-j-k co-ordinates // Map into i-j-k co-ordinates
const vectorField& C = mesh_.C(); const vectorField& C = mesh_.C();
c0_ = returnReduce(min(C), minOp<vector>()); c0_ = returnReduce(min(C), minOp<vector>());
const vector cMax = returnReduce(max(C), maxOp<vector>()); deltaC_ = returnReduce(max(C), maxOp<vector>());
deltaC_ = cMax - c0_; deltaC_ -= c0_;
forAll(C, celli) forAll(C, celli)
{ {

View File

@ -64,14 +64,13 @@ void Foam::surfaceDisplacementPointPatchVectorField::calcProjection
// we're guaranteed to hit something. // we're guaranteed to hit something.
//- Per point projection vector: //- Per point projection vector:
const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min()); const scalar projectLen = mesh.bounds().mag();
// For case of fixed projection vector: // For case of fixed projection vector:
vector projectVec(Zero); vector projectVec(Zero);
if (projectMode_ == FIXEDNORMAL) if (projectMode_ == FIXEDNORMAL)
{ {
vector n = projectDir_/mag(projectDir_); projectVec = projectLen * normalised(projectDir_);
projectVec = projectLen*n;
} }

View File

@ -64,14 +64,13 @@ void Foam::surfaceSlipDisplacementPointPatchVectorField::calcProjection
// we're guaranteed to hit something. // we're guaranteed to hit something.
//- Per point projection vector: //- Per point projection vector:
const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min()); const scalar projectLen = mesh.bounds().mag();
// For case of fixed projection vector: // For case of fixed projection vector:
vector projectVec(0, 0, 0); vector projectVec(Zero);
if (projectMode_ == FIXEDNORMAL) if (projectMode_ == FIXEDNORMAL)
{ {
vector n = projectDir_/mag(projectDir_); projectVec = projectLen * normalised(projectDir_);
projectVec = projectLen*n;
} }

View File

@ -44,19 +44,12 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
Random rndGen(419715); Random rndGen(419715);
const vector interactionVec = maxDistance_*vector::one; treeBoundBox procBb(mesh_.points());
treeBoundBox procBb(treeBoundBox(mesh_.points()));
treeBoundBox extendedProcBb
(
procBb.min() - interactionVec,
procBb.max() + interactionVec
);
treeBoundBoxList allExtendedProcBbs(Pstream::nProcs()); treeBoundBoxList allExtendedProcBbs(Pstream::nProcs());
allExtendedProcBbs[Pstream::myProcNo()] = extendedProcBb; allExtendedProcBbs[Pstream::myProcNo()] = procBb;
allExtendedProcBbs[Pstream::myProcNo()].grow(maxDistance_);
Pstream::allGatherList(allExtendedProcBbs); Pstream::allGatherList(allExtendedProcBbs);
@ -194,16 +187,11 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
globalTransforms.transformIndex(ciat) globalTransforms.transformIndex(ciat)
); );
treeBoundBox tempTransformedBb treeBoundBox extendedBb
( (
transform.invTransformPosition(cellBbsToExchange[bbI].points()) transform.invTransformPosition(cellBbsToExchange[bbI].points())
); );
extendedBb.grow(maxDistance_);
treeBoundBox extendedBb
(
tempTransformedBb.min() - interactionVec,
tempTransformedBb.max() + interactionVec
);
// Find all elements intersecting box. // Find all elements intersecting box.
labelList interactingElems labelList interactingElems
@ -419,16 +407,11 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
globalTransforms.transformIndex(wfiat) globalTransforms.transformIndex(wfiat)
); );
treeBoundBox tempTransformedBb treeBoundBox extendedBb
( (
transform.invTransformPosition(wallFaceBbsToExchange[bbI].points()) transform.invTransformPosition(wallFaceBbsToExchange[bbI].points())
); );
extendedBb.grow(maxDistance_);
treeBoundBox extendedBb
(
tempTransformedBb.min() - interactionVec,
tempTransformedBb.max() + interactionVec
);
// Find all elements intersecting box. // Find all elements intersecting box.
labelList interactingElems labelList interactingElems
@ -592,11 +575,8 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
{ {
const treeBoundBox& cellBb = cellBbs[celli]; const treeBoundBox& cellBb = cellBbs[celli];
treeBoundBox extendedBb treeBoundBox extendedBb(cellBb);
( extendedBb.grow(maxDistance_);
cellBb.min() - interactionVec,
cellBb.max() + interactionVec
);
// Find all cells intersecting extendedBb // Find all cells intersecting extendedBb
labelList interactingElems(allCellsTree.findBox(extendedBb)); labelList interactingElems(allCellsTree.findBox(extendedBb));

View File

@ -130,7 +130,7 @@ void Foam::PDRblock::adjustSizes()
grid_.y().clear(); grid_.y().clear();
grid_.z().clear(); grid_.z().clear();
bounds_ = boundBox::invertedBox; bounds_.reset();
edgeLimits_.min() = 0; edgeLimits_.min() = 0;
edgeLimits_.max() = 0; edgeLimits_.max() = 0;
return; return;

View File

@ -94,7 +94,7 @@ Foam::blockVertices::projectVertex::operator point() const
geometry_, geometry_,
surfaces_, surfaces_,
start, start,
scalarField(start.size(), magSqr(bb.span())), scalarField(start.size(), bb.magSqr()),
boundaryNear, boundaryNear,
boundaryConstraint boundaryConstraint
); );

View File

@ -3228,10 +3228,11 @@ void Foam::meshRefinement::distribute(const mapDistributePolyMesh& map)
Random rndGen(653213); Random rndGen(653213);
// Get local mesh bounding box. Single box for now. // Get local mesh bounding box. Single box for now.
List<treeBoundBox> meshBb(1); List<treeBoundBox> meshBb
treeBoundBox& bb = meshBb[0]; (
bb = treeBoundBox(mesh_.points()); 1,
bb = bb.extend(rndGen, 1e-4); treeBoundBox(mesh_.points()).extend(rndGen, 1e-4)
);
// Distribute all geometry (so refinementSurfaces and shellSurfaces) // Distribute all geometry (so refinementSurfaces and shellSurfaces)
searchableSurfaces& geometry = searchableSurfaces& geometry =

View File

@ -297,9 +297,7 @@ void Foam::refinementFeatures::buildTrees(const label featI)
// Slightly extended bb. Slightly off-centred just so on symmetric // Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
edgeTrees_.set edgeTrees_.set
( (
@ -438,9 +436,7 @@ Foam::refinementFeatures::regionEdgeTrees() const
// Slightly extended bb. Slightly off-centred just so on symmetric // Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
trees.set trees.set
( (

View File

@ -160,7 +160,7 @@ void Foam::shellSurfaces::setAndCheckLevels
void Foam::shellSurfaces::orient() void Foam::shellSurfaces::orient()
{ {
// Determine outside point. // Determine outside point.
boundBox overallBb = boundBox::invertedBox; boundBox overallBb;
bool hasSurface = false; bool hasSurface = false;

View File

@ -3172,9 +3172,7 @@ void Foam::snappySnapDriver::reverseAttractMeshPoints
// Slightly extended bb. Slightly off-centred just so on symmetric // Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
} }
// Collect candidate points for attraction // Collect candidate points for attraction

View File

@ -300,7 +300,7 @@ Foam::label Foam::advancingFrontAMI::findTargetFace
srcFacePti == -1 ? bb.centre() : srcPts[srcFace[srcFacePti]]; srcFacePti == -1 ? bb.centre() : srcPts[srcFace[srcFacePti]];
const pointIndexHit sample = const pointIndexHit sample =
treePtr_->findNearest(srcPt, magSqr(bb.max() - bb.centre()), fnOp); treePtr_->findNearest(srcPt, 0.25*bb.magSqr(), fnOp);
if (sample.hit() && isCandidate(srcFacei, sample.index())) if (sample.hit() && isCandidate(srcFacei, sample.index()))
{ {

View File

@ -337,9 +337,6 @@ bool Foam::faceAreaWeightAMI2D::calculate
// Find an approximate face length scale // Find an approximate face length scale
const scalar lf(Cbb_*Foam::sqrt(gAverage(srcMagSf_))); const scalar lf(Cbb_*Foam::sqrt(gAverage(srcMagSf_)));
// Expansion to apply to source face bounding box
const vector d(lf*vector::one);
if (validSize) if (validSize)
{ {
// Create the tgt tree // Create the tgt tree
@ -371,8 +368,7 @@ bool Foam::faceAreaWeightAMI2D::calculate
const face& srcFace = src[srcFacei]; const face& srcFace = src[srcFacei];
treeBoundBox srcFaceBb(srcPoints, srcFace); treeBoundBox srcFaceBb(srcPoints, srcFace);
srcFaceBb.min() -= d; srcFaceBb.grow(lf);
srcFaceBb.max() += d;
const labelList tgtFaces const labelList tgtFaces
( (

View File

@ -833,12 +833,9 @@ Foam::extendedEdgeMesh::pointTree() const
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
treeBoundBox bb treeBoundBox bb
( (
treeBoundBox(points()).extend(rndGen, 1e-4) treeBoundBox(points()).extend(rndGen, 1e-4, ROOTVSMALL)
); );
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
const labelList featurePointLabels = identity(nonFeatureStart_); const labelList featurePointLabels = identity(nonFeatureStart_);
pointTree_.reset pointTree_.reset
@ -873,12 +870,9 @@ Foam::extendedEdgeMesh::edgeTree() const
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
treeBoundBox bb treeBoundBox bb
( (
treeBoundBox(points()).extend(rndGen, 1e-4) treeBoundBox(points()).extend(rndGen, 1e-4, ROOTVSMALL)
); );
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
labelList allEdges(identity(edges().size())); labelList allEdges(identity(edges().size()));
edgeTree_.reset edgeTree_.reset
@ -915,12 +909,9 @@ Foam::extendedEdgeMesh::edgeTreesByType() const
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
treeBoundBox bb treeBoundBox bb
( (
treeBoundBox(points()).extend(rndGen, 1e-4) treeBoundBox(points()).extend(rndGen, 1e-4, ROOTVSMALL)
); );
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
labelListList sliceEdges(nEdgeTypes); labelListList sliceEdges(nEdgeTypes);
// External edges // External edges

View File

@ -337,7 +337,7 @@ void Foam::mappedPatchBase::findLocalSamples
cc, cc,
celli celli
); );
near.first().second().first() = magSqr(cc-sample); near.first().second().first() = sample.distSqr(cc);
near.first().second().second() = myRank; near.first().second().second() = myRank;
near.second() = mySampleWorld; near.second() = mySampleWorld;
} }
@ -396,11 +396,10 @@ void Foam::mappedPatchBase::findLocalSamples
treeBoundBox(pp.points(), pp.meshPoints()).extend treeBoundBox(pp.points(), pp.meshPoints()).extend
( (
rndGen, rndGen,
1e-4 1e-4,
ROOTVSMALL
) )
); );
patchBb.min() -= point::uniform(ROOTVSMALL);
patchBb.max() += point::uniform(ROOTVSMALL);
indexedOctree<treeDataFace> boundaryTree indexedOctree<treeDataFace> boundaryTree
( (
@ -425,7 +424,7 @@ void Foam::mappedPatchBase::findLocalSamples
nearInfo = boundaryTree.findNearest nearInfo = boundaryTree.findNearest
( (
sample, sample,
magSqr(patchBb.span()) patchBb.magSqr()
); );
if (!nearInfo.hit()) if (!nearInfo.hit())
@ -438,7 +437,7 @@ void Foam::mappedPatchBase::findLocalSamples
{ {
point fc(pp[nearInfo.index()].centre(pp.points())); point fc(pp[nearInfo.index()].centre(pp.points()));
nearInfo.setPoint(fc); nearInfo.setPoint(fc);
near.first().second().first() = magSqr(fc-sample); near.first().second().first() = sample.distSqr(fc);
near.first().second().second() = myRank; near.first().second().second() = myRank;
near.second() = mySampleWorld; near.second() = mySampleWorld;
} }
@ -471,11 +470,10 @@ void Foam::mappedPatchBase::findLocalSamples
treeBoundBox(pp.points(), pp.meshPoints()).extend treeBoundBox(pp.points(), pp.meshPoints()).extend
( (
rndGen, rndGen,
1e-4 1e-4,
ROOTVSMALL
) )
); );
patchBb.min() -= point::uniform(ROOTVSMALL);
patchBb.max() += point::uniform(ROOTVSMALL);
indexedOctree<treeDataPoint> boundaryTree indexedOctree<treeDataPoint> boundaryTree
( (
@ -499,7 +497,7 @@ void Foam::mappedPatchBase::findLocalSamples
nearInfo = boundaryTree.findNearest nearInfo = boundaryTree.findNearest
( (
sample, sample,
magSqr(patchBb.span()) patchBb.magSqr()
); );
if (!nearInfo.hit()) if (!nearInfo.hit())
@ -512,7 +510,7 @@ void Foam::mappedPatchBase::findLocalSamples
{ {
const point& pt = nearInfo.point(); const point& pt = nearInfo.point();
near.first().second().first() = magSqr(pt-sample); near.first().second().first() = sample.distSqr(pt);
near.first().second().second() = myRank; near.first().second().second() = myRank;
near.second() = mySampleWorld; near.second() = mySampleWorld;
} }
@ -552,7 +550,7 @@ void Foam::mappedPatchBase::findLocalSamples
const point& fc = mesh.faceCentres()[facei]; const point& fc = mesh.faceCentres()[facei];
near.first().first() = pointIndexHit(true, fc, facei); near.first().first() = pointIndexHit(true, fc, facei);
near.first().second().first() = magSqr(fc-sample); near.first().second().first() = sample.distSqr(fc);
near.first().second().second() = myRank; near.first().second().second() = myRank;
near.second() = mySampleWorld; near.second() = mySampleWorld;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -136,7 +136,7 @@ bool Foam::meshSearch::findNearer
forAll(points, pointi) forAll(points, pointi)
{ {
scalar distSqr = magSqr(points[pointi] - sample); scalar distSqr = sample.distSqr(points[pointi]);
if (distSqr < nearestDistSqr) if (distSqr < nearestDistSqr)
{ {
@ -165,7 +165,7 @@ bool Foam::meshSearch::findNearer
{ {
label pointi = indices[i]; label pointi = indices[i];
scalar distSqr = magSqr(points[pointi] - sample); scalar distSqr = sample.distSqr(points[pointi]);
if (distSqr < nearestDistSqr) if (distSqr < nearestDistSqr)
{ {
@ -184,11 +184,7 @@ Foam::label Foam::meshSearch::findNearestCellTree(const point& location) const
{ {
const indexedOctree<treeDataCell>& tree = cellTree(); const indexedOctree<treeDataCell>& tree = cellTree();
pointIndexHit info = tree.findNearest pointIndexHit info = tree.findNearest(location, tree.bb().magSqr());
(
location,
magSqr(tree.bb().max()-tree.bb().min())
);
if (!info.hit()) if (!info.hit())
{ {
@ -203,7 +199,7 @@ Foam::label Foam::meshSearch::findNearestCellLinear(const point& location) const
const vectorField& centres = mesh_.cellCentres(); const vectorField& centres = mesh_.cellCentres();
label nearestIndex = 0; label nearestIndex = 0;
scalar minProximity = magSqr(centres[nearestIndex] - location); scalar minProximity = location.distSqr(centres[nearestIndex]);
findNearer findNearer
( (
@ -232,7 +228,7 @@ Foam::label Foam::meshSearch::findNearestCellWalk
// Walk in direction of face that decreases distance // Walk in direction of face that decreases distance
label curCelli = seedCelli; label curCelli = seedCelli;
scalar distanceSqr = magSqr(mesh_.cellCentres()[curCelli] - location); scalar distanceSqr = location.distSqr(mesh_.cellCentres()[curCelli]);
bool closer; bool closer;
@ -259,11 +255,7 @@ Foam::label Foam::meshSearch::findNearestFaceTree(const point& location) const
const indexedOctree<treeDataCell>& tree = cellTree(); const indexedOctree<treeDataCell>& tree = cellTree();
// Search with decent span // Search with decent span
pointIndexHit info = tree.findNearest pointIndexHit info = tree.findNearest(location, tree.bb().magSqr());
(
location,
magSqr(tree.bb().max()-tree.bb().min())
);
if (!info.hit()) if (!info.hit())
{ {
@ -277,7 +269,7 @@ Foam::label Foam::meshSearch::findNearestFaceTree(const point& location) const
const cell& ownFaces = mesh_.cells()[info.index()]; const cell& ownFaces = mesh_.cells()[info.index()];
label nearestFacei = ownFaces[0]; label nearestFacei = ownFaces[0];
scalar minProximity = magSqr(centres[nearestFacei] - location); scalar minProximity = location.distSqr(centres[nearestFacei]);
findNearer findNearer
( (
@ -297,7 +289,7 @@ Foam::label Foam::meshSearch::findNearestFaceLinear(const point& location) const
const vectorField& centres = mesh_.faceCentres(); const vectorField& centres = mesh_.faceCentres();
label nearestFacei = 0; label nearestFacei = 0;
scalar minProximity = magSqr(centres[nearestFacei] - location); scalar minProximity = location.distSqr(centres[nearestFacei]);
findNearer findNearer
( (
@ -329,7 +321,7 @@ Foam::label Foam::meshSearch::findNearestFaceWalk
// Walk in direction of face that decreases distance // Walk in direction of face that decreases distance
label curFacei = seedFacei; label curFacei = seedFacei;
scalar distanceSqr = magSqr(centres[curFacei] - location); scalar distanceSqr = location.distSqr(centres[curFacei]);
while (true) while (true)
{ {
@ -415,7 +407,7 @@ Foam::label Foam::meshSearch::findCellWalk
// Walk in direction of face that decreases distance // Walk in direction of face that decreases distance
label curCelli = seedCelli; label curCelli = seedCelli;
scalar nearestDistSqr = magSqr(mesh_.cellCentres()[curCelli] - location); scalar nearestDistSqr = location.distSqr(mesh_.cellCentres()[curCelli]);
while(true) while(true)
{ {
@ -444,7 +436,7 @@ Foam::label Foam::meshSearch::findCellWalk
} }
// Also calculate the nearest cell // Also calculate the nearest cell
scalar distSqr = magSqr(mesh_.cellCentres()[celli] - location); scalar distSqr = location.distSqr(mesh_.cellCentres()[celli]);
if (distSqr < nearestDistSqr) if (distSqr < nearestDistSqr)
{ {
@ -615,9 +607,7 @@ const Foam::treeBoundBox& Foam::meshSearch::dataBoundBox() const
treeBoundBox& overallBb = overallBbPtr_(); treeBoundBox& overallBb = overallBbPtr_();
// Extend slightly and make 3D // Extend slightly and make 3D
overallBb = overallBb.extend(rndGen, 1e-4); overallBb.inflate(rndGen, 1e-4, ROOTVSMALL);
overallBb.min() -= point::uniform(ROOTVSMALL);
overallBb.max() += point::uniform(ROOTVSMALL);
} }
return *overallBbPtr_; return *overallBbPtr_;
@ -816,7 +806,7 @@ Foam::label Foam::meshSearch::findNearestBoundaryFace
pointIndexHit info = boundaryTree().findNearest pointIndexHit info = boundaryTree().findNearest
( (
location, location,
magSqr(tree.bb().max()-tree.bb().min()) tree.bb().magSqr()
); );
if (!info.hit()) if (!info.hit())

View File

@ -44,12 +44,11 @@ Foam::boundBox Foam::processorLODs::cellBox::calcSrcBox
const label srcObji const label srcObji
) const ) const
{ {
const UList<label>& cellFaces = srcCells_[srcObji]; boundBox bb;
boundBox bb(srcPoints_, srcFaces_[cellFaces[0]], false); for (const label facei : srcCells_[srcObji])
for (label i = 1; i < cellFaces.size(); ++i)
{ {
bb.add(srcPoints_, srcFaces_[cellFaces[i]]); bb.add(srcPoints_, srcFaces_[facei]);
} }
return bb; return bb;
@ -61,12 +60,11 @@ Foam::boundBox Foam::processorLODs::cellBox::calcTgtBox
const label tgtObji const label tgtObji
) const ) const
{ {
const UList<label>& cellFaces = tgtCells_[tgtObji]; boundBox bb;
boundBox bb(tgtPoints_, tgtFaces_[cellFaces[0]], false); for (const label facei : tgtCells_[tgtObji])
for (label i = 1; i < cellFaces.size(); ++i)
{ {
bb.add(tgtPoints_, tgtFaces_[cellFaces[i]]); bb.add(tgtPoints_, tgtFaces_[facei]);
} }
return bb; return bb;

View File

@ -89,19 +89,16 @@ Foam::searchableExtrudedCircle::searchableExtrudedCircle
const edgeList& edges = eMesh.edges(); const edgeList& edges = eMesh.edges();
bounds() = boundBox(points, false); bounds() = boundBox(points, false);
vector halfSpan(0.5*bounds().span()); // Make the boundBox into a perfect cube around its centre
point ctr(bounds().centre()); const scalar halfWidth = mag(0.5*bounds().span());
bounds().min() = ctr - mag(halfSpan) * vector::one; bounds().reset(bounds().centre());
bounds().max() = ctr + mag(halfSpan) * vector::one; bounds().grow(halfWidth);
// Calculate bb of all points
treeBoundBox bb(bounds());
// Slightly extended bb. Slightly off-centred just so on symmetric // Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
bb.min() -= point::uniform(ROOTVSMALL); treeBoundBox bb(bounds());
bb.max() += point::uniform(ROOTVSMALL); bb.grow(ROOTVSMALL);
edgeTree_.reset edgeTree_.reset
( (
@ -230,7 +227,7 @@ void Foam::searchableExtrudedCircle::findParametricNearest
const pointField& points = mesh.points(); const pointField& points = mesh.points();
const labelListList& pointEdges = mesh.pointEdges(); const labelListList& pointEdges = mesh.pointEdges();
const scalar maxDistSqr(Foam::magSqr(bounds().span())); const scalar maxDistSqr = bounds().magSqr();
// Normalise lambdas // Normalise lambdas
const scalarField lambdas const scalarField lambdas
@ -446,16 +443,14 @@ void Foam::searchableExtrudedCircle::getNormal
normal.setSize(info.size()); normal.setSize(info.size());
normal = Zero; normal = Zero;
const scalar distSqr = bounds().magSqr();
forAll(info, i) forAll(info, i)
{ {
if (info[i].hit()) if (info[i].hit())
{ {
// Find nearest on curve // Find nearest on curve
pointIndexHit curvePt = tree.findNearest pointIndexHit curvePt = tree.findNearest(info[i].point(), distSqr);
(
info[i].point(),
Foam::magSqr(bounds().span())
);
normal[i] = info[i].hitPoint()-curvePt.hitPoint(); normal[i] = info[i].hitPoint()-curvePt.hitPoint();

View File

@ -100,7 +100,7 @@ void Foam::searchableSurfaceCollection::findNearest
) )
); );
scalar distSqr = magSqr(globalPt - samples[pointi]); scalar distSqr = globalPt.distSqr(samples[pointi]);
if (distSqr < minDistSqr[pointi]) if (distSqr < minDistSqr[pointi])
{ {
@ -249,7 +249,7 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
indexOffset_.setSize(surfI+1); indexOffset_.setSize(surfI+1);
// Bounds is the overall bounds - prepare for min/max ops // Bounds is the overall bounds - prepare for min/max ops
bounds() = boundBox::invertedBox; bounds().reset();
forAll(subGeom_, surfI) forAll(subGeom_, surfI)
{ {

View File

@ -695,7 +695,7 @@ Foam::boundBox Foam::searchableSurfacesQueries::bounds
const labelUList& surfacesToTest const labelUList& surfacesToTest
) )
{ {
boundBox bb(boundBox::invertedBox); boundBox bb;
for (const label surfi : surfacesToTest) for (const label surfi : surfacesToTest)
{ {

View File

@ -304,9 +304,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s)
surfaceClosed_(-1), surfaceClosed_(-1),
outsideVolType_(volumeType::UNKNOWN) outsideVolType_(volumeType::UNKNOWN)
{ {
const pointField& pts = triSurface::points(); bounds() = boundBox(triSurface::points(), false);
bounds() = boundBox(pts, false);
} }
@ -334,9 +332,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
surfaceClosed_(-1), surfaceClosed_(-1),
outsideVolType_(volumeType::UNKNOWN) outsideVolType_(volumeType::UNKNOWN)
{ {
const pointField& pts = triSurface::points(); bounds() = boundBox(triSurface::points(), false);
bounds() = boundBox(pts, false);
} }
@ -387,9 +383,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
<< " : using scale " << scaleFactor << endl; << " : using scale " << scaleFactor << endl;
} }
const pointField& pts = triSurface::points(); bounds() = boundBox(triSurface::points(), false);
bounds() = boundBox(pts, false);
// Have optional minimum quality for normal calculation // Have optional minimum quality for normal calculation
if (dict.readIfPresent("minQuality", minQuality_) && minQuality_ > 0) if (dict.readIfPresent("minQuality", minQuality_) && minQuality_ > 0)
@ -494,8 +488,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const readAction r)
} }
} }
const pointField& pts = triSurface::points(); bounds() = boundBox(triSurface::points(), false);
bounds() = boundBox(pts, false);
} }
@ -629,8 +622,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
} }
const pointField& pts = triSurface::points(); bounds() = boundBox(triSurface::points(), false);
bounds() = boundBox(pts, false);
// Have optional minimum quality for normal calculation // Have optional minimum quality for normal calculation
if (dict.readIfPresent("minQuality", minQuality_) && minQuality_ > 0) if (dict.readIfPresent("minQuality", minQuality_) && minQuality_ > 0)
@ -706,8 +698,7 @@ void Foam::triSurfaceMesh::boundingSpheres
const point& fc = centres[facei]; const point& fc = centres[facei];
for (const label pointi : f) for (const label pointi : f)
{ {
const point& pt = pts[pointi]; radiusSqr[facei] = max(radiusSqr[facei], fc.distSqr(pts[pointi]));
radiusSqr[facei] = max(radiusSqr[facei], Foam::magSqr(fc-pt));
} }
} }
@ -782,7 +773,7 @@ Foam::triSurfaceMesh::edgeTree() const
identity(nEdges() - nInternalEdges(), nInternalEdges()) identity(nEdges() - nInternalEdges(), nInternalEdges())
); );
treeBoundBox bb(Zero, Zero); treeBoundBox bb(point::zero);
if (bEdges.size()) if (bEdges.size())
{ {
@ -800,9 +791,7 @@ Foam::triSurfaceMesh::edgeTree() const
// Slightly extended bb. Slightly off-centred just so on symmetric // Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
} }

View File

@ -126,7 +126,7 @@ Foam::triSurfaceRegionSearch::treeByRegion() const
); );
// Calculate bb without constructing local point numbering. // Calculate bb without constructing local point numbering.
treeBoundBox bb(Zero, Zero); treeBoundBox bb(point::zero);
if (indirectRegionPatches_[regionI].size()) if (indirectRegionPatches_[regionI].size())
{ {
@ -156,9 +156,7 @@ Foam::triSurfaceRegionSearch::treeByRegion() const
// Slightly extended bb. Slightly off-centred just so // Slightly extended bb. Slightly off-centred just so
// on symmetric geometry there are fewer face/edge // on symmetric geometry there are fewer face/edge
// aligned items. // aligned items.
bb = bb.extend(rndGen, 1e-4); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
} }
treeByRegion_.set treeByRegion_.set

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -208,7 +208,7 @@ Foam::triSurfaceSearch::tree() const
if (!treePtr_) if (!treePtr_)
{ {
// Calculate bb without constructing local point numbering. // Calculate bb without constructing local point numbering.
treeBoundBox bb(Zero, Zero); treeBoundBox bb(point::zero);
if (surface().size()) if (surface().size())
{ {
@ -230,9 +230,7 @@ Foam::triSurfaceSearch::tree() const
// Slightly extended bb. Slightly off-centred just so on symmetric // Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items. // geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
} }
const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol(); const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();

View File

@ -195,8 +195,7 @@ void Foam::cellCellStencils::inverseDistance::markBoundaries
// Mark in voxel mesh // Mark in voxel mesh
boundBox faceBb(pp.points(), pp[i], false); boundBox faceBb(pp.points(), pp[i], false);
faceBb.min() -= smallVec; faceBb.grow(smallVec);
faceBb.max() += smallVec;
if (bb.overlaps(faceBb)) if (bb.overlaps(faceBb))
{ {
@ -223,8 +222,7 @@ void Foam::cellCellStencils::inverseDistance::markBoundaries
// Mark in voxel mesh // Mark in voxel mesh
boundBox faceBb(pp.points(), pp[i], false); boundBox faceBb(pp.points(), pp[i], false);
faceBb.min() -= smallVec; faceBb.grow(smallVec);
faceBb.max() += smallVec;
if (bb.overlaps(faceBb)) if (bb.overlaps(faceBb))
{ {
@ -313,8 +311,7 @@ void Foam::cellCellStencils::inverseDistance::markPatchesAsHoles
{ {
label celli = tgtCellMap[tgtCelli]; label celli = tgtCellMap[tgtCelli];
treeBoundBox cBb(mesh_.cellBb(celli)); treeBoundBox cBb(mesh_.cellBb(celli));
cBb.min() -= smallVec_; cBb.grow(smallVec_);
cBb.max() += smallVec_;
if if
( (
@ -383,8 +380,7 @@ void Foam::cellCellStencils::inverseDistance::markPatchesAsHoles
{ {
label celli = tgtCellMap[tgtCelli]; label celli = tgtCellMap[tgtCelli];
treeBoundBox cBb(mesh_.cellBb(celli)); treeBoundBox cBb(mesh_.cellBb(celli));
cBb.min() -= smallVec_; cBb.grow(smallVec_);
cBb.max() += smallVec_;
if if
( (
@ -542,8 +538,7 @@ void Foam::cellCellStencils::inverseDistance::markDonors
if (srcOverlapProcs.size()) if (srcOverlapProcs.size())
{ {
treeBoundBox subBb(mesh_.cellBb(celli)); treeBoundBox subBb(mesh_.cellBb(celli));
subBb.min() -= smallVec_; subBb.grow(smallVec_);
subBb.max() += smallVec_;
forAll(srcOverlapProcs, i) forAll(srcOverlapProcs, i)
{ {
@ -1818,7 +1813,7 @@ bool Foam::cellCellStencils::inverseDistance::update()
} }
Pstream::listCombineReduce(nCellsPerZone, plusEqOp<label>()); Pstream::listCombineReduce(nCellsPerZone, plusEqOp<label>());
const boundBox& allBb(mesh_.bounds()); const boundBox& allBb = mesh_.bounds();
PtrList<fvMeshSubset> meshParts(nZones); PtrList<fvMeshSubset> meshParts(nZones);
List<treeBoundBoxList> meshBb(nZones); List<treeBoundBoxList> meshBb(nZones);

View File

@ -91,8 +91,7 @@ bool Foam::cellCellStencils::trackingInverseDistance::markBoundaries
// Mark in voxel mesh // Mark in voxel mesh
boundBox faceBb(pp.points(), pp[i], false); boundBox faceBb(pp.points(), pp[i], false);
faceBb.min() -= smallVec; faceBb.grow(smallVec);
faceBb.max() += smallVec;
if (bb.overlaps(faceBb)) if (bb.overlaps(faceBb))
{ {
@ -127,8 +126,8 @@ bool Foam::cellCellStencils::trackingInverseDistance::markBoundaries
// Mark in voxel mesh // Mark in voxel mesh
boundBox faceBb(pp.points(), pp[i], false); boundBox faceBb(pp.points(), pp[i], false);
faceBb.min() -= smallVec; faceBb.grow(smallVec);
faceBb.max() += smallVec;
if (!bb.contains(faceCentres[i])) if (!bb.contains(faceCentres[i]))
{ {
if (!hasWarned) if (!hasWarned)
@ -224,8 +223,7 @@ void Foam::cellCellStencils::trackingInverseDistance::markPatchesAsHoles
{ {
label celli = tgtCellMap[tgtCelli]; label celli = tgtCellMap[tgtCelli];
boundBox cBb(mesh_.cellBb(celli)); boundBox cBb(mesh_.cellBb(celli));
cBb.min() -= smallVec_; cBb.grow(smallVec_);
cBb.max() += smallVec_;
if if
( (
@ -293,8 +291,7 @@ void Foam::cellCellStencils::trackingInverseDistance::markPatchesAsHoles
{ {
label celli = tgtCellMap[tgtCelli]; label celli = tgtCellMap[tgtCelli];
boundBox cBb(mesh_.cellBb(celli)); boundBox cBb(mesh_.cellBb(celli));
cBb.min() -= smallVec_; cBb.grow(smallVec_);
cBb.max() += smallVec_;
if if
( (
@ -410,8 +407,7 @@ void Foam::cellCellStencils::trackingInverseDistance::markDonors
if (srcOverlapProcs.size()) if (srcOverlapProcs.size())
{ {
treeBoundBox subBb(mesh_.cellBb(celli)); treeBoundBox subBb(mesh_.cellBb(celli));
subBb.min() -= smallVec_; subBb.grow(smallVec_);
subBb.max() += smallVec_;
forAll(srcOverlapProcs, i) forAll(srcOverlapProcs, i)
{ {
@ -600,7 +596,7 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
<< exit(FatalIOError); << exit(FatalIOError);
} }
const boundBox& allBb(mesh_.bounds()); const boundBox& allBb = mesh_.bounds();
List<treeBoundBoxList> meshBb(nZones); List<treeBoundBoxList> meshBb(nZones);

View File

@ -950,7 +950,7 @@ Foam::distributedTriSurfaceMesh::findBestProcs
// Minimum search distance to find the triangle // Minimum search distance to find the triangle
point near, far; point near, far;
bbs[bbi].calcExtremities(centre, near, far); bbs[bbi].calcExtremities(centre, near, far);
minDistSqr = min(minDistSqr, magSqr(centre-far)); minDistSqr = min(minDistSqr, centre.distSqr(far));
} }
} }
} }
@ -977,11 +977,11 @@ Foam::distributedTriSurfaceMesh::findBestProcs
point near, far; point near, far;
bbs[bbi].calcExtremities(centre, near, far); bbs[bbi].calcExtremities(centre, near, far);
scalar d2 = magSqr(centre-near); scalar d2 = centre.distSqr(near);
if (d2 < minDistSqr) if (d2 < minDistSqr)
{ {
minDistSqr = d2; minDistSqr = d2;
maxDistSqr = min(radiusSqr, magSqr(centre-far)); maxDistSqr = min(radiusSqr, centre.distSqr(far));
minProci = proci; minProci = proci;
} }
} }
@ -1748,12 +1748,11 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
// Initialise to inverted box // Initialise to inverted box
List<List<treeBoundBox>> bbs(Pstream::nProcs()); List<List<treeBoundBox>> bbs
forAll(bbs, proci) (
{ Pstream::nProcs(),
bbs[proci].setSize(1, treeBoundBox(boundBox::invertedBox)); List<treeBoundBox>(1, treeBoundBox::null())
} );
const globalIndex& triIndexer = globalTris(); const globalIndex& triIndexer = globalTris();
@ -3735,7 +3734,7 @@ void Foam::distributedTriSurfaceMesh::findLineAll
const vectorField smallVec const vectorField smallVec
( (
ROOTSMALL*dirVec ROOTSMALL*dirVec
+ vector(ROOTVSMALL,ROOTVSMALL,ROOTVSMALL) + vector::uniform(ROOTVSMALL)
); );
// Copy to input and compact any hits // Copy to input and compact any hits

View File

@ -52,13 +52,13 @@ Foam::patchDistMethods::exact::patchSurface() const
Random rndGen(0); Random rndGen(0);
boundBox localBb(mesh_.points(), false); treeBoundBox localBb(mesh_.points());
// Determine mesh bounding boxes: // Determine mesh bounding boxes:
List<treeBoundBox> meshBb List<treeBoundBox> meshBb
( (
1, 1,
treeBoundBox(localBb).extend(rndGen, 1E-3) localBb.extend(rndGen, 1E-3)
); );
// Dummy bounds dictionary // Dummy bounds dictionary

View File

@ -46,12 +46,8 @@ Foam::scalar Foam::meshToMeshMethod::tolerance_ = 1e-6;
Foam::labelList Foam::meshToMeshMethod::maskCells() const Foam::labelList Foam::meshToMeshMethod::maskCells() const
{ {
boundBox intersectBb boundBox intersectBb(src_.bounds());
( intersectBb &= tgt_.bounds();
max(src_.bounds().min(), tgt_.bounds().min()),
min(src_.bounds().max(), tgt_.bounds().max())
);
intersectBb.inflate(0.01); intersectBb.inflate(0.01);
DynamicList<label> cells(src_.nCells()); DynamicList<label> cells(src_.nCells());

View File

@ -77,20 +77,16 @@ void Foam::meshToMesh0::calcAddressing()
} }
treeBoundBox meshBb(fromPoints); treeBoundBox meshBb(fromPoints);
treeBoundBox shiftedBb(meshBb);
scalar typDim = meshBb.avgDim()/(2.0*cbrt(scalar(fromCells.size()))); scalar typDim = meshBb.avgDim()/(2.0*cbrt(scalar(fromCells.size())));
shiftedBb.max() += vector::uniform(typDim);
treeBoundBox shiftedBb
(
meshBb.min(),
meshBb.max() + vector(typDim, typDim, typDim)
);
DebugInfo DebugInfo
<< "\nMesh" << nl << "\nMesh" << nl
<< " bounding box : " << meshBb << nl << " bounding box : " << meshBb << nl
<< " bounding box (shifted) : " << shiftedBb << nl << " bounding box (shifted) : " << shiftedBb << nl
<< " typical dimension : " << shiftedBb.typDim() << endl; << " typical dimension : " << shiftedBb.avgDim() << endl;
indexedOctree<treeDataCell> oc indexedOctree<treeDataCell> oc
( (
@ -155,14 +151,12 @@ void Foam::meshToMesh0::calcAddressing()
else else
{ {
treeBoundBox wallBb(fromPatch.localPoints()); treeBoundBox wallBb(fromPatch.localPoints());
treeBoundBox shiftedBb(wallBb);
scalar typDim = scalar typDim =
wallBb.avgDim()/(2.0*sqrt(scalar(fromPatch.size()))); wallBb.avgDim()/(2.0*sqrt(scalar(fromPatch.size())));
treeBoundBox shiftedBb shiftedBb.max() += vector::uniform(typDim);
(
wallBb.min(),
wallBb.max() + vector(typDim, typDim, typDim)
);
// Note: allow more levels than in meshSearch. Assume patch // Note: allow more levels than in meshSearch. Assume patch
// is not as big as all boundary faces // is not as big as all boundary faces
@ -180,7 +174,7 @@ void Foam::meshToMesh0::calcAddressing()
boundaryAddressing_[patchi].setSize(toPatch.size()); boundaryAddressing_[patchi].setSize(toPatch.size());
scalar distSqr = sqr(wallBb.mag()); scalar distSqr = wallBb.magSqr();
forAll(toPatch, toi) forAll(toPatch, toi)
{ {
@ -229,7 +223,7 @@ void Foam::meshToMesh0::cellAddresses
const vector& p = points[toI]; const vector& p = points[toI];
// set the sqr-distance // set the sqr-distance
scalar distSqr = magSqr(p - centresFrom[curCell]); scalar distSqr = p.distSqr(centresFrom[curCell]);
bool closer; bool closer;
@ -242,8 +236,7 @@ void Foam::meshToMesh0::cellAddresses
forAll(neighbours, nI) forAll(neighbours, nI)
{ {
scalar curDistSqr = scalar curDistSqr = p.distSqr(centresFrom[neighbours[nI]]);
magSqr(p - centresFrom[neighbours[nI]]);
// search through all the neighbours. // search through all the neighbours.
// If the cell is closer, reset current cell and distance // If the cell is closer, reset current cell and distance

View File

@ -71,7 +71,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh)
{ {
// Collect mesh faces and bounding box // Collect mesh faces and bounding box
labelList bndFaces(nFaces); labelList bndFaces(nFaces);
treeBoundBox overallBb(boundBox::invertedBox); treeBoundBox overallBb;
nFaces = 0; nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)
@ -88,9 +88,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh)
} }
Random rndGen(123456); Random rndGen(123456);
overallBb = overallBb.extend(rndGen, 1e-4); overallBb.inflate(rndGen, 1e-4, ROOTVSMALL);
overallBb.min() -= point::uniform(ROOTVSMALL);
overallBb.max() += point::uniform(ROOTVSMALL);
const indexedOctree<treeDataFace> boundaryTree const indexedOctree<treeDataFace> boundaryTree

View File

@ -133,7 +133,7 @@ Foam::cellCentreSet::cellCentreSet
searchEngine, searchEngine,
dict.getOrDefault<word>("axis", "xyz") dict.getOrDefault<word>("axis", "xyz")
), ),
bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)) bounds_(dict.getOrDefault("bounds", boundBox::null()))
{ {
genSamples(); genSamples();
} }

View File

@ -88,7 +88,7 @@ public:
const polyMesh& mesh, const polyMesh& mesh,
const meshSearch& searchEngine, const meshSearch& searchEngine,
const word& axis, const word& axis,
const boundBox& bbox = boundBox::invertedBox const boundBox& bbox = boundBox::null()
); );
//- Construct from dictionary //- Construct from dictionary

View File

@ -71,7 +71,7 @@ void Foam::patchCloudSet::calcSamples
labelList patchFaces(sz); labelList patchFaces(sz);
sz = 0; sz = 0;
treeBoundBox bb(boundBox::invertedBox); treeBoundBox bb;
for (const label patchi : patchSet_) for (const label patchi : patchSet_)
{ {
const polyPatch& pp = mesh().boundaryMesh()[patchi]; const polyPatch& pp = mesh().boundaryMesh()[patchi];
@ -88,11 +88,8 @@ void Foam::patchCloudSet::calcSamples
// Not very random // Not very random
Random rndGen(123456); Random rndGen(123456);
// Make bb asymmetric just to avoid problems on symmetric meshes // Make bb asymmetric just to avoid problems on symmetric meshes
bb = bb.extend(rndGen, 1e-4);
// Make sure bb is 3D. // Make sure bb is 3D.
bb.min() -= point::uniform(ROOTVSMALL); bb.inflate(rndGen, 1e-4, ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
indexedOctree<treeDataFace> patchTree indexedOctree<treeDataFace> patchTree

View File

@ -108,14 +108,9 @@ void Foam::patchSeedSet::calcSamples
treeBoundBox patchBb treeBoundBox patchBb
( (
treeBoundBox(pp.points(), pp.meshPoints()).extend treeBoundBox(pp.points(), pp.meshPoints())
( .extend(rndGen, 1e-4, ROOTVSMALL)
rndGen,
1e-4
)
); );
patchBb.min() -= point::uniform(ROOTVSMALL);
patchBb.max() += point::uniform(ROOTVSMALL);
indexedOctree<treeDataFace> boundaryTree indexedOctree<treeDataFace> boundaryTree
( (
@ -135,15 +130,7 @@ void Foam::patchSeedSet::calcSamples
// to be found // to be found
const scalar globalDistSqr const scalar globalDistSqr
( (
//magSqr //boundBox(pp.points(), pp.meshPoints(), true).magSqr()
//(
// boundBox
// (
// pp.points(),
// pp.meshPoints(),
// true
// ).span()
//)
GREAT GREAT
); );
@ -168,7 +155,7 @@ void Foam::patchSeedSet::calcSamples
{ {
point fc(pp[nearInfo.index()].centre(pp.points())); point fc(pp[nearInfo.index()].centre(pp.points()));
nearInfo.setPoint(fc); nearInfo.setPoint(fc);
nearest[sampleI].second().first() = magSqr(fc-sample); nearest[sampleI].second().first() = sample.magSqr(fc);
nearest[sampleI].second().second() = nearest[sampleI].second().second() =
Pstream::myProcNo(); Pstream::myProcNo();
} }

View File

@ -94,7 +94,7 @@ Foam::sampledCuttingSurface::sampledCuttingSurface
sampledSurface(defaultSurfaceName, mesh, dict), sampledSurface(defaultSurfaceName, mesh, dict),
cuttingSurface(defaultSurfaceName, mesh, dict), cuttingSurface(defaultSurfaceName, mesh, dict),
zoneNames_(), zoneNames_(),
bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), bounds_(dict.getOrDefault("bounds", boundBox::null())),
triangulate_(dict.getOrDefault("triangulate", true)), triangulate_(dict.getOrDefault("triangulate", true)),
needsUpdate_(true) needsUpdate_(true)
{ {

View File

@ -125,7 +125,7 @@ public:
const word& surfaceType, const word& surfaceType,
const word& surfaceName, const word& surfaceName,
const bool triangulate = true, const bool triangulate = true,
const boundBox& bounds = boundBox::invertedBox const boundBox& bounds = boundBox::null()
); );
//- Construct from dictionary //- Construct from dictionary

View File

@ -150,7 +150,7 @@ Foam::sampledPlane::sampledPlane
sampledSurface(name, mesh, dict), sampledSurface(name, mesh, dict),
cuttingPlane(definePlane(mesh, dict)), cuttingPlane(definePlane(mesh, dict)),
zoneNames_(), zoneNames_(),
bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), bounds_(dict.getOrDefault("bounds", boundBox::null())),
triangulate_(dict.getOrDefault("triangulate", true)), triangulate_(dict.getOrDefault("triangulate", true)),
needsUpdate_(true) needsUpdate_(true)
{ {

View File

@ -141,7 +141,7 @@ Foam::isoSurfaceParams::isoSurfaceParams
filter_(filter), filter_(filter),
snap_(true), snap_(true),
mergeTol_(1e-6), mergeTol_(1e-6),
clipBounds_(boundBox::invertedBox) clipBounds_()
{} {}

View File

@ -1115,7 +1115,7 @@ void Foam::isoSurfacePoint::trimToBox
} }
// Generate inwards pointing planes // Generate inwards pointing planes
PtrList<plane> planes(treeBoundBox::faceNormals.size()); PtrList<plane> planes(boundBox::nFaces());
forAll(treeBoundBox::faceNormals, faceI) forAll(treeBoundBox::faceNormals, faceI)
{ {
const vector& n = treeBoundBox::faceNormals[faceI]; const vector& n = treeBoundBox::faceNormals[faceI];

View File

@ -359,7 +359,7 @@ void Foam::triSurface::writeStats(Ostream& os) const
bitSet pointIsUsed(points().size()); bitSet pointIsUsed(points().size());
boundBox bb(boundBox::invertedBox); boundBox bb;
labelHashSet regionsUsed; labelHashSet regionsUsed;
for (const auto& f : *this) for (const auto& f : *this)

View File

@ -197,10 +197,7 @@ void Foam::faceReflecting::initialise(const dictionary& coeffs)
List<treeBoundBox> meshBb List<treeBoundBox> meshBb
( (
1, 1,
treeBoundBox treeBoundBox(mesh_.points()).extend(rndGen, 1e-3)
(
boundBox(mesh_.points(), false)
).extend(rndGen, 1e-3)
); );
// Dummy bounds dictionary // Dummy bounds dictionary
@ -332,9 +329,8 @@ void Foam::faceReflecting::calculate()
Pstream::listCombineReduce(refDisDirsIndex, maxEqOp<label>()); Pstream::listCombineReduce(refDisDirsIndex, maxEqOp<label>());
Pstream::mapCombineReduce(refFacesDirIndex, minEqOp<label>()); Pstream::mapCombineReduce(refFacesDirIndex, minEqOp<label>());
scalar maxBounding = 5.0*mag(mesh_.bounds().max() - mesh_.bounds().min()); const scalar maxBounding =
returnReduce(5.0*mesh_.bounds().mag(), maxOp<scalar>());
reduce(maxBounding, maxOp<scalar>());
// Shoot Rays // Shoot Rays
// From faces t = 0, r = 0 and a > 0 to all 'used' discrete reflected // From faces t = 0, r = 0 and a > 0 to all 'used' discrete reflected

View File

@ -194,10 +194,7 @@ void Foam::faceShading::calculate()
List<treeBoundBox> meshBb List<treeBoundBox> meshBb
( (
1, 1,
treeBoundBox treeBoundBox(mesh_.points()).extend(rndGen, 1e-3)
(
boundBox(mesh_.points(), false)
).extend(rndGen, 1e-3)
); );
// Dummy bounds dictionary // Dummy bounds dictionary
@ -263,9 +260,8 @@ void Foam::faceShading::calculate()
surfacesMesh.searchableSurface::write(); surfacesMesh.searchableSurface::write();
} }
scalar maxBounding = 5.0*mag(mesh_.bounds().max() - mesh_.bounds().min()); const scalar maxBounding =
returnReduce(5.0*mesh_.bounds().mag(), maxOp<scalar>());
reduce(maxBounding, maxOp<scalar>());
// Calculate index of faces which have a direct hit (local) // Calculate index of faces which have a direct hit (local)
DynamicList<label> rayStartFace(nFaces + 0.01*nFaces); DynamicList<label> rayStartFace(nFaces + 0.01*nFaces);