Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
AbstractCardiacCell.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
43AbstractCardiacCell::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
58
64
66{
67 mDt = dt;
68}
69
70void AbstractCardiacCell::SolveAndUpdateState(double tStart, double tEnd)
71{
72 mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
73}
74
75OdeSolution AbstractCardiacCell::Compute(double tStart, double tEnd, double tSamp)
76{
77 if (tSamp < mDt)
78 {
79 tSamp = mDt;
80 }
81 OdeSolution solution = mpOdeSolver->Solve(this, rGetStateVariables(), tStart, tEnd, mDt, tSamp);
82#ifndef NDEBUG
83 // Note that tests which rely on this throwing (e.g. such-and-such a variable is out of range)
84 // ought to be annotated with the NDEBUG macro
86#endif // NDEBUG
87 return solution;
88}
89
90void AbstractCardiacCell::ComputeExceptVoltage(double tStart, double tEnd)
91{
92 double saved_voltage = GetVoltage();
93
95 mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
97
98 SetVoltage(saved_voltage); // In case of naughty models
99
100#ifndef NDEBUG
101 // Note that tests which rely on this throwing (e.g. such-and-such a variable is out of range)
102 // ought to be annotated with the NDEBUG macro
104#endif // NDEBUG
105}
106
108{
110 SetFixedVoltage(voltage);
111}
112
117
122
127
132
133const std::vector<std::string>& AbstractCardiacCell::rGetStateVariableNames() const
134{
136}
137
138void AbstractCardiacCell::SetStateVariables(const std::vector<double>& rVariables)
139{
141}
142
143void AbstractCardiacCell::SetStateVariable(unsigned index, double newValue)
144{
146}
147
148void AbstractCardiacCell::SetStateVariable(const std::string& rName, double newValue)
149{
151}
152
153double AbstractCardiacCell::GetAnyVariable(const std::string& rName, double time)
154{
155 return AbstractOdeSystem::GetAnyVariable(rName, time);
156}
157
158double AbstractCardiacCell::GetParameter(const std::string& rParameterName)
159{
160 return AbstractOdeSystem::GetParameter(rParameterName);
161}
162
163double AbstractCardiacCell::GetParameter(unsigned parameterIndex)
164{
165 return AbstractOdeSystem::GetParameter(parameterIndex);
166}
167
168void AbstractCardiacCell::SetParameter(const std::string& rParameterName, double value)
169{
170 AbstractOdeSystem::SetParameter(rParameterName,value);
171}
172
173#include "LuoRudy1991.hpp"
174#include "LuoRudy1991BackwardEuler.hpp"
176{
177 if (dynamic_cast<CellLuoRudy1991FromCellML*>(this) || dynamic_cast<CellLuoRudy1991FromCellMLBackwardEuler*>(this))
178 {
179 // 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.
181// // The LR91 model saved in previous Chaste versions had a different ordering of state variables...
182// // Old is h, j, m, CaI, V, d, f, x
183// // New is V, m, h, j, d, f, X, [Ca]
184// assert(GetNumberOfStateVariables() == 8);
185// unsigned var_index_map[8] = {2, 3, 1, 7, 0, 4, 5, 6};
186// std::vector<double> old_state(this->mStateVariables);
187// for (unsigned i=0; i<8; i++)
188// {
189// this->mStateVariables[var_index_map[i]] = old_state[i];
190// }
191// // It also didn't used to have parameters...
192// this->mParameters.resize(this->rGetParameterNames().size());
193// assert(this->mParameters.size() == 3u);
194// this->mParameters[0] = 0.09;
195// this->mParameters[1] = 23.0;
196// this->mParameters[2] = 0.282;
197 }
198}
199
200
201/*
202 * METHODS NEEDED BY FAST CARDIAC CELLS
203 */
204void AbstractCardiacCell::SetState(CellModelState state)
205{
206 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
207}
208
209void AbstractCardiacCell::SetSlowValues(const std::vector<double> &rSlowValues)
210{
211 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
212}
213
214void AbstractCardiacCell::GetSlowValues(std::vector<double>& rSlowValues)
215{
216 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
217}
218
220{
221 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
222}
223
225{
226 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
227}
228
229void AbstractCardiacCell::AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues)
230{
231 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
232}
#define EXCEPTION(message)
#define NEVER_REACHED
virtual void SetVoltageDerivativeToZero(bool clamp=true)
boost::shared_ptr< AbstractIvpOdeSolver > mpOdeSolver
virtual void SolveAndUpdateState(double tStart, double tEnd)
double GetParameter(const std::string &rParameterName)
virtual OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)
virtual void AdjustOutOfRangeSlowValues(std::vector< double > &rSlowValues)
virtual void SetState(CellModelState state)
virtual void GetSlowValues(std::vector< double > &rSlowValues)
void SetVoltage(double voltage)
virtual void SetSlowValues(const std::vector< double > &rSlowValues)
void SetParameter(const std::string &rParameterName, double value)
const std::vector< std::string > & rGetStateVariableNames() const
AbstractCardiacCell(boost::shared_ptr< AbstractIvpOdeSolver > pOdeSolver, unsigned numberOfStateVariables, unsigned voltageIndex, boost::shared_ptr< AbstractStimulusFunction > pIntracellularStimulus)
std::vector< double > GetStdVecStateVariables()
double GetAnyVariable(const std::string &rName, double time=0.0)
unsigned GetNumberOfStateVariables() const
void SetStateVariables(const std::vector< double > &rVariables)
virtual unsigned GetNumSlowValues()
virtual void ComputeExceptVoltage(double tStart, double tEnd)
unsigned GetNumberOfParameters() const
void SetStateVariable(unsigned index, double newValue)
void SetStateVariables(const std::vector< double > &rStateVariables)
double GetAnyVariable(unsigned index, double time=0.0, std::vector< double > *pDerivedQuantities=NULL)
void SetParameter(const std::string &rName, double value)
const std::vector< std::string > & rGetParameterNames() const
const std::vector< std::string > & rGetStateVariableNames() const