LCOV - code coverage report
Current view: top level - include/distributions - BoostDistribution.h (source / functions) Hit Total Coverage
Test: stochastic_tools Test Coverage Lines: 9 9 100.0 %
Date: 2017-11-21 14:52:30 Functions: 9 15 60.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             : #ifndef BOOSTDISTRIBUTION_H
       9             : #define BOOSTDISTRIBUTION_H
      10             : 
      11             : #include "Distribution.h"
      12             : 
      13             : #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
      14             : #include <boost/math/distributions.hpp>
      15             : #else
      16             : class BoostDistributionDummy
      17             : {
      18             : public:
      19             :   BoostDistributionDummy(Real...) {}
      20             : };
      21             : namespace boost
      22             : {
      23             : namespace math
      24             : {
      25             : template <typename T>
      26             : using weibull_distribution = BoostDistributionDummy;
      27             : 
      28             : template <typename T>
      29             : using normal_distribution = BoostDistributionDummy;
      30             : 
      31             : template <typename T>
      32             : using lognormal_distribution = BoostDistributionDummy;
      33             : }
      34             : }
      35             : #endif
      36             : 
      37             : /**
      38             :  * A class used to as a base for distributions defined by Boost.
      39             :  *
      40             :  * The default type is set to Real to allow for derived classes to compile without Boost and
      41             :  * trigger the mooseError in the constructor.
      42             :  */
      43             : template <typename T = Real>
      44           4 : class BoostDistribution : public Distribution
      45             : {
      46             : public:
      47             :   BoostDistribution(const InputParameters & parameters);
      48             : 
      49             :   virtual Real pdf(const Real & x) override;
      50             :   virtual Real cdf(const Real & x) override;
      51             :   virtual Real quantile(const Real & y) override;
      52             : 
      53             : protected:
      54             :   /// This must be defined by the child class in the constructor
      55             :   std::unique_ptr<T> _distribution_unique_ptr;
      56             : };
      57             : 
      58             : template <typename T>
      59           4 : BoostDistribution<T>::BoostDistribution(const InputParameters & parameters)
      60           4 :   : Distribution(parameters)
      61             : {
      62             : #ifndef LIBMESH_HAVE_EXTERNAL_BOOST
      63             :   mooseError("The ",
      64             :              getParam<std::string>("type"),
      65             :              " distribution named '",
      66             :              name(),
      67             :              "' requires that libMesh be compiled with an external Boost library, this may be done "
      68             :              "using the --with-boost configure option.");
      69             : #endif
      70             : }
      71             : 
      72             : template <typename T>
      73             : Real
      74           3 : BoostDistribution<T>::pdf(const Real & x)
      75             : {
      76             : #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
      77             :   mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
      78           3 :   return boost::math::pdf(*_distribution_unique_ptr, x);
      79             : #else
      80             :   return x; // unreachable
      81             : #endif
      82             : }
      83             : 
      84             : template <typename T>
      85             : Real
      86           3 : BoostDistribution<T>::cdf(const Real & x)
      87             : {
      88             : #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
      89             :   mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
      90           3 :   return boost::math::cdf(*_distribution_unique_ptr, x);
      91             : #else
      92             :   return x; // unreachable
      93             : #endif
      94             : }
      95             : 
      96             : template <typename T>
      97             : Real
      98          33 : BoostDistribution<T>::quantile(const Real & y)
      99             : {
     100             : #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
     101             :   mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
     102          33 :   return boost::math::quantile(*_distribution_unique_ptr, y);
     103             : #else
     104             :   return y; // unreachable
     105             : #endif
     106             : }
     107             : 
     108             : #endif // BOOSTDISTRIBUTION_H

Generated by: LCOV version 1.11