LCOV - code coverage report
Current view: top level - src/distributions - UniformDistribution.C (source / functions) Hit Total Coverage
Test: stochastic_tools Test Coverage Lines: 22 24 91.7 %
Date: 2017-11-21 14:52:30 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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
      12          39 : validParams<UniformDistribution>()
      13             : {
      14          39 :   InputParameters params = validParams<Distribution>();
      15          78 :   params.addClassDescription("Continuous uniform distribution.");
      16         117 :   params.addParam<Real>("lower_bound", 0.0, "Distribution lower bound");
      17         117 :   params.addParam<Real>("upper_bound", 1.0, "Distribution upper bound");
      18          39 :   return params;
      19             : }
      20             : 
      21          39 : UniformDistribution::UniformDistribution(const InputParameters & parameters)
      22             :   : Distribution(parameters),
      23          78 :     _lower_bound(getParam<Real>("lower_bound")),
      24         195 :     _upper_bound(getParam<Real>("upper_bound"))
      25             : {
      26          39 :   if (_lower_bound >= _upper_bound)
      27           0 :     mooseError("The lower bound is larger than the upper bound!");
      28          39 : }
      29             : 
      30             : Real
      31           1 : UniformDistribution::pdf(const Real & x)
      32             : {
      33           1 :   if (x < _lower_bound || x > _upper_bound)
      34             :     return 0.0;
      35             :   else
      36           1 :     return 1.0 / (_upper_bound - _lower_bound);
      37             : }
      38             : 
      39             : Real
      40           1 : UniformDistribution::cdf(const Real & x)
      41             : {
      42           1 :   if (x < _lower_bound)
      43             :     return 0.0;
      44           1 :   else if (x > _upper_bound)
      45             :     return 1.0;
      46             :   else
      47           1 :     return (x - _lower_bound) / (_upper_bound - _lower_bound);
      48             : }
      49             : 
      50             : Real
      51         606 : UniformDistribution::quantile(const Real & y)
      52             : {
      53         606 :   if (y < 0 || y > 1)
      54           0 :     mooseError("The cdf_value provided is out of range 0 to 1.");
      55             :   else
      56         606 :     return y * (_upper_bound - _lower_bound) + _lower_bound;
      57        1812 : }

Generated by: LCOV version 1.11