Random: clean-up

This commit is contained in:
Henry 2015-03-13 09:52:13 +00:00
parent ec41a4cc7e
commit 211bb0531a

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -28,21 +28,15 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#if INT_MAX != 2147483647 #if INT_MAX != 2147483647
# error "INT_MAX != 2147483647" # error "INT_MAX != 2147483647"
# error "The random number generator may not work!" # error "The random number generator may not work!"
#endif #endif
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Random::Random(const label seed) Foam::Random::Random(const label seed)
{ {
if (seed > 1) if (seed > 1)
{ {
@ -57,7 +51,7 @@ Random::Random(const label seed)
} }
int Random::bit() int Foam::Random::bit()
{ {
if (osRandomInteger() > INT_MAX/2) if (osRandomInteger() > INT_MAX/2)
{ {
@ -70,13 +64,13 @@ int Random::bit()
} }
scalar Random::scalar01() Foam::scalar Foam::Random::scalar01()
{ {
return osRandomDouble(); return osRandomDouble();
} }
vector Random::vector01() Foam::vector Foam::Random::vector01()
{ {
vector rndVec; vector rndVec;
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++) for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
@ -88,7 +82,7 @@ vector Random::vector01()
} }
sphericalTensor Random::sphericalTensor01() Foam::sphericalTensor Foam::Random::sphericalTensor01()
{ {
sphericalTensor rndTen; sphericalTensor rndTen;
rndTen.ii() = scalar01(); rndTen.ii() = scalar01();
@ -97,7 +91,7 @@ sphericalTensor Random::sphericalTensor01()
} }
symmTensor Random::symmTensor01() Foam::symmTensor Foam::Random::symmTensor01()
{ {
symmTensor rndTen; symmTensor rndTen;
for (direction cmpt=0; cmpt<symmTensor::nComponents; cmpt++) for (direction cmpt=0; cmpt<symmTensor::nComponents; cmpt++)
@ -109,7 +103,7 @@ symmTensor Random::symmTensor01()
} }
tensor Random::tensor01() Foam::tensor Foam::Random::tensor01()
{ {
tensor rndTen; tensor rndTen;
for (direction cmpt=0; cmpt<tensor::nComponents; cmpt++) for (direction cmpt=0; cmpt<tensor::nComponents; cmpt++)
@ -121,13 +115,13 @@ tensor Random::tensor01()
} }
label Random::integer(const label lower, const label upper) Foam::label Foam::Random::integer(const label lower, const label upper)
{ {
return lower + (osRandomInteger() % (upper+1-lower)); return lower + (osRandomInteger() % (upper+1-lower));
} }
vector Random::position(const vector& start, const vector& end) Foam::vector Foam::Random::position(const vector& start, const vector& end)
{ {
vector rndVec(start); vector rndVec(start);
@ -141,40 +135,37 @@ vector Random::position(const vector& start, const vector& end)
} }
void Random::randomise(scalar& s) void Foam::Random::randomise(scalar& s)
{ {
s = scalar01(); s = scalar01();
} }
void Random::randomise(vector& v) void Foam::Random::randomise(vector& v)
{ {
v = vector01(); v = vector01();
} }
void Random::randomise(sphericalTensor& st) void Foam::Random::randomise(sphericalTensor& st)
{ {
st = sphericalTensor01(); st = sphericalTensor01();
} }
void Random::randomise(symmTensor& st) void Foam::Random::randomise(symmTensor& st)
{ {
st = symmTensor01(); st = symmTensor01();
} }
void Random::randomise(tensor& t) void Foam::Random::randomise(tensor& t)
{ {
t = tensor01(); t = tensor01();
} }
// return a normal Gaussian randon number Foam::scalar Foam::Random::GaussNormal()
// with zero mean and unity variance N(0, 1)
scalar Random::GaussNormal()
{ {
static int iset = 0; static int iset = 0;
static scalar gset; static scalar gset;
@ -204,8 +195,4 @@ scalar Random::GaussNormal()
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //