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 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 00030 #ifndef DOXYGENP 00031 namespace o2scl { 00032 #endif 00033 00034 /** 00035 \brief Adaptive stepper base 00036 00037 The adaptive stepper is based on \ref gsl_rkck unless 00038 otherwise specified in set_step(). 00039 */ 00040 template<class param_t, class func_t, class vec_t=ovector_view, 00041 class alloc_vec_t=ovector, class alloc_t=ovector_alloc> 00042 class adapt_step { 00043 00044 public: 00045 00046 adapt_step() { 00047 stepp=&def_step; 00048 verbose=0; 00049 } 00050 00051 virtual ~adapt_step() {} 00052 00053 /** 00054 \brief Make an adaptive integration step of the system 00055 \c derivs 00056 00057 This attempts to take a step of size \c h from the point \c 00058 x of an \c n-dimensional system \c derivs starting with \c 00059 y. On exit, \c x and \c y contain the new values at the end 00060 of the step, \c h contains the size of the step. 00061 */ 00062 virtual int astep(double &x, double &h, double xmax, size_t n, 00063 vec_t &y, param_t &pa, func_t &derivs) 00064 { 00065 00066 set_err_ret("Empty function in adapt_step::astep().", 00067 o2scl::gsl_nobase); 00068 } 00069 00070 /** 00071 \brief Make an adaptive integration step of the system 00072 \c derivs with derivatives 00073 00074 This attempts to take a step of size \c h from the point \c 00075 x of an \c n-dimensional system \c derivs starting with \c y 00076 and given the initial derivatives \c dydx. On exit, \c x, \c 00077 y and \c dydx contain the new values at the end of the step, 00078 \c h contains the size of the step. 00079 */ 00080 virtual int astep_derivs(double &x, double &h, double xmax, size_t n, 00081 vec_t &y, vec_t &dydx, param_t &pa, 00082 func_t &derivs) 00083 { 00084 00085 set_err_ret("Empty function in adapt_step::astep_derivs().", 00086 o2scl::gsl_nobase); 00087 } 00088 00089 /// Set output level 00090 int verbose; 00091 00092 /** 00093 \brief Set stepper 00094 00095 This sets the stepper for use in the adaptive step 00096 routine. If no stepper is specified, then the default 00097 (gsl_rkck) is used. 00098 */ 00099 int set_step(odestep<param_t,func_t,vec_t> &step) { 00100 stepp=&step; 00101 return 0; 00102 } 00103 00104 /// The default stepper 00105 gsl_rkck<param_t,func_t,vec_t,alloc_vec_t,alloc_t> def_step; 00106 00107 #ifndef DOXYGEN_INTERNAL 00108 00109 protected: 00110 00111 /// Pointer to the stepper being used 00112 odestep<param_t,func_t,vec_t> *stepp; 00113 00114 #endif 00115 00116 }; 00117 00118 #ifndef DOXYGENP 00119 } 00120 #endif 00121 00122 #endif