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