Exemplo n.º 1
0
def test_subtract_mean_of_sinkx_plus_constant_equals_sinkx():
    L = 2.0
    N = 128
    st = ScalarTool(N, L)
    sinkx = np.sin((2 * np.pi / L) * st.X[0])
    th = sinkx + 10.0
    assert np.allclose(st.subtract_mean(th), sinkx)
Exemplo n.º 2
0
def test_st_ifft_of_function_is_real():
    L = 10.5
    N = 128
    k = 2.0 * np.pi / L
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(k * X[0])
    st = ScalarTool(N, L)
    assert np.all(np.isreal(st.ifft(st.fft(th))))
Exemplo n.º 3
0
def test_integral_of_sinkx():
    L = 10.5
    N = 128
    k = 2.0 * np.pi / L
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(k * X[0])
    st = ScalarTool(N, L)
    assert np.isclose(st.sint(th), 0.0)
Exemplo n.º 4
0
def test_h1norm_of_sinkx_is_sqrt_of_half_of_Lsq_multiplied_by_k():
    L = 2.0 * np.pi
    N = 128
    k = 10.0 * np.pi / L
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(k * X[0])
    st = ScalarTool(N, L)
    assert math.isclose(st.h1norm(th), (0.5 * L**2)**0.5 * k)
Exemplo n.º 5
0
def test_that_l2norm_of_sinx_on_domain_with_L_of_2pi_equals_sqrt_of_half_of_Lsq(
):
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(2.0 * np.pi * X[0] / L)
    assert math.isclose(st.l2norm(th), (0.5 * L**2)**0.5)
Exemplo n.º 6
0
def test_lap_invlap_of_th_is_th_minus_mean_value():
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)

    th = np.random.random((N, N))

    assert np.allclose(st.lap(st.invlap(th)), st.subtract_mean(th))
Exemplo n.º 7
0
def test_ifft_of_fft_equals_original_scalar_function():
    L = 10.5
    N = 128
    k = 2.0 * np.pi / L
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(k * X[0])
    st = ScalarTool(N, L)
    assert np.allclose(st.ifft(st.fft(th)), th)
Exemplo n.º 8
0
def test_get_spectrum_includes_Nyquist_mode():
    L = 10.5
    N = 128
    k = int(N / 2) * 2.0 * np.pi / L
    st = ScalarTool(N, L)
    th = np.cos(k * st.X[0])  # SIN(K X)
    [klist, spectrum] = st.get_spectrum(th)
    spectrum_expected = np.zeros(len(klist))
    spectrum_expected[int(N / 2)] = 2.0
    assert np.allclose(spectrum, spectrum_expected)
Exemplo n.º 9
0
def test_l2norm_of_a_scalar_should_be_nearly_invariant_of_discretization():
    L = 10.0
    Narray = np.array([64, 128, 256, 512]).astype('int')
    l2norm = np.zeros(len(Narray))
    for i, N in enumerate(Narray):
        st = ScalarTool(N, L)
        X = np.mgrid[:N, :N].astype(float) * (L / N)
        th = np.sin(2.0 * np.pi * X[0] / L)
        l2norm[i] = st.l2norm(th)
    assert np.allclose(l2norm[-1], l2norm)
Exemplo n.º 10
0
def test_get_spectrum_of_sinkx():
    L = 10.5
    N = 128
    k = int(N / 4) * 2.0 * np.pi / L
    st = ScalarTool(N, L)
    th = np.sin(k * st.X[0])  # SIN(K X)
    [klist, spectrum] = st.get_spectrum(th)
    spectrum_expected = np.zeros(len(klist))
    spectrum_expected[int(N / 4)] = 1.0
    assert np.allclose(spectrum, spectrum_expected)
Exemplo n.º 11
0
def test_dealias_of_sinkx_where_k_is_above_two_thirds_dealias_boundary_is_zero_y_direction(
):
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)

    kabove = np.ceil(st.kmax_dealias) + 1
    th = np.sin(2. * np.pi / L * kabove * st.X[1])
    z = np.zeros(th.shape)

    assert np.allclose(st.dealias(th), z)
Exemplo n.º 12
0
def test_dealias_of_sinkx_where_k_is_below_two_thirds_dealias_boundary_is_zero_y_direction(
):
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)

    k = np.floor(st.kmax_dealias) - 1
    th = np.sin(2. * np.pi / L * k * st.X[1])
    z = np.zeros(th.shape)

    assert not np.allclose(st.dealias(th), z)
Exemplo n.º 13
0
def test_laplacian_of_sinkx_is_neq_ksq_times_sinkx():
    L = 10.5
    N = 128
    k = 2.0 * np.pi / L
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(k * X[0])

    st = ScalarTool(N, L)
    lapth = st.lap(th)

    assert np.allclose(lapth, -k**2 * np.sin(k * X[0]))
Exemplo n.º 14
0
def test_yderivative_of_sinky_is_kcosky():
    L = 10.5
    N = 128
    k = 2.0 * np.pi / L
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(k * X[1])

    st = ScalarTool(N, L)
    gradth = st.grad(th)

    assert np.allclose(gradth[1], k * np.cos(k * X[1]))
Exemplo n.º 15
0
def test_curl_is_equal_to_curl_computed_with_grad_function():
    N = 128
    L = 2.0
    kappa = 0.0
    gamma = 1.0
    v = np.random.random((2, N, N))
    # print(np.shape(v))
    st = ScalarTool(N, L)
    vt = VectorTool(N, L)
    v = vt.div_free_proj(v)
    v = vt.dealias(v)
    c = st.grad(v[1])[0] - st.grad(v[0])[1]
    assert np.allclose(c, vt.curl(v))
Exemplo n.º 16
0
def test_that_sinx_on_domain_with_L_of_2pi_has_equal_norms():
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)
    X = np.mgrid[:N, :N].astype(float) * (L / N)
    th = np.sin(2.0 * np.pi * X[0] / L)
    l2norm = st.l2norm(th)
    h1norm = st.h1norm(th)
    hm1norm = st.hm1norm(th)
    print(l2norm)
    print(h1norm)
    print(hm1norm)
    assert (math.isclose(l2norm, h1norm) and math.isclose(l2norm, hm1norm))
Exemplo n.º 17
0
def test_h1normsq_of_vector_is_spatial_integral_neg_lapvec_times_vec():
    N = 128
    L = 2.0
    kappa = 0.0
    gamma = 1.0
    v = np.random.random((2, N, N))
    st = ScalarTool(N, L)
    vt = VectorTool(N, L)
    v = vt.div_free_proj(v)
    v = vt.dealias(v)

    a = vt.h1norm(v)**2
    b = st.sint(np.sum(-vt.lap(v) * v, 0))
    assert np.allclose(a, b)
Exemplo n.º 18
0
def test_l2norm_squared_of_curl_of_vector_is_spatial_integral_of_neg_vector_times_lap_vector(
):
    N = 128
    L = 2.0
    kappa = 0.0
    gamma = 1.0
    v = np.random.random((2, N, N))
    # print(np.shape(v))
    st = ScalarTool(N, L)
    vt = VectorTool(N, L)
    v = vt.div_free_proj(v)
    v = vt.dealias(v)
    curl = vt.curl(v)
    a = st.l2norm(curl)**2.
    b = st.sint(np.sum(-vt.lap(v) * v, 0))
    assert np.allclose(a, b)
Exemplo n.º 19
0
def test_validate_div_free_projector():
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)
    vt = VectorTool(N, L)
    u = np.zeros((2, N, N))
    # Compressible flow
    u[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \
        np.sin((2.0 * np.pi / L) * vt.X[1])
    u[1] = -np.cos((2.0 * np.pi / L) * vt.X[0]) * \
        np.cos((2.0 * np.pi / L) * vt.X[1])

    w = np.zeros((2, N, N))

    w[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \
        np.sin((2.0 * np.pi / L) * vt.X[1])
    w[1] = np.cos((2.0 * np.pi / L) * vt.X[0]) * \
        np.cos((2.0 * np.pi / L) * vt.X[1])

    u = u + 0.1 * w

    projection_alt = u - st.grad_invlap(vt.div(u))
    print(np.amax(abs(projection_alt - vt.div_free_proj(u))))
    assert np.allclose(projection_alt, vt.div_free_proj(u))
Exemplo n.º 20
0
def test_spatial_integral_of_neg_invlap_th_time_th_equals_hm1_norm_sq():
    L = 2.0 * np.pi
    N = 128
    st = ScalarTool(N, L)

    th = np.random.random((N, N))
    th = st.dealias(th)
    a = st.sint(-1.0 * st.invlap(th) * th)
    b = st.hm1norm(th)**2.
    print(a, b)
    assert np.allclose(a, b)
Exemplo n.º 21
0
def test_integral_of_one():
    L = 10.5
    N = 128
    integrand = np.ones((N, N))
    st = ScalarTool(N, L)
    assert np.isclose(st.sint(integrand), L**2.0)
Exemplo n.º 22
0
def test_check_no_spectral_blocking_positive_codition():
    N = 64
    L = 1.0
    st = ScalarTool(N, L)
    th = np.sin((N / 2 - 2) * (2. * np.pi / L) * st.X[0])
    assert st.isblocked(th)
Exemplo n.º 23
0
def test_check_no_spectral_blocking_negative_codition():
    N = 64
    L = 1.0
    st = ScalarTool(N, L)
    th = np.zeros((N, N))
    assert (not st.isblocked(th))