BackwardEulerIvpOdeSolver.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 #ifndef BACKWARDEULERIVPODESOLVER_HPP_
00030 #define BACKWARDEULERIVPODESOLVER_HPP_
00031 
00032 #include "AbstractOneStepIvpOdeSolver.hpp"
00033 #include "AbstractOdeSystemWithAnalyticJacobian.hpp"
00034 
00035 #include <boost/serialization/access.hpp>
00036 #include <boost/serialization/base_object.hpp>
00037 
00038 #include "AbstractOneStepIvpOdeSolver.hpp"
00039 
00040 // Needs to be included last
00041 #include <boost/serialization/export.hpp>
00042 
00047 class BackwardEulerIvpOdeSolver  : public AbstractOneStepIvpOdeSolver
00048 {
00049 private:
00051     friend class boost::serialization::access;
00058     template<class Archive>
00059     void serialize(Archive & archive, const unsigned int version)
00060     {
00061         // This calls serialize on the base class.
00062         archive & boost::serialization::base_object<AbstractOneStepIvpOdeSolver>(*this);
00063         //archive & mSizeOfOdeSystem; - this done in save and load construct now.
00064         archive & mNumericalJacobianEpsilon;
00065         archive & mForceUseOfNumericalJacobian;
00066     }
00067 
00069     unsigned mSizeOfOdeSystem;
00070 
00072     double mNumericalJacobianEpsilon;
00073 
00078     bool mForceUseOfNumericalJacobian;
00079 
00080     /*
00081      * NOTE: we use (unsafe) double pointers here rather than
00082      * std::vectors because using std::vectors would lead to a
00083      * slow down by a factor of about 4.
00084      */
00085 
00087     double* mResidual;
00088 
00090     double** mJacobian;
00091 
00093     double* mUpdate;
00094 
00104     void ComputeResidual(AbstractOdeSystem* pAbstractOdeSystem,
00105                          double timeStep,
00106                          double time,
00107                          std::vector<double>& rCurrentYValues,
00108                          std::vector<double>& rCurrentGuess);
00109 
00119     void ComputeJacobian(AbstractOdeSystem* pAbstractOdeSystem,
00120                          double timeStep,
00121                          double time,
00122                          std::vector<double>& rCurrentYValues,
00123                          std::vector<double>& rCurrentGuess);
00124 
00131     void SolveLinearSystem();
00132 
00140     double ComputeNorm(double* pVector);
00141 
00151     void ComputeNumericalJacobian(AbstractOdeSystem* pAbstractOdeSystem,
00152                                   double timeStep,
00153                                   double time,
00154                                   std::vector<double>& rCurrentYValues,
00155                                   std::vector<double>& rCurrentGuess);
00156 
00157 protected:
00158 
00172     void CalculateNextYValue(AbstractOdeSystem* pAbstractOdeSystem,
00173                              double timeStep,
00174                              double time,
00175                              std::vector<double>& rCurrentYValues,
00176                              std::vector<double>& rNextYValues);
00177 
00178 public:
00179 
00185     BackwardEulerIvpOdeSolver(unsigned sizeOfOdeSystem);
00186 
00190     ~BackwardEulerIvpOdeSolver();
00191 
00198     void SetEpsilonForNumericalJacobian(double epsilon);
00199 
00204     void ForceUseOfNumericalJacobian();
00205     
00211      unsigned GetSystemSize() const {return mSizeOfOdeSystem;};
00212 };
00213 
00214 BOOST_CLASS_EXPORT(BackwardEulerIvpOdeSolver);
00215 
00216 namespace boost
00217 {
00218 namespace serialization
00219 {
00224 template<class Archive>
00225 inline void save_construct_data(
00226     Archive & ar, const BackwardEulerIvpOdeSolver * t, const unsigned int file_version)
00227 {
00228     const unsigned system_size = t->GetSystemSize();
00229     ar & system_size;
00230 }  
00231     
00238 template<class Archive>
00239 inline void load_construct_data(
00240     Archive & ar, BackwardEulerIvpOdeSolver * t, const unsigned int file_version)
00241 {
00242      unsigned ode_system_size;
00243      ar >> ode_system_size;
00244      ::new(t)BackwardEulerIvpOdeSolver(ode_system_size);
00245 }
00246 }
00247 } // namespace ...
00248 
00249 #endif /*BACKWARDEULERIVPODESOLVER_HPP_*/

Generated on Tue Aug 4 16:10:24 2009 for Chaste by  doxygen 1.5.5