From 88a218ce842978f845a0215f00cacb1698269f01 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 7 Jun 2018 14:04:48 +0100 Subject: [PATCH] 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. --- .../backgroundMeshDecomposition.C | 4 +-- .../conformalVoronoiMeshConformToSurface.C | 10 ++----- .../conformationSurfaces.C | 3 -- .../autoDensity/autoDensity.C | 6 +--- .../viewFactorsGen/searchingEngine.H | 2 +- .../surface/surfaceHookUp/surfaceHookUp.C | 5 +--- .../surfaceRedistributePar.C | 7 +---- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 10 +------ .../meshes/treeBoundBox/treeBoundBox.H | 7 ++--- .../meshes/treeBoundBox/treeBoundBoxI.H | 29 +++++++----------- .../polyMeshAdder/faceCoupleInfo.C | 4 +-- .../basic/InteractionLists/InteractionLists.C | 6 ++-- .../meshRefinement/meshRefinement.C | 5 +--- .../refinementFeatures/refinementFeatures.C | 14 ++------- .../snappySnapDriverFeature.C | 11 +------ .../extendedEdgeMesh/extendedEdgeMesh.C | 30 ++----------------- .../mappedPolyPatch/mappedPatchBase.C | 20 ++----------- src/meshTools/meshSearch/meshSearch.C | 12 +++----- .../triSurfaceMesh/triSurfaceMesh.C | 8 +---- .../triSurfaceSearch/triSurfaceRegionSearch.C | 8 +---- .../triSurfaceSearch/triSurfaceSearch.C | 7 +---- src/sampling/probes/patchProbes.C | 5 +--- .../sampledSet/patchCloud/patchCloudSet.C | 11 +------ .../sampledTriSurfaceMesh.C | 5 +--- 24 files changed, 43 insertions(+), 186 deletions(-) diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C index 7889a6ea34..c55a003322 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C @@ -692,8 +692,6 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree() // Overall bb treeBoundBox overallBb(boundaryFacesPtr_().localPoints()); - Random& rnd = rndGen_; - bFTreePtr_.reset ( new indexedOctree @@ -704,7 +702,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree() boundaryFacesPtr_(), indexedOctree::perturbTol() ), - overallBb.extend(rnd, 1e-4), + overallBb.extend(1e-4), 10, // maxLevel 10, // leafSize 3.0 // duplicity diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C index 4036f750a2..ba0f5ed19e 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C @@ -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 @@ -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 diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C index 7f5b8e7a06..5de4b45de6 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C @@ -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; diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/initialPointsMethod/autoDensity/autoDensity.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/initialPointsMethod/autoDensity/autoDensity.C index c41a8568e2..b7e2a03dba 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/initialPointsMethod/autoDensity/autoDensity.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/initialPointsMethod/autoDensity/autoDensity.C @@ -919,11 +919,7 @@ List 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 initialPoints; diff --git a/applications/utilities/preProcessing/viewFactorsGen/searchingEngine.H b/applications/utilities/preProcessing/viewFactorsGen/searchingEngine.H index 3711aff9bf..4518cfc327 100644 --- a/applications/utilities/preProcessing/viewFactorsGen/searchingEngine.H +++ b/applications/utilities/preProcessing/viewFactorsGen/searchingEngine.H @@ -7,7 +7,7 @@ List meshBb treeBoundBox ( boundBox(coarseMesh.points(), false) - ).extend(rndGen, 1e-3) + ).extend(1e-3) ); // Dummy bounds dictionary diff --git a/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C b/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C index a376bf65c8..074faecdad 100644 --- a/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C +++ b/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C @@ -174,12 +174,9 @@ void createBoundaryEdgeTrees // geometry there are less face/edge aligned items. treeBoundBox bb ( - treeBoundBox(UList(surf.localPoints())).extend(rndGen, 1e-4) + treeBoundBox(UList(surf.localPoints())).extend(1e-4) ); - bb.min() -= point(rootVSmall, rootVSmall, rootVSmall); - bb.max() += point(rootVSmall, rootVSmall, rootVSmall); - bEdgeTrees.set ( surfI, diff --git a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C index e825a1397a..ee419d0bcf 100644 --- a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C +++ b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C @@ -144,18 +144,13 @@ int main(int argc, char *argv[]) #include "createPolyMesh.H" - Random rndGen(653213); - // Determine mesh bounding boxes: List> meshBb(Pstream::nProcs()); { meshBb[Pstream::myProcNo()] = List ( 1, - treeBoundBox - ( - boundBox(mesh.points(), false) - ).extend(rndGen, 1e-3) + treeBoundBox(boundBox(mesh.points(), false)).extend(1e-3) ); Pstream::gatherList(meshBb); Pstream::scatterList(meshBb); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index c9a0011d46..5aca1df365 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -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 @@ -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 diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H index 8c35577fd8..3dcf163ffb 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H @@ -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 diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H index 3480eac00d..a4c24794c7 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H @@ -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; } diff --git a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C index 57f7d25f8c..b67eb12971 100644 --- a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C +++ b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C @@ -980,8 +980,6 @@ void Foam::faceCoupleInfo::findSlavesCoveringMaster treeBoundBox overallBb(mesh0.points()); - Random rndGen(123456); - indexedOctree 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 diff --git a/src/lagrangian/basic/InteractionLists/InteractionLists.C b/src/lagrangian/basic/InteractionLists/InteractionLists.C index b223232bd3..f5bd5fd873 100644 --- a/src/lagrangian/basic/InteractionLists/InteractionLists.C +++ b/src/lagrangian/basic/InteractionLists/InteractionLists.C @@ -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::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::buildInteractionLists() treeBoundBox procBbRndExt ( - treeBoundBox(mesh_.points()).extend(rndGen, 1e-4) + treeBoundBox(mesh_.points()).extend(1e-4) ); indexedOctree coupledPatchRangeTree diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index 887ce8dd8b..752da9f25e 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -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 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 = diff --git a/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C b/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C index d8bb33a50c..e9091dc684 100644 --- a/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C +++ b/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C @@ -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 ( diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriverFeature.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriverFeature.C index 8f7adad32e..648253c86f 100644 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriverFeature.C +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriverFeature.C @@ -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