AbstractOdeSystemInformation.cpp
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 #include <cassert>
00031 #include <algorithm>
00032
00033 #include "AbstractOdeSystemInformation.hpp"
00034 #include "Exception.hpp"
00035
00036 AbstractOdeSystemInformation::AbstractOdeSystemInformation()
00037 : mInitialised(false)
00038 {
00039 }
00040
00041 AbstractOdeSystemInformation::~AbstractOdeSystemInformation()
00042 {
00043 }
00044
00045 std::string AbstractOdeSystemInformation::GetSystemName() const
00046 {
00047 return mSystemName;
00048 }
00049
00050 void AbstractOdeSystemInformation::SetDefaultInitialConditions(const std::vector<double>& rInitialConditions)
00051 {
00052 assert(mInitialised);
00053 mInitialConditions = rInitialConditions;
00054 }
00055
00056 void AbstractOdeSystemInformation::SetDefaultInitialCondition(unsigned index, double initialCondition)
00057 {
00058 assert(mInitialised);
00059 mInitialConditions.at(index) = initialCondition;
00060 }
00061
00062 std::vector<double> AbstractOdeSystemInformation::GetInitialConditions() const
00063 {
00064 assert(mInitialised);
00065 return mInitialConditions;
00066 }
00067
00068 const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableNames() const
00069 {
00070 assert(mInitialised);
00071 return mVariableNames;
00072 }
00073
00074 const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableUnits() const
00075 {
00076 assert(mInitialised);
00077 return mVariableUnits;
00078 }
00079
00080 unsigned AbstractOdeSystemInformation::GetStateVariableIndex(const std::string& rName) const
00081 {
00082 assert(mInitialised);
00083 std::vector<std::string>::const_iterator it = find(mVariableNames.begin(), mVariableNames.end(), rName);
00084 if (it == mVariableNames.end())
00085 {
00086 EXCEPTION("No state variable named '" + rName + "'.");
00087 }
00088 return (unsigned)(it - mVariableNames.begin());
00089 }
00090
00091 bool AbstractOdeSystemInformation::HasStateVariable(const std::string& rName) const
00092 {
00093 assert(mInitialised);
00094 std::vector<std::string>::const_iterator it = find(mVariableNames.begin(), mVariableNames.end(), rName);
00095 return (it != mVariableNames.end());
00096 }
00097
00098 std::string AbstractOdeSystemInformation::GetStateVariableUnits(unsigned index) const
00099 {
00100 assert(mInitialised);
00101 if (index >= mVariableUnits.size())
00102 {
00103 EXCEPTION("The index passed in must be less than the number of state variables.");
00104 }
00105 return mVariableUnits[index];
00106 }
00107
00108 const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterNames() const
00109 {
00110 assert(mInitialised);
00111 return mParameterNames;
00112 }
00113
00114 const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterUnits() const
00115 {
00116 assert(mInitialised);
00117 return mParameterUnits;
00118 }
00119
00120 unsigned AbstractOdeSystemInformation::GetParameterIndex(const std::string& rName) const
00121 {
00122 assert(mInitialised);
00123 std::vector<std::string>::const_iterator it = find(mParameterNames.begin(), mParameterNames.end(), rName);
00124 if (it == mParameterNames.end())
00125 {
00126 EXCEPTION("No parameter named '" + rName + "'.");
00127 }
00128 return (unsigned)(it - mParameterNames.begin());
00129 }
00130
00131 bool AbstractOdeSystemInformation::HasParameter(const std::string& rName) const
00132 {
00133 assert(mInitialised);
00134 std::vector<std::string>::const_iterator it = find(mParameterNames.begin(), mParameterNames.end(), rName);
00135 return (it != mParameterNames.end());
00136 }
00137
00138 std::string AbstractOdeSystemInformation::GetParameterUnits(unsigned index) const
00139 {
00140 assert(mInitialised);
00141 if (index >= mParameterUnits.size())
00142 {
00143 EXCEPTION("The index passed in must be less than the number of parameters.");
00144 }
00145 return mParameterUnits[index];
00146 }
00147
00148 unsigned AbstractOdeSystemInformation::GetNumberOfParameters() const
00149 {
00150 assert(mInitialised);
00151 return mParameterUnits.size();
00152 }
00153
00154 unsigned AbstractOdeSystemInformation::GetAnyVariableIndex(const std::string& rName) const
00155 {
00156 assert(mInitialised);
00157 if (HasStateVariable(rName))
00158 {
00159 return GetStateVariableIndex(rName);
00160 }
00161 else if (HasParameter(rName))
00162 {
00163 return mVariableNames.size() + GetParameterIndex(rName);
00164 }
00165 else if (HasDerivedQuantity(rName))
00166 {
00167 return mVariableNames.size() + mParameterNames.size() + GetDerivedQuantityIndex(rName);
00168 }
00169 else
00170 {
00171 EXCEPTION("No state variable, parameter, or derived quantity named '" + rName + "'.");
00172 }
00173 }
00174
00175
00176 bool AbstractOdeSystemInformation::HasAnyVariable(const std::string& rName) const
00177 {
00178 assert(mInitialised);
00179 return (HasStateVariable(rName) || HasParameter(rName) || HasDerivedQuantity(rName));
00180 }
00181
00182 std::string AbstractOdeSystemInformation::GetAnyVariableUnits(unsigned index) const
00183 {
00184 assert(mInitialised);
00185 if (index < mVariableUnits.size())
00186 {
00187 return mVariableUnits[index];
00188 }
00189 else
00190 {
00191 unsigned offset = mVariableUnits.size();
00192 if (index - offset < mParameterUnits.size())
00193 {
00194 return mParameterUnits[index - offset];
00195 }
00196 else
00197 {
00198 offset += mParameterUnits.size();
00199 if (index - offset < mDerivedQuantityUnits.size())
00200 {
00201 return mDerivedQuantityUnits[index - offset];
00202 }
00203 else
00204 {
00205 EXCEPTION("Invalid index passed to GetAnyVariableUnits.");
00206 }
00207 }
00208 }
00209 }
00210
00211
00212 const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityNames() const
00213 {
00214 assert(mInitialised);
00215 return mDerivedQuantityNames;
00216 }
00217
00218 const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityUnits() const
00219 {
00220 assert(mInitialised);
00221 return mDerivedQuantityUnits;
00222 }
00223
00224 unsigned AbstractOdeSystemInformation::GetDerivedQuantityIndex(const std::string& rName) const
00225 {
00226 assert(mInitialised);
00227 std::vector<std::string>::const_iterator it = find(mDerivedQuantityNames.begin(), mDerivedQuantityNames.end(), rName);
00228 if (it == mDerivedQuantityNames.end())
00229 {
00230 EXCEPTION("No derived quantity named '" + rName + "'.");
00231 }
00232 return (unsigned)(it - mDerivedQuantityNames.begin());
00233 }
00234
00235 bool AbstractOdeSystemInformation::HasDerivedQuantity(const std::string& rName) const
00236 {
00237 assert(mInitialised);
00238 std::vector<std::string>::const_iterator it = find(mDerivedQuantityNames.begin(), mDerivedQuantityNames.end(), rName);
00239 return (it != mDerivedQuantityNames.end());
00240 }
00241
00242 std::string AbstractOdeSystemInformation::GetDerivedQuantityUnits(unsigned index) const
00243 {
00244 assert(mInitialised);
00245 if (index >= mDerivedQuantityUnits.size())
00246 {
00247 EXCEPTION("The index passed in must be less than the number of derived quantities.");
00248 }
00249 return mDerivedQuantityUnits[index];
00250 }
00251
00252 unsigned AbstractOdeSystemInformation::GetNumberOfDerivedQuantities() const
00253 {
00254 assert(mInitialised);
00255 return mDerivedQuantityUnits.size();
00256 }
00257
00258 unsigned AbstractOdeSystemInformation::GetNumberOfAttributes() const
00259 {
00260 assert(mInitialised);
00261 return mAttributes.size();
00262 }
00263
00264 bool AbstractOdeSystemInformation::HasAttribute(const std::string& rName) const
00265 {
00266 assert(mInitialised);
00267 return (mAttributes.find(rName) != mAttributes.end());
00268 }
00269
00270 double AbstractOdeSystemInformation::GetAttribute(const std::string& rName) const
00271 {
00272 assert(mInitialised);
00273 std::map<std::string, double>::const_iterator it = mAttributes.find(rName);
00274 if (it == mAttributes.end())
00275 {
00276 EXCEPTION("No attribute '" + rName + "' found.");
00277 }
00278 return it->second;
00279 }