Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix math bug in surface computations #1175

Merged
merged 7 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Undo mod by 2pi on phi
unalmis committed Aug 12, 2024

Verified

This commit was signed with the committer’s verified signature.
unalmis Kaya Unalmis
commit dd562816abc7802d34312f423d09d9c615a61aea
2 changes: 1 addition & 1 deletion desc/compute/_core.py
Original file line number Diff line number Diff line change
@@ -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


18 changes: 15 additions & 3 deletions tests/test_equilibrium.py
Original file line number Diff line number Diff line change
@@ -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

@@ -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")