def test_init_cond():
    params = Data()
    params.delta_x = 0.1 * np.ones(50)
    params.analytical = wave_forms.square
    controller = Controller(params)
    assert(controller.init[0] == 0.0)
    assert(controller.init[-1] == 0.0)
def test_mesh_initialize():
    params = Data()
    params.delta_x = np.array([0.5, 1.0, 0.1, 2.0])
    controller = Controller(params)
    correct = np.array([0.25, 1.0, 1.55, 2.6])
    assert(controller.mesh.domain_width == 3.6)
    assert(len(controller.mesh.x) == 4)
    assert((controller.mesh.x == correct).all())
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
# What material should we use? Look in the parameters/material file
# to see the options and to see how to define a new material.
params.material = wetdiabase


# 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.