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

Gamma_c (Nemov and Velasco et. al) Γ_c #1042

Merged
merged 128 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
a4f947f
Add Gamma_c to neoclassical compute quantities
unalmis Jun 2, 2024
069036f
Merge branch 'ripple' into Gamma_c
unalmis Jun 3, 2024
2cea638
Update thing after merge
unalmis Jun 3, 2024
03694a0
Merge branch 'ripple' into Gamma_c
unalmis Jun 4, 2024
c17a9df
Add Gamma_c plot
unalmis Jun 4, 2024
c616ee5
Merge branch 'ripple' into Gamma_c
unalmis Jun 12, 2024
e0dffc6
Merge branch 'ripple' into Gamma_c
unalmis Jun 12, 2024
4947bee
Add Gamma_c objective function
unalmis Jun 13, 2024
08af99d
Merge branch 'ripple' into Gamma_c
unalmis Jun 13, 2024
9979ab5
Fix docstring
unalmis Jun 13, 2024
0810075
Merge branch 'ripple' into Gamma_c
unalmis Jun 18, 2024
5956349
Update Gamma_c test after merge
unalmis Jun 18, 2024
39f9ade
Merge branch 'ripple' into Gamma_c
unalmis Jun 18, 2024
19b58ba
Merge branch 'ripple' into Gamma_c
unalmis Jun 22, 2024
802e4ba
Merge branch 'ripple' into Gamma_c
unalmis Jun 22, 2024
b6f0614
Merge branch 'ripple' into Gamma_c
unalmis Jun 24, 2024
a6c29df
Fix calls to rtz_grid after merge
unalmis Jun 24, 2024
36d5e82
Merge branch 'ripple' into Gamma_c
unalmis Jun 25, 2024
18960f8
Merge branch 'ripple' into Gamma_c
unalmis Jun 25, 2024
f3361cb
average before integration to reduce computation
unalmis Jun 25, 2024
10e9937
Merge branch 'ripple' into Gamma_c
unalmis Jul 2, 2024
e8f240d
Merge branch 'ripple' into Gamma_c
unalmis Jul 5, 2024
ad7f2b6
Merge branch 'ripple' into Gamma_c
unalmis Jul 11, 2024
e6adeb2
remove unused jitable arg causing error
dpanici Jul 16, 2024
1462d28
remove unneeded jitable call
dpanici Jul 17, 2024
0bf73b4
Merge branch 'ripple' into Gamma_c
unalmis Jul 20, 2024
7a50240
Merge branch 'ripple' into Gamma_c
unalmis Jul 25, 2024
0348288
Merge branch 'ripple' into Gamma_c
unalmis Jul 25, 2024
1c8d4eb
Only get profiles in objective build method
unalmis Jul 25, 2024
29903ed
Merge branch 'ripple' into Gamma_c
unalmis Jul 25, 2024
2ab29a9
Add num_wells parameter to increase performance
unalmis Jul 25, 2024
6b7bcfb
Merge branch 'ripple' into Gamma_c
unalmis Jul 25, 2024
a0d68fe
Merge branch 'ripple' into Gamma_c
unalmis Jul 25, 2024
67586ff
Add num_wells to Gamma_c objective
unalmis Jul 25, 2024
204dea8
Merge branch 'ripple' into Gamma_c
unalmis Jul 26, 2024
6ec5bd2
Add num_wells as static parameter to compute fun
unalmis Jul 26, 2024
29d1e8d
Merge branch 'ripple' into Gamma_c
unalmis Jul 26, 2024
2c54f9d
Specify kwargs for trapezoid integration after quadax API changes fro…
unalmis Jul 26, 2024
921f4d5
Add Nemov's Gamma_c
unalmis Aug 5, 2024
5ca2630
Remove hanging plt.show() from last commit
unalmis Aug 5, 2024
cd3b6b6
Fix comment
unalmis Aug 5, 2024
4577d4f
Fix another comment
unalmis Aug 5, 2024
d528b33
Merge branch 'ripple' into Gamma_c
unalmis Aug 7, 2024
67d0662
Merge branch 'ripple' into Gamma_c
unalmis Aug 18, 2024
4595546
Fix reshape error raised by JAX by reverting average before pitch int…
unalmis Aug 18, 2024
f0ad787
Merge branch 'ripple' into Gamma_c
unalmis Aug 18, 2024
e0dfd61
Merge branch 'ku/angles' into Gamma_c
unalmis Aug 18, 2024
75bc784
Use general angles rather than stream function aliases
unalmis Aug 18, 2024
72fb5e6
Merge branch 'ripple' into Gamma_c
unalmis Aug 20, 2024
75c9333
Merge branch 'ripple' into Gamma_c
unalmis Sep 3, 2024
d2bfe12
Merge branch 'ripple' into Gamma_c
unalmis Sep 4, 2024
2363303
Atone for B0 name change made in pull request #1168
unalmis Sep 4, 2024
4cea229
Merge branch 'ripple' into Gamma_c
unalmis Sep 4, 2024
ba758d6
Merge branch 'ripple' into Gamma_c
unalmis Sep 4, 2024
4216094
Merge branch 'ripple' into Gamma_c
unalmis Sep 4, 2024
d94ecd6
Update Gamma_c objective for recent changes on master
unalmis Sep 4, 2024
5cd7ebd
Add Gamma_c_Nemov baseline image for test
unalmis Sep 4, 2024
df2938e
Merge branch 'ripple' into Gamma_c
unalmis Sep 15, 2024
717426f
Merge branch 'ripple' into Gamma_c
unalmis Sep 15, 2024
c2e455d
Allow using other Gamma_c in objective
unalmis Sep 15, 2024
3d44b04
Merge branch 'ripple' into Gamma_c
unalmis Sep 16, 2024
9ed4a47
black format
unalmis Sep 16, 2024
070626b
Merge branch 'ripple' into Gamma_c
unalmis Sep 16, 2024
246427b
Merge branch 'ripple' into Gamma_c
unalmis Sep 16, 2024
621cb71
Merge branch 'ripple' into Gamma_c
unalmis Sep 17, 2024
a5a257b
Merge branch 'ripple' into Gamma_c
unalmis Sep 17, 2024
4d3169b
Merge branch 'ripple' into Gamma_c
unalmis Sep 17, 2024
55f8aa5
Merge branch 'master' into Gamma_c
unalmis Sep 18, 2024
9498ad4
Merge branch 'ripple' into Gamma_c
unalmis Sep 18, 2024
7894b41
Merge branch 'ripple' into Gamma_c
unalmis Sep 19, 2024
9acc900
Use infinite period for alpha
unalmis Sep 19, 2024
e31b602
Use better quadrature for part of integral in Nemov Gamma_c
unalmis Sep 21, 2024
a574827
Add quad2 kwargs for weak singular integrals
unalmis Sep 21, 2024
cff5494
Merge branch 'ripple' into Gamma_c
unalmis Sep 22, 2024
503f0d6
Avoid redundant computation of bounce points
unalmis Sep 22, 2024
362f198
Merge branch 'ripple' into Gamma_c
unalmis Sep 22, 2024
48d92fb
Merge branch 'ripple' into Gamma_c
unalmis Sep 22, 2024
3714827
Merge branch 'ripple' into Gamma_c
unalmis Sep 22, 2024
1739b3e
Merge branch 'ripple' into Gamma_c
unalmis Sep 22, 2024
9dac89e
Document that Velasco's expression converges to zero
unalmis Sep 24, 2024
5a8e861
Merge branch 'ripple' into Gamma_c
unalmis Sep 24, 2024
7268ad8
Update after merging
unalmis Sep 24, 2024
b58a1bd
Merge branch 'ripple' into Gamma_c
unalmis Sep 25, 2024
5b668ee
Merge branch 'ripple' into Gamma_c
unalmis Sep 26, 2024
eef81f6
Merge branch 'ripple' into Gamma_c
unalmis Sep 26, 2024
507a30c
Merge branch 'ripple' into Gamma_c
unalmis Sep 26, 2024
021b28a
Add chunk_size option
unalmis Sep 26, 2024
1a62674
Merge branch 'ripple' into Gamma_c
unalmis Sep 27, 2024
3f465d6
Merge branch 'ripple' into Gamma_c
unalmis Sep 27, 2024
157359d
Merge branch 'ripple' into Gamma_c
unalmis Sep 29, 2024
53ea40b
Merge branch 'ripple' into Gamma_c
unalmis Sep 29, 2024
779f57c
Make sure API is compatible for Gamma_d etc.
unalmis Sep 29, 2024
954b9ec
address my review comment
unalmis Sep 29, 2024
bc5f6d3
Resolve todo comment out smoothness
unalmis Sep 29, 2024
5b8ccb7
Merge branch 'ripple' into Gamma_c
unalmis Sep 30, 2024
f6aee2c
Merge branch 'ripple' into Gamma_c
unalmis Sep 30, 2024
e5127e0
Merge remote-tracking branch 'refs/remotes/origin/Gamma_c' into Gamma_c
unalmis Sep 30, 2024
21c2e6b
fix method name in gammaC compute call
dpanici Oct 3, 2024
e13bdaf
Merge branch 'ripple' into Gamma_c
unalmis Oct 17, 2024
d5f4473
Update comment about convergence to zero with warning to use adaptive…
unalmis Oct 17, 2024
1797fcc
Merge branch 'ripple' into Gamma_c
unalmis Oct 17, 2024
b83fed8
Merge branch 'ripple' into Gamma_c
unalmis Oct 19, 2024
2e74569
Merge branch 'ripple' into Gamma_c
unalmis Oct 19, 2024
9ffb527
Merge branch 'ripple' into Gamma_c
unalmis Oct 20, 2024
090ef23
Merge branch 'ripple' into Gamma_c
unalmis Oct 20, 2024
5be0f27
Merging ripple
unalmis Oct 20, 2024
7db67d6
Merge branch 'ripple' into Gamma_c
unalmis Oct 30, 2024
563a67c
Merge branch 'ripple' into Gamma_c
unalmis Oct 30, 2024
6c1b647
Merge branch 'ripple' into Gamma_c
unalmis Oct 31, 2024
bcc0dd0
Merge branch 'ripple' into Gamma_c
unalmis Nov 16, 2024
67ba404
Merge branch 'ripple' into Gamma_c
dpanici Nov 22, 2024
158fade
Merge branch 'ripple' into Gamma_c
unalmis Nov 26, 2024
27cfacf
fixing #1288, adding opt tests for Gamma_c
Dec 3, 2024
2f8ba3c
Revert "fixing #1288, adding opt tests for Gamma_c"
Dec 3, 2024
0257d91
Merge branch 'ripple' into Gamma_c
unalmis Dec 5, 2024
57d983f
Merge part 1
unalmis Dec 5, 2024
f7b6267
Merge branch 'ripple' into Gamma_c
unalmis Dec 5, 2024
c3a7296
Merging part 2
unalmis Dec 5, 2024
6057ec5
Merge branch 'ripple' into Gamma_c
unalmis Dec 5, 2024
7860d61
Merge branch 'master' into Gamma_c
unalmis Dec 6, 2024
231c643
Merge branch 'master' into Gamma_c
unalmis Dec 9, 2024
751ce53
Merge branch 'master' into Gamma_c
unalmis Dec 10, 2024
b505e70
Merge branch 'master' into Gamma_c
rahulgaur104 Dec 10, 2024
ec937d5
Review requests
unalmis Dec 10, 2024
86a0c2f
Review request 2
unalmis Dec 10, 2024
3c582e2
Merge branch 'master' into Gamma_c
unalmis Dec 11, 2024
c312aa1
review request to make objective only allow kwarg
unalmis Dec 13, 2024
ce98913
Merge branch 'master' into Gamma_c
unalmis Dec 13, 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
21 changes: 12 additions & 9 deletions desc/compute/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,8 +1858,8 @@ def _gradzeta(params, transforms, profiles, data, **kwargs):
# https://tinyurl.com/54udvaa4
label="\\mathrm{gbdrift} = 1/B^{2} (\\mathbf{b}\\times\\nabla B) \\cdot"
+ "\\nabla \\alpha",
units="1/(T-m^{2})",
units_long="inverse Tesla meters^2",
units="1 / Wb",
units_long="Inverse webers",
description="Binormal component of the geometric part of the gradB drift"
+ " used for local stability analyses, Gamma_c, epsilon_eff etc.",
dim=1,
Expand All @@ -1885,8 +1885,8 @@ def _gbdrift(params, transforms, profiles, data, **kwargs):
# https://tinyurl.com/54udvaa4
label="\\mathrm{cvdrift} = 1/B^{3} (\\mathbf{b}\\times\\nabla(p + B^2/2))"
+ "\\cdot \\nabla \\alpha",
units="1/(T-m^{2})",
units_long="inverse Tesla meters^2",
units="1 / Wb",
units_long="Inverse webers",
description="Binormal component of the geometric part of the curvature drift"
+ " used for local stability analyses, Gamma_c, epsilon_eff etc.",
dim=1,
Expand All @@ -1908,20 +1908,23 @@ def _cvdrift(params, transforms, profiles, data, **kwargs):
# eqn. 48 of Introduction to Quasisymmetry by Landreman
# https://tinyurl.com/54udvaa4
label="\\mathrm{cvdrift0} = 1/B^{2} (\\mathbf{b}\\times\\nabla B)"
+ "\\cdot \\nabla \\rho",
units="1/(T-m^{2})",
units_long="inverse Tesla meters^2",
+ "\\cdot (2 \\rho \\nabla \\rho)",
units="1 / Wb",
units_long="Inverse webers",
description="Radial component of the geometric part of the curvature drift"
+ " used for local stability analyses for Gamma_c.",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["|B|^2", "b", "e^rho", "grad(|B|)"],
data=["|B|^2", "b", "e^rho", "grad(|B|)", "rho"],
)
def _cvdrift0(params, transforms, profiles, data, **kwargs):
data["cvdrift0"] = (
1 / data["|B|^2"] * (dot(data["b"], cross(data["grad(|B|)"], data["e^rho"])))
2
* data["rho"]
unalmis marked this conversation as resolved.
Show resolved Hide resolved
/ data["|B|^2"]
* dot(data["b"], cross(data["grad(|B|)"], data["e^rho"]))
)
return data
128 changes: 126 additions & 2 deletions desc/compute/_neoclassical.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from functools import partial

from orthax.legendre import leggauss
from quadax import simpson
from quadax import romberg, simpson

from desc.backend import imap, jit, jnp
from desc.backend import imap, jit, jnp, trapezoid

from .bounce_integral import bounce_integral, get_pitch
from .data_index import register_compute_fun
Expand Down Expand Up @@ -271,3 +271,127 @@ def _effective_ripple(params, transforms, profiles, data, **kwargs):
* data["effective ripple raw"]
)
return data


@register_compute_fun(
name="Gamma_c",
label="Γ_c = π/(8√2) ∫dλ 〈 ∑ⱼ [v τ γ_c²]ⱼ 〉",
units="~",
units_long="None",
description="Energetic ion confinement proxy",
dim=1,
params=[],
transforms={"grid": []},
profiles=[],
coordinates="r",
data=[
"min_tz |B|",
"max_tz |B|",
"B^zeta",
"|B|",
"|B|_z|r,a",
"cvdrift0",
"gbdrift",
"<L|r,a>",
],
source_grid_requirement={"coordinates": "raz", "is_meshgrid": True},
num_quad="int : Resolution for quadrature of bounce integrals. Default is 31.",
num_pitch=(
"int : Resolution for quadrature over velocity coordinate. Default is 125."
),
adaptive=(
"bool : Whether to adaptively integrate over the velocity coordinate. "
"If true, then num_pitch specifies an upper bound on the maximum number "
"of function evaluations."
),
batch="bool : Whether to vectorize part of the computation. Default is true.",
)
@partial(jit, static_argnames=["num_quad", "num_pitch", "adaptive", "batch"])
def _Gamma_c(params, transforms, profiles, data, **kwargs):
"""Energetic ion confinement proxy.

A model for the fast evaluation of prompt losses of energetic ions in stellarators.
J.L. Velasco et al. 2021 Nucl. Fusion 61 116059.
https://doi.org/10.1088/1741-4326/ac2994.
Equation 16.

Poloidal motion of trapped particle orbits in real-space coordinates.
V. V. Nemov, S. V. Kasilov, W. Kernbichler, G. O. Leitold.
Phys. Plasmas 1 May 2008; 15 (5): 052501.
https://doi.org/10.1063/1.2912456.
Equation 61, using Velasco's γ_c from equation 15 of the above paper.
"""
batch = kwargs.get("batch", True)
g = transforms["grid"].source_grid
knots = g.compress(g.nodes[:, 2], surface_label="zeta")
quad = leggauss(kwargs.get("num_quad", 31))
num_pitch = kwargs.get("num_pitch", 125)
adaptive = kwargs.get("adaptive", False)
pitch = _get_pitch(g, data, num_pitch, adaptive)

def d_v_tau(B, pitch):
return 2 / jnp.sqrt(1 - pitch * B)

def d_gamma_c(f, B, pitch):
return f * (1 - pitch * B / 2) / jnp.sqrt(1 - pitch * B)

if not adaptive:
bounce_integrate, _ = bounce_integral(
data["B^zeta"], data["|B|"], data["|B|_z|r,a"], knots, quad
)

def d_Gamma_c(pitch):
# Return ∑ⱼ [v τ γ_c²]ⱼ evaluated at λ = pitch.
# Note v τ = 4λ⁻²B₀⁻¹ ∂I/∂((λB₀)⁻¹) where v is the particle velocity,
# τ is the bounce time, and I is defined in Nemov eq. 36.
v_tau = bounce_integrate(d_v_tau, [], pitch, batch=batch)
gamma_c = (
2
/ jnp.pi
* jnp.arctan(
bounce_integrate(d_gamma_c, data["cvdrift0"], pitch, batch=batch)
/ bounce_integrate(d_gamma_c, data["gbdrift"], pitch, batch=batch)
)
)
return jnp.nansum(v_tau * gamma_c**2, axis=-1)

# The integrand is piecewise continuous and likely poorly approximated by a
# polynomial, so composite quadrature should perform better than higher order
# methods.
Gamma_c = trapezoid(jnp.squeeze(imap(d_Gamma_c, pitch), axis=1), pitch, axis=0)
else:

def d_Gamma_c(pitch, B_sup_z, B, B_z_ra, cvdrift0, gbdrift):
bounce_integrate, _ = bounce_integral(B_sup_z, B, B_z_ra, knots, quad)
v_tau = bounce_integrate(d_v_tau, [], pitch, batch=batch)
gamma_c = (
2
/ jnp.pi
* jnp.arctan(
bounce_integrate(d_gamma_c, cvdrift0, pitch, batch=batch)
/ bounce_integrate(d_gamma_c, gbdrift, pitch, batch=batch)
)
)
return jnp.squeeze(jnp.nansum(v_tau * gamma_c**2, axis=-1))

args = [
f.reshape(g.num_rho, g.num_alpha, g.num_zeta)
for f in [
data["B^zeta"],
data["|B|"],
data["|B|_z|r,a"],
data["cvdrift0"],
data["gbdrift"],
]
]
Gamma_c = _vec_quadax(romberg, divmax=jnp.log2(num_pitch + 1))(
d_Gamma_c, pitch, *args
)

data["Gamma_c"] = (
jnp.pi
/ (8 * 2**0.5)
* g.expand(_poloidal_mean(g, Gamma_c.reshape(g.num_rho, g.num_alpha)))
/ data["<L|r,a>"]
)
return data
Loading