Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
AbstractRushLarsenCardiacCell.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
36#include "AbstractRushLarsenCardiacCell.hpp"
37
38#include <cassert>
39#include <cmath>
40
41#include "Exception.hpp"
42#include "OdeSolution.hpp"
43#include "TimeStepper.hpp"
44
46 unsigned voltageIndex,
47 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
48 : AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver>(),
49 numberOfStateVariables,
50 voltageIndex,
51 pIntracellularStimulus)
52{}
53
56
57OdeSolution AbstractRushLarsenCardiacCell::Compute(double tStart, double tEnd, double tSamp)
58{
59 // In this method, we iterate over timesteps, doing the following for each:
60 // - update V using a forward Euler step
61 // - do as in ComputeExceptVoltage(t) to update the remaining state variables
62 // using Rush Larsen method or forward Euler as appropriate
63
64 // Check length of time interval
65 if (tSamp < mDt)
66 {
67 tSamp = mDt;
68 }
69 const unsigned n_steps = (unsigned) floor((tEnd - tStart)/tSamp + 0.5);
70 assert(fabs(tStart+n_steps*tSamp - tEnd) < 1e-12);
71 const unsigned n_small_steps = (unsigned) floor(tSamp/mDt+0.5);
72 assert(fabs(mDt*n_small_steps - tSamp) < 1e-12);
73
74 // Initialise solution store
75 OdeSolution solutions;
76 solutions.SetNumberOfTimeSteps(n_steps);
77 solutions.rGetSolutions().push_back(rGetStateVariables());
78 solutions.rGetTimes().push_back(tStart);
80
81 std::vector<double> dy(mNumberOfStateVariables, 0);
82 std::vector<double> alpha(mNumberOfStateVariables, 0);
83 std::vector<double> beta(mNumberOfStateVariables, 0);
84
85 // Loop over time
86 for (unsigned i=0; i<n_steps; i++)
87 {
88 double curr_time = tStart;
89 for (unsigned j=0; j<n_small_steps; j++)
90 {
91 curr_time = tStart + i*tSamp + j*mDt;
92 EvaluateEquations(curr_time, dy, alpha, beta);
94 ComputeOneStepExceptVoltage(dy, alpha, beta);
96 }
97
98 // Update solutions
99 solutions.rGetSolutions().push_back(rGetStateVariables());
100 solutions.rGetTimes().push_back(curr_time+mDt);
101 }
102
103 return solutions;
104}
105
107{
109 TimeStepper stepper(tStart, tEnd, mDt);
110
111 std::vector<double> dy(mNumberOfStateVariables, 0);
112 std::vector<double> alpha(mNumberOfStateVariables, 0);
113 std::vector<double> beta(mNumberOfStateVariables, 0);
114
115 while (!stepper.IsTimeAtEnd())
116 {
117 EvaluateEquations(stepper.GetTime(), dy, alpha, beta);
118 ComputeOneStepExceptVoltage(dy, alpha, beta);
119
120#ifndef NDEBUG
121 // Check gating variables are still in range
123#endif // NDEBUG
124
125 stepper.AdvanceOneTimeStep();
126 }
128}
129
131{
132 TimeStepper stepper(tStart, tEnd, mDt);
133
134 std::vector<double> dy(mNumberOfStateVariables, 0);
135 std::vector<double> alpha(mNumberOfStateVariables, 0);
136 std::vector<double> beta(mNumberOfStateVariables, 0);
137
138 while (!stepper.IsTimeAtEnd())
139 {
140 EvaluateEquations(stepper.GetTime(), dy, alpha, beta);
142 ComputeOneStepExceptVoltage(dy, alpha, beta);
144
145 stepper.AdvanceOneTimeStep();
146 }
147}
148
150{
151 unsigned v_index = GetVoltageIndex();
152 rGetStateVariables()[v_index] += mDt*rDY[v_index];
153}
virtual void ComputeOneStepExceptVoltage(const std::vector< double > &rDY, const std::vector< double > &rAlphaOrTau, const std::vector< double > &rBetaOrInf)=0
OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)
AbstractRushLarsenCardiacCell(unsigned numberOfStateVariables, unsigned voltageIndex, boost::shared_ptr< AbstractStimulusFunction > pIntracellularStimulus)
void SolveAndUpdateState(double tStart, double tEnd)
virtual void EvaluateEquations(double time, std::vector< double > &rDY, std::vector< double > &rAlphaOrTau, std::vector< double > &rBetaOrInf)=0
void UpdateTransmembranePotential(const std::vector< double > &rDY)
void ComputeExceptVoltage(double tStart, double tEnd)
boost::shared_ptr< AbstractOdeSystemInformation > mpSystemInfo
void SetNumberOfTimeSteps(unsigned numTimeSteps)
std::vector< std::vector< double > > & rGetSolutions()
std::vector< double > & rGetTimes()
void SetOdeSystemInformation(boost::shared_ptr< const AbstractOdeSystemInformation > pOdeSystemInfo)
bool IsTimeAtEnd() const
double GetTime() const
void AdvanceOneTimeStep()