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

Add aliases for data_index #648

Merged
merged 23 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 8 additions & 2 deletions desc/compute/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,8 @@ def _g_sup_zz(params, transforms, profiles, data, **kwargs):


@register_compute_fun(
name="g^rt",
# name="g^rt"
kianorr marked this conversation as resolved.
Show resolved Hide resolved
name=["g^" + i + j for i in ['r', 't', 'z'] for j in ['r', 't', 'z']],
kianorr marked this conversation as resolved.
Show resolved Hide resolved
label="g^{\\rho\\theta}",
units="m^{-2}",
units_long="inverse square meters",
Expand All @@ -1307,7 +1308,12 @@ def _g_sup_zz(params, transforms, profiles, data, **kwargs):
data=["e^rho", "e^theta"],
)
def _g_sup_rt(params, transforms, profiles, data, **kwargs):
kianorr marked this conversation as resolved.
Show resolved Hide resolved
data["g^rt"] = dot(data["e^rho"], data["e^theta"])
# data["g^rt"] = dot(data["e^rho"], data["e^theta"])
kianorr marked this conversation as resolved.
Show resolved Hide resolved
# reruns each time but looks cleaner this way i think
aliases = ["g^" + i + j for i in ['r', 't', 'z'] for j in ['r', 't', 'z']]
kianorr marked this conversation as resolved.
Show resolved Hide resolved
for alias in aliases:
data[alias] = dot(data["e^rho"], data["e^theta"])

return data


Expand Down
7 changes: 6 additions & 1 deletion desc/compute/data_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ def _decorator(func):
raise ValueError(
f"Already registered function with parameterization {p} and name {name}."
)
data_index[base_class][name] = d.copy()
if isinstance(name, list):
data_index[base_class][name[0]] = d.copy()
for alias in name:
data_index[base_class][alias] = data_index[base_class][name[0]]
kianorr marked this conversation as resolved.
Show resolved Hide resolved
else:
data_index[base_class][name] = d.copy()
flag = True
if not flag:
raise ValueError(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_compute_funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def myconvolve_2d(arr_1d, stencil, shape):
return conv


@pytest.mark.unit
def test_aliases():
kianorr marked this conversation as resolved.
Show resolved Hide resolved
eq = Equilibrium() # torus
rho = np.linspace(0, 1, 64)
grid = LinearGrid(M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, sym=eq.sym, rho=rho)
aliases = ["g^" + i + j for i in ['r', 't', 'z'] for j in ['r', 't', 'z']]
data = eq.compute(aliases, grid=grid)
kianorr marked this conversation as resolved.
Show resolved Hide resolved
kianorr marked this conversation as resolved.
Show resolved Hide resolved
np.testing.assert_allclose([data[alias] for alias in aliases])


kianorr marked this conversation as resolved.
Show resolved Hide resolved
kianorr marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.unit
def test_total_volume(DummyStellarator):
"""Test that the volume enclosed by the LCFS is equal to the total volume."""
Expand Down
Loading