コード例 #1
0
def test_linearized_mms_ldg_irk():
    # g = functions.Sine(offset=2.0)
    # r = -1.0
    # exact_solution = flux_functions.ExponentialFunction(g, r)
    exact_solution = flux_functions.AdvectingSine(offset=2.0)
    t_initial = 0.0
    t_final = 0.1
    exact_solution_final = lambda x: exact_solution(x, t_final)
    bc = boundary.Periodic()
    p_class = convection_hyper_diffusion.NonlinearHyperDiffusion
    p_func = p_class.linearized_manufactured_solution
    for diffusion_function in diffusion_functions:
        problem = p_func(exact_solution, diffusion_function)
        for num_basis_cpts in range(1, 3):
            irk = implicit_runge_kutta.get_time_stepper(num_basis_cpts)
            for basis_class in basis.BASIS_LIST:
                basis_ = basis_class(num_basis_cpts)
                error_list = []
                for i in [1, 2]:
                    if i == 1:
                        delta_t = 0.01
                        num_elems = 20
                    else:
                        delta_t = 0.005
                        num_elems = 40
                    mesh_ = mesh.Mesh1DUniform(0.0, 1.0, num_elems)
                    dg_solution = basis_.project(problem.initial_condition,
                                                 mesh_)
                    # time_dependent_matrix time does matter
                    matrix_function = lambda t: problem.ldg_matrix(
                        dg_solution, t, bc, bc, bc, bc)
                    rhs_function = problem.get_implicit_operator(
                        bc, bc, bc, bc)
                    solve_function = time_stepping.get_solve_function_matrix(
                        matrix_function)
                    new_solution = time_stepping.time_step_loop_implicit(
                        dg_solution,
                        t_initial,
                        t_final,
                        delta_t,
                        irk,
                        rhs_function,
                        solve_function,
                    )
                    error = math_utils.compute_error(new_solution,
                                                     exact_solution_final)
                    error_list.append(error)
                    # plot.plot_dg_1d(new_solution, function=exact_solution_final)
                order = utils.convergence_order(error_list)
                assert order >= num_basis_cpts
コード例 #2
0
def test_nonlinear_mms_ldg_irk():
    exact_solution = flux_functions.AdvectingSine(amplitude=0.1, offset=0.15)
    t_initial = 0.0
    t_final = 0.1
    exact_solution_final = lambda x: exact_solution(x, t_final)
    bc = boundary.Periodic()
    p_func = thin_film.ThinFilmDiffusion.manufactured_solution
    problem = p_func(exact_solution)
    for num_basis_cpts in range(1, 3):
        irk = implicit_runge_kutta.get_time_stepper(num_basis_cpts)
        cfl = 0.5
        for basis_class in basis.BASIS_LIST:
            basis_ = basis_class(num_basis_cpts)
            error_list = []
            n = 40
            for num_elems in [n, 2 * n]:
                mesh_ = mesh.Mesh1DUniform(0.0, 1.0, num_elems)
                delta_t = cfl * mesh_.delta_x / exact_solution.wavespeed
                dg_solution = basis_.project(problem.initial_condition, mesh_)
                # time_dependent_matrix time does matter
                matrix_function = lambda t, q: problem.ldg_matrix(q, t, bc, bc, bc, bc)
                rhs_function = problem.get_implicit_operator(bc, bc, bc, bc)
                solve_function = time_stepping.get_solve_function_picard(
                    matrix_function, num_basis_cpts, num_elems * num_basis_cpts
                )
                new_solution = time_stepping.time_step_loop_implicit(
                    dg_solution,
                    t_initial,
                    t_final,
                    delta_t,
                    irk,
                    rhs_function,
                    solve_function,
                )
                error = math_utils.compute_error(new_solution, exact_solution_final)
                error_list.append(error)
                # plot.plot_dg_1d(new_solution, function=exact_solution_final)
            with open("thin_film_nonlinear_irk_test.yml", "a") as file:
                dict_ = dict()
                subdict = dict()
                subdict["cfl"] = cfl
                subdict["n"] = n
                subdict["error0"] = float(error_list[0])
                subdict["error1"] = float(error_list[1])
                subdict["order"] = float(np.log2(error_list[0] / error_list[1]))
                dict_[num_basis_cpts] = subdict
                yaml.dump(dict_, file, default_flow_style=False)
            order = utils.convergence_order(error_list)
            assert order >= num_basis_cpts
コード例 #3
0
def test_ldg_matrix_irk():
    p_func = convection_hyper_diffusion.HyperDiffusion.periodic_exact_solution
    problem = p_func(x_functions.Sine(offset=2.0), diffusion_constant=1.0)
    t_initial = 0.0
    t_final = 0.1
    bc = boundary.Periodic()
    exact_solution = lambda x: problem.exact_solution(x, t_final)
    for num_basis_cpts in range(1, 3):
        irk = implicit_runge_kutta.get_time_stepper(num_basis_cpts)
        for basis_class in basis.BASIS_LIST:
            basis_ = basis_class(num_basis_cpts)
            error_list = []
            # constant matrix
            n = 20
            for num_elems in [n, 2 * n]:
                mesh_ = mesh.Mesh1DUniform(0.0, 1.0, num_elems)
                delta_t = mesh_.delta_x / 5
                dg_solution = basis_.project(problem.initial_condition, mesh_)
                # constant matrix time doesn't matter
                tuple_ = problem.ldg_matrix(dg_solution, t_initial, bc, bc, bc,
                                            bc)
                matrix = tuple_[0]
                vector = tuple_[1]
                rhs_function = problem.get_implicit_operator(bc, bc, bc, bc)
                solve_function = time_stepping.get_solve_function_constant_matrix(
                    matrix, vector)
                new_solution = time_stepping.time_step_loop_implicit(
                    dg_solution,
                    t_initial,
                    t_final,
                    delta_t,
                    irk,
                    rhs_function,
                    solve_function,
                )
                dg_error = math_utils.compute_dg_error(new_solution,
                                                       exact_solution)
                error = dg_error.norm()
                error_list.append(error)
                # plot.plot_dg_1d(new_solution, function=exact_solution)
                # plot.plot(dg_error)
            order = utils.convergence_order(error_list)
            # if not already at machine error
            if error_list[0] > 1e-10 and error_list[1] > 1e-10:
                assert order >= num_basis_cpts
コード例 #4
0
def test_ldg_matrix_irk():
    diffusion = convection_diffusion.Diffusion.periodic_exact_solution()
    t_initial = 0.0
    t_final = 0.1
    bc = boundary.Periodic()
    basis_ = basis.LegendreBasis1D(1)
    exact_solution = lambda x: diffusion.exact_solution(x, t_final)
    for num_basis_cpts in range(1, 3):
        irk = implicit_runge_kutta.get_time_stepper(num_basis_cpts)
        for basis_class in basis.BASIS_LIST:
            basis_ = basis_class(num_basis_cpts)
            error_list = []
            # constant matrix
            for i in [1, 2]:
                if i == 1:
                    delta_t = 0.01
                    num_elems = 20
                else:
                    delta_t = 0.005
                    num_elems = 40
                mesh_ = mesh.Mesh1DUniform(0.0, 1.0, num_elems)
                dg_solution = basis_.project(diffusion.initial_condition,
                                             mesh_)
                # constant matrix time doesn't matter
                tuple_ = diffusion.ldg_matrix(dg_solution, t_initial, bc, bc)
                matrix = tuple_[0]
                # vector = tuple_[1]
                rhs_function = diffusion.get_implicit_operator(bc, bc)
                solve_function = time_stepping.get_solve_function_constant_matrix(
                    matrix)
                new_solution = time_stepping.time_step_loop_implicit(
                    dg_solution,
                    t_initial,
                    t_final,
                    delta_t,
                    irk,
                    rhs_function,
                    solve_function,
                )
                error = math_utils.compute_error(new_solution, exact_solution)
                error_list.append(error)
            order = utils.convergence_order(error_list)
            assert order >= num_basis_cpts