Chaste  Release::3.4
AbstractCardiacCell.cpp
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 #include "AbstractCardiacCell.hpp"
36 
37 #include <cassert>
38 #include <iostream>
39 
40 #include "HeartConfig.hpp"
41 #include "Exception.hpp"
42 
43 AbstractCardiacCell::AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver> pOdeSolver,
44  unsigned numberOfStateVariables,
45  unsigned voltageIndex,
46  boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
47  : AbstractCardiacCellInterface(pOdeSolver, voltageIndex, pIntracellularStimulus),
48  AbstractOdeSystem(numberOfStateVariables),
49  mDt(HeartConfig::Instance()->GetOdeTimeStep())
50 {
51  // The second clause is to allow for FakeBathCell.
52  assert(voltageIndex < mNumberOfStateVariables || mNumberOfStateVariables == 0);
53 }
54 
56 {
57 }
58 
60 {
62  mParameters.resize(rGetParameterNames().size());
63 }
64 
66 {
67  mDt = dt;
68 }
69 
70 void AbstractCardiacCell::SolveAndUpdateState(double tStart, double tEnd)
71 {
72  mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
73 }
74 
75 OdeSolution AbstractCardiacCell::Compute(double tStart, double tEnd, double tSamp)
76 {
77  if (tSamp < mDt)
78  {
79  tSamp = mDt;
80  }
81  return mpOdeSolver->Solve(this, rGetStateVariables(), tStart, tEnd, mDt, tSamp);
82 }
83 
84 void AbstractCardiacCell::ComputeExceptVoltage(double tStart, double tEnd)
85 {
86  double saved_voltage = GetVoltage();
87 
89  mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
91 
92  SetVoltage(saved_voltage); // In case of naughty models
93 
94 #ifndef NDEBUG
95  // Note that tests which rely on this throwing (e.g. such-and-such a variable is out of range)
96  // ought to be annotated with the NDEBUG macro
98 #endif // NDEBUG
99 }
100 
102 {
103  SetAnyVariable(mVoltageIndex, voltage);
104  SetFixedVoltage(voltage);
105 }
106 
108 {
110 }
111 
113 {
115 }
116 
118 {
120 }
121 
123 {
125 }
126 
127 const std::vector<std::string>& AbstractCardiacCell::rGetStateVariableNames() const
128 {
130 }
131 
132 void AbstractCardiacCell::SetStateVariables(const std::vector<double>& rVariables)
133 {
135 }
136 
137 void AbstractCardiacCell::SetStateVariable(unsigned index, double newValue)
138 {
139  AbstractOdeSystem::SetStateVariable(index, newValue);
140 }
141 
142 void AbstractCardiacCell::SetStateVariable(const std::string& rName, double newValue)
143 {
144  AbstractOdeSystem::SetStateVariable(rName, newValue);
145 }
146 
147 double AbstractCardiacCell::GetAnyVariable(const std::string& rName, double time)
148 {
149  return AbstractOdeSystem::GetAnyVariable(rName, time);
150 }
151 
152 double AbstractCardiacCell::GetParameter(const std::string& rParameterName)
153 {
154  return AbstractOdeSystem::GetParameter(rParameterName);
155 }
156 
157 double AbstractCardiacCell::GetParameter(unsigned parameterIndex)
158 {
159  return AbstractOdeSystem::GetParameter(parameterIndex);
160 }
161 
162 void AbstractCardiacCell::SetParameter(const std::string& rParameterName, double value)
163 {
164  AbstractOdeSystem::SetParameter(rParameterName,value);
165 }
166 
167 #include "LuoRudy1991.hpp"
168 #include "LuoRudy1991BackwardEuler.hpp"
170 {
171  if (dynamic_cast<CellLuoRudy1991FromCellML*>(this) || dynamic_cast<CellLuoRudy1991FromCellMLBackwardEuler*>(this))
172  {
173  // If you do reach this, then you can try un-commenting the below, but you would be better re-generating your archive with a new version of Chaste.
175 // // The LR91 model saved in previous Chaste versions had a different ordering of state variables...
176 // // Old is h, j, m, CaI, V, d, f, x
177 // // New is V, m, h, j, d, f, X, [Ca]
178 // assert(GetNumberOfStateVariables() == 8);
179 // unsigned var_index_map[8] = {2, 3, 1, 7, 0, 4, 5, 6};
180 // std::vector<double> old_state(this->mStateVariables);
181 // for (unsigned i=0; i<8; i++)
182 // {
183 // this->mStateVariables[var_index_map[i]] = old_state[i];
184 // }
185 // // It also didn't used to have parameters...
186 // this->mParameters.resize(this->rGetParameterNames().size());
187 // assert(this->mParameters.size() == 3u);
188 // this->mParameters[0] = 0.09;
189 // this->mParameters[1] = 23.0;
190 // this->mParameters[2] = 0.282;
191  }
192 }
193 
194 
195 /*
196  * METHODS NEEDED BY FAST CARDIAC CELLS
197  */
198 void AbstractCardiacCell::SetState(CellModelState state)
199 {
200  EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
201 }
202 
203 void AbstractCardiacCell::SetSlowValues(const std::vector<double> &rSlowValues)
204 {
205  EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
206 }
207 
208 void AbstractCardiacCell::GetSlowValues(std::vector<double>& rSlowValues)
209 {
210  EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
211 }
212 
214 {
215  EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
216 }
217 
219 {
220  EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
221 }
222 
223 void AbstractCardiacCell::AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues)
224 {
225  EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
226 }
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 EXCEPTION(message)
Definition: Exception.hpp:143
double GetParameter(const std::string &rParameterName)
std::vector< double > GetStdVecStateVariables()
const std::vector< std::string > & rGetStateVariableNames() const
void SetStateVariables(const std::vector< double > &rStateVariables)
const std::vector< std::string > & rGetStateVariableNames() const
#define NEVER_REACHED
Definition: Exception.hpp:206
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 SetAnyVariable(unsigned index, double value)
void SetParameter(const std::string &rName, double value)
void SetStateVariables(const std::vector< double > &rVariables)
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)
virtual void GetSlowValues(std::vector< double > &rSlowValues)
virtual void SetVoltageDerivativeToZero(bool clamp=true)
boost::shared_ptr< AbstractIvpOdeSolver > mpOdeSolver
void SetStateVariable(unsigned index, double newValue)
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
double GetAnyVariable(unsigned index, double time=0.0, std::vector< double > *pDerivedQuantities=NULL)