inte_tanh_sinh_boost.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2019, 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 #ifndef O2SCL_OLDER_COMPILER
33 #include <boost/math/quadrature/tanh_sinh.hpp>
34 #endif
35 
36 #include <o2scl/inte.h>
37 
38 #ifndef DOXYGEN_NO_O2NS
39 namespace o2scl {
40 #endif
41 
42  /** \brief Tanh-sinh integration class (Boost)
43 
44  This class calls the error handler if the
45  error returned by boost is larger than \ref inte::tol_rel .
46  */
47  template<class func_t=funct, size_t max_refine=15, class fp_t=double>
49  public inte<func_t, fp_t> {
50 
51  protected:
52 
53  /// The boost integration object
54  boost::math::quadrature::tanh_sinh<fp_t> it;
55 
56  /// L1 norm
57  double L1norm;
58 
59  public:
60 
61  inte_tanh_sinh_boost() : it(max_refine) {
62  }
63 
64  virtual ~inte_tanh_sinh_boost() {
65  }
66 
67  /** \brief Integrate function \c func from \c a to \c b and place
68  the result in \c res and the error in \c err
69  */
70  virtual int integ_err(func_t &func, fp_t a, fp_t b,
71  fp_t &res, fp_t &err) {
72  res=it.integrate(func,a,b,this->tol_rel,&err,&L1norm);
73  if (err>this->tol_rel) {
74  O2SCL_ERR2("Failed to achieve tolerance in ",
75  "inte_tanh_sinh_boost::integ_err().",o2scl::exc_efailed);
76  }
77  return 0;
78  }
79 
80  };
81 
82 #ifndef DOXYGEN_NO_O2NS
83 }
84 #endif
85 
86 #endif
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
fp_t tol_rel
The maximum relative uncertainty in the value of the integral (default )
Definition: inte.h:75
generic failure
Definition: err_hnd.h:61
Base integration class [abstract base].
Definition: inte.h:51
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
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.
boost::math::quadrature::tanh_sinh< fp_t > it
The boost integration object.
Tanh-sinh integration class (Boost)

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