www.mooseframework.org
RandomIC.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "RandomIC.h"
11 
12 #include "libmesh/point.h"
13 #include "Distribution.h"
14 
15 registerMooseObject("MooseApp", RandomIC);
16 
19 {
22  params.addParam<Real>(
23  "min", 0.0, "Lower bound of uniformly distributed randomly generated values");
24  params.addParam<Real>(
25  "max", 1.0, "Upper bound of uniformly distributed randomly generated values");
26  params.addParam<DistributionName>(
27  "distribution", "Name of distribution defining distribution of randomly generated values");
28 
29  params.addClassDescription("Initialize a variable with randomly generated numbers following "
30  "either a uniform distribution or a user-defined distribution");
31  return params;
32 }
33 
35  : RandomICBase(parameters),
37  _min(getParam<Real>("min")),
38  _max(getParam<Real>("max")),
39  _distribution(nullptr)
40 {
41  if (_min >= _max)
42  paramError("min", "Min >= Max for RandomIC!");
43 
44  if (parameters.isParamSetByUser("distribution"))
45  {
46  _distribution = &getDistributionByName(getParam<DistributionName>("distribution"));
48  paramError("distribution", "Cannot use together with 'min' or 'max' parameter");
49  }
50 }
51 
52 Real
53 RandomIC::value(const Point & /*p*/)
54 {
55  if (_distribution)
57  else
58  return generateRandom() * (_max - _min) + _min;
59 }
registerMooseObject("MooseApp", RandomIC)
Real generateRandom()
Generate a uniformly distributed random number on the interval from 0 to 1.
Definition: RandomICBase.C:90
const Real _max
The upper bound of the random number range.
Definition: RandomIC.h:47
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
RandomIC(const InputParameters &parameters)
Constructor.
Definition: RandomIC.C:34
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: RandomIC.C:53
Interface for objects that need to use distributions.
RandomIC just returns a Random value.
Definition: RandomIC.h:29
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Distribution const * _distribution
Distribution object optionally used to define distribution of random numbers.
Definition: RandomIC.h:50
const Real _min
The lower bound of the random number range.
Definition: RandomIC.h:44
const Distribution & getDistributionByName(const DistributionName &name) const
Get a distribution with a given name.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
Definition: RandomIC.C:18
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const InputParameters & parameters() const
Get the parameters of the object.
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...
virtual Real quantile(const Real &y) const =0
Compute the inverse CDF (quantile function) value for given variable value y.
static InputParameters validParams()
Definition: RandomICBase.C:34
Base class for randomly generated initial conditions.
Definition: RandomICBase.h:29