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
00030 #ifndef _ABSTRACTODESYSTEM_HPP_
00031 #define _ABSTRACTODESYSTEM_HPP_
00032
00033 #include <vector>
00034 #include <string>
00035 #include <cassert>
00036
00037 #include <boost/shared_ptr.hpp>
00038
00039 #include "Exception.hpp"
00040 #include "AbstractOdeSystemInformation.hpp"
00041
00046 class AbstractOdeSystem
00047 {
00048 friend class TestAbstractOdeSystem;
00049
00050 protected:
00051 unsigned mNumberOfStateVariables;
00052 std::vector<double> mStateVariables;
00053
00060 boost::shared_ptr<AbstractOdeSystemInformation> mpSystemInfo;
00061
00063 bool mUseAnalytic;
00064
00065 public:
00071 AbstractOdeSystem(unsigned numberOfStateVariables = 0);
00072
00076 virtual ~AbstractOdeSystem();
00077
00085 virtual void EvaluateYDerivatives(double time, const std::vector<double> &rY,
00086 std::vector<double> &rDY)=0;
00087
00088 unsigned GetNumberOfStateVariables() const
00089 {
00090 return mNumberOfStateVariables;
00091 }
00092
00093
00094 void SetInitialConditions(const std::vector<double>& rInitialConditions)
00095 {
00096 if (rInitialConditions.size() != mNumberOfStateVariables)
00097 {
00098 EXCEPTION("The number of initial conditions must be that of the number of state variables");
00099 }
00100 assert(mpSystemInfo);
00101 mpSystemInfo->SetInitialConditions(rInitialConditions);
00102 }
00103
00104 void SetInitialConditionsComponent(unsigned index, double initialCondition)
00105 {
00106 if ( index >= mNumberOfStateVariables)
00107 {
00108 EXCEPTION("Index is greater than the number of state variables");
00109 }
00110 assert(mpSystemInfo);
00111 mpSystemInfo->SetInitialConditionsComponent(index, initialCondition);
00112 }
00113
00114
00115 std::vector<double> GetInitialConditions() const
00116 {
00117 assert(mpSystemInfo);
00118 return mpSystemInfo->GetInitialConditions();
00119 }
00120
00121 void SetStateVariables(const std::vector<double>& rStateVariables)
00122 {
00123 if ( mNumberOfStateVariables != rStateVariables.size() )
00124 {
00125 EXCEPTION("The size of the passed in vector must be that of the number of state variables");
00126 }
00127 mStateVariables = rStateVariables;
00128 }
00129
00130 std::vector<double>& rGetStateVariables()
00131 {
00132 return mStateVariables;
00133 }
00134
00135 std::vector<std::string>& rGetVariableNames()
00136 {
00137 assert(mpSystemInfo);
00138 return mpSystemInfo->rGetVariableNames();
00139 }
00140
00141 std::vector<std::string>& rGetVariableUnits()
00142 {
00143 assert(mpSystemInfo);
00144 return mpSystemInfo->rGetVariableUnits();
00145 }
00146
00155 virtual bool CalculateStoppingEvent(double time, const std::vector<double> &rY);
00156
00164 virtual double CalculateRootFunction(double time, const std::vector<double> &rY)
00165 {
00166 bool stop = CalculateStoppingEvent(time, rY);
00167 return stop ? 0.0 : 1.0;
00168 }
00169
00170 bool GetUseAnalytic()
00171 {
00172 return mUseAnalytic;
00173 }
00174
00175
00186 unsigned GetStateVariableNumberByName(const std::string name)
00187 {
00188 assert(mpSystemInfo);
00189 return mpSystemInfo->GetStateVariableNumberByName(name);
00190 }
00191
00197 double GetStateVariableValueByNumber(unsigned varNumber) const
00198 {
00199 assert(varNumber < mNumberOfStateVariables);
00200 return mStateVariables[varNumber];
00201 }
00202
00208 std::string GetStateVariableUnitsByNumber(unsigned varNumber) const
00209 {
00210 assert(varNumber < mNumberOfStateVariables);
00211 assert(mpSystemInfo);
00212 return mpSystemInfo->GetStateVariableUnitsByNumber(varNumber);
00213 }
00214
00215 protected:
00221 std::string DumpState(const std::string& message,
00222 std::vector<double> Y = std::vector<double>());
00223 };
00224
00225
00226 #endif //_ABSTRACTODESYSTEM_HPP_