Esempio n. 1
0
def test_dc():
    n = 7
    k = [1]*(n-1)
    rd = ReactionDiffusion(n, [[i] for i in range(n-1)],
                           [[i] for i in range(1, n)], k=k)
    fout = rd.alloc_fout()
    y0 = [0]*n
    y0[0] = 1
    y_ = [0] + y0
    y0 = np.asarray(y0, dtype=np.float64)
    rd.f(0, y0, fout)
    pos, neg = [0]+k, k+[0]
    _test_f(rd, 0, y0)
    fref = [pos[i]*y_[i] - neg[i]*y_[i+1] for i in range(n)]
    assert np.allclose(fref, fout)

    jout = rd.alloc_jout(order='C')
    rd.dense_jac_rmaj(0, y0, jout)
    jref = np.zeros_like(jout)
    for i in range(n):
        if i < n - 1:
            jref[i, i] = -k[i]
        if i > 0:
            jref[i, i-1] = k[i-1]
    assert np.allclose(jref, jout)
    _test_dense_jac_rmaj(rd, 0, y0)
def test_per_bin_diffusion():
    rd = ReactionDiffusion(1, [], [], [], N=5, D=[0, 0, 1, 0, 0])
    fout = rd.alloc_fout()
    y = [0, 1, 2, 1, 0]
    rd.f(0.0, np.asarray(y, dtype=np.float64), fout)
    assert np.all(fout[:2] == 0) and np.all(fout[-2:] == 0) and fout[2] < 0