CEPS  24.01
Cardiac ElectroPhysiology Simulator
MS03.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #include "ode/ionicModels/MS03.hpp"
31 
33  Unknown* u,
34  const CepsSet<CepsAttribute>& attrs,
35  InputParameters* params
36 ):
37  AbstractIonicModel(u,attrs)
38 {
39 
40  m_name = "Mitchell-Schaeffer 2003";
41  m_nStateVars = 1;
42  m_stateVarNames = {"h [adim]"};
43 
44  // ================================================================================
45  // Default parameters
46 
47  m_vMin = -90;
48  m_vMax = 50;
49  m_cellSurface = 1.;
50 
51  m_constants = new CepsReal[5];
52  m_constants[_tauIn ] = 0.3;
53  m_constants[_tauOut ] = 6;
54  m_constants[_tauOpen ] = 130;
55  m_constants[_tauClose] = 150;
56  m_constants[_vGate ] = 0.13;
57 
58  m_vInit = 0.00000820413566106744;
59  m_hInit = 0.8789655121804799;
60 
61  m_paperCm = 1.;
62  m_paperStim = 0.2;
63 
64  // ================================================================================
65  // Parameters from text inputs, if any
66  if (ceps::isValidPtr(params))
67  setupWithParameters(params,nullptr);
68 
69 }
70 
71 void
73 {
74  // *v = 0.0;
75  // y[_h] = 1.0;
76  *v = m_vInit;
77  y[_h] = m_hInit;
78 }
79 
80 void
82  CepsReal t,
83  CepsReal* y,
84  CepsReal* vm,
85  CepsReal* dtyLin,
86  CepsReal* dtyNLin,
87  CepsReal* dtv,
88  DegreeOfFreedom* dof
89 ) const
90 {
91 
92  CepsReal* c = m_constants;
93  CepsReal v = *vm;
94 
95  CepsReal tau = v<c[_vGate] ? c[_tauOpen] : c[_tauClose];
96  CepsReal wInf = v<c[_vGate] ? 1:0;
97  dtyLin [_h] = -1/tau;
98  dtyNLin[_h] = wInf/tau;
99 
100  CepsReal cm = getCmInternal(t,dof);
101  CepsReal iStim = getStimulation(dof,t);
102  CepsReal iion = y[_h]*(1-v)*v*v/c[_tauIn] - v/c[_tauOut];
103  #ifdef DEBUG
104  ceps::checkNanOrInf(iion,
105  "Ionic current on DoF " + CepsString(dof->getGlobalIndex() + " at time" + CepsString(t))
106  );
107  #endif
108 
109  *dtv = iion + iStim;
110  *dtv /= cm;
111 
112 }
113 
114 CepsReal
116 {
117  return m_vMin + v*(m_vMax-m_vMin);
118 }
119 
120 CepsReal
122 {
123  return (v-m_vMin)/(m_vMax-m_vMin);
124 }
125 
126 CepsReal
128 {
129  return i/(m_vMax-m_vMin);
130 }
131 
132 CepsReal
134 {
135  return dtv*(m_vMax-m_vMin);
136 }
137 
138 CepsReal
140 {
141  return cm;
142 }
143 
144 CepsReal
146 {
147  return cm;
148 }
149 
150 void
152 {
153 
154  m_constants[_tauIn ] = params->getReal("MS03 tauIn ",m_constants[_tauIn ]);
155  m_constants[_tauOut ] = params->getReal("MS03 tauOut ",m_constants[_tauOut ]);
156  m_constants[_tauOpen ] = params->getReal("MS03 tauOpen ",m_constants[_tauOpen ]);
157  m_constants[_tauClose] = params->getReal("MS03 tauClose",m_constants[_tauClose]);
158  m_constants[_vGate ] = params->getReal("MS03 vGate ",m_constants[_vGate ]);
159 
160 
161  m_vMin = params->getReal("MS03 vMin" ,m_vMin );
162  m_vMax = params->getReal("MS03 vMax" ,m_vMax );
163  m_vInit = params->getReal("MS03 v init" ,m_vInit );
164  m_hInit = params->getReal("MS03 h init" ,m_hInit );
165  m_cellSurface = params->getReal("MS03 cell surface",m_cellSurface);
166 
167  return;
168 }
169 
170 
171 // =================================================================================================
172 // Modded MS03 (Regularized+bounded currents)
173 
175  Unknown* u,
176  const CepsSet<CepsAttribute>& attrs,
177  InputParameters* params
178 ):
179  MS03(u,attrs,params)
180 {
181 
182  m_name = "Mitchell-Schaeffer 2003";
183  m_nStateVars = 1;
184  m_stateVarNames = {"h [adim]"};
185 
186  // ================================================================================
187  // Default parameters
188  delete[] m_constants;
189  m_constants = new CepsReal[8];
190  m_constants[_tauIn ] = 0.3;
191  m_constants[_tauOut ] = 6;
192  m_constants[_tauOpen ] = 130;
193  m_constants[_tauClose] = 150;
194  m_constants[_vGate ] = 0.13;
195  m_constants[_etaGate ] = 0.02;
196  m_constants[_vB ] = 5;
197  m_constants[_vA ] = -5;
198 
199  // ================================================================================
200  // Parameters from text inputs, if any
201  if (ceps::isValidPtr(params))
202  setupWithParameters(params,nullptr);
203 
204 }
205 
206 void
208  CepsReal t,
209  CepsReal* y,
210  CepsReal* vm,
211  CepsReal* dtyLin,
212  CepsReal* dtyNLin,
213  CepsReal* dtv,
214  DegreeOfFreedom* dof
215 ) const
216 {
217 
218  CepsReal* c = m_constants;
219  CepsReal v = *vm;
220  CepsReal a = m_constants[_vA];
221  CepsReal b = m_constants[_vB];
222 
223  CepsReal hinfty = 0.5*(1-std::tanh((v-c[_vGate])/c[_etaGate]));
224  CepsReal coeff = 1/c[_tauClose] + hinfty*(c[_tauClose]-c[_tauOpen])/(c[_tauClose]*c[_tauOpen]);
225 
226  dtyLin [_h] = -coeff;
227  dtyNLin[_h] = coeff*hinfty;
228 
229  CepsReal cm = getCmInternal(t,dof);
230  CepsReal iStim = getStimulation(dof,t);
231 
232  CepsReal iIonB = y[_h]*(1-b)*b*b/c[_tauIn] - b/c[_tauOut];
233  CepsReal iIonA = y[_h]*(1-a)*a*a/c[_tauIn] - a/c[_tauOut];
234 
235  // Current limiter
236  CepsReal iIon;
237  if (ceps::greaterThan(v,b) and not ceps::equals(iIonB,0.))
238  {
239  CepsReal kB = -1/iIonB*(y[_h]/c[_tauIn]*b*(3*b-2)+1/c[_tauOut]);
240  iIon = iIonB*(1+std::tanh(kB*(v-b)));
241  }
242  else if (ceps::lesserThan(v,a) and not ceps::equals(iIonA,0.))
243  {
244  CepsReal kA = 1/iIonA*(y[_h]/c[_tauIn]*a*(3*a-2)+1/c[_tauOut]);
245  iIon = iIonA*(1-std::tanh(kA*(v-a)));
246  }
247  else
248  iIon = y[_h]*(1-v)*v*v/c[_tauIn] - v/c[_tauOut];
249 
250  #ifdef DEBUG
251  ceps::checkNanOrInf(iIon,
252  "Ionic current on DoF " + CepsString(dof->getGlobalIndex() + " at time" + CepsString(t))
253  );
254  #endif
255 
256  *dtv = iIon + iStim;
257  *dtv /= cm;
258 
259 }
260 
261 
262 void
264 {
265 
266  MS03::setupWithParameters(params,dico);
267  m_constants[_etaGate] = params->getReal("MS03 etaGate",m_constants[_etaGate]);
268  m_constants[_vA ] = params->getReal("MS03 a" ,m_constants[_vA ]);
269  m_constants[_vB ] = params->getReal("MS03 b" ,m_constants[_vB ]);
270 
271  return;
272 }
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
Represents a ionic model for a group of cells, i.e. multiple systems of ODEs.
CepsReal m_paperStim
Original stim amplitude.
CepsUInt m_nStateVars
Dimensionality of the ODE system, -1 for vm.
CepsReal * m_constants
Constant parameters of the model, from inputs.
CepsReal getStimulation(DegreeOfFreedom *x, CepsReal t) const
Get the sum of all stimulations at time t and dof x.
CepsVector< CepsString > m_stateVarNames
Names of state variables.
CepsReal getCmInternal(CepsReal t, DegreeOfFreedom *dof) const
Get either the value of cm on dof, or the default value from the paper.
CepsReal m_paperCm
Original value of Cm.
CepsString m_name
A label for display.
A degree of freedom for any kind of problem The dof can be associated to a geometrical element or not...
FunctionDictionary that holds functions which can be used to define source terms, boundary conditions...
Reads and stores simulation configuration.
CepsReal getReal(const keyType &key) const
Reads a floating point value from configuration.
void setupWithParameters(InputParameters *p, FunctionDictionary *dico)
Sets the constants and the space dependant parameters from text inputs.
Definition: MS03.cpp:263
MS03Modified(Unknown *u, const CepsSet< CepsAttribute > &attrs={}, InputParameters *params=nullptr)
Constructor (sets constants)
Definition: MS03.cpp:174
void computeRates(CepsReal t, CepsReal *y, CepsReal *v, CepsReal *dtyL, CepsReal *dtyNL, CepsReal *dtv, DegreeOfFreedom *dof) const final
Get the linear and non linear part of the evolution function f. Also computes the ionic current.
Definition: MS03.cpp:207
static constexpr const CepsInt _vB
indexing alias
Definition: MS03.hpp:185
static constexpr const CepsInt _vA
indexing alias
Definition: MS03.hpp:184
static constexpr const CepsInt _etaGate
indexing alias
Definition: MS03.hpp:183
Mitchell-Schaeffer ionic model.
Definition: MS03.hpp:48
static constexpr const CepsInt _h
indexing alias
Definition: MS03.hpp:120
static constexpr const CepsInt _tauOut
indexing alias
Definition: MS03.hpp:124
static constexpr const CepsInt _tauIn
indexing alias
Definition: MS03.hpp:123
CepsReal convertVoltageToCepsUnit(const CepsReal &u) const override
Convert from no unit to mV.
Definition: MS03.cpp:115
CepsReal convertCmToCepsUnit(const CepsReal &cm) const override
Convert capacitance from ionic model units to ceps units (uF/cm2).
Definition: MS03.cpp:145
static constexpr const CepsInt _tauOpen
indexing alias
Definition: MS03.hpp:125
CepsReal m_vMin
lower bound of voltage normalization interval
Definition: MS03.hpp:112
void computeRates(CepsReal t, CepsReal *y, CepsReal *v, CepsReal *dtyL, CepsReal *dtyNL, CepsReal *dtv, DegreeOfFreedom *dof) const override
Get the linear and non linear part of the evolution function f. Also computes the ionic current.
Definition: MS03.cpp:81
CepsReal m_hInit
Initial condition for h.
Definition: MS03.hpp:117
CepsReal m_cellSurface
surface of a cell used for unit scaling. Default is surface of a cylinder (r=10um,...
Definition: MS03.hpp:114
static constexpr const CepsInt _vGate
indexing alias
Definition: MS03.hpp:127
CepsReal convertCurrentFromCepsUnit(const CepsReal &i) const override
Convert from uA per cm2 to s-1.
Definition: MS03.cpp:127
CepsReal m_vInit
Initial condition for v.
Definition: MS03.hpp:116
void getInitialCondition(CepsReal *v, CepsReal *y) const final
Sets initial values of state variables and transmembrane voltage for a single point....
Definition: MS03.cpp:72
static constexpr const CepsInt _tauClose
indexing alias
Definition: MS03.hpp:126
void setupWithParameters(InputParameters *p, FunctionDictionary *dico)
Sets the constants and the space dependant parameters from text inputs.
Definition: MS03.cpp:151
CepsReal convertDtvToCepsUnit(const CepsReal &i) const override
Convert from s-1 to uA per cm2.
Definition: MS03.cpp:133
CepsReal convertCmFromCepsUnit(const CepsReal &cm) const override
Convert capacitance from ceps units (uF/cm2) to ionic model units.
Definition: MS03.cpp:139
CepsReal convertVoltageFromCepsUnit(const CepsReal &u) const override
Convert from mV to no unit.
Definition: MS03.cpp:121
MS03(Unknown *u, const CepsSet< CepsAttribute > &attrs={}, InputParameters *params=nullptr)
Constructor (sets constants)
Definition: MS03.cpp:32
CepsReal m_vMax
upper bound of voltage normalization interval
Definition: MS03.hpp:113
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
Definition: Unknown.hpp:45
const CepsGlobalIndex & getGlobalIndex() const
Get the index
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
CepsBool greaterThan(CepsReal a, CepsReal b, CepsReal epsilon=FLOATING_POINT_EPSILON)
Greater than comparison with epsilon tolerance.
Definition: Precision.hpp:98
void checkNanOrInf(CepsReal v, CepsString message="")
Stops if value is NaN or infty.
CepsBool lesserThan(CepsReal a, CepsReal b, CepsReal epsilon=FLOATING_POINT_EPSILON)
Lesser than comparison with epsilon tolerance.
Definition: Precision.hpp:111
CepsBool equals(CepsReal a, CepsReal b, CepsReal error=1.0)
CepsReal equality up to machine precision.
Definition: Precision.hpp:54