LCOV - code coverage report
Current view: top level - src/distributions - Uniform.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 27 30 90.0 %
Date: 2025-07-25 05:00:46 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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       12920 : Uniform::validParams()
      16             : {
      17       12920 :   InputParameters params = Distribution::validParams();
      18       12920 :   params.addClassDescription("Continuous uniform distribution.");
      19       25840 :   params.addParam<Real>("lower_bound", 0.0, "Distribution lower bound");
      20       25840 :   params.addParam<Real>("upper_bound", 1.0, "Distribution upper bound");
      21       12920 :   return params;
      22           0 : }
      23             : 
      24        6460 : Uniform::Uniform(const InputParameters & parameters)
      25             :   : Distribution(parameters),
      26        6460 :     _lower_bound(getParam<Real>("lower_bound")),
      27       19380 :     _upper_bound(getParam<Real>("upper_bound"))
      28             : {
      29        6460 :   if (_lower_bound >= _upper_bound)
      30           0 :     mooseError("The lower bound is larger than the upper bound!");
      31        6460 : }
      32             : 
      33             : Real
      34        2816 : Uniform::pdf(const Real & x, const Real & lower_bound, const Real & upper_bound)
      35             : {
      36        2816 :   if (x < lower_bound || x > upper_bound)
      37             :     return 0.0;
      38             :   else
      39        1600 :     return 1.0 / (upper_bound - lower_bound);
      40             : }
      41             : 
      42             : Real
      43        1616 : Uniform::cdf(const Real & x, const Real & lower_bound, const Real & upper_bound)
      44             : {
      45        1616 :   if (x < lower_bound)
      46             :     return 0.0;
      47        1584 :   else if (x > upper_bound)
      48             :     return 1.0;
      49             :   else
      50         160 :     return (x - lower_bound) / (upper_bound - lower_bound);
      51             : }
      52             : 
      53             : Real
      54     2260530 : Uniform::quantile(const Real & y, const Real & lower_bound, const Real & upper_bound)
      55             : {
      56     2260530 :   if (y < 0 || y > 1)
      57           0 :     ::mooseError("The cdf_value provided is out of range 0 to 1.");
      58             :   else
      59     2260530 :     return y * (upper_bound - lower_bound) + lower_bound;
      60             : }
      61             : 
      62             : Real
      63        1216 : Uniform::pdf(const Real & x) const
      64             : {
      65        1216 :   return pdf(x, _lower_bound, _upper_bound);
      66             : }
      67             : 
      68             : Real
      69          16 : Uniform::cdf(const Real & x) const
      70             : {
      71          16 :   return cdf(x, _lower_bound, _upper_bound);
      72             : }
      73             : 
      74             : Real
      75     2260514 : Uniform::quantile(const Real & y) const
      76             : {
      77     2260514 :   return quantile(y, _lower_bound, _upper_bound);
      78             : }

Generated by: LCOV version 1.14