Beispiel #1
0
    def test_with_stationary_solution(self):
        expected_order = 1
        num_grid_points = 100000

        err_lists = [[], []]
        dt_list = []

        a = 0.5

        max_exp = 5

        baseline_dt = 1.0 / (
            (2**16) * num_grid_points)  # largest dt that will be used

        simul_t = 100 * baseline_dt

        for i in range(4):
            dt = (a**i) * baseline_dt

            params = {
                'num_grid_points': num_grid_points,
                'domain_size': 10.0,
                'dt': dt,
                'end_time': simul_t
            }

            time_derivative_input = [True, True]

            case_sol_input = []

            error_tracker_list = gen_test_data(params, Euler.Explicit,
                                               LogTimeDerivative,
                                               time_derivative_input,
                                               StationarySolution,
                                               case_sol_input)
            err_lists[0].append(error_tracker_list[0].tot_error)
            err_lists[1].append(error_tracker_list[1].tot_error)

            dt_list.append(dt)

        for i in range(len(err_lists[0])):
            print(err_lists[0][i])
            print(err_lists[1][i])
            # actual_order = math.log(err_lists[0][i + 1] / err_lists[0][i], a)
            self.assertTrue(
                err_lists[0][i] < 1e-15,
                msg=
                "Mistake found at time-resolution {} for u. Expected error of {} but got {}"
                .format(dt_list[i], 1e-15, err_lists[0][i]))

            # actual_order = math.log(err_lists[1][i + 1] / err_lists[1][i], a)
            self.assertTrue(
                err_lists[1][i] < 1e-15,
                msg=
                "Mistake found at time-resolution {} for v. Expected error of {} but got {}"
                .format(dt_list[i], 1e-15, err_lists[1][i]))
Beispiel #2
0
    def test_with_solution(self):
        c = 1.0
        num_grid_points = 100000

        err_lists = [[], []]
        dt_list = []

        a = 0.5
        expected_order = 2

        t = 20 / (4.0 * num_grid_points * c)

        for i in range(10):
            dt = (a**i) * (2**10) * 64.0 / (4.0 * num_grid_points * c)

            params = {
                'num_grid_points': num_grid_points,
                'domain_size': 1.0,
                'dt': dt,
                'end_time': t
            }

            time_derivative_input = [c]

            case_sol_input = [
                c,
                GaussianBump(params['domain_size'] * 0.5,
                             2).get_start_condition
            ]

            error_tracker_list = gen_test_data(params, Heun.Explicit,
                                               PeriodicWaveTimeDerivative,
                                               time_derivative_input,
                                               CaseSolution, case_sol_input)
            err_lists[0].append(error_tracker_list[0].tot_error)
            err_lists[1].append(error_tracker_list[1].tot_error)

            dt_list.append(dt)

        for i in range(len(err_lists[0]) - 1):
            actual_order = math.log(err_lists[0][i + 1] / err_lists[0][i], a)
            self.assertTrue(
                expected_order * 0.95 < actual_order < expected_order * 1.05,
                msg=
                "Mistake found at time-resolutions {} x {} for u. Expected order of {} but got {}"
                .format(dt_list[i], dt_list[i + 1], expected_order,
                        actual_order))

            actual_order = math.log(err_lists[1][i + 1] / err_lists[1][i], a)
            self.assertTrue(
                expected_order * 0.95 < actual_order < expected_order * 1.05,
                msg=
                "Mistake found at time-resolutions {} x {} for v. Expected order of {} but got {}"
                .format(dt_list[i], dt_list[i + 1], expected_order,
                        actual_order))
Beispiel #3
0
    def test_with_solution(self):
        c = 1.0
        num_grid_points = 100000

        err_lists = [[], []]
        dt_list = []

        a = 0.5
        expected_order = 4

        t = 20 / (4.0 * num_grid_points * c)

        for i in range(10):
            dt = (a**i) * (2**10) * 64.0 / (4.0 * num_grid_points * c)

            params = {
                'num_grid_points': num_grid_points,
                'domain_size': 1.0,
                'dt': dt,
                'end_time': t
            }

            time_derivative_input = [c]

            case_sol_input = [c, [(1, 1.0), (2, 2.0)]]

            error_tracker_list = gen_test_data(params, RungeKutta.Explicit,
                                               WaveEquationLaplace,
                                               time_derivative_input,
                                               StandingWaveFixedEnd,
                                               case_sol_input)
            err_lists[0].append(error_tracker_list[0].tot_error)
            err_lists[1].append(error_tracker_list[1].tot_error)

            dt_list.append(dt)

        for i in range(len(err_lists[0]) - 1):
            actual_order = math.log(err_lists[0][i + 1] / err_lists[0][i], a)
            self.assertTrue(
                expected_order * 0.95 < actual_order < expected_order * 1.05,
                msg=
                "Mistake found at time-resolutions {} x {} for u. Expected order of {} but got {}"
                .format(dt_list[i], dt_list[i + 1], expected_order,
                        actual_order))
Beispiel #4
0
    def test_with_solution(self):
        expected_order = 2
        c = 1.0
        num_grid_points = 100000

        err_lists = [[], []]
        dt_list = []

        a = 0.5

        max_exp = 5

        overresolution = 16

        baseline_dt = 1.0 / (4.0 * num_grid_points * c
                             )  # largest dt that will be used

        ref_dt = (a**max_exp) * baseline_dt / overresolution

        ref_t = 33 * baseline_dt
        simul_t = 32 * baseline_dt

        for i in range(3):
            dt = (a**i) * baseline_dt

            params = {
                'num_grid_points': num_grid_points,
                'domain_size': 1.0,
                'dt': dt,
                'end_time': simul_t
            }

            time_derivative_input = [c]

            ref_solution_generator = ReferenceSolutionCalculator(
                num_grid_points,
                2,
                TimeDerivativeLaplace,
                time_derivative_input, [0, 0],
                params['domain_size'],
                down_sampling_rate=overresolution)

            start_cond = GaussianBump(params['domain_size'] * 0.5, 100)
            case_sol_input = [
                2, ref_solution_generator,
                [start_cond.get_start_condition, start_cond.get_derivative],
                ref_dt, ref_t
            ]

            error_tracker_list = gen_test_data(params, Heun.Explicit,
                                               TimeDerivativeLaplace,
                                               time_derivative_input,
                                               CaseSolution, case_sol_input)
            err_lists[0].append(error_tracker_list[0].tot_error)
            err_lists[1].append(error_tracker_list[1].tot_error)

            dt_list.append(dt)

        for i in range(len(err_lists[0]) - 1):
            print(i)
            actual_order = math.log(err_lists[0][i + 1] / err_lists[0][i], a)
            self.assertTrue(
                expected_order * 0.95 < actual_order < expected_order * 1.05,
                msg=
                "Mistake found at time-resolutions {} x {} for u. Expected order of {} but got {}"
                .format(dt_list[i], dt_list[i + 1], expected_order,
                        actual_order))
                'num_grid_points': num_grid_points,
                'domain_size': 10.0,
                'dt': dt,
                'end_time': sim_time
            }

            time_derivative_input = [c]  # wave speed

            case_sol_input = [
                c,  # wave speed
                GaussianBump(params['domain_size'] * 0.5,
                             2).get_start_condition
            ]  # start condition

            error_trackers = run_utils.gen_test_data(
                params, integrator, PeriodicWaveTimeDerivative,
                time_derivative_input, CaseSolution, case_sol_input)

            # Get error
            error = error_trackers[0].tot_error + error_trackers[1].tot_error

            # cache error
            arr[res_exp][res_factor] = np.log(error)
    # arr[8][0] = 10000
    np.save(utils.data_path + "heatmap.npy", arr)
    plt.imshow(arr,
               origin="lower",
               extent=[100, 100 * (max_res_factor), 1e-3, 3e-2],
               aspect="auto",
               cmap="seismic",
               interpolation="gaussian",
    num_grid_points = resolution

    params = {
        'num_grid_points': num_grid_points,
        'domain_size': 10.0,
        'dt': dt,
        'end_time': sim_time
    }

    time_derivative_input = [c]

    case_sol_input = [c, starting_conditions.GaussianBump(params['domain_size'] * 0.5, 5).get_start_condition]

    error_trackers = run_utils.gen_test_data(params, Exponential,
                                             TimeDerivativeMatrix, time_derivative_input,
                                             CaseSolution, case_sol_input)

    # Get error
    error_u = error_trackers[0].tot_error
    error_v = error_trackers[1].tot_error

    # cache error
    errors_u.add_entry(resolution, 0, error_u)
    errors_v.add_entry(resolution, 0, error_v)

vis = WindowManager(1, 1)
vis.display_error(1, errors_u, double_log=True, line_name="u_error")
vis.display_error(1, errors_u, double_log=True, line_name="v_error")
vis.draw_loglog_oder_line(1, 1e2, 1e-2, 0.5, 2)
vis.draw_loglog_oder_line(1, 1e2, 1e-2, 0.5, 3)