32 Foam::scalar Foam::cachedRandom::scalar01()
39 if (sampleI_ == samples_.
size() - 1)
41 scalar
s = samples_[sampleI_];
47 scalar
s = samples_[sampleI_];
61 hasGaussSample_(false),
88 samples_(cr.samples_),
89 sampleI_(cr.sampleI_),
90 hasGaussSample_(cr.hasGaussSample_),
91 gaussSample_(cr.gaussSample_)
95 hasGaussSample_ =
false;
102 "Foam::cachedRandom::cachedRandom(const cachedRandom& cr)" 103 ) <<
"Copy constructor called, but samples not being cached. " 104 <<
"This may lead to non-repeatable behaviour" <<
endl;
109 if (reset && samples_.
size())
134 return round(scalar01());
143 hasGaussSample_ =
false;
151 v1 = 2*scalar01() - 1;
152 v2 = 2*scalar01() - 1;
154 }
while (rsq >= 1 || rsq == 0);
156 scalar fac =
sqrt(-2*
log(rsq)/rsq);
158 gaussSample_ = v1*fac;
159 hasGaussSample_ =
true;
169 return round(GaussNormal<scalar>());
180 return start + scalar01()*(end - start);
187 return start + round(scalar01()*(end - start));
194 scalar value = -GREAT;
210 scalar value = -GREAT;
226 scalar value = -GREAT;
230 value = GaussNormal<scalar>();
242 scalar value = -GREAT;
246 value = GaussNormal<scalar>();
262 scalar value = -GREAT;
266 value = scalar01()*(end - start);
271 return start + value;
286 value = round(scalar01()*(end - start));
291 return start + value;
dimensionedScalar sqrt(const dimensionedScalar &ds)
Type globalSample01()
Return a sample whose components lie in the range 0-1.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject( name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE ))
scalar osRandomDouble()
Return random double precision (uniform distribution between 0 and 1)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Type globalPosition(const Type &start, const Type &end)
Return a sample between start and end.
void size(const label)
Override size to be inconsistent with allocated storage.
dimensionedScalar log(const dimensionedScalar &ds)
void setSize(const label)
Reset size of List.
Ostream & endl(Ostream &os)
Add newline and flush stream.
#define WarningIn(functionName)
Report a warning using Foam::Warning.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
static const label labelMin
void osRandomSeed(const label seed)
Seed random number generator.
Type sample01()
Return a sample whose components lie in the range 0-1.
static bool master(const label communicator=0)
Am I the master process.
label seed() const
Return const access to the initial random number seed.
Type position(const Type &start, const Type &end)
Return a sample between start and end.
Type globalGaussNormal()
Return a sample whose components are normally distributed.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Type GaussNormal()
Return a sample whose components are normally distributed.
cachedRandom(const label seed, const label count)
Construct given seed and sample count.