![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006-2012, Andrew W. 00005 Steiner and Jerry Gagelman 00006 00007 This file is part of O2scl. 00008 00009 O2scl is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 O2scl is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00021 00022 ------------------------------------------------------------------- 00023 */ 00024 #ifndef O2SCL_INTE_H 00025 #define O2SCL_INTE_H 00026 00027 #include <cmath> 00028 #include <o2scl/err_hnd.h> 00029 #include <o2scl/funct.h> 00030 00031 #ifndef DOXYGENP 00032 namespace o2scl { 00033 #endif 00034 00035 /** \brief Base integration class [abstract base] 00036 00037 \future It might be useful to have all of the integration 00038 classes report the number of function evaluations used 00039 in addition to the number of iterations which were taken 00040 */ 00041 template<class func_t=funct> class inte { 00042 00043 public: 00044 00045 inte() { 00046 tol_rel=1.0e-8; 00047 tol_abs=1.0e-8; 00048 verbose=0; 00049 interror=0.0; 00050 err_nonconv=true; 00051 last_conv=0; 00052 } 00053 00054 virtual ~inte() {} 00055 00056 /** \brief Verbosity 00057 */ 00058 int verbose; 00059 00060 /// The most recent number of iterations taken 00061 size_t last_iter; 00062 00063 /** \brief The maximum relative uncertainty 00064 in the value of the integral (default \f$ 10^{-8} \f$) 00065 */ 00066 double tol_rel; 00067 00068 /** \brief The maximum absolute uncertainty 00069 in the value of the integral (default \f$ 10^{-8} \f$) 00070 */ 00071 double tol_abs; 00072 00073 /** \brief If true, call the error handler if the routine does not 00074 converge or reach the desired tolerance (default true) 00075 00076 If this is false, the function proceeds normally and 00077 may provide convergence information in \ref last_conv. 00078 */ 00079 bool err_nonconv; 00080 00081 /** \brief Integer indicating convergence properties of 00082 the last call to integ() or integ_err(). 00083 00084 This is zero if the last call to integ() or integ_err() 00085 converged successfully. This variable is particularly useful, in 00086 combination with setting \ref err_nonconv to false, to test for 00087 non-convergence without calling the error handler. 00088 */ 00089 int last_conv; 00090 00091 /** \brief Integrate function \c func from \c a to \c b. 00092 */ 00093 virtual double integ(func_t &func, double a, double b) { 00094 double res; 00095 integ_err(func,a,b,res,this->interror); 00096 return res; 00097 } 00098 00099 /** \brief Integrate function \c func from \c a to \c b and place 00100 the result in \c res and the error in \c err 00101 */ 00102 virtual int integ_err(func_t &func, double a, double b, 00103 double &res, double &err)=0; 00104 00105 /** \brief Return the numerically estimated error in the result from 00106 the last call to integ() 00107 00108 This will quietly return zero if no integrations have been 00109 performed or if the integrator does not estimate the error. 00110 */ 00111 double get_error() { return interror; } 00112 00113 /// Return string denoting type ("inte") 00114 virtual const char *type() { return "inte"; } 00115 00116 #ifndef DOXYGEN_INTERNAL 00117 00118 protected: 00119 00120 /// The uncertainty for the last integration computation 00121 double interror; 00122 00123 #endif 00124 00125 }; 00126 00127 #ifndef DOXYGENP 00128 } 00129 #endif 00130 00131 #endif 00132 00133 00134 00135
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).