adapt_step.h

00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006, 2007, 2008, 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 
00024 #ifndef O2SCL_ADAPT_STEP_H
00025 #define O2SCL_ADAPT_STEP_H
00026 
00027 #include <o2scl/odestep.h>
00028 #include <o2scl/gsl_rkck.h>
00029 #include <o2scl/ode_funct.h>
00030 
00031 #ifndef DOXYGENP
00032 namespace o2scl {
00033 #endif
00034 
00035   /** 
00036       \brief Adaptive stepper base
00037       
00038       The adaptive stepper routines are based on several applications
00039       of ordinary ODE steppers (implemented in \ref odestep). Each
00040       adaptive stepper (gsl_astep or nonadapt_step) can be used with
00041       any of the ODE stepper classes (e.g. gsl_rkck). By default,
00042       gsl_rkck is used. To modify the ODE stepper which is used, use
00043       the member function set_step() documented below.
00044 
00045       \note If you use gsl_rkck_fast or gsl_rk8pd_fast, you'll 
00046       need to make sure that the argument \c n to astep() or
00047       astep_derivs() below matches the template size parameter 
00048       given in the ODE stepper. 
00049   */
00050   template<class param_t, class func_t=ode_funct<param_t>, 
00051     class vec_t=ovector_view, class alloc_vec_t=ovector, 
00052     class alloc_t=ovector_alloc> class adapt_step {
00053     
00054       public:
00055     
00056       adapt_step() {
00057         stepp=&def_step;
00058         verbose=0;
00059       }
00060 
00061       virtual ~adapt_step() {}
00062       
00063       /** 
00064           \brief Make an adaptive integration step of the system 
00065           \c derivs 
00066           
00067           This attempts to take a step of size \c h from the point \c
00068           x of an \c n-dimensional system \c derivs starting with \c
00069           y. On exit, \c x and \c y contain the new values at the end
00070           of the step, \c h contains the size of the step.
00071       */
00072       virtual int astep(double &x, double &h, double xmax, size_t n, 
00073                         vec_t &y, param_t &pa, func_t &derivs) 
00074       {
00075         
00076         set_err_ret("Empty function in adapt_step::astep().",
00077                     o2scl::gsl_nobase);
00078       }
00079 
00080       /** 
00081           \brief Make an adaptive integration step of the system 
00082           \c derivs with derivatives
00083           
00084           This attempts to take a step of size \c h from the point \c
00085           x of an \c n-dimensional system \c derivs starting with \c y
00086           and given the initial derivatives \c dydx. On exit, \c x, \c
00087           y and \c dydx contain the new values at the end of the step,
00088           \c h contains the size of the step.
00089       */
00090       virtual int astep_derivs(double &x, double &h, double xmax, size_t n, 
00091                                vec_t &y, vec_t &dydx, param_t &pa, 
00092                                func_t &derivs) 
00093       {
00094         
00095         set_err_ret("Empty function in adapt_step::astep_derivs().",
00096                     o2scl::gsl_nobase);
00097       }
00098     
00099       /// Set output level
00100       int verbose;
00101 
00102       /** 
00103           \brief Set stepper
00104 
00105           This sets the stepper for use in the adaptive step 
00106           routine. If no stepper is specified, then the default
00107           (gsl_rkck) is used.
00108       */
00109       int set_step(odestep<param_t,func_t,vec_t> &step) {
00110         stepp=&step;
00111         return 0;
00112       }
00113   
00114       /// The default stepper
00115       gsl_rkck<param_t,func_t,vec_t,alloc_vec_t,alloc_t> def_step;
00116       
00117 #ifndef DOXYGEN_INTERNAL
00118 
00119     protected:
00120       
00121       /// Pointer to the stepper being used
00122       odestep<param_t,func_t,vec_t> *stepp;
00123     
00124 #endif
00125 
00126     };
00127 
00128 #ifndef DOXYGENP
00129 }
00130 #endif
00131 
00132 #endif

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

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page