Random: Replaced drand48 with an in-class implementation

This is faster than the library functionality that it replaces, as it
allows the compiler to do inlining. It also does not utilise any static
state so generators do not interfere with each other. It is also faster
than the the array lookup in cachedRandom. The cachedRandom class
therefore offers no advantage over Random and has been removed.
This commit is contained in:
Will Bainbridge
2018-06-07 17:33:16 +01:00
parent 88a218ce84
commit 002e7d7b06
96 changed files with 625 additions and 1358 deletions

View File

@ -1,3 +1,3 @@
Test-Distribution.C
EXE = $(FOAM_USER_APPBIN)/Test-DistributionTest
EXE = $(FOAM_USER_APPBIN)/Test-Distribution

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -66,12 +66,12 @@ int main(int argc, char *argv[])
Info<< nl << "Distribution<scalar>" << nl
<< "Sampling "
<< randomDistributionTestSize
<< " times from GaussNormal distribution."
<< " times from a standard normal distribution."
<< endl;
for (label i = 0; i < randomDistributionTestSize; i++)
{
dS.add(2.5*R.GaussNormal() + 8.5);
dS.add(2.5*R.scalarNormal() + 8.5);
}
Info<< "Mean " << dS.mean() << nl
@ -85,12 +85,12 @@ int main(int argc, char *argv[])
Info<< nl << "Distribution<scalar>" << nl
<< "Sampling "
<< randomDistributionTestSize
<< " times from GaussNormal distribution."
<< " times from a standard normal distribution."
<< endl;
for (label i = 0; i < randomDistributionTestSize; i++)
{
dS2.add(1.5*R.GaussNormal() -6.0);
dS2.add(1.5*R.scalarNormal() -6.0);
}
Info<< "Mean " << dS2.mean() << nl
@ -150,23 +150,23 @@ int main(int argc, char *argv[])
Info<< nl << "Distribution<vector>" << nl
<< "Sampling "
<< randomDistributionTestSize
<< " times from uniform and GaussNormal distribution."
<< " times from uniform and a standard normal distribution."
<< endl;
for (label i = 0; i < randomDistributionTestSize; i++)
{
dV.add(R.vector01());
dV.add(R.sample01<vector>());
// Adding separate GaussNormal components with component
// Adding separate standard normal components with component
// weights
dV.add
(
vector
(
R.GaussNormal()*3.0 + 1.5,
R.GaussNormal()*0.25 + 4.0,
R.GaussNormal()*3.0 - 1.5
R.scalarNormal()*3.0 + 1.5,
R.scalarNormal()*0.25 + 4.0,
R.scalarNormal()*3.0 - 1.5
),
vector(1.0, 2.0, 5.0)
);
@ -197,9 +197,9 @@ int main(int argc, char *argv[])
// (
// labelVector
// (
// R.integer(-1000, 1000),
// R.integer(-5000, 5000),
// R.integer(-2000, 7000)
// R.sampleAB<label>(-1000, 1001),
// R.sampleAB<label>(-5000, 5001),
// R.sampleAB<label>(-2000, 7001)
// )
// );
// }
@ -225,7 +225,7 @@ int main(int argc, char *argv[])
for (label i = 0; i < randomDistributionTestSize; i++)
{
dT.add(R.tensor01());
dT.add(R.sample01<tensor>());
}
Info<< "Mean " << dT.mean() << nl
@ -249,7 +249,7 @@ int main(int argc, char *argv[])
for (label i = 0; i < randomDistributionTestSize; i++)
{
dSyT.add(R.symmTensor01());
dSyT.add(R.sample01<symmTensor>());
}
Info<< "Mean " << dSyT.mean() << nl
@ -273,7 +273,7 @@ int main(int argc, char *argv[])
for (label i = 0; i < randomDistributionTestSize; i++)
{
dSpT.add(R.sphericalTensor01());
dSpT.add(R.sample01<sphericalTensor>());
}
Info<< "Mean " << dSpT.mean() << nl

View File

@ -163,7 +163,7 @@ int main(int argc, char *argv[])
}
// Remove face
label candidateFacei = rndGen.integer(0, mesh.nInternalFaces()-1);
label candidateFacei = rndGen.sampleAB<label>(0, mesh.nInternalFaces());
Info<< "Wanting to delete face " << mesh.faceCentres()[candidateFacei]
<< nl << endl;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -195,7 +195,7 @@ int main(int argc, char *argv[])
mesh.topoChanging(false);
label action = rndGen.integer(0, 5);
label action = rndGen.sampleAB<label>(0, 6);
if (action == 0)
@ -216,7 +216,10 @@ int main(int argc, char *argv[])
for (label i=0; i<nRefine; i++)
{
refineCandidates.append(rndGen.integer(0, mesh.nCells()-1));
refineCandidates.append
(
rndGen.sampleAB<label>(0, mesh.nCells())
);
}
labelList cellsToRefine
@ -245,7 +248,8 @@ int main(int argc, char *argv[])
for (label i=0; i<nUnrefine; i++)
{
label index = rndGen.integer(0, allSplitPoints.size()-1);
label index =
rndGen.sampleAB<label>(0, allSplitPoints.size());
candidates.insert(allSplitPoints[index]);
}

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
@ -62,7 +62,8 @@ int main(int argc, char *argv[])
List<Tuple2<label, List<scalar>>> complexData(100);
forAll(complexData, i)
{
complexData[i].first() = rndGen.integer(0, Pstream::nProcs()-1);
complexData[i].first() =
rndGen.sampleAB<label>(0, Pstream::nProcs());
complexData[i].second().setSize(3);
complexData[i].second()[0] = 1;
complexData[i].second()[1] = 2;

View File

@ -38,7 +38,7 @@ int main()
for (label i=0; i<size; i+=rndAddrSkip)
{
addr[i] = genAddr.integer(0, size-1);
addr[i] = genAddr.sampleAB<label>(0, size);
}
for (label i=0; i<redSize; i++)

View File

@ -48,7 +48,7 @@ void testPackedList(const polyMesh& mesh, Random& rndGen)
PackedList<3> bits(mesh.nEdges());
forAll(bits, i)
{
bits.set(i, rndGen.integer(0,3));
bits.set(i, rndGen.sampleAB<label>(0, 4));
}
labelList edgeValues(mesh.nEdges());
@ -95,7 +95,7 @@ void testPackedList(const polyMesh& mesh, Random& rndGen)
PackedList<3> bits(mesh.nPoints());
forAll(bits, i)
{
bits.set(i, rndGen.integer(0,3));
bits.set(i, rndGen.sampleAB<label>(0, 4));
}
labelList pointValues(mesh.nPoints());
@ -143,7 +143,7 @@ void testPackedList(const polyMesh& mesh, Random& rndGen)
PackedList<3> bits(mesh.nFaces());
forAll(bits, facei)
{
bits.set(facei, rndGen.integer(0,3));
bits.set(facei, rndGen.sampleAB<label>(0, 4));
}
labelList faceValues(mesh.nFaces());
@ -213,7 +213,7 @@ void testSparseData(const polyMesh& mesh, Random& rndGen)
forAll(localPoints, i)
{
const point pt = localPoints[i] + 1e-4*rndGen.vector01();
const point pt = localPoints[i] + 1e-4*rndGen.sample01<vector>();
label meshPointi = allBoundary.meshPoints()[i];
@ -298,7 +298,8 @@ void testSparseData(const polyMesh& mesh, Random& rndGen)
{
const edge& e = edges[i];
const point pt = e.centre(localPoints) + 1e-4*rndGen.vector01();
const point pt =
e.centre(localPoints) + 1e-4*rndGen.sample01<vector>();
label meshEdgeI = meshEdges[i];

View File

@ -729,7 +729,7 @@ bool Foam::autoDensity::fillBox
{
trialPoints++;
point p = min + cmptMultiply(span, rndGen().vector01());
point p = min + cmptMultiply(span, rndGen().sample01<vector>());
scalar localSize = cellShapeControls().cellSize(p);

View File

@ -20,7 +20,7 @@
const fileName pdfPath = runTime.path()/"pdf";
mkDir(pdfPath);
cachedRandom rndGen(label(0), -1);
Random rndGen(label(0));
autoPtr<distributionModel> p
(

View File

@ -122,8 +122,7 @@ sha1 = primitives/hashes/SHA1
$(sha1)/SHA1.C
$(sha1)/SHA1Digest.C
primitives/random/Random/Random.C
primitives/random/cachedRandom/cachedRandom.C
primitives/Random/Random.C
ranges = primitives/ranges
$(ranges)/labelRange/labelRange.C

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
@ -42,7 +42,6 @@ SourceFiles
#include "point.H"
#include "primitiveFieldsFwd.H"
#include "pointHit.H"
#include "cachedRandom.H"
#include "Random.H"
#include "FixedList.H"
#include "UList.H"
@ -171,10 +170,6 @@ public:
// uniform distribution
inline Point randomPoint(Random& rndGen) const;
//- Return a random point in the tetrahedron from a
// uniform distribution
inline Point randomPoint(cachedRandom& rndGen) const;
//- Calculate the point from the given barycentric coordinates.
inline Point barycentricToPoint(const barycentric& bary) const;

View File

@ -249,16 +249,6 @@ inline Point Foam::tetrahedron<Point, PointRef>::randomPoint
}
template<class Point, class PointRef>
inline Point Foam::tetrahedron<Point, PointRef>::randomPoint
(
cachedRandom& rndGen
) const
{
return barycentricToPoint(barycentric01(rndGen));
}
template<class Point, class PointRef>
inline Point Foam::tetrahedron<Point, PointRef>::barycentricToPoint
(

View File

@ -40,7 +40,6 @@ SourceFiles
#include "tensor.H"
#include "pointHit.H"
#include "Random.H"
#include "cachedRandom.H"
#include "FixedList.H"
#include "UList.H"
#include "linePointRef.H"
@ -167,10 +166,6 @@ public:
// distribution
inline Point randomPoint(Random& rndGen) const;
//- Return a random point on the triangle from a uniform
// distribution
inline Point randomPoint(cachedRandom& rndGen) const;
//- Calculate the point from the given barycentric coordinates.
inline Point barycentricToPoint(const barycentric2D& bary) const;

View File

@ -244,16 +244,6 @@ inline Point Foam::triangle<Point, PointRef>::randomPoint(Random& rndGen) const
}
template<class Point, class PointRef>
inline Point Foam::triangle<Point, PointRef>::randomPoint
(
cachedRandom& rndGen
) const
{
return barycentricToPoint(barycentric2D01(rndGen));
}
template<class Point, class PointRef>
inline Point Foam::triangle<Point, PointRef>::barycentricToPoint
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,17 +25,15 @@ License
#include "barycentric.H"
#include "Random.H"
#include "cachedRandom.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::barycentric barycentric01
(
Foam::scalar s,
Foam::scalar t,
Foam::scalar u
)
Foam::barycentric Foam::barycentric01(Random& rndGen)
{
scalar s = rndGen.scalar01();
scalar t = rndGen.scalar01();
scalar u = rndGen.scalar01();
// Transform the random point in the unit cube to a random point in the
// unit tet by means of a series of reflections. See
// <http://vcg.isti.cnr.it/jgt/tetra.htm> for details.
@ -66,30 +64,4 @@ Foam::barycentric barycentric01
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::barycentric Foam::barycentric01(Random& rndGen)
{
return
::barycentric01
(
rndGen.scalar01(),
rndGen.scalar01(),
rndGen.scalar01()
);
}
Foam::barycentric Foam::barycentric01(cachedRandom& rndGen)
{
return
::barycentric01
(
rndGen.sample01<scalar>(),
rndGen.sample01<scalar>(),
rndGen.sample01<scalar>()
);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,7 +43,6 @@ namespace Foam
// Forward declaration of classes
class Random;
class cachedRandom;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,7 +52,6 @@ typedef Barycentric<scalar> barycentric;
//- Generate a random barycentric coordinate within the unit tetrahedron
barycentric barycentric01(Random& rndGen);
barycentric barycentric01(cachedRandom& rndGen);
template<>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,16 +25,14 @@ License
#include "barycentric2D.H"
#include "Random.H"
#include "cachedRandom.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::barycentric2D barycentric2D01
(
Foam::scalar s,
Foam::scalar t
)
Foam::barycentric2D Foam::barycentric2D01(Random& rndGen)
{
scalar s = rndGen.scalar01();
scalar t = rndGen.scalar01();
// Transform the random point in the unit square to a random point in the
// unit tri by reflecting across the diagonal
@ -48,28 +46,4 @@ Foam::barycentric2D barycentric2D01
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::barycentric2D Foam::barycentric2D01(Random& rndGen)
{
return
::barycentric2D01
(
rndGen.scalar01(),
rndGen.scalar01()
);
}
Foam::barycentric2D Foam::barycentric2D01(cachedRandom& rndGen)
{
return
::barycentric2D01
(
rndGen.sample01<scalar>(),
rndGen.sample01<scalar>()
);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,7 +43,6 @@ namespace Foam
// Forward declaration of classes
class Random;
class cachedRandom;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,7 +52,6 @@ typedef Barycentric2D<scalar> barycentric2D;
//- Generate a random barycentric coordinate within the unit triangle
barycentric2D barycentric2D01(Random& rndGen);
barycentric2D barycentric2D01(cachedRandom& rndGen);
template<>

View File

@ -0,0 +1,109 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "Random.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::scalar Foam::Random::scalarNormal()
{
// Proper inversion of the distribution. Slow. Exactly maintains
// the random behaviour of the generator.
/*
using namespace constant::mathematical;
static const scalar sqrtTwo = sqrt(scalar(2));
static const scalar sqrtPiByTwo = sqrt(pi)/2;
static const scalar a = 8*(pi - 3)/(3*pi*(4 - pi));
const scalar x = 2*scalar01() - 1;
const scalar xPos = mag(x);
// Initial approximation
const scalar l = log(1 - sqr(xPos));
const scalar ll = 2/(pi*a) + l/2;
scalar y = sqrt(sqrt(sqr(ll) - l/a) - ll);
// Newton improvement
label n = 0;
while (n < 2)
{
const scalar dt = (erf(y) - xPos)/exp(- y*y)*sqrtPiByTwo;
y -= dt;
n += mag(dt) < rootSmall;
}
return sign(x)*sqrtTwo*y;
*/
// Box-Muller transform. Fast. Uses rejection and caching so the
// random sequence is not guaranteed.
if (scalarNormalStored_)
{
scalarNormalStored_ = false;
return scalarNormalValue_;
}
else
{
scalar x1, x2, rr;
do
{
x1 = 2*scalar01() - 1;
x2 = 2*scalar01() - 1;
rr = sqr(x1) + sqr(x2);
}
while (rr >= 1 || rr == 0);
const scalar f = sqrt(- 2*log(rr)/rr);
scalarNormalValue_ = x1*f;
scalarNormalStored_ = true;
return x2*f;
}
}
Foam::scalar Foam::Random::globalScalar01()
{
scalar value = - vGreat;
if (Pstream::master())
{
value = scalar01();
}
Pstream::scatter(value);
return value;
}
// ************************************************************************* //

View File

@ -0,0 +1,158 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::Random
Description
Random number generator
This is a clone of the drand48 algorithm. This is significantly quicker
than drand48, presumably due to the compiler inlining the sampling methods.
It is also significantly quicker than the standard library linear
congruential engine, as it does not use Schrage's algorithm to prevent
overflow.
See <http://pubs.opengroup.org/onlinepubs/007908775/xsh/drand48.html> for
details of the seeding and iteration sequence.
SourceFiles
RandomI.H
\*---------------------------------------------------------------------------*/
#ifndef Random_H
#define Random_H
#include "scalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class Random Declaration
\*---------------------------------------------------------------------------*/
class Random
{
// Private typedefs
//- Working type
typedef uint64_t type;
// Private static data
//- The parameters of the linear congruential iteration
static const type A = 0x5DEECE66D, C = 0xB, M = type(1) << 48;
// Private data
//- The stored integer
type x_;
//- Is a normal scalar sample stored?
bool scalarNormalStored_;
//- A stored normal scalar sample
scalar scalarNormalValue_;
// Private Member Functions
//- Advance the state and return an integer sample
inline type sample();
public:
// Constructors
//- Construct from a seed
inline Random(const label s);
//- Destructor
inline ~Random();
// Member Functions
// Scalars
//- Advance the state and return a scalar sample from a uniform
// distribution between zero and one
inline scalar scalar01();
//- Advance the state and return a scalar sample from a uniform
// distribution between two limits
inline scalar scalarAB(const scalar a, const scalar b);
//- Advance the state and return a scalar sample from a normal
// distribution with mean zero and standard deviation one
scalar scalarNormal();
// Other types
//- Advance the state and return a sample of a given type from a
// uniform distribution between zero and one
template<class Type>
inline Type sample01();
//- Advance the state and return a sample of a given type from a
// uniform distribution between two limits
template<class Type>
inline Type sampleAB(const Type& a, const Type& b);
//- Advance the state and return a sample of a given type from a
// normal distribution with mean zero and standard deviation one
template<class Type>
inline Type sampleNormal();
// Global scalars
//- Advance the state and return a scalar sample from a uniform
// distribution between zero and one. Synchronises across all
// cores. Use of this is discouraged. It is expensive and
// introduces non-randomness in all cores other then the master.
scalar globalScalar01();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "RandomI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "Random.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline Foam::Random::type Foam::Random::sample()
{
x_ = (A*x_ + C) % M;
return x_ >> 17;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::Random::Random(const label s)
:
x_((type(s) << 16) + 0x330E),
scalarNormalStored_(false),
scalarNormalValue_(0)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
inline Foam::Random::~Random()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::scalar Foam::Random::scalar01()
{
return scalar(sample())/(M >> 17);
}
inline Foam::scalar Foam::Random::scalarAB(const scalar a, const scalar b)
{
return a + scalar01()*(b - a);
}
template<class Type>
inline Type Foam::Random::sample01()
{
Type value;
for (direction i = 0; i < pTraits<Type>::nComponents; ++ i)
{
value.component(i) = scalar01();
}
return value;
}
template<>
inline Foam::scalar Foam::Random::sample01()
{
return scalar01();
}
template<>
inline Foam::label Foam::Random::sample01()
{
return sample() % 2;
}
template<class Type>
inline Type Foam::Random::sampleAB(const Type& a, const Type& b)
{
return a + cmptMultiply(sample01<Type>(), b - a);
}
template<>
inline Foam::scalar Foam::Random::sampleAB(const scalar& a, const scalar& b)
{
return scalarAB(a, b);
}
template<>
inline Foam::label Foam::Random::sampleAB(const label& a, const label& b)
{
return a + sample() % (b - a);
}
template<class Type>
inline Type Foam::Random::sampleNormal()
{
Type value;
for (direction i = 0; i < pTraits<Type>::nComponents; ++ i)
{
value.component(i) = scalarNormal();
}
return value;
}
template<>
inline Foam::scalar Foam::Random::sampleNormal()
{
return scalarNormal();
}
// ************************************************************************* //

View File

@ -1,198 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "Random.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#if INT_MAX != 2147483647
# error "INT_MAX != 2147483647"
# error "The random number generator may not work!"
#endif
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::Random::Random(const label seed)
{
if (seed > 1)
{
Seed = seed;
}
else
{
Seed = 1;
}
osRandomSeed(Seed);
}
int Foam::Random::bit()
{
if (osRandomInteger() > INT_MAX/2)
{
return 1;
}
else
{
return 0;
}
}
Foam::scalar Foam::Random::scalar01()
{
return osRandomDouble();
}
Foam::vector Foam::Random::vector01()
{
vector rndVec;
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
{
rndVec.component(cmpt) = scalar01();
}
return rndVec;
}
Foam::sphericalTensor Foam::Random::sphericalTensor01()
{
sphericalTensor rndTen;
rndTen.ii() = scalar01();
return rndTen;
}
Foam::symmTensor Foam::Random::symmTensor01()
{
symmTensor rndTen;
for (direction cmpt=0; cmpt<symmTensor::nComponents; cmpt++)
{
rndTen.component(cmpt) = scalar01();
}
return rndTen;
}
Foam::tensor Foam::Random::tensor01()
{
tensor rndTen;
for (direction cmpt=0; cmpt<tensor::nComponents; cmpt++)
{
rndTen.component(cmpt) = scalar01();
}
return rndTen;
}
Foam::label Foam::Random::integer(const label lower, const label upper)
{
return lower + (osRandomInteger() % (upper+1-lower));
}
Foam::vector Foam::Random::position(const vector& start, const vector& end)
{
vector rndVec(start);
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
{
rndVec.component(cmpt) +=
scalar01()*(end.component(cmpt) - start.component(cmpt));
}
return rndVec;
}
void Foam::Random::randomise(scalar& s)
{
s = scalar01();
}
void Foam::Random::randomise(vector& v)
{
v = vector01();
}
void Foam::Random::randomise(sphericalTensor& st)
{
st = sphericalTensor01();
}
void Foam::Random::randomise(symmTensor& st)
{
st = symmTensor01();
}
void Foam::Random::randomise(tensor& t)
{
t = tensor01();
}
Foam::scalar Foam::Random::GaussNormal()
{
static int iset = 0;
static scalar gset;
scalar fac, rsq, v1, v2;
if (iset == 0)
{
do
{
v1 = 2.0*scalar01() - 1.0;
v2 = 2.0*scalar01() - 1.0;
rsq = sqr(v1) + sqr(v2);
} while (rsq >= 1.0 || rsq == 0.0);
fac = sqrt(-2.0*log(rsq)/rsq);
gset = v1*fac;
iset = 1;
return v2*fac;
}
else
{
iset = 0;
return gset;
}
}
// ************************************************************************* //

View File

@ -1,110 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::Random
Description
Simple random number generator.
SourceFiles
Random.C
\*---------------------------------------------------------------------------*/
#ifndef Random_H
#define Random_H
#include "vector.H"
#include "tensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class Random Declaration
\*---------------------------------------------------------------------------*/
class Random
{
// Private data
label Seed;
public:
// Constructors
//- Construct given seed
Random(const label);
// Member functions
int bit();
//- Scalar [0..1] (so including 0,1)
scalar scalar01();
//- Vector with every component scalar01
vector vector01();
//- sphericalTensor with every component scalar01
sphericalTensor sphericalTensor01();
//- symmTensor with every component scalar01
symmTensor symmTensor01();
//- Tensor with every component scalar01
tensor tensor01();
//- Label [lower..upper]
label integer(const label lower, const label upper);
vector position(const vector&, const vector&);
void randomise(scalar&);
void randomise(vector&);
void randomise(sphericalTensor&);
void randomise(symmTensor&);
void randomise(tensor&);
//- Return a normal Gaussian randon number
// with zero mean and unity variance N(0, 1)
scalar GaussNormal();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,293 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cachedRandom.H"
#include "OSspecific.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * private Member Functions * * * * * * * * * * * //
Foam::scalar Foam::cachedRandom::scalar01()
{
if (sampleI_ < 0)
{
return osRandomDouble();
}
if (sampleI_ == samples_.size() - 1)
{
scalar s = samples_[sampleI_];
sampleI_ = 0;
return s;
}
else
{
scalar s = samples_[sampleI_];
sampleI_++;
return s;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cachedRandom::cachedRandom(const label seed, const label count)
:
seed_(1),
samples_(0),
sampleI_(-1),
hasGaussSample_(false),
gaussSample_(0)
{
if (seed > 1)
{
seed_ = seed;
}
// Samples will be cached if count > 0
if (count > 0)
{
samples_.setSize(count);
sampleI_ = 0;
}
// Initialise samples
osRandomSeed(seed_);
forAll(samples_, i)
{
samples_[i] = osRandomDouble();
}
}
Foam::cachedRandom::cachedRandom(const cachedRandom& cr, const bool reset)
:
seed_(cr.seed_),
samples_(cr.samples_),
sampleI_(cr.sampleI_),
hasGaussSample_(cr.hasGaussSample_),
gaussSample_(cr.gaussSample_)
{
if (reset)
{
hasGaussSample_ = false;
gaussSample_ = 0;
}
if (sampleI_ == -1)
{
WarningInFunction
<< "Copy constructor called, but samples not being cached. "
<< "This may lead to non-repeatable behaviour" << endl;
osRandomSeed(seed_);
}
if (reset && samples_.size())
{
sampleI_ = 0;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cachedRandom::~cachedRandom()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<>
Foam::scalar Foam::cachedRandom::sample01()
{
return scalar01();
}
template<>
Foam::label Foam::cachedRandom::sample01()
{
return round(scalar01());
}
template<>
Foam::scalar Foam::cachedRandom::GaussNormal()
{
if (hasGaussSample_)
{
hasGaussSample_ = false;
return gaussSample_;
}
else
{
scalar rsq, v1, v2;
do
{
v1 = 2*scalar01() - 1;
v2 = 2*scalar01() - 1;
rsq = sqr(v1) + sqr(v2);
} while (rsq >= 1 || rsq == 0);
scalar fac = sqrt(-2*log(rsq)/rsq);
gaussSample_ = v1*fac;
hasGaussSample_ = true;
return v2*fac;
}
}
template<>
Foam::label Foam::cachedRandom::GaussNormal()
{
return round(GaussNormal<scalar>());
}
template<>
Foam::scalar Foam::cachedRandom::position
(
const scalar& start,
const scalar& end
)
{
return start + scalar01()*(end - start);
}
template<>
Foam::label Foam::cachedRandom::position(const label& start, const label& end)
{
return start + round(scalar01()*(end - start));
}
template<>
Foam::scalar Foam::cachedRandom::globalSample01()
{
scalar value = -great;
if (Pstream::master())
{
value = scalar01();
}
Pstream::scatter(value);
return value;
}
template<>
Foam::label Foam::cachedRandom::globalSample01()
{
scalar value = -great;
if (Pstream::master())
{
value = scalar01();
}
Pstream::scatter(value);
return round(value);
}
template<>
Foam::scalar Foam::cachedRandom::globalGaussNormal()
{
scalar value = -great;
if (Pstream::master())
{
value = GaussNormal<scalar>();
}
Pstream::scatter(value);
return value;
}
template<>
Foam::label Foam::cachedRandom::globalGaussNormal()
{
scalar value = -great;
if (Pstream::master())
{
value = GaussNormal<scalar>();
}
Pstream::scatter(value);
return round(value);
}
template<>
Foam::scalar Foam::cachedRandom::globalPosition
(
const scalar& start,
const scalar& end
)
{
scalar value = -great;
if (Pstream::master())
{
value = scalar01()*(end - start);
}
Pstream::scatter(value);
return start + value;
}
template<>
Foam::label Foam::cachedRandom::globalPosition
(
const label& start,
const label& end
)
{
label value = labelMin;
if (Pstream::master())
{
value = round(scalar01()*(end - start));
}
Pstream::scatter(value);
return start + value;
}
// ************************************************************************* //

View File

@ -1,234 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::cachedRandom
Description
Random number generator.
Pre-computes and caches samples on construction, so that when sample01()
is called, the function simply returns the next (pre-computed) sample. On
reaching the last sample, the sample sequence is repeated.
Constructed using a seed and sample count. If the supplied count is
negative, no caching is performed, and a new sample is generated on each
call to sample01().
Note: the copy constructor cannot be used if count = -1.
SourceFiles
cachedRandomI.H
cachedRandom.C
cachedRandomTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef cachedRandom_H
#define cachedRandom_H
#include "scalarList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class cachedRandom;
/*---------------------------------------------------------------------------*\
Class cachedRandom Declaration
\*---------------------------------------------------------------------------*/
class cachedRandom
{
// Private data
//- Initial random number seed
label seed_;
//- List of scalar samples
scalarList samples_;
//- Current sample marker
label sampleI_;
//- Indicator, which tells if there is a stored gaussian sample
bool hasGaussSample_;
//- Stored sample value
scalar gaussSample_;
// Private Member Functions
//- Returns the current sample
scalar scalar01();
public:
// Constructors
//- Construct given seed and sample count
cachedRandom(const label seed, const label count);
//- Copy constructor with optional reset of sampleI
cachedRandom(const cachedRandom& cr, const bool reset = false);
// Destructor
~cachedRandom();
// Member functions
// Access
//- Return const access to the initial random number seed
inline label seed() const;
//- Return const access to the list of samples
inline const scalarList& samples() const;
//- Return the current sample marker
inline label sampleI() const;
// Manipulation
//- Return non-const access to the sample marker
inline label& sampleI();
// Evaluation
// Random numbers
//- Return a sample whose components lie in the range 0-1
template<class Type>
Type sample01();
//- Return a sample whose components are normally distributed
// with zero mean and unity variance N(0, 1)
template<class Type>
Type GaussNormal();
//- Return a sample between start and end
template<class Type>
Type position(const Type& start, const Type& end);
//- Randomise value in the range 0-1
template<class Type>
void randomise01(Type& value);
// Global random numbers - consistent across all processors
//- Return a sample whose components lie in the range 0-1
template<class Type>
Type globalSample01();
//- Return a sample whose components are normally distributed
// with zero mean and unity variance N(0, 1)
template<class Type>
Type globalGaussNormal();
//- Return a sample between start and end
template<class Type>
Type globalPosition(const Type& start, const Type& end);
//- Randomise value in the range 0-1
template<class Type>
void globalRandomise01(Type& value);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Template specialisations
template<>
scalar cachedRandom::sample01<scalar>();
template<>
label cachedRandom::sample01<label>();
template<>
scalar cachedRandom::GaussNormal<scalar>();
template<>
label cachedRandom::GaussNormal<label>();
template<>
scalar cachedRandom::position<scalar>
(
const scalar& start,
const scalar& end
);
template<>
label cachedRandom::position<label>(const label& start, const label& end);
template<>
scalar cachedRandom::globalSample01<scalar>();
template<>
label cachedRandom::globalSample01<label>();
template<>
scalar cachedRandom::globalGaussNormal<scalar>();
template<>
label cachedRandom::globalGaussNormal<label>();
template<>
scalar cachedRandom::globalPosition<scalar>
(
const scalar& start,
const scalar& end
);
template<>
label cachedRandom::globalPosition<label>(const label& start, const label& end);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "cachedRandomI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "cachedRandomTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,54 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cachedRandom.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::label Foam::cachedRandom::seed() const
{
return seed_;
}
inline const Foam::scalarList& Foam::cachedRandom::samples() const
{
return samples_;
}
inline Foam::label Foam::cachedRandom::sampleI() const
{
return sampleI_;
}
inline Foam::label& Foam::cachedRandom::sampleI()
{
return sampleI_;
}
// ************************************************************************* //

View File

@ -1,140 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cachedRandom.H"
#include "Pstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::cachedRandom::sample01()
{
Type value;
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
value.component(cmpt) = scalar01();
}
return value;
}
template<class Type>
Type Foam::cachedRandom::GaussNormal()
{
Type value;
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
value.component(cmpt) = GaussNormal<scalar>();
}
return value;
}
template<class Type>
Type Foam::cachedRandom::position(const Type& start, const Type& end)
{
Type value(start);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
value.component(cmpt) +=
scalar01()*(end.component(cmpt) - start.component(cmpt));
}
return value;
}
template<class Type>
void Foam::cachedRandom::randomise01(Type& value)
{
value = sample01<Type>();
}
template<class Type>
Type Foam::cachedRandom::globalSample01()
{
Type value = -great*pTraits<Type>::one;
if (Pstream::master())
{
value = sample01<Type>();
}
Pstream::scatter(value);
return value;
}
template<class Type>
Type Foam::cachedRandom::globalGaussNormal()
{
Type value = -great*pTraits<Type>::one;
if (Pstream::master())
{
value = GaussNormal<Type>();
}
Pstream::scatter(value);
return value;
}
template<class Type>
Type Foam::cachedRandom::globalPosition(const Type& start, const Type& end)
{
Type value = -great*pTraits<Type>::one;
if (Pstream::master())
{
value = position<Type>(start, end);
}
Pstream::scatter(value);
return value;
}
template<class Type>
void Foam::cachedRandom::globalRandomise01(Type& value)
{
value = -great*pTraits<Type>::one;
if (Pstream::master())
{
value = sample01<Type>();
}
Pstream::scatter(value);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -166,7 +166,7 @@ void Foam::turbulentInletFvPatchField<Type>::updateCoeffs()
forAll(patchField, facei)
{
ranGen_.randomise(randomField[facei]);
randomField[facei] = ranGen_.sample01<Type>();
}
// Correction-factor to compensate for the loss of RMS fluctuation

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -46,8 +46,7 @@ bool Foam::functionObjects::randomise::calcRandomised()
forAll(field, celli)
{
Type rndPert;
rand.randomise(rndPert);
Type rndPert = rand.sample01<Type>();
rndPert = 2.0*rndPert - pTraits<Type>::one;
rndPert /= mag(rndPert);
rfield[celli] += magPerturbation_*rndPert;

View File

@ -273,7 +273,7 @@ void Foam::DSMCCloud<ParcelType>::collisions()
// subCell candidate selection procedure
// Select the first collision candidate
label candidateP = rndGen_.integer(0, nC - 1);
label candidateP = rndGen_.sampleAB<label>(0, nC);
// Declare the second collision candidate
label candidateQ = -1;
@ -289,7 +289,7 @@ void Foam::DSMCCloud<ParcelType>::collisions()
do
{
candidateQ = subCellPs[rndGen_.integer(0, nSC - 1)];
candidateQ = subCellPs[rndGen_.sampleAB<label>(0, nSC)];
} while (candidateP == candidateQ);
}
else
@ -300,7 +300,7 @@ void Foam::DSMCCloud<ParcelType>::collisions()
do
{
candidateQ = rndGen_.integer(0, nC - 1);
candidateQ = rndGen_.sampleAB<label>(0, nC);
} while (candidateP == candidateQ);
}
@ -308,15 +308,15 @@ void Foam::DSMCCloud<ParcelType>::collisions()
// uniform candidate selection procedure
// // Select the first collision candidate
// label candidateP = rndGen_.integer(0, nC-1);
// label candidateP = rndGen_.sampleAB<label>(0, nC);
// // Select a possible second collision candidate
// label candidateQ = rndGen_.integer(0, nC-1);
// label candidateQ = rndGen_.sampleAB<label>(0, nC);
// // If the same candidate is chosen, choose again
// while (candidateP == candidateQ)
// {
// candidateQ = rndGen_.integer(0, nC-1);
// candidateQ = rndGen_.sampleAB<label>(0, nC);
// }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -1016,12 +1016,7 @@ Foam::vector Foam::DSMCCloud<ParcelType>::equipartitionLinearVelocity
{
return
sqrt(physicoChemical::k.value()*temperature/mass)
*vector
(
rndGen_.GaussNormal(),
rndGen_.GaussNormal(),
rndGen_.GaussNormal()
);
*rndGen_.sampleNormal<vector>();
}

View File

@ -390,8 +390,8 @@ void Foam::FreeStream<CloudType>::inflow()
vector U =
sqrt(physicoChemical::k.value()*faceTemperature/mass)
*(
rndGen.GaussNormal()*t1
+ rndGen.GaussNormal()*t2
rndGen.scalarNormal()*t1
+ rndGen.scalarNormal()*t2
)
+ (t1 & faceVelocity)*t1
+ (t2 & faceVelocity)*t2

View File

@ -113,8 +113,8 @@ void Foam::MaxwellianThermal<CloudType>::correct
U =
sqrt(physicoChemical::k.value()*T/mass)
*(
rndGen.GaussNormal()*tw1
+ rndGen.GaussNormal()*tw2
rndGen.scalarNormal()*tw1
+ rndGen.scalarNormal()*tw2
- sqrt(-2.0*log(max(1 - rndGen.scalar01(), vSmall)))*nw
);

View File

@ -115,8 +115,8 @@ void Foam::MixedDiffuseSpecular<CloudType>::correct
U =
sqrt(physicoChemical::k.value()*T/mass)
*(
rndGen.GaussNormal()*tw1
+ rndGen.GaussNormal()*tw2
rndGen.scalarNormal()*tw1
+ rndGen.scalarNormal()*tw2
- sqrt(-2.0*log(max(1 - rndGen.scalar01(), vSmall)))*nw
);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::RosinRammler::RosinRammler
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -82,7 +82,7 @@ public:
// Constructors
//- Construct from components
RosinRammler(const dictionary& dict, cachedRandom& rndGen);
RosinRammler(const dictionary& dict, Random& rndGen);
//- Construct copy
RosinRammler(const RosinRammler& p);

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
@ -63,7 +63,7 @@ Foam::distributionModel::distributionModel
(
const word& name,
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModelDict_(dict.subDict(name + "Distribution")),

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
@ -55,7 +55,7 @@ SourceFiles
#include "IOdictionary.H"
#include "autoPtr.H"
#include "cachedRandom.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -77,7 +77,7 @@ protected:
const dictionary distributionModelDict_;
//- Reference to the random number generator
cachedRandom& rndGen_;
Random& rndGen_;
// Protected Member Functions
@ -100,7 +100,7 @@ public:
dictionary,
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
),
(dict, rndGen)
);
@ -113,7 +113,7 @@ public:
(
const word& name,
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
);
//- Construct copy
@ -127,7 +127,7 @@ public:
static autoPtr<distributionModel> New
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
);

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
@ -30,7 +30,7 @@ License
Foam::autoPtr<Foam::distributionModel> Foam::distributionModel::New
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
{
const word modelType(dict.lookup("type"));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::exponential::exponential
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -75,7 +75,7 @@ public:
// Constructors
//- Construct from components
exponential(const dictionary& dict, cachedRandom& rndGen);
exponential(const dictionary& dict, Random& rndGen);
//- Construct copy
exponential(const exponential& p);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::fixedValue::fixedValue
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -66,7 +66,7 @@ public:
// Constructors
//- Construct from components
fixedValue(const dictionary& dict, cachedRandom& rndGen);
fixedValue(const dictionary& dict, Random& rndGen);
//- Construct copy
fixedValue(const fixedValue& p);

View File

@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::general::general
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -80,7 +80,7 @@ public:
// Constructors
//- Construct from components
general(const dictionary& dict, cachedRandom& rndGen);
general(const dictionary& dict, Random& rndGen);
//- Construct copy
general(const general& p);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::massRosinRammler::massRosinRammler
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -93,7 +93,7 @@ public:
// Constructors
//- Construct from components
massRosinRammler(const dictionary& dict, cachedRandom& rndGen);
massRosinRammler(const dictionary& dict, Random& rndGen);
//- Construct copy
massRosinRammler(const massRosinRammler& p);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::multiNormal::multiNormal
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -85,7 +85,7 @@ public:
// Constructors
//- Construct from components
multiNormal(const dictionary& dict, cachedRandom& rndGen);
multiNormal(const dictionary& dict, Random& rndGen);
//- Construct copy
multiNormal(const multiNormal& p);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,7 +43,7 @@ namespace distributionModels
Foam::distributionModels::normal::normal
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),

View File

@ -85,7 +85,7 @@ public:
// Constructors
//- Construct from components
normal(const dictionary& dict, cachedRandom& rndGen);
normal(const dictionary& dict, Random& rndGen);
//- Construct copy
normal(const normal& p);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,7 +42,7 @@ namespace distributionModels
Foam::distributionModels::uniform::uniform
(
const dictionary& dict,
cachedRandom& rndGen
Random& rndGen
)
:
distributionModel(typeName, dict, rndGen),
@ -71,7 +71,7 @@ Foam::distributionModels::uniform::~uniform()
Foam::scalar Foam::distributionModels::uniform::sample() const
{
return rndGen_.position<scalar>(minValue_, maxValue_);
return rndGen_.scalarAB(minValue_, maxValue_);
}

View File

@ -70,7 +70,7 @@ public:
// Constructors
//- Construct from components
uniform(const dictionary& dict, cachedRandom& rndGen);
uniform(const dictionary& dict, Random& rndGen);
//- Construct copy
uniform(const uniform& p);

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
@ -322,13 +322,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
(
particleProperties_.subOrEmptyDict("subModels", solution_.active())
),
rndGen_
(
label(0),
solution_.steadyState() ?
particleProperties_.lookupOrDefault<label>("randomSampleSize", 100000)
: -1
),
rndGen_(0),
cellOccupancyPtr_(),
cellLengthScale_(mag(cbrt(mesh_.V()))),
rho_(rho),
@ -430,7 +424,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
solution_(c.solution_),
constProps_(c.constProps_),
subModelProperties_(c.subModelProperties_),
rndGen_(c.rndGen_, true),
rndGen_(c.rndGen_),
cellOccupancyPtr_(nullptr),
cellLengthScale_(c.cellLengthScale_),
rho_(c.rho_),
@ -521,7 +515,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
solution_(mesh),
constProps_(),
subModelProperties_(dictionary::null),
rndGen_(0, 0),
rndGen_(0),
cellOccupancyPtr_(nullptr),
cellLengthScale_(c.cellLengthScale_),
rho_(c.rho_),

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
@ -56,7 +56,7 @@ SourceFiles
#include "kinematicCloud.H"
#include "IOdictionary.H"
#include "autoPtr.H"
#include "cachedRandom.H"
#include "Random.H"
#include "fvMesh.H"
#include "volFields.H"
#include "fvMatrices.H"
@ -161,7 +161,7 @@ protected:
const dictionary subModelProperties_;
//- Random number generator - used by some injection routines
mutable cachedRandom rndGen_;
mutable Random rndGen_;
//- Cell occupancy information for each parcel, (demand driven)
autoPtr<List<DynamicList<parcelType*>>> cellOccupancyPtr_;
@ -368,7 +368,7 @@ public:
// Cloud data
//- Return reference to the random object
inline cachedRandom& rndGen() const;
inline Random& rndGen() const;
//- Return the cell occupancy information for each
// parcel, non-const access, the caller is

View File

@ -356,7 +356,7 @@ inline Foam::scalar Foam::KinematicCloud<CloudType>::Dmax() const
template<class CloudType>
inline Foam::cachedRandom& Foam::KinematicCloud<CloudType>::rndGen() const
inline Foam::Random& Foam::KinematicCloud<CloudType>::rndGen() const
{
return rndGen_;
}

View File

@ -180,7 +180,7 @@ void Foam::ParticleCollector<CloudType>::initConcentricCircles()
Random rnd(1234);
while (magTangent < small)
{
vector v = rnd.vector01();
vector v = rnd.sample01<vector>();
tangent = v - (v & normal_[0])*normal_[0];
magTangent = mag(tangent);

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
@ -40,7 +40,7 @@ void Foam::CellZoneInjection<CloudType>::setPositions
const fvMesh& mesh = this->owner().mesh();
const scalarField& V = mesh.V();
const label nCells = cellZoneCells.size();
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
DynamicList<vector> positions(nCells); // initial size only
DynamicList<label> injectorCells(nCells); // initial size only

View File

@ -250,7 +250,7 @@ void Foam::ConeInjection<CloudType>::setProperties
typename CloudType::parcelType& parcel
)
{
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
// set particle velocity
const label i = parcelI % positionAxis_.size();
@ -258,7 +258,7 @@ void Foam::ConeInjection<CloudType>::setProperties
scalar t = time - this->SOI_;
scalar ti = thetaInner_.value(t);
scalar to = thetaOuter_.value(t);
scalar coneAngle = degToRad(rnd.position<scalar>(ti, to));
scalar coneAngle = degToRad(rnd.scalarAB(ti, to));
scalar alpha = sin(coneAngle);
scalar dcorr = cos(coneAngle);

View File

@ -304,9 +304,9 @@ void Foam::ConeNozzleInjection<CloudType>::setPositionAndCell
label& tetPti
)
{
cachedRandom& rndGen = this->owner().rndGen();
Random& rndGen = this->owner().rndGen();
scalar beta = mathematical::twoPi*rndGen.globalSample01<scalar>();
scalar beta = mathematical::twoPi*rndGen.globalScalar01();
normal_ = tanVec1_*cos(beta) + tanVec2_*sin(beta);
switch (injectionMethod_)
@ -322,7 +322,7 @@ void Foam::ConeNozzleInjection<CloudType>::setPositionAndCell
}
case imDisc:
{
scalar frac = rndGen.globalSample01<scalar>();
scalar frac = rndGen.globalScalar01();
scalar dr = outerDiameter_ - innerDiameter_;
scalar r = 0.5*(innerDiameter_ + frac*dr);
position = position_ + r*normal_;
@ -356,7 +356,7 @@ void Foam::ConeNozzleInjection<CloudType>::setProperties
typename CloudType::parcelType& parcel
)
{
cachedRandom& rndGen = this->owner().rndGen();
Random& rndGen = this->owner().rndGen();
// set particle velocity
const scalar deg2Rad = mathematical::pi/180.0;

View File

@ -203,7 +203,7 @@ Foam::label Foam::InflationInjection<CloudType>::parcelsToInject
newParticles_.clear();
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
// Diameter factor, when splitting particles into 4, this is the
// factor that modifies the diameter.
@ -241,14 +241,8 @@ Foam::label Foam::InflationInjection<CloudType>::parcelsToInject
break;
}
label cI = generationCells_
[
rnd.position
(
label(0),
generationCells_.size() - 1
)
];
label cI =
generationCells_[rnd.sampleAB<label>(0, generationCells_.size())];
// Pick a particle at random from the cell - if there are
// none, insert one at the cell centre. Otherwise, split an
@ -276,7 +270,7 @@ Foam::label Foam::InflationInjection<CloudType>::parcelsToInject
}
else
{
label cPI = rnd.position(label(0), cellOccupancy[cI].size() - 1);
label cPI = rnd.sampleAB<label>(0, cellOccupancy[cI].size());
// This has to be a reference to the pointer so that it
// can be set to nullptr when the particle is deleted.

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -182,8 +182,8 @@ void Foam::KinematicLookupTableInjection<CloudType>::setPositionAndCell
label injectorI = 0;
if (randomise_)
{
cachedRandom& rnd = this->owner().rndGen();
injectorI = rnd.position<label>(0, injectorCells_.size() - 1);
Random& rnd = this->owner().rndGen();
injectorI = rnd.sampleAB<label>(0, injectorCells_.size());
}
else
{

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
@ -162,7 +162,7 @@ Foam::label Foam::PatchFlowRateInjection<CloudType>::parcelsToInject
scalar nParcels = parcelConcentration_*c*flowRate()*dt;
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
label nParcelsToInject = floor(nParcels);
@ -171,10 +171,7 @@ Foam::label Foam::PatchFlowRateInjection<CloudType>::parcelsToInject
if
(
nParcelsToInject > 0
&& (
nParcels - scalar(nParcelsToInject)
> rnd.globalPosition(scalar(0), scalar(1))
)
&& nParcels - scalar(nParcelsToInject) > rnd.globalScalar01()
)
{
++nParcelsToInject;

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
@ -122,7 +122,7 @@ Foam::label Foam::PatchInjection<CloudType>::parcelsToInject
{
scalar nParcels = (time1 - time0)*parcelsPerSecond_;
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
label nParcelsToInject = floor(nParcels);
@ -131,10 +131,7 @@ Foam::label Foam::PatchInjection<CloudType>::parcelsToInject
if
(
nParcelsToInject > 0
&& (
nParcels - scalar(nParcelsToInject)
> rnd.globalPosition(scalar(0), scalar(1))
)
&& (nParcels - scalar(nParcelsToInject) > rnd.globalScalar01())
)
{
++nParcelsToInject;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,7 +26,7 @@ License
#include "patchInjectionBase.H"
#include "polyMesh.H"
#include "SubField.H"
#include "cachedRandom.H"
#include "Random.H"
#include "triPointRef.H"
#include "volFields.H"
#include "polyMeshTetDecomposition.H"
@ -151,14 +151,14 @@ void Foam::patchInjectionBase::updateMesh(const polyMesh& mesh)
void Foam::patchInjectionBase::setPositionAndCell
(
const fvMesh& mesh,
cachedRandom& rnd,
Random& rnd,
vector& position,
label& cellOwner,
label& tetFacei,
label& tetPti
)
{
scalar areaFraction = rnd.globalPosition(scalar(0), patchArea_);
scalar areaFraction = rnd.globalScalar01()*patchArea_;
if (cellOwners_.size() > 0)
{
@ -199,7 +199,7 @@ void Foam::patchInjectionBase::setPositionAndCell
const point pf(tri.randomPoint(rnd));
// Position perturbed away from face (into domain)
const scalar a = rnd.position(scalar(0.1), scalar(0.5));
const scalar a = rnd.scalarAB(0.1, 0.5);
const vector& pc = mesh.cellCentres()[cellOwner];
const vector d =
mag((pf - pc) & patchNormal_[facei])*patchNormal_[facei];

View File

@ -54,7 +54,7 @@ namespace Foam
// Forward class declarations
class polyMesh;
class fvMesh;
class cachedRandom;
class Random;
/*---------------------------------------------------------------------------*\
Class patchInjectionBase Declaration
@ -118,7 +118,7 @@ public:
virtual void setPositionAndCell
(
const fvMesh& mesh,
cachedRandom& rnd,
Random& rnd,
vector& position,
label& cellOwner,
label& tetFacei,

View File

@ -71,7 +71,7 @@ Foam::scalar Foam::IsotropyModels::Stochastic<CloudType>::sampleGauss()
}
else
{
cachedRandom& rndGen = this->owner().rndGen();
Random& rndGen = this->owner().rndGen();
scalar f, m, x, y;
@ -98,7 +98,7 @@ void Foam::IsotropyModels::Stochastic<CloudType>::calculate()
{
const fvMesh& mesh = this->owner().mesh();
const scalar deltaT(this->owner().db().time().deltaTValue());
cachedRandom& rndGen = this->owner().rndGen();
Random& rndGen = this->owner().rndGen();
const scalar oneBySqrtThree = sqrt(1.0/3.0);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -181,8 +181,8 @@ void Foam::ReactingLookupTableInjection<CloudType>::setPositionAndCell
label injectorI = 0;
if (randomise_)
{
cachedRandom& rnd = this->owner().rndGen();
injectorI = rnd.position<label>(0, injectorCells_.size() - 1);
Random& rnd = this->owner().rndGen();
injectorI = rnd.sampleAB<label>(0, injectorCells_.size());
}
else
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -187,8 +187,8 @@ void Foam::ReactingMultiphaseLookupTableInjection<CloudType>::setPositionAndCell
label injectorI = 0;
if (randomise_)
{
cachedRandom& rnd = this->owner().rndGen();
injectorI = rnd.position<label>(0, injectorCells_.size() - 1);
Random& rnd = this->owner().rndGen();
injectorI = rnd.sampleAB<label>(0, injectorCells_.size());
}
else
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -182,8 +182,8 @@ void Foam::ThermoLookupTableInjection<CloudType>::setPositionAndCell
label injectorI = 0;
if (randomise_)
{
cachedRandom& rnd = this->owner().rndGen();
injectorI = rnd.position<label>(0, injectorCells_.size() - 1);
Random& rnd = this->owner().rndGen();
injectorI = rnd.sampleAB<label>(0, injectorCells_.size());
}
else
{

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
@ -98,7 +98,7 @@ protected:
typedef typename CloudType::parcelType parcelType;
//- Reference to the cloud random number generator
cachedRandom& rndGen_;
Random& rndGen_;
//- Reference to the cloud thermo package
const SLGThermo& thermo_;

View File

@ -301,12 +301,9 @@ inline Foam::vector Foam::moleculeCloud::equipartitionLinearVelocity
scalar mass
)
{
return sqrt(physicoChemical::k.value()*temperature/mass)*vector
(
rndGen_.GaussNormal(),
rndGen_.GaussNormal(),
rndGen_.GaussNormal()
);
return
sqrt(physicoChemical::k.value()*temperature/mass)
*rndGen_.sampleNormal<vector>();
}
@ -323,17 +320,17 @@ inline Foam::vector Foam::moleculeCloud::equipartitionAngularMomentum
return sqrtKbT*vector
(
0.0,
sqrt(cP.momentOfInertia().yy())*rndGen_.GaussNormal(),
sqrt(cP.momentOfInertia().zz())*rndGen_.GaussNormal()
sqrt(cP.momentOfInertia().yy())*rndGen_.scalarNormal(),
sqrt(cP.momentOfInertia().zz())*rndGen_.scalarNormal()
);
}
else
{
return sqrtKbT*vector
(
sqrt(cP.momentOfInertia().xx())*rndGen_.GaussNormal(),
sqrt(cP.momentOfInertia().yy())*rndGen_.GaussNormal(),
sqrt(cP.momentOfInertia().zz())*rndGen_.GaussNormal()
sqrt(cP.momentOfInertia().xx())*rndGen_.scalarNormal(),
sqrt(cP.momentOfInertia().yy())*rndGen_.scalarNormal(),
sqrt(cP.momentOfInertia().zz())*rndGen_.scalarNormal()
);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -133,7 +133,7 @@ public:
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const = 0;
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -92,7 +92,7 @@ void Foam::BlobsSheetAtomization<CloudType>::update
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const
{
scalar lBU =

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -119,7 +119,7 @@ public:
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const;
};

View File

@ -118,7 +118,7 @@ void Foam::LISAAtomization<CloudType>::update
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const
{
if (volFlowRate < small)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -139,7 +139,7 @@ public:
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const;
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -95,7 +95,7 @@ void Foam::NoAtomization<CloudType>::update
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const
{}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -102,7 +102,7 @@ public:
const vector& injectionPos,
const scalar pAmbient,
const scalar chi,
cachedRandom& rndGen
Random& rndGen
) const;
};

View File

@ -138,7 +138,7 @@ bool Foam::SHF<CloudType>::update
scalar& massChild
)
{
cachedRandom& rndGen = this->owner().rndGen();
Random& rndGen = this->owner().rndGen();
bool addChild = false;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -110,7 +110,7 @@ bool Foam::TAB<CloudType>::update
scalar& massChild
)
{
cachedRandom& rndGen = this->owner().rndGen();
Random& rndGen = this->owner().rndGen();
scalar r = 0.5*d;
scalar r2 = r*r;

View File

@ -100,7 +100,7 @@ Foam::vector Foam::GradientDispersionRAS<CloudType>::update
scalar& tTurb
)
{
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
const scalar cps = 0.16432;
@ -135,11 +135,11 @@ Foam::vector Foam::GradientDispersionRAS<CloudType>::update
// prevent this we let fac be both negative/positive
if (this->owner().mesh().nSolutionD() == 2)
{
fac = rnd.GaussNormal<scalar>();
fac = rnd.scalarNormal();
}
else
{
fac = mag(rnd.GaussNormal<scalar>());
fac = mag(rnd.scalarNormal());
}
UTurb = sigma*fac*dir;

View File

@ -71,7 +71,7 @@ Foam::vector Foam::StochasticDispersionRAS<CloudType>::update
scalar& tTurb
)
{
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
const scalar cps = 0.16432;
@ -99,13 +99,13 @@ Foam::vector Foam::StochasticDispersionRAS<CloudType>::update
// Calculate a random direction dir distributed uniformly
// in spherical coordinates
const scalar theta = rnd.sample01<scalar>()*twoPi;
const scalar u = 2*rnd.sample01<scalar>() - 1;
const scalar theta = rnd.scalar01()*twoPi;
const scalar u = 2*rnd.scalar01() - 1;
const scalar a = sqrt(1 - sqr(u));
const vector dir(a*cos(theta), a*sin(theta), u);
UTurb = sigma*mag(rnd.GaussNormal<scalar>())*dir;
UTurb = sigma*mag(rnd.scalarNormal())*dir;
}
}
else

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
@ -207,15 +207,15 @@ Foam::forceSuSp Foam::BrownianMotionForce<CloudType>::calcCoupled
// To generate a spherical distribution:
cachedRandom& rnd = this->owner().rndGen();
Random& rnd = this->owner().rndGen();
const scalar theta = rnd.sample01<scalar>()*twoPi;
const scalar u = 2*rnd.sample01<scalar>() - 1;
const scalar theta = rnd.scalar01()*twoPi;
const scalar u = 2*rnd.scalar01() - 1;
const scalar a = sqrt(1 - sqr(u));
const vector dir(a*cos(theta), a*sin(theta), u);
value.Su() = f*mag(rnd.GaussNormal<scalar>())*dir;
value.Su() = f*mag(rnd.scalarNormal())*dir;
return value;
}

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
@ -46,7 +46,7 @@ SourceFiles
#define BrownianMotionForce_H
#include "ParticleForce.H"
#include "cachedRandom.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -65,7 +65,7 @@ class BrownianMotionForce
// Private data
//- Reference to the cloud random number generator
cachedRandom& rndGen_;
Random& rndGen_;
//- Molecular free path length [m]
const scalar lambda_;

View File

@ -328,11 +328,11 @@ bool Foam::edgeIntersections::rotatePerturb
const edge& e = surf1.edges()[edgeI];
// Endpoint to modify. Choose either start or end.
label pointi = e[rndGen.bit()];
label pointi = e[rndGen.sampleAB<label>(0, 2)];
// label pointi = e[0];
// Generate random vector slightly larger than tolerance.
vector rndVec = rndGen.vector01() - vector(0.5, 0.5, 0.5);
vector rndVec = rndGen.sample01<vector>() - vector(0.5, 0.5, 0.5);
// Make sure rndVec only perp to edge
vector n(points1[meshPoints[e[1]]] - points1[meshPoints[e[0]]]);

View File

@ -216,7 +216,7 @@ void Foam::pointToPointPlanarInterpolation::calcWeights
{
localVertices[i] +=
perturb_
*(rndGen.position(bb.min(), bb.max())-bbMid);
*(rndGen.sampleAB<vector>(bb.min(), bb.max()) - bbMid);
}
// Determine triangulation

View File

@ -40,9 +40,9 @@ complexVector UOprocess::WeinerProcess()
{
return RootDeltaT*complexVector
(
complex(GaussGen.GaussNormal(), GaussGen.GaussNormal()),
complex(GaussGen.GaussNormal(), GaussGen.GaussNormal()),
complex(GaussGen.GaussNormal(), GaussGen.GaussNormal())
complex(GaussGen.scalarNormal(), GaussGen.scalarNormal()),
complex(GaussGen.scalarNormal(), GaussGen.scalarNormal()),
complex(GaussGen.scalarNormal(), GaussGen.scalarNormal())
);
}

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
@ -51,7 +51,7 @@ Foam::vectorField Foam::turbGen::U()
forAll(K, i)
{
s[i] = RanGen.vector01();
s[i] = RanGen.sample01<vector>();
rndPhases[i] = RanGen.scalar01();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -50,7 +50,7 @@ distributionContactAngleForce::distributionContactAngleForce
)
:
contactAngleForce(typeName, film, dict),
rndGen_(label(0), -1),
rndGen_(label(0)),
distribution_
(
distributionModel::New

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -41,7 +41,7 @@ SourceFiles
#include "contactAngleForce.H"
#include "distributionModel.H"
#include "cachedRandom.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,7 +63,7 @@ class distributionContactAngleForce
// Private Data
//- Random number generator
cachedRandom rndGen_;
Random rndGen_;
//- Parcel size PDF model
const autoPtr<distributionModel> distribution_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -57,7 +57,7 @@ perturbedTemperatureDependentContactAngleForce
:
contactAngleForce(typeName, film, dict),
thetaPtr_(Function1<scalar>::New("theta", coeffDict_)),
rndGen_(label(0), -1),
rndGen_(label(0)),
distribution_
(
distributionModel::New

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -51,7 +51,7 @@ SourceFiles
#include "contactAngleForce.H"
#include "Function1.H"
#include "distributionModel.H"
#include "cachedRandom.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -76,7 +76,7 @@ class perturbedTemperatureDependentContactAngleForce
autoPtr<Function1<scalar>> thetaPtr_;
//- Random number generator
cachedRandom rndGen_;
Random rndGen_;
//- Parcel size PDF model
const autoPtr<distributionModel> distribution_;

View File

@ -57,7 +57,7 @@ drippingInjection::drippingInjection
injectionModel(type(), film, dict),
deltaStable_(readScalar(coeffDict_.lookup("deltaStable"))),
particlesPerParcel_(readScalar(coeffDict_.lookup("particlesPerParcel"))),
rndGen_(label(0), -1),
rndGen_(label(0)),
parcelDistribution_
(
distributionModel::New

View File

@ -42,7 +42,7 @@ SourceFiles
#include "injectionModel.H"
#include "distributionModel.H"
#include "cachedRandom.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -84,7 +84,7 @@ protected:
scalar particlesPerParcel_;
//- Random number generator
cachedRandom rndGen_;
Random rndGen_;
//- Parcel size PDF model
const autoPtr<distributionModel>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -65,7 +65,7 @@ Foam::labelList Foam::randomRenumber::renumber
{
forAll(newToOld, i)
{
label j = rndGen.integer(0, newToOld.size()-1);
label j = rndGen.sampleAB<label>(0, newToOld.size());
Swap(newToOld[i], newToOld[j]);
}
}

View File

@ -102,7 +102,7 @@ void Foam::patchSeedSet::calcSamples
{
forAll(subset, i)
{
label j = rndGen.integer(0, subset.size()-1);
label j = rndGen.sampleAB<label>(0, subset.size());
Swap(subset[i], subset[j]);
}
}