chombo-discharge
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Random Class Reference

Class for encapsulating random number generation. This class is MPI and OpenMP safe. More...

#include <CD_Random.H>

Public Member Functions

 Random ()=delete
 Disallowed constructor.
 
 Random (const Random &a_other)=delete
 Deleted copy constructor. Must be impossible because this is a singleton.
 
 Random (const Random &&a_other)=delete
 Deleted copy constructor. Must be impossible because this is a singleton.
 
Randomoperator= (const Random &a_other)=delete
 Disallowed copy assignment.
 
Randomoperator= (const Random &&a_other)=delete
 Disallowed move assignment.
 

Static Public Member Functions

template<typename T , typename = std::enable_if_t<std::is_integral<T>::value>>
static T getPoisson (const Real a_mean)
 Get Poisson distributed number.
 
template<typename T , typename = std::enable_if_t<std::is_integral<T>::value>>
static T getBinomial (const T a_N, const Real a_p) noexcept
 Get Poisson distributed number.
 
static Real getUniformReal01 ()
 Get a uniform real number on the interval [0,1].
 
static Real getUniformReal11 ()
 Get a uniform real number on the interval [-1,1].
 
static Real getNormal01 ()
 Get a number from a normal distribution centered on zero and variance 1.
 
static RealVect getDirection ()
 Get a random direction in space.
 
template<typename T >
static Real get (T &a_distribution)
 For getting a random number from a user-supplied distribution. T must be a distribution for which we can call T(s_rng)
 
template<typename T >
static size_t getDiscrete (T &a_distribution)
 For getting a random number from a user-supplied distribution. T must be a distribution for which we can call T(s_rng)
 
static void seed ()
 Seed the RNG.
 
static void setSeed (const int a_seed)
 Set the RNG seed.
 
static void setRandomSeed ()
 Set a random RNG seed.
 
static RealVect randomPosition (const RealVect &a_lo, const RealVect &a_hi) noexcept
 Return a random position in the cube (a_lo, a_hi);.
 
static RealVect randomPosition (const RealVect &a_cellPos, const RealVect &a_lo, const RealVect &a_hi, const RealVect &a_bndryCentroid, const RealVect &a_bndryNormal, const Real a_dx, const Real a_kappa) noexcept
 Draw a random position physical somewhere in a grid cell.
 
static RealVect randomPosition (const RealVect &a_lo, const RealVect &a_hi, const RealVect &a_bndryCentroid, const RealVect &a_bndryNormal) noexcept
 Draw a random position somewhere in a cut-cell.
 

Detailed Description

Class for encapsulating random number generation. This class is MPI and OpenMP safe.

The user can specify a seed 's' where each MPI rank will initialize their RNG with seed 's + procID()'. Note that unless the user specifies Random.seed = <number> in the input script, the RNG will use a seed of '0 + procID()' for the various ranks. If the user specifies a <number> less than 0, a random seed will be used.

Constructor & Destructor Documentation

◆ Random() [1/2]

Random::Random ( const Random a_other)
delete

Deleted copy constructor. Must be impossible because this is a singleton.

Parameters
[in]a_otherOther RNG engine.

◆ Random() [2/2]

Random::Random ( const Random &&  a_other)
delete

Deleted copy constructor. Must be impossible because this is a singleton.

Parameters
[in]a_otherOther RNG engine.

Member Function Documentation

◆ get()

template<typename T >
Real Random::get ( T a_distribution)
inlinestatic

For getting a random number from a user-supplied distribution. T must be a distribution for which we can call T(s_rng)

Parameters
[in]a_distributionDistribution. Must have object of type
Returns
Return value

◆ getBinomial()

template<typename T , typename >
T Random::getBinomial ( const T  a_N,
const Real  a_p 
)
inlinestaticnoexcept

Get Poisson distributed number.

Parameters
[in]a_NNumber of trials
[in]a_pThe usual success probability in binomial distributions
Returns
Binomial

◆ getDirection()

RealVect Random::getDirection ( )
inlinestatic

Get a random direction in space.

Uses Marsaglia algorithm.

Returns
Direction

◆ getDiscrete()

template<typename T >
size_t Random::getDiscrete ( T a_distribution)
inlinestatic

For getting a random number from a user-supplied distribution. T must be a distribution for which we can call T(s_rng)

Parameters
[in]a_distributionDistribution. Must have object of type
Returns
Discrete

◆ getNormal01()

Real Random::getNormal01 ( )
inlinestatic

Get a number from a normal distribution centered on zero and variance 1.

Returns
Normal01

◆ getPoisson()

template<typename T , typename >
T Random::getPoisson ( const Real  a_mean)
inlinestatic

Get Poisson distributed number.

Parameters
[in]a_meanPoisson mean value (inverse rate)
Returns
Poisson

◆ getUniformReal01()

Real Random::getUniformReal01 ( )
inlinestatic

Get a uniform real number on the interval [0,1].

Returns
Uniform real01

◆ getUniformReal11()

Real Random::getUniformReal11 ( )
inlinestatic

Get a uniform real number on the interval [-1,1].

Returns
Uniform real11

◆ operator=() [1/2]

Random & Random::operator= ( const Random &&  a_other)
delete

Disallowed move assignment.

Parameters
[in]a_otherOther RNG engine.

◆ operator=() [2/2]

Random & Random::operator= ( const Random a_other)
delete

Disallowed copy assignment.

Parameters
[in]a_otherOther RNG engine.

◆ randomPosition() [1/3]

RealVect Random::randomPosition ( const RealVect a_cellPos,
const RealVect a_lo,
const RealVect a_hi,
const RealVect a_bndryCentroid,
const RealVect a_bndryNormal,
const Real  a_dx,
const Real  a_kappa 
)
inlinestaticnoexcept

Draw a random position physical somewhere in a grid cell.

This is the version that respects cut-cells – it will draw a position (through rejection sampling) such that the particle ends up on the correct side of the EB.

Parameters
[in]a_cellPosCell-center position.
[in]a_loLower-left corner of volume that encloses the cut-cell. This is relative to the unit cell.
[in]a_hiUpper-right corner of volume that encloses the cut-cell. This is relative to the unit cell.
[in]a_bndryCentroidEB centroid position
[in]a_bndryNormalEB normal (points into the fluid region)
[in]a_dxGrid resolution
[in]a_kappaCell volume
Returns
Return value

◆ randomPosition() [2/3]

RealVect Random::randomPosition ( const RealVect a_lo,
const RealVect a_hi 
)
inlinestaticnoexcept

Return a random position in the cube (a_lo, a_hi);.

Parameters
[in]a_loLower-left corner
[in]a_hiUpper-right corner
Returns
Return value

◆ randomPosition() [3/3]

RealVect Random::randomPosition ( const RealVect a_lo,
const RealVect a_hi,
const RealVect a_bndryCentroid,
const RealVect a_bndryNormal 
)
inlinestaticnoexcept

Draw a random position somewhere in a cut-cell.

Parameters
[in]a_loLower-left corner of volume that encloses the cut-cell. This is relative to the unit cell.
[in]a_hiUpper-right corner of volume that encloses the cut-cell. This is relative to the unit cell.
[in]a_bndryCentroidEB centroid position
[in]a_bndryNormalEB normal (points into the fluid region)
Returns
Returns a position inside the cut-cell and on the correct side of the EB.

◆ setSeed()

void Random::setSeed ( const int  a_seed)
inlinestatic

Set the RNG seed.

If using MPI, the seed is set to a_seed + procID().

Parameters
[in]a_seedSeed to use for RNG.

The documentation for this class was generated from the following files: