www.mooseframework.org
RandomIC.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 "RandomIC.h"
16 #include "MooseRandom.h"
17 
18 #include "libmesh/point.h"
19 
20 template <>
23 {
25  params.addParam<Real>("min", 0.0, "Lower bound of the randomly generated values");
26  params.addParam<Real>("max", 1.0, "Upper bound of the randomly generated values");
27  params.addParam<unsigned int>("seed", 0, "Seed value for the random number generator");
28  return params;
29 }
30 
32  : InitialCondition(parameters),
33  _min(getParam<Real>("min")),
34  _max(getParam<Real>("max")),
35  _range(_max - _min)
36 {
37  mooseAssert(_range > 0.0, "Min > Max for RandomIC!");
38  MooseRandom::seed(getParam<unsigned int>("seed"));
39 }
40 
41 Real
42 RandomIC::value(const Point & /*p*/)
43 {
44  // Random number between 0 and 1
45  Real rand_num = MooseRandom::rand();
46 
47  // Between 0 and range
48  rand_num *= _range;
49 
50  // Between min and max
51  rand_num += _min;
52 
53  return rand_num;
54 }
static double rand()
This method returns the next random number (double format) from the generator.
Definition: MooseRandom.h:55
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< RandomIC >()
Definition: RandomIC.C:22
InitialConditions are objects that set the initial value of variables.
RandomIC(const InputParameters &parameters)
Constructor.
Definition: RandomIC.C:31
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: RandomIC.C:42
static void seed(unsigned int seed)
The method seeds the random number generator.
Definition: MooseRandom.h:49
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...
InputParameters validParams< InitialCondition >()
Real _range
Definition: RandomIC.h:55
Real _min
Definition: RandomIC.h:53