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_NONADAPT_STEP_H 00025 #define O2SCL_NONADAPT_STEP_H 00026 00027 #include <o2scl/adapt_step.h> 00028 #include <gsl/gsl_math.h> 00029 #include <gsl/gsl_odeiv.h> 00030 00031 #ifndef DOXYGENP 00032 namespace o2scl { 00033 #endif 00034 00035 /** 00036 \brief An non-adaptive stepper implementation of \ref adapt_step. 00037 00038 This class simply calls the specified ODE stepper without any 00039 attempt to modify the size of the step, and is primarily useful 00040 to allow for simple comparisons between adaptive and 00041 non-adaptive solution. To modify the ODE stepper which is used, 00042 use the adapt_step::set_step(). 00043 00044 \future Modify so that memory allocation/deallocation is only 00045 performed when necessary 00046 */ 00047 template<class param_t, class func_t=ode_funct<param_t>, 00048 class vec_t=ovector_base, class alloc_vec_t=ovector, 00049 class alloc_t=ovector_alloc> class nonadapt_step : 00050 public adapt_step<param_t,func_t,vec_t,alloc_vec_t,alloc_t> { 00051 00052 #ifndef DOXYGEN_INTERNAL 00053 00054 protected: 00055 00056 /// The allocated vector size 00057 size_t msize; 00058 00059 /** 00060 \brief Internal storage for dydx 00061 00062 \comment 00063 This isn't named dydx so that we can name function 00064 arguments dydx in astep_derivs(). 00065 \endcomment 00066 */ 00067 alloc_vec_t dydx_int; 00068 00069 /// Memory allocator for objects of type \c alloc_vec_t 00070 alloc_t ao; 00071 00072 #endif 00073 00074 public: 00075 00076 nonadapt_step() { 00077 msize=0; 00078 } 00079 00080 virtual ~nonadapt_step() { 00081 if (msize>0) { 00082 ao.free(dydx_int); 00083 } 00084 } 00085 00086 /** 00087 \brief Make an adaptive integration step of the system 00088 \c derivs 00089 00090 This attempts to take a step of size \c h from the point \c 00091 x of an \c n-dimensional system \c derivs starting with \c 00092 y. On exit, \c x and \c y contain the new values at the end 00093 of the step, \c h contains the size of the step, \c dydx_out 00094 contains the derivative at the end of the step, and \c yerr 00095 contains the estimated error at the end of the step. 00096 00097 If the base stepper returns a non-zero value, that 00098 value is passed on as the return value of <tt>astep()</tt>, 00099 though the input \c y may still have been modified by 00100 the base stepper. 00101 00102 */ 00103 virtual int astep(double &x, double &h, double xmax, 00104 size_t n, vec_t &y, vec_t &u_dydx_out, 00105 vec_t &yerr, param_t &pa, 00106 func_t &derivs) { 00107 00108 if (n!=msize) { 00109 ao.allocate(dydx_int,n); 00110 } 00111 00112 derivs(x,n,y,dydx_int,pa); 00113 int ret=this->stepp->step(x,h,n,y,dydx_int,y,yerr, 00114 u_dydx_out,pa,derivs); 00115 x+=h; 00116 00117 return ret; 00118 } 00119 00120 /** 00121 \brief Make an adaptive integration step of the system 00122 \c derivs with derivatives 00123 00124 This attempts to take a step of size \c h from the point \c 00125 x of an \c n-dimensional system \c derivs starting with \c y 00126 and given the initial derivatives \c dydx. On exit, \c x, \c 00127 y and \c dydx contain the new values at the end of the step, 00128 \c h contains the size of the step, \c dydx 00129 contains the derivative at the end of the step, and \c yerr 00130 contains the estimated error at the end of the step. 00131 00132 If the base stepper returns a non-zero value, that value is 00133 passed on as the return value of <tt>astep()</tt>, though the 00134 inputs \c y and \c dydx may still have been modified by the 00135 base stepper. 00136 00137 */ 00138 virtual int astep_derivs(double &x, double &h, double xmax, 00139 size_t n, vec_t &y, vec_t &dydx, 00140 vec_t &yerr, param_t &pa, 00141 func_t &derivs) { 00142 00143 int ret=this->stepp->step(x,h,n,y,dydx,y,yerr,dydx,pa,derivs); 00144 x+=h; 00145 00146 return ret; 00147 } 00148 00149 }; 00150 00151 #ifndef DOXYGENP 00152 } 00153 #endif 00154 00155 #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