Chaste  Release::3.4
AbstractCardiacCell.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef ABSTRACTCARDIACCELL_HPP_
37 #define ABSTRACTCARDIACCELL_HPP_
38 
39 #include "ChasteSerialization.hpp"
41 #include "ClassIsAbstract.hpp"
42 #include <boost/serialization/base_object.hpp>
43 #include <boost/shared_ptr.hpp>
44 #include <boost/serialization/shared_ptr.hpp>
45 
46 
47 // This is only needed to prevent compilation errors on PETSc 2.2/Boost 1.33.1 combo
48 #include "UblasVectorInclude.hpp"
49 
50 #include "AbstractCardiacCellInterface.hpp"
51 #include "AbstractOdeSystem.hpp"
52 #include "AbstractIvpOdeSolver.hpp"
53 #include "AbstractStimulusFunction.hpp"
54 
55 #include <vector>
56 
57 typedef enum _CellModelState
58 {
59  STATE_UNSET = 0,
60  FAST_VARS_ONLY,
61  ALL_VARS
62 } CellModelState;
63 
75 {
76 private:
85  template<class Archive>
86  void serialize(Archive & archive, const unsigned int version)
87  {
88  // This calls serialize on the base class.
89  archive & boost::serialization::base_object<AbstractOdeSystem>(*this);
90 
91  if (version > 0)
92  {
93  archive & boost::serialization::base_object<AbstractCardiacCellInterface>(*this);
94  }
95  archive & mDt;
96 
97  // For version 2 and above these move into AbstractCardiacCellInterface
98  // (AbstractCardiacCellInterface serialization moved to 1 at the same time as this moved to 2).
99  if (version <= 1)
100  {
101  archive & this->mSetVoltageDerivativeToZero;
102  if (version > 0)
103  {
104  // Note that when loading a version 0 archive, this will be initialised to
105  // false by our constructor. So we should get a consistent (wrong) answer
106  // with previous versions of Chaste when in tissue.
107  archive & this->mIsUsedInTissue;
108  archive & this->mHasDefaultStimulusFromCellML;
109  }
110  }
111 
112  if (version == 0)
113  {
115  }
116 
117  // Paranoia check
118  assert(this->mParameters.size() == this->rGetParameterNames().size());
119  }
120 
133  void CheckForArchiveFix();
134 
135 protected:
137  double mDt;
138 
139 public:
151  AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver> pOdeSolver,
152  unsigned numberOfStateVariables,
153  unsigned voltageIndex,
154  boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
155 
157  virtual ~AbstractCardiacCell();
158 
166  void Init();
167 
173  void SetTimestep(double dt);
174 
182  virtual void SolveAndUpdateState(double tStart, double tEnd);
183 
193  virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0);
194 
202  virtual void ComputeExceptVoltage(double tStart, double tEnd);
203 
207  void SetVoltage(double voltage);
208 
213  double GetVoltage();
214 
215 
225  unsigned GetNumberOfStateVariables() const;
226 
236  unsigned GetNumberOfParameters() const;
237 
247  std::vector<double> GetStdVecStateVariables();
248 
258  const std::vector<std::string>& rGetStateVariableNames() const;
259 
260 
270  void SetStateVariables(const std::vector<double>& rVariables);
271 
282  void SetStateVariable(unsigned index, double newValue);
283 
294  void SetStateVariable(const std::string& rName, double newValue);
295 
307  double GetAnyVariable(const std::string& rName, double time=0.0);
308 
319  double GetParameter(const std::string& rParameterName);
320 
331  double GetParameter(unsigned parameterIndex);
332 
343  void SetParameter(const std::string& rParameterName, double value);
344 
346  // METHODS NEEDED BY FAST CARDIAC CELLS
348 
360  virtual void SetState(CellModelState state);
361 
369  virtual void SetSlowValues(const std::vector<double> &rSlowValues);
370 
378  virtual void GetSlowValues(std::vector<double>& rSlowValues);
379 
384  virtual bool IsFastOnly();
385 
398  virtual void AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues);
399 
406  virtual unsigned GetNumSlowValues();
407 
408 };
409 
411 BOOST_CLASS_VERSION(AbstractCardiacCell, 2)
412 
413 #endif /*ABSTRACTCARDIACCELL_HPP_*/
virtual void SetSlowValues(const std::vector< double > &rSlowValues)
virtual unsigned GetNumSlowValues()
AbstractCardiacCell(boost::shared_ptr< AbstractIvpOdeSolver > pOdeSolver, unsigned numberOfStateVariables, unsigned voltageIndex, boost::shared_ptr< AbstractStimulusFunction > pIntracellularStimulus)
#define CLASS_IS_ABSTRACT(T)
double GetParameter(const std::string &rParameterName)
std::vector< double > GetStdVecStateVariables()
const std::vector< std::string > & rGetStateVariableNames() const
double GetAnyVariable(const std::string &rName, double time=0.0)
virtual void SetState(CellModelState state)
virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)
void SetStateVariables(const std::vector< double > &rVariables)
friend class boost::serialization::access
virtual void SolveAndUpdateState(double tStart, double tEnd)
void SetParameter(const std::string &rParameterName, double value)
unsigned GetNumberOfParameters() const
void SetStateVariable(unsigned index, double newValue)
void SetTimestep(double dt)
void serialize(Archive &archive, const unsigned int version)
virtual void GetSlowValues(std::vector< double > &rSlowValues)
void SetVoltage(double voltage)
virtual void AdjustOutOfRangeSlowValues(std::vector< double > &rSlowValues)
unsigned GetNumberOfStateVariables() const
virtual void ComputeExceptVoltage(double tStart, double tEnd)
const std::vector< std::string > & rGetParameterNames() const