Line data Source code
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 "Uniform.h" 11 : 12 : registerMooseObject("StochasticToolsApp", Uniform); 13 : 14 : InputParameters 15 13764 : Uniform::validParams() 16 : { 17 13764 : InputParameters params = Distribution::validParams(); 18 13764 : params.addClassDescription("Continuous uniform distribution."); 19 27528 : params.addParam<Real>("lower_bound", 0.0, "Distribution lower bound"); 20 27528 : params.addParam<Real>("upper_bound", 1.0, "Distribution upper bound"); 21 13764 : return params; 22 0 : } 23 : 24 6882 : Uniform::Uniform(const InputParameters & parameters) 25 : : Distribution(parameters), 26 6882 : _lower_bound(getParam<Real>("lower_bound")), 27 20646 : _upper_bound(getParam<Real>("upper_bound")) 28 : { 29 6882 : if (_lower_bound >= _upper_bound) 30 0 : mooseError("The lower bound is larger than the upper bound!"); 31 6882 : } 32 : 33 : Real 34 3037 : Uniform::pdf(const Real & x, const Real & lower_bound, const Real & upper_bound) 35 : { 36 3037 : if (x < lower_bound || x > upper_bound) 37 : return 0.0; 38 : else 39 1736 : return 1.0 / (upper_bound - lower_bound); 40 : } 41 : 42 : Real 43 1717 : Uniform::cdf(const Real & x, const Real & lower_bound, const Real & upper_bound) 44 : { 45 1717 : if (x < lower_bound) 46 : return 0.0; 47 1683 : else if (x > upper_bound) 48 : return 1.0; 49 : else 50 170 : return (x - lower_bound) / (upper_bound - lower_bound); 51 : } 52 : 53 : Real 54 2486464 : Uniform::quantile(const Real & y, const Real & lower_bound, const Real & upper_bound) 55 : { 56 2486464 : if (y < 0 || y > 1) 57 0 : ::mooseError("The cdf_value provided is out of range 0 to 1."); 58 : else 59 2486464 : return y * (upper_bound - lower_bound) + lower_bound; 60 : } 61 : 62 : Real 63 1337 : Uniform::pdf(const Real & x) const 64 : { 65 1337 : return pdf(x, _lower_bound, _upper_bound); 66 : } 67 : 68 : Real 69 17 : Uniform::cdf(const Real & x) const 70 : { 71 17 : return cdf(x, _lower_bound, _upper_bound); 72 : } 73 : 74 : Real 75 2486447 : Uniform::quantile(const Real & y) const 76 : { 77 2486447 : return quantile(y, _lower_bound, _upper_bound); 78 : }