Skip to content

Commit

Permalink
added and changed tests that involve polyhedralprismcurrentsource end…
Browse files Browse the repository at this point in the history
… cap angles
  • Loading branch information
kj5248 committed Apr 25, 2024
1 parent 741b935 commit e3b4e65
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
20 changes: 10 additions & 10 deletions bluemira/magnetostatics/polyhedral_prism.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@ def __init__(
alpha: float,
beta: float,
current: float,
*,
bypass_endcap_error: bool | None = False,
endcap_warning: bool | None = True,
):
alpha, beta = np.deg2rad(alpha), np.deg2rad(beta)
self._origin = origin
if endcap_warning is False:
self._warning = False
self._warning = False
length = np.linalg.norm(ds)
self._halflength = 0.5 * length
self._check_angle_values(alpha, beta, bypass_endcap_error, endcap_warning)
Expand Down Expand Up @@ -461,14 +461,6 @@ def _check_angle_values(self, alpha, beta, bypass_endcap_error, endcap_warning):
Check that end-cap angles are acceptable.
"""
if bypass_endcap_error is True:
if (endcap_warning is True) and (not np.isclose(alpha, beta)):
bluemira_warn(
"Unequal end cap angles will result in result not being precise."
" This inaccuracy will increase as the end cap angle"
" discrepency increases."
)
elif (endcap_warning is False) and (not np.isclose(alpha, beta)):
self._warning = True
if not (0 <= abs(alpha) < 0.5 * np.pi):
raise MagnetostaticsError(
f"{self.__class__.__name__} instantiation error: {alpha=:.3f}"
Expand All @@ -479,6 +471,14 @@ def _check_angle_values(self, alpha, beta, bypass_endcap_error, endcap_warning):
f"{self.__class__.__name__} instantiation error: {beta=:.3f}"
" is outside bounds of [0, 180°)."
)
if (endcap_warning is True) and (not np.isclose(alpha, beta)):
bluemira_warn(
"Unequal end cap angles will result in result not being precise."
" This inaccuracy will increase as the end cap angle"
" discrepency increases."
)
elif (endcap_warning is False) and (not np.isclose(alpha, beta)):
self._warning = True
else:
if not np.isclose(alpha, beta):
raise MagnetostaticsError(
Expand Down
8 changes: 8 additions & 0 deletions tests/magnetostatics/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,14 @@ def test_continuity(self, point):
np.testing.assert_allclose(Bz, Bz_coil, rtol=1e-3)


class TestPolyhedralSourceGeneration:
def test_polyhedralprism_endcapwarning(self, caplog):
shape = PrincetonD().create_shape()
xs = Coordinates({"x": [-1, 1, 1, -1], "z": [-1, -1, 1, 1]})
circuit = ArbitraryPlanarPolyhedralXSCircuit(shape.discretize(30), xs, current=1)
assert len(caplog.records) == 1


class TestArbitraryPlanarPolyhedralPFCoil:
coordinates = make_circle(10).discretise(31)
xs = Coordinates({"x": [-1, 1, 1, -1], "z": [-1, -1, 1, 1]})
Expand Down
43 changes: 43 additions & 0 deletions tests/magnetostatics/test_polyhedral_prism.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,49 @@ def test_diff_angle_error(self):
current=1,
)

def test_diff_angle_warning(self, caplog):
PolyhedralPrismCurrentSource(
[10, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
make_xs_from_bd(0.5, 0.5),
40,
35,
current=1,
bypass_endcap_error=True,
)
assert len(caplog.records) == 1

@pytest.mark.parametrize("angle", [54, 45.0001])
def test_angle_bounds(self, angle):
with pytest.raises(MagnetostaticsError):
PolyhedralPrismCurrentSource(
[10, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
make_xs_from_bd(0.5, 0.5),
angle,
angle,
current=1,
)

@pytest.mark.parametrize(("angle1", "angle2"), [(10, 100), (100, 20)])
def test_angle_bounds_bypass(self, angle1, angle2):
with pytest.raises(MagnetostaticsError):
PolyhedralPrismCurrentSource(
[10, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
make_xs_from_bd(0.5, 0.5),
angle1,
angle2,
current=1,
bypass_endcap_error=True,
)


class TestPolyhedralMaths:
same_angle_1 = (
Expand Down

0 comments on commit e3b4e65

Please sign in to comment.