All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inte_gen.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2014, 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  At present, the only implementation of this abstract base is in
59  \ref o2scl::inte_gen_comp .
60 
61  \future It might be interesting to construct a child class of
62  \ref o2scl::inte_gen which automatically transforms variables to
63  a hypercube and then applies a child of \ref o2scl::inte_multi
64  to do the integration.
65  */
66  template<class func_t, class lfunc_t, class ufunc_t,
68 
69  public:
70 
71  inte_gen() {
72  tol_rel=1.0e-8;
73  verbose=0;
74  interror=0.0;
75  err_nonconv=true;
76  }
77 
78  virtual ~inte_gen() {}
79 
80  /** \brief Verbosity
81  */
82  int verbose;
83 
84  /** \brief The maximum "uncertainty" in the value of the integral
85  */
86  double tol_rel;
87 
88  /// If true, call the error handler if the routine does not "converge"
90 
91  /** \brief Integrate function \c func from
92  \f$ x_i=a_i(x_i) \f$ to \f$ x_i=b_i(x_i) \f$ for
93  \f$ 0<i<\mathrm{ndim}-1 \f$.
94  */
95  virtual double ginteg(func_t &func, size_t ndim, lfunc_t &a, ufunc_t &b)=0;
96 
97  /** \brief Integrate function \c func from
98  \f$ x_i=a_i(x_i) \f$ to \f$ x_i=b_i(x_i) \f$ for
99  \f$ 0<i<\mathrm{ndim}-1 \f$.
100  */
101  virtual int ginteg_err(func_t &func, size_t ndim, lfunc_t &a,
102  ufunc_t &b, double &res, double &err) {
103  res=ginteg(func,ndim,a,b);
104  return 0;
105  }
106 
107  /** \brief Return the error in the result from the last call to
108  ginteg() or ginteg_err()
109 
110  This will quietly return zero if no integrations have been
111  performed.
112  */
113  double get_error() { return interror; }
114 
115  /// Return string denoting type ("inte_gen")
116  const char *type() { return "inte_gen"; }
117 
118 #ifndef DOXYGEN_INTERNAL
119 
120  protected:
121 
122  /// The uncertainty for the last integration computation
123  double interror;
124 
125 #endif
126 
127  };
128 
129 #ifndef DOXYGEN_NO_O2NS
130 }
131 #endif
132 
133 #endif
134 
135 
136 
137 
138 
139 
int verbose
Verbosity.
Definition: inte_gen.h:82
double get_error()
Return the error in the result from the last call to ginteg() or ginteg_err()
Definition: inte_gen.h:113
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:101
const char * type()
Return string denoting type ("inte_gen")
Definition: inte_gen.h:116
Generalized multi-dimensional integration [abstract base].
Definition: inte_gen.h:67
bool err_nonconv
If true, call the error handler if the routine does not "converge".
Definition: inte_gen.h:89
double tol_rel
The maximum "uncertainty" in the value of the integral.
Definition: inte_gen.h:86
double interror
The uncertainty for the last integration computation.
Definition: inte_gen.h:123
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).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..