示例#1
0
 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)
示例#2
0
 def simulate(centers):
     world = World()
     fluid = world.add(Fluid(Domain([5, 4], boundaries=CLOSED, box=AABox(0, [40, 32])),
                             buoyancy_factor=0.1,
                             batch_size=centers.shape[0]),
                       physics=IncompressibleFlow(pressure_solver=SparseCG(max_iterations=3)))
     world.add(Inflow(Sphere(center=centers, radius=3), rate=0.2))
     world.add(Fan(Sphere(center=centers, radius=5), acceleration=[1.0, 0]))
     world.step(dt=1.5)
     world.step(dt=1.5)
     world.step(dt=1.5)
     print()
     return fluid.density.data[0, ...], fluid.velocity.unstack()[0].data[0, ...], fluid.velocity.unstack()[1].data[0, ...]
示例#3
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)
示例#4
0
 def test_sparse_cg(self):
     _test_all(SparseCG())
示例#5
0
 def test_sparse_cg(self):
     solver = SparseCG()
     for domain in DOMAINS:
         _test_solve_no_obstacles(domain, solver)
示例#6
0
    if domain.boundaries is CLOSED:
        np.testing.assert_almost_equal(p.laplace().data, data_in, decimal=5)
    # rows = math.unstack(p.data, 1)
    # for row in rows[1:]:
    #     np.testing.assert_almost_equal(row, rows[0], decimal=5)


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

SOLVERS = [SparseCG(), GeometricCG()]


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 SOLVERS
            ]
            for field in pressure_fields[1:]:
                np.testing.assert_almost_equal(field,
                                               pressure_fields[0],
                                               decimal=4)