def test_conv_test():
    my_params = Data()
    my_params.plotter = Data()
    my_params.plotter.always_plot = False
    my_params.plotter.never_plot = True
    my_params.plotter.plot_interval = 0.5
    my_params.t_max = 50.0
    #my_params.analytical = lambda x: wave_forms.sin_4(x, 2 * np.pi * 1.0)
    my_params.analytical = lambda x: wave_forms.gaussian(x, 4.0, 2.5)
    ct = ConvergenceTest(my_params, 5.0)
def test_error_tracker():
    delta_x = 0.01 * np.ones(100)
    exact = lambda t: np.linspace(0, 1, 100) + t
    params = Data()
    params.error_norm = 1
    params.plotter = Data()
    params.plotter.never_plot = True
    e1 = ErrorTracker(Mesh(delta_x), exact, params)
    params.error_norm = 2
    e2 = ErrorTracker(Mesh(delta_x), exact, params)
    for i in range(1, 10):
        # the exact result is x + i
        e1.update(e1.mesh.x + 0.9 * i, float(i), 1.0)
        # in any norm the error should be 0.i
        assert(abs(e1.error[i] - i * 0.1) <= 1e-9)

        new_val = exact(i)
        new_val[0] = 0
        # the difference
        e2.update(new_val, float(i), 1.0)
        # L2 norm of the error should be 0.(i + 1)
        assert(abs(e2.error[i] - (i * 0.01)) <= 1e-9)
def _test_controller_helper(wave, t_max, delta_x, error_bound, always=False,
                            setup_callback=None):
    # Simple test to make sure the code works right
    my_params = Data()
    my_params.delta_x = delta_x
    my_params.plotter = Data()
    my_params.plotter.always_plot = always
    my_params.plotter.never_plot = not interactive_test
    my_params.plotter.plot_interval = 0.5
    my_params.t_max = t_max
    my_params.analytical = wave
    cont = Controller(my_params)
    if setup_callback is not None:
        setup_callback(cont)
    et = ErrorTracker(cont.mesh, cont.analytical, my_params)

    soln_plot = UpdatePlotter(my_params.plotter)

    soln_plot.add_line(cont.mesh.x, cont.init, '+')
    soln_plot.add_line(cont.mesh.x, cont.init, '-')
    cont.observers.append(soln_plot)
    cont.observers.append(et)
    result = cont.compute()
    soln_plot.add_line(cont.mesh.x, cont.exact)

    # check essentially non-oscillatoriness
    # total variation <= initial_tv + O(h^2)
    init_tv = Controller.total_variation(cont.init)
    result_tv = Controller.total_variation(result)

    if interactive_test is True:
        pyp.show()
    assert(result_tv < init_tv + error_bound)

    # check error
    assert(et.error[-1] < error_bound)
    return et, soln_plot
Exemple #4
0

# Setup the solution domain, first we define the cell spacings
delta_x = []
count = 2000
domain_length = 10.0
for i in range(count):
    if i % 10 == 0:
        delta_x.append(domain_length / count)
    else:
        delta_x.append(domain_length / count)
width = np.sum(delta_x)
params.delta_x = np.array(delta_x)

# plotting parameters
params.plotter = Data()
params.plotter.always_plot = False
params.plotter.never_plot = False
params.plotter.plot_interval = 0.1


params.t_max = 100.0
wavelengths = 3
# params.analytical = lambda x: wave_forms.sin_4(x, wavelengths * np.pi / width)
params.analytical = wave_forms.square

# Define project and run parameters in order to save the results to
# the proper data folder.
params.proj_name = "fvm"
params.run_name = "development"