www.mooseframework.org
UniformDistribution.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "UniformDistribution.h"
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<Distribution>();
15  params.addClassDescription("Continuous uniform distribution.");
16  params.addParam<Real>("lower_bound", 0.0, "Distribution lower bound");
17  params.addParam<Real>("upper_bound", 1.0, "Distribution upper bound");
18  return params;
19 }
20 
21 UniformDistribution::UniformDistribution(const InputParameters & parameters)
22  : Distribution(parameters),
23  _lower_bound(getParam<Real>("lower_bound")),
24  _upper_bound(getParam<Real>("upper_bound"))
25 {
27  mooseError("The lower bound is larger than the upper bound!");
28 }
29 
30 Real
31 UniformDistribution::pdf(const Real & x)
32 {
33  if (x < _lower_bound || x > _upper_bound)
34  return 0.0;
35  else
36  return 1.0 / (_upper_bound - _lower_bound);
37 }
38 
39 Real
40 UniformDistribution::cdf(const Real & x)
41 {
42  if (x < _lower_bound)
43  return 0.0;
44  else if (x > _upper_bound)
45  return 1.0;
46  else
47  return (x - _lower_bound) / (_upper_bound - _lower_bound);
48 }
49 
50 Real
52 {
53  if (y < 0 || y > 1)
54  mooseError("The cdf_value provided is out of range 0 to 1.");
55  else
56  return y * (_upper_bound - _lower_bound) + _lower_bound;
57 }
const Real & _upper_bound
The upper bound for the uniform distribution.
const Real & _lower_bound
The lower bound for the uniform distribution.
UniformDistribution(const InputParameters &parameters)
virtual Real pdf(const Real &x) override
virtual Real cdf(const Real &x) override
virtual Real quantile(const Real &y) override
InputParameters validParams< UniformDistribution >()