def test_nu_BDF4_diff(resolution, spatial_order): grid = field.UniformPeriodicGrid(resolution, 50) x = grid.values IC = np.exp(-(x - 30)**2 / 4) u = field.Field(grid, IC) target = 1 / np.sqrt(5) * np.exp(-(x - 30)**2 / 20) d = spatial.FiniteDifferenceUniformGrid(2, spatial_order, grid, stencil_type='centered') ts = timesteppers.BackwardDifferentiationFormula(u, d, 4) alpha = 0.2 ts.evolve(1, alpha * grid.dx / 2) ts.evolve(3, alpha * grid.dx / 3) ts.evolve(4, alpha * grid.dx) error = np.max(np.abs(u.data - target)) error_est = error_nu_BDF4_diff[(resolution, spatial_order)] assert error < error_est
def test_nu_BDF5_wave(resolution, spatial_order): grid = field.UniformPeriodicGrid(resolution, 2 * np.pi) x = grid.values IC = np.exp(-(x - np.pi)**2 * 8) u = field.Field(grid, IC) target = np.exp(-(x - np.pi + 2 * np.pi * 0.2)**2 * 8) d = spatial.FiniteDifferenceUniformGrid(1, spatial_order, grid, stencil_type='centered') ts = timesteppers.BackwardDifferentiationFormula(u, d, 5) alpha = 0.5 num_periods = 1.2 ts.evolve(0.5 * np.pi * num_periods, alpha * grid.dx) ts.evolve(1.25 * np.pi * num_periods, alpha * grid.dx / 3) ts.evolve(2 * np.pi * num_periods, alpha * grid.dx / 2) error = np.max(np.abs(u.data - target)) error_est = error_nu_BDF5_wave[(resolution, spatial_order)] assert error < error_est
def test_BDF6_wave(resolution): grid = field.UniformPeriodicGrid(resolution, 2 * np.pi) x = grid.values IC = np.exp(-(x - np.pi)**2 * 8) u = field.Field(grid, IC) target = np.exp(-(x - np.pi - 2 * np.pi * 0.2)**2 * 8) d = spatial.FiniteDifferenceUniformGrid(1, 6, grid, stencil_type='centered') ts = timesteppers.BackwardDifferentiationFormula(u, d, 6) alpha = 0.5 num_periods = 1.8 ts.evolve(2 * np.pi * num_periods, alpha * grid.dx) error = np.max(np.abs(u.data - target)) error_est = error_BDF6_wave[resolution] assert error < error_est