Exemplo n.º 1
0
def test_Mult_CTD(SD):
    C = CTDmat(np.arange(N).astype(np.float))
    B = BTTmat(np.arange(N).astype(np.float), SD.quad)

    uk = np.random.randn((N)) + np.random.randn((N)) * 1j
    vk = np.random.randn((N)) + np.random.randn((N)) * 1j
    wk = np.random.randn((N)) + np.random.randn((N)) * 1j

    bv = np.zeros(N, dtype=np.complex)
    bw = np.zeros(N, dtype=np.complex)
    vk0 = np.zeros(N, dtype=np.complex)
    wk0 = np.zeros(N, dtype=np.complex)

    vk0 = SD.fst(vk, vk0)
    vk = SD.ifst(vk0, vk)
    vk0 = SD.fst(vk, vk0)
    wk0 = SD.fst(wk, wk0)
    wk = SD.ifst(wk0, wk)
    wk0 = SD.fst(wk, wk0)

    SFTc.Mult_CTD_1D(N, vk0, wk0, bv, bw)

    cv = C.matvec(vk0)
    cw = C.matvec(wk0)
    cv /= B.dd
    cw /= B.dd

    assert np.allclose(cv, bv)
    assert np.allclose(cw, bw)
Exemplo n.º 2
0
def test_CTDmat(SDST):
    SD, ST = SDST

    Cm = CTDmat(np.arange(N).astype(np.float))

    fj = np.random.randn(N)
    # project to ST
    f_hat = np.zeros(N)
    f_hat = SD.fst(fj, f_hat)
    fj = SD.ifst(f_hat, fj)

    # Check if ST.fcs(f') equals Cm*SD.fst(f)
    f_hat = SD.fst(fj, f_hat)
    cs = Cm.matvec(f_hat)
    df = np.zeros(N)
    df = SD.fastChebDerivative(fj, df)
    cs2 = np.zeros(N)
    cs2 = ST.fastChebScalar(df, cs2)

    # from IPython import embed; embed()
    assert np.allclose(cs, cs2)

    # Multidimensional version
    f_hat = f_hat.repeat(4 * 4).reshape((N, 4, 4)) + 1j * f_hat.repeat(4 * 4).reshape((N, 4, 4))
    df = df.repeat(4 * 4).reshape((N, 4, 4)) + 1j * df.repeat(4 * 4).reshape((N, 4, 4))
    cs = Cm.matvec(f_hat)
    cs2 = np.zeros((N, 4, 4), dtype=np.complex)
    cs2 = ST.fastChebScalar(df, cs2)

    assert np.allclose(cs, cs2)