https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RandomIC.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 "RandomIC.h"
11
12#include "libmesh/point.h"
13#include "Distribution.h"
14
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
52Real
53RandomIC::value(const Point & /*p*/)
54{
55 if (_distribution)
57 else
58 return generateRandom() * (_max - _min) + _min;
59}
registerMooseObject("MooseApp", RandomIC)
Interface for objects that need to use distributions.
static InputParameters validParams()
const Distribution & getDistributionByName(const DistributionName &name) const
Get a distribution with a given name.
virtual Real quantile(const Real &y) const =0
Compute the inverse CDF (quantile function) value for given variable value y.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
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.
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.
Definition MooseBase.h:131
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 MooseBase.h:457
Base class for randomly generated initial conditions.
static InputParameters validParams()
Real generateRandom()
Generate a uniformly distributed random number on the interval from 0 to 1.
RandomIC just returns a Random value.
Definition RandomIC.h:30
const Real _max
The upper bound of the random number range.
Definition RandomIC.h:47
static InputParameters validParams()
Definition RandomIC.C:18
Distribution const * _distribution
Distribution object optionally used to define distribution of random numbers.
Definition RandomIC.h:50
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
const Real _min
The lower bound of the random number range.
Definition RandomIC.h:44