Skip to content
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
17 changes: 11 additions & 6 deletions python/gvec/util/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ def two_power(xv):
case "gauss_trunc":
if current_density:
return _gauss_legendre_integral(
lambda xv: c[0]
* (np.exp(-((xv / c[1]) ** 2)) - np.exp(-((1 / c[1]) ** 2))),
lambda xv: (
c[0] * (np.exp(-((xv / c[1]) ** 2)) - np.exp(-((1 / c[1]) ** 2)))
),
x,
)
return (
Expand Down Expand Up @@ -744,10 +745,14 @@ def power_series(kind: str) -> bool:
("zaxis_cc", "X2_a_cos"),
("zaxis_cs", "X2_a_sin"),
]:
if vmec_key not in nml:
continue
values = np.array(nml[vmec_key], dtype=float)
if values.ndim == 0:
values = np.atleast_1d(np.array(nml.get(vmec_key, []), dtype=float))
# VMEC copies the nonzero entries of the legacy RAXIS and ZAXIS into RAXIS_CC and ZAXIS_CS
legacy = {"raxis_cc": "raxis", "zaxis_cs": "zaxis"}.get(vmec_key)
if legacy in nml:
old = np.atleast_1d(np.array(nml[legacy], dtype=float))
values = np.pad(values, (0, max(0, old.size - values.size)))
values[: old.size] = np.where(old != 0.0, old, values[: old.size])
if values.size == 0:
continue
params[gvec_key] = {(0, n): v for n, v in enumerate(values)}
if not any(k in params for k in ["X1_a_cos", "X1_a_sin", "X2_a_cos", "X2_a_sin"]):
Expand Down
26 changes: 26 additions & 0 deletions test-CI/unit-pygvec/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,32 @@ def test_parameters_from_vmec_accepts_sparse_boundary_arrays():
}


def test_parameters_from_vmec_reads_legacy_and_scalar_axis():
"""VMEC copies nonzero RAXIS and ZAXIS entries into RAXIS_CC and ZAXIS_CS."""
import f90nml

nml = f90nml.reads(
"""
&INDATA
MPOL = 2
NTOR = 2
RAXIS = 5.5 0.2
ZAXIS = 0.0 -0.1
RAXIS_CC = 9.0 9.0 0.01
ZAXIS_CC = 0.3
RBC(0, 0) = 5.5 RBC(0, 1) = 0.7 ZBS(0, 1) = 0.7
/
"""
)["indata"]

parameters = util.parameters_from_vmec(nml, "legacy_axis")

assert parameters["X1_a_cos"] == {(0, 0): 5.5, (0, 1): 0.2, (0, 2): 0.01}
assert parameters["X2_a_sin"] == {(0, 0): 0.0, (0, 1): -0.1}
assert parameters["X2_a_cos"] == {(0, 0): 0.3}
assert "init_average_axis" not in parameters


def test_parameters_from_vmec_converts_vmec_profile_types():
"""Non-polynomial VMEC profiles convert to the profiles VMEC evaluates."""
import f90nml
Expand Down