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()]] for field in pressure_fields[1:]: np.testing.assert_almost_equal(field, pressure_fields[0], decimal=4)
def _test_solve_no_obstacles(domain, solver): print('Testing domain with boundaries: %s' % (domain.boundaries,)) data_in = _generate_examples() p = poisson_solve(domain.centered_grid(data_in), domain, solver=solver)[0] np.testing.assert_almost_equal(p.laplace().data, data_in, decimal=5) if domain.boundaries is CLOSED: np.testing.assert_almost_equal(p.laplace().data, data_in, decimal=5)
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)
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)