Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 00037 #include <cassert> 00038 #include <algorithm> 00039 00040 #include "AbstractOdeSystemInformation.hpp" 00041 #include "Exception.hpp" 00042 00043 AbstractOdeSystemInformation::AbstractOdeSystemInformation() 00044 : mInitialised(false) 00045 { 00046 } 00047 00048 AbstractOdeSystemInformation::~AbstractOdeSystemInformation() 00049 { 00050 } 00051 00052 std::string AbstractOdeSystemInformation::GetSystemName() const 00053 { 00054 return mSystemName; 00055 } 00056 00057 std::string AbstractOdeSystemInformation::GetFreeVariableName() const 00058 { 00059 return mFreeVariableName; 00060 } 00061 00062 std::string AbstractOdeSystemInformation::GetFreeVariableUnits() const 00063 { 00064 return mFreeVariableUnits; 00065 } 00066 00067 void AbstractOdeSystemInformation::SetDefaultInitialConditions(const std::vector<double>& rInitialConditions) 00068 { 00069 assert(mInitialised); 00070 mInitialConditions = rInitialConditions; 00071 } 00072 00073 void AbstractOdeSystemInformation::SetDefaultInitialCondition(unsigned index, double initialCondition) 00074 { 00075 assert(mInitialised); 00076 mInitialConditions.at(index) = initialCondition; 00077 } 00078 00079 std::vector<double> AbstractOdeSystemInformation::GetInitialConditions() const 00080 { 00081 assert(mInitialised); 00082 return mInitialConditions; 00083 } 00084 00085 const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableNames() const 00086 { 00087 assert(mInitialised); 00088 return mVariableNames; 00089 } 00090 00091 const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableUnits() const 00092 { 00093 assert(mInitialised); 00094 return mVariableUnits; 00095 } 00096 00097 unsigned AbstractOdeSystemInformation::GetStateVariableIndex(const std::string& rName) const 00098 { 00099 assert(mInitialised); 00100 std::vector<std::string>::const_iterator it = find(mVariableNames.begin(), mVariableNames.end(), rName); 00101 if (it == mVariableNames.end()) 00102 { 00103 EXCEPTION("No state variable named '" + rName + "'."); 00104 } 00105 return (unsigned)(it - mVariableNames.begin()); 00106 } 00107 00108 bool AbstractOdeSystemInformation::HasStateVariable(const std::string& rName) const 00109 { 00110 assert(mInitialised); 00111 std::vector<std::string>::const_iterator it = find(mVariableNames.begin(), mVariableNames.end(), rName); 00112 return (it != mVariableNames.end()); 00113 } 00114 00115 std::string AbstractOdeSystemInformation::GetStateVariableUnits(unsigned index) const 00116 { 00117 assert(mInitialised); 00118 if (index >= mVariableUnits.size()) 00119 { 00120 EXCEPTION("The index passed in must be less than the number of state variables."); 00121 } 00122 return mVariableUnits[index]; 00123 } 00124 00125 const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterNames() const 00126 { 00127 assert(mInitialised); 00128 return mParameterNames; 00129 } 00130 00131 const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterUnits() const 00132 { 00133 assert(mInitialised); 00134 return mParameterUnits; 00135 } 00136 00137 unsigned AbstractOdeSystemInformation::GetParameterIndex(const std::string& rName) const 00138 { 00139 assert(mInitialised); 00140 std::vector<std::string>::const_iterator it = find(mParameterNames.begin(), mParameterNames.end(), rName); 00141 if (it == mParameterNames.end()) 00142 { 00143 EXCEPTION("No parameter named '" + rName + "'."); 00144 } 00145 return (unsigned)(it - mParameterNames.begin()); 00146 } 00147 00148 bool AbstractOdeSystemInformation::HasParameter(const std::string& rName) const 00149 { 00150 assert(mInitialised); 00151 std::vector<std::string>::const_iterator it = find(mParameterNames.begin(), mParameterNames.end(), rName); 00152 return (it != mParameterNames.end()); 00153 } 00154 00155 std::string AbstractOdeSystemInformation::GetParameterUnits(unsigned index) const 00156 { 00157 assert(mInitialised); 00158 if (index >= mParameterUnits.size()) 00159 { 00160 EXCEPTION("The index passed in must be less than the number of parameters."); 00161 } 00162 return mParameterUnits[index]; 00163 } 00164 00165 unsigned AbstractOdeSystemInformation::GetNumberOfParameters() const 00166 { 00167 assert(mInitialised); 00168 return mParameterUnits.size(); 00169 } 00170 00171 unsigned AbstractOdeSystemInformation::GetAnyVariableIndex(const std::string& rName) const 00172 { 00173 assert(mInitialised); 00174 if (HasStateVariable(rName)) 00175 { 00176 return GetStateVariableIndex(rName); 00177 } 00178 else if (HasParameter(rName)) 00179 { 00180 return mVariableNames.size() + GetParameterIndex(rName); 00181 } 00182 else if (HasDerivedQuantity(rName)) 00183 { 00184 return mVariableNames.size() + mParameterNames.size() + GetDerivedQuantityIndex(rName); 00185 } 00186 else 00187 { 00188 EXCEPTION("No state variable, parameter, or derived quantity named '" + rName + "'."); 00189 } 00190 } 00191 00192 00193 bool AbstractOdeSystemInformation::HasAnyVariable(const std::string& rName) const 00194 { 00195 assert(mInitialised); 00196 return (HasStateVariable(rName) || HasParameter(rName) || HasDerivedQuantity(rName)); 00197 } 00198 00199 std::string AbstractOdeSystemInformation::GetAnyVariableUnits(unsigned index) const 00200 { 00201 assert(mInitialised); 00202 if (index < mVariableUnits.size()) 00203 { 00204 return mVariableUnits[index]; 00205 } 00206 else 00207 { 00208 unsigned offset = mVariableUnits.size(); 00209 if (index - offset < mParameterUnits.size()) 00210 { 00211 return mParameterUnits[index - offset]; 00212 } 00213 else 00214 { 00215 offset += mParameterUnits.size(); 00216 if (index - offset < mDerivedQuantityUnits.size()) 00217 { 00218 return mDerivedQuantityUnits[index - offset]; 00219 } 00220 else 00221 { 00222 EXCEPTION("Invalid index passed to GetAnyVariableUnits."); 00223 } 00224 } 00225 } 00226 } 00227 00228 00229 const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityNames() const 00230 { 00231 assert(mInitialised); 00232 return mDerivedQuantityNames; 00233 } 00234 00235 const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityUnits() const 00236 { 00237 assert(mInitialised); 00238 return mDerivedQuantityUnits; 00239 } 00240 00241 unsigned AbstractOdeSystemInformation::GetDerivedQuantityIndex(const std::string& rName) const 00242 { 00243 assert(mInitialised); 00244 std::vector<std::string>::const_iterator it = find(mDerivedQuantityNames.begin(), mDerivedQuantityNames.end(), rName); 00245 if (it == mDerivedQuantityNames.end()) 00246 { 00247 EXCEPTION("No derived quantity named '" + rName + "'."); 00248 } 00249 return (unsigned)(it - mDerivedQuantityNames.begin()); 00250 } 00251 00252 bool AbstractOdeSystemInformation::HasDerivedQuantity(const std::string& rName) const 00253 { 00254 assert(mInitialised); 00255 std::vector<std::string>::const_iterator it = find(mDerivedQuantityNames.begin(), mDerivedQuantityNames.end(), rName); 00256 return (it != mDerivedQuantityNames.end()); 00257 } 00258 00259 std::string AbstractOdeSystemInformation::GetDerivedQuantityUnits(unsigned index) const 00260 { 00261 assert(mInitialised); 00262 if (index >= mDerivedQuantityUnits.size()) 00263 { 00264 EXCEPTION("The index passed in must be less than the number of derived quantities."); 00265 } 00266 return mDerivedQuantityUnits[index]; 00267 } 00268 00269 unsigned AbstractOdeSystemInformation::GetNumberOfDerivedQuantities() const 00270 { 00271 assert(mInitialised); 00272 return mDerivedQuantityUnits.size(); 00273 } 00274 00275 unsigned AbstractOdeSystemInformation::GetNumberOfAttributes() const 00276 { 00277 assert(mInitialised); 00278 return mAttributes.size(); 00279 } 00280 00281 bool AbstractOdeSystemInformation::HasAttribute(const std::string& rName) const 00282 { 00283 assert(mInitialised); 00284 return (mAttributes.find(rName) != mAttributes.end()); 00285 } 00286 00287 double AbstractOdeSystemInformation::GetAttribute(const std::string& rName) const 00288 { 00289 assert(mInitialised); 00290 std::map<std::string, double>::const_iterator it = mAttributes.find(rName); 00291 if (it == mAttributes.end()) 00292 { 00293 EXCEPTION("No attribute '" + rName + "' found."); 00294 } 00295 return it->second; 00296 }