AbstractOdeSystem.hpp

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 #ifndef _ABSTRACTODESYSTEM_HPP_
00030 #define _ABSTRACTODESYSTEM_HPP_
00031 
00032 
00033 #include <cassert>
00034 #include <climits> // Work around a boost bug - see #1024.
00035 
00036 #include "ChasteSerialization.hpp"
00037 #include <boost/serialization/vector.hpp>
00038 #include "ClassIsAbstract.hpp"
00039 #include <boost/shared_ptr.hpp>
00040 
00041 #include "Exception.hpp"
00042 #include "AbstractOdeSystemInformation.hpp"
00043 
00077 class AbstractOdeSystem
00078 {
00079     friend class TestAbstractOdeSystem;
00080 
00082     friend class boost::serialization::access;
00083 private:
00090     template<class Archive>
00091     void serialize(Archive & archive, const unsigned int version)
00092     {
00093         archive & mNumberOfStateVariables;
00094         archive & mUseAnalyticJacobian;
00095         archive & mStateVariables;
00096         archive & mParameters;
00097 
00098         // This is always set up by subclass constructors, and is essentially
00099         // 'static' data, so shouldn't go in the archive.
00100         //archive &mpSystemInfo;
00101     }
00102 
00103 protected:
00104 
00106     unsigned mNumberOfStateVariables;
00107 
00109     std::vector<double> mStateVariables;
00110 
00112     std::vector<double> mParameters;
00113 
00120     boost::shared_ptr<AbstractOdeSystemInformation> mpSystemInfo;
00121 
00123     bool mUseAnalyticJacobian;
00124 
00125 public:
00126 
00132     AbstractOdeSystem(unsigned numberOfStateVariables = 0);
00133 
00137     virtual ~AbstractOdeSystem();
00138 
00146     virtual void EvaluateYDerivatives(double time, const std::vector<double>& rY,
00147                                       std::vector<double>& rDY)=0;
00148 
00154     unsigned GetNumberOfStateVariables() const;
00155 
00156 
00160     unsigned GetNumberOfParameters() const;
00161 
00167     double GetParameter(unsigned index) const;
00168 
00175     void SetParameter(unsigned index, double value);
00176 
00180     const std::vector<std::string>& rGetParameterNames() const;
00181 
00185     const std::vector<std::string>& rGetParameterUnits() const;
00186 
00187 
00193     void SetInitialConditions(const std::vector<double>& rInitialConditions);
00194 
00201     void SetInitialConditionsComponent(unsigned index, double initialCondition);
00202 
00206     std::vector<double> GetInitialConditions() const;
00207 
00213     void SetStateVariables(const std::vector<double>& rStateVariables);
00214 
00221     void SetStateVariable(unsigned stateVariable, double newValue);
00222 
00226     std::vector<double>& rGetStateVariables();
00227 
00231     const std::vector<std::string>& rGetVariableNames() const;
00232 
00236     const std::vector<std::string>& rGetVariableUnits() const;
00237 
00249     virtual bool CalculateStoppingEvent(double time, const std::vector<double>& rY);
00250 
00261     virtual double CalculateRootFunction(double time, const std::vector<double>& rY);
00262 
00268     bool GetUseAnalyticJacobian();
00269 
00281     unsigned GetStateVariableNumberByName(const std::string name) const;
00282 
00291     double GetStateVariableValueByNumber(unsigned varNumber) const;
00292 
00300     std::string GetStateVariableUnitsByNumber(unsigned varNumber) const;
00301 
00305     boost::shared_ptr<const AbstractOdeSystemInformation> GetSystemInformation() const;
00306 
00307 protected:
00308 
00317     std::string DumpState(const std::string& rMessage,
00318                           std::vector<double> Y = std::vector<double>());
00319 };
00320 
00321 CLASS_IS_ABSTRACT(AbstractOdeSystem)
00322 
00323 
00324 #endif //_ABSTRACTODESYSTEM_HPP_

Generated by  doxygen 1.6.2