Example #1
0
 def test_addition_centered_grid(self):
     """add one field to another"""
     shape = [32, 27]
     for boundary in [CLOSED, PERIODIC, OPEN]:
         domain = Domain(shape, boundaries=(boundary, boundary))
         centered_grid = CenteredGrid.sample(1, domain)
         result_array = (centered_grid + centered_grid).data
         np.testing.assert_array_equal(result_array, 2)
Example #2
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)
Example #3
0
 def test_division_centered_grid(self):
     """divide one field by another"""
     shape = [32, 27]
     for boundary in [CLOSED, PERIODIC, OPEN]:
         domain = Domain(shape, boundaries=(boundary, boundary))
         centered_grid = CenteredGrid.sample(2, domain)
         result_array = (centered_grid / centered_grid.copied_with(
             data=4 * np.ones([1] + shape + [1]))).data
         np.testing.assert_array_equal(result_array, 1. / 2)
Example #4
0
 def test_multiplication_centered_grid(self):
     """multiply one field with another"""
     shape = [32, 27]
     for boundary in [CLOSED, PERIODIC, OPEN]:
         domain = Domain(shape, boundaries=(boundary, boundary))
         centered_grid = CenteredGrid.sample(1, domain)
         result_array = (centered_grid * centered_grid.copied_with(
             data=2 * np.ones([1] + shape + [1]))).data
         np.testing.assert_array_equal(result_array, 2)
Example #5
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)
Example #6
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)
Example #7
0
    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)


def _test_all(solver):
    for domain in DOMAINS:
        _test_solve_no_obstacles(domain, solver)
    _test_random_closed(solver)
    _test_random_open(solver)
    _test_random_periodic(solver)


DOMAINS = [
    Domain([4, 5], boundaries=CLOSED),
    Domain([4, 5], boundaries=OPEN),
    Domain([4, 5], boundaries=PERIODIC),
    Domain([4, 5], boundaries=[CLOSED, PERIODIC]),
    Domain([4, 5], boundaries=[CLOSED, OPEN]),
    Domain([4, 5], boundaries=[PERIODIC, OPEN]),
]


class TestPoissonSolve(TestCase):

    def test_equal_results(self):
        data_in = _generate_examples()
        for domain in DOMAINS:
            pressure_fields = [poisson_solve(domain.centered_grid(data_in), domain, solver=solver)[0].data
                               for solver in [SparseCG(), GeometricCG()]]