inte.h

00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006, 2007, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef O2SCL_INTE_H
00024 #define O2SCL_INTE_H
00025 
00026 #include <cmath>
00027 #include <o2scl/err_hnd.h>
00028 
00029 #ifndef DOXYGENP
00030 namespace o2scl {
00031 #endif
00032 
00033   /** \brief Base integration class
00034    */
00035   template<class param_t, class func_t> class inte {
00036   
00037   public:
00038   
00039     /** \brief Verbosity
00040      */
00041     int verbose;
00042   
00043     /** \brief The maximum relative uncertainty 
00044         in the value of the integral (default \f$ 10^{-8} \f$)
00045      */
00046     double tolf;
00047     
00048     /** \brief The maximum absolute uncertainty 
00049         in the value of the integral  (default \f$ 10^{-8} \f$)
00050      */
00051     double tolx;
00052   
00053     inte() {
00054       tolf=1.0e-8;
00055       tolx=1.0e-8;
00056       verbose=0;
00057       interror=0.0;
00058     }
00059 
00060     virtual ~inte() {}
00061 
00062     /** \brief Integrate function \c func from \c a to \c b.
00063      */
00064     virtual double integ(func_t &func, double a, double b, param_t &pa) {
00065       return 0.0;
00066     }
00067   
00068     /** \brief Integrate function \c func from \c a to \c b and place
00069         the result in \c res and the error in \c err
00070         
00071         Ideally, if this function succeeds, then \c err should be
00072         less than or close to \ref tolf. 
00073     */
00074     virtual int integ_err(func_t &func, double a, double b, 
00075                           param_t &pa, double &res, double &err) {
00076       return 0;
00077     }
00078   
00079     /** \brief Return the error in the result from the last call to 
00080         integ()
00081       
00082         This will quietly return zero if no integrations have been
00083         performed.
00084     */
00085     double get_error() { return interror; }
00086   
00087     /// Return string denoting type ("inte")
00088     virtual const char *type() { return "inte"; }
00089   
00090 #ifndef DOXYGEN_INTERNAL
00091   
00092   protected:
00093   
00094     /// The uncertainty for the last integration computation
00095     double interror;
00096   
00097 #endif
00098   
00099   };
00100 
00101 #ifndef DOXYGENP
00102 }
00103 #endif
00104 
00105 #endif
00106 
00107 
00108 
00109 

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.