www.mooseframework.org
BoostDistribution.h
Go to the documentation of this file.
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
17 {
18 public:
20 };
21 namespace boost
22 {
23 namespace math
24 {
25 template <typename T>
27 
28 template <typename T>
30 
31 template <typename T>
33 }
34 }
35 #endif
36 
43 template <typename T = Real>
44 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:
55  std::unique_ptr<T> _distribution_unique_ptr;
56 };
57 
58 template <typename T>
59 BoostDistribution<T>::BoostDistribution(const InputParameters & parameters)
60  : 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
75 {
76 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
77  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
78  return boost::math::pdf(*_distribution_unique_ptr, x);
79 #else
80  return x; // unreachable
81 #endif
82 }
83 
84 template <typename T>
85 Real
87 {
88 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
89  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
90  return boost::math::cdf(*_distribution_unique_ptr, x);
91 #else
92  return x; // unreachable
93 #endif
94 }
95 
96 template <typename T>
97 Real
99 {
100 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
101  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
102  return boost::math::quantile(*_distribution_unique_ptr, y);
103 #else
104  return y; // unreachable
105 #endif
106 }
107 
108 #endif // BOOSTDISTRIBUTION_H
virtual Real quantile(const Real &y) override
virtual Real cdf(const Real &x) override
A class used to as a base for distributions defined by Boost.
std::unique_ptr< T > _distribution_unique_ptr
This must be defined by the child class in the constructor.
virtual Real pdf(const Real &x) override
BoostDistribution(const InputParameters &parameters)