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

PEST coordinate system basis vectors #1090

Merged
merged 22 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
42e6112
Genearlize PEST coordinate system compute funs to genearlized toroida…
unalmis Jul 1, 2024
b65351a
BUGFIX: don't change basis to xyz erroneously assuming input is in rpz
unalmis Jul 1, 2024
4c4553a
BUGFIX: don't change basis to xyz erroneously assuming input is in rpz
unalmis Jul 1, 2024
a145e6f
Fix issue with merge
unalmis Jul 1, 2024
455a9a3
Fix issue with merge
unalmis Jul 1, 2024
bd840b9
Merge branch 'basis_bug' into sfl_coordinates
unalmis Jul 1, 2024
031d29e
Add guards to compute funs that should be fixed in GitHub pull reques…
unalmis Jul 1, 2024
571f187
add missing basis kwarg to e_phi|R,Z
unalmis Jul 2, 2024
41033d7
Merge branch 'basis_bug' into sfl_coordinates
unalmis Jul 2, 2024
7aa74ce
review suggestions
unalmis Jul 2, 2024
e7e6572
Merge branch 'master' into basis_bug
dpanici Jul 3, 2024
4266028
Merge branch 'basis_bug' into sfl_coordinates
unalmis Jul 3, 2024
4192967
Review requests
unalmis Jul 3, 2024
35ec354
Remove e_phi|R,Z
unalmis Jul 3, 2024
eebeb90
Merge branch 'master' into basis_bug
unalmis Jul 5, 2024
6341542
Merge branch 'master' into basis_bug
unalmis Jul 5, 2024
92717c0
Merge branch 'basis_bug' into sfl_coordinates
unalmis Jul 5, 2024
449d332
Remove code that merge didn't remove
unalmis Jul 5, 2024
33e1e81
Use master_compute_data from master
unalmis Jul 5, 2024
8e9f43a
Merge branch 'master' into sfl_coordinates
unalmis Jul 11, 2024
a2c5cf9
Fix merge conflicts from basing branch of now closed basis_bug
unalmis Jul 11, 2024
2dad8f8
Merge branch 'master' into sfl_coordinates
unalmis Jul 20, 2024
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
91 changes: 70 additions & 21 deletions desc/compute/_basis_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@
/ data["sqrt(g)"] ** 2
+ 2 * temp.T * data["sqrt(g)_r"] * data["sqrt(g)_r"] / data["sqrt(g)"] ** 3
).T

return data


Expand Down Expand Up @@ -1140,7 +1139,6 @@
/ data["sqrt(g)"] ** 2
+ 2 * temp.T * data["sqrt(g)_r"] * data["sqrt(g)_z"] / data["sqrt(g)"] ** 3
).T

return data


Expand Down Expand Up @@ -1184,7 +1182,6 @@
* safediv(data["sqrt(g)_rt"], data["sqrt(g)_r"] ** 2)
).T,
)

return data


Expand Down Expand Up @@ -1235,7 +1232,6 @@
/ data["sqrt(g)"] ** 2
+ 2 * temp.T * data["sqrt(g)_t"] * data["sqrt(g)_t"] / data["sqrt(g)"] ** 3
).T

return data


Expand Down Expand Up @@ -1291,7 +1287,6 @@
/ data["sqrt(g)"] ** 2
+ 2 * temp.T * data["sqrt(g)_t"] * data["sqrt(g)_z"] / data["sqrt(g)"] ** 3
).T

return data


Expand Down Expand Up @@ -1335,7 +1330,6 @@
* safediv(data["sqrt(g)_rz"], data["sqrt(g)_r"] ** 2)
).T,
)

return data


Expand Down Expand Up @@ -1386,16 +1380,15 @@
/ data["sqrt(g)"] ** 2
+ 2 * temp.T * data["sqrt(g)_z"] * data["sqrt(g)_z"] / data["sqrt(g)"] ** 3
).T

return data


@register_compute_fun(
name="e_phi",
label="\\mathbf{e}_{\\phi}",
name="e_phi|r,t",
label="\\mathbf{e}_{\\phi} |_{\\rho, \\theta}",
units="m",
units_long="meters",
description="Covariant cylindrical toroidal basis vector",
description="Covariant toroidal basis vector in (ρ,θ,ϕ) coordinates",
dim=3,
params=[],
transforms={},
Expand All @@ -1407,11 +1400,13 @@
"desc.geometry.surface.FourierRZToroidalSurface",
"desc.geometry.core.Surface",
],
aliases=["e_phi"],
# Our usual notation implies e_phi = (∂X/∂ϕ)|R,Z = R ϕ̂, but we need to alias e_phi
f0uriest marked this conversation as resolved.
Show resolved Hide resolved
# to e_phi|r,t = (∂X/∂ϕ)|ρ,θ for compatibility with older versions of the code.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really care about backwards compatibility here? I doubt a lot of users have code that depends on computing "e_phi"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could deprecate it later in that case

)
def _e_sub_phi(params, transforms, profiles, data, **kwargs):
# dX/dphi at const r,t = dX/dz * dz/dphi = dX/dz / (dphi/dz)
data["e_phi"] = (data["e_zeta"].T / data["phi_z"]).T

def _e_sub_phi_rt(params, transforms, profiles, data, **kwargs):
# (∂X/∂ϕ)|ρ,θ = (∂X/∂ζ)|ρ,θ / (∂ϕ/∂ζ)|ρ,θ
data["e_phi|r,t"] = (data["e_zeta"].T / data["phi_z"]).T
return data


Expand Down Expand Up @@ -2434,27 +2429,81 @@
safediv(data["e_theta"].T, data["sqrt(g)"]).T,
lambda: safediv(data["e_theta_r"].T, data["sqrt(g)_r"]).T,
)

return data


@register_compute_fun(
name="e_theta_PEST",
label="\\mathbf{e}_{\\theta_{PEST}}",
label="\\mathbf{e}_{\\vartheta} |_{\\rho, \\phi} = \\mathbf{e}_{\\theta_{PEST}}",
units="m",
units_long="meters",
description="Covariant straight field line (PEST) poloidal basis vector",
description="Covariant poloidal basis vector in (ρ,ϑ,ϕ) coordinates or"
" straight field line PEST coordinates. ϕ increases counterclockwise"
" when viewed from above (cylindrical R,ϕ plane with Z out of page).",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_theta", "theta_PEST_t"],
data=["e_theta", "theta_PEST_t", "e_zeta", "theta_PEST_z", "phi_t", "phi_z"],
aliases=["e_vartheta"],
)
def _e_sub_theta_pest(params, transforms, profiles, data, **kwargs):
# dX/dv at const r,z = dX/dt * dt/dv / dX/dt / dv/dt
data["e_theta_PEST"] = (data["e_theta"].T / data["theta_PEST_t"]).T
def _e_sub_vartheta_rp(params, transforms, profiles, data, **kwargs):
# constant ρ and ϕ
e_vartheta = (

Check warning on line 2453 in desc/compute/_basis_vectors.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L2453

Added line #L2453 was not covered by tests
data["e_theta"].T * data["phi_z"] - data["e_zeta"].T * data["phi_t"]
) / (data["theta_PEST_t"] * data["phi_z"] - data["theta_PEST_z"] * data["phi_t"])
data["e_theta_PEST"] = e_vartheta.T
return data

Check warning on line 2457 in desc/compute/_basis_vectors.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L2456-L2457

Added lines #L2456 - L2457 were not covered by tests


@register_compute_fun(
name="e_phi|r,v",
label="\\mathbf{e}_{\\phi} |_{\\rho, \\vartheta}",
units="m",
units_long="meters",
description="Covariant toroidal basis vector in (ρ,ϑ,ϕ) coordinates or"
" straight field line PEST coordinates. ϕ increases counterclockwise"
" when viewed from above (cylindrical R,ϕ plane with Z out of page).",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_theta", "theta_PEST_t", "e_zeta", "theta_PEST_z", "phi_t", "phi_z"],
)
def _e_sub_phi_rv(params, transforms, profiles, data, **kwargs):
# constant ρ and ϑ
e_phi = (

Check warning on line 2477 in desc/compute/_basis_vectors.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L2477

Added line #L2477 was not covered by tests
data["e_zeta"].T * data["theta_PEST_t"]
- data["e_theta"].T * data["theta_PEST_z"]
) / (data["theta_PEST_t"] * data["phi_z"] - data["theta_PEST_z"] * data["phi_t"])
data["e_phi|r,v"] = e_phi.T
return data

Check warning on line 2482 in desc/compute/_basis_vectors.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L2481-L2482

Added lines #L2481 - L2482 were not covered by tests


@register_compute_fun(
name="e_rho|v,p",
label="\\mathbf{e}_{\\rho} |_{\\vartheta, \\phi}",
units="m",
units_long="meters",
description="Covariant radial basis vector in (ρ,ϑ,ϕ) coordinates or"
" straight field line PEST coordinates. ϕ increases counterclockwise"
" when viewed from above (cylindrical R,ϕ plane with Z out of page).",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_rho", "e_vartheta", "e_phi|r,v", "theta_PEST_r", "phi_r"],
)
def _e_sub_rho_vp(params, transforms, profiles, data, **kwargs):
# constant ϑ and ϕ
data["e_rho|v,p"] = (

Check warning on line 2502 in desc/compute/_basis_vectors.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L2502

Added line #L2502 was not covered by tests
data["e_rho"].T
- data["e_vartheta"].T * data["theta_PEST_r"]
- data["e_phi|r,v"].T * data["phi_r"]
).T
return data


Expand Down
12 changes: 8 additions & 4 deletions desc/compute/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@ def _sqrtg(params, transforms, profiles, data, **kwargs):
label="\\sqrt{g}_{PEST}",
units="m^{3}",
units_long="cubic meters",
description="Jacobian determinant of PEST flux coordinate system",
description="Jacobian determinant of (ρ,ϑ,ϕ) coordinate system or"
" straight field line PEST coordinates. ϕ increases counterclockwise"
" when viewed from above (cylindrical R,ϕ plane with Z out of page).",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_rho", "e_theta_PEST", "e_phi"],
data=["sqrt(g)", "theta_PEST_t", "phi_z", "theta_PEST_z", "phi_t"],
)
def _sqrtg_pest(params, transforms, profiles, data, **kwargs):
data["sqrt(g)_PEST"] = dot(
data["e_rho"], cross(data["e_theta_PEST"], data["e_phi"])
# Same as dot(data["e_rho|v,p"], cross(data["e_vartheta"], data["e_phi|r,v"])), but
# more efficient as it avoids computing radial derivatives of the stream functions.
data["sqrt(g)_PEST"] = data["sqrt(g)"] / (
data["theta_PEST_t"] * data["phi_z"] - data["theta_PEST_z"] * data["phi_t"]
)
return data

Expand Down
3 changes: 3 additions & 0 deletions desc/compute/_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .data_index import register_compute_fun
from .geom_utils import rpz2xyz

# TODO: review when zeta no longer equals phi


@register_compute_fun(
name="x",
Expand All @@ -25,6 +27,7 @@
def _x_FourierRZToroidalSurface(params, transforms, profiles, data, **kwargs):
R = transforms["R"].transform(params["R_lmn"])
Z = transforms["Z"].transform(params["Z_lmn"])
# TODO: change when zeta no longer equals phi
phi = transforms["grid"].nodes[:, 2]
coords = jnp.stack([R, phi, Z], axis=1)
# default basis for "x" is rpz, the conversion will be done
Expand Down
Binary file modified tests/inputs/master_compute_data_rpz.pkl
Binary file not shown.
Binary file modified tests/inputs/master_compute_data_xyz.pkl
Binary file not shown.
Loading