예제 #1
0
def test_setting_boundary_conditions():
    """ test setting some boundary conditions """
    grid = CylindricalGrid(1, [0, 1], 3)
    b_inner = NeumannBC(grid, 0, upper=False)

    assert grid.get_boundary_conditions("natural")[0].low == b_inner
    assert grid.get_boundary_conditions({"value": 2})[0].low != b_inner
예제 #2
0
def test_laplace_cyl():
    """ test the implementation of the laplace operator """
    for boundary_z in ["periodic", "derivative"]:
        grid = CylindricalGrid(4, (0, 5), (8, 16),
                               periodic_z=(boundary_z == "periodic"))
        a_2d = np.random.uniform(0, 1, grid.shape)

        bcs = grid.get_boundary_conditions(["derivative", boundary_z])
        lap_2d = ops.make_laplace(bcs)
        b_2d = lap_2d(a_2d)
        assert b_2d.shape == grid.shape
예제 #3
0
def test_grid_div_grad():
    """ compare div grad to laplacian """
    grid = CylindricalGrid(2 * np.pi, (0, 2 * np.pi), (16, 16),
                           periodic_z=True)
    r, z = grid.cell_coords[..., 0], grid.cell_coords[..., 1]
    arr = np.cos(r) + np.sin(z)

    bcs = grid.get_boundary_conditions()
    laplace = grid.get_operator("laplace", bcs)
    grad = grid.get_operator("gradient", bcs)
    div = grid.get_operator("divergence", bcs.differentiated)
    a = laplace(arr)
    b = div(grad(arr))
    res = (-np.sin(r) / r - np.cos(r)) - np.sin(z)
    # do not test the radial boundary points
    np.testing.assert_allclose(a[1:-1], res[1:-1], rtol=0.1, atol=0.05)
    np.testing.assert_allclose(b[1:-1], res[1:-1], rtol=0.1, atol=0.05)
예제 #4
0
def test_setting_domain_cylindrical():
    """ test various versions of settings bcs for cylindrical grids """
    grid = CylindricalGrid(1, [0, 1], [2, 2], periodic_z=False)
    grid.get_boundary_conditions("natural")
    grid.get_boundary_conditions(["derivative", "derivative"])
    with pytest.raises(ValueError):
        grid.get_boundary_conditions(["derivative"])
    with pytest.raises(ValueError):
        grid.get_boundary_conditions(["derivative"] * 3)
    with pytest.raises(RuntimeError):
        grid.get_boundary_conditions(["derivative", "periodic"])

    grid = CylindricalGrid(1, [0, 1], [2, 2], periodic_z=True)
    grid.get_boundary_conditions("natural")
    grid.get_boundary_conditions(["derivative", "periodic"])
    with pytest.raises(RuntimeError):
        grid.get_boundary_conditions(["derivative", "derivative"])