AbstractOdeSystemInformation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 
00032 #include "AbstractOdeSystemInformation.hpp"
00033 #include "Exception.hpp"
00034 
00035 AbstractOdeSystemInformation::AbstractOdeSystemInformation()
00036     : mInitialised(false)
00037 {
00038 }
00039 
00040 AbstractOdeSystemInformation::~AbstractOdeSystemInformation()
00041 {
00042 }
00043 
00044 std::string AbstractOdeSystemInformation::GetSystemName() const
00045 {
00046     return mSystemName;
00047 }
00048 
00049 void AbstractOdeSystemInformation::SetDefaultInitialConditions(const std::vector<double>& rInitialConditions)
00050 {
00051     assert(mInitialised);
00052     mInitialConditions = rInitialConditions;
00053 }
00054 
00055 void AbstractOdeSystemInformation::SetDefaultInitialCondition(unsigned index, double initialCondition)
00056 {
00057     assert(mInitialised);
00058     mInitialConditions.at(index) = initialCondition;
00059 }
00060 
00061 std::vector<double> AbstractOdeSystemInformation::GetInitialConditions() const
00062 {
00063     assert(mInitialised);
00064     return mInitialConditions;
00065 }
00066 
00067 const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableNames() const
00068 {
00069     assert(mInitialised);
00070     return mVariableNames;
00071 }
00072 
00073 const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableUnits() const
00074 {
00075     assert(mInitialised);
00076     return mVariableUnits;
00077 }
00078 
00079 unsigned AbstractOdeSystemInformation::GetStateVariableIndex(const std::string& rName) const
00080 {
00081     assert(mInitialised);
00082     unsigned index = 0u;
00083     std::vector<std::string>::const_iterator it = mVariableNames.begin();
00084     for ( ; it != mVariableNames.end() && *it != rName; ++it, ++index);
00085     if (it == mVariableNames.end())
00086     {
00087         EXCEPTION("No state variable named '" + rName + "'.");
00088     }
00089     return index;
00090 }
00091 
00092 std::string AbstractOdeSystemInformation::GetStateVariableUnits(unsigned index) const
00093 {
00094     assert(mInitialised);
00095     if (index >= mVariableUnits.size())
00096     {
00097         EXCEPTION("The index passed in must be less than the number of state variables.");
00098     }
00099     return mVariableUnits[index];
00100 }
00101 
00102 
00103 const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterNames() const
00104 {
00105     assert(mInitialised);
00106     return mParameterNames;
00107 }
00108 
00109 const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterUnits() const
00110 {
00111     assert(mInitialised);
00112     return mParameterUnits;
00113 }
00114 
00115 unsigned AbstractOdeSystemInformation::GetParameterIndex(const std::string& rName) const
00116 {
00117     assert(mInitialised);
00118     unsigned index = 0u;
00119     std::vector<std::string>::const_iterator it = mParameterNames.begin();
00120     for ( ; it != mParameterNames.end() && *it != rName; ++it, ++index);
00121     if (it == mParameterNames.end())
00122     {
00123         EXCEPTION("No parameter named '" + rName + "'.");
00124     }
00125     return index;
00126 }
00127 
00128 std::string AbstractOdeSystemInformation::GetParameterUnits(unsigned index) const
00129 {
00130     assert(mInitialised);
00131     if (index >= mParameterUnits.size())
00132     {
00133         EXCEPTION("The index passed in must be less than the number of parameters.");
00134     }
00135     return mParameterUnits[index];
00136 }
00137 
00138 unsigned AbstractOdeSystemInformation::GetAnyVariableIndex(const std::string& rName) const
00139 {
00140     assert(mInitialised);
00141     try
00142     {
00143         return GetStateVariableIndex(rName);
00144     }
00145     catch (const Exception& e)
00146     {
00147         try
00148         {
00149             return mVariableNames.size() + GetParameterIndex(rName);
00150         }
00151         catch (const Exception& e)
00152         {
00153             try
00154             {
00155                 return mVariableNames.size() + mParameterNames.size() + GetDerivedQuantityIndex(rName);
00156             }
00157             catch (const Exception& e)
00158             {
00159                 EXCEPTION("No state variable, parameter, or derived quantity named '" + rName + "'.");
00160             }
00161         }
00162     }
00163 }
00164 
00165 std::string AbstractOdeSystemInformation::GetAnyVariableUnits(unsigned index) const
00166 {
00167     assert(mInitialised);
00168     if (index < mVariableUnits.size())
00169     {
00170         return mVariableUnits[index];
00171     }
00172     else
00173     {
00174         unsigned offset = mVariableUnits.size();
00175         if (index - offset < mParameterUnits.size())
00176         {
00177             return mParameterUnits[index - offset];
00178         }
00179         else
00180         {
00181             offset += mParameterUnits.size();
00182             if (index - offset < mDerivedQuantityUnits.size())
00183             {
00184                 return mDerivedQuantityUnits[index - offset];
00185             }
00186             else
00187             {
00188                 EXCEPTION("Invalid index passed to GetAnyVariableUnits.");
00189             }
00190         }
00191     }
00192 }
00193 
00194 
00195 const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityNames() const
00196 {
00197     assert(mInitialised);
00198     return mDerivedQuantityNames;
00199 }
00200 
00201 const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityUnits() const
00202 {
00203     assert(mInitialised);
00204     return mDerivedQuantityUnits;
00205 }
00206 
00207 unsigned AbstractOdeSystemInformation::GetDerivedQuantityIndex(const std::string& rName) const
00208 {
00209     assert(mInitialised);
00210     unsigned index = 0u;
00211     std::vector<std::string>::const_iterator it = mDerivedQuantityNames.begin();
00212     for ( ; it != mDerivedQuantityNames.end() && *it != rName; ++it, ++index);
00213     if (it == mDerivedQuantityNames.end())
00214     {
00215         EXCEPTION("No derived quantity named '" + rName + "'.");
00216     }
00217     return index;
00218 }
00219 
00220 std::string AbstractOdeSystemInformation::GetDerivedQuantityUnits(unsigned index) const
00221 {
00222     assert(mInitialised);
00223     if (index >= mDerivedQuantityUnits.size())
00224     {
00225         EXCEPTION("The index passed in must be less than the number of derived quantities.");
00226     }
00227     return mDerivedQuantityUnits[index];
00228 }
00229 

Generated on Mon Nov 1 12:35:24 2010 for Chaste by  doxygen 1.5.5