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 
17 template <>
20 {
23  params.addParam<Real>(
24  "min", 0.0, "Lower bound of uniformly distributed randomly generated values");
25  params.addParam<Real>(
26  "max", 1.0, "Upper bound of uniformly distributed randomly generated values");
27  params.addParam<DistributionName>(
28  "distribution", "Name of distribution defining distribution of randomly generated values");
29 
30  params.addClassDescription("Initialize a variable with randomly generated numbers following "
31  "either a uniform distribution or a user-defined distribution");
32  return params;
33 }
34 
36  : RandomICBase(parameters),
38  _min(getParam<Real>("min")),
39  _max(getParam<Real>("max")),
40  _distribution(nullptr)
41 {
42  if (_min >= _max)
43  paramError("min", "Min >= Max for RandomIC!");
44 
45  if (parameters.isParamSetByUser("distribution"))
46  {
47  _distribution = &getDistributionByName(getParam<DistributionName>("distribution"));
49  paramError("distribution", "Cannot use together with 'min' or 'max' parameter");
50  }
51 }
52 
53 Real
54 RandomIC::value(const Point & /*p*/)
55 {
56  if (_distribution)
58  else
59  return generateRandom() * (_max - _min) + _min;
60 }
registerMooseObject("MooseApp", RandomIC)
Real generateRandom()
Generate a uniformly distributed random number on the interval from 0 to 1.
Definition: RandomICBase.C:91
const Real _max
The upper bound of the random number range.
Definition: RandomIC.h:49
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< RandomIC >()
Definition: RandomIC.C:19
RandomIC(const InputParameters &parameters)
Constructor.
Definition: RandomIC.C:35
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: RandomIC.C:54
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
Interface for objects that need to use distributions.
RandomIC just returns a Random value.
Definition: RandomIC.h:33
InputParameters validParams< RandomICBase >()
Definition: RandomICBase.C:35
Distribution const * _distribution
Distribution object optionally used to define distribution of random numbers.
Definition: RandomIC.h:52
void paramError(const std::string &param, Args... args)
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseObject.h:108
InputParameters validParams< DistributionInterface >()
const Real _min
The lower bound of the random number range.
Definition: RandomIC.h:46
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.
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.
Base class for randomly generated initial conditions.
Definition: RandomICBase.h:33