Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
AbstractGeneralizedRushLarsenCardiacCell.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/*
37Megan E. Marsh, Raymond J. Spiteri
38Numerical Simulation Laboratory
39University of Saskatchewan
40December 2011
41Partial support provided by research grants from the National
42Science and Engineering Research Council (NSERC) of Canada
43and the MITACS/Mprime Canadian Network of Centres of Excellence.
44*/
45
46#include "AbstractGeneralizedRushLarsenCardiacCell.hpp"
47#include <cassert>
48#include <cmath>
49#include "Exception.hpp"
50#include "OdeSolution.hpp"
51#include "TimeStepper.hpp"
52
54 unsigned voltageIndex,
55 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
56 : AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver>(),
57 numberOfStateVariables,
58 voltageIndex,
59 pIntracellularStimulus),
60 mHasAnalyticJacobian(false)
61{
62 mPartialF.resize(numberOfStateVariables);
63 mEvalF.resize(numberOfStateVariables);
64 mYInit.resize(numberOfStateVariables);
65}
66
69
70OdeSolution AbstractGeneralizedRushLarsenCardiacCell::Compute(double tStart, double tEnd, double tSamp)
71{
72 // Check length of time interval
73 if (tSamp < mDt)
74 {
75 tSamp = mDt;
76 }
77 const unsigned n_steps = (unsigned) floor((tEnd - tStart)/tSamp + 0.5);
78 assert(fabs(tStart+n_steps*tSamp - tEnd) < 1e-12);
79 const unsigned n_small_steps = (unsigned) floor(tSamp/mDt+0.5);
80 assert(fabs(mDt*n_small_steps - tSamp) < 1e-12);
81
82 // Initialise solution store
83 OdeSolution solutions;
84 solutions.SetNumberOfTimeSteps(n_steps);
85 solutions.rGetSolutions().push_back(rGetStateVariables());
86 solutions.rGetTimes().push_back(tStart);
88
89 // Loop over time
90 double v_old, v_new;
91 double& r_V = rGetStateVariables()[GetVoltageIndex()];
92 for (unsigned i=0; i<n_steps; i++)
93 {
94 double curr_time = tStart;
95 for (unsigned j=0; j<n_small_steps; j++)
96 {
97 curr_time = tStart + i*tSamp + j*mDt;
98 v_old = r_V;
100 v_new = r_V;
101 r_V = v_old;
103 r_V = v_new;
105 }
106
107 // Update solutions
108 solutions.rGetSolutions().push_back(rGetStateVariables());
109 solutions.rGetTimes().push_back(curr_time+mDt);
110 }
111
112 return solutions;
113}
114
116{
118 TimeStepper stepper(tStart, tEnd, mDt);
119
120 while (!stepper.IsTimeAtEnd())
121 {
123
124#ifndef NDEBUG
125 // Check gating variables are still in range
127#endif // NDEBUG
128
129 stepper.AdvanceOneTimeStep();
130 }
132}
133
135{
136 TimeStepper stepper(tStart, tEnd, mDt);
137
138 double v_old, v_new;
139 double& r_V = rGetStateVariables()[GetVoltageIndex()];
140 while (!stepper.IsTimeAtEnd())
141 {
142 v_old = r_V;
144 v_new = r_V;
145 r_V = v_old;
147 r_V = v_new;
149
150 stepper.AdvanceOneTimeStep();
151 }
152}
153
158
160{
161 if (!useNumericalJacobian)
162 {
163 EXCEPTION("Using analytic Jacobian terms for generalised Rush-Larsen is not yet supported.");
164 }
165// if (!useNumericalJacobian && !mHasAnalyticJacobian)
166// {
167// EXCEPTION("Analytic Jacobian requested, but this ODE system doesn't have one. You can check this with HasAnalyticJacobian().");
168// }
169 mUseAnalyticJacobian = !useNumericalJacobian;
170}
#define EXCEPTION(message)
virtual void SetVoltageDerivativeToZero(bool clamp=true)
virtual void UpdateTransmembranePotential(double time)=0
OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)
virtual void ComputeOneStepExceptVoltage(double time)=0
AbstractGeneralizedRushLarsenCardiacCell(unsigned numberOfStateVariables, unsigned voltageIndex, boost::shared_ptr< AbstractStimulusFunction > pIntracellularStimulus)
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()