chombo-discharge
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. More...
 
 Random (const Random &&a_other)=delete
 Deleted copy constructor. Must be impossible because this is a singleton. More...
 
Randomoperator= (const Random &a_other)=delete
 Disallowed copy assignment. More...
 
Randomoperator= (const Random &&a_other)=delete
 Disallowed move assignment. More...
 

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. More...
 
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. More...
 
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. More...
 
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) More...
 
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) More...
 
static void seed ()
 Seed the RNG.
 
static void setSeed (const int a_seed)
 Set the RNG seed. More...
 
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);. More...
 
static RealVect randomPosition (const RealVect a_cellPos, const RealVect a_lo, const RealVect a_hi, const RealVect a_bndryCentroid, const RealVect a_normal, const Real a_dx, const Real a_kappa) noexcept
 Draw a random position physical somewhere in a grid cell. More...
 
static RealVect randomPosition (const RealVect a_lo, const RealVect a_hi, const RealVect a_bndryCentroid, const RealVect a_normal) noexcept
 Draw a random position somewhere in a cut-cell. More...
 

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

◆ 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

◆ getDirection()

RealVect Random::getDirection ( )
inlinestatic

Get a random direction in space.

Uses Marsaglia algorithm.

◆ 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

◆ 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)

◆ 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_normal,
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_normalEB normal (points into the fluid region)
[in]a_dxGrid resolution
[in]a_kappaCell volume

◆ 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

◆ randomPosition() [3/3]

RealVect Random::randomPosition ( const RealVect  a_lo,
const RealVect  a_hi,
const RealVect  a_bndryCentroid,
const RealVect  a_normal 
)
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_normalEB 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: