Exemplo n.º 1
0
def iter_grids():
    """generate some test grids"""
    yield grids.UnitGrid([2, 2], periodic=[True, False])
    yield grids.CartesianGrid([[0, 1]], [2], periodic=[False])
    yield grids.CylindricalSymGrid(2, (0, 2), (2, 2), periodic_z=True)
    yield grids.SphericalSymGrid(2, 2)
    yield grids.PolarSymGrid(2, 2)
Exemplo n.º 2
0
def iter_grids():
    """generator providing some test grids"""
    for periodic in [True, False]:
        yield grids.UnitGrid([3], periodic=periodic)
        yield grids.UnitGrid([3, 3, 3], periodic=periodic)
        yield grids.CartesianGrid([[-1, 2], [0, 3]], [5, 7], periodic=periodic)
        yield grids.CylindricalSymGrid(3, [-1, 2], [7, 8], periodic_z=periodic)
    yield grids.PolarSymGrid(3, 4)
    yield grids.SphericalSymGrid(3, 4)
Exemplo n.º 3
0
 def iter_grids():
     """helper function iterating over different grids"""
     for periodic in [True, False]:
         yield grids.UnitGrid([3, 4], periodic=periodic)
         yield grids.CartesianGrid([[0, 1], [-2, 3]], [4, 5],
                                   periodic=periodic)
         yield grids.CylindricalSymGrid(3, [-1, 2], [5, 7],
                                        periodic_z=periodic)
     yield grids.SphericalSymGrid(4, 6)
     yield grids.PolarSymGrid(4, 5)
Exemplo n.º 4
0
def test_anti_periodic_bcs():
    """test a simulation with anti-periodic BCs"""
    grid = grids.CartesianGrid([[-10, 10]], 32, periodic=True)
    field = ScalarField.from_expression(grid, "0.01 * x**2")
    field -= field.average

    # test normal periodic BCs
    eq1 = PDE({"c": "laplace(c) + c - c**3"}, bc="periodic")
    res1 = eq1.solve(field, t_range=1e5, dt=1e-1)
    assert np.allclose(np.abs(res1.data), 1)
    assert res1.fluctuations == pytest.approx(0)

    # test normal anti-periodic BCs
    eq2 = PDE({"c": "laplace(c) + c - c**3"}, bc="anti-periodic")
    res2 = eq2.solve(field, t_range=1e3, dt=1e-3)
    assert np.all(np.abs(res2.data) <= 1)
    assert res2.fluctuations > 0.1
Exemplo n.º 5
0
def test_normalize_point(reflect):
    """ test normalize_point method """
    grid = grids.CartesianGrid([[1, 3]], [1], periodic=False)

    norm_numba = grid.make_normalize_point_compiled(reflect=reflect)

    def norm_numba_wrap(x):
        y = np.array([x])
        norm_numba(y)
        return y

    if reflect:
        values = [(0, 2), (1, 1), (2, 2), (3, 3), (4, 2), (5, 1), (6, 2)]
    else:
        values = [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]

    for norm in [
            norm_numba_wrap,
            partial(grid.normalize_point, reflect=reflect)
    ]:
        for x, y in values:
            assert norm(x) == pytest.approx(y), (norm, x)