예제 #1
0
def test_plot_C_vs_t_in_bin():
    N = 3
    rd = _get_decay_rd(N)
    tout = np.linspace(0, 3.0, 7)
    y0 = [3.0, 1.0] * N
    integr = run(rd, y0, tout)
    ax = plot_C_vs_t_in_bin(rd, tout, integr.yout, 0)
    assert isinstance(ax, matplotlib.axes.Axes)
예제 #2
0
def integrate_rd(tend=1.0, k1=7e-1, k2=3e2, k3=7.0,
                 A0=1.0, B0=0.0, C0=0.0, nt=512,
                 plot=False, savefig='None'):
    """
    Runs integration and (optionally) generates plots.


    Examples
    --------
    ::

       $ python steady_state_approx.py --plot --savefig steady_state_approx.png


    .. image:: ../_generated/steady_state_approx.png


    ::

       $ python steady_state_approx.py --plot --savefig \
steady_state_approx.html


    :download:`steady_state_approx.html\
        <../_generated/steady_state_approx.html>`

    """
    def f(t):
        return A0/(k3/k2*A0 + 1)*np.exp(-k1*t)

    y = [A0, B0, C0]
    k = [k1, k2, k3]
    rd = ReactionDiffusion(
        3, [[0], [1], [0, 1]], [[1], [2], [1, 2]], k)
    t = np.linspace(0, tend, nt)
    integr = run(rd, y, t)
    A_ssB = 1/(1/f(t) - k3/k2)
    A_ssB_2fast = f(t)

    if plot:
        import matplotlib.pyplot as plt
        plt.figure(figsize=(6, 10))

        ax = plt.subplot(3, 1, 1)
        plot_C_vs_t_in_bin(rd, t, integr.Cout, ax=ax)
        plt.subplot(3, 1, 2)
        plt.plot(t, integr.Cout[:, 0, 0] - A_ssB,
                 label="Abs. err. in A assuming steady state of B")
        plt.legend(loc='best', prop={'size': 11})
        plt.subplot(3, 1, 3)
        plt.plot(t, integr.Cout[:, 0, 0] - A_ssB_2fast,
                 label="Abs. err. in A when also assuming k2 >> k3")
        plt.legend(loc='best', prop={'size': 11})
        plt.tight_layout()

        save_and_or_show_plot(savefig=savefig)

    def ydot(x, y):
        return (-k1*y[0] - k3*y[0]*y[1], k1*y[0] - k2*y[1],
                k2*y[1] + k3*y[0]*y[1])
    return t, integr.Cout, A_ssB, A_ssB_2fast, ydot