Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8fb2b38
Add fft grid and raz grid to test against master
unalmis Apr 10, 2026
25164d0
remove noise by tighten tolerance
unalmis Apr 10, 2026
0d23c66
final attempt
unalmis Apr 10, 2026
5e70567
rory comment
unalmis Apr 10, 2026
945f1af
fix last commit
unalmis Apr 10, 2026
c2ecc4b
Increase correlation in discretization error for optimization
unalmis Apr 12, 2026
bb8ac6a
Merge branch 'master' into ku/test
unalmis Apr 12, 2026
7489317
.
unalmis Apr 12, 2026
e240249
increase tol for test
unalmis Apr 12, 2026
be41c58
remove not implemented todo
unalmis Apr 12, 2026
a55b170
.
unalmis Apr 12, 2026
2cff860
add back short-circuit
unalmis Apr 12, 2026
1727fba
collect redundant docs
unalmis Apr 13, 2026
339643b
Fix if statements
unalmis Apr 13, 2026
bda562a
Merge branch 'master' into ku/test
f0uriest Apr 13, 2026
ff53f80
Resolves #2162
unalmis Apr 14, 2026
83ffee6
loosen tol on test
unalmis Apr 14, 2026
ccf228f
flake8
unalmis Apr 14, 2026
f8a3515
flake8 blank line space
unalmis Apr 14, 2026
d05bda1
future proof
unalmis Apr 15, 2026
c06687d
daniel comments
unalmis Apr 15, 2026
d5a682f
fix render
unalmis Apr 16, 2026
f325bbf
Apply suggestions from code review
unalmis Apr 16, 2026
1792e91
Apply suggestions from code review
unalmis Apr 16, 2026
89479dc
Apply suggestions from code review
unalmis Apr 16, 2026
947641b
dan comment v2
unalmis Apr 16, 2026
13b6870
dan v2
unalmis Apr 16, 2026
a58c075
more dan
unalmis Apr 16, 2026
ad86912
last dan
unalmis Apr 16, 2026
f4faed4
last commit to desc
unalmis Apr 16, 2026
c42a92b
flake
unalmis Apr 16, 2026
2a5d6c2
Merge branch 'master' into ku/test
unalmis Apr 17, 2026
585d59a
Merge branch 'master' into ku/test
unalmis Apr 18, 2026
fcea971
Merge branch 'master' into ku/test
dpanici Apr 19, 2026
571c7d5
Merge branch 'master' into ku/test
unalmis Apr 23, 2026
fdf80fe
Merge branch 'master' into ku/test
f0uriest Apr 29, 2026
3fe1120
Merge branch 'master' into ku/test
f0uriest Apr 29, 2026
2de27b0
Merge branch 'master' into ku/test
unalmis Apr 30, 2026
9b9d666
Merge branch 'master' into ku/test
unalmis May 1, 2026
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
Binary file removed tests/baseline/test_Gamma_c_Nemov_1D.png
Binary file not shown.
Binary file removed tests/baseline/test_Gamma_c_Nemov_2D_0.png
Binary file not shown.
Binary file removed tests/baseline/test_Gamma_c_Nemov_2D_1e-07.png
Binary file not shown.
Binary file removed tests/baseline/test_Gamma_c_Velasco_1D.png
Binary file not shown.
Binary file removed tests/baseline/test_Gamma_c_Velasco_2D_0.png
Binary file not shown.
Binary file removed tests/baseline/test_Gamma_c_Velasco_2D_1e-07.png
Binary file not shown.
Binary file removed tests/baseline/test_effective_ripple_1D.png
Binary file not shown.
Binary file removed tests/baseline/test_effective_ripple_2D_0.png
Binary file not shown.
Binary file removed tests/baseline/test_effective_ripple_2D_1e-06.png
Binary file not shown.
Binary file modified tests/inputs/master_compute_data_rpz.pkl
Binary file not shown.
66 changes: 64 additions & 2 deletions tests/test_compute_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
FourierXYZCurve,
ZernikeRZToroidalSection,
)
from desc.grid import LinearGrid
from desc.grid import Grid, LinearGrid
from desc.integrals import Bounce2D
from desc.magnetic_fields import (
CurrentPotentialField,
FourierCurrentPotentialField,
OmnigenousField,
)
from desc.utils import ResolutionWarning, errorif, xyz2rpz, xyz2rpz_vec
from desc.utils import ResolutionWarning, apply, errorif, xyz2rpz, xyz2rpz_vec


def _compare_against_master(
Expand Down Expand Up @@ -259,6 +260,11 @@ def need_special(name):
f"Parameterization: {p}. Can't compute "
+ f"{names - this_branch_data_rpz[p].keys()}."
)

# now we get the special grid data
this_branch_data_rpz[p].update(fft_grid_data(p))
this_branch_data_rpz[p].update(raz_grid_data(p))

# compare data against master branch
error_rpz, update_master_data_rpz = _compare_against_master(
p,
Expand Down Expand Up @@ -297,3 +303,59 @@ def need_special(name):
pickle.dump(this_branch_data_rpz, file)

assert not error_rpz


def fft_grid_data(p):
"""Compute fft grid quantities."""
if p != "desc.equilibrium.equilibrium.Equilibrium":
return {}

# TODO: can automate this later to add omngeneity, boozer transform, etc.
fft_names = ["effective ripple", "Gamma_c", "Gamma_c Velasco"]

eq = get("W7-X")
rho = np.linspace(0, 1, 10)
grid = LinearGrid(rho=rho, M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, sym=False)

kwargs = dict(
angle=Bounce2D.angle(eq, X=32, Y=32, rho=rho),
Y_B=grid.num_zeta * grid.NFP,
num_transit=10,
num_well=20 * 10,
nufft_eps=1e-8,
)
data = eq.compute(fft_names, grid, surf_batch_size=1, **kwargs)

# check vectorization too
d = data.copy()
for name in fft_names:
d.pop(name)
d = eq.compute(fft_names, grid, surf_batch_size=2, data=d, **kwargs)
for name in fft_names:
np.testing.assert_allclose(
d[name], data[name], rtol=1e-8, atol=1e-8, err_msg=name
)

data = apply(data, grid.compress, fft_names)
return data


def raz_grid_data(p):
"""Compute field line grid quantities."""
if p != "desc.equilibrium.equilibrium.Equilibrium":
return {}

# TODO: can automate this later to add ballooning etc.
raz_names = ["old effective ripple", "old Gamma_c", "old Gamma_c Velasco"]

eq = get("W7-X")
num_transit = 10
Y_B = eq.N_grid * 2 * eq.NFP
rho = np.linspace(0, 1, 10)
alpha = np.array([0])
zeta = np.linspace(0, num_transit * 2 * np.pi, num_transit * Y_B)
grid = Grid.create_meshgrid([rho, alpha, zeta], coordinates="raz")

data = eq.compute(raz_names, grid, num_well=20 * num_transit)
data = apply(data, grid.compress, raz_names)
return data
39 changes: 39 additions & 0 deletions tests/test_compute_funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,45 @@ def test_parallel_grad_fd(DummyStellarator):
)


@pytest.mark.unit
@pytest.mark.slow
def test_fieldline_average():
Comment thread
unalmis marked this conversation as resolved.
"""Test that fieldline average converges to surface average."""
rho = np.array([1])
alpha = np.array([0])
eq = get("DSHAPE")
iota_grid = LinearGrid(rho=rho, M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, sym=eq.sym)
iota = iota_grid.compress(eq.compute("iota", grid=iota_grid)["iota"]).item()
# For axisymmetric devices, one poloidal transit must be exact.
zeta = np.linspace(0, 2 * np.pi / iota, 25)
grid = Grid.create_meshgrid([rho, alpha, zeta], coordinates="raz")
data = eq.compute(
["fieldline length", "fieldline length/volume", "V_r(r)"], grid=grid
)
np.testing.assert_allclose(
data["fieldline length"] / data["fieldline length/volume"],
data["V_r(r)"] / (4 * np.pi**2),
rtol=1e-3,
)
assert np.all(data["fieldline length"] > 0)
assert np.all(data["fieldline length/volume"] > 0)

# Otherwise, many toroidal transits are necessary to sample surface.
eq = get("W7-X")
zeta = np.linspace(0, 40 * np.pi, 300)
grid = Grid.create_meshgrid([rho, alpha, zeta], coordinates="raz")
data = eq.compute(
["fieldline length", "fieldline length/volume", "V_r(r)"], grid=grid
)
np.testing.assert_allclose(
data["fieldline length"] / data["fieldline length/volume"],
data["V_r(r)"] / (4 * np.pi**2),
rtol=2e-3,
)
assert np.all(data["fieldline length"] > 0)
assert np.all(data["fieldline length/volume"] > 0)


@pytest.mark.unit
def test_compute_deprecation_warning():
"""Test DeprecationWarning for deprecated compute names."""
Expand Down
100 changes: 0 additions & 100 deletions tests/test_fast_ion.py
Comment thread
unalmis marked this conversation as resolved.
Outdated

This file was deleted.

115 changes: 0 additions & 115 deletions tests/test_neoclassical.py
Comment thread
unalmis marked this conversation as resolved.
Outdated

This file was deleted.

Loading