Chaste Release::3.1
AbstractCardiacCell.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef ABSTRACTCARDIACCELL_HPP_
00037 #define ABSTRACTCARDIACCELL_HPP_
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include "ChasteSerializationVersion.hpp"
00041 #include "ClassIsAbstract.hpp"
00042 #include <boost/serialization/base_object.hpp>
00043 #include <boost/shared_ptr.hpp>
00044 #include <boost/serialization/shared_ptr.hpp>
00045 
00046 
00047 // This is only needed to prevent compilation errors on PETSc 2.2/Boost 1.33.1 combo
00048 #include "UblasVectorInclude.hpp"
00049 
00050 #include "AbstractCardiacCellInterface.hpp"
00051 #include "AbstractOdeSystem.hpp"
00052 #include "AbstractIvpOdeSolver.hpp"
00053 #include "AbstractStimulusFunction.hpp"
00054 
00055 #include <vector>
00056 
00057 typedef enum _CellModelState
00058 {
00059     STATE_UNSET = 0,
00060     FAST_VARS_ONLY,
00061     ALL_VARS
00062 } CellModelState;
00063 
00074 class AbstractCardiacCell : public AbstractCardiacCellInterface, public AbstractOdeSystem
00075 {
00076 private:
00078     friend class boost::serialization::access;
00085     template<class Archive>
00086     void serialize(Archive & archive, const unsigned int version)
00087     {
00088         // This calls serialize on the base class.
00089         archive & boost::serialization::base_object<AbstractOdeSystem>(*this);
00090 
00091         if (version > 0)
00092         {
00093             archive & boost::serialization::base_object<AbstractCardiacCellInterface>(*this);
00094         }
00095         archive & mDt;
00096 
00097         // For version 2 and above these move into AbstractCardiacCellInterface
00098         // (AbstractCardiacCellInterface serialization moved to 1 at the same time as this moved to 2).
00099         if (version <= 1)
00100         {
00101             archive & this->mSetVoltageDerivativeToZero;
00102             if (version > 0)
00103             {
00104                 // Note that when loading a version 0 archive, this will be initialised to
00105                 // false by our constructor.  So we should get a consistent (wrong) answer
00106                 // with previous versions of Chaste when in tissue.
00107                 archive & this->mIsUsedInTissue;
00108                 archive & this->mHasDefaultStimulusFromCellML;
00109             }
00110         }
00111 
00112         if (version == 0)
00113         {
00114             CheckForArchiveFix();
00115         }
00116 
00117         // Paranoia check
00118         assert(this->mParameters.size() == this->rGetParameterNames().size());
00119     }
00120 
00126     void CheckForArchiveFix();
00127 
00128 protected:
00130     double mDt;
00131 
00132 public:
00144     AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver> pOdeSolver,
00145                         unsigned numberOfStateVariables,
00146                         unsigned voltageIndex,
00147                         boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00148 
00150     virtual ~AbstractCardiacCell();
00151 
00159     void Init();
00160 
00166     void SetTimestep(double dt);
00167 
00175     virtual void SolveAndUpdateState(double tStart, double tEnd);
00176 
00185     virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0);
00186 
00194     virtual void ComputeExceptVoltage(double tStart, double tEnd);
00195 
00199     void SetVoltage(double voltage);
00200 
00205     double GetVoltage();
00206 
00207 
00217     unsigned GetNumberOfStateVariables() const;
00218 
00228     unsigned GetNumberOfParameters() const;
00229 
00239     std::vector<double> GetStdVecStateVariables();
00240 
00250     const std::vector<std::string>& rGetStateVariableNames() const;
00251 
00252 
00262     void SetStateVariables(const std::vector<double>& rVariables);
00263 
00274     void SetStateVariable(unsigned index, double newValue);
00275 
00286     void SetStateVariable(const std::string& rName, double newValue);
00287 
00299     double GetAnyVariable(const std::string& rName, double time=0.0);
00300 
00311     double GetParameter(const std::string& rParameterName);
00312 
00323     double GetParameter(unsigned parameterIndex);
00324 
00335     void SetParameter(const std::string& rParameterName, double value);
00336 
00347     void SetParameter(unsigned parameterIndex, double value);
00348 
00350     //  METHODS NEEDED BY FAST CARDIAC CELLS
00352 
00364     virtual void SetState(CellModelState state);
00365 
00373     virtual void SetSlowValues(const std::vector<double> &rSlowValues);
00374 
00382     virtual void GetSlowValues(std::vector<double>& rSlowValues);
00383 
00388     virtual bool IsFastOnly();
00389 
00402     virtual void AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues);
00403 
00410     virtual unsigned GetNumSlowValues();
00411 
00412 };
00413 
00414 CLASS_IS_ABSTRACT(AbstractCardiacCell)
00415 BOOST_CLASS_VERSION(AbstractCardiacCell, 2)
00416 
00417 #endif /*ABSTRACTCARDIACCELL_HPP_*/