Loading [MathJax]/extensions/tex2jax.js
www.mooseframework.org
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 
18 
21 {
24  params.addParam<Real>(
25  "min", 0.0, "Lower bound of uniformly distributed randomly generated values");
26  params.addParam<Real>(
27  "max", 1.0, "Upper bound of uniformly distributed randomly generated values");
28  params.addParam<DistributionName>(
29  "distribution", "Name of distribution defining distribution of randomly generated values");
30 
31  params.addClassDescription("Initialize a variable with randomly generated numbers following "
32  "either a uniform distribution or a user-defined distribution");
33  return params;
34 }
35 
37  : RandomICBase(parameters),
39  _min(getParam<Real>("min")),
40  _max(getParam<Real>("max")),
41  _distribution(nullptr)
42 {
43  if (_min >= _max)
44  paramError("min", "Min >= Max for RandomIC!");
45 
46  if (parameters.isParamSetByUser("distribution"))
47  {
48  _distribution = &getDistributionByName(getParam<DistributionName>("distribution"));
50  paramError("distribution", "Cannot use together with 'min' or 'max' parameter");
51  }
52 }
53 
54 Real
55 RandomIC::value(const Point & /*p*/)
56 {
57  if (_distribution)
59  else
60  return generateRandom() * (_max - _min) + _min;
61 }
InputParameters::isParamSetByUser
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
Definition: InputParameters.C:837
RandomIC
RandomIC just returns a Random value.
Definition: RandomIC.h:33
RandomICBase
Base class for randomly generated initial conditions.
Definition: RandomICBase.h:33
RandomIC.h
RandomIC::_max
const Real _max
The upper bound of the random number range.
Definition: RandomIC.h:51
RandomIC::RandomIC
RandomIC(const InputParameters &parameters)
Constructor.
Definition: RandomIC.C:36
InputParameters::addParam
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.
Definition: InputParameters.h:1198
MooseObject::parameters
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:76
DistributionInterface::validParams
static InputParameters validParams()
Definition: DistributionInterface.C:18
registerMooseObject
registerMooseObject("MooseApp", RandomIC)
Distribution.h
MooseObject::paramError
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 ...
Definition: MooseObject.h:215
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
DistributionInterface
Interface for objects that need to use distributions.
Definition: DistributionInterface.h:28
InputParameters::addClassDescription
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.
Definition: InputParameters.C:70
DistributionInterface::getDistributionByName
const Distribution & getDistributionByName(const DistributionName &name) const
Get a distribution with a given name.
Definition: DistributionInterface.C:39
RandomIC::_min
const Real _min
The lower bound of the random number range.
Definition: RandomIC.h:48
RandomIC::value
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: RandomIC.C:55
RandomIC::validParams
static InputParameters validParams()
Definition: RandomIC.C:20
RandomICBase::validParams
static InputParameters validParams()
Definition: RandomICBase.C:36
Distribution::quantile
virtual Real quantile(const Real &y) const =0
Compute the inverse CDF (quantile function) value for given variable value y.
defineLegacyParams
defineLegacyParams(RandomIC)
RandomICBase::generateRandom
Real generateRandom()
Generate a uniformly distributed random number on the interval from 0 to 1.
Definition: RandomICBase.C:92
RandomIC::_distribution
const Distribution * _distribution
Distribution object optionally used to define distribution of random numbers.
Definition: RandomIC.h:54