Exemple #1
0
def test_failures():
    with pytest.raises(rtd.RTDInputError):
        rtd.Pfr(tau=-1, dt=DT, time_end=TIME_END)
    with pytest.raises(rtd.RTDInputError):
        rtd.Pfr(tau=1, dt=-1, time_end=TIME_END)
    with pytest.raises(rtd.RTDInputError):
        rtd.Pfr(tau=1, dt=DT, time_end=-1)
Exemple #2
0
def test_iteration():
    a = rtd.Ncstr(n=1, tau=1, dt=DT, time_end=TIME_END)
    b = rtd.Pfr(tau=1, dt=DT, time_end=TIME_END)
    c = rtd.Elist([a, b])
    elist = [c, b, a]
    d = rtd.Elist(elist)
    for i, j in zip(elist, d):
        assert i == j
Exemple #3
0
def test_listoflist():
    n = 1
    tau_cstr = 10
    tau_pfr = 1
    a = rtd.Ncstr(n=n, tau=tau_cstr, dt=DT, time_end=TIME_END)
    b = rtd.Pfr(tau=tau_pfr, dt=DT, time_end=TIME_END)
    c = rtd.Elist([a, b])
    d = rtd.Elist([c, c])
    assert len(d.time) == len(d.exitage)
    assert (np.isclose(d.integral(), 1, rtol=rtol, atol=atol))
    assert (np.isclose(d.mrt(), 22, rtol=rtol, atol=atol))
    assert (np.isclose(d.sigma(), 200, rtol=rtol, atol=atol))
Exemple #4
0
def test_step_output():
    # test that a CSTR convolved with a step input signal
    # is the same as a CSTR+PFR stepresponse
    a = rtdpy.Ncstr(n=1, tau=10, dt=DT, time_end=TIME_END)
    b = rtdpy.Pfr(tau=10, dt=DT, time_end=TIME_END)
    c = rtdpy.Elist([a, b])

    inputtime = a.time
    inputsignal = np.zeros(inputtime.size)
    inputsignal[inputtime > 10] = 1

    outputsignal = a.output(inputtime, inputsignal)[:inputtime.size]

    assert np.allclose(outputsignal, c.stepresponse, rtol=rtol, atol=atol)
Exemple #5
0
def test1(tau_cstr, tau_pfr):
    n = 1
    a = rtd.Ncstr(n=n, tau=tau_cstr, dt=DT, time_end=TIME_END)
    b = rtd.Pfr(tau=tau_pfr, dt=DT, time_end=TIME_END)
    c = rtd.Elist([a, b])
    assert len(c.time) == len(c.exitage)
    assert (np.isclose(c.integral(), 1, rtol=rtol, atol=atol))
    assert (np.isclose(c.mrt(),
                       analytical_mrt(tau_cstr=tau_cstr, tau_pfr=tau_pfr),
                       rtol=rtol,
                       atol=atol))
    assert (np.isclose(c.sigma(),
                       analytical_sigma(n=n, tau_cstr=tau_cstr),
                       rtol=rtol,
                       atol=atol))
Exemple #6
0
def test_endtau():
    with pytest.raises(rtd.RTDInputError):
        rtd.Pfr(200, dt=DT, time_end=TIME_END)
Exemple #7
0
def test1(tau):
    a = rtd.Pfr(tau=tau, dt=DT, time_end=TIME_END)
    assert (np.isclose(a.integral(), 1, rtol=rtol, atol=atol))
    assert (np.isclose(a.mrt(), analytical_mrt(tau), rtol=rtol, atol=atol))
    assert (np.isclose(a.sigma(), analytical_sigma(), rtol=rtol, atol=atol))
Exemple #8
0
import matplotlib.pyplot as plt
import rtdpy
a = rtdpy.Ncstr(tau=1, n=1, dt=.01, time_end=15)
b = rtdpy.Pfr(tau=10, dt=.01, time_end=15)
c = rtdpy.Elist([a, b])
plt.plot(a.time, a.exitage, label="CSTR")
plt.plot(b.time, b.exitage, label="PFR")
plt.ylim(0, 1.1)
plt.title('Original RTD models')
plt.xlabel('Time')
plt.ylabel('Exit Age Function')
plt.legend()
plt.figure()
plt.plot(c.time, c.exitage)
plt.xlabel('Time')
plt.ylabel('Exit Age Function')
plt.title('Combination of models')
plt.show()
Exemple #9
0
def test_repr():
    a = rtd.Pfr(tau=10, dt=DT, time_end=TIME_END)
    b = eval("rtd." + repr(a))
    assert np.isclose(a.integral(), b.integral(), rtol=rtol, atol=atol)
    assert np.isclose(a.mrt(), b.mrt(), rtol=rtol, atol=atol)
    assert np.isclose(a.sigma(), b.sigma(), rtol=rtol, atol=atol)