diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.C index 359021075a..b41409bd2d 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.C @@ -40,7 +40,8 @@ Foam::DelaunayMesh::DelaunayMesh(const Time& runTime) Triangulation(), vertexCount_(0), cellCount_(0), - runTime_(runTime) + runTime_(runTime), + rndGen_(64293*Pstream::myProcNo()) {} @@ -54,7 +55,8 @@ Foam::DelaunayMesh::DelaunayMesh Triangulation(), vertexCount_(0), cellCount_(0), - runTime_(runTime) + runTime_(runTime), + rndGen_(64293*Pstream::myProcNo()) { Info<< "Reading " << meshName << " from " << runTime.name() << endl; @@ -302,7 +304,7 @@ Foam::Map Foam::DelaunayMesh::rangeInsertWithInfo ); } - std::random_shuffle(points.begin(), points.end()); + rndGen().permute(points); spatial_sort ( diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.H index 3aa207dd8f..769b504c77 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,6 +45,7 @@ SourceFiles #include "CGALTriangulation3Ddefs.H" #include "Time.H" #include "autoPtr.H" +#include "Random.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -106,6 +107,9 @@ private: //- Reference to Time const Time& runTime_; + //- Random number generator + mutable Random rndGen_; + //- Spatial sort traits to use with a pair of point pointers and an int. // Taken from a post on the CGAL lists: 2010-01/msg00004.html by // Sebastien Loriot (Geometry Factory). @@ -219,6 +223,10 @@ public: inline void resetVertexCount(); + //- Access the random number generator + inline Random& rndGen() const; + + // Triangulation manipulation functions //- Clear the entire triangulation diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMeshI.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMeshI.H index 073127cdb3..4971413721 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMeshI.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DelaunayMeshI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,7 +33,7 @@ inline const Foam::Time& Foam::DelaunayMesh::time() const template -void Foam::DelaunayMesh::timeCheck +inline void Foam::DelaunayMesh::timeCheck ( const string& description, const bool check @@ -90,31 +90,38 @@ inline Foam::label Foam::DelaunayMesh::getNewVertexIndex() const template -Foam::label Foam::DelaunayMesh::cellCount() const +inline Foam::label Foam::DelaunayMesh::cellCount() const { return cellCount_; } template -Foam::label Foam::DelaunayMesh::vertexCount() const +inline Foam::label Foam::DelaunayMesh::vertexCount() const { return vertexCount_; } template -void Foam::DelaunayMesh::resetCellCount() +inline void Foam::DelaunayMesh::resetCellCount() { cellCount_ = 0; } template -void Foam::DelaunayMesh::resetVertexCount() +inline void Foam::DelaunayMesh::resetVertexCount() { vertexCount_ = 0; } +template +inline Foam::Random& Foam::DelaunayMesh::rndGen() const +{ + return rndGen_; +} + + // ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C index c7c60bcf88..fa6cb3efae 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C @@ -900,7 +900,7 @@ Foam::DistributedDelaunayMesh::rangeInsertReferredWithInfo ); } - std::random_shuffle(pointsBbDistSqr.begin(), pointsBbDistSqr.end()); + this->rndGen().permute(pointsBbDistSqr); // Sort in ascending order by the distance of the point from the centre // of the processor bounding box diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index 9daec62ed9..4535582e52 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -827,7 +827,6 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh : DistributedDelaunayMesh(runTime), runTime_(runTime), - rndGen_(64293*Pstream::myProcNo()), foamyHexMeshControls_(foamyHexMeshDict), allGeometry_ ( @@ -846,7 +845,7 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh geometryToConformTo_ ( runTime_, - rndGen_, + rndGen(), allGeometry_, foamyHexMeshDict.subDict("surfaceConformation") ), @@ -856,7 +855,7 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh ? new backgroundMeshDecomposition ( runTime_, - rndGen_, + rndGen(), geometryToConformTo_, foamyHexMeshControls().foamyHexMeshDict().subDict ( @@ -884,7 +883,7 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh ( foamyHexMeshDict.subDict("initialPoints"), runTime_, - rndGen_, + rndGen(), geometryToConformTo_, cellShapeControl_, decomposition_ @@ -986,7 +985,7 @@ void Foam::conformalVoronoiMesh::initialiseForConformation() new backgroundMeshDecomposition ( runTime_, - rndGen_, + rndGen(), geometryToConformTo_, foamyHexMeshControls().foamyHexMeshDict().subDict ( diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index 730e662e86..500214ae5f 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -139,9 +139,6 @@ private: //- The time registry of the application const Time& runTime_; - //- Random number generator - mutable Random rndGen_; - //- Controls for the conformal Voronoi meshing process cvControls foamyHexMeshControls_; @@ -902,9 +899,6 @@ public: //- Return the Time object inline const Time& time() const; - //- Return the random number generator - inline Random& rndGen() const; - //- Return the allGeometry object inline const searchableSurfaces& allGeometry() const; diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H index 7abf36ccc4..604706dd4a 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -293,9 +293,9 @@ inline Foam::point Foam::conformalVoronoiMesh::perturbPoint scalar pert = 1e-12*defaultCellSize(); - perturbedPt.x() += pert*(rndGen_.scalar01() - 0.5); - perturbedPt.y() += pert*(rndGen_.scalar01() - 0.5); - perturbedPt.z() += pert*(rndGen_.scalar01() - 0.5); + perturbedPt.x() += pert*(rndGen().scalar01() - 0.5); + perturbedPt.y() += pert*(rndGen().scalar01() - 0.5); + perturbedPt.z() += pert*(rndGen().scalar01() - 0.5); return perturbedPt; } @@ -533,12 +533,6 @@ inline const Foam::Time& Foam::conformalVoronoiMesh::time() const } -inline Foam::Random& Foam::conformalVoronoiMesh::rndGen() const -{ - return rndGen_; -} - - inline const Foam::searchableSurfaces& Foam::conformalVoronoiMesh::allGeometry() const { 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 8461103f52..b29d385386 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/initialPointsMethod/autoDensity/autoDensity.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/initialPointsMethod/autoDensity/autoDensity.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -566,7 +566,7 @@ bool Foam::autoDensity::fillBox // Randomise the order of the points to (potentially) improve the speed // of assessing the density ratio, and prevent a box being filled from a // corner when only some these points are required. - shuffle(samplePoints); + rndGen().permute(samplePoints); scalarField sampleSizes = cellShapeControls().cellSize(samplePoints); diff --git a/src/OpenFOAM/algorithms/boundSphere/boundSphereTemplates.C b/src/OpenFOAM/algorithms/boundSphere/boundSphereTemplates.C index e9b3bbc93d..3303543494 100644 --- a/src/OpenFOAM/algorithms/boundSphere/boundSphereTemplates.C +++ b/src/OpenFOAM/algorithms/boundSphere/boundSphereTemplates.C @@ -264,10 +264,7 @@ Foam::boundSphere(const PointField& ps, Random& rndGen) else { labelList pis(identity(ps.size())); - forAll(pis, i) - { - Swap(pis[i], pis[rndGen.sampleAB