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;
101 <<
"Copy constructor called, but samples not being cached. " 102 <<
"This may lead to non-repeatable behaviour" <<
endl;
107 if (reset && samples_.
size())
132 return round(scalar01());
141 hasGaussSample_ =
false;
149 v1 = 2*scalar01() - 1;
150 v2 = 2*scalar01() - 1;
152 }
while (rsq >= 1 || rsq == 0);
154 scalar fac =
sqrt(-2*
log(rsq)/rsq);
156 gaussSample_ = v1*fac;
157 hasGaussSample_ =
true;
167 return round(GaussNormal<scalar>());
178 return start + scalar01()*(end - start);
185 return start + round(scalar01()*(end - start));
192 scalar value = -GREAT;
208 scalar value = -GREAT;
224 scalar value = -GREAT;
228 value = GaussNormal<scalar>();
240 scalar value = -GREAT;
244 value = GaussNormal<scalar>();
260 scalar value = -GREAT;
264 value = scalar01()*(end - start);
269 return start + value;
284 value = round(scalar01()*(end - start));
289 return start + value;
label seed() const
Return const access to the initial random number seed.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Inter-processor communication reduction functions.
dimensionedScalar log(const dimensionedScalar &ds)
cachedRandom(const label seed, const label count)
Construct given seed and sample count.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void size(const label)
Override size to be inconsistent with allocated storage.
scalar osRandomDouble()
Return random double precision (uniform distribution between 0 and 1)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool master(const label communicator=0)
Am I the master process.
Type globalPosition(const Type &start, const Type &end)
Return a sample between start and end.
Type GaussNormal()
Return a sample whose components are normally distributed.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
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))
Type sample01()
Return a sample whose components lie in the range 0-1.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
void setSize(const label)
Reset size of List.
Type globalGaussNormal()
Return a sample whose components are normally distributed.
#define WarningInFunction
Report a warning using Foam::Warning.
Type position(const Type &start, const Type &end)
Return a sample between start and end.
void osRandomSeed(const label seed)
Seed random number generator.
static const label labelMin
Type globalSample01()
Return a sample whose components lie in the range 0-1.