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_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
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" # Define the set of experiments to be run class Play(Experiment): def _initialize(self): self.cont = Controller(self.params) # self.cont.deriv.reconstructor = WENO(self.cont.mesh) et = ErrorTracker(self.cont.mesh, self.cont.analytical, self.params)