def test_boundaries(): """test setting boundaries for multiple systems""" b = ["periodic", "value", {"type": "derivative", "value": 1}] for bx, by in itertools.product(b, b): periodic = [b == "periodic" for b in (bx, by)] g = UnitGrid([2, 2], periodic=periodic) bcs = Boundaries.from_data(g, [bx, by]) bc_x = get_boundary_axis(g, 0, bx) bc_y = get_boundary_axis(g, 1, by) assert bcs.grid.num_axes == 2 assert bcs.periodic == periodic assert bcs[0] == bc_x assert bcs[1] == bc_y assert "field" in bcs.get_mathematical_representation("field") assert isinstance(str(bcs), str) assert isinstance(repr(bcs), str) assert bcs == Boundaries.from_data(g, [bc_x, bc_y]) if bx == by: assert bcs == Boundaries.from_data(g, bx) bc2 = bcs.copy() assert bcs == bc2 assert bcs is not bc2 b1 = Boundaries.from_data(UnitGrid([2, 2]), "auto_periodic_neumann") b2 = Boundaries.from_data(UnitGrid([3, 3]), "auto_periodic_neumann") assert b1 != b2
def test_boundaries_edge_cases(): """test treatment of invalid data""" grid = UnitGrid([3, 3]) bcs = grid.get_boundary_conditions("auto_periodic_neumann") with pytest.raises(BCDataError): Boundaries([]) with pytest.raises(BCDataError): Boundaries([bcs[0]]) with pytest.raises(BCDataError): Boundaries([bcs[0], bcs[0]]) assert bcs == Boundaries([bcs[0], bcs[1]]) bc0 = get_boundary_axis(grid.copy(), 0, "auto_periodic_neumann") assert bcs == Boundaries([bc0, bcs[1]]) bc0 = get_boundary_axis(UnitGrid([4, 3]), 0, "auto_periodic_neumann") with pytest.raises(BCDataError): Boundaries([bc0, bcs[1]]) bc0 = get_boundary_axis(UnitGrid([3, 3], periodic=True), 0, "auto_periodic_neumann") with pytest.raises(BCDataError): Boundaries([bc0, bcs[1]])
def test_get_axis_boundaries(): """ test setting boundary conditions including periodic ones """ g = UnitGrid([2]) for data in ["value", "derivative", "periodic"]: b = get_boundary_axis(g, 0, data) assert str(b) == '"' + data + '"' if data == "periodic": assert b.periodic assert len(list(b)) == 0 else: assert not b.periodic assert len(list(b)) == 2
def test_boundaries(): """test setting boundaries for multiple systems""" b = ["periodic", "value", {"type": "derivative", "value": 1}] for bx, by in itertools.product(b, b): g = UnitGrid([2, 2], periodic=[b == "periodic" for b in (bx, by)]) bcs = Boundaries.from_data(g, [bx, by]) bc_x = get_boundary_axis(g, 0, bx) bc_y = get_boundary_axis(g, 1, by) assert bcs.grid.num_axes == 2 assert bcs[0] == bc_x assert bcs[1] == bc_y assert bcs == Boundaries.from_data(g, [bc_x, bc_y]) if bx == by: assert bcs == Boundaries.from_data(g, bx) bc2 = bcs.copy() assert bcs == bc2 assert bcs is not bc2 b1 = Boundaries.from_data(UnitGrid([2, 2]), "natural") b2 = Boundaries.from_data(UnitGrid([3, 3]), "natural") assert b1 != b2