Skip to content

Commit

Permalink
Merge branch 'master' into clebsh_basis
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanici authored Jul 8, 2024
2 parents f53c8fa + f187a12 commit 5d69f25
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions desc/coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,9 +1153,15 @@ def from_symmetry(cls, coils, NFP=1, sym=False):
"""
if not isinstance(coils, CoilSet):
coils = CoilSet(coils)

[_check_type(coil, coils[0]) for coil in coils]
try:
coils = CoilSet(coils)
except (TypeError, ValueError):
# likely there are multiple coil types,
# so make a MixedCoilSet
coils = MixedCoilSet(coils)
if not isinstance(coils, MixedCoilSet):
# only need to check this for a CoilSet, not MixedCoilSet
[_check_type(coil, coils[0]) for coil in coils]

# check toroidal extent of coils to be repeated
maxphi = 2 * np.pi / NFP / (sym + 1)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ def test_from_symmetry(self):
)[0]
np.testing.assert_allclose(B_true, B_approx, rtol=1e-3, atol=1e-10)

# With a MixedCoilSet as the base coils and only rotation
coil = FourierPlanarCoil(I)
coils = [coil] + [FourierXYZCoil(I) for i in range(N // 4 - 1)]
for i, c in enumerate(coils[1:]):
c.rotate(angle=2 * np.pi / N * (i + 1))
coils = MixedCoilSet.from_symmetry(coils, NFP=4)
grid = LinearGrid(N=32, endpoint=False)
transforms = get_transforms(["x", "x_s", "ds"], coil, grid=grid)
B_approx = coils.compute_magnetic_field(
[10, 0, 0], basis="rpz", source_grid=grid
)[0]
np.testing.assert_allclose(B_true, B_approx, rtol=1e-3, atol=1e-10)

@pytest.mark.unit
def test_properties(self):
"""Test getting/setting of CoilSet attributes."""
Expand Down

0 comments on commit 5d69f25

Please sign in to comment.