inte_double_exp_boost.h
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2019-2020, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_INTE_TANH_SINH_BOOST_H
24 #define O2SCL_INTE_TANH_SINH_BOOST_H
25 
26 /** \file inte_tanh_sinh_boost.h
27  \brief File defining \ref o2scl::inte_tanh_sinh_boost
28 */
29 
30 #include <cmath>
31 
32 #if defined(O2SCL_NEW_BOOST_INTEGRATION) || defined(DOXYGEN)
33 
34 #include <boost/math/quadrature/tanh_sinh.hpp>
35 #include <boost/math/quadrature/exp_sinh.hpp>
36 #include <boost/math/quadrature/sinh_sinh.hpp>
37 
38 #include <o2scl/inte.h>
39 
40 #ifndef DOXYGEN_NO_O2NS
41 namespace o2scl {
42 #endif
43 
44  /** \brief Tanh-sinh integration class (Boost)
45 
46  This class calls the error handler if the
47  error returned by boost is larger than \ref inte::tol_rel .
48  */
49  template<class func_t=funct, size_t max_refine=15, class fp_t=double>
51  public inte<func_t, fp_t> {
52 
53  protected:
54 
55  /// The boost integration object
56  boost::math::quadrature::tanh_sinh<fp_t> it;
57 
58  /// L1 norm
59  fp_t L1norm;
60 
61  public:
62 
63  inte_tanh_sinh_boost() : it(max_refine) {
64  }
65 
66  virtual ~inte_tanh_sinh_boost() {
67  }
68 
69  /** \brief Integrate function \c func from \c a to \c b and place
70  the result in \c res and the error in \c err
71  */
72  virtual int integ_err(func_t &func, fp_t a, fp_t b,
73  fp_t &res, fp_t &err) {
74  res=it.integrate(func,a,b,this->tol_rel,&err,&L1norm);
75  if (err>this->tol_rel) {
76  O2SCL_ERR2("Failed to achieve tolerance in ",
77  "inte_tanh_sinh_boost::integ_err().",o2scl::exc_efailed);
78  }
79  return 0;
80  }
81 
82  /** \brief Integrate function \c func from \c a to \c b and place
83  the result in \c res and the error in \c err
84  */
85  virtual int integ_err(func_t &func,
86  fp_t &res, fp_t &err) {
87  res=it.integrate(func,this->tol_rel,&err,&L1norm);
88  if (err>this->tol_rel) {
89  O2SCL_ERR2("Failed to achieve tolerance in ",
90  "inte_tanh_sinh_boost::integ_err().",o2scl::exc_efailed);
91  }
92  return 0;
93  }
94 
95  };
96 
97  /** \brief Exp-sinh integration class (Boost)
98 
99  This class calls the error handler if the
100  error returned by boost is larger than \ref inte::tol_rel .
101  */
102  template<class func_t=funct, size_t max_refine=15, class fp_t=double>
104  public inte<func_t, fp_t> {
105 
106  protected:
107 
108  /// The boost integration object
109  boost::math::quadrature::exp_sinh<fp_t> it;
110 
111  /// L1 norm
112  fp_t L1norm;
113 
114  public:
115 
116  inte_exp_sinh_boost() : it(max_refine) {
117  }
118 
119  virtual ~inte_exp_sinh_boost() {
120  }
121 
122  /** \brief Integrate function \c func from \c a to \c b and place
123  the result in \c res and the error in \c err
124  */
125  virtual int integ_err(func_t &func, fp_t a, fp_t b,
126  fp_t &res, fp_t &err) {
127  res=it.integrate(func,a,b,this->tol_rel,&err,&L1norm);
128  if (err>this->tol_rel) {
129  O2SCL_ERR2("Failed to achieve tolerance in ",
130  "inte_exp_sinh_boost::integ_err().",o2scl::exc_efailed);
131  }
132  return 0;
133  }
134 
135  /** \brief Integrate function \c func from \c a to \c b and place
136  the result in \c res and the error in \c err
137  */
138  virtual int integ_err(func_t &func,
139  fp_t &res, fp_t &err) {
140  res=it.integrate(func,this->tol_rel,&err,&L1norm);
141  if (err>this->tol_rel) {
142  O2SCL_ERR2("Failed to achieve tolerance in ",
143  "inte_exp_sinh_boost::integ_err().",o2scl::exc_efailed);
144  }
145  return 0;
146  }
147 
148  };
149 
150  /** \brief Sinh-sinh integration class (Boost)
151 
152  This class calls the error handler if the
153  error returned by boost is larger than \ref inte::tol_rel .
154  */
155  template<class func_t=funct, size_t max_refine=15, class fp_t=double>
157 
158  protected:
159 
160  /// The boost integration object
161  boost::math::quadrature::sinh_sinh<fp_t> it;
162 
163  /// L1 norm
164  fp_t L1norm;
165 
166  public:
167 
168  inte_sinh_sinh_boost() : it(max_refine) {
169  }
170 
171  virtual ~inte_sinh_sinh_boost() {
172  }
173 
174  /** \brief Integrate function \c func from \c a to \c b and place
175  the result in \c res and the error in \c err
176  */
177  virtual int integ_err(func_t &func,
178  fp_t &res, fp_t &err) {
179  res=it.integrate(func,this->tol_rel,&err,&L1norm);
180  if (err>this->tol_rel) {
181  O2SCL_ERR2("Failed to achieve tolerance in ",
182  "inte_sinh_sinh_boost::integ_err().",o2scl::exc_efailed);
183  }
184  return 0;
185  }
186 
187  };
188 
189 #ifndef DOXYGEN_NO_O2NS
190 }
191 #endif
192 
193 // End of #if defined(O2SCL_NEW_BOOST_INTEGRATION) || defined(DOXYGEN)
194 #endif
195 
196 #endif
o2scl::inte_sinh_sinh_boost::L1norm
fp_t L1norm
L1 norm.
Definition: inte_double_exp_boost.h:164
o2scl::inte_exp_sinh_boost
Exp-sinh integration class (Boost)
Definition: inte_double_exp_boost.h:103
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
o2scl::inte_exp_sinh_boost::it
boost::math::quadrature::exp_sinh< fp_t > it
The boost integration object.
Definition: inte_double_exp_boost.h:109
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
o2scl::inte_sinh_sinh_boost::it
boost::math::quadrature::sinh_sinh< fp_t > it
The boost integration object.
Definition: inte_double_exp_boost.h:161
o2scl::inte_sinh_sinh_boost::integ_err
virtual int integ_err(func_t &func, fp_t &res, fp_t &err)
Integrate function func from a to b and place the result in res and the error in err.
Definition: inte_double_exp_boost.h:177
o2scl
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
Definition: anneal.h:42
o2scl::inte_exp_sinh_boost::integ_err
virtual int integ_err(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err)
Integrate function func from a to b and place the result in res and the error in err.
Definition: inte_double_exp_boost.h:125
o2scl::inte_tanh_sinh_boost::L1norm
fp_t L1norm
L1 norm.
Definition: inte_double_exp_boost.h:59
o2scl::inte_exp_sinh_boost::L1norm
fp_t L1norm
L1 norm.
Definition: inte_double_exp_boost.h:112
o2scl::inte_tanh_sinh_boost::integ_err
virtual int integ_err(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err)
Integrate function func from a to b and place the result in res and the error in err.
Definition: inte_double_exp_boost.h:72
o2scl::inte_exp_sinh_boost::integ_err
virtual int integ_err(func_t &func, fp_t &res, fp_t &err)
Integrate function func from a to b and place the result in res and the error in err.
Definition: inte_double_exp_boost.h:138
o2scl::inte_sinh_sinh_boost
Sinh-sinh integration class (Boost)
Definition: inte_double_exp_boost.h:156
o2scl::inte_tanh_sinh_boost::it
boost::math::quadrature::tanh_sinh< fp_t > it
The boost integration object.
Definition: inte_double_exp_boost.h:56
o2scl::inte< funct, double >::tol_rel
double tol_rel
The maximum relative uncertainty in the value of the integral (default )
Definition: inte.h:75
o2scl::inte
Base integration class [abstract base].
Definition: inte.h:51
o2scl::inte_tanh_sinh_boost::integ_err
virtual int integ_err(func_t &func, fp_t &res, fp_t &err)
Integrate function func from a to b and place the result in res and the error in err.
Definition: inte_double_exp_boost.h:85
o2scl::inte_tanh_sinh_boost
Tanh-sinh integration class (Boost)
Definition: inte_double_exp_boost.h:50

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).