Ejemplo n.º 1
0
def test_nodal_basis_1d():
    for num_nodes in range(2, 10):
        nodes = np.linspace(-1, 1, num=num_nodes)
        nodal_basis = basis.NodalBasis1D(nodes)
        utils.check_to_from_dict(nodal_basis, basis_factory)
        assert nodal_basis.num_basis_cpts == num_nodes
        check_matrices(nodal_basis)
        check_derivative_matrix(nodal_basis)
Ejemplo n.º 2
0
def test_identity():
    flux_function = flux_functions.Identity()
    utils.check_to_from_dict(flux_function, flux_functions)
    # should always give q back out
    for q in range(-10, 10):
        assert flux_function(q) == q
        for x in range(-10, 10):
            assert flux_function(q, x) == q
            for t in range(-10, 10):
                assert flux_function(q, x, t) == q
Ejemplo n.º 3
0
def test_zero():
    flux_function = flux_functions.Zero()
    utils.check_to_from_dict(flux_function, flux_functions)
    # should always give zero
    for q in range(-10, 10):
        assert flux_function(q) == 0.0
        for x in range(-10, 10):
            assert flux_function(q, x) == 0.0
            for t in range(-10, 10):
                assert flux_function(q, x, t) == 0.0
Ejemplo n.º 4
0
def test_variable_advection():
    wavespeed_function = functions.Sine(offset=2.0)
    flux_function = flux_functions.VariableAdvection(wavespeed_function)
    utils.check_to_from_dict(flux_function, flux_functions)
    q = 1.0
    x = 1.0
    # shouldn't depend on t
    assert flux_function(q, x, 0) == flux_function(q, x, 1.0)
    # t_derivative should be zero
    assert flux_function.t_derivative(q, x, 0.0) == 0.0
    # q_derivative should be wavespeed_function
    assert flux_function.q_derivative(q, x, 0.0) == wavespeed_function(x)
    # higher q_derivatives should be zero
    assert flux_function.q_derivative(q, x, 0.0, order=2) == 0.0
Ejemplo n.º 5
0
def test_linearized_about_q():
    original_flux_function = flux_functions.Polynomial(degree=3)
    q = xt_functions.AdvectingSine()
    xt_function = xt_functions.LinearizedAboutQ(original_flux_function, q)
    utils.check_to_from_dict(xt_function, xt_functions)

    x = 0.5
    t = 0.1
    assert xt_function(q(x, t), x, t) is not None
    assert xt_function(x, t) is not None
    assert xt_function(x, t) == xt_function(q(x, t), x, t)

    for x in range(10):
        for t in range(10):
            assert xt_function(x, t) == original_flux_function(q(x, t), x, t)
Ejemplo n.º 6
0
def test_exponential_function():
    g = x_functions.Sine()
    r = 1.0
    xt_function = xt_functions.ExponentialFunction(g, r)
    utils.check_to_from_dict(xt_function, xt_functions)
    # should be able to call with (x, t) and (q, x, t)
    q = 0.0
    x = 0.5
    t = 0.1
    assert xt_function(x, t) is not None
    assert xt_function(q, x, t) is not None
    assert xt_function(q, x, t) == xt_function(x, t)
    assert xt_function.q_derivative(q, x, t) is not None
    assert xt_function.x_derivative(q, x, t) is not None
    assert xt_function.x_derivative(x, t) is not None
    assert xt_function.x_derivative(x, t) == xt_function.x_derivative(q, x, t)
    assert xt_function.t_derivative(q, x, t) is not None
    assert xt_function.t_derivative(x, t) is not None
    assert xt_function.t_derivative(x, t) == xt_function.t_derivative(q, x, t)
Ejemplo n.º 7
0
def test_scalar_autonomous():
    f = functions.Exponential()
    flux_function = flux_functions.ScalarAutonomous(f)
    utils.check_to_from_dict(flux_function, flux_functions)
    q = 1.0
    x = 1.5
    t = 2.0
    # should be able to call with just q
    assert flux_function(q) is not None
    # should be able to call with two inputs
    assert flux_function(q, x) is not None
    # should be able to call with three inputs
    assert flux_function(q, x, t) is not None
    # shouldn't depend on x or t
    assert flux_function(q, x, t) == flux_function(q, x + 1.0, t)
    assert flux_function(q, x, t) == flux_function(q, x, t + 1.0)
    assert flux_function(q, x, t) == flux_function(q, x + 1.0, t + 1.0)

    # x and t derivatives should be zero
    assert flux_function.x_derivative(q, x, t) == 0.0
    assert flux_function.t_derivative(q, x, t) == 0.0
Ejemplo n.º 8
0
def test_advecting_function():
    xt_function = xt_functions.AdvectingSine()
    utils.check_to_from_dict(xt_function, xt_functions)
    # should be able to call with just x and t
    x = 0.0
    t = 0.0
    q = 1.0
    assert xt_function(x, t) is not None
    # should also be able to call with (q, x, t)
    assert xt_function(q, x, t) is not None
    assert xt_function(q, x, t) == xt_function(x, t)
    assert xt_function.q_derivative(q, x, t) is not None
    assert xt_function.x_derivative(q, x, t) is not None
    assert xt_function.x_derivative(x, t) is not None
    assert xt_function.x_derivative(x, t) == xt_function.x_derivative(q, x, t)
    assert xt_function.t_derivative(q, x, t) is not None
    assert xt_function.t_derivative(x, t) is not None
    assert xt_function.t_derivative(x, t) == xt_function.t_derivative(q, x, t)
    # should be traveling to the right at speed 1
    for x in range(-10, 10):
        for t in range(-10, 10):
            assert xt_function(x, t) == xt_function(x - 1, t - 1)
Ejemplo n.º 9
0
def check_x_function(x_function):
    q = 1.0
    x = 0.5
    t = 0.1

    # should be able to call as (q, x, t), (x, t) or (x)
    assert x_function(q, x, t) is not None
    assert x_function(x, t) is not None
    assert x_function(x) is not None

    # should give same value as long as x is same
    assert x_function(q, x, t) == x_function(x)
    assert x_function(x, t) == x_function(x)

    # should give 0.0 q_derivative and t_derivative
    assert x_function.q_derivative(q, x, t) == 0.0
    assert x_function.q_derivative(x, t) == 0.0
    assert x_function.q_derivative(x) == 0.0
    assert x_function.t_derivative(q, x, t) == 0.0
    assert x_function.t_derivative(x, t) == 0.0
    assert x_function.t_derivative(x) == 0.0

    # should be able to convert to dict and back again
    utils.check_to_from_dict(x_function, x_functions)
Ejemplo n.º 10
0
def test_gauss_lobatto_nodal_basis_1d():
    gl_nodal_basis = basis.GaussLobattoNodalBasis1D(1)
    utils.check_to_from_dict(gl_nodal_basis, basis_factory)
    assert gl_nodal_basis.num_basis_cpts == 1
    assert gl_nodal_basis.nodes[0] == 0.0
    check_matrices(gl_nodal_basis)
    check_derivative_matrix(gl_nodal_basis)

    gl_nodal_basis = basis.GaussLobattoNodalBasis1D(2)
    utils.check_to_from_dict(gl_nodal_basis, basis_factory)
    assert gl_nodal_basis.num_basis_cpts == 2
    assert gl_nodal_basis.nodes[0] == -1.0
    assert gl_nodal_basis.nodes[1] == 1.0
    check_matrices(gl_nodal_basis)
    check_derivative_matrix(gl_nodal_basis)

    for num_basis_cpts in range(3, 10):
        gl_nodal_basis = basis.GaussLobattoNodalBasis1D(num_basis_cpts)
        utils.check_to_from_dict(gl_nodal_basis, basis_factory)
        check_matrices(gl_nodal_basis)
        check_derivative_matrix(gl_nodal_basis)
Ejemplo n.º 11
0
def test_modal_basis_2d_triangle():
    for space_order in range(1, 6):
        modal_basis_2d_triangle = basis.ModalBasis2DTriangle(space_order)
        utils.check_to_from_dict(modal_basis_2d_triangle, basis_factory)
        check_matrices(modal_basis_2d_triangle)
Ejemplo n.º 12
0
def test_legendre_basis_2d_cartesian():
    for space_order in range(1, 10):
        legendre_basis_2d_cartesian = basis.LegendreBasis2DCartesian(
            space_order)
        utils.check_to_from_dict(legendre_basis_2d_cartesian, basis_factory)
        check_matrices(legendre_basis_2d_cartesian)
Ejemplo n.º 13
0
def test_fv_basis_1d():
    fv_basis = basis.FiniteVolumeBasis1D()
    utils.check_to_from_dict(fv_basis, basis_factory)
    check_matrices(fv_basis)
Ejemplo n.º 14
0
def test_legendre_basis_1d():
    for num_basis_cpts in range(1, 10):
        legendre_basis = basis.LegendreBasis1D(num_basis_cpts)
        utils.check_to_from_dict(legendre_basis, basis_factory)
        check_matrices(legendre_basis)
Ejemplo n.º 15
0
def test_gauss_legendre_nodal_basis_1d():
    for num_nodes in range(1, 10):
        gl_nodal_basis = basis.GaussLegendreNodalBasis1D(num_nodes)
        utils.check_to_from_dict(gl_nodal_basis, basis_factory)
        check_matrices(gl_nodal_basis)
        check_derivative_matrix(gl_nodal_basis)