inte_gen.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2017, 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_GEN_INTE_H
24 #define O2SCL_GEN_INTE_H
25 
26 /** \file inte_gen.h
27  \brief File defining \ref o2scl::inte_gen
28 */
29 
30 #ifndef DOXYGEN_NO_O2NS
31 namespace o2scl {
32 #endif
33 
34  /** \brief Generalized multi-dimensional integration [abstract base]
35 
36  Perform the generalized multi-dimensional integral:
37  \f[
38  \int_{x_0=a_0}^{x_0=b_0} f(x_0) \int_{x_1=a_1(x_0)}^{x_1=b_1(x_0)}
39  f(x_0, x_1) ...
40  \int_{x_{\mathrm{n}-1}=a_{\mathrm{n}-1}(x_0,x_1,..,x_{\mathrm{n}-2})}^
41  {x_{\mathrm{n}-1}=b_{\mathrm{n}-1}(x_0,x_1,..,x_{\mathrm{n}-2})}
42  f(x_0,x_1,...,x_{\mathrm{n-1}})~d x_{\mathrm{n}-1}~...~d x_1~d x_0
43  \f]
44 
45  The functions \f$ a_i \f$ and \f$ b_i \f$ are specified
46  in the arguments <tt>a</tt> and <tt>b</tt> to the function
47  \ref ginteg() or \ref ginteg_err() .
48 
49  In order to allow the user to specify only three functions (for
50  the integrand, the lower limits, and the upper limits) the first
51  argument to the limit and integrand functions is used to
52  distinguish among the limits for each separate integral. So
53  first argument to <tt>a</tt> for \f$ a_0() \f$ is 0, and the
54  first argument to <tt>a</tt> for \f$ a_1() \f$ is 1, etc., and
55  similarly for the upper limits specified in <tt>b</tt> and
56  the integrands specified in <tt>func</tt>.
57 
58  \future It might be interesting to construct a child class of
59  \ref o2scl::inte_gen which automatically transforms variables to
60  a hypercube and then applies a child of \ref o2scl::inte_multi
61  to do the integration.
62  */
63  template<class func_t, class lfunc_t, class ufunc_t,
65 
66  public:
67 
68  inte_gen() {
69  tol_rel=1.0e-8;
70  verbose=0;
71  interror=0.0;
72  err_nonconv=true;
73  }
74 
75  virtual ~inte_gen() {}
76 
77  /** \brief Verbosity
78  */
79  int verbose;
80 
81  /** \brief The maximum "uncertainty" in the value of the integral
82  */
83  double tol_rel;
84 
85  /// If true, call the error handler if the routine does not "converge"
87 
88  /** \brief Integrate function \c func from
89  \f$ x_i=a_i(x_i) \f$ to \f$ x_i=b_i(x_i) \f$ for
90  \f$ 0<i<\mathrm{ndim}-1 \f$.
91  */
92  virtual double ginteg(func_t &func, size_t ndim, lfunc_t &a, ufunc_t &b)=0;
93 
94  /** \brief Integrate function \c func from
95  \f$ x_i=a_i(x_i) \f$ to \f$ x_i=b_i(x_i) \f$ for
96  \f$ 0<i<\mathrm{ndim}-1 \f$.
97  */
98  virtual int ginteg_err(func_t &func, size_t ndim, lfunc_t &a,
99  ufunc_t &b, double &res, double &err) {
100  res=ginteg(func,ndim,a,b);
101  return 0;
102  }
103 
104  /** \brief Return the error in the result from the last call to
105  ginteg() or ginteg_err()
106 
107  This will quietly return zero if no integrations have been
108  performed.
109  */
110  double get_error() { return interror; }
111 
112  /// Return string denoting type ("inte_gen")
113  const char *type() { return "inte_gen"; }
114 
115 #ifndef DOXYGEN_INTERNAL
116 
117  protected:
118 
119  /// The uncertainty for the last integration computation
120  double interror;
121 
122 #endif
123 
124  };
125 
126 #ifndef DOXYGEN_NO_O2NS
127 }
128 #endif
129 
130 #endif
131 
132 
133 
134 
135 
136 
int verbose
Verbosity.
Definition: inte_gen.h:79
double get_error()
Return the error in the result from the last call to ginteg() or ginteg_err()
Definition: inte_gen.h:110
virtual int ginteg_err(func_t &func, size_t ndim, lfunc_t &a, ufunc_t &b, double &res, double &err)
Integrate function func from to for .
Definition: inte_gen.h:98
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
const char * type()
Return string denoting type ("inte_gen")
Definition: inte_gen.h:113
Generalized multi-dimensional integration [abstract base].
Definition: inte_gen.h:64
bool err_nonconv
If true, call the error handler if the routine does not "converge".
Definition: inte_gen.h:86
double tol_rel
The maximum "uncertainty" in the value of the integral.
Definition: inte_gen.h:83
double interror
The uncertainty for the last integration computation.
Definition: inte_gen.h:120
virtual double ginteg(func_t &func, size_t ndim, lfunc_t &a, ufunc_t &b)=0
Integrate function func from to for .

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