AbstractCardiacCell.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 ABSTRACTCARDIACCELL_HPP_
00030 #define ABSTRACTCARDIACCELL_HPP_
00031 
00032 #include "ChasteSerialization.hpp"
00033 #include "ClassIsAbstract.hpp"
00034 #include <boost/serialization/base_object.hpp>
00035 #include <boost/shared_ptr.hpp>
00036 #include <boost/serialization/shared_ptr.hpp>
00037 #include <boost/serialization/version.hpp>
00038 
00039 // This is only needed to prevent compilation errors on PETSc 2.2/Boost 1.33.1 combo
00040 #include "UblasVectorInclude.hpp"
00041 
00042 #include "AbstractCardiacCellInterface.hpp"
00043 #include "AbstractOdeSystem.hpp"
00044 #include "AbstractIvpOdeSolver.hpp"
00045 #include "AbstractStimulusFunction.hpp"
00046 
00047 #include <vector>
00048 
00049 typedef enum _CellModelState
00050 {
00051     STATE_UNSET = 0,
00052     FAST_VARS_ONLY,
00053     ALL_VARS
00054 } CellModelState;
00055 
00066 class AbstractCardiacCell : public AbstractCardiacCellInterface, public AbstractOdeSystem
00067 {
00068 private:
00070     friend class boost::serialization::access;
00077     template<class Archive>
00078     void serialize(Archive & archive, const unsigned int version)
00079     {
00080         // This calls serialize on the base class.
00081         archive & boost::serialization::base_object<AbstractOdeSystem>(*this);
00082         if (version > 0)
00083         {
00084             archive & boost::serialization::base_object<AbstractCardiacCellInterface>(*this);
00085         }
00086         archive & mDt;
00087         archive & this->mSetVoltageDerivativeToZero;
00088         if (version > 0)
00089         {
00090             // Note that when loading a version 0 archive, this will be initialised to
00091             // false by our constructor.  So we should get a consistent (wrong) answer
00092             // with previous versions of Chaste when in tissue.
00093             archive & this->mIsUsedInTissue;
00094             archive & this->mHasDefaultStimulusFromCellML;
00095         }
00096         // archive & mVoltageIndex; - always set by constructor - called by concrete class
00097         // archive & mpOdeSolver; - always set by constructor - called by concrete class
00098         // archive & mpIntracellularStimulus; - always set by constructor - called by concrete class
00099         if (version == 0)
00100         {
00101             CheckForArchiveFix();
00102         }
00103         // Paranoia check
00104         assert(this->mParameters.size() == this->rGetParameterNames().size());
00105     }
00106 
00112     void CheckForArchiveFix();
00113 
00114 protected:
00116     double mDt;
00117 
00118 public:
00130     AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver> pOdeSolver,
00131                         unsigned numberOfStateVariables,
00132                         unsigned voltageIndex,
00133                         boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00134 
00136     virtual ~AbstractCardiacCell();
00137 
00145     void Init();
00146 
00150     void ResetToInitialConditions();
00151 
00157     void SetTimestep(double dt);
00158 
00166     virtual void SolveAndUpdateState(double tStart, double tEnd);
00167 
00176     virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0);
00177 
00185     virtual void ComputeExceptVoltage(double tStart, double tEnd);
00186 
00190     void SetVoltage(double voltage);
00191 
00196     double GetVoltage();
00197 
00205     virtual double GetIntracellularCalciumConcentration();
00206 
00214     virtual void SetStretch(double stretch)
00215     {
00216     }
00217 
00224     virtual void VerifyStateVariables()
00225     {
00232 //        for(std::set<unsigned>::iterator iter = mGatingVariableIndices.begin();
00233 //            iter != mGatingVariableIndices.end();
00234 //            ++iter)
00235 //        {
00236 //            double value = mStateVariables[*iter];
00237 //            if(value<0.0)
00238 //            {
00239 //                std::stringstream error;
00240 //                error << "State variable " << *iter << ", a gating variable, has gone negative";
00241 //                EXCEPTION(DumpState(error.str()));
00242 //            }
00243 //            if(value>1.0)
00244 //            {
00245 //                std::stringstream error;
00246 //                error << "State variable " << *iter << ", a gating variable, has become greater than one";
00247 //                EXCEPTION(DumpState(error.str()));
00248 //            }
00249 //        }
00250 //
00251 //        for(std::set<unsigned>::iterator iter = mConcentrationIndices.begin();
00252 //            iter != mConcentrationIndices.end();
00253 //            ++iter)
00254 //        {
00255 //            if(mStateVariables[*iter] < 0.0)
00256 //            {
00257 //                std::stringstream error;
00258 //                error << "State variable " << *iter << ", a concentration, has gone negative";
00259 //                EXCEPTION(DumpState(error.str()));
00260 //            }
00261 //        }
00262     }
00263 
00264 
00265 
00267     //  METHODS NEEDED BY FAST CARDIAC CELLS
00269 
00281     virtual void SetState(CellModelState state);
00282 
00290     virtual void SetSlowValues(const std::vector<double> &rSlowValues);
00291 
00299     virtual void GetSlowValues(std::vector<double>& rSlowValues);
00300 
00305     virtual bool IsFastOnly();
00306 
00319     virtual void AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues);
00320 
00327     virtual unsigned GetNumSlowValues();
00328 
00329 };
00330 
00331 CLASS_IS_ABSTRACT(AbstractCardiacCell)
00332 BOOST_CLASS_VERSION(AbstractCardiacCell, 1)
00333 
00334 #endif /*ABSTRACTCARDIACCELL_HPP_*/

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5