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
7 changes: 4 additions & 3 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 @@ -1105,7 +1106,7 @@ def bspl2gvec(
def profile_from_parameters(params: CaseInsensitiveDict) -> BSpline | Polynomial:
match params.get("type", "polynomial"):
case "polynomial":
coefs = np.array(params["coefs"])
coefs = np.array(params["coefs"], dtype=float)
coefs *= params.get("scale", PARAMETER_SCALE_DEFAULT)
return np.polynomial.Polynomial(coefs)

Expand Down
9 changes: 9 additions & 0 deletions test-CI/unit-pygvec/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,12 @@ def test_compute_boundary_perturbation_removes_dropped_modes_keeps_base():
assert dict(pert["X1pert_b_cos"]) == {(2, 1): -0.03}
assert dict(pert["X1pert_b_sin"]) == {(1, 1): -0.01}
assert dict(pert["X2pert_b_sin"]) == {}


def test_polynomial_profile_with_integer_coefficients():
import numpy as np

from gvec.util.params import profile_from_parameters

iota = profile_from_parameters({"type": "polynomial", "coefs": [1], "scale": -1.0})
np.testing.assert_allclose(iota(0.5), -1.0)