inte.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2017, 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  \future It might be useful to have all of the integration
41  classes report the number of function evaluations used
42  in addition to the number of iterations which were taken
43  */
44  template<class func_t=funct11> class inte {
45 
46  public:
47 
48  inte() {
49  tol_rel=1.0e-8;
50  tol_abs=1.0e-8;
51  verbose=0;
52  interror=0.0;
53  err_nonconv=true;
54  }
55 
56  virtual ~inte() {}
57 
58  /** \brief Verbosity
59  */
60  int verbose;
61 
62  /// The most recent number of iterations taken
63  size_t last_iter;
64 
65  /** \brief The maximum relative uncertainty
66  in the value of the integral (default \f$ 10^{-8} \f$)
67  */
68  double tol_rel;
69 
70  /** \brief The maximum absolute uncertainty
71  in the value of the integral (default \f$ 10^{-8} \f$)
72  */
73  double tol_abs;
74 
75  /** \brief If true, call the error handler if the routine does not
76  converge or reach the desired tolerance (default true)
77 
78  If this is false, the function proceeds normally and
79  may provide convergence information in the integer return value.
80  */
82 
83  /** \brief Integrate function \c func from \c a to \c b.
84  */
85  virtual double integ(func_t &func, double a, double b) {
86  double res;
87  int ret=integ_err(func,a,b,res,this->interror);
88  if (ret!=0) {
89  O2SCL_ERR2("Integration failed in inte::integ(), ",
90  "but cannot return int.",o2scl::exc_efailed);
91  }
92  return res;
93  }
94 
95  /** \brief Integrate function \c func from \c a to \c b and place
96  the result in \c res and the error in \c err
97  */
98  virtual int integ_err(func_t &func, double a, double b,
99  double &res, double &err)=0;
100 
101  /** \brief Return the numerically estimated error in the result from
102  the last call to integ()
103 
104  This will quietly return zero if no integrations have been
105  performed or if the integrator does not estimate the error.
106  */
107  double get_error() { return interror; }
108 
109  /// Return string denoting type ("inte")
110  virtual const char *type() { return "inte"; }
111 
112 #ifndef DOXYGEN_INTERNAL
113 
114  protected:
115 
116  /// The uncertainty for the last integration computation
117  double interror;
118 
119 #endif
120 
121  };
122 
123 #ifndef DOXYGEN_NO_O2NS
124 }
125 #endif
126 
127 #endif
128 
129 
130 
131 
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 int integ_err(func_t &func, double a, double b, double &res, double &err)=0
Integrate function func from a to b and place the result in res and the error in err.
double get_error()
Return the numerically estimated error in the result from the last call to integ() ...
Definition: inte.h:107
size_t last_iter
The most recent number of iterations taken.
Definition: inte.h:63
bool err_nonconv
If true, call the error handler if the routine does not converge or reach the desired tolerance (defa...
Definition: inte.h:81
virtual double integ(func_t &func, double a, double b)
Integrate function func from a to b.
Definition: inte.h:85
generic failure
Definition: err_hnd.h:61
double tol_abs
The maximum absolute uncertainty in the value of the integral (default )
Definition: inte.h:73
Base integration class [abstract base].
Definition: inte.h:44
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
double interror
The uncertainty for the last integration computation.
Definition: inte.h:117
double tol_rel
The maximum relative uncertainty in the value of the integral (default )
Definition: inte.h:68
int verbose
Verbosity.
Definition: inte.h:60
virtual const char * type()
Return string denoting type ("inte")
Definition: inte.h:110

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