treeBoundBox: Removed unecessary randomisation

Tree bound boxes are expanded asymmetrically to reduce the liklihood of
octree faces aliging with mesh faces and edges. The asymmetry is now
generated using hard-coded irrational numbers, rather than using a
random generator.

The asymmetry was effectively already hard coded. The random numbers are
only pseudo random, so the same numbers were being applied to the bound
boxes every time. This change simply removes the overhead of creating
the generator, and also gets rid of some duplicated code.
This commit is contained in:
Will Bainbridge
2018-06-07 14:04:48 +01:00
parent dc2c1e2d6d
commit 88a218ce84
24 changed files with 43 additions and 186 deletions

View File

@ -692,8 +692,6 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
// Overall bb
treeBoundBox overallBb(boundaryFacesPtr_().localPoints());
Random& rnd = rndGen_;
bFTreePtr_.reset
(
new indexedOctree<treeDataBPatch>
@ -704,7 +702,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
boundaryFacesPtr_(),
indexedOctree<treeDataBPatch>::perturbTol()
),
overallBb.extend(rnd, 1e-4),
overallBb.extend(1e-4),
10, // maxLevel
10, // leafSize
3.0 // duplicity

View File

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

View File

@ -558,10 +558,7 @@ Foam::conformationSurfaces::conformationSurfaces
// Extend the global bounds to stop the bound box sitting on the surfaces
// to be conformed to
// globalBounds_ = globalBounds_.extend(rndGen_, 1e-4);
vector newSpan = 1e-4*globalBounds_.span();
globalBounds_.min() -= newSpan;
globalBounds_.max() += newSpan;

View File

@ -919,11 +919,7 @@ List<Vb::Point> autoDensity::initialPoints() const
else
{
// Extend the global box to move it off large plane surfaces
hierBB = geometryToConformTo().globalBounds().extend
(
rndGen(),
1e-6
);
hierBB = geometryToConformTo().globalBounds().extend(1e-6);
}
DynamicList<Vb::Point> initialPoints;

View File

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

View File

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

View File

@ -144,18 +144,13 @@ int main(int argc, char *argv[])
#include "createPolyMesh.H"
Random rndGen(653213);
// Determine mesh bounding boxes:
List<List<treeBoundBox>> meshBb(Pstream::nProcs());
{
meshBb[Pstream::myProcNo()] = List<treeBoundBox>
(
1,
treeBoundBox
(
boundBox(mesh.points(), false)
).extend(rndGen, 1e-3)
treeBoundBox(boundBox(mesh.points(), false)).extend(1e-3)
);
Pstream::gatherList(meshBb);
Pstream::scatterList(meshBb);

View File

@ -876,14 +876,6 @@ Foam::polyMesh::cellTree() const
{
if (cellTreePtr_.empty())
{
treeBoundBox overallBb(points());
static Random rndGen(261782);
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
overallBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
cellTreePtr_.reset
(
new indexedOctree<treeDataCell>
@ -894,7 +886,7 @@ Foam::polyMesh::cellTree() const
*this,
CELL_TETS // use tet-decomposition for any inside test
),
overallBb,
treeBoundBox(points()).extend(1e-4),
8, // maxLevel
10, // leafsize
5.0 // duplicity

View File

@ -344,10 +344,9 @@ public:
// 0 : none of the above.
label distanceCmp(const point&, const treeBoundBox& other) const;
//- Return slightly wider bounding box
// Extends all dimensions with s*span*Random::scalar01()
// and guarantees in any direction s*mag(span) minimum width
inline treeBoundBox extend(Random&, const scalar s) const;
//- Return asymetrically extended bounding box, with guaranteed
// minimum width of s*mag(span) in any direction
inline treeBoundBox extend(const scalar s) const;
// Write

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -312,27 +312,18 @@ inline void Foam::treeBoundBox::searchOrder
}
//- Return slightly wider bounding box
inline Foam::treeBoundBox Foam::treeBoundBox::extend
(
Random& rndGen,
const scalar s
) const
inline Foam::treeBoundBox Foam::treeBoundBox::extend(const scalar s) const
{
// Numbers that don't approximate rational fractions with which to make the
// box asymmetric. These are between one and two.
static const vector a = vector::uniform(sqrt(1.25) + 0.5);
static const vector b = vector::uniform(sqrt(2.0));
treeBoundBox bb(*this);
vector newSpan = bb.span();
// Make 3D
scalar minSpan = s * Foam::mag(newSpan);
for (direction dir = 0; dir < vector::nComponents; dir++)
{
newSpan[dir] = Foam::max(newSpan[dir], minSpan);
}
bb.min() -= cmptMultiply(s * rndGen.vector01(), newSpan);
bb.max() += cmptMultiply(s * rndGen.vector01(), newSpan);
const scalar delta = s*Foam::mag(bb.span());
bb.min() -= Foam::max(delta*a, vector::uniform(rootVSmall));
bb.max() += Foam::max(delta*b, vector::uniform(rootVSmall));
return bb;
}

View File

@ -980,8 +980,6 @@ void Foam::faceCoupleInfo::findSlavesCoveringMaster
treeBoundBox overallBb(mesh0.points());
Random rndGen(123456);
indexedOctree<treeDataFace> tree
(
treeDataFace // all information needed to search faces
@ -990,7 +988,7 @@ void Foam::faceCoupleInfo::findSlavesCoveringMaster
mesh0,
bndFaces // boundary faces only
),
overallBb.extend(rndGen, 1e-4), // overall search domain
overallBb.extend(1e-4), // overall search domain
8, // maxLevel
10, // leafsize
3.0 // duplicity

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,8 +39,6 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
Info<< "Building InteractionLists with interaction distance "
<< maxDistance_ << endl;
Random rndGen(419715);
const vector interactionVec = maxDistance_*vector::one;
treeBoundBox procBb(treeBoundBox(mesh_.points()));
@ -158,7 +156,7 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
treeBoundBox procBbRndExt
(
treeBoundBox(mesh_.points()).extend(rndGen, 1e-4)
treeBoundBox(mesh_.points()).extend(1e-4)
);
indexedOctree<treeDataCell> coupledPatchRangeTree

View File

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

View File

@ -253,14 +253,9 @@ void Foam::refinementFeatures::buildTrees(const label featI)
// Calculate bb of all points
treeBoundBox bb(points);
// Random number generator. Bit dodgy since not exactly random ;-)
Random rndGen(65431);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
bb = bb.extend(1e-4);
edgeTrees_.set
(
@ -394,14 +389,9 @@ Foam::refinementFeatures::regionEdgeTrees() const
// Calculate bb of all points
treeBoundBox bb(points);
// Random number generator. Bit dodgy since not exactly random ;-)
Random rndGen(65431);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
bb = bb.extend(1e-4);
trees.set
(

View File

@ -2466,16 +2466,7 @@ void Foam::snappySnapDriver::reverseAttractMeshPoints
// Get search domain and extend it a bit
treeBoundBox bb(pp.localPoints());
{
// Random number generator. Bit dodgy since not exactly random ;-)
Random rndGen(65431);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
}
bb = bb.extend(1e-4);
// Collect candidate points for attraction
DynamicList<label> attractPoints(pp.nPoints());

View File

@ -826,17 +826,9 @@ Foam::extendedEdgeMesh::pointTree() const
{
if (pointTree_.empty())
{
Random rndGen(17301893);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
treeBoundBox bb
(
treeBoundBox(points()).extend(rndGen, 1e-4)
);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
treeBoundBox bb(treeBoundBox(points()).extend(1e-4));
const labelList featurePointLabels = identity(nonFeatureStart_);
@ -866,17 +858,9 @@ Foam::extendedEdgeMesh::edgeTree() const
{
if (edgeTree_.empty())
{
Random rndGen(17301893);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
treeBoundBox bb
(
treeBoundBox(points()).extend(rndGen, 1e-4)
);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
treeBoundBox bb(treeBoundBox(points()).extend(1e-4));
labelList allEdges(identity(edges().size()));
@ -910,17 +894,9 @@ Foam::extendedEdgeMesh::edgeTreesByType() const
{
edgeTreesByType_.setSize(nEdgeTypes);
Random rndGen(872141);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
treeBoundBox bb
(
treeBoundBox(points()).extend(rndGen, 1e-4)
);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
treeBoundBox bb(treeBoundBox(points()).extend(1e-4));
labelListList sliceEdges(nEdgeTypes);

View File

@ -273,8 +273,6 @@ void Foam::mappedPatchBase::findSamples
case NEARESTPATCHFACE:
{
Random rndGen(123456);
const polyPatch& pp = samplePolyPatch();
if (pp.empty())
@ -292,14 +290,8 @@ void Foam::mappedPatchBase::findSamples
treeBoundBox patchBb
(
treeBoundBox(pp.points(), pp.meshPoints()).extend
(
rndGen,
1e-4
)
treeBoundBox(pp.points(), pp.meshPoints()).extend(1e-4)
);
patchBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
patchBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
indexedOctree<treeDataFace> boundaryTree
(
@ -347,8 +339,6 @@ void Foam::mappedPatchBase::findSamples
case NEARESTPATCHPOINT:
{
Random rndGen(123456);
const polyPatch& pp = samplePolyPatch();
if (pp.empty())
@ -364,14 +354,8 @@ void Foam::mappedPatchBase::findSamples
// patch (local) points
treeBoundBox patchBb
(
treeBoundBox(pp.points(), pp.meshPoints()).extend
(
rndGen,
1e-4
)
treeBoundBox(pp.points(), pp.meshPoints()).extend(1e-4)
);
patchBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
patchBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
indexedOctree<treeDataPoint> boundaryTree
(

View File

@ -552,17 +552,15 @@ Foam::meshSearch::boundaryTree() const
if (!overallBbPtr_.valid())
{
Random rndGen(261782);
overallBbPtr_.reset
(
new treeBoundBox(mesh_.points())
);
treeBoundBox& overallBb = overallBbPtr_();
// Extend slightly and make 3D
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
overallBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
overallBb = overallBb.extend(1e-4);
}
// all boundary faces (not just walls)
@ -605,17 +603,15 @@ Foam::meshSearch::cellTree() const
if (!overallBbPtr_.valid())
{
Random rndGen(261782);
overallBbPtr_.reset
(
new treeBoundBox(mesh_.points())
);
treeBoundBox& overallBb = overallBbPtr_();
// Extend slightly and make 3D
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
overallBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
overallBb = overallBb.extend(1e-4);
}
cellTreePtr_.reset

View File

@ -565,15 +565,9 @@ Foam::triSurfaceMesh::edgeTree() const
nPoints
);
// Random number generator. Bit dodgy since not exactly random ;-)
Random rndGen(65431);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
bb = bb.extend(1e-4);
}
scalar oldTol = indexedOctree<treeDataEdge>::perturbTol();

View File

@ -144,16 +144,10 @@ Foam::triSurfaceRegionSearch::treeByRegion() const
// << endl;
// }
// Random number generator. Bit dodgy since not exactly
// random ;-)
Random rndGen(65431);
// Slightly extended bb. Slightly off-centred just so
// on symmetric geometry there are fewer face/edge
// aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
bb = bb.extend(1e-4);
}
treeByRegion_.set

View File

@ -217,14 +217,9 @@ Foam::triSurfaceSearch::tree() const
<< endl;
}
// Random number generator. Bit dodgy since not exactly random ;-)
Random rndGen(65431);
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
bb = bb.extend(1e-4);
}
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();

View File

@ -78,10 +78,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh)
}
treeBoundBox overallBb(pp.points());
Random rndGen(123456);
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
overallBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
overallBb = overallBb.extend(1e-4);
const indexedOctree<treeDataFace> boundaryTree
(

View File

@ -90,16 +90,7 @@ void Foam::patchCloudSet::calcSamples
bb.min() = min(bb.min(), patchBb.min());
bb.max() = max(bb.max(), patchBb.max());
}
// Not very random
Random rndGen(123456);
// Make bb asymetric just to avoid problems on symmetric meshes
bb = bb.extend(rndGen, 1e-4);
// Make sure bb is 3D.
bb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
bb.max() += point(rootVSmall, rootVSmall, rootVSmall);
bb = bb.extend(1e-4);
indexedOctree<treeDataFace> patchTree
(

View File

@ -109,10 +109,7 @@ Foam::sampledTriSurfaceMesh::nonCoupledboundaryTree() const
treeBoundBox overallBb(mesh().points());
Random rndGen(123456);
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(rootVSmall, rootVSmall, rootVSmall);
overallBb.max() += point(rootVSmall, rootVSmall, rootVSmall);
overallBb = overallBb.extend(1e-4);
boundaryTreePtr_.reset
(