Skip to content

Commit e550ef3

Browse files
committed
Merge remote-tracking branch 'origin/master' into yge/deps
2 parents 2dc5afe + e80e4bb commit e550ef3

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Bug Fixes
2020
- Fixes a bug in `OmnigenousField.change_resolution` when changing `L_B`.
2121
- Scaling a `ScaledProfile` or taking power of a `PowerProfile` now only updates the `scale`/`power` attributes instead of nesting the `ScaledProfile`/`PowerProfile`s.
2222
- `jax.Array`s in `_static_attrs` will be automatically converted to `np.ndarray` to prevent stalling code. In general, jax arrays should be omitted in `_static_attrs`.
23+
- Fixes a bug in `desc.magnetic_fields.field_integrate` when calling with an integer `bs_chunk_size`.
2324

2425
Performance Improvements
2526

desc/magnetic_fields/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from netCDF4 import Dataset, chartostring, stringtochar
2020
from scipy.constants import mu_0
2121

22-
from desc.backend import jit, jnp, sign
22+
from desc.backend import jnp, sign
2323
from desc.basis import (
2424
ChebyshevDoubleFourierBasis,
2525
ChebyshevPolynomial,
@@ -2816,8 +2816,8 @@ def _intfun_wrapper(
28162816
)
28172817

28182818

2819-
@jit
28202819
def _odefun(s, rpz, args):
2820+
# Note: this function is already jitted by diffeqsolve
28212821
field, params, scale, source_grid, bs_chunk_size = args
28222822
r = rpz[0]
28232823
br, bp, bz = (

tests/test_magnetic_fields.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from desc.backend import jax, jit, jnp
1717
from desc.basis import DoubleFourierSeries
18+
from desc.coils import CoilSet, FourierPlanarCoil
1819
from desc.compute.utils import get_params, get_transforms
1920
from desc.examples import get
2021
from desc.geometry import FourierRZToroidalSurface, FourierXYZCurve
@@ -1212,6 +1213,31 @@ def test_field_line_integrate(self):
12121213
np.testing.assert_allclose(r[-1], 10, rtol=1e-6, atol=1e-6)
12131214
np.testing.assert_allclose(z[-1], 0.001, rtol=1e-6, atol=1e-6)
12141215

1216+
@pytest.mark.unit
1217+
def test_field_line_integrate_coil_bs_chunk(self):
1218+
"""Test field line integration for coils with bs_chunk_size."""
1219+
# Related to issue #2214
1220+
# simple toroidal field
1221+
B0 = 1
1222+
R0 = 4
1223+
I = 2 * np.pi * B0 * R0 / mu_0
1224+
field = CoilSet(
1225+
FourierPlanarCoil(
1226+
current=I,
1227+
center=[R0, 0, 0],
1228+
normal=[0, 1, 0],
1229+
r_n=R0 / 4,
1230+
),
1231+
NFP=40,
1232+
check_intersection=False,
1233+
)
1234+
r0 = [10.0]
1235+
z0 = [0.0]
1236+
phis = [0, np.pi]
1237+
r, z = field_line_integrate(r0, z0, phis, field, bs_chunk_size=1000)
1238+
np.testing.assert_allclose(r[-1], r0[0], rtol=1e-6, atol=1e-6)
1239+
np.testing.assert_allclose(z[-1], z0[0], rtol=1e-6, atol=1e-6)
1240+
12151241
@pytest.mark.unit
12161242
def test_field_line_integrate_jax_transforms(self, capsys):
12171243
"""Test field line integration is JAX transformable."""

0 commit comments

Comments
 (0)