def __init__(self, wavespeed=1.0, initial_condition=None, source_function=None):
        self.wavespeed = wavespeed
        if initial_condition is None:
            self.initial_condition = x_functions.Sine()
        else:
            self.initial_condition = initial_condition

        app = advection.Advection(wavespeed, source_function)
        max_wavespeed = wavespeed
        exact_solution = advection.ExactSolution(initial_condition, wavespeed)

        super().__init__(
            app, initial_condition, max_wavespeed, exact_solution
        )
    def __init__(
        self,
        wavespeed=1.0,
        left_states=None,
        right_states=None,
        discontinuity_locations=None,
        source_function=None,
    ):
        self.wavespeed = wavespeed
        # left_state, right_state, and discontinuity_location should be arrays or lists
        if left_states is None:
            self.left_states = [1.0, 2.0]
        else:
            self.left_states = left_states

        if right_states is None:
            self.right_states = [-1.0, 1.0]
        else:
            self.right_states = right_states

        if discontinuity_locations is None:
            self.discontinuity_locations = [-0.6, -0.4]
        else:
            self.discontinuity_locations = discontinuity_locations

        app_ = advection.Advection(wavespeed, source_function)
        riemann_problems = []
        for i in range(len(left_states)):
            riemann_problems.append(x_functions.RiemannProblem(
                left_states[i], right_states[i], discontinuity_locations[i]
            ))

        initial_condition = x_functions.ComposedVector(riemann_problems)
        max_wavespeed = wavespeed
        exact_solution = advection.ExactSolution(initial_condition, self.wavespeed)

        super().__init__(
            app_, initial_condition, max_wavespeed, exact_solution
        )
示例#3
0
    def __init__(
        self,
        wavespeed=1.0,
        left_state=1.0,
        right_state=-1.0,
        discontinuity_location=0.0,
        source_function=None,
    ):
        self.wavespeed = wavespeed
        self.left_state = left_state
        self.right_state = right_state
        self.discontinuity_location = discontinuity_location

        app_ = advection.Advection(wavespeed, source_function)
        initial_condition = x_functions.RiemannProblem(left_state, right_state,
                                                       discontinuity_location)
        max_wavespeed = wavespeed
        exact_solution = advection.ExactSolution(initial_condition,
                                                 self.wavespeed)

        super().__init__(app_, initial_condition, max_wavespeed,
                         exact_solution)
示例#4
0
def test_advection_operator():
    # test that dg_operator acting on projected initial condition converges to
    # exact time derivative
    # will lose one order of accuracy

    for i in range(2):
        if i == 0:
            sin = x_functions.Sine()
            cos = x_functions.Cosine()
            initial_condition = x_functions.ComposedVector([sin, cos])
        else:
            initial_condition = x_functions.Sine()
        wavespeed = 1.0
        exact_solution = advection.ExactSolution(initial_condition, wavespeed)
        exact_time_derivative = advection.ExactTimeDerivative(exact_solution, wavespeed)
        initial_time_derivative = x_functions.FrozenT(exact_time_derivative, 0.0)

        app_ = advection.Advection(wavespeed)
        riemann_solver = riemann_solvers.LocalLaxFriedrichs(app_.flux_function)
        boundary_condition = boundary.Periodic()

        for basis_class in basis.BASIS_LIST:
            for num_basis_cpts in range(1, 5):
                basis_ = basis_class(num_basis_cpts)
                error_list = []
                for num_elems in [20, 40]:
                    mesh_ = mesh.Mesh1DUniform(0.0, 1.0, num_elems)
                    dg_sol = basis_.project(initial_condition, mesh_)
                    dg_operator = app_.get_explicit_operator(
                        riemann_solver, boundary_condition
                    )
                    F = dg_operator(0.0, dg_sol)
                    error = math_utils.compute_error(F, initial_time_derivative)
                    error_list.append(error)

                order = utils.convergence_order(error_list)
                assert order >= max([1.0, num_basis_cpts - 1])
    def __init__(self,
                 wavespeed=1.0,
                 initial_condition=None,
                 source_function=None):
        self.wavespeed = wavespeed
        if initial_condition is None:
            initial_condition = x_functions.Sine()

        app = advection.Advection(wavespeed, source_function)
        max_wavespeed = wavespeed
        exact_solution = advection.ExactSolution(initial_condition, wavespeed)
        exact_operator = advection.ExactOperator(exact_solution, wavespeed,
                                                 source_function)
        exact_time_derivative = advection.ExactTimeDerivative(
            exact_solution, wavespeed, source_function)

        super().__init__(
            app,
            initial_condition,
            max_wavespeed,
            exact_solution,
            exact_operator,
            exact_time_derivative,
        )