Skip to content

Commit

Permalink
Undo mod by 2pi on phi
Browse files Browse the repository at this point in the history
  • Loading branch information
unalmis committed Aug 12, 2024
1 parent a43a5bf commit dd56281
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion desc/compute/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,7 @@ def _zeta(params, transforms, profiles, data, **kwargs):
data=["zeta", "omega"],
)
def _phi(params, transforms, profiles, data, **kwargs):
data["phi"] = (data["zeta"] + data["omega"]) % (2 * jnp.pi)
data["phi"] = data["zeta"] + data["omega"]
return data


Expand Down
18 changes: 15 additions & 3 deletions tests/test_equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from desc.io import InputReader
from desc.objectives import ForceBalance, ObjectiveFunction, get_equilibrium_objective
from desc.profiles import PowerSeriesProfile
from desc.utils import errorif

from .utils import area_difference, compute_coords

Expand Down Expand Up @@ -55,16 +56,27 @@ def test_map_coordinates():
iota = grid.compress(eq.compute("iota", grid=grid)["iota"])
iota = np.broadcast_to(iota, shape=(n,))

out_1 = eq.map_coordinates(coords, inbasis=["rho", "alpha", "zeta"], iota=iota)
tol = 1e-5
out_1 = eq.map_coordinates(
coords, inbasis=["rho", "alpha", "zeta"], iota=iota, tol=tol
)
assert np.isfinite(out_1).all()
out_2 = eq.map_coordinates(
coords,
inbasis=["rho", "alpha", "zeta"],
period=(np.inf, 2 * np.pi, np.inf),
tol=tol,
)
assert np.isfinite(out_2).all()
diff = (out_1 - out_2) % (2 * np.pi)
assert np.all(np.isclose(diff, 0) | np.isclose(np.abs(diff), 2 * np.pi))
diff = out_1 - out_2
errorif(
not np.all(
np.isclose(diff, 0, atol=2 * tol)
| np.isclose(np.abs(diff), 2 * np.pi, atol=2 * tol)
),
AssertionError,
f"diff: {diff}",
)

eq = get("DSHAPE")

Expand Down

0 comments on commit dd56281

Please sign in to comment.