Ejemplo n.º 1
0
def test_polar_annulus():
    """ test simple polar grid with a hole """
    grid = PolarGrid((2, 4), 8)
    assert grid.dim == 2
    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(np.pi * (4**2 - 2**2))
    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.get_operator("laplace", "natural")(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(1.99))

    # 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]))
Ejemplo n.º 2
0
def test_polar_grid():
    """ test simple polar grid """
    grid = PolarGrid(4, 8)
    assert grid.dim == 2
    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(np.pi * 4**2)
    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.get_operator("laplace", "natural")(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