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>
151 if ( mNumberOfStateVariables !=
GetVectorSize(rStateVariables) )
153 EXCEPTION(
"The size of the passed in vector must be that of the number of state variables.");
157 for (
unsigned i=0; i<mNumberOfStateVariables; i++)
163 template<
typename VECTOR>
166 if (index >= mNumberOfStateVariables)
168 EXCEPTION(
"The index passed in must be less than the number of state variables.");
173 template<
typename VECTOR>
176 return GetStateVariable(GetStateVariableIndex(rName));
179 template<
typename VECTOR>
182 if ( mNumberOfStateVariables <= index )
184 EXCEPTION(
"The index passed in must be less than the number of state variables.");
189 template<
typename VECTOR>
192 SetStateVariable(GetStateVariableIndex(rName), newValue);
200 template<
typename VECTOR>
203 if (
GetVectorSize(rInitialConditions) != mNumberOfStateVariables)
205 EXCEPTION(
"The number of initial conditions must be that of the number of state variables.");
207 assert(mpSystemInfo);
208 std::vector<double> inits;
210 mpSystemInfo->SetDefaultInitialConditions(inits);
213 template<
typename VECTOR>
216 if (index >= mNumberOfStateVariables)
218 EXCEPTION(
"Index is greater than the number of state variables.");
220 assert(mpSystemInfo);
221 mpSystemInfo->SetDefaultInitialCondition(index, initialCondition);
224 template<
typename VECTOR>
227 assert(mpSystemInfo);
235 template<
typename VECTOR>
238 VECTOR inits = GetInitialConditions();
239 SetStateVariables(inits);
247 template<
typename VECTOR>
252 EXCEPTION(
"The index passed in must be less than the number of parameters.");
257 template<
typename VECTOR>
262 EXCEPTION(
"The index passed in must be less than the number of parameters.");
267 template<
typename VECTOR>
273 template<
typename VECTOR>
276 return GetParameter(GetParameterIndex(rName));
283 template<
typename VECTOR>
285 VECTOR* pDerivedQuantities)
287 if (index < mNumberOfStateVariables)
291 else if (index - mNumberOfStateVariables <
GetVectorSize(mParameters))
297 unsigned offset = mNumberOfStateVariables +
GetVectorSize(mParameters);
298 if (index - offset < GetNumberOfDerivedQuantities())
301 if (pDerivedQuantities == NULL)
303 dqs = ComputeDerivedQuantitiesFromCurrentState(time);
304 pDerivedQuantities = &dqs;
307 if (pDerivedQuantities == &dqs)
315 EXCEPTION(
"Invalid index passed to GetAnyVariable.");
320 template<
typename VECTOR>
323 VECTOR* pDerivedQuantities)
325 return GetAnyVariable(GetAnyVariableIndex(rName), time, pDerivedQuantities);
328 template<
typename VECTOR>
331 if (index < mNumberOfStateVariables)
335 else if (index - mNumberOfStateVariables <
GetVectorSize(mParameters))
341 EXCEPTION(
"Cannot set the value of a derived quantity, or invalid index.");
345 template<
typename VECTOR>
348 SetAnyVariable(GetAnyVariableIndex(rName), value);
355 template<
typename VECTOR>
357 const VECTOR& rState)
359 EXCEPTION(
"This ODE system does not define derived quantities.");
362 template<
typename VECTOR>
365 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)