def holzapfelogden_dev(self, params, f0, s0, C): # anisotropic invariants - keep in mind that for growth, self.C is the elastic part of C (hence != to function input variable C) I4 = dot(dot(self.C,f0), f0) I6 = dot(dot(self.C,s0), s0) I8 = dot(dot(self.C,s0), f0) # to guarantee initial configuration is stress-free (in case of initially non-orthogonal fibers f0 and s0) I8 -= dot(f0,s0) a_0, b_0 = params['a_0'], params['b_0'] a_f, b_f = params['a_f'], params['b_f'] a_s, b_s = params['a_s'], params['b_s'] a_fs, b_fs = params['a_fs'], params['b_fs'] try: fiber_comp = params['fiber_comp'] except: fiber_comp = False # conditional parameters: fibers are only active in tension if fiber_comp is False if not fiber_comp: a_f_c = conditional(ge(I4,1.), a_f, 0.) a_s_c = conditional(ge(I6,1.), a_s, 0.) else: a_f_c = a_f a_s_c = a_s # Holzapfel-Ogden (Holzapfel and Ogden 2009) material w/o split applied to invariants I4, I6, I8 (Sansour 2008) psi_dev = a_0/(2.*b_0)*(exp(b_0*(self.Ic_bar-3.)) - 1.) + \ a_f_c/(2.*b_f)*(exp(b_f*(I4-1.)**2.) - 1.) + a_s_c/(2.*b_s)*(exp(b_s*(I6-1.)**2.) - 1.) + \ a_fs/(2.*b_fs)*(exp(b_fs*I8**2.) - 1.) S = 2.*diff(psi_dev,C) return S
def g(self, lam): amp_min = self.params['amp_min'] amp_max = self.params['amp_max'] lam_threslo = self.params['lam_threslo'] lam_maxlo = self.params['lam_maxlo'] lam_threshi = self.params['lam_threshi'] lam_maxhi = self.params['lam_maxhi'] # Diss Hirschvogel eq. 2.107 # TeX: g(\lambda_{\mathrm{myo}}) = \begin{cases} a_{\mathrm{min}}, & \lambda_{\mathrm{myo}} \leq \hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,lo}}, \\ a_{\mathrm{min}}+\frac{1}{2}\left(a_{\mathrm{max}}-a_{\mathrm{min}}\right)\left(1-\cos \frac{\pi(\lambda_{\mathrm{myo}}-\hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,lo}})}{\hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,lo}}-\hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,lo}}}\right), & \hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,lo}} \leq \lambda_{\mathrm{myo}} \leq \hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,lo}}, \\ a_{\mathrm{max}}, & \hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,lo}} \leq \lambda_{\mathrm{myo}} \leq \hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,hi}}, \\ a_{\mathrm{min}}+\frac{1}{2}\left(a_{\mathrm{max}}-a_{\mathrm{min}}\right)\left(1-\cos \frac{\pi(\lambda_{\mathrm{myo}}-\hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,hi}})}{\hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,hi}}-\hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,hi}}}\right), & \hat{\lambda}_{\mathrm{myo}}^{\mathrm{thres,hi}} \leq \lambda_{\mathrm{myo}} \leq \hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,hi}}, \\ a_{\mathrm{min}}, & \lambda_{\mathrm{myo}} \geq \hat{\lambda}_{\mathrm{myo}}^{\mathrm{max,hi}} \end{cases} return conditional( le(lam, lam_threslo), amp_min, conditional( And(ge(lam, lam_threslo), le(lam, lam_maxlo)), amp_min + 0.5 * (amp_max - amp_min) * (1. - cos(pi * (lam - lam_threslo) / (lam_maxlo - lam_threslo))), conditional( And(ge(lam, lam_maxlo), le(lam, lam_threshi)), amp_max, conditional( And(ge(lam, lam_threshi), le(lam, lam_maxhi)), amp_min + 0.5 * (amp_max - amp_min) * (1. - cos(pi * (lam - lam_maxhi) / (lam_maxhi - lam_threshi))), conditional(ge(lam, lam_maxhi), amp_min, as_ufl(0))))))
def test_conditional(mode, compile_args): cell = ufl.triangle element = ufl.FiniteElement("Lagrange", cell, 1) u, v = ufl.TrialFunction(element), ufl.TestFunction(element) x = ufl.SpatialCoordinate(cell) condition = ufl.Or(ufl.ge(ufl.real(x[0] + x[1]), 0.1), ufl.ge(ufl.real(x[1] + x[1]**2), 0.1)) c1 = ufl.conditional(condition, 2.0, 1.0) a = c1 * ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx x1x2 = ufl.real(x[0] + ufl.as_ufl(2) * x[1]) c2 = ufl.conditional(ufl.ge(x1x2, 0), 6.0, 0.0) b = c2 * ufl.conj(v) * ufl.dx forms = [a, b] compiled_forms, module = ffcx.codegeneration.jit.compile_forms( forms, parameters={'scalar_type': mode}, cffi_extra_compile_args=compile_args) form0 = compiled_forms[0][0].create_cell_integral(-1) form1 = compiled_forms[1][0].create_cell_integral(-1) ffi = cffi.FFI() c_type, np_type = float_to_type(mode) A1 = np.zeros((3, 3), dtype=np_type) w1 = np.array([1.0, 1.0, 1.0], dtype=np_type) c = np.array([], dtype=np.float64) coords = np.array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0], dtype=np.float64) form0.tabulate_tensor( ffi.cast('{type} *'.format(type=c_type), A1.ctypes.data), ffi.cast('{type} *'.format(type=c_type), w1.ctypes.data), ffi.cast('{type} *'.format(type=c_type), c.ctypes.data), ffi.cast('double *', coords.ctypes.data), ffi.NULL, ffi.NULL, 0) expected_result = np.array([[2, -1, -1], [-1, 1, 0], [-1, 0, 1]], dtype=np_type) assert np.allclose(A1, expected_result) A2 = np.zeros(3, dtype=np_type) w2 = np.array([1.0, 1.0, 1.0], dtype=np_type) coords = np.array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0], dtype=np.float64) form1.tabulate_tensor( ffi.cast('{type} *'.format(type=c_type), A2.ctypes.data), ffi.cast('{type} *'.format(type=c_type), w2.ctypes.data), ffi.cast('{type} *'.format(type=c_type), c.ctypes.data), ffi.cast('double *', coords.ctypes.data), ffi.NULL, ffi.NULL, 0) expected_result = np.ones(3, dtype=np_type) assert np.allclose(A2, expected_result)
def p_sat(temp): """Water vapour saturation pressure Parameters ---------- temp0: Previous temp function [K] Note ---- Kunzel 1995, page 40, formula (50). """ a = conditional(ge(temp, 273.15), 17.08, 22.44) theta0 = conditional(ge(temp, 273.15), 234.18, 272.44) return 611. * exp(a * (temp - 273.15) / (theta0 + (temp - 273.15)))
def liquidity(theta_k, theta_kp1, solidus, implicitness=1.): theta_avg = avg(theta_k, theta_kp1, implicitness) form = theta_avg - Constant(solidus) # filter to liquid parts form *= conditional(ge(form, 0.), 1., 0.) return form
def compute_welding_size(evo, V, threshold_temp, x, ds): '''Computes either the welding depth or the welding radius. Parameters: evo: ndarray The coefficients of the solution to the corresponding forward problem in the basis of the space V (see solve_forward). V: dolfin.FunctionSpace The FEM space of the problem being solved. threshold_temp: float The threshold temperature used as a criterion for successful welding. ds: dolfin.Measure The measure on either the symmetry axis (for welding depth) or the top boundary (for welding radius). Returns: evo_size: ndarray Contains size of either the welding depth or the welding radius over all time steps. ''' theta_k = dolfin.Function(V) Nt = len(evo) - 1 evo_size = np.zeros(Nt+1) for k in range(Nt+1): theta_k.vector().set_local(evo[k]) evo_size[k] = dolfin.assemble( conditional(ge(theta_k, threshold_temp), 1., 0.) * ds ) return evo_size
def test_cpp_formatting_of_conditionals(): x, y = ufl.SpatialCoordinate(ufl.triangle) # Test conditional expressions assert expr2cpp(ufl.conditional(ufl.lt(x, 2), y, 3)) \ == "x[0] < 2 ? x[1]: 3" assert expr2cpp(ufl.conditional(ufl.gt(x, 2), 4 + y, 3)) \ == "x[0] > 2 ? 4 + x[1]: 3" assert expr2cpp(ufl.conditional(ufl.And(ufl.le(x, 2), ufl.ge(y, 4)), 7, 8)) \ == "x[0] <= 2 && x[1] >= 4 ? 7: 8" assert expr2cpp(ufl.conditional(ufl.Or(ufl.eq(x, 2), ufl.ne(y, 4)), 7, 8)) \ == "x[0] == 2 || x[1] != 4 ? 7: 8"
def grfnc1(self, trigger, thres, params): thetamax, thetamin = params['thetamax'], params['thetamin'] tau_gr, tau_gr_rev = params['tau_gr'], params['tau_gr_rev'] gamma_gr, gamma_gr_rev = params['gamma_gr'], params['gamma_gr_rev'] k_plus = (1./tau_gr) * ((thetamax-self.theta)/(thetamax-thetamin))**(gamma_gr) k_minus = (1./tau_gr_rev) * ((self.theta-thetamin)/(thetamax-thetamin))**(gamma_gr_rev) k = conditional(ge(trigger,thres), k_plus, k_minus) return k
def __init__(self, spline, ufl_element): self._ufl_coef = ufl.Coefficient(ufl_element) t = self._ufl_coef knots = spline.knots coef_array = spline.coef_array # assigning left polynomial form = ufl.conditional(lt(t, knots[0]), 1., 0.)\ * Polynomial(coef_array[0])(t) # assigning internal polynomials for knot, knot_, coef in\ zip(knots[:-1], knots[1:], coef_array[1:-1]): form += ufl.conditional(And(ge(t, knot), lt(t, knot_)), 1., 0.)\ * Polynomial(coef)(t) # assigning right polynomial form += ufl.conditional(ge(t, knots[-1]), 1., 0.)\ * Polynomial(coef_array[-1])(t) self._ufl_form = form
def _I(self, v, s, time): """ Original gotran transmembrane current dV/dt """ time = time if time else Constant(0.0) # Assign states V = v assert(len(s) == 7) m, h, j, Cai, d, f, x1 = s # Assign parameters E_Na = self._parameters["E_Na"] g_Na = self._parameters["g_Na"] g_Nac = self._parameters["g_Nac"] g_s = self._parameters["g_s"] IstimAmplitude = self._parameters["IstimAmplitude"] IstimPulseDuration = self._parameters["IstimPulseDuration"] IstimStart = self._parameters["IstimStart"] C = self._parameters["C"] # Init return args current = [ufl.zero()]*1 # Expressions for the Sodium current component i_Na = (g_Nac + g_Na*(m*m*m)*h*j)*(-E_Na + V) # Expressions for the Slow inward current component E_s = -82.3 - 13.0287*ufl.ln(0.001*Cai) i_s = g_s*(-E_s + V)*d*f # Expressions for the Time dependent outward current component i_x1 = 0.00197277571153*(-1 +\ 21.7584023962*ufl.exp(0.04*V))*ufl.exp(-0.04*V)*x1 # Expressions for the Time independent outward current component i_K1 = 0.0035*(-4 +\ 119.85640019*ufl.exp(0.04*V))/(8.33113748769*ufl.exp(0.04*V) +\ 69.4078518388*ufl.exp(0.08*V)) + 0.0035*(4.6 + 0.2*V)/(1 -\ 0.398519041085*ufl.exp(-0.04*V)) # Expressions for the Stimulus protocol component Istim = ufl.conditional(ufl.And(ufl.ge(time, IstimStart),\ ufl.le(time, IstimPulseDuration + IstimStart)), IstimAmplitude,\ 0) # Expressions for the Membrane component current[0] = (-i_K1 + Istim - i_Na - i_x1 - i_s)/C # Return results return current[0]
def _I(self, v, s, time): """ Original gotran transmembrane current dV/dt """ time = time if time else Constant(0.0) # Assign states V = v # Assign parameters g_leak = self._parameters["g_L"] Cm = self._parameters["Cm"] E_leak = self._parameters["E_L"] stim_type = self._parameters["stim_type"] g_s = self._parameters["g_S"] alpha = self._parameters["alpha"] v_eq = self._parameters["v_eq"] t0 = self._parameters["t_start"] t1 = self._parameters["t_stop"] # Init return args current = [ufl.zero()] * 1 # Expressions for the Membrane component if stim_type == 0: i_stim = g_s * (-v_eq + V) * ufl.conditional( ufl.ge(time, t0), 1, 0) * ufl.exp((t0 - time) / alpha) elif stim_type == 1: i_stim = -g_s * ufl.conditional(ufl.ge(time, t0), 1, 0) elif stim_type == 2: i_stim = -g_s * ufl.conditional( ufl.And(ufl.ge(time, t0), ufl.le(time, t1)), 1, 0) i_leak = g_leak * (-E_leak + V) current[0] = (-i_leak - i_stim) / Cm # Return results return current[0]
def test_comparison_checker(self): cell = triangle element = FiniteElement("Lagrange", cell, 1) u = TrialFunction(element) v = TestFunction(element) a = conditional(ge(abs(u), imag(v)), u, v) b = conditional(le(sqrt(abs(u)), imag(v)), as_ufl(1), as_ufl(1j)) c = conditional(gt(abs(u), pow(imag(v), 0.5)), sin(u), cos(v)) d = conditional(lt(as_ufl(-1), as_ufl(1)), u, v) e = max_value(as_ufl(0), real(u)) f = min_value(sin(u), cos(v)) g = min_value(sin(pow(u, 3)), cos(abs(v))) assert do_comparison_check(a) == conditional(ge(real(abs(u)), real(imag(v))), u, v) with pytest.raises(ComplexComparisonError): b = do_comparison_check(b) with pytest.raises(ComplexComparisonError): c = do_comparison_check(c) assert do_comparison_check(d) == conditional(lt(real(as_ufl(-1)), real(as_ufl(1))), u, v) assert do_comparison_check(e) == max_value(real(as_ufl(0)), real(real(u))) assert do_comparison_check(f) == min_value(real(sin(u)), real(cos(v))) assert do_comparison_check(g) == min_value(real(sin(pow(u, 3))), real(cos(abs(v))))
def _I(self, v, s, time): """ Original gotran transmembrane current dV/dt """ time = time if time else Constant(0.0) # Assign states V = v assert (len(s) == 2) s, m = s # Assign parameters Cm = self._parameters["Cm"] E_L = self._parameters["E_L"] g_L = self._parameters["g_L"] # synapse components alpha = self._parameters["alpha"] g_S = self._parameters["g_S"] t0 = self._parameters["t0"] v_eq = self._parameters["v_eq"] # Init return args current = [ufl.zero()] * 1 # Expressions for the Membrane component # FIXME: base on stim_type + add to Hodgkin # if # i_Stim = g_S*(-v_eq + V)*ufl.conditional(ufl.ge(time, t0), 1, 0)*ufl.exp((t0 - time)/alpha) # elif sss: # i_Stim = g_S*ufl.conditional(ufl.ge(time, t0), 1, 0) # else: # i_Stim = g_S*ufl.conditional(ufl.And(ufl.ge(time, t0), # ufl.le(time, t1), 1, 0)) i_Stim = g_S * (-v_eq + V) * ufl.conditional(ufl.ge( time, t0), 1, 0) * ufl.exp((t0 - time) / alpha) i_L = g_L * (-E_L + V) current[0] = (-i_L - i_Stim) / Cm # Return results return current[0]
def solidification_indicator(theta_k, theta_kp1, solidus, liquidus): return conditional( And(ge(theta_k, solidus), lt(theta_kp1, liquidus)), 1., 0., )
tf = project(Expression("sin(2*pi*x[0])"), V) def norm_approx(u, alpha=1e-4): # A smooth approximation to ||u|| return sqrt(inner(u, u)+alpha**2) # Advect shift = 0.1 theta = 0.5 uhalf = Constant(1.-theta)*u0 + Constant(theta)*u F = (inner(u-u0, q) + Constant(shift)*inner(uhalf.dx(0)*1, q) + Constant(1e-8)*inner(grad(u), grad(q)))*dx solve(F == 0, u) plot(u, interactive=True, title="Computed after shifting") u_shift = project(Expression("1+sin(2*pi*(x[0]-shift))", shift=shift), V) plot(u_shift, interactive=True, title="Expected after shifting") # Diffuse a = Function(V) chi = ufl.conditional(ufl.ge(tf, 0.0), 0, 1) F1 = chi*(inner(a-u0, q) + Constant(1e3)*inner(grad(a), grad(q)))*dx invchi = 1-chi F2 = inner(invchi*a, q)*dx F = F1 + F2 solve(F == 0, a) adg = interpolate(a, Vdg) f = File("averaged.pvd") f << adg plot(adg, interactive=True, title="Averaged")
def F(self, v, s, time=None): """ Right hand side for ODE system """ time = time if time else Constant(0.0) # Assign states V_m = v assert (len(s) == 38) h, j, m, x_kr, x_ks, x_to_f, x_to_s, y_to_f, y_to_s, d, f, f_Ca_Bj,\ f_Ca_Bsl, Ry_Ri, Ry_Ro, Ry_Rr, Na_Bj, Na_Bsl, CaM, Myo_c, Myo_m,\ SRB, Tn_CHc, Tn_CHm, Tn_CL, SLH_j, SLH_sl, SLL_j, SLL_sl, Ca_sr,\ Csqn_b, Na_i, Na_j, Na_sl, K_i, Ca_i, Ca_j, Ca_sl = s # Assign parameters Fjunc = self._parameters["Fjunc"] Fjunc_CaL = self._parameters["Fjunc_CaL"] cellLength = self._parameters["cellLength"] cellRadius = self._parameters["cellRadius"] GNa = self._parameters["GNa"] GNaB = self._parameters["GNaB"] IbarNaK = self._parameters["IbarNaK"] KmKo = self._parameters["KmKo"] KmNaip = self._parameters["KmNaip"] Q10CaL = self._parameters["Q10CaL"] pCa = self._parameters["pCa"] pNa = self._parameters["pNa"] IbarNCX = self._parameters["IbarNCX"] Kdact = self._parameters["Kdact"] KmCai = self._parameters["KmCai"] KmCao = self._parameters["KmCao"] KmNai = self._parameters["KmNai"] KmNao = self._parameters["KmNao"] Q10NCX = self._parameters["Q10NCX"] ksat = self._parameters["ksat"] nu = self._parameters["nu"] IbarSLCaP = self._parameters["IbarSLCaP"] KmPCa = self._parameters["KmPCa"] Q10SLCaP = self._parameters["Q10SLCaP"] GCaB = self._parameters["GCaB"] Kmf = self._parameters["Kmf"] Kmr = self._parameters["Kmr"] MaxSR = self._parameters["MaxSR"] MinSR = self._parameters["MinSR"] Q10SRCaP = self._parameters["Q10SRCaP"] Vmax_SRCaP = self._parameters["Vmax_SRCaP"] ec50SR = self._parameters["ec50SR"] hillSRCaP = self._parameters["hillSRCaP"] kiCa = self._parameters["kiCa"] kim = self._parameters["kim"] koCa = self._parameters["koCa"] kom = self._parameters["kom"] ks = self._parameters["ks"] Bmax_Naj = self._parameters["Bmax_Naj"] Bmax_Nasl = self._parameters["Bmax_Nasl"] koff_na = self._parameters["koff_na"] kon_na = self._parameters["kon_na"] Bmax_CaM = self._parameters["Bmax_CaM"] Bmax_SR = self._parameters["Bmax_SR"] Bmax_TnChigh = self._parameters["Bmax_TnChigh"] Bmax_TnClow = self._parameters["Bmax_TnClow"] Bmax_myosin = self._parameters["Bmax_myosin"] koff_cam = self._parameters["koff_cam"] koff_myoca = self._parameters["koff_myoca"] koff_myomg = self._parameters["koff_myomg"] koff_sr = self._parameters["koff_sr"] koff_tnchca = self._parameters["koff_tnchca"] koff_tnchmg = self._parameters["koff_tnchmg"] koff_tncl = self._parameters["koff_tncl"] kon_cam = self._parameters["kon_cam"] kon_myoca = self._parameters["kon_myoca"] kon_myomg = self._parameters["kon_myomg"] kon_sr = self._parameters["kon_sr"] kon_tnchca = self._parameters["kon_tnchca"] kon_tnchmg = self._parameters["kon_tnchmg"] kon_tncl = self._parameters["kon_tncl"] Bmax_SLhighj0 = self._parameters["Bmax_SLhighj0"] Bmax_SLhighsl0 = self._parameters["Bmax_SLhighsl0"] Bmax_SLlowj0 = self._parameters["Bmax_SLlowj0"] Bmax_SLlowsl0 = self._parameters["Bmax_SLlowsl0"] koff_slh = self._parameters["koff_slh"] koff_sll = self._parameters["koff_sll"] kon_slh = self._parameters["kon_slh"] kon_sll = self._parameters["kon_sll"] Bmax_Csqn0 = self._parameters["Bmax_Csqn0"] J_ca_juncsl = self._parameters["J_ca_juncsl"] J_ca_slmyo = self._parameters["J_ca_slmyo"] koff_csqn = self._parameters["koff_csqn"] kon_csqn = self._parameters["kon_csqn"] J_na_juncsl = self._parameters["J_na_juncsl"] J_na_slmyo = self._parameters["J_na_slmyo"] Nao = self._parameters["Nao"] Ko = self._parameters["Ko"] Cao = self._parameters["Cao"] Mgi = self._parameters["Mgi"] Cmem = self._parameters["Cmem"] Frdy = self._parameters["Frdy"] R = self._parameters["R"] Temp = self._parameters["Temp"] g_K1_factor = self._parameters["g_K1_factor"] g_CaL_factor = self._parameters["g_CaL_factor"] g_Kr_factor = self._parameters["g_Kr_factor"] g_Ks_factor = self._parameters["g_Ks_factor"] g_to_factor = self._parameters["g_to_factor"] SR_Ca_release_ks_factor = self._parameters["SR_Ca_release_ks_factor"] # Init return args F_expressions = [ufl.zero()] * 38 # Expressions for the Geometry component Vcell = 1e-15 * ufl.pi * cellLength * (cellRadius * cellRadius) Vmyo = 0.65 * Vcell Vsr = 0.035 * Vcell Vsl = 0.02 * Vcell Vjunc = 0.000539 * Vcell Fsl = 1 - Fjunc Fsl_CaL = 1 - Fjunc_CaL # Expressions for the Reversal potentials component FoRT = Frdy / (R * Temp) ena_junc = ufl.ln(Nao / Na_j) / FoRT ena_sl = ufl.ln(Nao / Na_sl) / FoRT eca_junc = ufl.ln(Cao / Ca_j) / (2 * FoRT) eca_sl = ufl.ln(Cao / Ca_sl) / (2 * FoRT) Qpow = -31 + Temp / 10 # Expressions for the I_Na component mss = 1.0/((1 + 0.00184221158117*ufl.exp(-0.110741971207*V_m))*(1 +\ 0.00184221158117*ufl.exp(-0.110741971207*V_m))) taum = 0.1292*ufl.exp(-((2.94658944659 +\ 0.0643500643501*V_m)*(2.94658944659 + 0.0643500643501*V_m))) +\ 0.06487*ufl.exp(-((-0.0943466353678 +\ 0.0195618153365*V_m)*(-0.0943466353678 + 0.0195618153365*V_m))) ah = ufl.conditional(ufl.ge(V_m, -40), 0,\ 4.43126792958e-07*ufl.exp(-0.147058823529*V_m)) bh = ufl.conditional(ufl.ge(V_m, -40), 0.77/(0.13 +\ 0.0497581410839*ufl.exp(-0.0900900900901*V_m)),\ 310000.0*ufl.exp(0.3485*V_m) + 2.7*ufl.exp(0.079*V_m)) tauh = 1.0 / (bh + ah) hss = 1.0/((1 + 15212.5932857*ufl.exp(0.134589502019*V_m))*(1 +\ 15212.5932857*ufl.exp(0.134589502019*V_m))) aj = ufl.conditional(ufl.ge(V_m, -40), 0, (37.78 +\ V_m)*(-25428.0*ufl.exp(0.2444*V_m) -\ 6.948e-06*ufl.exp(-0.04391*V_m))/(1 +\ 50262745826.0*ufl.exp(0.311*V_m))) bj = ufl.conditional(ufl.ge(V_m, -40), 0.6*ufl.exp(0.057*V_m)/(1 +\ 0.0407622039784*ufl.exp(-0.1*V_m)),\ 0.02424*ufl.exp(-0.01052*V_m)/(1 +\ 0.0039608683399*ufl.exp(-0.1378*V_m))) tauj = 1.0 / (bj + aj) jss = 1.0/((1 + 15212.5932857*ufl.exp(0.134589502019*V_m))*(1 +\ 15212.5932857*ufl.exp(0.134589502019*V_m))) F_expressions[2] = (-m + mss) / taum F_expressions[0] = (hss - h) / tauh F_expressions[1] = (-j + jss) / tauj I_Na_junc = Fjunc * GNa * (m * m * m) * (-ena_junc + V_m) * h * j I_Na_sl = GNa * (m * m * m) * (-ena_sl + V_m) * Fsl * h * j # Expressions for the I_NaBK component I_nabk_junc = Fjunc * GNaB * (-ena_junc + V_m) I_nabk_sl = GNaB * (-ena_sl + V_m) * Fsl # Expressions for the I_NaK component sigma = -1 / 7 + ufl.exp(0.0148588410104 * Nao) / 7 fnak = 1.0/(1 + 0.1245*ufl.exp(-0.1*FoRT*V_m) +\ 0.0365*ufl.exp(-FoRT*V_m)*sigma) I_nak_junc = Fjunc*IbarNaK*Ko*fnak/((1 + ufl.elem_pow(KmNaip,\ 4)/ufl.elem_pow(Na_j, 4))*(KmKo + Ko)) I_nak_sl = IbarNaK*Ko*Fsl*fnak/((1 + ufl.elem_pow(KmNaip,\ 4)/ufl.elem_pow(Na_sl, 4))*(KmKo + Ko)) # Expressions for the I_Kr component xrss = 1.0 / (1 + ufl.exp(-2 - V_m / 5)) tauxr = 230/(1 + ufl.exp(2 + V_m/20)) + 3300/((1 + ufl.exp(-22/9 -\ V_m/9))*(1 + ufl.exp(11/9 + V_m/9))) F_expressions[3] = (-x_kr + xrss) / tauxr # Expressions for the I_Ks component xsss = 1.0 / (1 + 0.765928338365 * ufl.exp(-0.0701754385965 * V_m)) tauxs = 990.1 / (1 + 0.841540408868 * ufl.exp(-0.070821529745 * V_m)) F_expressions[4] = (-x_ks + xsss) / tauxs # Expressions for the I_to component xtoss = 1.0 / (1 + ufl.exp(19 / 13 - V_m / 13)) ytoss = 1.0 / (1 + 49.4024491055 * ufl.exp(V_m / 5)) tauxtos = 0.5 + 9 / (1 + ufl.exp(1 / 5 + V_m / 15)) tauytos = 30 + 800 / (1 + ufl.exp(6 + V_m / 10)) F_expressions[6] = (-x_to_s + xtoss) / tauxtos F_expressions[8] = (ytoss - y_to_s) / tauytos tauxtof = 0.5 + 8.5 * ufl.exp(-((9 / 10 + V_m / 50) * (9 / 10 + V_m / 50))) tauytof = 7 + 85 * ufl.exp(-((40 + V_m) * (40 + V_m)) / 220) F_expressions[5] = (xtoss - x_to_f) / tauxtof F_expressions[7] = (ytoss - y_to_f) / tauytof # Expressions for the I_Ca component fss = 0.6 / (1 + ufl.exp(5 / 2 - V_m / 20)) + 1.0 / ( 1 + ufl.exp(35 / 9 + V_m / 9)) dss = 1.0 / (1 + ufl.exp(-5 / 6 - V_m / 6)) taud = (1 - ufl.exp(-5 / 6 - V_m / 6)) * dss / (0.175 + 0.035 * V_m) tauf = 1.0/(0.02 + 0.0197*ufl.exp(-((0.48865 + 0.0337*V_m)*(0.48865 +\ 0.0337*V_m)))) F_expressions[9] = (-d + dss) / taud F_expressions[10] = (fss - f) / tauf F_expressions[11] = 1.7 * (1 - f_Ca_Bj) * Ca_j - 0.0119 * f_Ca_Bj F_expressions[12] = -0.0119 * f_Ca_Bsl + 1.7 * (1 - f_Ca_Bsl) * Ca_sl fcaCaMSL = 0 fcaCaj = 0 ibarca_j = 4*Frdy*pCa*(-0.341*Cao +\ 0.341*Ca_j*ufl.exp(2*FoRT*V_m))*FoRT*V_m/(-1 +\ ufl.exp(2*FoRT*V_m)) ibarca_sl = 4*Frdy*pCa*(-0.341*Cao +\ 0.341*Ca_sl*ufl.exp(2*FoRT*V_m))*FoRT*V_m/(-1 +\ ufl.exp(2*FoRT*V_m)) ibarna_j = Frdy*pNa*(-0.75*Nao +\ 0.75*Na_j*ufl.exp(FoRT*V_m))*FoRT*V_m/(-1 + ufl.exp(FoRT*V_m)) ibarna_sl = Frdy*pNa*(0.75*Na_sl*ufl.exp(FoRT*V_m) -\ 0.75*Nao)*FoRT*V_m/(-1 + ufl.exp(FoRT*V_m)) I_Ca_junc = g_CaL_factor*0.45*Fjunc_CaL*ufl.elem_pow(Q10CaL, Qpow)*(1 - f_Ca_Bj +\ fcaCaj)*d*f*ibarca_j I_Ca_sl = g_CaL_factor*0.45*ufl.elem_pow(Q10CaL, Qpow)*(1 - f_Ca_Bsl +\ fcaCaMSL)*Fsl_CaL*d*f*ibarca_sl I_CaNa_junc = g_CaL_factor*0.45*Fjunc_CaL*ufl.elem_pow(Q10CaL, Qpow)*(1 - f_Ca_Bj\ + fcaCaj)*d*f*ibarna_j I_CaNa_sl = g_CaL_factor*0.45*ufl.elem_pow(Q10CaL, Qpow)*(1 - f_Ca_Bsl +\ fcaCaMSL)*Fsl_CaL*d*f*ibarna_sl # Expressions for the I_NCX component Ka_junc = 1.0 / (1 + (Kdact * Kdact) / (Ca_j * Ca_j)) Ka_sl = 1.0 / (1 + (Kdact * Kdact) / (Ca_sl * Ca_sl)) s1_junc = Cao * (Na_j * Na_j * Na_j) * ufl.exp(nu * FoRT * V_m) s1_sl = Cao * (Na_sl * Na_sl * Na_sl) * ufl.exp(nu * FoRT * V_m) s2_junc = (Nao * Nao * Nao) * Ca_j * ufl.exp((-1 + nu) * FoRT * V_m) s3_junc = KmCao*(Na_j*Na_j*Na_j) + (Nao*Nao*Nao)*Ca_j +\ Cao*(Na_j*Na_j*Na_j) + KmCai*(Nao*Nao*Nao)*(1 +\ (Na_j*Na_j*Na_j)/(KmNai*KmNai*KmNai)) + (KmNao*KmNao*KmNao)*(1 +\ Ca_j/KmCai)*Ca_j s2_sl = (Nao * Nao * Nao) * Ca_sl * ufl.exp((-1 + nu) * FoRT * V_m) s3_sl = KmCai*(Nao*Nao*Nao)*(1 +\ (Na_sl*Na_sl*Na_sl)/(KmNai*KmNai*KmNai)) + (Nao*Nao*Nao)*Ca_sl +\ (KmNao*KmNao*KmNao)*(1 + Ca_sl/KmCai)*Ca_sl +\ Cao*(Na_sl*Na_sl*Na_sl) + KmCao*(Na_sl*Na_sl*Na_sl) I_ncx_junc = Fjunc*IbarNCX*ufl.elem_pow(Q10NCX, Qpow)*(-s2_junc +\ s1_junc)*Ka_junc/((1 + ksat*ufl.exp((-1 + nu)*FoRT*V_m))*s3_junc) I_ncx_sl = IbarNCX*ufl.elem_pow(Q10NCX, Qpow)*(-s2_sl +\ s1_sl)*Fsl*Ka_sl/((1 + ksat*ufl.exp((-1 + nu)*FoRT*V_m))*s3_sl) # Expressions for the I_PCa component I_pca_junc = Fjunc*IbarSLCaP*ufl.elem_pow(Q10SLCaP,\ Qpow)*ufl.elem_pow(Ca_j, 1.6)/(ufl.elem_pow(Ca_j, 1.6) +\ ufl.elem_pow(KmPCa, 1.6)) I_pca_sl = IbarSLCaP*ufl.elem_pow(Q10SLCaP, Qpow)*ufl.elem_pow(Ca_sl,\ 1.6)*Fsl/(ufl.elem_pow(Ca_sl, 1.6) + ufl.elem_pow(KmPCa, 1.6)) # Expressions for the I_CaBK component I_cabk_junc = Fjunc * GCaB * (-eca_junc + V_m) I_cabk_sl = GCaB * (-eca_sl + V_m) * Fsl # Expressions for the SR Fluxes component kCaSR = MaxSR - (-MinSR + MaxSR) / (1 + ufl.elem_pow(ec50SR / Ca_sr, 2.5)) koSRCa = koCa / kCaSR kiSRCa = kiCa * kCaSR RI = 1 - Ry_Ro - Ry_Ri - Ry_Rr F_expressions[15] = -(Ca_j*Ca_j)*Ry_Rr*koSRCa + kom*Ry_Ro + kim*RI -\ Ca_j*Ry_Rr*kiSRCa F_expressions[14] = -kom*Ry_Ro - Ca_j*Ry_Ro*kiSRCa + kim*Ry_Ri +\ (Ca_j*Ca_j)*Ry_Rr*koSRCa F_expressions[13] = -kim*Ry_Ri + Ca_j*Ry_Ro*kiSRCa - kom*Ry_Ri +\ (Ca_j*Ca_j)*RI*koSRCa J_SRCarel = SR_Ca_release_ks_factor * ks * (Ca_sr - Ca_j) * Ry_Ro J_serca = Vmax_SRCaP*ufl.elem_pow(Q10SRCaP,\ Qpow)*(-ufl.elem_pow(Ca_sr/Kmr, hillSRCaP) +\ ufl.elem_pow(Ca_i/Kmf, hillSRCaP))/(1 + ufl.elem_pow(Ca_sr/Kmr,\ hillSRCaP) + ufl.elem_pow(Ca_i/Kmf, hillSRCaP)) J_SRleak = 5.348e-06 * Ca_sr - 5.348e-06 * Ca_j # Expressions for the Na Buffers component F_expressions[16] = -koff_na * Na_Bj + kon_na * (-Na_Bj + Bmax_Naj) * Na_j F_expressions[17] = kon_na * (-Na_Bsl + Bmax_Nasl) * Na_sl - koff_na * Na_Bsl # Expressions for the Cytosolic Ca Buffers component F_expressions[24] = kon_tncl*(Bmax_TnClow - Tn_CL)*Ca_i -\ koff_tncl*Tn_CL F_expressions[22] = -koff_tnchca*Tn_CHc + kon_tnchca*(-Tn_CHc +\ Bmax_TnChigh - Tn_CHm)*Ca_i F_expressions[23] = Mgi*kon_tnchmg*(-Tn_CHc + Bmax_TnChigh - Tn_CHm)\ - koff_tnchmg*Tn_CHm F_expressions[18] = kon_cam * (-CaM + Bmax_CaM) * Ca_i - koff_cam * CaM F_expressions[19] = -koff_myoca*Myo_c + kon_myoca*(-Myo_c +\ Bmax_myosin - Myo_m)*Ca_i F_expressions[20] = Mgi*kon_myomg*(-Myo_c + Bmax_myosin - Myo_m) -\ koff_myomg*Myo_m F_expressions[21] = kon_sr * (Bmax_SR - SRB) * Ca_i - koff_sr * SRB J_CaB_cytosol = -koff_tnchca*Tn_CHc - koff_myoca*Myo_c +\ Mgi*kon_myomg*(-Myo_c + Bmax_myosin - Myo_m) +\ Mgi*kon_tnchmg*(-Tn_CHc + Bmax_TnChigh - Tn_CHm) -\ koff_tnchmg*Tn_CHm + kon_tncl*(Bmax_TnClow - Tn_CL)*Ca_i +\ kon_sr*(Bmax_SR - SRB)*Ca_i - koff_myomg*Myo_m + kon_cam*(-CaM +\ Bmax_CaM)*Ca_i - koff_cam*CaM - koff_tncl*Tn_CL +\ kon_myoca*(-Myo_c + Bmax_myosin - Myo_m)*Ca_i +\ kon_tnchca*(-Tn_CHc + Bmax_TnChigh - Tn_CHm)*Ca_i - koff_sr*SRB # Expressions for the Junctional and SL Ca Buffers component Bmax_SLlowsl = Bmax_SLlowsl0 * Vmyo / Vsl Bmax_SLlowj = Bmax_SLlowj0 * Vmyo / Vjunc Bmax_SLhighsl = Bmax_SLhighsl0 * Vmyo / Vsl Bmax_SLhighj = Bmax_SLhighj0 * Vmyo / Vjunc F_expressions[27] = kon_sll * (Bmax_SLlowj - SLL_j) * Ca_j - koff_sll * SLL_j F_expressions[28] = kon_sll*(-SLL_sl + Bmax_SLlowsl)*Ca_sl -\ koff_sll*SLL_sl F_expressions[25] = kon_slh*(Bmax_SLhighj - SLH_j)*Ca_j -\ koff_slh*SLH_j F_expressions[26] = kon_slh*(-SLH_sl + Bmax_SLhighsl)*Ca_sl -\ koff_slh*SLH_sl J_CaB_junction = kon_slh*(Bmax_SLhighj - SLH_j)*Ca_j +\ kon_sll*(Bmax_SLlowj - SLL_j)*Ca_j - koff_slh*SLH_j -\ koff_sll*SLL_j J_CaB_sl = kon_sll*(-SLL_sl + Bmax_SLlowsl)*Ca_sl + kon_slh*(-SLH_sl\ + Bmax_SLhighsl)*Ca_sl - koff_sll*SLL_sl - koff_slh*SLH_sl # Expressions for the SR Ca Concentrations component Bmax_Csqn = Bmax_Csqn0 * Vmyo / Vsr F_expressions[30] = -koff_csqn*Csqn_b + kon_csqn*(Bmax_Csqn -\ Csqn_b)*Ca_sr F_expressions[29] = -kon_csqn*(Bmax_Csqn - Csqn_b)*Ca_sr -\ J_SRleak*Vmyo/Vsr + koff_csqn*Csqn_b - J_SRCarel + J_serca # Expressions for the Na Concentrations component I_Na_tot_junc = 3*I_nak_junc + 3*I_ncx_junc + I_CaNa_junc + I_Na_junc\ + I_nabk_junc I_Na_tot_sl = I_Na_sl + I_nabk_sl + 3 * I_nak_sl + I_CaNa_sl + 3 * I_ncx_sl F_expressions[32] = -Cmem*I_Na_tot_junc/(Frdy*Vjunc) +\ J_na_juncsl*(Na_sl - Na_j)/Vjunc - F_expressions[16] F_expressions[33] = -F_expressions[17] + J_na_slmyo*(-Na_sl +\ Na_i)/Vsl + J_na_juncsl*(-Na_sl + Na_j)/Vsl -\ Cmem*I_Na_tot_sl/(Frdy*Vsl) F_expressions[31] = J_na_slmyo * (Na_sl - Na_i) / Vmyo # Expressions for the K Concentration component F_expressions[34] = Constant(0.0) # Expressions for the Ca Concentrations component I_Ca_tot_junc = I_pca_junc + I_cabk_junc + I_Ca_junc - 2 * I_ncx_junc I_Ca_tot_sl = -2 * I_ncx_sl + I_pca_sl + I_cabk_sl + I_Ca_sl F_expressions[36] = J_ca_juncsl*(Ca_sl - Ca_j)/Vjunc +\ J_SRCarel*Vsr/Vjunc - J_CaB_junction -\ Cmem*I_Ca_tot_junc/(2*Frdy*Vjunc) + J_SRleak*Vmyo/Vjunc F_expressions[37] = -J_CaB_sl + J_ca_juncsl*(Ca_j - Ca_sl)/Vsl -\ Cmem*I_Ca_tot_sl/(2*Frdy*Vsl) + J_ca_slmyo*(Ca_i - Ca_sl)/Vsl F_expressions[35] = -J_CaB_cytosol + J_ca_slmyo*(Ca_sl - Ca_i)/Vmyo -\ J_serca*Vsr/Vmyo # Return results return dolfin.as_vector(F_expressions)
def xtest_latex_formatting_of_conditionals(): # Test conditional expressions assert expr2latex(ufl.conditional(ufl.lt(x, 2), y, 3)) == "x_0 < 2 ? x_1: 3" assert expr2latex(ufl.conditional(ufl.gt(x, 2), 4 + y, 3)) == "x_0 > 2 ? 4 + x_1: 3" assert expr2latex(ufl.conditional(ufl.And(ufl.le(x, 2), ufl.ge(y, 4)), 7, 8)) == "x_0 <= 2 && x_1 >= 4 ? 7: 8" assert expr2latex(ufl.conditional(ufl.Or(ufl.eq(x, 2), ufl.ne(y, 4)), 7, 8)) == "x_0 == 2 || x_1 != 4 ? 7: 8"
def rhs(states, time, parameters, dy=None): """ Compute right hand side """ # Imports import ufl import dolfin # Assign states assert (isinstance(states, dolfin.Function)) assert (states.function_space().depth() == 1) assert (states.function_space().num_sub_spaces() == 17) Xr1, Xr2, Xs, m, h, j, d, f, fCa, s, r, Ca_SR, Ca_i, g, Na_i, V, K_i =\ dolfin.split(states) # Assign parameters assert (isinstance(parameters, (dolfin.Function, dolfin.Constant))) if isinstance(parameters, dolfin.Function): assert (parameters.function_space().depth() == 1) assert (parameters.function_space().num_sub_spaces() == 45) else: assert (parameters.value_size() == 45) P_kna, g_K1, g_Kr, g_Ks, g_Na, g_bna, g_CaL, g_bca, g_to, K_mNa, K_mk,\ P_NaK, K_NaCa, K_sat, Km_Ca, Km_Nai, alpha, gamma, K_pCa, g_pCa,\ g_pK, Buf_c, Buf_sr, Ca_o, K_buf_c, K_buf_sr, K_up, V_leak, V_sr,\ Vmax_up, a_rel, b_rel, c_rel, tau_g, Na_o, Cm, F, R, T, V_c,\ stim_amplitude, stim_duration, stim_period, stim_start, K_o =\ dolfin.split(parameters) # Reversal potentials E_Na = R * T * ufl.ln(Na_o / Na_i) / F E_K = R * T * ufl.ln(K_o / K_i) / F E_Ks = R * T * ufl.ln((Na_o * P_kna + K_o) / (Na_i * P_kna + K_i)) / F E_Ca = 0.5 * R * T * ufl.ln(Ca_o / Ca_i) / F # Inward rectifier potassium current alpha_K1 = 0.1 / (1.0 + 6.14421235332821e-6 * ufl.exp(0.06 * V - 0.06 * E_K)) beta_K1 = (3.06060402008027*ufl.exp(0.0002*V - 0.0002*E_K) +\ 0.367879441171442*ufl.exp(0.1*V - 0.1*E_K))/(1.0 + ufl.exp(0.5*E_K -\ 0.5*V)) xK1_inf = alpha_K1 / (alpha_K1 + beta_K1) i_K1 = 0.430331482911935 * ufl.sqrt(K_o) * (-E_K + V) * g_K1 * xK1_inf # Rapid time dependent potassium current i_Kr = 0.430331482911935 * ufl.sqrt(K_o) * (-E_K + V) * Xr1 * Xr2 * g_Kr # Rapid time dependent potassium current xr1 gate xr1_inf = 1.0 / (1.0 + 0.0243728440732796 * ufl.exp(-0.142857142857143 * V)) alpha_xr1 = 450.0 / (1.0 + ufl.exp(-9 / 2 - V / 10.0)) beta_xr1 = 6.0 / (1.0 + 13.5813245225782 * ufl.exp(0.0869565217391304 * V)) tau_xr1 = alpha_xr1 * beta_xr1 # Rapid time dependent potassium current xr2 gate xr2_inf = 1.0 / (1.0 + 39.1212839981532 * ufl.exp(0.0416666666666667 * V)) alpha_xr2 = 3.0 / (1.0 + 0.0497870683678639 * ufl.exp(-0.05 * V)) beta_xr2 = 1.12 / (1.0 + 0.0497870683678639 * ufl.exp(0.05 * V)) tau_xr2 = alpha_xr2 * beta_xr2 # Slow time dependent potassium current i_Ks = (Xs * Xs) * (V - E_Ks) * g_Ks # Slow time dependent potassium current xs gate xs_inf = 1.0 / (1.0 + 0.69967253737513 * ufl.exp(-0.0714285714285714 * V)) alpha_xs = 1100.0/ufl.sqrt(1.0 +\ 0.188875602837562*ufl.exp(-0.166666666666667*V)) beta_xs = 1.0 / (1.0 + 0.0497870683678639 * ufl.exp(0.05 * V)) tau_xs = alpha_xs * beta_xs # Fast sodium current i_Na = (m * m * m) * (-E_Na + V) * g_Na * h * j # Fast sodium current m gate m_inf = 1.0/((1.0 +\ 0.00184221158116513*ufl.exp(-0.110741971207087*V))*(1.0 +\ 0.00184221158116513*ufl.exp(-0.110741971207087*V))) alpha_m = 1.0 / (1.0 + ufl.exp(-12.0 - V / 5.0)) beta_m = 0.1/(1.0 + 0.778800783071405*ufl.exp(0.005*V)) + 0.1/(1.0 +\ ufl.exp(7.0 + V/5.0)) tau_m = alpha_m * beta_m # Fast sodium current h gate h_inf = 1.0/((1.0 + 15212.5932856544*ufl.exp(0.134589502018843*V))*(1.0 +\ 15212.5932856544*ufl.exp(0.134589502018843*V))) alpha_h = 4.43126792958051e-7*ufl.exp(-0.147058823529412*V)/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)) beta_h = (310000.0*ufl.exp(0.3485*V) + 2.7*ufl.exp(0.079*V))/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)) + 0.77*(1.0 - 1.0/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)))/(0.13 +\ 0.0497581410839387*ufl.exp(-0.0900900900900901*V)) tau_h = 1.0 / (alpha_h + beta_h) # Fast sodium current j gate j_inf = 1.0/((1.0 + 15212.5932856544*ufl.exp(0.134589502018843*V))*(1.0 +\ 15212.5932856544*ufl.exp(0.134589502018843*V))) beta_j = ufl.conditional(ufl.lt(V, -40.0),\ 0.02424*ufl.exp(-0.01052*V)/(1.0 +\ 0.00396086833990426*ufl.exp(-0.1378*V)), 0.6*ufl.exp(0.057*V)/(1.0 +\ 0.0407622039783662*ufl.exp(-0.1*V))) alpha_j = (37.78 + V)*(-6.948e-6*ufl.exp(-0.04391*V) -\ 25428.0*ufl.exp(0.2444*V))/((1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V))*(1.0 +\ 50262745825.954*ufl.exp(0.311*V))) beta_j = 0.6*(1.0 - 1.0/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)))*ufl.exp(0.057*V)/(1.0 +\ 0.0407622039783662*ufl.exp(-0.1*V)) +\ 0.02424*ufl.exp(-0.01052*V)/((1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V))*(1.0 +\ 0.00396086833990426*ufl.exp(-0.1378*V))) tau_j = 1.0 / (alpha_j + beta_j) # Sodium background current i_b_Na = (-E_Na + V) * g_bna # L type ca current i_CaL = 4.0*(F*F)*(-0.341*Ca_o +\ Ca_i*ufl.exp(2.0*F*V/(R*T)))*V*d*f*fCa*g_CaL/((-1.0 +\ ufl.exp(2.0*F*V/(R*T)))*R*T) # L type ca current d gate d_inf = 1.0 / (1.0 + 0.513417119032592 * ufl.exp(-0.133333333333333 * V)) alpha_d = 0.25 + 1.4/(1.0 +\ 0.0677244716592409*ufl.exp(-0.0769230769230769*V)) beta_d = 1.4 / (1.0 + ufl.exp(1.0 + V / 5.0)) gamma_d = 1.0 / (1.0 + 12.1824939607035 * ufl.exp(-0.05 * V)) tau_d = gamma_d + alpha_d * beta_d # L type ca current f gate f_inf = 1.0 / (1.0 + 17.4117080633276 * ufl.exp(0.142857142857143 * V)) tau_f = 80.0 + 165.0/(1.0 + ufl.exp(5/2 - V/10.0)) +\ 1125.0*ufl.exp(-0.00416666666666667*((27.0 + V)*(27.0 + V))) # L type ca current fca gate alpha_fCa = 1.0 / (1.0 + 8.03402376701711e+27 * ufl.elem_pow(Ca_i, 8.0)) beta_fCa = 0.1 / (1.0 + 0.00673794699908547 * ufl.exp(10000.0 * Ca_i)) gama_fCa = 0.2 / (1.0 + 0.391605626676799 * ufl.exp(1250.0 * Ca_i)) fCa_inf = 0.157534246575342 + 0.684931506849315*gama_fCa +\ 0.684931506849315*beta_fCa + 0.684931506849315*alpha_fCa tau_fCa = 2.0 d_fCa = (-fCa + fCa_inf) / tau_fCa # Calcium background current i_b_Ca = (V - E_Ca) * g_bca # Transient outward current i_to = (-E_K + V) * g_to * r * s # Transient outward current s gate s_inf = 1.0 / (1.0 + ufl.exp(4.0 + V / 5.0)) tau_s = 3.0 + 85.0*ufl.exp(-0.003125*((45.0 + V)*(45.0 + V))) + 5.0/(1.0 +\ ufl.exp(-4.0 + V/5.0)) # Transient outward current r gate r_inf = 1.0 / (1.0 + 28.0316248945261 * ufl.exp(-0.166666666666667 * V)) tau_r = 0.8 + 9.5 * ufl.exp(-0.000555555555555556 * ((40.0 + V) * (40.0 + V))) # Sodium potassium pump current i_NaK = K_o*Na_i*P_NaK/((K_mk + K_o)*(Na_i + K_mNa)*(1.0 +\ 0.0353*ufl.exp(-F*V/(R*T)) + 0.1245*ufl.exp(-0.1*F*V/(R*T)))) # Sodium calcium exchanger current i_NaCa = (-(Na_o*Na_o*Na_o)*Ca_i*alpha*ufl.exp((-1.0 + gamma)*F*V/(R*T))\ + (Na_i*Na_i*Na_i)*Ca_o*ufl.exp(F*V*gamma/(R*T)))*K_NaCa/((1.0 +\ K_sat*ufl.exp((-1.0 + gamma)*F*V/(R*T)))*((Na_o*Na_o*Na_o) +\ (Km_Nai*Km_Nai*Km_Nai))*(Km_Ca + Ca_o)) # Calcium pump current i_p_Ca = Ca_i * g_pCa / (K_pCa + Ca_i) # Potassium pump current i_p_K = (-E_K + V)*g_pK/(1.0 +\ 65.4052157419383*ufl.exp(-0.167224080267559*V)) # Calcium dynamics i_rel = ((Ca_SR * Ca_SR) * a_rel / ((Ca_SR * Ca_SR) + (b_rel * b_rel)) + c_rel) * d * g i_up = Vmax_up / (1.0 + (K_up * K_up) / (Ca_i * Ca_i)) i_leak = (-Ca_i + Ca_SR) * V_leak g_inf = (1.0 - 1.0/(1.0 + 0.0301973834223185*ufl.exp(10000.0*Ca_i)))/(1.0 +\ 1.97201988740492e+55*ufl.elem_pow(Ca_i, 16.0)) + 1.0/((1.0 +\ 0.0301973834223185*ufl.exp(10000.0*Ca_i))*(1.0 +\ 5.43991024148102e+20*ufl.elem_pow(Ca_i, 6.0))) d_g = (-g + g_inf) / tau_g Ca_i_bufc = 1.0 / (1.0 + Buf_c * K_buf_c / ((K_buf_c + Ca_i) * (K_buf_c + Ca_i))) Ca_sr_bufsr = 1.0/(1.0 + Buf_sr*K_buf_sr/((K_buf_sr + Ca_SR)*(K_buf_sr +\ Ca_SR))) # Sodium dynamics # Membrane i_Stim = ufl.conditional(ufl.And(ufl.ge(time, stim_start), ufl.le(time,\ stim_start + stim_duration)), -stim_amplitude, 0.0) # Potassium dynamics # The ODE system: 17 states # Init test function _v = dolfin.TestFunction(states.function_space()) # Derivative for state Xr1 dy = ((-Xr1 + xr1_inf) / tau_xr1) * _v[0] # Derivative for state Xr2 dy += ((-Xr2 + xr2_inf) / tau_xr2) * _v[1] # Derivative for state Xs dy += ((-Xs + xs_inf) / tau_xs) * _v[2] # Derivative for state m dy += ((-m + m_inf) / tau_m) * _v[3] # Derivative for state h dy += ((-h + h_inf) / tau_h) * _v[4] # Derivative for state j dy += ((j_inf - j) / tau_j) * _v[5] # Derivative for state d dy += ((d_inf - d) / tau_d) * _v[6] # Derivative for state f dy += ((-f + f_inf) / tau_f) * _v[7] # Derivative for state fCa dy += ((1.0 - 1.0/((1.0 + ufl.exp(60.0 + V))*(1.0 + ufl.exp(-10.0*fCa +\ 10.0*fCa_inf))))*d_fCa)*_v[8] # Derivative for state s dy += ((-s + s_inf) / tau_s) * _v[9] # Derivative for state r dy += ((-r + r_inf) / tau_r) * _v[10] # Derivative for state Ca_SR dy += ((-i_leak + i_up - i_rel) * Ca_sr_bufsr * V_c / V_sr) * _v[11] # Derivative for state Ca_i dy += ((-i_up - (i_CaL + i_p_Ca + i_b_Ca - 2.0*i_NaCa)*Cm/(2.0*F*V_c) +\ i_leak + i_rel)*Ca_i_bufc)*_v[12] # Derivative for state g dy += ((1.0 - 1.0/((1.0 + ufl.exp(60.0 + V))*(1.0 + ufl.exp(-10.0*g +\ 10.0*g_inf))))*d_g)*_v[13] # Derivative for state Na_i dy += ((-3.0 * i_NaK - 3.0 * i_NaCa - i_Na - i_b_Na) * Cm / (F * V_c)) * _v[14] # Derivative for state V dy += (-i_Ks - i_to - i_Kr - i_p_K - i_NaK - i_NaCa - i_Na - i_p_Ca -\ i_b_Na - i_CaL - i_Stim - i_K1 - i_b_Ca)*_v[15] # Derivative for state K_i dy += ((-i_Ks - i_to - i_Kr - i_p_K - i_Stim - i_K1 +\ 2.0*i_NaK)*Cm/(F*V_c))*_v[16] # Return dy return dy
def F(self, v, s, time=None): """ Right hand side for ODE system """ time = time if time else Constant(0.0) # Assign states V = v assert(len(s) == 16) Xr1, Xr2, Xs, m, h, j, d, f, fCa, s, r, g, Ca_i, Ca_SR, Na_i, K_i = s # Assign parameters P_kna = self._parameters["P_kna"] g_K1 = self._parameters["g_K1"] g_Kr = self._parameters["g_Kr"] g_Ks = self._parameters["g_Ks"] g_Na = self._parameters["g_Na"] g_bna = self._parameters["g_bna"] g_CaL = self._parameters["g_CaL"] g_bca = self._parameters["g_bca"] g_to = self._parameters["g_to"] K_mNa = self._parameters["K_mNa"] K_mk = self._parameters["K_mk"] P_NaK = self._parameters["P_NaK"] K_NaCa = self._parameters["K_NaCa"] K_sat = self._parameters["K_sat"] Km_Ca = self._parameters["Km_Ca"] Km_Nai = self._parameters["Km_Nai"] alpha = self._parameters["alpha"] gamma = self._parameters["gamma"] K_pCa = self._parameters["K_pCa"] g_pCa = self._parameters["g_pCa"] g_pK = self._parameters["g_pK"] Buf_c = self._parameters["Buf_c"] Buf_sr = self._parameters["Buf_sr"] Ca_o = self._parameters["Ca_o"] K_buf_c = self._parameters["K_buf_c"] K_buf_sr = self._parameters["K_buf_sr"] K_up = self._parameters["K_up"] V_leak = self._parameters["V_leak"] V_sr = self._parameters["V_sr"] Vmax_up = self._parameters["Vmax_up"] a_rel = self._parameters["a_rel"] b_rel = self._parameters["b_rel"] c_rel = self._parameters["c_rel"] tau_g = self._parameters["tau_g"] Na_o = self._parameters["Na_o"] Cm = self._parameters["Cm"] F = self._parameters["F"] R = self._parameters["R"] T = self._parameters["T"] V_c = self._parameters["V_c"] stim_amplitude = self._parameters["stim_amplitude"] stim_duration = self._parameters["stim_duration"] stim_period = self._parameters["stim_period"] stim_start = self._parameters["stim_start"] K_o = self._parameters["K_o"] # Init return args F_expressions = [ufl.zero()]*16 # Expressions for the Reversal potentials component E_Na = R*T*ufl.ln(Na_o/Na_i)/F E_K = R*T*ufl.ln(K_o/K_i)/F E_Ks = R*T*ufl.ln((K_o + Na_o*P_kna)/(P_kna*Na_i + K_i))/F E_Ca = 0.5*R*T*ufl.ln(Ca_o/Ca_i)/F # Expressions for the Inward rectifier potassium current component alpha_K1 = 0.1/(1.0 + 6.14421235332821e-06*ufl.exp(0.06*V - 0.06*E_K)) beta_K1 = (0.36787944117144233*ufl.exp(0.1*V - 0.1*E_K) +\ 3.0606040200802673*ufl.exp(0.0002*V - 0.0002*E_K))/(1.0 +\ ufl.exp(0.5*E_K - 0.5*V)) xK1_inf = alpha_K1/(alpha_K1 + beta_K1) i_K1 = 0.4303314829119352*g_K1*ufl.sqrt(K_o)*(-E_K + V)*xK1_inf # Expressions for the Rapid time dependent potassium current component i_Kr = 0.4303314829119352*g_Kr*ufl.sqrt(K_o)*(-E_K + V)*Xr1*Xr2 # Expressions for the Xr1 gate component xr1_inf = 1.0/(1.0 +\ 0.02437284407327961*ufl.exp(-0.14285714285714285*V)) alpha_xr1 = 450.0/(1.0 + 0.011108996538242306*ufl.exp(-0.1*V)) beta_xr1 = 6.0/(1.0 +\ 13.581324522578193*ufl.exp(0.08695652173913043*V)) tau_xr1 = 1.0*alpha_xr1*beta_xr1 F_expressions[0] = (-Xr1 + xr1_inf)/tau_xr1 # Expressions for the Xr2 gate component xr2_inf = 1.0/(1.0 + 39.12128399815321*ufl.exp(0.041666666666666664*V)) alpha_xr2 = 3.0/(1.0 + 0.049787068367863944*ufl.exp(-0.05*V)) beta_xr2 = 1.12/(1.0 + 0.049787068367863944*ufl.exp(0.05*V)) tau_xr2 = 1.0*alpha_xr2*beta_xr2 F_expressions[1] = (-Xr2 + xr2_inf)/tau_xr2 # Expressions for the Slow time dependent potassium current component i_Ks = g_Ks*ufl.elem_pow(Xs, 2.0)*(-E_Ks + V) # Expressions for the Xs gate component xs_inf = 1.0/(1.0 + 0.6996725373751304*ufl.exp(-0.07142857142857142*V)) alpha_xs = 1100.0/ufl.sqrt(1.0 +\ 0.18887560283756186*ufl.exp(-0.16666666666666666*V)) beta_xs = 1.0/(1.0 + 0.049787068367863944*ufl.exp(0.05*V)) tau_xs = 1.0*alpha_xs*beta_xs F_expressions[2] = (-Xs + xs_inf)/tau_xs # Expressions for the Fast sodium current component i_Na = g_Na*ufl.elem_pow(m, 3.0)*(-E_Na + V)*h*j # Expressions for the m gate component m_inf = 1.0*ufl.elem_pow(1.0 +\ 0.0018422115811651339*ufl.exp(-0.1107419712070875*V), -2.0) alpha_m = 1.0/(1.0 + 6.14421235332821e-06*ufl.exp(-0.2*V)) beta_m = 0.1/(1.0 + 1096.6331584284585*ufl.exp(0.2*V)) + 0.1/(1.0 +\ 0.7788007830714049*ufl.exp(0.005*V)) tau_m = 1.0*alpha_m*beta_m F_expressions[3] = (-m + m_inf)/tau_m # Expressions for the h gate component h_inf = 1.0*ufl.elem_pow(1.0 +\ 15212.593285654404*ufl.exp(0.13458950201884254*V), -2.0) alpha_h = ufl.conditional(ufl.lt(V, -40.0),\ 4.4312679295805147e-07*ufl.exp(-0.14705882352941177*V), 0) beta_h = ufl.conditional(ufl.lt(V, -40.0), 310000.0*ufl.exp(0.3485*V)\ + 2.7*ufl.exp(0.079*V), 0.77/(0.13 +\ 0.049758141083938695*ufl.exp(-0.0900900900900901*V))) tau_h = 1.0/(alpha_h + beta_h) F_expressions[4] = (-h + h_inf)/tau_h # Expressions for the j gate component j_inf = 1.0*ufl.elem_pow(1.0 +\ 15212.593285654404*ufl.exp(0.13458950201884254*V), -2.0) alpha_j = ufl.conditional(ufl.lt(V, -40.0), 1.0*(37.78 +\ V)*(-25428.0*ufl.exp(0.2444*V) -\ 6.948e-06*ufl.exp(-0.04391*V))/(1.0 +\ 50262745825.95399*ufl.exp(0.311*V)), 0) beta_j = ufl.conditional(ufl.lt(V, -40.0),\ 0.02424*ufl.exp(-0.01052*V)/(1.0 +\ 0.003960868339904256*ufl.exp(-0.1378*V)),\ 0.6*ufl.exp(0.057*V)/(1.0 +\ 0.040762203978366204*ufl.exp(-0.1*V))) tau_j = 1.0/(alpha_j + beta_j) F_expressions[5] = (-j + j_inf)/tau_j # Expressions for the Sodium background current component i_b_Na = g_bna*(-E_Na + V) # Expressions for the L_type Ca current component i_CaL = 4.0*g_CaL*ufl.elem_pow(F, 2.0)*(-0.341*Ca_o +\ Ca_i*ufl.exp(2.0*F*V/(R*T)))*V*d*f*fCa/(R*T*(-1.0 +\ ufl.exp(2.0*F*V/(R*T)))) # Expressions for the d gate component d_inf = 1.0/(1.0 + 0.513417119032592*ufl.exp(-0.13333333333333333*V)) alpha_d = 0.25 + 1.4/(1.0 +\ 0.0677244716592409*ufl.exp(-0.07692307692307693*V)) beta_d = 1.4/(1.0 + 2.718281828459045*ufl.exp(0.2*V)) gamma_d = 1.0/(1.0 + 12.182493960703473*ufl.exp(-0.05*V)) tau_d = 1.0*alpha_d*beta_d + gamma_d F_expressions[6] = (-d + d_inf)/tau_d # Expressions for the f gate component f_inf = 1.0/(1.0 + 17.411708063327644*ufl.exp(0.14285714285714285*V)) tau_f = 80.0 + 165.0/(1.0 + 12.182493960703473*ufl.exp(-0.1*V)) +\ 1125.0*ufl.exp(-0.004166666666666667*ufl.elem_pow(27.0 + V, 2.0)) F_expressions[7] = (-f + f_inf)/tau_f # Expressions for the FCa gate component alpha_fCa = 1.0/(1.0 + 8.03402376701711e+27*ufl.elem_pow(Ca_i, 8.0)) beta_fCa = 0.1/(1.0 + 0.006737946999085467*ufl.exp(10000.0*Ca_i)) gama_fCa = 0.2/(1.0 + 0.391605626676799*ufl.exp(1250.0*Ca_i)) fCa_inf = 0.15753424657534246 + 0.684931506849315*alpha_fCa +\ 0.684931506849315*beta_fCa + 0.684931506849315*gama_fCa tau_fCa = 2.0 d_fCa = (-fCa + fCa_inf)/tau_fCa F_expressions[8] = ufl.conditional(ufl.And(ufl.gt(V, -60.0),\ ufl.gt(fCa_inf, fCa)), 0, d_fCa) # Expressions for the Calcium background current component i_b_Ca = g_bca*(-E_Ca + V) # Expressions for the Transient outward current component i_to = g_to*(-E_K + V)*r*s # Expressions for the s gate component s_inf = 1.0/(1.0 + 54.598150033144236*ufl.exp(0.2*V)) tau_s = 3.0 + 5.0/(1.0 + 0.01831563888873418*ufl.exp(0.2*V)) +\ 85.0*ufl.exp(-0.003125*ufl.elem_pow(45.0 + V, 2.0)) F_expressions[9] = (-s + s_inf)/tau_s # Expressions for the r gate component r_inf = 1.0/(1.0 + 28.031624894526125*ufl.exp(-0.16666666666666666*V)) tau_r = 0.8 + 9.5*ufl.exp(-0.0005555555555555556*ufl.elem_pow(40.0 +\ V, 2.0)) F_expressions[10] = (-r + r_inf)/tau_r # Expressions for the Sodium potassium pump current component i_NaK = K_o*P_NaK*Na_i/((K_mNa + Na_i)*(K_mk + K_o)*(1.0 +\ 0.0353*ufl.exp(-F*V/(R*T)) + 0.1245*ufl.exp(-0.1*F*V/(R*T)))) # Expressions for the Sodium calcium exchanger current component i_NaCa = K_NaCa*(Ca_o*ufl.elem_pow(Na_i,\ 3.0)*ufl.exp(F*gamma*V/(R*T)) - alpha*ufl.elem_pow(Na_o,\ 3.0)*Ca_i*ufl.exp(F*(-1.0 + gamma)*V/(R*T)))/((1.0 +\ K_sat*ufl.exp(F*(-1.0 + gamma)*V/(R*T)))*(Ca_o +\ Km_Ca)*(ufl.elem_pow(Km_Nai, 3.0) + ufl.elem_pow(Na_o, 3.0))) # Expressions for the Calcium pump current component i_p_Ca = g_pCa*Ca_i/(K_pCa + Ca_i) # Expressions for the Potassium pump current component i_p_K = g_pK*(-E_K + V)/(1.0 +\ 65.40521574193832*ufl.exp(-0.16722408026755853*V)) # Expressions for the Calcium dynamics component i_rel = (c_rel + a_rel*ufl.elem_pow(Ca_SR, 2.0)/(ufl.elem_pow(b_rel,\ 2.0) + ufl.elem_pow(Ca_SR, 2.0)))*d*g i_up = Vmax_up/(1.0 + ufl.elem_pow(K_up, 2.0)*ufl.elem_pow(Ca_i, -2.0)) i_leak = V_leak*(-Ca_i + Ca_SR) g_inf = ufl.conditional(ufl.lt(Ca_i, 0.00035), 1.0/(1.0 +\ 5.439910241481018e+20*ufl.elem_pow(Ca_i, 6.0)), 1.0/(1.0 +\ 1.9720198874049195e+55*ufl.elem_pow(Ca_i, 16.0))) d_g = (-g + g_inf)/tau_g F_expressions[11] = ufl.conditional(ufl.And(ufl.gt(V, -60.0),\ ufl.gt(g_inf, g)), 0, d_g) Ca_i_bufc = 1.0/(1.0 + Buf_c*K_buf_c*ufl.elem_pow(K_buf_c + Ca_i,\ -2.0)) Ca_sr_bufsr = 1.0/(1.0 + Buf_sr*K_buf_sr*ufl.elem_pow(K_buf_sr +\ Ca_SR, -2.0)) F_expressions[12] = (-i_up - 0.5*Cm*(1.0*i_CaL + 1.0*i_b_Ca +\ 1.0*i_p_Ca - 2.0*i_NaCa)/(F*V_c) + i_leak + i_rel)*Ca_i_bufc F_expressions[13] = V_c*(-i_leak - i_rel + i_up)*Ca_sr_bufsr/V_sr # Expressions for the Sodium dynamics component F_expressions[14] = 1.0*Cm*(-1.0*i_Na - 1.0*i_b_Na - 3.0*i_NaCa -\ 3.0*i_NaK)/(F*V_c) # Expressions for the Membrane component i_Stim = ufl.conditional(ufl.And(ufl.ge(time -\ stim_period*ufl.floor(time/stim_period), stim_start), ufl.le(time\ - stim_period*ufl.floor(time/stim_period), stim_duration +\ stim_start)), -stim_amplitude, 0) # Expressions for the Potassium dynamics component F_expressions[15] = 1.0*Cm*(2.0*i_NaK - 1.0*i_K1 - 1.0*i_Kr -\ 1.0*i_Ks - 1.0*i_Stim - 1.0*i_p_K - 1.0*i_to)/(F*V_c) # Return results return dolfin.as_vector(F_expressions)
from dolfin import * import ufl mesh = UnitIntervalMesh(100) V = FunctionSpace(mesh, "CG", 1) u0 = project(Expression("1+sin(2*pi*x[0])"), V) plot(u0, interactive=True) u = Function(V) q = TestFunction(V) tf = project(Expression("sin(2*pi*x[0])"), V) chi = ufl.conditional(ufl.ge(tf, 0.0), 0, 1) nu = Constant(1e0) F1 = chi * (inner(u - u0, q) + nu * Constant(1e+1) * inner(u.dx(0) * u, q) + nu * Constant(1e-8) * nu * inner(grad(u), grad(q))) * dx invchi = 1 - chi F2 = inner(invchi * u, q) * dx F = F1 + F2 def norm_approx(u, alpha=1e-4): # A smooth approximation to ||u|| return sqrt(inner(u, u) + alpha**2) F1 = chi * (inner(u - u0, q) + Constant(10e-1) * inner(u0.dx(0) * u0 / norm_approx(u0), q) +
def _I(self, v, s, time): """ Original gotran transmembrane current dV/dt """ time = time if time else Constant(0.0) # Assign states V = v assert(len(s) == 16) Xr1, Xr2, Xs, m, h, j, d, f, fCa, s, r, g, Ca_i, Ca_SR, Na_i, K_i = s # Assign parameters P_kna = self._parameters["P_kna"] g_K1 = self._parameters["g_K1"] g_Kr = self._parameters["g_Kr"] g_Ks = self._parameters["g_Ks"] g_Na = self._parameters["g_Na"] g_bna = self._parameters["g_bna"] g_CaL = self._parameters["g_CaL"] g_bca = self._parameters["g_bca"] g_to = self._parameters["g_to"] K_mNa = self._parameters["K_mNa"] K_mk = self._parameters["K_mk"] P_NaK = self._parameters["P_NaK"] K_NaCa = self._parameters["K_NaCa"] K_sat = self._parameters["K_sat"] Km_Ca = self._parameters["Km_Ca"] Km_Nai = self._parameters["Km_Nai"] alpha = self._parameters["alpha"] gamma = self._parameters["gamma"] K_pCa = self._parameters["K_pCa"] g_pCa = self._parameters["g_pCa"] g_pK = self._parameters["g_pK"] Ca_o = self._parameters["Ca_o"] Na_o = self._parameters["Na_o"] F = self._parameters["F"] R = self._parameters["R"] T = self._parameters["T"] stim_amplitude = self._parameters["stim_amplitude"] stim_duration = self._parameters["stim_duration"] stim_period = self._parameters["stim_period"] stim_start = self._parameters["stim_start"] K_o = self._parameters["K_o"] # Init return args current = [ufl.zero()]*1 # Expressions for the Reversal potentials component E_Na = R*T*ufl.ln(Na_o/Na_i)/F E_K = R*T*ufl.ln(K_o/K_i)/F E_Ks = R*T*ufl.ln((K_o + Na_o*P_kna)/(P_kna*Na_i + K_i))/F E_Ca = 0.5*R*T*ufl.ln(Ca_o/Ca_i)/F # Expressions for the Inward rectifier potassium current component alpha_K1 = 0.1/(1.0 + 6.14421235332821e-06*ufl.exp(0.06*V - 0.06*E_K)) beta_K1 = (0.36787944117144233*ufl.exp(0.1*V - 0.1*E_K) +\ 3.0606040200802673*ufl.exp(0.0002*V - 0.0002*E_K))/(1.0 +\ ufl.exp(0.5*E_K - 0.5*V)) xK1_inf = alpha_K1/(alpha_K1 + beta_K1) i_K1 = 0.4303314829119352*g_K1*ufl.sqrt(K_o)*(-E_K + V)*xK1_inf # Expressions for the Rapid time dependent potassium current component i_Kr = 0.4303314829119352*g_Kr*ufl.sqrt(K_o)*(-E_K + V)*Xr1*Xr2 # Expressions for the Slow time dependent potassium current component i_Ks = g_Ks*ufl.elem_pow(Xs, 2.0)*(-E_Ks + V) # Expressions for the Fast sodium current component i_Na = g_Na*ufl.elem_pow(m, 3.0)*(-E_Na + V)*h*j # Expressions for the Sodium background current component i_b_Na = g_bna*(-E_Na + V) # Expressions for the L_type Ca current component i_CaL = 4.0*g_CaL*ufl.elem_pow(F, 2.0)*(-0.341*Ca_o +\ Ca_i*ufl.exp(2.0*F*V/(R*T)))*V*d*f*fCa/(R*T*(-1.0 +\ ufl.exp(2.0*F*V/(R*T)))) # Expressions for the Calcium background current component i_b_Ca = g_bca*(-E_Ca + V) # Expressions for the Transient outward current component i_to = g_to*(-E_K + V)*r*s # Expressions for the Sodium potassium pump current component i_NaK = K_o*P_NaK*Na_i/((K_mNa + Na_i)*(K_mk + K_o)*(1.0 +\ 0.0353*ufl.exp(-F*V/(R*T)) + 0.1245*ufl.exp(-0.1*F*V/(R*T)))) # Expressions for the Sodium calcium exchanger current component i_NaCa = K_NaCa*(Ca_o*ufl.elem_pow(Na_i,\ 3.0)*ufl.exp(F*gamma*V/(R*T)) - alpha*ufl.elem_pow(Na_o,\ 3.0)*Ca_i*ufl.exp(F*(-1.0 + gamma)*V/(R*T)))/((1.0 +\ K_sat*ufl.exp(F*(-1.0 + gamma)*V/(R*T)))*(Ca_o +\ Km_Ca)*(ufl.elem_pow(Km_Nai, 3.0) + ufl.elem_pow(Na_o, 3.0))) # Expressions for the Calcium pump current component i_p_Ca = g_pCa*Ca_i/(K_pCa + Ca_i) # Expressions for the Potassium pump current component i_p_K = g_pK*(-E_K + V)/(1.0 +\ 65.40521574193832*ufl.exp(-0.16722408026755853*V)) # Expressions for the Membrane component i_Stim = ufl.conditional(ufl.And(ufl.ge(time -\ stim_period*ufl.floor(time/stim_period), stim_start), ufl.le(time\ - stim_period*ufl.floor(time/stim_period), stim_duration +\ stim_start)), -stim_amplitude, 0) current[0] = -1.0*i_CaL - 1.0*i_K1 - 1.0*i_Kr - 1.0*i_Ks - 1.0*i_Na -\ 1.0*i_NaCa - 1.0*i_NaK - 1.0*i_Stim - 1.0*i_b_Ca - 1.0*i_b_Na -\ 1.0*i_p_Ca - 1.0*i_p_K - 1.0*i_to # Return results return current[0]