https://mooseframework.inl.gov
RandomInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "Moose.h"
11 #include "RandomInterface.h"
12 #include "RandomData.h"
13 #include "MooseRandom.h"
14 #include "FEProblemBase.h"
15 #include "Assembly.h"
16 
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 }
27 
29  FEProblemBase & problem,
30  THREAD_ID tid,
31  bool is_nodal)
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),
38  _reset_on(EXEC_LINEAR),
39  _curr_node(problem.assembly(tid, 0).node()),
40  _curr_element(problem.assembly(tid, 0).elem())
41 {
42 }
43 
45 
46 void
48 {
49  _reset_on = exec_flag;
51 }
52 
53 void
55 {
56  _random_data = random_data;
58 }
59 
60 unsigned int
61 RandomInterface::getSeed(std::size_t id)
62 {
63  mooseAssert(_random_data, "RandomData object is NULL!");
64 
65  return _random_data->getSeed(id);
66 }
67 
68 unsigned long
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 }
81 
82 Real
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 uint32_t randl()
This method returns the next random number (long format) from the generator.
Definition: MooseRandom.h:71
unsigned long getRandomLong() const
Returns the next random number (long) from the generator tied to this object (elem/node).
RandomInterface(const InputParameters &parameters, FEProblemBase &problem, THREAD_ID tid, bool is_nodal)
const Node *const & _curr_node
RandomData * _random_data
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)
unsigned int getSeed(std::size_t id)
Get the seed for the passed in elem/node id.
void setRandomResetFrequency(ExecFlagType exec_flag)
This interface should be called from a derived class to enable random number generation in this objec...
ExecFlagType _reset_on
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
InputParameters emptyInputParameters()
const std::string _ri_name
static InputParameters validParams()
const Elem *const & _curr_element
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:29
FEProblemBase & _ri_problem
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
void setRandomDataPointer(RandomData *random_data)
unsigned int getSeed(dof_id_type id)
Get the seed for the passed in elem/node id.
Definition: RandomData.C:40
static Real rand()
This method returns the next random number (Real format) from the generator.
Definition: MooseRandom.h:50
MooseRandom * _generator
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...
MooseRandom & getGenerator()
Return the underlying MooseRandom generator object for this data instance.
Definition: RandomData.h:41
void ErrorVector unsigned int
Real getRandomReal() const
Returns the next random number (Real) from the generator tied to this object (elem/node).
unsigned int THREAD_ID
Definition: MooseTypes.h:209
uint8_t dof_id_type
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...