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 #include <vector>
00033 #include <string>
00034 
00035 
00036 #include "ChasteSerialization.hpp"
00037 #include <boost/serialization/split_member.hpp>
00038 #include <boost/serialization/vector.hpp>
00039 #include <boost/serialization/version.hpp>
00040 #include "ClassIsAbstract.hpp"
00041 
00042 #include "AbstractParameterisedSystem.hpp"
00043 #include "Exception.hpp"
00044 
00079 class AbstractOdeSystem : public AbstractParameterisedSystem<std::vector<double> >
00080 {
00081     friend class TestAbstractOdeSystem;
00082 
00083 private:
00084 
00085 
00086     friend class boost::serialization::access;
00093     template<class Archive>
00094     void save(Archive & archive, const unsigned int version) const
00095     {
00096         // Despite the fact that 3 of these variables actually live in our base class,
00097         // we still archive them here to maintain backwards compatibility.  Since the
00098         // N_Vector version of AbstractParameterisedSystem doesn't get checkpointed yet,
00099         // this doesn't hurt.
00100         archive & mNumberOfStateVariables;
00101         archive & mUseAnalyticJacobian;
00102         archive & mStateVariables;
00103         archive & mParameters;
00104         
00105         if (version > 0)
00106         {
00107             archive & rGetParameterNames();
00108         }
00109         
00110         // This is always set up by subclass constructors, and is essentially
00111         // 'static' data, so shouldn't go in the archive.
00112         //archive &mpSystemInfo;
00113     }
00120     template<class Archive>
00121     void load(Archive & archive, const unsigned int version)
00122     {
00123         archive & mNumberOfStateVariables;
00124         archive & mUseAnalyticJacobian;
00125         archive & mStateVariables;
00126         archive & mParameters;
00127         
00128         if (version > 0)
00129         {
00130             std::vector<std::string> param_names;
00131             archive & param_names;
00132             
00133             if (param_names.size() != rGetParameterNames().size())
00134             {
00135                 EXCEPTION("Number of ODE parameters in archive does not match number in class.");
00136             }
00137             for (unsigned i=0; i<param_names.size(); ++i)
00138             {
00139                 if (param_names[i] != rGetParameterNames()[i])
00140                 {
00141                     std::string message = "ODE system parameter names do not match: '"
00142                         + param_names[i] + "' in archive but '" + rGetParameterNames()[i] + "' in class."; 
00143                     EXCEPTION(message);
00144                 }
00145             }
00146         }
00147     }
00148     BOOST_SERIALIZATION_SPLIT_MEMBER()
00149 
00150 protected:
00151 
00153     bool mUseAnalyticJacobian;
00154 
00163     std::string DumpState(const std::string& rMessage,
00164                           std::vector<double> Y = std::vector<double>());
00165 
00166 public:
00167 
00173     AbstractOdeSystem(unsigned numberOfStateVariables);
00174 
00178     virtual ~AbstractOdeSystem();
00179 
00187     virtual void EvaluateYDerivatives(double time, const std::vector<double>& rY,
00188                                       std::vector<double>& rDY)=0;
00189 
00196     void SetDefaultInitialConditions(const std::vector<double>& rInitialConditions);
00197 
00205     void SetDefaultInitialCondition(unsigned index, double initialCondition);
00206 
00210     std::vector<double> GetInitialConditions() const;
00211 
00217     void SetStateVariables(const std::vector<double>& rStateVariables);
00218 
00230     virtual bool CalculateStoppingEvent(double time, const std::vector<double>& rY);
00231 
00242     virtual double CalculateRootFunction(double time, const std::vector<double>& rY);
00243 
00249     bool GetUseAnalyticJacobian();
00250 
00256     const std::vector<double>& rGetConstStateVariables() const;
00257 };
00258 
00259 CLASS_IS_ABSTRACT(AbstractOdeSystem)
00260 BOOST_CLASS_VERSION(AbstractOdeSystem, 1u)
00261 
00262 #endif //_ABSTRACTODESYSTEM_HPP_

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