www.mooseframework.org
Public Member Functions | Private Attributes | List of all members
RandomInterface Class Reference

Interface for objects that need parallel consistent random numbers without patterns over the course of multiple runs. More...

#include <RandomInterface.h>

Inheritance diagram for RandomInterface:
[legend]

Public Member Functions

 RandomInterface (const InputParameters &parameters, FEProblemBase &problem, THREAD_ID tid, bool is_nodal)
 
 ~RandomInterface ()
 
void setRandomResetFrequency (ExecFlagType exec_flag)
 This interface should be called from a derived class to enable random number generation in this object. More...
 
unsigned long getRandomLong () const
 Returns the next random number (long) from the generator tied to this object (elem/node). More...
 
Real getRandomReal () const
 Returns the next random number (Real) from the generator tied to this object (elem/node). More...
 
unsigned int getSeed (std::size_t id)
 Get the seed for the passed in elem/node id. More...
 
unsigned int getMasterSeed () const
 
bool isNodal () const
 
ExecFlagType getResetOnTime () const
 
void setRandomDataPointer (RandomData *random_data)
 

Private Attributes

RandomData_random_data
 
MooseRandom_generator
 
FEProblemBase_ri_problem
 
const std::string _ri_name
 
unsigned int _master_seed
 
bool _is_nodal
 
ExecFlagType _reset_on
 
const Node *& _curr_node
 
const Elem *& _curr_element
 

Detailed Description

Interface for objects that need parallel consistent random numbers without patterns over the course of multiple runs.

Definition at line 34 of file RandomInterface.h.

Constructor & Destructor Documentation

◆ RandomInterface()

RandomInterface::RandomInterface ( const InputParameters parameters,
FEProblemBase problem,
THREAD_ID  tid,
bool  is_nodal 
)

Definition at line 28 of file RandomInterface.C.

32  : _random_data(nullptr),
33  _generator(nullptr),
34  _ri_problem(problem),
35  _ri_name(parameters.get<std::string>("_object_name")),
36  _master_seed(parameters.get<unsigned int>("seed")),
37  _is_nodal(is_nodal),
39  _curr_node(problem.assembly(tid).node()),
40  _curr_element(problem.assembly(tid).elem())
41 {
42 }
const Node *& _curr_node
virtual Assembly & assembly(THREAD_ID tid) override
RandomData * _random_data
ExecFlagType _reset_on
const Elem *& _curr_element
const Node *& node()
Returns the reference to the node.
Definition: Assembly.h:350
const std::string _ri_name
const ExecFlagType EXEC_LINEAR
FEProblemBase & _ri_problem
const Elem *& elem()
Return the current element.
Definition: Assembly.h:270
unsigned int _master_seed
MooseRandom * _generator

◆ ~RandomInterface()

RandomInterface::~RandomInterface ( )

Definition at line 44 of file RandomInterface.C.

44 {}

Member Function Documentation

◆ getMasterSeed()

unsigned int RandomInterface::getMasterSeed ( ) const
inline

Definition at line 70 of file RandomInterface.h.

70 { return _master_seed; }
unsigned int _master_seed

◆ getRandomLong()

unsigned long RandomInterface::getRandomLong ( ) const

Returns the next random number (long) from the generator tied to this object (elem/node).

Definition at line 69 of file RandomInterface.C.

70 {
71  mooseAssert(_generator, "Random Generator is NULL, did you call setRandomResetFrequency()?");
72 
73  dof_id_type id;
74  if (_is_nodal)
75  id = _curr_node->id();
76  else
77  id = _curr_element->id();
78 
79  return _generator->randl(id);
80 }
static uint32_t randl()
This method returns the next random number (long format) from the generator.
Definition: MooseRandom.h:71
const Node *& _curr_node
const Elem *& _curr_element
MooseRandom * _generator

◆ getRandomReal()

Real RandomInterface::getRandomReal ( ) const

Returns the next random number (Real) from the generator tied to this object (elem/node).

Definition at line 83 of file RandomInterface.C.

84 {
85  mooseAssert(_generator, "Random Generator is NULL, did you call setRandomResetFrequency()?");
86 
87  dof_id_type id;
88  if (_is_nodal)
89  id = _curr_node->id();
90  else
91  id = _curr_element->id();
92 
93  return _generator->rand(id);
94 }
static double rand()
This method returns the next random number (double format) from the generator.
Definition: MooseRandom.h:50
const Node *& _curr_node
const Elem *& _curr_element
MooseRandom * _generator

◆ getResetOnTime()

ExecFlagType RandomInterface::getResetOnTime ( ) const
inline

Definition at line 72 of file RandomInterface.h.

72 { return _reset_on; }
ExecFlagType _reset_on

◆ getSeed()

unsigned int RandomInterface::getSeed ( std::size_t  id)

Get the seed for the passed in elem/node id.

Parameters
id- dof object id
Returns
current seed for this id

Definition at line 61 of file RandomInterface.C.

62 {
63  mooseAssert(_random_data, "RandomData object is NULL!");
64 
65  return _random_data->getSeed(id);
66 }
RandomData * _random_data
unsigned int getSeed(dof_id_type id)
Get the seed for the passed in elem/node id.
Definition: RandomData.C:40

◆ isNodal()

bool RandomInterface::isNodal ( ) const
inline

Definition at line 71 of file RandomInterface.h.

71 { return _is_nodal; }

◆ setRandomDataPointer()

void RandomInterface::setRandomDataPointer ( RandomData random_data)

Definition at line 54 of file RandomInterface.C.

Referenced by FEProblemBase::registerRandomInterface().

55 {
56  _random_data = random_data;
58 }
RandomData * _random_data
MooseRandom * _generator
MooseRandom & getGenerator()
Return the underlying MooseRandom generator object for this data instance.
Definition: RandomData.h:42

◆ setRandomResetFrequency()

void RandomInterface::setRandomResetFrequency ( ExecFlagType  exec_flag)

This interface should be called from a derived class to enable random number generation in this object.

Definition at line 47 of file RandomInterface.C.

48 {
49  _reset_on = exec_flag;
51 }
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)
ExecFlagType _reset_on
const std::string _ri_name
FEProblemBase & _ri_problem

Member Data Documentation

◆ _curr_element

const Elem*& RandomInterface::_curr_element
private

Definition at line 88 of file RandomInterface.h.

Referenced by getRandomLong(), and getRandomReal().

◆ _curr_node

const Node*& RandomInterface::_curr_node
private

Definition at line 87 of file RandomInterface.h.

Referenced by getRandomLong(), and getRandomReal().

◆ _generator

MooseRandom* RandomInterface::_generator
mutableprivate

Definition at line 78 of file RandomInterface.h.

Referenced by getRandomLong(), getRandomReal(), and setRandomDataPointer().

◆ _is_nodal

bool RandomInterface::_is_nodal
private

Definition at line 84 of file RandomInterface.h.

Referenced by getRandomLong(), getRandomReal(), and isNodal().

◆ _master_seed

unsigned int RandomInterface::_master_seed
private

Definition at line 83 of file RandomInterface.h.

Referenced by getMasterSeed().

◆ _random_data

RandomData* RandomInterface::_random_data
private

Definition at line 77 of file RandomInterface.h.

Referenced by getSeed(), and setRandomDataPointer().

◆ _reset_on

ExecFlagType RandomInterface::_reset_on
private

Definition at line 85 of file RandomInterface.h.

Referenced by getResetOnTime(), and setRandomResetFrequency().

◆ _ri_name

const std::string RandomInterface::_ri_name
private

Definition at line 81 of file RandomInterface.h.

Referenced by setRandomResetFrequency().

◆ _ri_problem

FEProblemBase& RandomInterface::_ri_problem
private

Definition at line 80 of file RandomInterface.h.

Referenced by setRandomResetFrequency().


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