AbstractOdeSystem.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 #ifndef _ABSTRACTODESYSTEM_HPP_
00031 #define _ABSTRACTODESYSTEM_HPP_
00032 
00033 #include <vector>
00034 #include <string>
00035 #include <cassert>
00036 
00037 #include <boost/shared_ptr.hpp>
00038 
00039 #include "Exception.hpp"
00040 #include "AbstractOdeSystemInformation.hpp"
00041 
00046 class AbstractOdeSystem
00047 {
00048     friend class TestAbstractOdeSystem;
00049 
00050 protected:
00051     unsigned mNumberOfStateVariables;
00052     std::vector<double> mStateVariables;
00053 
00060     boost::shared_ptr<AbstractOdeSystemInformation> mpSystemInfo;
00061 
00063     bool mUseAnalytic;
00064 
00065 public:
00071     AbstractOdeSystem(unsigned numberOfStateVariables = 0);
00072 
00076     virtual ~AbstractOdeSystem();
00077 
00085     virtual void EvaluateYDerivatives(double time, const std::vector<double> &rY,
00086                                       std::vector<double> &rDY)=0;
00087 
00088     unsigned GetNumberOfStateVariables() const
00089     {
00090         return mNumberOfStateVariables;
00091     }
00092 
00093 
00094     void SetInitialConditions(const std::vector<double>& rInitialConditions)
00095     {
00096         if (rInitialConditions.size() != mNumberOfStateVariables)
00097         {
00098             EXCEPTION("The number of initial conditions must be that of the number of state variables");
00099         }
00100         assert(mpSystemInfo);
00101         mpSystemInfo->SetInitialConditions(rInitialConditions);
00102     }
00103 
00104     void SetInitialConditionsComponent(unsigned index, double initialCondition)
00105     {
00106         if ( index >= mNumberOfStateVariables)
00107         {
00108             EXCEPTION("Index is greater than the number of state variables");
00109         }
00110         assert(mpSystemInfo);
00111         mpSystemInfo->SetInitialConditionsComponent(index, initialCondition);
00112     }
00113 
00114 
00115     std::vector<double> GetInitialConditions() const
00116     {
00117         assert(mpSystemInfo);
00118         return mpSystemInfo->GetInitialConditions();
00119     }
00120 
00121     void SetStateVariables(const std::vector<double>& rStateVariables)
00122     {
00123         if ( mNumberOfStateVariables != rStateVariables.size() )
00124         {
00125             EXCEPTION("The size of the passed in vector must be that of the number of state variables");
00126         }
00127         mStateVariables = rStateVariables;
00128     }
00129 
00130     std::vector<double>& rGetStateVariables()
00131     {
00132         return mStateVariables;
00133     }
00134 
00135     std::vector<std::string>& rGetVariableNames()
00136     {
00137         assert(mpSystemInfo);
00138         return mpSystemInfo->rGetVariableNames();
00139     }
00140 
00141     std::vector<std::string>& rGetVariableUnits()
00142     {
00143         assert(mpSystemInfo);
00144         return mpSystemInfo->rGetVariableUnits();
00145     }
00146 
00155     virtual bool CalculateStoppingEvent(double time, const std::vector<double> &rY);
00156     
00164     virtual double CalculateRootFunction(double time, const std::vector<double> &rY)
00165     {
00166         bool stop = CalculateStoppingEvent(time, rY);
00167         return stop ? 0.0 : 1.0;
00168     }
00169 
00170     bool GetUseAnalytic()
00171     {
00172         return mUseAnalytic;
00173     }
00174 
00175 
00186     unsigned GetStateVariableNumberByName(const std::string name)
00187     {
00188         assert(mpSystemInfo);
00189         return mpSystemInfo->GetStateVariableNumberByName(name);
00190     }
00191 
00197     double GetStateVariableValueByNumber(unsigned varNumber) const
00198     {
00199         assert(varNumber < mNumberOfStateVariables);
00200         return mStateVariables[varNumber];
00201     }
00202 
00208     std::string GetStateVariableUnitsByNumber(unsigned varNumber) const
00209     {
00210         assert(varNumber < mNumberOfStateVariables);
00211         assert(mpSystemInfo);
00212         return mpSystemInfo->GetStateVariableUnitsByNumber(varNumber);
00213     }
00214 
00215 protected:
00221     std::string DumpState(const std::string& message,
00222                           std::vector<double> Y = std::vector<double>());
00223 };
00224 
00225 
00226 #endif //_ABSTRACTODESYSTEM_HPP_

Generated on Wed Mar 18 12:51:56 2009 for Chaste by  doxygen 1.5.5