LCOV - code coverage report
Current view: top level - src/distributions - Lognormal.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 22 23 95.7 %
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 "Lognormal.h"
      11             : #include "Normal.h"
      12             : #include "math.h"
      13             : #include "libmesh/utility.h"
      14             : 
      15             : registerMooseObject("StochasticToolsApp", Lognormal);
      16             : 
      17             : InputParameters
      18          96 : Lognormal::validParams()
      19             : {
      20          96 :   InputParameters params = Distribution::validParams();
      21          96 :   params.addClassDescription("Lognormal distribution");
      22         192 :   params.addRequiredParam<Real>("location", "The Lognormal location parameter (m or mu).");
      23         192 :   params.addRequiredParam<Real>("scale", "The Lognormal scale parameter (s or sigma).");
      24          96 :   return params;
      25           0 : }
      26             : 
      27          48 : Lognormal::Lognormal(const InputParameters & parameters)
      28         144 :   : Distribution(parameters), _location(getParam<Real>("location")), _scale(getParam<Real>("scale"))
      29             : {
      30          48 : }
      31             : 
      32             : Real
      33          16 : Lognormal::pdf(const Real & x, const Real & location, const Real & scale)
      34             : {
      35          16 :   return 1.0 / (x * scale * std::sqrt(2.0 * M_PI)) *
      36          16 :          std::exp(-0.5 * Utility::pow<2>((std::log(x) - location) / scale));
      37             : }
      38             : 
      39             : Real
      40          16 : Lognormal::cdf(const Real & x, const Real & location, const Real & scale)
      41             : {
      42          16 :   return 0.5 * (1.0 + std::erf((std::log(x) - location) / (scale * std::sqrt(2.0))));
      43             : }
      44             : 
      45             : Real
      46         616 : Lognormal::quantile(const Real & p, const Real & location, const Real & scale)
      47             : {
      48         616 :   return std::exp(Normal::quantile(p, location, scale));
      49             : }
      50             : 
      51             : Real
      52          16 : Lognormal::pdf(const Real & x) const
      53             : {
      54          16 :   return pdf(x, _location, _scale);
      55             : }
      56             : 
      57             : Real
      58          16 : Lognormal::cdf(const Real & x) const
      59             : {
      60          16 :   return cdf(x, _location, _scale);
      61             : }
      62             : 
      63             : Real
      64         616 : Lognormal::quantile(const Real & p) const
      65             : {
      66         616 :   return quantile(p, _location, _scale);
      67             : }

Generated by: LCOV version 1.14