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 #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 <boost/serialization/access.hpp> 00037 #include <boost/serialization/vector.hpp> 00038 #include <boost/serialization/is_abstract.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 // archive &mpSystemInfo; 00100 } 00101 00102 protected: 00103 00105 unsigned mNumberOfStateVariables; 00106 00108 std::vector<double> mStateVariables; 00109 00111 std::vector<double> mParameters; 00112 00119 boost::shared_ptr<AbstractOdeSystemInformation> mpSystemInfo; 00120 00122 bool mUseAnalyticJacobian; 00123 00124 public: 00125 00131 AbstractOdeSystem(unsigned numberOfStateVariables = 0); 00132 00136 virtual ~AbstractOdeSystem(); 00137 00145 virtual void EvaluateYDerivatives(double time, const std::vector<double>& rY, 00146 std::vector<double>& rDY)=0; 00147 00153 unsigned GetNumberOfStateVariables() const; 00154 00155 00159 unsigned GetNumberOfParameters() const; 00160 00166 double GetParameter(unsigned index) const; 00167 00174 void SetParameter(unsigned index, double value); 00175 00179 const std::vector<std::string>& rGetParameterNames() const; 00180 00184 const std::vector<std::string>& rGetParameterUnits() const; 00185 00186 00192 void SetInitialConditions(const std::vector<double>& rInitialConditions); 00193 00200 void SetInitialConditionsComponent(unsigned index, double initialCondition); 00201 00205 std::vector<double> GetInitialConditions() const; 00206 00212 void SetStateVariables(const std::vector<double>& rStateVariables); 00213 00220 void SetStateVariable(unsigned stateVariable, double newValue); 00221 00225 std::vector<double>& rGetStateVariables(); 00226 00230 const std::vector<std::string>& rGetVariableNames() const; 00231 00235 const std::vector<std::string>& rGetVariableUnits() const; 00236 00248 virtual bool CalculateStoppingEvent(double time, const std::vector<double>& rY); 00249 00260 virtual double CalculateRootFunction(double time, const std::vector<double>& rY); 00261 00267 bool GetUseAnalyticJacobian(); 00268 00280 unsigned GetStateVariableNumberByName(const std::string name); 00281 00290 double GetStateVariableValueByNumber(unsigned varNumber) const; 00291 00299 std::string GetStateVariableUnitsByNumber(unsigned varNumber) const; 00300 00304 boost::shared_ptr<const AbstractOdeSystemInformation> GetSystemInformation() const; 00305 00306 protected: 00307 00316 std::string DumpState(const std::string& rMessage, 00317 std::vector<double> Y = std::vector<double>()); 00318 }; 00319 00320 BOOST_IS_ABSTRACT(AbstractOdeSystem) 00321 00322 00323 #endif //_ABSTRACTODESYSTEM_HPP_