示例#1
0
 def __angle__(self):
     x, y = self.real, self.imag
     try:
         return np.angle(x + 1j * y)
     except:
         return dolfin.conditional(
             ufl.eq(self.__abs__(), 0),
             0,
             dolfin.conditional(
                 ufl.eq(self.__abs__() + x, 0),
                 dolfin.pi,
                 2 * dolfin.atan(y / (self.__abs__() + x)),
             ),
         )
示例#2
0
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"
示例#3
0
def test_cpp_formatting_with_variables():
    x, y = ufl.SpatialCoordinate(ufl.triangle)
    # Test user-provided C variables for subexpressions
    # we can use variables for x[0], and sum, and power
    assert expr2cpp(x**2 + y**2, variables={x**2: 'x2', y**2: 'y2'}) == "x2 + y2"
    assert expr2cpp(x**2 + y**2, variables={x: 'z', y**2: 'y2'}) == "pow(z, 2) + y2"
    assert expr2cpp(x**2 + y**2, variables={x**2 + y**2: 'q'}) == "q"
    # we can use variables in conditionals
    assert expr2cpp(ufl.conditional(ufl.Or(ufl.eq(x, 2), ufl.ne(y, 4)), 7, 8),
                    variables={ufl.eq(x, 2): 'c1', ufl.ne(y, 4): 'c2'}) == "c1 || c2 ? 7: 8"
    # we can replace coefficients (formatted by user provided code)
    V = ufl.FiniteElement("CG", ufl.triangle, 1)
    f = ufl.Coefficient(V, count=0)
    assert expr2cpp(f, variables={f: 'f'}) == "f"
    assert expr2cpp(f**3, variables={f: 'f'}) == "pow(f, 3)"
    # variables do not replace derivatives of variable expressions
    assert expr2cpp(f.dx(0), variables={f: 'f'}) == "d1_w0[0]"

    # This test depends on which differentiation algorithm is in use
    # in UFL, representing derivatives as SpatialDerivative or Grad:
    # variables do replace variable expressions that are themselves derivatives
    assert expr2cpp(f.dx(0), variables={f.dx(0): 'df', ufl.grad(f)[0]: 'df'}) == "df"
    assert expr2cpp(ufl.grad(f)[0], variables={f.dx(0): 'df', ufl.grad(f)[0]: 'df'}) == "df"
示例#4
0
def test_latex_formatting_of_variables():
    x, y = ufl.SpatialCoordinate(ufl.triangle)
    # Test user-provided C variables for subexpressions
    # we can use variables for x[0], and sum, and power
    assert expr2latex(x**2 + y**2, variables={x**2: 'x2', y**2: 'y2'}) == "x2 + y2"
    assert expr2latex(x**2 + y**2, variables={x: 'z', y**2: 'y2'}) == r"{z}^{2} + y2"
    assert expr2latex(x**2 + y**2, variables={x**2 + y**2: 'q'}) == "q"
    # we can use variables in conditionals
    if 0:
        assert expr2latex(ufl.conditional(ufl.Or(ufl.eq(x, 2), ufl.ne(y, 4)), 7, 8), variables={ufl.eq(x, 2): 'c1', ufl.ne(y, 4): 'c2'}) == "c1 || c2 ? 7: 8"
    # we can replace coefficients (formatted by user provided code)
    V = ufl.FiniteElement("CG", ufl.triangle, 1)
    f = ufl.Coefficient(V, count=0)
    assert expr2latex(f, variables={f: 'f'}) == "f"
    assert expr2latex(f**3, variables={f: 'f'}) == r"{f}^{3}"
    # variables do not replace derivatives of variable expressions
    assert expr2latex(f.dx(0), variables={f: 'f'}) == r"\overset{0}{w}_{, 0}"
    # variables do replace variable expressions that are themselves derivatives
    assert expr2latex(f.dx(0), variables={f.dx(0): 'df', ufl.grad(f)[0]: 'df'}) == "df"
    assert expr2latex(ufl.grad(f)[0], variables={f.dx(0): 'df', ufl.grad(f)[0]: 'df'}) == "df"
示例#5
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
        assert (len(s) == 17)
        m, h, j, d, f1, f2, fCa, Xr1, Xr2, Xs, Xf, q, r, Nai, g, Cai, Ca_SR = s

        # Assign parameters
        Chromanol_iKs30 = self._parameters["Chromanol_iKs30"]
        Chromanol_iKs50 = self._parameters["Chromanol_iKs50"]
        Chromanol_iKs70 = self._parameters["Chromanol_iKs70"]
        Chromanol_iKs90 = self._parameters["Chromanol_iKs90"]
        E4031_100nM = self._parameters["E4031_100nM"]
        E4031_30nM = self._parameters["E4031_30nM"]
        TTX_10uM = self._parameters["TTX_10uM"]
        TTX_30uM = self._parameters["TTX_30uM"]
        TTX_3uM = self._parameters["TTX_3uM"]
        nifed_100nM = self._parameters["nifed_100nM"]
        nifed_10nM = self._parameters["nifed_10nM"]
        nifed_30nM = self._parameters["nifed_30nM"]
        nifed_3nM = self._parameters["nifed_3nM"]
        PkNa = self._parameters["PkNa"]
        g_Na = self._parameters["g_Na"]
        g_CaL = self._parameters["g_CaL"]
        g_Kr = self._parameters["g_Kr"]
        g_Ks = self._parameters["g_Ks"]
        g_K1 = self._parameters["g_K1"]
        E_f = self._parameters["E_f"]
        g_f = self._parameters["g_f"]
        g_b_Na = self._parameters["g_b_Na"]
        g_b_Ca = self._parameters["g_b_Ca"]
        Km_K = self._parameters["Km_K"]
        Km_Na = self._parameters["Km_Na"]
        PNaK = self._parameters["PNaK"]
        KmCa = self._parameters["KmCa"]
        KmNai = self._parameters["KmNai"]
        Ksat = self._parameters["Ksat"]
        alpha = self._parameters["alpha"]
        gamma = self._parameters["gamma"]
        kNaCa = self._parameters["kNaCa"]
        KPCa = self._parameters["KPCa"]
        g_PCa = self._parameters["g_PCa"]
        g_to = self._parameters["g_to"]
        Cao = self._parameters["Cao"]
        F = self._parameters["F"]
        Ki = self._parameters["Ki"]
        Ko = self._parameters["Ko"]
        Nao = self._parameters["Nao"]
        R = self._parameters["R"]
        T = self._parameters["T"]

        # Init return args
        current = [ufl.zero()] * 1

        # Expressions for the Electric potentials component
        E_Na = R * T * ufl.ln(Nao / Nai) / F
        E_K = R * T * ufl.ln(Ko / Ki) / F
        E_Ks = R * T * ufl.ln((Ko + Nao * PkNa) / (Ki + PkNa * Nai)) / F
        E_Ca = 0.5 * R * T * ufl.ln(Cao / Cai) / F

        # Expressions for the i_Na component
        TTX_coeff = ufl.conditional(ufl.eq(TTX_3uM, 1), 0.18,\
            ufl.conditional(ufl.eq(TTX_10uM, 1), 0.06,\
            ufl.conditional(ufl.eq(TTX_30uM, 1), 0.02, 1)))
        i_Na = g_Na * (m * m * m) * (-E_Na + V) * TTX_coeff * h * j

        # Expressions for the i_CaL component
        nifed_coeff = ufl.conditional(ufl.eq(nifed_3nM, 1), 0.93,\
            ufl.conditional(ufl.eq(nifed_10nM, 1), 0.79,\
            ufl.conditional(ufl.eq(nifed_30nM, 1), 0.56,\
            ufl.conditional(ufl.eq(nifed_100nM, 1), 0.28, 1))))
        i_CaL = 4*g_CaL*(F*F)*(-0.341*Cao +\
            Cai*ufl.exp(2*F*V/(R*T)))*V*d*f1*f2*fCa*nifed_coeff/(R*T*(-1 +\
            ufl.exp(2*F*V/(R*T))))

        # Expressions for the i_Kr component
        E4031_coeff = ufl.conditional(ufl.eq(E4031_30nM, 1), 0.77,\
            ufl.conditional(ufl.eq(E4031_100nM, 1), 0.5, 1))
        i_Kr = 0.430331482912 * g_Kr * ufl.sqrt(Ko) * (
            -E_K + V) * E4031_coeff * Xr1 * Xr2

        # Expressions for the i_Ks component
        Chromanol_coeff = ufl.conditional(ufl.eq(Chromanol_iKs30, 1), 0.7,\
            ufl.conditional(ufl.eq(Chromanol_iKs50, 1), 0.5,\
            ufl.conditional(ufl.eq(Chromanol_iKs70, 1), 0.3,\
            ufl.conditional(ufl.eq(Chromanol_iKs90, 1), 0.1, 1))))
        i_Ks = g_Ks*(Xs*Xs)*(1 + 0.6/(1 +\
            6.48182102606e-07*ufl.elem_pow(1.0/Cai, 1.4)))*(-E_Ks +\
            V)*Chromanol_coeff

        # Expressions for the i_K1 component
        alpha_K1 = 3.91 / (
            1 + 2.44592857399e-52 * ufl.exp(594.2 * V - 594.2 * E_K))
        beta_K1 = (0.00277806676906*ufl.exp(588.6*V - 588.6*E_K) -\
            1.5394838221*ufl.exp(0.2*V - 0.2*E_K))/(1 + ufl.exp(454.7*V -\
            454.7*E_K))
        XK1_inf = alpha_K1 / (alpha_K1 + beta_K1)
        i_K1 = 0.430331482912 * g_K1 * ufl.sqrt(Ko) * (-E_K + V) * XK1_inf

        # Expressions for the i_f component
        i_f = g_f * (-E_f + V) * Xf

        # Expressions for the i_b Na component
        i_b_Na = g_b_Na * (-E_Na + V)

        # Expressions for the i_b Ca component
        i_b_Ca = g_b_Ca * (-E_Ca + V)

        # Expressions for the i_NaK component
        i_NaK = Ko*PNaK*Nai/((Km_K + Ko)*(Km_Na + Nai)*(1 +\
            0.0353*ufl.exp(-F*V/(R*T)) + 0.1245*ufl.exp(-0.1*F*V/(R*T))))

        # Expressions for the i_NaCa component
        i_NaCa = kNaCa*(Cao*(Nai*Nai*Nai)*ufl.exp(F*gamma*V/(R*T)) -\
            alpha*(Nao*Nao*Nao)*Cai*ufl.exp(F*(-1 + gamma)*V/(R*T)))/((1 +\
            Ksat*ufl.exp(F*(-1 + gamma)*V/(R*T)))*(Cao +\
            KmCa)*((KmNai*KmNai*KmNai) + (Nao*Nao*Nao)))

        # Expressions for the i_PCa component
        i_PCa = g_PCa * Cai / (KPCa + Cai)

        # Expressions for the i_to component
        i_to = g_to * (-E_K + V) * q * r

        # Expressions for the Membrane component
        current[0] = -i_CaL - i_K1 - i_Kr - i_Ks - i_Na - i_NaCa - i_NaK -\
            i_PCa - i_b_Ca - i_b_Na - i_f - i_to

        # Return results
        return current[0]
示例#6
0
    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) == 17)
        m, h, j, d, f1, f2, fCa, Xr1, Xr2, Xs, Xf, q, r, Nai, g, Cai, Ca_SR = s

        # Assign parameters
        TTX_10uM = self._parameters["TTX_10uM"]
        TTX_30uM = self._parameters["TTX_30uM"]
        TTX_3uM = self._parameters["TTX_3uM"]
        nifed_100nM = self._parameters["nifed_100nM"]
        nifed_10nM = self._parameters["nifed_10nM"]
        nifed_30nM = self._parameters["nifed_30nM"]
        nifed_3nM = self._parameters["nifed_3nM"]
        g_Na = self._parameters["g_Na"]
        g_CaL = self._parameters["g_CaL"]
        tau_fCa = self._parameters["tau_fCa"]
        L0 = self._parameters["L0"]
        Q = self._parameters["Q"]
        g_b_Na = self._parameters["g_b_Na"]
        g_b_Ca = self._parameters["g_b_Ca"]
        Km_K = self._parameters["Km_K"]
        Km_Na = self._parameters["Km_Na"]
        PNaK = self._parameters["PNaK"]
        KmCa = self._parameters["KmCa"]
        KmNai = self._parameters["KmNai"]
        Ksat = self._parameters["Ksat"]
        alpha = self._parameters["alpha"]
        gamma = self._parameters["gamma"]
        kNaCa = self._parameters["kNaCa"]
        KPCa = self._parameters["KPCa"]
        g_PCa = self._parameters["g_PCa"]
        Cao = self._parameters["Cao"]
        Cm = self._parameters["Cm"]
        F = self._parameters["F"]
        Ko = self._parameters["Ko"]
        Nao = self._parameters["Nao"]
        R = self._parameters["R"]
        T = self._parameters["T"]
        V_SR = self._parameters["V_SR"]
        Vc = self._parameters["Vc"]
        Buf_C = self._parameters["Buf_C"]
        Buf_SR = self._parameters["Buf_SR"]
        Kbuf_C = self._parameters["Kbuf_C"]
        Kbuf_SR = self._parameters["Kbuf_SR"]
        Kup = self._parameters["Kup"]
        V_leak = self._parameters["V_leak"]
        VmaxUp = self._parameters["VmaxUp"]
        a_rel = self._parameters["a_rel"]
        b_rel = self._parameters["b_rel"]
        c_rel = self._parameters["c_rel"]
        tau_g = self._parameters["tau_g"]

        # Init return args
        F_expressions = [ufl.zero()] * 17

        # Expressions for the Electric potentials component
        E_Na = R * T * ufl.ln(Nao / Nai) / F
        E_Ca = 0.5 * R * T * ufl.ln(Cao / Cai) / F

        # Expressions for the i_Na component
        TTX_coeff = ufl.conditional(ufl.eq(TTX_3uM, 1), 0.18,\
            ufl.conditional(ufl.eq(TTX_10uM, 1), 0.06,\
            ufl.conditional(ufl.eq(TTX_30uM, 1), 0.02, 1)))
        i_Na = g_Na * (m * m * m) * (-E_Na + V) * TTX_coeff * h * j

        # Expressions for the m gate component
        m_inf = 1.0*ufl.elem_pow(1 +\
            0.00308976260789*ufl.exp(-169.491525424*V), -0.333333333333)
        alpha_m = 1.0 / (1 + 6.14421235333e-06 * ufl.exp(-200.0 * V))
        beta_m = 0.1/(1 + 1096.63315843*ufl.exp(200.0*V)) + 0.1/(1 +\
            0.778800783071*ufl.exp(5.0*V))
        tau_m = 0.001 * alpha_m * beta_m
        F_expressions[0] = (-m + m_inf) / tau_m

        # Expressions for the h gate component
        h_inf = 1.0 / ufl.sqrt(1 + 311490.091283 * ufl.exp(175.438596491 * V))
        alpha_h = ufl.conditional(ufl.lt(V, -0.04),\
            4.43126792958e-07*ufl.exp(-147.058823529*V), 0)
        beta_h = ufl.conditional(ufl.lt(V, -0.04), 310000.0*ufl.exp(348.5*V)\
            + 2.7*ufl.exp(79.0*V), 0.77/(0.13 +\
            0.0497581410839*ufl.exp(-90.0900900901*V)))
        tau_h = ufl.conditional(ufl.lt(V, -0.04), 1.5/(1000*alpha_h +\
            1000*beta_h), 0.002542)
        F_expressions[1] = (-h + h_inf) / tau_h

        # Expressions for the j gate component
        j_inf = 1.0 / ufl.sqrt(1 + 311490.091283 * ufl.exp(175.438596491 * V))
        alpha_j = ufl.conditional(ufl.lt(V, -0.04), (37.78 +\
            1000*V)*(-25428*ufl.exp(244.4*V) -\
            6.948e-06*ufl.exp(-43.91*V))/(1 +\
            50262745826.0*ufl.exp(311.0*V)), 0)
        beta_j = ufl.conditional(ufl.lt(V, -0.04),\
            0.02424*ufl.exp(-10.52*V)/(1 +\
            0.0039608683399*ufl.exp(-137.8*V)), 0.6*ufl.exp(57.0*V)/(1 +\
            0.0407622039784*ufl.exp(-100.0*V)))
        tau_j = 7.0 / (1000 * alpha_j + 1000 * beta_j)
        F_expressions[2] = (-j + j_inf) / tau_j

        # Expressions for the i_CaL component
        nifed_coeff = ufl.conditional(ufl.eq(nifed_3nM, 1), 0.93,\
            ufl.conditional(ufl.eq(nifed_10nM, 1), 0.79,\
            ufl.conditional(ufl.eq(nifed_30nM, 1), 0.56,\
            ufl.conditional(ufl.eq(nifed_100nM, 1), 0.28, 1))))
        i_CaL = 4*g_CaL*(F*F)*(-0.341*Cao +\
            Cai*ufl.exp(2*F*V/(R*T)))*V*d*f1*f2*fCa*nifed_coeff/(R*T*(-1 +\
            ufl.exp(2*F*V/(R*T))))

        # Expressions for the d gate component
        d_infinity = 1.0 / (1 + 0.272531793034 * ufl.exp(-1000 * V / 7))
        alpha_d = 0.25 + 1.4 / (1 + ufl.exp(-35 / 13 - 1000 * V / 13))
        beta_d = 1.4 / (1 + ufl.exp(1 + 200 * V))
        gamma_d = 1.0 / (1 + ufl.exp(5 / 2 - 50 * V))
        tau_d = 0.001 * gamma_d + 0.001 * alpha_d * beta_d
        F_expressions[3] = (-d + d_infinity) / tau_d

        # Expressions for the F1 gate component
        f1_inf = 1.0 / (1 + ufl.exp(26 / 3 + 1000 * V / 3))
        constf1 = ufl.conditional(ufl.gt(-f1 + f1_inf, 0), 0.92835 +\
            1433*Cai, 1)
        tau_f1 = 0.001*(20 + 200.0/(1 + ufl.exp(13/10 - 100*V)) + 180.0/(1 +\
            ufl.exp(3 + 100*V)) +\
            1102.5*ufl.exp(-0.00444444444444*ufl.elem_pow(27 + 1000*V,\
            4)))*constf1
        F_expressions[4] = (-f1 + f1_inf) / tau_f1

        # Expressions for the F2 gate component
        f2_inf = 0.33 + 0.67 / (1 + ufl.exp(35 / 4 + 250 * V))
        constf2 = 1
        tau_f2 = 0.001*constf2*(600*ufl.exp(-((25 + 1000*V)*(25 +\
            1000*V))/170) + 16.0/(1 + ufl.exp(3 + 100*V)) + 31.0/(1 +\
            ufl.exp(5/2 - 100*V)))
        F_expressions[5] = (-f2 + f2_inf) / tau_f2

        # Expressions for the FCa gate component
        alpha_fCa = 1.0 / (1 + 5.95374180765e+25 * ufl.elem_pow(Cai, 8))
        beta_fCa = 0.1 / (1 + 0.000123409804087 * ufl.exp(10000.0 * Cai))
        gamma_fCa = 0.3 / (1 + 0.391605626677 * ufl.exp(1250.0 * Cai))
        fCa_inf = 0.760109455762*alpha_fCa + 0.760109455762*beta_fCa +\
            0.760109455762*gamma_fCa
        constfCa = ufl.conditional(ufl.And(ufl.gt(V, -0.06), ufl.gt(fCa_inf,\
            fCa)), 0, 1)
        F_expressions[6] = (-fCa + fCa_inf) * constfCa / tau_fCa

        # Expressions for the Xr1 gate component
        V_half = -19.0 - 1000*R*T*ufl.ln(ufl.elem_pow(1 + 0.384615384615*Cao,\
            4)/(L0*ufl.elem_pow(1 + 1.72413793103*Cao, 4)))/(F*Q)
        Xr1_inf = 1.0 / (1 +
                         ufl.exp(0.204081632653 * V_half - 204.081632653 * V))
        alpha_Xr1 = 450.0 / (1 + ufl.exp(-9 / 2 - 100 * V))
        beta_Xr1 = 6.0 / (1 + 13.5813245226 * ufl.exp(86.9565217391 * V))
        tau_Xr1 = 0.001 * alpha_Xr1 * beta_Xr1
        F_expressions[7] = (-Xr1 + Xr1_inf) / tau_Xr1

        # Expressions for the Xr2 gate component
        Xr2_infinity = 1.0 / (1 + ufl.exp(44 / 25 + 20 * V))
        alpha_Xr2 = 3.0 / (1 + ufl.exp(-3 - 50 * V))
        beta_Xr2 = 1.12 / (1 + ufl.exp(-3 + 50 * V))
        tau_Xr2 = 0.001 * alpha_Xr2 * beta_Xr2
        F_expressions[8] = (-Xr2 + Xr2_infinity) / tau_Xr2

        # Expressions for the Xs gate component
        Xs_infinity = 1.0 / (1 + ufl.exp(-5 / 4 - 125 * V / 2))
        alpha_Xs = 1100.0 / ufl.sqrt(1 + ufl.exp(-5 / 3 - 500 * V / 3))
        beta_Xs = 1.0 / (1 + ufl.exp(-3 + 50 * V))
        tau_Xs = alpha_Xs * beta_Xs / 1000
        F_expressions[9] = (-Xs + Xs_infinity) / tau_Xs

        # Expressions for the Xf gate component
        Xf_infinity = 1.0 / (1 + 5780495.71031 * ufl.exp(200 * V))
        tau_Xf = 1.9 / (1 + ufl.exp(3 / 2 + 100 * V))
        F_expressions[10] = (-Xf + Xf_infinity) / tau_Xf

        # Expressions for the i_b Na component
        i_b_Na = g_b_Na * (-E_Na + V)

        # Expressions for the i_b Ca component
        i_b_Ca = g_b_Ca * (-E_Ca + V)

        # Expressions for the i_NaK component
        i_NaK = Ko*PNaK*Nai/((Km_K + Ko)*(Km_Na + Nai)*(1 +\
            0.0353*ufl.exp(-F*V/(R*T)) + 0.1245*ufl.exp(-0.1*F*V/(R*T))))

        # Expressions for the i_NaCa component
        i_NaCa = kNaCa*(Cao*(Nai*Nai*Nai)*ufl.exp(F*gamma*V/(R*T)) -\
            alpha*(Nao*Nao*Nao)*Cai*ufl.exp(F*(-1 + gamma)*V/(R*T)))/((1 +\
            Ksat*ufl.exp(F*(-1 + gamma)*V/(R*T)))*(Cao +\
            KmCa)*((KmNai*KmNai*KmNai) + (Nao*Nao*Nao)))

        # Expressions for the i_PCa component
        i_PCa = g_PCa * Cai / (KPCa + Cai)

        # Expressions for the q gate component
        q_inf = 1.0 / (1 + ufl.exp(53 / 13 + 1000 * V / 13))
        tau_q = 0.00606 + 0.039102/(0.0168716780457*ufl.exp(-80.0*V) +\
            6.42137321286*ufl.exp(100.0*V))
        F_expressions[11] = (-q + q_inf) / tau_q

        # Expressions for the r gate component
        r_inf = 1.0 / (1 + 3.28489055021 * ufl.exp(-53.3333333333 * V))
        tau_r = 0.00275352 + 0.01440516/(16.3010892258*ufl.exp(90.0*V) +\
            0.0211152735604*ufl.exp(-120.0*V))
        F_expressions[12] = (-r + r_inf) / tau_r

        # Expressions for the Sodium dynamics component
        F_expressions[13] = -1e+18*Cm*(3*i_NaCa + 3*i_NaK + i_Na +\
            i_b_Na)/(F*Vc)

        # Expressions for the Calcium dynamics component
        i_rel = 0.0411*(c_rel + a_rel*(Ca_SR*Ca_SR)/((b_rel*b_rel) +\
            (Ca_SR*Ca_SR)))*d*g
        i_up = VmaxUp / (1 + (Kup * Kup) / (Cai * Cai))
        i_leak = V_leak * (-Cai + Ca_SR)
        g_inf = ufl.conditional(ufl.le(Cai, 0.00035), 1.0/(1 +\
            5.43991024148e+20*ufl.elem_pow(Cai, 6)), 1.0/(1 +\
            1.9720198874e+55*ufl.elem_pow(Cai, 16)))
        const2 = ufl.conditional(ufl.And(ufl.gt(V, -0.06), ufl.gt(g_inf, g)),\
            0, 1)
        F_expressions[14] = (-g + g_inf) * const2 / tau_g
        Cai_bufc = 1.0 / (1 + Buf_C * Kbuf_C / ((Kbuf_C + Cai) *
                                                (Kbuf_C + Cai)))
        Ca_SR_bufSR = 1.0/(1 + Buf_SR*Kbuf_SR/((Kbuf_SR + Ca_SR)*(Kbuf_SR +\
            Ca_SR)))
        F_expressions[15] = (-i_up - 5e+17*Cm*(-2*i_NaCa + i_CaL + i_PCa +\
            i_b_Ca)/(F*Vc) + i_leak + i_rel)*Cai_bufc
        F_expressions[16] = Vc * (-i_leak - i_rel + i_up) * Ca_SR_bufSR / V_SR

        # Return results
        return dolfin.as_vector(F_expressions)
示例#7
0
    def _I(self, v, s, time):
        """
        Original gotran transmembrane current dV/dt
        """
        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"]
        GNa = self._parameters["GNa"]
        GNaB = self._parameters["GNaB"]
        IbarNaK = self._parameters["IbarNaK"]
        KmKo = self._parameters["KmKo"]
        KmNaip = self._parameters["KmNaip"]
        gkp = self._parameters["gkp"]
        pNaK = self._parameters["pNaK"]
        epi = self._parameters["epi"]
        GClB = self._parameters["GClB"]
        GClCa = self._parameters["GClCa"]
        KdClCa = self._parameters["KdClCa"]
        Q10CaL = self._parameters["Q10CaL"]
        pCa = self._parameters["pCa"]
        pK = self._parameters["pK"]
        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"]
        Nao = self._parameters["Nao"]
        Ko = self._parameters["Ko"]
        Cao = self._parameters["Cao"]
        Cli = self._parameters["Cli"]
        Clo = self._parameters["Clo"]
        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
        current = [ufl.zero()] * 1

        # Expressions for the Geometry component
        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
        ek = ufl.ln(Ko / K_i) / FoRT
        eca_junc = ufl.ln(Cao / Ca_j) / (2 * FoRT)
        eca_sl = ufl.ln(Cao / Ca_sl) / (2 * FoRT)
        ecl = ufl.ln(Cli / Clo) / FoRT
        Qpow = -31 + Temp / 10

        # Expressions for the I_Na component
        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))
        I_nak = I_nak_junc + I_nak_sl

        # Expressions for the I_Kr component
        gkr = g_Kr_factor * 0.0150616019019 * ufl.sqrt(Ko)
        rkr = 1.0 / (1 + ufl.exp(37 / 12 + V_m / 24))
        I_kr = (-ek + V_m) * gkr * rkr * x_kr

        # Expressions for the I_Kp component
        kp_kp = 1.0 / (1 + 1786.47556538 * ufl.exp(-0.167224080268 * V_m))
        I_kp_junc = Fjunc * gkp * (-ek + V_m) * kp_kp
        I_kp_sl = gkp * (-ek + V_m) * Fsl * kp_kp
        I_kp = I_kp_sl + I_kp_junc

        # Expressions for the I_Ks component
        eks = ufl.ln((Nao * pNaK + Ko) / (pNaK * Na_i + K_i)) / FoRT
        gks_junc = g_Ks_factor * 0.0035
        gks_sl = g_Ks_factor * 0.0035
        I_ks_junc = Fjunc * gks_junc * (x_ks * x_ks) * (-eks + V_m)
        I_ks_sl = gks_sl * (x_ks * x_ks) * (-eks + V_m) * Fsl
        I_ks = I_ks_sl + I_ks_junc

        # Expressions for the I_to component
        GtoSlow = ufl.conditional(ufl.eq(epi, 1), 0.0156, 0.037596)
        GtoFast = ufl.conditional(ufl.eq(epi, 1), 0.1144, 0.001404)
        I_tos = (-ek + V_m) * GtoSlow * x_to_s * y_to_s
        I_tof = (-ek + V_m) * g_to_factor * GtoFast * x_to_f * y_to_f
        I_to = I_tos + I_tof

        # Expressions for the I_Ki component
        aki = 1.02 / (1 +
                      7.35454251046e-07 * ufl.exp(0.2385 * V_m - 0.2385 * ek))
        bki = (0.762624006506*ufl.exp(0.08032*V_m - 0.08032*ek) +\
            1.15340563519e-16*ufl.exp(0.06175*V_m - 0.06175*ek))/(1 +\
            0.0867722941577*ufl.exp(-0.5143*V_m + 0.5143*ek))
        kiss = aki / (aki + bki)
        I_ki = g_K1_factor * 0.150616019019 * ufl.sqrt(Ko) * (-ek + V_m) * kiss

        # Expressions for the I_ClCa component
        I_ClCa_junc = Fjunc * GClCa * (-ecl + V_m) / (1 + KdClCa / Ca_j)
        I_ClCa_sl = GClCa * (-ecl + V_m) * Fsl / (1 + KdClCa / Ca_sl)
        I_ClCa = I_ClCa_sl + I_ClCa_junc
        I_Clbk = GClB * (-ecl + V_m)

        # Expressions for the I_Ca component
        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))
        ibark = Frdy*pK*(-0.75*Ko + 0.75*K_i*ufl.exp(FoRT*V_m))*FoRT*V_m/(-1 +\
            ufl.exp(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_CaK = g_CaL_factor*0.45*ufl.elem_pow(Q10CaL, Qpow)*(Fjunc_CaL*(1 - f_Ca_Bj +\
            fcaCaj) + (1 - f_Ca_Bsl + fcaCaMSL)*Fsl_CaL)*d*f*ibark
        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 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

        # Expressions for the K Concentration component
        I_K_tot = -2 * I_nak + I_ks + I_CaK + I_kr + I_kp + I_ki + I_to

        # 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

        # Expressions for the Membrane potential component
        i_Stim = 0
        I_Na_tot = I_Na_tot_junc + I_Na_tot_sl
        I_Cl_tot = I_Clbk + I_ClCa
        I_Ca_tot = I_Ca_tot_junc + I_Ca_tot_sl
        I_tot = I_Na_tot + I_K_tot + I_Cl_tot + I_Ca_tot
        current[0] = -I_tot - i_Stim

        # Return results
        return current[0]
示例#8
0
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"