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_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_view, 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 public: 00053 00054 nonadapt_step() { 00055 } 00056 00057 virtual ~nonadapt_step() {} 00058 00059 /** 00060 \brief Make an adaptive integration step of the system 00061 \c derivs 00062 00063 This attempts to take a step of size \c h from the point \c 00064 x of an \c n-dimensional system \c derivs starting with \c 00065 y. On exit, \c x and \c y contain the new values at the end 00066 of the step, \c h contains the size of the step, \c dydx_out 00067 contains the derivative at the end of the step, and \c yerr 00068 contains the estimated error at the end of the step. 00069 */ 00070 virtual int astep(double &x, double &h, double xmax, 00071 size_t n, vec_t &y, vec_t &u_dydx_out, 00072 vec_t &yerr, param_t &pa, 00073 func_t &derivs) { 00074 00075 alloc_vec_t dydx; 00076 00077 ao.allocate(dydx,n); 00078 00079 derivs(x,n,y,dydx,pa); 00080 int ret=this->stepp->step(x,h,n,y,dydx,y,yerr,u_dydx_out,pa,derivs); 00081 x+=h; 00082 00083 ao.free(dydx); 00084 00085 return ret; 00086 } 00087 00088 /** 00089 \brief Make an adaptive integration step of the system 00090 \c derivs with derivatives 00091 00092 This attempts to take a step of size \c h from the point \c 00093 x of an \c n-dimensional system \c derivs starting with \c y 00094 and given the initial derivatives \c dydx. On exit, \c x, \c 00095 y and \c dydx contain the new values at the end of the step, 00096 \c h contains the size of the step, \c dydx 00097 contains the derivative at the end of the step, and \c yerr 00098 contains the estimated error at the end of the step. 00099 */ 00100 virtual int astep_derivs(double &x, double &h, double xmax, 00101 size_t n, vec_t &y, vec_t &dydx, 00102 vec_t &yerr, param_t &pa, 00103 func_t &derivs) { 00104 00105 int ret=this->stepp->step(x,h,n,y,dydx,y,yerr,dydx,pa,derivs); 00106 x+=h; 00107 00108 return ret; 00109 } 00110 00111 #ifndef DOXYGEN_INTERNAL 00112 00113 protected: 00114 00115 /// Memory allocator for objects of type \c alloc_vec_t 00116 alloc_t ao; 00117 00118 #endif 00119 00120 }; 00121 00122 #ifndef DOXYGENP 00123 } 00124 #endif 00125 00126 #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