Chaste Release::3.1
RungeKuttaFehlbergIvpOdeSolver.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef _RUNGEKUTTAFEHLBERGIVPODESOLVER_HPP_
00037 #define _RUNGEKUTTAFEHLBERGIVPODESOLVER_HPP_
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/base_object.hpp>
00041 
00042 #include "AbstractOneStepIvpOdeSolver.hpp"
00043 
00056 class RungeKuttaFehlbergIvpOdeSolver : public AbstractIvpOdeSolver
00057 {
00058 friend class TestRungeKuttaFehlbergIvpOdeSolver;
00059 
00060 private:
00062     friend class boost::serialization::access;
00069     template<class Archive>
00070     void serialize(Archive & archive, const unsigned int version)
00071     {
00072         // This calls serialize on the base class - all member variables instantiated on construction or temporary.
00073         archive & boost::serialization::base_object<AbstractIvpOdeSolver>(*this);
00074     }
00075 
00076     /*
00077      * All these are here for more efficient memory allocation, rather than
00078      * because they need to be member variables.
00079      */
00080 
00081     double m1932o2197;  
00082     double m7200o2197;  
00083     double m7296o2197;  
00084     double m12o13;      
00085     double m439o216;    
00086     double m3680o513;   
00087     double m845o4104;   
00088     double m8o27;       
00089     double m3544o2565;  
00090     double m1859o4104;  
00091     double m1o360;      
00092     double m128o4275;   
00093     double m2197o75240; 
00094     double m2o55;       
00095     double m25o216;     
00096     double m1408o2565;  
00097     double m2197o4104;  
00099     std::vector<double> mError; 
00101     std::vector<double> mk1;  
00102     std::vector<double> mk2;  
00103     std::vector<double> mk3;  
00104     std::vector<double> mk4;  
00105     std::vector<double> mk5;  
00106     std::vector<double> mk6;  
00107     std::vector<double> myk2; 
00108     std::vector<double> myk3; 
00109     std::vector<double> myk4; 
00110     std::vector<double> myk5; 
00111     std::vector<double> myk6; 
00113 protected:
00114 
00129     void InternalSolve(OdeSolution& rSolution,
00130                        AbstractOdeSystem* pAbstractOdeSystem,
00131                        std::vector<double>& rCurrentYValues,
00132                        std::vector<double>& rWorkingMemory,
00133                        double startTime,
00134                        double endTime,
00135                        double maxTimeStep,
00136                        double minTimeStep,
00137                        double tolerance,
00138                        bool outputSolution);
00139 
00150     void CalculateNextYValue(AbstractOdeSystem* pAbstractOdeSystem,
00151                              double timeStep,
00152                              double time,
00153                              std::vector<double>& rCurrentYValues,
00154                              std::vector<double>& rNextYValues);
00155 
00166     void AdjustStepSize(double& rCurrentStepSize,
00167                         const double& rError,
00168                         const double& rTolerance,
00169                         const double& rMaxTimeStep,
00170                         const double& rMinTimeStep);
00171 
00172 public:
00173 
00177     RungeKuttaFehlbergIvpOdeSolver();
00178 
00199     OdeSolution Solve(AbstractOdeSystem* pAbstractOdeSystem,
00200                       std::vector<double>& rYValues,
00201                       double startTime,
00202                       double endTime,
00203                       double timeStep,
00204                       double ignoredSamplingTime);
00205 
00221     void Solve(AbstractOdeSystem* pAbstractOdeSystem,
00222                std::vector<double>& rYValues,
00223                double startTime,
00224                double endTime,
00225                double timeStep);
00226 
00227 };
00228 
00229 #include "SerializationExportWrapper.hpp"
00230 CHASTE_CLASS_EXPORT(RungeKuttaFehlbergIvpOdeSolver)
00231 
00232 #endif //_RUNGEKUTTAFEHLBERGIVPODESOLVER_HPP_