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 #include <algorithm>
00035
00036
00037 #include "ChasteSerialization.hpp"
00038 #include <boost/serialization/split_member.hpp>
00039 #include <boost/serialization/vector.hpp>
00040 #include <boost/serialization/version.hpp>
00041 #include "ClassIsAbstract.hpp"
00042
00043 #include "AbstractParameterisedSystem.hpp"
00044 #include "Exception.hpp"
00045
00080 class AbstractOdeSystem : public AbstractParameterisedSystem<std::vector<double> >
00081 {
00082 friend class TestAbstractOdeSystem;
00083
00084 private:
00085
00086
00087 friend class boost::serialization::access;
00094 template<class Archive>
00095 void save(Archive & archive, const unsigned int version) const
00096 {
00097
00098
00099
00100
00101 archive & mNumberOfStateVariables;
00102 archive & mUseAnalyticJacobian;
00103 archive & mStateVariables;
00104 archive & mParameters;
00105
00106 if (version > 0)
00107 {
00108 archive & rGetParameterNames();
00109 }
00110
00111
00112
00113
00114 }
00121 template<class Archive>
00122 void load(Archive & archive, const unsigned int version)
00123 {
00124 archive & mNumberOfStateVariables;
00125 archive & mUseAnalyticJacobian;
00126 archive & mStateVariables;
00127 std::vector<double> parameters;
00128 archive & parameters;
00129
00130 if (version > 0)
00131 {
00132 std::vector<std::string> param_names;
00133 archive & param_names;
00134
00135 if (mParameters.size() != rGetParameterNames().size())
00136 {
00137
00138 if (param_names.size() != rGetParameterNames().size())
00139 {
00140 EXCEPTION("Number of ODE parameters in archive does not match number in class.");
00141 }
00142 mParameters.resize(rGetParameterNames().size());
00143 }
00144
00145
00146
00147 std::vector<unsigned> index_map(param_names.size());
00148 for (unsigned i=0; i<param_names.size(); ++i)
00149 {
00150 index_map[i] = find(rGetParameterNames().begin(), rGetParameterNames().end(), param_names[i])
00151 - rGetParameterNames().begin();
00152 if (index_map[i] == rGetParameterNames().size())
00153 {
00154 EXCEPTION("Archive specifies a parameter '" + param_names[i] + "' which does not appear in this class.");
00155 }
00156 }
00157
00158 for (unsigned i=0; i<param_names.size(); ++i)
00159 {
00160 mParameters[index_map[i]] = parameters[i];
00161 }
00162 }
00163 else
00164 {
00165 mParameters = parameters;
00166 }
00167 }
00168 BOOST_SERIALIZATION_SPLIT_MEMBER()
00169
00170 protected:
00171
00173 bool mUseAnalyticJacobian;
00174
00183 std::string DumpState(const std::string& rMessage,
00184 std::vector<double> Y = std::vector<double>());
00185
00186 public:
00187
00193 AbstractOdeSystem(unsigned numberOfStateVariables);
00194
00198 virtual ~AbstractOdeSystem();
00199
00207 virtual void EvaluateYDerivatives(double time, const std::vector<double>& rY,
00208 std::vector<double>& rDY)=0;
00209
00221 virtual bool CalculateStoppingEvent(double time, const std::vector<double>& rY);
00222
00233 virtual double CalculateRootFunction(double time, const std::vector<double>& rY);
00234
00240 bool GetUseAnalyticJacobian();
00241
00247 const std::vector<double>& rGetConstStateVariables() const;
00248 };
00249
00250 CLASS_IS_ABSTRACT(AbstractOdeSystem)
00251 BOOST_CLASS_VERSION(AbstractOdeSystem, 1u)
00252
00253 #endif //_ABSTRACTODESYSTEM_HPP_