Random number generator. More...
Public Member Functions | |
cachedRandom (const label seed, const label count) | |
Construct given seed and sample count. More... | |
cachedRandom (const cachedRandom &cr, const bool reset=false) | |
Copy constructor with optional reset of sampleI. More... | |
~cachedRandom () | |
label | seed () const |
Return const access to the initial random number seed. More... | |
const scalarList & | samples () const |
Return const access to the list of samples. More... | |
label | sampleI () const |
Return the current sample marker. More... | |
label & | sampleI () |
Return non-const access to the sample marker. More... | |
template<class Type > | |
Type | sample01 () |
Return a sample whose components lie in the range 0-1. More... | |
template<class Type > | |
Type | GaussNormal () |
Return a sample whose components are normally distributed. More... | |
template<class Type > | |
Type | position (const Type &start, const Type &end) |
Return a sample between start and end. More... | |
template<class Type > | |
void | randomise01 (Type &value) |
Randomise value in the range 0-1. More... | |
template<class Type > | |
Type | globalSample01 () |
Return a sample whose components lie in the range 0-1. More... | |
template<class Type > | |
Type | globalGaussNormal () |
Return a sample whose components are normally distributed. More... | |
template<class Type > | |
Type | globalPosition (const Type &start, const Type &end) |
Return a sample between start and end. More... | |
template<class Type > | |
void | globalRandomise01 (Type &value) |
Randomise value in the range 0-1. More... | |
template<> | |
Foam::scalar | sample01 () |
template<> | |
Foam::scalar | GaussNormal () |
template<> | |
Foam::scalar | position (const scalar &start, const scalar &end) |
template<> | |
Foam::label | position (const label &start, const label &end) |
template<> | |
Foam::scalar | globalSample01 () |
template<> | |
Foam::scalar | globalGaussNormal () |
template<> | |
Foam::scalar | globalPosition (const scalar &start, const scalar &end) |
template<> | |
Foam::label | globalPosition (const label &start, const label &end) |
template<> | |
scalar | sample01 () |
template<> | |
label | sample01 () |
template<> | |
scalar | GaussNormal () |
template<> | |
label | GaussNormal () |
template<> | |
scalar | position (const scalar &start, const scalar &end) |
template<> | |
label | position (const label &start, const label &end) |
template<> | |
scalar | globalSample01 () |
template<> | |
label | globalSample01 () |
template<> | |
scalar | globalGaussNormal () |
template<> | |
label | globalGaussNormal () |
template<> | |
scalar | globalPosition (const scalar &start, const scalar &end) |
template<> | |
label | globalPosition (const label &start, const label &end) |
Private Member Functions | |
scalar | scalar01 () |
Returns the current sample. More... | |
Private Attributes | |
label | seed_ |
Initial random number seed. More... | |
scalarList | samples_ |
List of scalar samples. More... | |
label | sampleI_ |
Current sample marker. More... | |
bool | hasGaussSample_ |
Indicator, which tells if there is a stored gaussian sample. More... | |
scalar | gaussSample_ |
Stored sample value. More... | |
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.
Definition at line 63 of file cachedRandom.H.
cachedRandom | ( | const label | seed, |
const label | count | ||
) |
Construct given seed and sample count.
Definition at line 56 of file cachedRandom.C.
References forAll, Foam::osRandomDouble(), Foam::osRandomSeed(), cachedRandom::sampleI_, cachedRandom::samples_, cachedRandom::seed(), cachedRandom::seed_, and List::setSize().
cachedRandom | ( | const cachedRandom & | cr, |
const bool | reset = false |
||
) |
Copy constructor with optional reset of sampleI.
Definition at line 85 of file cachedRandom.C.
References Foam::endl(), cachedRandom::gaussSample_, cachedRandom::hasGaussSample_, Foam::osRandomSeed(), cachedRandom::sampleI_, cachedRandom::samples_, cachedRandom::seed_, List::size(), and WarningInFunction.
~cachedRandom | ( | ) |
Definition at line 116 of file cachedRandom.C.
|
private |
Returns the current sample.
Definition at line 32 of file cachedRandom.C.
References Foam::osRandomDouble(), s(), cachedRandom::sampleI_, cachedRandom::samples_, and List::size().
Referenced by edgeIntersections::inlinePerturb(), main(), edgeIntersections::offsetPerturb(), tetrahedron::randomPoint(), and cachedRandom::sample01().
|
inline |
Return const access to the initial random number seed.
Definition at line 30 of file cachedRandomI.H.
References cachedRandom::seed_.
Referenced by cachedRandom::cachedRandom().
|
inline |
Return const access to the list of samples.
Definition at line 36 of file cachedRandomI.H.
|
inline |
Return the current sample marker.
Definition at line 42 of file cachedRandomI.H.
|
inline |
Return non-const access to the sample marker.
Type sample01 |
Return a sample whose components lie in the range 0-1.
Definition at line 32 of file cachedRandomTemplates.C.
References cachedRandom::scalar01().
Referenced by ConeInjection< CloudType >::ConeInjection(), InflationInjection< CloudType >::parcelsToInject(), tetrahedron::randomPoint(), CellZoneInjection< CloudType >::setPositions(), ConeInjection< CloudType >::setProperties(), StochasticDispersionRAS< CloudType >::update(), and SHF< CloudType >::update().
Type GaussNormal |
Return a sample whose components are normally distributed.
with zero mean and unity variance N(0, 1)
Definition at line 45 of file cachedRandomTemplates.C.
Referenced by StochasticDispersionRAS< CloudType >::update(), and GradientDispersionRAS< CloudType >::update().
Type position | ( | const Type & | start, |
const Type & | end | ||
) |
Return a sample between start and end.
Definition at line 58 of file cachedRandomTemplates.C.
Referenced by InflationInjection< CloudType >::parcelsToInject(), patchInjectionBase::setPositionAndCell(), KinematicLookupTableInjection< CloudType >::setPositionAndCell(), ReactingLookupTableInjection< CloudType >::setPositionAndCell(), ThermoLookupTableInjection< CloudType >::setPositionAndCell(), ReactingMultiphaseLookupTableInjection< CloudType >::setPositionAndCell(), and ConeInjection< CloudType >::setProperties().
void randomise01 | ( | Type & | value | ) |
Randomise value in the range 0-1.
Definition at line 72 of file cachedRandomTemplates.C.
Type globalSample01 |
Return a sample whose components lie in the range 0-1.
Definition at line 79 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Type globalGaussNormal |
Return a sample whose components are normally distributed.
with zero mean and unity variance N(0, 1)
Definition at line 95 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Type globalPosition | ( | const Type & | start, |
const Type & | end | ||
) |
Return a sample between start and end.
Definition at line 111 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Referenced by PatchInjection< CloudType >::parcelsToInject().
void globalRandomise01 | ( | Type & | value | ) |
Randomise value in the range 0-1.
Definition at line 127 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Foam::label sample01 | ( | ) |
Definition at line 123 of file cachedRandom.C.
Foam::label GaussNormal | ( | ) |
Definition at line 137 of file cachedRandom.C.
References Foam::log(), Foam::sqr(), and Foam::sqrt().
Foam::scalar position | ( | const scalar & | start, |
const scalar & | end | ||
) |
Definition at line 173 of file cachedRandom.C.
Foam::label position | ( | const label & | start, |
const label & | end | ||
) |
Definition at line 183 of file cachedRandom.C.
Foam::label globalSample01 | ( | ) |
Definition at line 190 of file cachedRandom.C.
References UPstream::master(), and Pstream::scatter().
Foam::label globalGaussNormal | ( | ) |
Definition at line 222 of file cachedRandom.C.
References UPstream::master(), and Pstream::scatter().
Foam::scalar globalPosition | ( | const scalar & | start, |
const scalar & | end | ||
) |
Definition at line 255 of file cachedRandom.C.
References UPstream::master(), and Pstream::scatter().
Foam::label globalPosition | ( | const label & | start, |
const label & | end | ||
) |
Definition at line 275 of file cachedRandom.C.
References Foam::labelMin, UPstream::master(), and Pstream::scatter().
scalar sample01 | ( | ) |
label sample01 | ( | ) |
scalar GaussNormal | ( | ) |
label GaussNormal | ( | ) |
scalar position | ( | const scalar & | start, |
const scalar & | end | ||
) |
scalar globalSample01 | ( | ) |
label globalSample01 | ( | ) |
scalar globalGaussNormal | ( | ) |
label globalGaussNormal | ( | ) |
scalar globalPosition | ( | const scalar & | start, |
const scalar & | end | ||
) |
|
private |
Initial random number seed.
Definition at line 68 of file cachedRandom.H.
Referenced by cachedRandom::cachedRandom(), and cachedRandom::seed().
|
private |
List of scalar samples.
Definition at line 71 of file cachedRandom.H.
Referenced by cachedRandom::cachedRandom(), and cachedRandom::scalar01().
|
private |
Current sample marker.
Definition at line 74 of file cachedRandom.H.
Referenced by cachedRandom::cachedRandom(), and cachedRandom::scalar01().
|
private |
Indicator, which tells if there is a stored gaussian sample.
Definition at line 77 of file cachedRandom.H.
Referenced by cachedRandom::cachedRandom().
|
private |
Stored sample value.
Definition at line 80 of file cachedRandom.H.
Referenced by cachedRandom::cachedRandom().
Copyright © 2011-2018 OpenFOAM | OPENFOAM® is a registered trademark of OpenCFD Ltd.