AbstractOdeSystemInformation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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 }
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3