https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static 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 (const RandomInterface &object, const Moose::Kokkos::FunctorCopy &key)
 Special constructor used for Kokkos functor copy during parallel dispatch.
 
 ~RandomInterface ()
 
void setRandomResetFrequency (ExecFlagType exec_flag)
 This interface should be called from a derived class to enable random number generation in this object.
 
unsigned long getRandomLong () const
 Returns the next random number (long) from the generator tied to this object (elem/node).
 
Real getRandomReal () const
 Returns the next random number (Real) from the generator tied to this object (elem/node).
 
unsigned int getSeed (std::size_t id)
 Get the seed for the passed in elem/node id.
 
unsigned int getMasterSeed () const
 
bool isNodal () const
 
ExecFlagType getResetOnTime () const
 
void setRandomDataPointer (RandomData *random_data)
 

Static Public Member Functions

static InputParameters validParams ()
 

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 *const & _curr_node
 
const Elem *const & _curr_element
 

Detailed Description

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

Definition at line 28 of file RandomInterface.h.

Constructor & Destructor Documentation

◆ RandomInterface() [1/2]

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.getObjectName()),
36 _master_seed(parameters.get<unsigned int>("seed")),
37 _is_nodal(is_nodal),
39 _curr_node(problem.assembly(tid, 0).node()),
40 _curr_element(problem.assembly(tid, 0).elem())
41{
42}
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
const Elem *const & elem() const
Return the current element.
Definition Assembly.h:414
const Node *const & node() const
Returns the reference to the node.
Definition Assembly.h:545
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const std::string & getObjectName() const
const Elem *const & _curr_element
RandomData * _random_data
const std::string _ri_name
MooseRandom * _generator
ExecFlagType _reset_on
unsigned int _master_seed
const Node *const & _curr_node
FEProblemBase & _ri_problem

◆ RandomInterface() [2/2]

RandomInterface::RandomInterface ( const RandomInterface object,
const Moose::Kokkos::FunctorCopy key 
)

Special constructor used for Kokkos functor copy during parallel dispatch.

Definition at line 45 of file RandomInterface.C.

46 : _random_data(object._random_data),
47 _generator(object._generator),
49 _ri_name(object._ri_name),
51 _is_nodal(object._is_nodal),
52 _reset_on(object._reset_on),
53 _curr_node(object._curr_node),
55{
56}

◆ ~RandomInterface()

RandomInterface::~RandomInterface ( )

Definition at line 59 of file RandomInterface.C.

59{}

Member Function Documentation

◆ getMasterSeed()

unsigned int RandomInterface::getMasterSeed ( ) const
inline

Definition at line 73 of file RandomInterface.h.

73{ return _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 84 of file RandomInterface.C.

85{
86 mooseAssert(_generator, "Random Generator is NULL, did you call setRandomResetFrequency()?");
87
88 dof_id_type id;
89 if (_is_nodal)
90 id = _curr_node->id();
91 else
92 id = _curr_element->id();
93
94 return _generator->randl(id);
95}
static uint32_t randl()
This method returns the next random number (long format) from the generator.
Definition MooseRandom.h:71
uint8_t dof_id_type

◆ getRandomReal()

Real RandomInterface::getRandomReal ( ) const

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

Definition at line 98 of file RandomInterface.C.

99{
100 mooseAssert(_generator, "Random Generator is NULL, did you call setRandomResetFrequency()?");
101
102 dof_id_type id;
103 if (_is_nodal)
104 id = _curr_node->id();
105 else
106 id = _curr_element->id();
107
108 return _generator->rand(id);
109}
static Real rand()
This method returns the next random number (Real format) from the generator.
Definition MooseRandom.h:50

◆ getResetOnTime()

ExecFlagType RandomInterface::getResetOnTime ( ) const
inline

Definition at line 75 of file RandomInterface.h.

75{ return _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 76 of file RandomInterface.C.

77{
78 mooseAssert(_random_data, "RandomData object is NULL!");
79
80 return _random_data->getSeed(id);
81}
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

◆ setRandomDataPointer()

void RandomInterface::setRandomDataPointer ( RandomData random_data)

Definition at line 69 of file RandomInterface.C.

70{
71 _random_data = random_data;
73}
MooseRandom & getGenerator()
Return the underlying MooseRandom generator object for this data instance.
Definition RandomData.h:41

Referenced by FEProblemBase::registerRandomInterface().

◆ 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 62 of file RandomInterface.C.

63{
64 _reset_on = exec_flag;
66}
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)

◆ validParams()

InputParameters RandomInterface::validParams ( )
static

Definition at line 18 of file RandomInterface.C.

19{
20
22 params.addParam<unsigned int>("seed", 0, "The seed for the master random number generator");
23
24 params.addParamNamesToGroup("seed", "Advanced");
25 return params;
26}
InputParameters emptyInputParameters()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.

Referenced by AuxKernelBase::validParams(), LinearSystemContributionObject::validParams(), ResidualObject::validParams(), MaterialBase::validParams(), DomainUserObject::validParams(), ElementUserObject::validParams(), and NodalUserObject::validParams().

Member Data Documentation

◆ _curr_element

const Elem* const& RandomInterface::_curr_element
private

Definition at line 91 of file RandomInterface.h.

Referenced by getRandomLong(), and getRandomReal().

◆ _curr_node

const Node* const& RandomInterface::_curr_node
private

Definition at line 90 of file RandomInterface.h.

Referenced by getRandomLong(), and getRandomReal().

◆ _generator

MooseRandom* RandomInterface::_generator
mutableprivate

Definition at line 81 of file RandomInterface.h.

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

◆ _is_nodal

bool RandomInterface::_is_nodal
private

Definition at line 87 of file RandomInterface.h.

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

◆ _master_seed

unsigned int RandomInterface::_master_seed
private

Definition at line 86 of file RandomInterface.h.

Referenced by getMasterSeed().

◆ _random_data

RandomData* RandomInterface::_random_data
private

Definition at line 80 of file RandomInterface.h.

Referenced by getSeed(), and setRandomDataPointer().

◆ _reset_on

ExecFlagType RandomInterface::_reset_on
private

Definition at line 88 of file RandomInterface.h.

Referenced by getResetOnTime(), and setRandomResetFrequency().

◆ _ri_name

const std::string RandomInterface::_ri_name
private

Definition at line 84 of file RandomInterface.h.

Referenced by setRandomResetFrequency().

◆ _ri_problem

FEProblemBase& RandomInterface::_ri_problem
private

Definition at line 83 of file RandomInterface.h.

Referenced by setRandomResetFrequency().


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