00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, 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 [abstract base] 00037 00038 The adaptive stepper routines are based on one or many 00039 applications of ordinary ODE steppers (implemented in \ref 00040 odestep). Each adaptive stepper (gsl_astep or nonadapt_step) can 00041 be used with any of the ODE stepper classes (e.g. gsl_rkck). By 00042 default, gsl_rkck is used. To modify the ODE stepper which is 00043 used, use 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_base, 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, \c dydx_out 00071 contains the derivative at the end of the step, and \c yerr 00072 contains the estimated error at the end of the step. 00073 */ 00074 virtual int astep(double &x, double &h, double xlimit, 00075 size_t n, vec_t &y, vec_t &dydx_out, 00076 vec_t &yerr, param_t &pa, 00077 func_t &derivs)=0; 00078 00079 /** 00080 \brief Make an adaptive integration step of the system 00081 \c derivs with derivatives 00082 00083 This attempts to take a step of size \c h from the point \c 00084 x of an \c n-dimensional system \c derivs starting with \c y 00085 and given the initial derivatives \c dydx. On exit, \c x, \c 00086 y and \c dydx contain the new values at the end of the step, 00087 \c h contains the size of the step, \c dydx contains the 00088 derivative at the end of the step, and \c yerr contains the 00089 estimated error at the end of the step. 00090 */ 00091 virtual int astep_derivs(double &x, double &h, double xlimit, 00092 size_t n, vec_t &y, vec_t &dydx, 00093 vec_t &yerr, param_t &pa, 00094 func_t &derivs)=0; 00095 00096 /** \brief Make an adaptive integration step of the system 00097 \c derivs with derivatives 00098 00099 This function performs an adaptive integration step with the 00100 \c n-dimensional system \c derivs and parameter \c pa. It 00101 Begins at \c x with initial stepsize \c h, ensuring that the 00102 step goes no farther than \c xlimit. At the end of the step, 00103 the size of the step taken is \c h and the new value of \c x 00104 is in \c x_out. Initially, the function values and 00105 derivatives should be specified in \c y and \c dydx. The 00106 function values, derivatives, and the error at the end of 00107 the step are given in \c yout, \c yerr, and \c dydx_out. 00108 Unlike in \c odestep objects, the objects \c y, \c yout, 00109 \c dydx, and \c dydx_out must all be distinct. 00110 */ 00111 virtual int astep_full(double x, double &h, double xlimit, double &x_out, 00112 size_t n, vec_t &y, vec_t &dydx, 00113 vec_t &yout, vec_t &yerr, vec_t &dydx_out, 00114 param_t &pa, func_t &derivs)=0; 00115 00116 /// Set output level 00117 int verbose; 00118 00119 /** 00120 \brief Set stepper 00121 00122 This sets the stepper for use in the adaptive step 00123 routine. If no stepper is specified, then the default 00124 (\ref def_step of type \ref gsl_rkck) is used. 00125 */ 00126 int set_step(odestep<param_t,func_t,vec_t> &step) { 00127 stepp=&step; 00128 return 0; 00129 } 00130 00131 /// The default stepper 00132 gsl_rkck<param_t,func_t,vec_t,alloc_vec_t,alloc_t> def_step; 00133 00134 #ifndef DOXYGEN_INTERNAL 00135 00136 protected: 00137 00138 /// Pointer to the stepper being used 00139 odestep<param_t,func_t,vec_t> *stepp; 00140 00141 #endif 00142 00143 }; 00144 00145 #ifndef DOXYGENP 00146 } 00147 #endif 00148 00149 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page