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

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

View File

@ -77,20 +77,16 @@ void Foam::meshToMesh0::calcAddressing()
}
treeBoundBox meshBb(fromPoints);
treeBoundBox shiftedBb(meshBb);
scalar typDim = meshBb.avgDim()/(2.0*cbrt(scalar(fromCells.size())));
treeBoundBox shiftedBb
(
meshBb.min(),
meshBb.max() + vector(typDim, typDim, typDim)
);
shiftedBb.max() += vector::uniform(typDim);
DebugInfo
<< "\nMesh" << nl
<< " bounding box : " << meshBb << nl
<< " bounding box (shifted) : " << shiftedBb << nl
<< " typical dimension : " << shiftedBb.typDim() << endl;
<< " typical dimension : " << shiftedBb.avgDim() << endl;
indexedOctree<treeDataCell> oc
(
@ -155,14 +151,12 @@ void Foam::meshToMesh0::calcAddressing()
else
{
treeBoundBox wallBb(fromPatch.localPoints());
treeBoundBox shiftedBb(wallBb);
scalar typDim =
wallBb.avgDim()/(2.0*sqrt(scalar(fromPatch.size())));
treeBoundBox shiftedBb
(
wallBb.min(),
wallBb.max() + vector(typDim, typDim, typDim)
);
shiftedBb.max() += vector::uniform(typDim);
// Note: allow more levels than in meshSearch. Assume patch
// is not as big as all boundary faces
@ -180,7 +174,7 @@ void Foam::meshToMesh0::calcAddressing()
boundaryAddressing_[patchi].setSize(toPatch.size());
scalar distSqr = sqr(wallBb.mag());
scalar distSqr = wallBb.magSqr();
forAll(toPatch, toi)
{
@ -229,7 +223,7 @@ void Foam::meshToMesh0::cellAddresses
const vector& p = points[toI];
// set the sqr-distance
scalar distSqr = magSqr(p - centresFrom[curCell]);
scalar distSqr = p.distSqr(centresFrom[curCell]);
bool closer;
@ -242,8 +236,7 @@ void Foam::meshToMesh0::cellAddresses
forAll(neighbours, nI)
{
scalar curDistSqr =
magSqr(p - centresFrom[neighbours[nI]]);
scalar curDistSqr = p.distSqr(centresFrom[neighbours[nI]]);
// search through all the neighbours.
// 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
labelList bndFaces(nFaces);
treeBoundBox overallBb(boundBox::invertedBox);
treeBoundBox overallBb;
nFaces = 0;
forAll(patchIDs, i)
@ -88,9 +88,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh)
}
Random rndGen(123456);
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point::uniform(ROOTVSMALL);
overallBb.max() += point::uniform(ROOTVSMALL);
overallBb.inflate(rndGen, 1e-4, ROOTVSMALL);
const indexedOctree<treeDataFace> boundaryTree

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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