39 #include "AbstractParameterisedSystem.hpp"
45 template<
typename VECTOR>
53 template<
typename VECTOR>
56 return GetStateMessage(rMessage, mStateVariables);
59 template<
typename VECTOR>
63 return GetStateMessage(rMessage, Y);
66 template<
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);
77 template<
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];
96 template<
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());
135 template<
typename VECTOR>
138 return mStateVariables;
141 template<
typename VECTOR>
147 template<
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++)
162 template<
typename VECTOR>
165 if (index >= mNumberOfStateVariables)
167 EXCEPTION(
"The index passed in must be less than the number of state variables.");
172 template<
typename VECTOR>
175 return GetStateVariable(GetStateVariableIndex(rName));
178 template<
typename VECTOR>
181 if (mNumberOfStateVariables <= index)
183 EXCEPTION(
"The index passed in must be less than the number of state variables.");
188 template<
typename VECTOR>
191 SetStateVariable(GetStateVariableIndex(rName), newValue);
198 template<
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);
211 template<
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);
222 template<
typename VECTOR>
225 assert(mpSystemInfo);
233 template<
typename VECTOR>
236 VECTOR inits = GetInitialConditions();
237 SetStateVariables(inits);
245 template<
typename VECTOR>
250 EXCEPTION(
"The index passed in must be less than the number of parameters.");
255 template<
typename VECTOR>
260 EXCEPTION(
"The index passed in must be less than the number of parameters.");
265 template<
typename VECTOR>
271 template<
typename VECTOR>
274 return GetParameter(GetParameterIndex(rName));
281 template<
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.");
318 template<
typename VECTOR>
321 VECTOR* pDerivedQuantities)
323 return GetAnyVariable(GetAnyVariableIndex(rName), time, pDerivedQuantities);
326 template<
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.");
343 template<
typename VECTOR>
346 SetAnyVariable(GetAnyVariableIndex(rName), value);
353 template<
typename VECTOR>
355 const VECTOR& rState)
357 EXCEPTION(
"This ODE system does not define derived quantities.");
360 template<
typename VECTOR>
363 return this->ComputeDerivedQuantities(time, mStateVariables);
void SetDefaultInitialCondition(unsigned index, double initialCondition)
void SetDefaultInitialConditions(const VECTOR &rInitialConditions)
#define EXCEPTION(message)
VECTOR CopyVector(VECTOR &rVec)
VECTOR & rGetStateVariables()
void ResetToInitialConditions()
std::string DumpState(const std::string &rMessage)
void InitialiseEmptyVector(VECTOR &rVec)
void SetStateVariables(const VECTOR &rStateVariables)
double GetStateVariable(unsigned index) const
double GetParameter(unsigned index) const
VECTOR GetInitialConditions() const
void CreateVectorIfEmpty(VECTOR &rVec, unsigned size)
VECTOR GetStateVariables()
void SetVectorComponent(VECTOR &rVec, unsigned index, double value)
void SetAnyVariable(unsigned index, double value)
void SetParameter(const std::string &rName, double value)
virtual VECTOR ComputeDerivedQuantities(double time, const VECTOR &rState)
void SetStateVariable(unsigned index, double newValue)
void CopyFromStdVector(const std::vector< double > &rSrc, VECTOR &rDest)
void CheckParametersOnLoad(const std::vector< double > &rParameters, const std::vector< std::string > &rParameterNames)
void CopyToStdVector(const VECTOR &rSrc, std::vector< double > &rDest)
double GetVectorComponent(const VECTOR &rVec, unsigned index)
VECTOR ComputeDerivedQuantitiesFromCurrentState(double time)
std::string GetStateMessage(const std::string &rMessage, VECTOR Y)
void DeleteVector(VECTOR &rVec)
double GetAnyVariable(unsigned index, double time=0.0, VECTOR *pDerivedQuantities=NULL)
unsigned GetVectorSize(const VECTOR &rVec)
AbstractParameterisedSystem(unsigned numberOfStateVariables)