RungeKuttaFehlberg.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: RungeKuttaFehlberg.hpp 2457 2010-08-18 14:20:12Z coandrei $"
00002 
00009 #ifndef GPSTK_RUNGE_KUTTA_FEHLBERG_HPP
00010 #define GPSTK_RUNGE_KUTTA_FEHLBERG_HPP
00011 
00012 
00013 //============================================================================
00014 //
00015 //  This file is part of GPSTk, the GPS Toolkit.
00016 //
00017 //  The GPSTk is free software; you can redistribute it and/or modify
00018 //  it under the terms of the GNU Lesser General Public License as published
00019 //  by the Free Software Foundation; either version 2.1 of the License, or
00020 //  any later version.
00021 //
00022 //  The GPSTk is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU Lesser General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU Lesser General Public
00028 //  License along with GPSTk; if not, write to the Free Software Foundation,
00029 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00030 //
00031 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010
00032 //
00033 //============================================================================
00034 
00035 
00036 #include "Integrator.hpp"
00037 
00038 
00039 namespace gpstk
00040 {
00041 
00044 
00057    class RungeKuttaFehlberg : public Integrator
00058    {
00059    public:
00060          // Parametera for RKF78
00061       struct RKF78Param
00062       {
00063          double a[13] ;
00064          double b[13][12] ;
00065          double c1[13] ;
00066          double c2[13] ;
00067       };
00068 
00069    public:
00070 
00072       RungeKuttaFehlberg();
00073 
00075       virtual ~RungeKuttaFehlberg()
00076       { };
00077 
00079       void test();
00080 
00088       virtual Vector<double> integrateTo(const double&           t, 
00089                                          const Vector<double>&   y, 
00090                                          EquationOfMotion*       peom,
00091                                          const double&           tf );
00092       
00094       RungeKuttaFehlberg& setAccuracy(const double& accuracy)
00095       { accuracyEps = accuracy; return (*this);}
00096          
00098       RungeKuttaFehlberg& setMinStepSize(const double& step)
00099       { minStepSize = step; return (*this ); }
00100       
00102       RungeKuttaFehlberg& setAdaptive(const bool& adaptive = true)
00103       { isAdaptive = adaptive; return (*this); }
00104 
00105 
00106    protected:
00107          
00108 
00109       Vector<double> integrateFixedStep(const double&           t, 
00110                                         const Vector<double>&   y, 
00111                                         EquationOfMotion*       peom,
00112                                         const double&           tf );
00113 
00114       Vector<double> integrateAdaptive(const double&           t, 
00115                                        const Vector<double>&   y, 
00116                                        EquationOfMotion*       peom,
00117                                        const double&           tf );
00118       
00119 
00120          // takes one "quality-controlled" Runge-Kutta-Fehlberg step 
00121          // 0 = Success
00122          // 1 = Unable to allocate workspace memory
00123          // 2 = Stepsize underflow
00124       int rkfqcs(double&           x,
00125                  Vector<double>&   y,
00126                  const double&     htry,
00127                  const double&     accuracy,
00128                  EquationOfMotion* peom,
00129                  Vector<double>&   yscal,
00130                  double& hdid,
00131                  double& hnext);
00132          
00133          // RKF78 single step
00134          // 0 = Success
00135          // 1 = Failed to allocate memory
00136       int rkfs78(const double&          x,
00137                  const Vector<double>&  y,
00138                  const double&          h,
00139                  EquationOfMotion*      peom,
00140                  Vector<double>&        yout,
00141                  Vector<double>&        yerr);
00142 
00143    protected:
00144       
00146       double accuracyEps;
00147 
00149       double minStepSize;
00150 
00152       bool isAdaptive;
00153 
00155       static const double RKF_EPS;
00156 
00158       static const double RKF_MAXSTEP;
00159 
00160    private:
00161      
00163       const static struct RKF78Param rkf78_param;
00164       
00165          // Easy accessing RKF78 parameters
00166       double A(int i){ return rkf78_param.a[i]; }
00167 
00168       double B(int i, int j){ return rkf78_param.b[i][j]; }
00169       
00170       double C(int i){ return rkf78_param.c1[i]; }
00171 
00172       double C2(int i){ return rkf78_param.c2[i]; }
00173       
00174       double DC(int i){ return (rkf78_param.c1[i]-rkf78_param.c2[i]); }
00175 
00176 
00177    }; // End of class 'RungeKuttaFehlberg'
00178 
00179       // @}
00180 
00181 }  // End of namespace 'gpstk'
00182 
00183 
00184 #endif // GPSTK_RUNGE_KUTTA_FEHLBERG_HPP
00185 

Generated on Tue May 22 03:31:01 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1