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

Clebsch field line coordinate functions #1102

Merged
merged 17 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
238 changes: 234 additions & 4 deletions desc/compute/_basis_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from desc.backend import jnp

from .data_index import register_compute_fun
from .utils import cross, safediv
from .utils import cross, dot, safediv


@register_compute_fun(
Expand All @@ -34,7 +34,7 @@


@register_compute_fun(
name="e^rho",
name="e^rho", # ∇ρ is the same in (ρ,θ,ζ) and (ρ,α,ζ) coordinates.
label="\\mathbf{e}^{\\rho}",
units="m^{-1}",
units_long="inverse meters",
Expand Down Expand Up @@ -928,7 +928,7 @@


@register_compute_fun(
name="e^zeta",
name="e^zeta", # ∇ζ is the same in (ρ,θ,ζ) and (ρ,α,ζ) coordinates.
label="\\mathbf{e}^{\\zeta}",
units="m^{-1}",
units_long="inverse meters",
Expand Down Expand Up @@ -2452,7 +2452,7 @@
data=["e_theta", "theta_PEST_t"],
)
def _e_sub_theta_pest(params, transforms, profiles, data, **kwargs):
# dX/dv at const r,z = dX/dt * dt/dv / dX/dt / dv/dt
# 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

return data
Expand Down Expand Up @@ -3357,3 +3357,233 @@
def _e_sub_theta_rp(params, transforms, profiles, data, **kwargs):
data["e_theta|r,p"] = data["e_theta"] - (data["e_phi"].T * data["phi_t"]).T
return data


@register_compute_fun(
name="e_rho|a,z",
label="\\mathbf{e}_{\\rho} |_{\\alpha, \\zeta}",
units="m",
units_long="meters",
description="Tangent vector along radial field line label",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_rho", "e_alpha", "alpha_r"],
)
def _e_rho_az(params, transforms, profiles, data, **kwargs):
# constant α and ζ
data["e_rho|a,z"] = (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3377

Added line #L3377 was not covered by tests
data["e_rho"] - data["e_alpha"] * data["alpha_r"][:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3380

Added line #L3380 was not covered by tests


@register_compute_fun(
name="e_alpha",
label="\\mathbf{e}_{\\alpha}",
units="m",
units_long="meters",
description="Tangent vector along poloidal field line label",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_theta", "alpha_t"],
)
def _e_alpha(params, transforms, profiles, data, **kwargs):
# constant ρ and ζ
data["e_alpha"] = data["e_theta"] / data["alpha_t"][:, jnp.newaxis]
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3398-L3399

Added lines #L3398 - L3399 were not covered by tests


@register_compute_fun(
name="e_alpha_t",
label="\\partial_{\\theta} \\mathbf{e}_{\\alpha}",
units="m",
units_long="meters",
description="Tangent vector along poloidal field line label, derivative wrt"
" DESC poloidal angle",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_theta", "alpha_t", "e_theta_t", "alpha_tt"],
)
def _e_alpha_t(params, transforms, profiles, data, **kwargs):
data["e_alpha_t"] = (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3417

Added line #L3417 was not covered by tests
data["e_theta_t"] / data["alpha_t"][:, jnp.newaxis]
- data["e_theta"] * (data["alpha_tt"] / data["alpha_t"] ** 2)[:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3421

Added line #L3421 was not covered by tests


@register_compute_fun(
name="e_alpha_z",
label="\\partial_{\\zeta} \\mathbf{e}_{\\alpha}",
units="m",
units_long="meters",
description="Tangent vector along poloidal field line label, "
"derivative wrt DESC toroidal angle",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_theta", "alpha_t", "e_theta_z", "alpha_tz"],
)
def _e_alpha_z(params, transforms, profiles, data, **kwargs):
data["e_alpha_z"] = (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3439

Added line #L3439 was not covered by tests
data["e_theta_z"] / data["alpha_t"][:, jnp.newaxis]
- data["e_theta"] * (data["alpha_tz"] / data["alpha_t"] ** 2)[:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3443

Added line #L3443 was not covered by tests


@register_compute_fun(
name="e_zeta|r,a", # Same as B/(B⋅∇ζ).
label="\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha} "
"= \\frac{\\mathbf{B}}{\\mathbf{B} \\cdot \\nabla \\zeta}",
units="m",
units_long="meters",
description="Tangent vector along (collinear to) field line",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_zeta", "e_alpha", "alpha_z"],
)
def _e_zeta_ra(params, transforms, profiles, data, **kwargs):
data["e_zeta|r,a"] = (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3461

Added line #L3461 was not covered by tests
data["e_zeta"] - data["e_alpha"] * data["alpha_z"][:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3464

Added line #L3464 was not covered by tests


@register_compute_fun(
name="(e_zeta|r,a)_t",
label="\\partial_{\\theta} (\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha})",
units="m",
units_long="meters",
description="Tangent vector along (collinear to) field line, "
"derivative wrt DESC poloidal angle",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_zeta_t", "e_alpha", "alpha_z", "e_alpha_t", "alpha_tz"],
)
def _e_zeta_ra_t(params, transforms, profiles, data, **kwargs):
data["(e_zeta|r,a)_t"] = data["e_zeta_t"] - (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3482

Added line #L3482 was not covered by tests
data["e_alpha_t"] * data["alpha_z"][:, jnp.newaxis]
+ data["e_alpha"] * data["alpha_tz"][:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3486

Added line #L3486 was not covered by tests


@register_compute_fun(
name="(e_zeta|r,a)_a",
label="\\partial_{\\alpha} (\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha})",
units="m",
units_long="meters",
description="Tangent vector along (collinear to) field line, derivative "
"wrt field line poloidal label",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["(e_zeta|r,a)_t", "alpha_t"],
)
def _e_zeta_ra_a(params, transforms, profiles, data, **kwargs):
data["(e_zeta|r,a)_a"] = data["(e_zeta|r,a)_t"] / data["alpha_t"][:, jnp.newaxis]
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3504-L3505

Added lines #L3504 - L3505 were not covered by tests


@register_compute_fun(
name="(e_zeta|r,a)_z",
label="\\partial_{\\zeta} (\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha})",
units="m",
units_long="meters",
description="Tangent vector along (collinear to) field line, "
"derivative wrt DESC toroidal angle",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_zeta_z", "e_alpha", "alpha_z", "e_alpha_z", "alpha_zz"],
)
def _e_zeta_ra_z(params, transforms, profiles, data, **kwargs):
data["(e_zeta|r,a)_z"] = data["e_zeta_z"] - (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3523

Added line #L3523 was not covered by tests
data["e_alpha_z"] * data["alpha_z"][:, jnp.newaxis]
+ data["e_alpha"] * data["alpha_zz"][:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3527

Added line #L3527 was not covered by tests


@register_compute_fun(
name="(e_zeta|r,a)_z|r,a",
label="\\partial_{\\zeta} (\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha}) "
"|_{\\rho, \\alpha}",
units="m",
units_long="meters",
description="Curvature vector along field line",
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["(e_zeta|r,a)_z", "(e_zeta|r,a)_a", "alpha_z"],
)
def _e_zeta_z_ra(params, transforms, profiles, data, **kwargs):
data["(e_zeta|r,a)_z|r,a"] = (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3545

Added line #L3545 was not covered by tests
data["(e_zeta|r,a)_z"]
- data["(e_zeta|r,a)_a"] * data["alpha_z"][:, jnp.newaxis]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3549

Added line #L3549 was not covered by tests


@register_compute_fun(
name="|e_zeta|r,a|", # Often written as |dℓ/dζ| = |B/(B⋅∇ζ)|.
label="|\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha}|"
" = \\frac{|\\mathbf{B}|}{|\\mathbf{B} \\cdot \\nabla \\zeta|}",
units="m",
units_long="meters",
description="Differential length along field line",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e_zeta|r,a"],
)
def _d_ell_d_zeta(params, transforms, profiles, data, **kwargs):
data["|e_zeta|r,a|"] = jnp.linalg.norm(data["e_zeta|r,a"], axis=-1)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3567-L3568

Added lines #L3567 - L3568 were not covered by tests


@register_compute_fun(
name="|e_zeta|r,a|_z|r,a",
label="\\partial_{\\zeta} |\\mathbf{e}_{\\zeta} |_{\\rho, \\alpha}| "
"|_{\\rho, \\alpha}",
units="m",
units_long="meters",
description="Differential length along field line, derivative along field line",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["|e_zeta|r,a|", "(e_zeta|r,a)_z|r,a", "e_zeta|r,a"],
)
def _d_ell_d_zeta_z(params, transforms, profiles, data, **kwargs):
data["|e_zeta|r,a|_z|r,a"] = (

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3586

Added line #L3586 was not covered by tests
dot(data["(e_zeta|r,a)_z|r,a"], data["e_zeta|r,a"]) / data["|e_zeta|r,a|"]
)
return data

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

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L3589

Added line #L3589 was not covered by tests
Loading
Loading