def test_convert_butcher_to_shu_osher_form():
    # NOTE: converting butcher to shu osher is not unique
    forward_euler = explicit_runge_kutta.ForwardEuler()
    tuple_ = explicit_runge_kutta.convert_butcher_to_shu_osher_form(
        forward_euler.a_b, forward_euler.b_b, forward_euler.c_b
    )
    a_s = tuple_[0]
    b_s = tuple_[1]
    c_s = tuple_[2]

    assert np.all(a_s == forward_euler.a_s)
    assert np.all(b_s == forward_euler.b_s)
    assert np.all(c_s == forward_euler.c_s)
def get_time_stepper(order=2,
                     num_frames=10,
                     time_step_function=None,
                     is_verbose=True):
    if order == 1:
        return explicit_runge_kutta.ForwardEuler(num_frames,
                                                 time_step_function,
                                                 is_verbose)
    elif order == 2:
        return SSP2(2, num_frames, time_step_function, is_verbose)
    elif order == 3:
        return SSP3(2, num_frames, time_step_function, is_verbose)
    elif order == 4:
        return SSP4(num_frames, time_step_function, is_verbose)
    else:
        raise Exception(
            "This order is not supported for low_storage_explicit_runge_kutta")
Ejemplo n.º 3
0
def test_advection_one_time_step():
    def initial_condition(x):
        return np.sin(2.0 * np.pi * x)

    advection_ = advection.Advection(initial_condition=initial_condition)
    riemann_solver = riemann_solvers.LocalLaxFriedrichs(
        advection_.flux_function, advection_.wavespeed_function
    )
    explicit_time_stepper = explicit_runge_kutta.ForwardEuler()
    boundary_condition = boundary.Periodic()
    cfl = 1.0
    for basis_class in basis.BASIS_LIST:
        basis_ = basis_class(1)
        error_list = []
        for num_elems in [20, 40]:
            mesh_ = mesh.Mesh1DUniform(0.0, 1.0, num_elems)
            dg_solution = basis_.project(advection_.initial_condition, mesh_)

            delta_t = dg_utils.get_delta_t(cfl, advection_.wavespeed, mesh_.delta_x)
            time_initial = 0.0
            time_final = delta_t

            rhs_function = lambda time, q: dg_utils.dg_weak_formulation(
                q, advection_.flux_function, riemann_solver, boundary_condition
            )
            final_solution = time_stepping.time_step_loop_explicit(
                dg_solution,
                time_initial,
                time_final,
                delta_t,
                explicit_time_stepper,
                rhs_function,
            )
            error = math_utils.compute_error(
                final_solution, lambda x: advection_.exact_solution(x, time_final)
            )
            error_list.append(error)
        order = utils.convergence_order(error_list)
        assert order >= 1
Ejemplo n.º 4
0
def dogpack_timestepper_from_dict(dict_):
    # 1st Order - Forward Euler
    # 2nd Order - TVDRK2
    # 3rd Order - TVDRK3
    # 4th Order - SSP RK4 10 stages
    # 5th Order - 8 Stages
    order = dict_["order"]
    num_frames = dict_["num_frames"]
    is_verbose = dict_["is_verbose"]
    target_cfl = dict_["target_cfl"]
    if target_cfl == "auto":
        target_cfl = get_dogpack_auto_cfl_target(order)

    max_cfl = dict_["max_cfl"]
    if max_cfl == "auto":
        max_cfl = get_dogpack_auto_cfl_max(order)

    dogpack_timestep_function = get_dogpack_timestep_function(
        target_cfl, max_cfl)
    if order == 1:
        return explicit_runge_kutta.ForwardEuler(num_frames,
                                                 dogpack_timestep_function,
                                                 is_verbose)
    elif order == 2:
        return explicit_runge_kutta.TVDRK2(num_frames,
                                           dogpack_timestep_function,
                                           is_verbose)
    elif order == 3:
        return explicit_runge_kutta.TVDRK3(num_frames,
                                           dogpack_timestep_function,
                                           is_verbose)
    elif order == 4:
        return low_storage_explicit_runge_kutta.SSP4(
            num_frames, dogpack_timestep_function, is_verbose)
    else:
        raise errors.InvalidParameter("order", order)
def test_convert_shu_osher_to_butcher_form():
    forward_euler = explicit_runge_kutta.ForwardEuler()
    tuple_ = explicit_runge_kutta.convert_shu_osher_to_butcher_form(
        forward_euler.a_s, forward_euler.b_s, forward_euler.c_s
    )
    a_b = tuple_[0]
    b_b = tuple_[1]
    c_b = tuple_[2]

    assert np.all(a_b == forward_euler.a_b)
    assert np.all(b_b == forward_euler.b_b)
    assert np.all(c_b == forward_euler.c_b)

    tvd_rk2 = explicit_runge_kutta.TVDRK2()
    tuple_ = explicit_runge_kutta.convert_shu_osher_to_butcher_form(
        tvd_rk2.a_s, tvd_rk2.b_s, tvd_rk2.c_s
    )
    a_b = tuple_[0]
    b_b = tuple_[1]
    c_b = tuple_[2]

    assert np.all(a_b == tvd_rk2.a_b)
    assert np.all(b_b == tvd_rk2.b_b)
    assert np.all(c_b == tvd_rk2.c_b)

    tvd_rk3 = explicit_runge_kutta.TVDRK2()
    tuple_ = explicit_runge_kutta.convert_shu_osher_to_butcher_form(
        tvd_rk3.a_s, tvd_rk3.b_s, tvd_rk3.c_s
    )
    a_b = tuple_[0]
    b_b = tuple_[1]
    c_b = tuple_[2]

    assert np.all(a_b == tvd_rk3.a_b)
    assert np.all(b_b == tvd_rk3.b_b)
    assert np.all(c_b == tvd_rk3.c_b)
def test_forward_euler():
    forward_euler = explicit_runge_kutta.ForwardEuler()
    odes.sample_odes(forward_euler, 1)
def test_forward_euler_event_hooks():
    forward_euler = explicit_runge_kutta.ForwardEuler(1)
    odes.check_event_hooks(forward_euler)
def test_forward_euler_linear():
    forward_euler = explicit_runge_kutta.ForwardEuler()
    odes.check_linear_case(forward_euler)
def test_forward_euler_steady_state():
    forward_euler = explicit_runge_kutta.ForwardEuler()
    odes.check_steady_state_case(forward_euler)
Ejemplo n.º 10
0
    problem = torrilhon_example.TorrilhonExample(
        num_moments,
        gravity_constant,
        kinematic_viscosity,
        slip_length,
        displacement,
        velocity,
        linear_coefficient,
        quadratic_coefficient,
        cubic_coefficient,
        max_height,
    )

    dg_solution = basis_.project(problem.initial_condition, mesh_)

    time_initial = 0.0
    delta_t = 0.05 * mesh_.delta_x / velocity
    time_final = 2.0

    timestepper = explicit_runge_kutta.ForwardEuler()

    def explicit_operator(t, q):
        return rhs_function(t, q, problem.app_)

    final_solution = time_stepping.time_step_loop_explicit(
        dg_solution, time_initial, time_final, delta_t, timestepper,
        explicit_operator)

    plot.plot_dg_1d(final_solution,
                    transformation=swme.get_primitive_variables)