Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixOmniBmax bug fix #1268

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desc/objectives/linear_objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -3065,7 +3065,7 @@
np.logical_and((basis.modes[:, 1] % 2 == 0), basis.modes[:, 1] > 0),
)
)[0]
mm = basis.modes[idx_m, 2]
mm = basis.modes[idx_m, 1]

Check warning on line 3068 in desc/objectives/linear_objectives.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/linear_objectives.py#L3068

Added line #L3068 was not covered by tests
self._A[i, idx_0] = 1
self._A[i, idx_m] = (mm % 2 - 1) * (mm % 4 - 1)

Expand Down
21 changes: 21 additions & 0 deletions tests/test_linear_objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
FixNearAxisLambda,
FixNearAxisR,
FixNearAxisZ,
FixOmniBmax,
FixOmniMap,
FixOmniWell,
FixParameters,
Expand Down Expand Up @@ -915,6 +916,26 @@ def test_fix_omni_indices():
assert constraint.dim_f == indices.size


@pytest.mark.unit
def test_fix_omni_Bmax():
"""Test that omnigenity parameters are constrained for B_max to be a straight line.

Test for GH issue #1266.
"""

def _test(M_x, N_x, NFP, sum):
field = OmnigenousField(L_x=2, M_x=M_x, N_x=N_x, NFP=NFP, helicity=(1, NFP))
constraint = FixOmniBmax(field=field)
constraint.build()
assert constraint.dim_f == (2 * field.N_x + 1) * (field.L_x + 1)
# 0 - 2 + 4 - 6 + 8 ...
np.testing.assert_allclose(constraint._A @ field.x_basis.modes[:, 1], sum)

_test(M_x=6, N_x=3, NFP=1, sum=-4)
_test(M_x=9, N_x=4, NFP=2, sum=4)
_test(M_x=12, N_x=5, NFP=3, sum=6)


@pytest.mark.unit
def test_fix_parameters_input_order(DummyStellarator):
"""Test that FixParameters preserves the input indices and target ordering."""
Expand Down