00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00062 archive & boost::serialization::base_object<AbstractOneStepIvpOdeSolver>(*this);
00063
00064 archive & mNumericalJacobianEpsilon;
00065 archive & mForceUseOfNumericalJacobian;
00066 }
00067
00069 unsigned mSizeOfOdeSystem;
00070
00072 double mNumericalJacobianEpsilon;
00073
00078 bool mForceUseOfNumericalJacobian;
00079
00080
00081
00082
00083
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 }
00248
00249 #endif