def visual_test():
    window_manager = WindowManager(1, 1)

    for op, name in zip([operators.derivative.diff_backward_n1_e1, operators.derivative.diff_n1_e2,
                         operators.derivative.diff_n1_e4],
                        ["Derivative Order: 1", "Derivative Order: 2", "Derivative Order: 4"]):
        print(name)
        tracker = error_tracking_tools.ErrorTracker(num_points=None, x_label="Number of Samples", norm="l_inf")
        for resolution_exp in range(20):
            num_points = 5 * (2 ** resolution_exp)
            L = 1

            # shifting axis by irrational number e to avoid 'random' perfect results at low resolutions
            axis = np.linspace(0, L, num_points + 1)[:-1] - np.e
            dx = L * 1.0 / num_points

            factor = np.pi * 2 * 10  # 2 pi to have a periodic signal, other factors to increase the frequency
            signal = np.sin(axis * factor)

            calculated_result = op(signal, dx)
            accurate_result = factor * np.cos(axis * factor)

            tracker.add_entry(num_points, accurate_result, calculated_result)
            print(str(num_points) + "\t" + str(tracker.abs_error[-1]) + "\t" + str(1 / dx ** 2))

        window_manager.display_error(1, tracker, double_log=True, line_name=name, clear_axis=False)

    window_manager.draw_loglog_oder_line(1, 10, 1e-6, 1, 1)
    window_manager.draw_loglog_oder_line(1, 10, 1e-6, 1, 2)
    window_manager.draw_loglog_oder_line(1, 10, 1e-6, 1, 4)
    plt.grid()
    plt.show()
Exemplo n.º 2
0
from integrators.RungeKutta import Explicit as RK4
from cases import run_utils
from matplotlib import pyplot as plt
from starting_conditions import GaussianBump
#########################################################
# This file creates the heatmap-diagram from the thesis #
#########################################################

# Total simulation time
sim_time = 0.5
# time step size
# dt = 0.1
# wave speed
c = 1.0

vis = WindowManager(1, 1)
max_time_exp, max_res_factor = 11, 40

for integrator, name, line_type in zip([RK4], ["RK4"], ["-"]):
    print(name)
    arr = np.zeros((max_time_exp, max_res_factor))
    # tracker = ErrorTracker(num_points=None, x_label="step_size", norm="l_inf")

    dt0 = sim_time / 10

    for res_exp in range(max_time_exp):
        print(res_exp)
        # dt = dt0 / (1.5 ** res_exp)
        dt = 1e-3 + res_exp * (3e-2 - 1e-3) / 10
        for res_factor in range(max_res_factor):
            print(res_factor)
Exemplo n.º 3
0
from debug_tools.error_tracking_tools import ErrorTracker
from debug_tools.visualization import WindowManager
from integrators.Euler import Explicit as RK1
from integrators.Heun import Explicit as RK2
from integrators.RungeKutta import Explicit as RK4
from cases import run_utils
from matplotlib import pyplot as plt

# Total simulation time
sim_time = 0.1
# time step size
# dt = 0.1
# wave speed
c = 10.0

vis = WindowManager(1, 1)

for integrator, name, line_type in zip([RK1, RK2, RK4],
                            ["RK1", "RK2", "RK4"],
                            ["-","--",":"]):
    print(name)
    tracker = ErrorTracker(num_points=None, x_label="step_size", norm="l_inf")

    dt0 = 1

    for res_exp in range(30):
        dt = dt0 / (1.5**res_exp)
        # Initialize and compute time integration

        num_grid_points = 1
import numpy as np
from math import sqrt
from matplotlib import pyplot as plt

from debug_tools import error_tracking_tools
from debug_tools.visualization import WindowManager
from operators.derivative import *

window_manager = WindowManager(1, 1)

for op, name, ls in zip(
    [diff_backward_n1_e1, diff_n1_e2, diff_n1_e4],
    ["Derivative Order: 1", "Derivative Order: 2", "Derivative Order: 4"],
    ["-", "--", ":"]):
    print(name)
    tracker = error_tracking_tools.ErrorTracker(num_points=None,
                                                x_label="Number of Samples",
                                                norm="l_inf")
    for resolution_exp in range(40):
        num_points = int(5 * (1.5**resolution_exp))
        L = 1

        # shifting axis by irrational number e to avoid 'random' perfect results at low resolutions
        axis = np.linspace(0, L, num_points + 1)[:-1] - np.e
        dx = L * 1.0 / num_points

        factor = np.pi * 2 * 10  # 2 pi to have a periodic signal, other factors to increase the frequency
        signal = np.sin(axis * factor)

        calculated_result = op(signal, dx)
        accurate_result = factor * np.cos(axis * factor)
    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)
vis.draw_loglog_oder_line(1, 1e2, 1e-2, 0.5, 4)
plt.show()
"""print("u")
for i in range(len(resolutions) - 1):
    # comparing the previous error with current one
    print(errors_u.abs_error[i] / errors_u.abs_error[i + 1])
print("v")
for i in range(len(resolutions) - 1):
    # comparing the previous error with current one
    print(errors_v.abs_error[i] / errors_v.abs_error[i + 1])
plt.show()"""