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
        case_sol_input = [0,  # t0
                          1,  # start_value
                          case_num]  # case num

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

        # Get error
        error = error_trackers[0].tot_error

        # cache error
        tracker.add_entry(dt, 0, error)

    vis.display_error(1, tracker, double_log=True, line_name=name,linestyle=line_type)
vis.draw_loglog_oder_line(1, 1e-4, 1e-3, 1.0, -1)
vis.draw_loglog_oder_line(1, 1e-4, 1e-7, 1.0, -2)
vis.draw_loglog_oder_line(1, 1e-2, 1e-11, 1.0, -4)
plt.grid()
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()"""
        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,
                                 linestyle=ls)

window_manager.draw_loglog_oder_line(1, 1e4, 1e+0, 1, 1)
window_manager.draw_loglog_oder_line(1, 1e4, 1e-2, 1, 2)
window_manager.draw_loglog_oder_line(1, sqrt(10) * 1e3, 1e-4, 1, 4)
plt.plot([1e7], [1e2], "")
plt.grid()
plt.show()
    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()"""