inte.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2018, Andrew W. Steiner and Jerry Gagelman
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_H
24 #define O2SCL_INTE_H
25 
26 /** \file inte.h
27  \brief File defining \ref o2scl::inte
28 */
29 
30 #include <cmath>
31 #include <o2scl/err_hnd.h>
32 #include <o2scl/funct.h>
33 
34 #ifndef DOXYGEN_NO_O2NS
35 namespace o2scl {
36 #endif
37 
38  /** \brief Base integration class [abstract base]
39 
40  \note Currently \o2 supports only types \c double and, for some
41  integration methods, \c long \c double for the floating point
42  type \c fp_t . Also, the default values of \ref tol_rel
43  and \ref tol_abs are designed for double precision and
44  likely need to be decreased for long double precision
45  integration.
46 
47  \future It might be useful to have all of the integration
48  classes report the number of function evaluations used
49  in addition to the number of iterations which were taken.
50  */
51  template<class func_t=funct, class fp_t=double> class inte {
52 
53  public:
54 
55  inte() {
56  tol_rel=1.0e-8;
57  tol_abs=1.0e-8;
58  verbose=0;
59  interror=0.0;
60  err_nonconv=true;
61  }
62 
63  virtual ~inte() {}
64 
65  /** \brief Verbosity
66  */
67  int verbose;
68 
69  /// The most recent number of iterations taken
70  size_t last_iter;
71 
72  /** \brief The maximum relative uncertainty
73  in the value of the integral (default \f$ 10^{-8} \f$)
74  */
75  fp_t tol_rel;
76 
77  /** \brief The maximum absolute uncertainty
78  in the value of the integral (default \f$ 10^{-8} \f$)
79  */
80  fp_t tol_abs;
81 
82  /** \brief If true, call the error handler if the routine does not
83  converge or reach the desired tolerance (default true)
84 
85  If this is false, the function proceeds normally and
86  may provide convergence information in the integer return value.
87  */
89 
90  /** \brief Integrate function \c func from \c a to \c b.
91  */
92  virtual fp_t integ(func_t &func, fp_t a, fp_t b) {
93  fp_t res;
94  int ret=integ_err(func,a,b,res,this->interror);
95  if (ret!=0) {
96  O2SCL_ERR2("Integration failed in inte::integ(), ",
97  "but cannot return int.",o2scl::exc_efailed);
98  }
99  return res;
100  }
101 
102  /** \brief Integrate function \c func from \c a to \c b and place
103  the result in \c res and the error in \c err
104  */
105  virtual int integ_err(func_t &func, fp_t a, fp_t b,
106  fp_t &res, fp_t &err)=0;
107 
108  /** \brief Return the numerically estimated error in the result from
109  the last call to integ()
110 
111  This will quietly return zero if no integrations have been
112  performed or if the integrator does not estimate the error.
113  */
114  fp_t get_error() { return interror; }
115 
116  /// Return string denoting type ("inte")
117  virtual const char *type() { return "inte"; }
118 
119 #ifndef DOXYGEN_INTERNAL
120 
121  protected:
122 
123  /// The uncertainty for the last integration computation
124  fp_t interror;
125 
126 #endif
127 
128  };
129 
130 #ifndef DOXYGEN_NO_O2NS
131 }
132 #endif
133 
134 #endif
135 
136 
137 
138 
fp_t tol_abs
The maximum absolute uncertainty in the value of the integral (default )
Definition: inte.h:80
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
virtual fp_t integ(func_t &func, fp_t a, fp_t b)
Integrate function func from a to b.
Definition: inte.h:92
fp_t tol_rel
The maximum relative uncertainty in the value of the integral (default )
Definition: inte.h:75
virtual int integ_err(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err)=0
Integrate function func from a to b and place the result in res and the error in err.
virtual const char * type()
Return string denoting type ("inte")
Definition: inte.h:117
bool err_nonconv
If true, call the error handler if the routine does not converge or reach the desired tolerance (defa...
Definition: inte.h:88
generic failure
Definition: err_hnd.h:61
fp_t get_error()
Return the numerically estimated error in the result from the last call to integ() ...
Definition: inte.h:114
size_t last_iter
The most recent number of iterations taken.
Definition: inte.h:70
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
int verbose
Verbosity.
Definition: inte.h:67
fp_t interror
The uncertainty for the last integration computation.
Definition: inte.h:124

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