def test_spherical_annulus(): """test simple spherical grid with a hole""" grid = SphericalSymGrid((2, 4), 8) assert grid.dim == 3 assert grid.numba_type == "f8[:]" assert grid.shape == (8,) assert grid.has_hole assert grid.discretization[0] == pytest.approx(0.25) assert not grid.uniform_cell_volumes np.testing.assert_array_equal(grid.discretization, np.array([0.25])) assert grid.volume == pytest.approx(4 / 3 * np.pi * (4**3 - 2**3)) assert grid.volume == pytest.approx(grid.integrate(1)) assert grid.radius == (2, 4) np.testing.assert_allclose(grid.axes_coords[0], np.linspace(2.125, 3.875, 8)) a = grid.make_operator("laplace", "auto_periodic_neumann")(np.random.random(8)) assert a.shape == (8,) assert np.all(np.isfinite(a)) assert grid.contains_point(grid.get_random_point(coords="cartesian")) p = grid.get_random_point(boundary_distance=1.99, coords="cartesian") assert grid.contains_point(p) # test boundary points np.testing.assert_equal(grid._boundary_coordinates(0, False), np.array([2])) np.testing.assert_equal(grid._boundary_coordinates(0, True), np.array([4]))
def test_spherical_grid(): """test simple spherical grid""" grid = SphericalSymGrid(4, 8) assert grid.dim == 3 assert grid.numba_type == "f8[:]" assert grid.shape == (8, ) assert not grid.has_hole assert grid.discretization[0] == pytest.approx(0.5) assert not grid.uniform_cell_volumes np.testing.assert_array_equal(grid.discretization, np.array([0.5])) assert grid.volume == pytest.approx(4 / 3 * np.pi * 4**3) assert grid.volume == pytest.approx(grid.integrate(1)) np.testing.assert_allclose(grid.axes_coords[0], np.linspace(0.25, 3.75, 8)) a = grid.make_operator("laplace", "auto_periodic_neumann")(np.random.random(8)) assert a.shape == (8, ) assert np.all(np.isfinite(a)) # random points c = np.random.randint(8, size=(6, 1)) p = grid.cell_to_point(c) np.testing.assert_array_equal(c, grid.point_to_cell(p)) assert grid.contains_point(grid.get_random_point()) assert grid.contains_point(grid.get_random_point(3.99)) assert "laplace" in grid.operators