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 #include <cassert>
00030
00031 #include "AbstractParameterisedSystem.hpp"
00032
00033 #include "Exception.hpp"
00034 #include "VectorHelperFunctions.hpp"
00035
00036 #ifdef CHASTE_CVODE
00037
00038 #include <nvector/nvector_serial.h>
00039 #endif
00040
00041 template<typename VECTOR>
00042 AbstractParameterisedSystem<VECTOR>::AbstractParameterisedSystem(unsigned numberOfStateVariables)
00043 : mNumberOfStateVariables(numberOfStateVariables)
00044 {
00045 InitialiseEmptyVector(mParameters);
00046 InitialiseEmptyVector(mStateVariables);
00047 }
00048
00049 template<typename VECTOR>
00050 AbstractParameterisedSystem<VECTOR>::~AbstractParameterisedSystem()
00051 {
00052 }
00053
00054 template<typename VECTOR>
00055 boost::shared_ptr<const AbstractOdeSystemInformation> AbstractParameterisedSystem<VECTOR>::GetSystemInformation() const
00056 {
00057 assert(mpSystemInfo);
00058 return mpSystemInfo;
00059 }
00060
00061
00062 template<typename VECTOR>
00063 std::string AbstractParameterisedSystem<VECTOR>::GetSystemName() const
00064 {
00065 assert(mpSystemInfo);
00066 return mpSystemInfo->GetSystemName();
00067 }
00068
00069
00070
00071
00072
00073 template<typename VECTOR>
00074 unsigned AbstractParameterisedSystem<VECTOR>::GetNumberOfStateVariables() const
00075 {
00076 return mNumberOfStateVariables;
00077 }
00078
00079 template<typename VECTOR>
00080 VECTOR& AbstractParameterisedSystem<VECTOR>::rGetStateVariables()
00081 {
00082 return mStateVariables;
00083 }
00084
00085 template<typename VECTOR>
00086 double AbstractParameterisedSystem<VECTOR>::GetStateVariable(unsigned index) const
00087 {
00088 if (index >= mNumberOfStateVariables)
00089 {
00090 EXCEPTION("The index passed in must be less than the number of state variables.");
00091 }
00092 return GetVectorComponent(mStateVariables, index);
00093 }
00094
00095 template<typename VECTOR>
00096 void AbstractParameterisedSystem<VECTOR>::SetStateVariable(unsigned index, double newValue)
00097 {
00098 if ( mNumberOfStateVariables <= index )
00099 {
00100 EXCEPTION("The index passed in must be less than the number of state variables.");
00101 }
00102 SetVectorComponent(mStateVariables, index, newValue);
00103 }
00104
00105 template<typename VECTOR>
00106 const std::vector<std::string>& AbstractParameterisedSystem<VECTOR>::rGetStateVariableNames() const
00107 {
00108 assert(mpSystemInfo);
00109 return mpSystemInfo->rGetStateVariableNames();
00110 }
00111
00112 template<typename VECTOR>
00113 const std::vector<std::string>& AbstractParameterisedSystem<VECTOR>::rGetStateVariableUnits() const
00114 {
00115 assert(mpSystemInfo);
00116 return mpSystemInfo->rGetStateVariableUnits();
00117 }
00118
00119 template<typename VECTOR>
00120 unsigned AbstractParameterisedSystem<VECTOR>::GetStateVariableIndex(const std::string& rName) const
00121 {
00122 assert(mpSystemInfo);
00123 return mpSystemInfo->GetStateVariableIndex(rName);
00124 }
00125
00126 template<typename VECTOR>
00127 std::string AbstractParameterisedSystem<VECTOR>::GetStateVariableUnits(unsigned index) const
00128 {
00129 assert(mpSystemInfo);
00130 return mpSystemInfo->GetStateVariableUnits(index);
00131 }
00132
00133
00134
00135
00136
00137 template<typename VECTOR>
00138 unsigned AbstractParameterisedSystem<VECTOR>::GetNumberOfParameters() const
00139 {
00140 return GetVectorSize(mParameters);
00141 }
00142
00143 template<typename VECTOR>
00144 double AbstractParameterisedSystem<VECTOR>::GetParameter(unsigned index) const
00145 {
00146 if (index >= GetVectorSize(mParameters))
00147 {
00148 EXCEPTION("The index passed in must be less than the number of parameters.");
00149 }
00150 return GetVectorComponent(mParameters, index);
00151 }
00152
00153 template<typename VECTOR>
00154 void AbstractParameterisedSystem<VECTOR>::SetParameter(unsigned index, double value)
00155 {
00156 if (index >= GetVectorSize(mParameters))
00157 {
00158 EXCEPTION("The index passed in must be less than the number of parameters.");
00159 }
00160 SetVectorComponent(mParameters, index, value);
00161 }
00162
00163 template<typename VECTOR>
00164 void AbstractParameterisedSystem<VECTOR>::SetParameter(const std::string& rName, double value)
00165 {
00166 SetVectorComponent(mParameters, GetParameterIndex(rName), value);
00167 }
00168
00169 template<typename VECTOR>
00170 const std::vector<std::string>& AbstractParameterisedSystem<VECTOR>::rGetParameterNames() const
00171 {
00172 assert(mpSystemInfo);
00173 return mpSystemInfo->rGetParameterNames();
00174 }
00175
00176 template<typename VECTOR>
00177 const std::vector<std::string>& AbstractParameterisedSystem<VECTOR>::rGetParameterUnits() const
00178 {
00179 assert(mpSystemInfo);
00180 return mpSystemInfo->rGetParameterUnits();
00181 }
00182
00183 template<typename VECTOR>
00184 unsigned AbstractParameterisedSystem<VECTOR>::GetParameterIndex(const std::string& rName) const
00185 {
00186 assert(mpSystemInfo);
00187 return mpSystemInfo->GetParameterIndex(rName);
00188 }
00189
00190 template<typename VECTOR>
00191 std::string AbstractParameterisedSystem<VECTOR>::GetParameterUnits(unsigned index) const
00192 {
00193 assert(mpSystemInfo);
00194 return mpSystemInfo->GetParameterUnits(index);
00195 }
00196
00197
00198
00199
00200
00201 template<typename VECTOR>
00202 double AbstractParameterisedSystem<VECTOR>::GetAnyVariable(unsigned index, double time,
00203 VECTOR* pDerivedQuantities)
00204 {
00205 if (index < mNumberOfStateVariables)
00206 {
00207 return GetVectorComponent(mStateVariables, index);
00208 }
00209 else if (index - mNumberOfStateVariables < GetVectorSize(mParameters))
00210 {
00211 return GetVectorComponent(mParameters, index - mNumberOfStateVariables);
00212 }
00213 else
00214 {
00215 unsigned offset = mNumberOfStateVariables + GetVectorSize(mParameters);
00216 if (index - offset < GetNumberOfDerivedQuantities())
00217 {
00218 VECTOR dqs;
00219 if (pDerivedQuantities == NULL)
00220 {
00221 dqs = ComputeDerivedQuantitiesFromCurrentState(time);
00222 pDerivedQuantities = &dqs;
00223 }
00224 double value = GetVectorComponent(*pDerivedQuantities, index - offset);
00225 if (pDerivedQuantities == &dqs)
00226 {
00227 DeleteVector(dqs);
00228 }
00229 return value;
00230 }
00231 else
00232 {
00233 EXCEPTION("Invalid index passed to GetAnyVariable.");
00234 }
00235 }
00236 }
00237
00238 template<typename VECTOR>
00239 unsigned AbstractParameterisedSystem<VECTOR>::GetAnyVariableIndex(const std::string& rName) const
00240 {
00241 assert(mpSystemInfo);
00242 return mpSystemInfo->GetAnyVariableIndex(rName);
00243 }
00244
00245 template<typename VECTOR>
00246 std::string AbstractParameterisedSystem<VECTOR>::GetAnyVariableUnits(unsigned index) const
00247 {
00248 assert(mpSystemInfo);
00249 return mpSystemInfo->GetAnyVariableUnits(index);
00250 }
00251
00252
00253
00254
00255
00256 template<typename VECTOR>
00257 unsigned AbstractParameterisedSystem<VECTOR>::GetNumberOfDerivedQuantities() const
00258 {
00259 assert(mpSystemInfo);
00260 return mpSystemInfo->rGetDerivedQuantityNames().size();
00261 }
00262
00263 template<typename VECTOR>
00264 VECTOR AbstractParameterisedSystem<VECTOR>::ComputeDerivedQuantities(double time,
00265 const VECTOR& rState)
00266 {
00267 EXCEPTION("This ODE system does not define derived quantities.");
00268 }
00269
00270 template<typename VECTOR>
00271 VECTOR AbstractParameterisedSystem<VECTOR>::ComputeDerivedQuantitiesFromCurrentState(double time)
00272 {
00273 return this->ComputeDerivedQuantities(time, mStateVariables);
00274 }
00275
00276 template<typename VECTOR>
00277 const std::vector<std::string>& AbstractParameterisedSystem<VECTOR>::rGetDerivedQuantityNames() const
00278 {
00279 assert(mpSystemInfo);
00280 return mpSystemInfo->rGetDerivedQuantityNames();
00281 }
00282
00283 template<typename VECTOR>
00284 const std::vector<std::string>& AbstractParameterisedSystem<VECTOR>::rGetDerivedQuantityUnits() const
00285 {
00286 assert(mpSystemInfo);
00287 return mpSystemInfo->rGetDerivedQuantityUnits();
00288 }
00289
00290 template<typename VECTOR>
00291 unsigned AbstractParameterisedSystem<VECTOR>::GetDerivedQuantityIndex(const std::string& rName) const
00292 {
00293 assert(mpSystemInfo);
00294 return mpSystemInfo->GetDerivedQuantityIndex(rName);
00295 }
00296
00297 template<typename VECTOR>
00298 std::string AbstractParameterisedSystem<VECTOR>::GetDerivedQuantityUnits(unsigned index) const
00299 {
00300 assert(mpSystemInfo);
00301 return mpSystemInfo->GetDerivedQuantityUnits(index);
00302 }
00303
00304
00305
00307
00309
00310 template class AbstractParameterisedSystem<std::vector<double> >;
00311 #ifdef CHASTE_CVODE
00312 template class AbstractParameterisedSystem<N_Vector>;
00313 #endif