BackwardEulerIvpOdeSolver.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 "ChasteSerialization.hpp"
00036 #include <boost/serialization/base_object.hpp>
00037 
00038 #include "AbstractOneStepIvpOdeSolver.hpp"
00039 
00044 class BackwardEulerIvpOdeSolver  : public AbstractOneStepIvpOdeSolver
00045 {
00046 private:
00048     friend class boost::serialization::access;
00055     template<class Archive>
00056     void serialize(Archive & archive, const unsigned int version)
00057     {
00058         // This calls serialize on the base class.
00059         archive & boost::serialization::base_object<AbstractOneStepIvpOdeSolver>(*this);
00060         //archive & mSizeOfOdeSystem; - this done in save and load construct now.
00061         archive & mNumericalJacobianEpsilon;
00062         archive & mForceUseOfNumericalJacobian;
00063     }
00064 
00066     unsigned mSizeOfOdeSystem;
00067 
00069     double mNumericalJacobianEpsilon;
00070 
00075     bool mForceUseOfNumericalJacobian;
00076 
00077     /*
00078      * NOTE: we use (unsafe) double pointers here rather than
00079      * std::vectors because using std::vectors would lead to a
00080      * slow down by a factor of about 4.
00081      */
00082 
00084     double* mResidual;
00085 
00087     double** mJacobian;
00088 
00090     double* mUpdate;
00091 
00101     void ComputeResidual(AbstractOdeSystem* pAbstractOdeSystem,
00102                          double timeStep,
00103                          double time,
00104                          std::vector<double>& rCurrentYValues,
00105                          std::vector<double>& rCurrentGuess);
00106 
00116     void ComputeJacobian(AbstractOdeSystem* pAbstractOdeSystem,
00117                          double timeStep,
00118                          double time,
00119                          std::vector<double>& rCurrentYValues,
00120                          std::vector<double>& rCurrentGuess);
00121 
00128     void SolveLinearSystem();
00129 
00137     double ComputeNorm(double* pVector);
00138 
00148     void ComputeNumericalJacobian(AbstractOdeSystem* pAbstractOdeSystem,
00149                                   double timeStep,
00150                                   double time,
00151                                   std::vector<double>& rCurrentYValues,
00152                                   std::vector<double>& rCurrentGuess);
00153 
00154 protected:
00155 
00169     void CalculateNextYValue(AbstractOdeSystem* pAbstractOdeSystem,
00170                              double timeStep,
00171                              double time,
00172                              std::vector<double>& rCurrentYValues,
00173                              std::vector<double>& rNextYValues);
00174 
00175 public:
00176 
00182     BackwardEulerIvpOdeSolver(unsigned sizeOfOdeSystem);
00183 
00187     ~BackwardEulerIvpOdeSolver();
00188 
00195     void SetEpsilonForNumericalJacobian(double epsilon);
00196 
00201     void ForceUseOfNumericalJacobian();
00202 
00208      unsigned GetSystemSize() const {return mSizeOfOdeSystem;};
00209 };
00210 
00211 #include "SerializationExportWrapper.hpp"
00212 CHASTE_CLASS_EXPORT(BackwardEulerIvpOdeSolver)
00213 
00214 namespace boost
00215 {
00216 namespace serialization
00217 {
00222 template<class Archive>
00223 inline void save_construct_data(
00224     Archive & ar, const BackwardEulerIvpOdeSolver * t, const unsigned int file_version)
00225 {
00226     const unsigned system_size = t->GetSystemSize();
00227     ar & system_size;
00228 }
00229 
00236 template<class Archive>
00237 inline void load_construct_data(
00238     Archive & ar, BackwardEulerIvpOdeSolver * t, const unsigned int file_version)
00239 {
00240      unsigned ode_system_size;
00241      ar >> ode_system_size;
00242      ::new(t)BackwardEulerIvpOdeSolver(ode_system_size);
00243 }
00244 }
00245 } // namespace ...
00246 
00247 #endif /*BACKWARDEULERIVPODESOLVER_HPP_*/

Generated on Tue May 31 14:31:48 2011 for Chaste by  doxygen 1.5.5