39#include "AbstractParameterisedSystem.hpp"
45template<
typename VECTOR>
53template<
typename VECTOR>
56 return GetStateMessage(rMessage, mStateVariables);
59template<
typename VECTOR>
63 return GetStateMessage(rMessage, Y);
66template<
typename VECTOR>
71 std::stringstream extra_message;
72 extra_message << std::endl <<
"At independent variable (usually time) = " << time;
73 std::string new_message = rMessage + extra_message.str();
74 return GetStateMessage(new_message, Y);
77template<
typename VECTOR>
80 std::stringstream res;
81 res << rMessage << std::endl <<
"State:" << std::endl;
83 const std::vector<std::string>& r_units = rGetStateVariableUnits();
89 res <<
" " << r_units[i];
96template<
typename VECTOR>
99 if (
GetVectorSize(mParameters) != rGetParameterNames().size())
102 if (rParameterNames.size() != rGetParameterNames().size())
104 EXCEPTION(
"Number of ODE parameters in archive does not match number in class.");
111 std::vector<unsigned> index_map(rParameterNames.size());
112 for (
unsigned i=0; i<rParameterNames.size(); ++i)
114 index_map[i] = find(rGetParameterNames().begin(), rGetParameterNames().end(), rParameterNames[i])
115 - rGetParameterNames().begin();
116 if (index_map[i] == rGetParameterNames().size())
118 EXCEPTION(
"Archive specifies a parameter '" + rParameterNames[i] +
"' which does not appear in this class.");
122 for (
unsigned i=0; i<rParameterNames.size(); ++i)
128 assert(
GetVectorSize(mParameters) == rGetParameterNames().size());
135template<
typename VECTOR>
138 return mStateVariables;
141template<
typename VECTOR>
147template<
typename VECTOR>
150 if (mNumberOfStateVariables !=
GetVectorSize(rStateVariables))
152 EXCEPTION(
"The size of the passed in vector must be that of the number of state variables.");
156 for (
unsigned i=0; i<mNumberOfStateVariables; i++)
162template<
typename VECTOR>
165 if (index >= mNumberOfStateVariables)
167 EXCEPTION(
"The index passed in must be less than the number of state variables.");
172template<
typename VECTOR>
175 return GetStateVariable(GetStateVariableIndex(rName));
178template<
typename VECTOR>
181 if (mNumberOfStateVariables <= index)
183 EXCEPTION(
"The index passed in must be less than the number of state variables.");
188template<
typename VECTOR>
191 SetStateVariable(GetStateVariableIndex(rName), newValue);
198template<
typename VECTOR>
201 if (
GetVectorSize(rInitialConditions) != mNumberOfStateVariables)
203 EXCEPTION(
"The number of initial conditions must be that of the number of state variables.");
205 assert(mpSystemInfo);
206 std::vector<double> inits;
208 mpSystemInfo->SetDefaultInitialConditions(inits);
211template<
typename VECTOR>
214 if (index >= mNumberOfStateVariables)
216 EXCEPTION(
"Index is greater than the number of state variables.");
218 assert(mpSystemInfo);
219 mpSystemInfo->SetDefaultInitialCondition(index, initialCondition);
222template<
typename VECTOR>
225 assert(mpSystemInfo);
233template<
typename VECTOR>
236 VECTOR inits = GetInitialConditions();
237 SetStateVariables(inits);
245template<
typename VECTOR>
250 EXCEPTION(
"The index passed in must be less than the number of parameters.");
255template<
typename VECTOR>
260 EXCEPTION(
"The index passed in must be less than the number of parameters.");
265template<
typename VECTOR>
271template<
typename VECTOR>
274 return GetParameter(GetParameterIndex(rName));
281template<
typename VECTOR>
283 VECTOR* pDerivedQuantities)
285 if (index < mNumberOfStateVariables)
289 else if (index - mNumberOfStateVariables <
GetVectorSize(mParameters))
295 unsigned offset = mNumberOfStateVariables +
GetVectorSize(mParameters);
296 if (index - offset < GetNumberOfDerivedQuantities())
299 if (pDerivedQuantities ==
nullptr)
301 dqs = ComputeDerivedQuantitiesFromCurrentState(time);
302 pDerivedQuantities = &dqs;
305 if (pDerivedQuantities == &dqs)
313 EXCEPTION(
"Invalid index passed to GetAnyVariable.");
318template<
typename VECTOR>
321 VECTOR* pDerivedQuantities)
323 return GetAnyVariable(GetAnyVariableIndex(rName), time, pDerivedQuantities);
326template<
typename VECTOR>
329 if (index < mNumberOfStateVariables)
333 else if (index - mNumberOfStateVariables <
GetVectorSize(mParameters))
339 EXCEPTION(
"Cannot set the value of a derived quantity, or invalid index.");
343template<
typename VECTOR>
346 SetAnyVariable(GetAnyVariableIndex(rName), value);
353template<
typename VECTOR>
355 const VECTOR& rState)
357 EXCEPTION(
"This ODE system does not define derived quantities.");
360template<
typename VECTOR>
363 return this->ComputeDerivedQuantities(time, mStateVariables);
#define EXCEPTION(message)
void DeleteVector(VECTOR &rVec)
void CreateVectorIfEmpty(VECTOR &rVec, unsigned size)
void SetVectorComponent(VECTOR &rVec, unsigned index, double value)
double GetVectorComponent(const VECTOR &rVec, unsigned index)
unsigned GetVectorSize(const VECTOR &rVec)
VECTOR CopyVector(VECTOR &rVec)
void InitialiseEmptyVector(VECTOR &rVec)
void CopyFromStdVector(const std::vector< double > &rSrc, VECTOR &rDest)
void CopyToStdVector(const VECTOR &rSrc, std::vector< double > &rDest)
virtual VECTOR ComputeDerivedQuantities(double time, const VECTOR &rState)
double GetStateVariable(unsigned index) const
void SetStateVariables(const VECTOR &rStateVariables)
double GetAnyVariable(unsigned index, double time=0.0, VECTOR *pDerivedQuantities=NULL)
VECTOR GetStateVariables()
double GetParameter(unsigned index) const
void SetStateVariable(unsigned index, double newValue)
void SetAnyVariable(unsigned index, double value)
VECTOR ComputeDerivedQuantitiesFromCurrentState(double time)
void ResetToInitialConditions()
void CheckParametersOnLoad(const std::vector< double > &rParameters, const std::vector< std::string > &rParameterNames)
VECTOR GetInitialConditions() const
std::string GetStateMessage(const std::string &rMessage, VECTOR Y)
void SetParameter(const std::string &rName, double value)
AbstractParameterisedSystem(unsigned numberOfStateVariables)
VECTOR & rGetStateVariables()
std::string DumpState(const std::string &rMessage)
void SetDefaultInitialCondition(unsigned index, double initialCondition)
void SetDefaultInitialConditions(const VECTOR &rInitialConditions)