nonadapt_step.h

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   /** \brief An non-adaptive stepper implementation of \ref adapt_step.
00036    */
00037   template<class param_t, class func_t, class vec_t=ovector_view, 
00038     class alloc_vec_t=ovector, class alloc_t=ovector_alloc> 
00039     class nonadapt_step : 
00040   public adapt_step<param_t,func_t,vec_t,alloc_vec_t,alloc_t> {
00041     
00042     public:
00043     
00044     nonadapt_step()  {
00045     }
00046       
00047     virtual ~nonadapt_step() {}
00048 
00049     /** \brief Make an adaptive integration step of the system 
00050         \c derivs 
00051           
00052         This attempts to take a step of size \c h from the point \c x
00053         of an \c n-dimensional system \c derivs starting with \c y. On
00054         exit, \c x and \c y contain the new values at the end of the
00055         step and \c h contains the size of the step. 
00056     */
00057     virtual int astep(double &x, double &h, double xmax, size_t n, 
00058                       vec_t &y, param_t &pa, func_t &derivs) 
00059     {
00060       alloc_vec_t dydx, yerr;
00061 
00062       ao.allocate(dydx,n);
00063       ao.allocate(yerr,n);
00064         
00065       derivs(x,n,y,dydx,pa);
00066       int ret=this->stepp->step(x,h,n,y,dydx,y,yerr,dydx,pa,derivs);
00067       x+=h;
00068 
00069       ao.free(dydx);
00070       ao.free(yerr);
00071 
00072       return ret;
00073     }
00074       
00075     /** \brief Make an adaptive integration step of the system 
00076         \c derivs 
00077           
00078         This attempts to take a step of size \c h from the point \c x
00079         of an \c n-dimensional system \c derivs starting with \c y. On
00080         exit, \c x and \c y contain the new values at the end of the
00081         step and \c h contains the size of the step. 
00082     */
00083     virtual int astep_derivs(double &x, double &h, double xmax, size_t n, 
00084                              vec_t &y, vec_t &dydx, param_t &pa, 
00085                              func_t &derivs) 
00086     {
00087       alloc_vec_t yerr;
00088 
00089       ao.allocate(yerr,n);
00090         
00091       int ret=this->stepp->step(x,h,n,y,dydx,y,yerr,dydx,pa,derivs);
00092       x+=h;
00093 
00094       ao.free(yerr);
00095 
00096       return ret;
00097     }
00098       
00099 #ifndef DOXYGEN_INTERNAL
00100 
00101     protected:
00102 
00103     /// Memory allocator for objects of type \c alloc_vec_t
00104     alloc_t ao;
00105       
00106 #endif
00107       
00108   };
00109   
00110 #ifndef DOXYGENP
00111 }
00112 #endif
00113 
00114 #endif

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.