https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.getObjectName()),
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
44#ifdef MOOSE_KOKKOS_ENABLED
46 : _random_data(object._random_data),
47 _generator(object._generator),
48 _ri_problem(object._ri_problem),
49 _ri_name(object._ri_name),
50 _master_seed(object._master_seed),
51 _is_nodal(object._is_nodal),
52 _reset_on(object._reset_on),
53 _curr_node(object._curr_node),
54 _curr_element(object._curr_element)
55{
56}
57#endif
58
60
61void
67
68void
74
75unsigned int
77{
78 mooseAssert(_random_data, "RandomData object is NULL!");
79
80 return _random_data->getSeed(id);
81}
82
83unsigned long
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}
96
97Real
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}
InputParameters emptyInputParameters()
unsigned int THREAD_ID
Definition MooseTypes.h:237
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
void ErrorVector unsigned int
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)
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.
Class for containing MooseEnum item information.
static Real rand()
This method returns the next random number (Real format) from the generator.
Definition MooseRandom.h:50
static uint32_t randl()
This method returns the next random number (long format) from the generator.
Definition MooseRandom.h:71
MooseRandom & getGenerator()
Return the underlying MooseRandom generator object for this data instance.
Definition RandomData.h:41
unsigned int getSeed(dof_id_type id)
Get the seed for the passed in elem/node id.
Definition RandomData.C:40
Interface for objects that need parallel consistent random numbers without patterns over the course o...
const Elem *const & _curr_element
Real getRandomReal() const
Returns the next random number (Real) from the generator tied to this object (elem/node).
RandomInterface(const InputParameters &parameters, FEProblemBase &problem, THREAD_ID tid, bool is_nodal)
RandomData * _random_data
void setRandomResetFrequency(ExecFlagType exec_flag)
This interface should be called from a derived class to enable random number generation in this objec...
const std::string _ri_name
unsigned int getSeed(std::size_t id)
Get the seed for the passed in elem/node id.
MooseRandom * _generator
static InputParameters validParams()
unsigned long getRandomLong() const
Returns the next random number (long) from the generator tied to this object (elem/node).
ExecFlagType _reset_on
const Node *const & _curr_node
FEProblemBase & _ri_problem
void setRandomDataPointer(RandomData *random_data)