www.mooseframework.org
BoostDistribution.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #pragma once
11 
12 #include "Distribution.h"
13 
14 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
15 #include "libmesh/ignore_warnings.h"
16 #pragma GCC diagnostic ignored "-Wparentheses"
17 #include <boost/math/distributions.hpp>
18 #include "libmesh/restore_warnings.h"
19 #else
21 {
22 public:
24 };
25 namespace boost
26 {
27 namespace math
28 {
29 template <typename T>
31 
32 template <typename T>
34 
35 template <typename T>
37 }
38 }
39 #endif
40 
47 template <typename T = Real>
48 class BoostDistribution : public Distribution
49 {
50 public:
51  BoostDistribution(const InputParameters & parameters);
52 
53  virtual Real pdf(const Real & x) const override;
54  virtual Real cdf(const Real & x) const override;
55  virtual Real quantile(const Real & y) const override;
56  virtual Real median() const override;
57 
58 protected:
60  std::unique_ptr<T> _distribution_unique_ptr;
61 };
62 
63 template <typename T>
64 BoostDistribution<T>::BoostDistribution(const InputParameters & parameters)
65  : Distribution(parameters)
66 {
67 #ifndef LIBMESH_HAVE_EXTERNAL_BOOST
68  mooseError("The ",
69  getParam<std::string>("type"),
70  " distribution named '",
71  name(),
72  "' requires that libMesh be compiled with an external Boost library, this may be done "
73  "using the --with-boost configure option.");
74 #endif
75 }
76 
77 template <typename T>
78 Real
79 BoostDistribution<T>::pdf(const Real & x) const
80 {
81 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
82  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
83  return boost::math::pdf(*_distribution_unique_ptr, x);
84 #else
85  return x; // unreachable
86 #endif
87 }
88 
89 template <typename T>
90 Real
91 BoostDistribution<T>::cdf(const Real & x) const
92 {
93 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
94  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
95  return boost::math::cdf(*_distribution_unique_ptr, x);
96 #else
97  return x; // unreachable
98 #endif
99 }
100 
101 template <typename T>
102 Real
103 BoostDistribution<T>::quantile(const Real & y) const
104 {
105 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
106  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
107  return boost::math::quantile(*_distribution_unique_ptr, y);
108 #else
109  return y; // unreachable
110 #endif
111 }
112 
113 template <typename T>
114 Real
116 {
117 #ifdef LIBMESH_HAVE_EXTERNAL_BOOST
118  mooseAssert(_distribution_unique_ptr, "Boost distribution pointer not defined.");
119  return boost::math::median(*_distribution_unique_ptr);
120 #else
121  return 0; // unreachable
122 #endif
123 }
124 
virtual Real median() const override
virtual Real pdf(const Real &x) const override
virtual Real cdf(const Real &x) const override
virtual Real quantile(const Real &y) const override
A class used to as a base for distributions defined by Boost.
const std::string name
Definition: Setup.h:21
std::unique_ptr< T > _distribution_unique_ptr
This must be defined by the child class in the constructor.
BoostDistribution(const InputParameters &parameters)