www.mooseframework.org
RandomInterface.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "Moose.h"
16 #include "RandomInterface.h"
17 #include "Assembly.h"
18 #include "RandomData.h"
19 #include "MooseRandom.h"
20 #include "FEProblemBase.h"
21 
22 template <>
25 {
27  params.addParam<unsigned int>("seed", 0, "The seed for the master random number generator");
28 
29  params.addParamNamesToGroup("seed", "Advanced");
30  return params;
31 }
32 
34  FEProblemBase & problem,
35  THREAD_ID tid,
36  bool is_nodal)
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),
43  _reset_on(EXEC_LINEAR),
44  _curr_node(problem.assembly(tid).node()),
45  _curr_element(problem.assembly(tid).elem())
46 {
47 }
48 
50 
51 void
53 {
54  _reset_on = exec_flag;
56 }
57 
58 void
60 {
61  _random_data = random_data;
63 }
64 
65 unsigned int
66 RandomInterface::getSeed(unsigned int id)
67 {
68  mooseAssert(_random_data, "RandomData object is NULL!");
69 
70  return _random_data->getSeed(id);
71 }
72 
73 unsigned long
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 }
86 
87 Real
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 }
Object is evaluated in every residual computation.
Definition: MooseTypes.h:96
Real getRandomReal() const
Returns the next random number (Real) from the generator tied to this object (elem/node).
static uint32_t randl()
This method returns the next random number (long format) from the generator.
Definition: MooseRandom.h:76
static double rand()
This method returns the next random number (double format) from the generator.
Definition: MooseRandom.h:55
RandomInterface(const InputParameters &parameters, FEProblemBase &problem, THREAD_ID tid, bool is_nodal)
const Node *& _curr_node
RandomData * _random_data
unsigned int getSeed(unsigned int id)
Get the seed for the passed in elem/node id.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)
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()
unsigned long getRandomLong() const
Returns the next random number (long) from the generator tied to this object (elem/node).
const Elem *& _curr_element
InputParameters validParams< RandomInterface >()
const std::string _ri_name
FEProblemBase & _ri_problem
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:34
MooseRandom * _generator
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
MooseRandom & getGenerator()
Return the underlying MooseRandom generator object for this data instance.
Definition: RandomData.h:42
unsigned int THREAD_ID
Definition: MooseTypes.h:79
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...