inte_kronrod_boost.h
Go to the documentation of this file.
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_KRONROD_BOOST_H
24 #define O2SCL_INTE_KRONROD_BOOST_H
25 
26 /** \file inte_kronrod_boost.h
27  \brief File defining \ref o2scl::inte_kronrod_boost
28 */
29 
30 #include <cmath>
31 
32 #ifdef O2SCL_NEW_BOOST_INTEGRATION
33 #include <boost/math/quadrature/gauss_kronrod.hpp>
34 #endif
35 
36 #include <o2scl/inte.h>
37 
38 #ifndef DOXYGEN_NO_O2NS
39 namespace o2scl {
40 #endif
41 
42  /** \brief Gauss-Kronrod integration class (Boost)
43 
44  The rule parameter should be either 15, 31, 41, 51, or 61.
45 
46  This class calls the error handler if the
47  error returned by boost is larger than \ref inte::tol_rel .
48 
49  \future Figure out what to do with L1norm. The boost
50  documentation claims that "the error estimates provided by the
51  routine are woefully pessimistic" and the integral appears to be
52  correct, but the boost documentation also says "if there is a
53  significant difference between this [the L1 norm] and the
54  returned value, then the result is likely to be
55  ill-conditioned". It would be nice to test L1 norm in some
56  reasonable way.
57  */
58  template<class func_t=funct, size_t rule=15, class fp_t=double>
60  public inte<func_t,fp_t> {
61 
62  protected:
63 
64  /// Maximum depth
65  size_t max_depth;
66 
67  /// L1 norm
68  fp_t L1norm;
69 
70  public:
71 
73  max_depth=15;
74  }
75 
76  virtual ~inte_kronrod_boost() {
77  }
78 
79  void set_max_depth(size_t md) {
80  max_depth=md;
81  return;
82  }
83 
84  /** \brief Integrate function \c func from \c a to \c b and place
85  the result in \c res and the error in \c err
86  */
87  virtual int integ_err(func_t &func, fp_t a, fp_t b,
88  fp_t &res, fp_t &err) {
89  res=boost::math::quadrature::gauss_kronrod<fp_t,rule>::integrate
90  (func,a,b,max_depth,this->tol_rel,&err,&L1norm);
91  if (err>this->tol_rel) {
92  O2SCL_ERR2("Failed to achieve tolerance in ",
93  "inte_kronrod_boost::integ_err().",o2scl::exc_efailed);
94  }
95  return 0;
96  }
97 
98  };
99 
100 #ifndef DOXYGEN_NO_O2NS
101 }
102 #endif
103 
104 #endif
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
o2scl::inte_kronrod_boost
Gauss-Kronrod integration class (Boost)
Definition: inte_kronrod_boost.h:59
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_kronrod_boost::max_depth
size_t max_depth
Maximum depth.
Definition: inte_kronrod_boost.h:65
o2scl::inte_kronrod_boost::L1norm
fp_t L1norm
L1 norm.
Definition: inte_kronrod_boost.h:68
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_kronrod_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_kronrod_boost.h:87

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