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 (unsigned int 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 38 of file RandomInterface.h.

Constructor & Destructor Documentation

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

Definition at line 33 of file RandomInterface.C.

37  : _random_data(NULL),
38  _generator(NULL),
39  _ri_problem(problem),
40  _ri_name(parameters.get<std::string>("_object_name")),
41  _master_seed(parameters.get<unsigned int>("seed")),
42  _is_nodal(is_nodal),
44  _curr_node(problem.assembly(tid).node()),
45  _curr_element(problem.assembly(tid).elem())
46 {
47 }
Object is evaluated in every residual computation.
Definition: MooseTypes.h:96
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:269
const std::string _ri_name
FEProblemBase & _ri_problem
const Elem *& elem()
Return the current element.
Definition: Assembly.h:189
unsigned int _master_seed
MooseRandom * _generator
RandomInterface::~RandomInterface ( )

Definition at line 49 of file RandomInterface.C.

49 {}

Member Function Documentation

unsigned int RandomInterface::getMasterSeed ( ) const
inline

Definition at line 74 of file RandomInterface.h.

74 { return _master_seed; }
unsigned int _master_seed
unsigned long RandomInterface::getRandomLong ( ) const

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

Definition at line 74 of file RandomInterface.C.

75 {
76  mooseAssert(_generator, "Random Generator is NULL, did you call setRandomResetFrequency()?");
77 
78  dof_id_type id;
79  if (_is_nodal)
80  id = _curr_node->id();
81  else
82  id = _curr_element->id();
83 
84  return _generator->randl(static_cast<unsigned int>(id));
85 }
static uint32_t randl()
This method returns the next random number (long format) from the generator.
Definition: MooseRandom.h:76
const Node *& _curr_node
const Elem *& _curr_element
MooseRandom * _generator
Real RandomInterface::getRandomReal ( ) const

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

Definition at line 88 of file RandomInterface.C.

89 {
90  mooseAssert(_generator, "Random Generator is NULL, did you call setRandomResetFrequency()?");
91 
92  dof_id_type id;
93  if (_is_nodal)
94  id = _curr_node->id();
95  else
96  id = _curr_element->id();
97 
98  return _generator->rand(static_cast<unsigned int>(id));
99 }
static double rand()
This method returns the next random number (double format) from the generator.
Definition: MooseRandom.h:55
const Node *& _curr_node
const Elem *& _curr_element
MooseRandom * _generator
ExecFlagType RandomInterface::getResetOnTime ( ) const
inline

Definition at line 76 of file RandomInterface.h.

76 { return _reset_on; }
ExecFlagType _reset_on
unsigned int RandomInterface::getSeed ( unsigned int  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 66 of file RandomInterface.C.

67 {
68  mooseAssert(_random_data, "RandomData object is NULL!");
69 
70  return _random_data->getSeed(id);
71 }
RandomData * _random_data
unsigned int getSeed(dof_id_type id)
Get the seed for the passed in elem/node id.
Definition: RandomData.C:34
bool RandomInterface::isNodal ( ) const
inline

Definition at line 75 of file RandomInterface.h.

75 { return _is_nodal; }
void RandomInterface::setRandomDataPointer ( RandomData random_data)

Definition at line 59 of file RandomInterface.C.

Referenced by getResetOnTime(), and FEProblemBase::registerRandomInterface().

60 {
61  _random_data = random_data;
63 }
RandomData * _random_data
MooseRandom * _generator
MooseRandom & getGenerator()
Return the underlying MooseRandom generator object for this data instance.
Definition: RandomData.h:42
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 52 of file RandomInterface.C.

53 {
54  _reset_on = exec_flag;
56 }
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)
ExecFlagType _reset_on
const std::string _ri_name
FEProblemBase & _ri_problem

Member Data Documentation

const Elem*& RandomInterface::_curr_element
private

Definition at line 92 of file RandomInterface.h.

Referenced by getRandomLong(), and getRandomReal().

const Node*& RandomInterface::_curr_node
private

Definition at line 91 of file RandomInterface.h.

Referenced by getRandomLong(), and getRandomReal().

MooseRandom* RandomInterface::_generator
mutableprivate

Definition at line 82 of file RandomInterface.h.

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

bool RandomInterface::_is_nodal
private

Definition at line 88 of file RandomInterface.h.

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

unsigned int RandomInterface::_master_seed
private

Definition at line 87 of file RandomInterface.h.

Referenced by getMasterSeed().

RandomData* RandomInterface::_random_data
private

Definition at line 81 of file RandomInterface.h.

Referenced by getSeed(), and setRandomDataPointer().

ExecFlagType RandomInterface::_reset_on
private

Definition at line 89 of file RandomInterface.h.

Referenced by getResetOnTime(), and setRandomResetFrequency().

const std::string RandomInterface::_ri_name
private

Definition at line 85 of file RandomInterface.h.

Referenced by setRandomResetFrequency().

FEProblemBase& RandomInterface::_ri_problem
private

Definition at line 84 of file RandomInterface.h.

Referenced by setRandomResetFrequency().


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