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 _ABSTRACTODESYSTEM_HPP_
00030 #define _ABSTRACTODESYSTEM_HPP_
00031
00032 #include <vector>
00033 #include <string>
00034
00035
00036 #include "ChasteSerialization.hpp"
00037 #include <boost/serialization/split_member.hpp>
00038 #include <boost/serialization/vector.hpp>
00039 #include <boost/serialization/version.hpp>
00040 #include "ClassIsAbstract.hpp"
00041
00042 #include "AbstractParameterisedSystem.hpp"
00043 #include "Exception.hpp"
00044
00079 class AbstractOdeSystem : public AbstractParameterisedSystem<std::vector<double> >
00080 {
00081 friend class TestAbstractOdeSystem;
00082
00083 private:
00084
00085
00086 friend class boost::serialization::access;
00093 template<class Archive>
00094 void save(Archive & archive, const unsigned int version) const
00095 {
00096
00097
00098
00099
00100 archive & mNumberOfStateVariables;
00101 archive & mUseAnalyticJacobian;
00102 archive & mStateVariables;
00103 archive & mParameters;
00104
00105 if (version > 0)
00106 {
00107 archive & rGetParameterNames();
00108 }
00109
00110
00111
00112
00113 }
00120 template<class Archive>
00121 void load(Archive & archive, const unsigned int version)
00122 {
00123 archive & mNumberOfStateVariables;
00124 archive & mUseAnalyticJacobian;
00125 archive & mStateVariables;
00126 archive & mParameters;
00127
00128 if (version > 0)
00129 {
00130 std::vector<std::string> param_names;
00131 archive & param_names;
00132
00133 if (param_names.size() != rGetParameterNames().size())
00134 {
00135 EXCEPTION("Number of ODE parameters in archive does not match number in class.");
00136 }
00137 for (unsigned i=0; i<param_names.size(); ++i)
00138 {
00139 if (param_names[i] != rGetParameterNames()[i])
00140 {
00141 std::string message = "ODE system parameter names do not match: '"
00142 + param_names[i] + "' in archive but '" + rGetParameterNames()[i] + "' in class.";
00143 EXCEPTION(message);
00144 }
00145 }
00146 }
00147 }
00148 BOOST_SERIALIZATION_SPLIT_MEMBER()
00149
00150 protected:
00151
00153 bool mUseAnalyticJacobian;
00154
00163 std::string DumpState(const std::string& rMessage,
00164 std::vector<double> Y = std::vector<double>());
00165
00166 public:
00167
00173 AbstractOdeSystem(unsigned numberOfStateVariables);
00174
00178 virtual ~AbstractOdeSystem();
00179
00187 virtual void EvaluateYDerivatives(double time, const std::vector<double>& rY,
00188 std::vector<double>& rDY)=0;
00189
00196 void SetDefaultInitialConditions(const std::vector<double>& rInitialConditions);
00197
00205 void SetDefaultInitialCondition(unsigned index, double initialCondition);
00206
00210 std::vector<double> GetInitialConditions() const;
00211
00217 void SetStateVariables(const std::vector<double>& rStateVariables);
00218
00230 virtual bool CalculateStoppingEvent(double time, const std::vector<double>& rY);
00231
00242 virtual double CalculateRootFunction(double time, const std::vector<double>& rY);
00243
00249 bool GetUseAnalyticJacobian();
00250
00256 const std::vector<double>& rGetConstStateVariables() const;
00257 };
00258
00259 CLASS_IS_ABSTRACT(AbstractOdeSystem)
00260 BOOST_CLASS_VERSION(AbstractOdeSystem, 1u)
00261
00262 #endif //_ABSTRACTODESYSTEM_HPP_