Beispiel #1
0
 def test_subtraction_centered_grid(self):
     """subtract one field from another"""
     shape = [32, 27]
     for boundary in [CLOSED, PERIODIC, OPEN]:
         domain = Domain(shape, boundaries=(boundary, boundary))
         centered_grid = CenteredGrid.sample(Noise(), domain)
         result_array = (centered_grid - centered_grid).data
         np.testing.assert_array_equal(result_array, 0)
Beispiel #2
0
 def test_reconst(self, set_accuracy=1e-5, shape=[40, 40], first_order_tolerance=3, second_order_tolerance=40,
                  boundary_list=[PERIODIC, OPEN, CLOSED]):
     for boundary in boundary_list:
         domain = Domain(shape, boundaries=(boundary, boundary))
         solver_list = [
             ('SparseCG', lambda field: poisson_solve(field, domain, SparseCG(accuracy=set_accuracy)), lambda field: field.laplace()),
             ('GeometricCG', lambda field: poisson_solve(field, domain, GeometricCG(accuracy=set_accuracy)), lambda field: field.laplace()),
             #('SparseSciPy', lambda field: poisson_solve(field, domain, SparseSciPy()), lambda field: field.laplace()),
             # ('Fourier', lambda field: poisson_solve(field, domain, Fourier()))]  # TODO: poisson_solve() causes resolution to be empty
             ('FFT', math.fourier_poisson, math.fourier_laplace)]
         in_data = CenteredGrid.sample(Noise(), domain)
         sloped_data = (np.array([np.arange(shape[1]) for _ in range(shape[0])]).reshape([1] + shape + [1]) / 10 + 1)
         in_data = in_data.copied_with(data=sloped_data)
         for name, solver, laplace in solver_list:
             print('Testing {} boundary with {} solver... '.format(boundary, name)),
             _test_reconstruction_first_order(in_data, solver, laplace, set_accuracy, name, first_order_tolerance=first_order_tolerance)
             _test_reconstruction_second_order(in_data, solver, laplace, set_accuracy, name, second_order_tolerance=second_order_tolerance)
         print('Testing {} boundary with {} solver... '.format(boundary, 'higher order FFT')),
         _run_higher_order_fft_reconstruction(in_data, set_accuracy, order=2, tolerance=second_order_tolerance)
Beispiel #3
0
def _test_random_periodic(solver):
    domain = Domain([40, 32], boundaries=PERIODIC)
    div = domain.centered_grid(Noise())
    div_ = poisson_solve(div, domain, solver)[0].laplace()
    np.testing.assert_almost_equal(div.data, div_.data, decimal=3)