RungeKuttaFehlbergIvpOdeSolver.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00033 #ifndef _RUNGEKUTTAFEHLBERGIVPODESOLVER_HPP_
00034 #define _RUNGEKUTTAFEHLBERGIVPODESOLVER_HPP_
00035 
00036 #include "AbstractOneStepIvpOdeSolver.hpp"
00037 #include "AbstractOdeSystem.hpp"
00038 #include "OdeSolution.hpp"
00039 
00040 #include <vector>
00041 
00053 class RungeKuttaFehlbergIvpOdeSolver : public AbstractIvpOdeSolver
00054 {
00055 friend class TestRungeKuttaFehlbergIvpOdeSolver;
00056 
00057 private:
00058     /*
00059      * All these are here for more efficient memory allocation, rather than
00060      * because they need to be member variables...
00061      */
00062     double m1932o2197;
00063     double m7200o2197;
00064     double m7296o2197;
00065     double m12o13;
00066     double m439o216;
00067     double m3680o513;
00068     double m845o4104;
00069     double m8o27;
00070     double m3544o2565;
00071     double m1859o4104;
00072     double m1o360;
00073     double m128o4275;
00074     double m2197o75240;
00075     double m2o55;
00076     double m25o216;
00077     double m1408o2565;
00078     double m2197o4104;
00079     std::vector<double> mError;
00080     std::vector<double> mk1;
00081     std::vector<double> mk2;
00082     std::vector<double> mk3;
00083     std::vector<double> mk4;
00084     std::vector<double> mk5;
00085     std::vector<double> mk6;
00086     std::vector<double> myk2;
00087     std::vector<double> myk3;
00088     std::vector<double> myk4;
00089     std::vector<double> myk5;
00090     std::vector<double> myk6;
00091 
00092 protected:
00105     void InternalSolve(OdeSolution& rSolution,
00106                                AbstractOdeSystem* pAbstractOdeSystem,
00107                                std::vector<double>& rCurrentYValues,
00108                                std::vector<double>& rWorkingMemory,
00109                                double startTime,
00110                                double endTime,
00111                                double maxTimeStep,
00112                                double minTimeStep,
00113                                double tolerance,
00114                                bool outputSolution);
00115 
00127     void CalculateNextYValue(AbstractOdeSystem* pAbstractOdeSystem,
00128                                      double timeStep,
00129                                      double time,
00130                                      std::vector<double>& currentYValues,
00131                                      std::vector<double>& nextYValues);
00132 
00143     void AdjustStepSize(double& rCurrentStepSize, const double& rError, const double& rTolerance,
00144                                 const double& rMaxTimeStep, const double& rMinTimeStep);
00145 
00146 public:
00147 
00148     OdeSolution Solve(AbstractOdeSystem* pAbstractOdeSystem,
00149                               std::vector<double>& rYValues,
00150                               double startTime,
00151                               double endTime,
00152                               double timeStep,
00153                               double ignoredSamplingTime);
00154 
00155     void Solve(AbstractOdeSystem* pAbstractOdeSystem,
00156                        std::vector<double>& rYValues,
00157                        double startTime,
00158                        double endTime,
00159                        double timeStep);
00160 
00161     RungeKuttaFehlbergIvpOdeSolver()
00162       : m1932o2197(1932.0/2197.0),// you need the .0 s - caused me no end of trouble.
00163         m7200o2197(7200.0/2197.0),
00164         m7296o2197(7296.0/2197.0),
00165         m12o13(12.0/13.0),
00166         m439o216(439.0/216.0),
00167         m3680o513(3680.0/513.0),
00168         m845o4104(845.0/4104.0),
00169         m8o27(8.0/27.0),
00170         m3544o2565(3544.0/2565.0),
00171         m1859o4104(1859.0/4104.0),
00172         m1o360(1.0/360.0),
00173         m128o4275(128.0/4275.0),
00174         m2197o75240(2197.0/75240.0),
00175         m2o55(2.0/55.0),
00176         m25o216(25.0/216.0),
00177         m1408o2565(1408.0/2565.0),
00178         m2197o4104(2197.0/4104.0)
00179     {
00180     };
00181 };
00182 
00183 #endif //_RUNGEKUTTAFEHLBERGIVPODESOLVER_HPP_

Generated on Wed Mar 18 12:51:56 2009 for Chaste by  doxygen 1.5.5