-
Notifications
You must be signed in to change notification settings - Fork 26
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
Critical gradient #1318
base: master
Are you sure you want to change the base?
Critical gradient #1318
Changes from 6 commits
b3c50ad
aeb2ff8
0069348
7a62626
5b2de89
afc54a3
5eeec7b
5000336
08680ab
df9260e
56fdce4
32019fc
2ad65de
aa6a6c5
99a6ab4
f6a1068
b1f772e
eb8d2a1
719e318
58ac2f6
884d659
d30065a
7edb28b
96b63c6
96a42bc
6e4cf29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notebook for testing critical gradient optimization |
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notebook for testing jax implementation of critical gradient |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"""Compute functions for turbulent transport. | ||
|
||
Notes | ||
----- | ||
Some quantities require additional work to compute at the magnetic axis. | ||
A Python lambda function is used to lazily compute the magnetic axis limits | ||
of these quantities. These lambda functions are evaluated only when the | ||
computational grid has a node on the magnetic axis to avoid potentially | ||
expensive computations. | ||
""" | ||
from .data_index import register_compute_fun | ||
from ..backend import jnp | ||
from ..integrals.critical_gradient import extract_Kd_wells, fit_Kd_wells | ||
|
||
|
||
@register_compute_fun( | ||
name="Kd", | ||
# Exact definition of the dimenstionless drift curvature can be found | ||
# in https://journals.aps.org/prresearch/pdf/10.1103/PhysRevResearch.4.L032028 | ||
label="\\mathrm{cvdrift} = a^2\\nabla\\alpha\\cdot\\mathbf{b}\\times\\kappa", | ||
units="", | ||
units_long="", | ||
description="Dimensionless drift curvature", | ||
dim=1, | ||
params=[], | ||
transforms={}, | ||
profiles=[], | ||
coordinates="rtz", | ||
data=["cvdrift", "|B|", "a"], | ||
) | ||
|
||
def _Kd(params, transforms, profiles, data, **kwargs): | ||
data["Kd"] = ( | ||
data["a"]**2*jnp.multiply(data["|B|"],data["cvdrift"]) | ||
) | ||
return data | ||
|
||
@register_compute_fun( | ||
name="R_eff", | ||
# Exact definition of the effective radius of curvature can be found | ||
# in https://journals.aps.org/prresearch/pdf/10.1103/PhysRevResearch.4.L032028 | ||
label="R_eff", | ||
units="", | ||
units_long="", | ||
description="Effective radius of the drift curvature along the field line", | ||
dim=1, | ||
params=[], | ||
transforms={"grid": []}, | ||
profiles=[], | ||
coordinates="rtz", | ||
data=["Kd"], | ||
) | ||
|
||
def _R_eff(params, transforms, profiles, data, **kwargs): | ||
grid = transforms["grid"].source_grid | ||
Kd_wells,_,masks = extract_Kd_wells(data["Kd"]) | ||
_,_,R_eff = fit_Kd_wells(grid.nodes[:,2], Kd_wells, masks) | ||
data["R_eff"] = R_eff | ||
return data | ||
|
||
@register_compute_fun( | ||
name="L_par", | ||
# Parallel connection length defined as width of Kd wells | ||
label="L_par", | ||
units="", | ||
units_long="", | ||
description="Width of Kd wells along the field line", | ||
dim=1, | ||
params=[], | ||
transforms={"grid": []}, | ||
profiles=[], | ||
coordinates="rtz", | ||
data=["Kd"], | ||
) | ||
|
||
def _L_par(params, transforms, profiles, data, **kwargs): | ||
grid = transforms["grid"].source_grid | ||
_,length_wells,_ = extract_Kd_wells(data["Kd"],order=True) | ||
L_par = jnp.diff(grid.nodes[:,2])[0]*length_wells | ||
data["L_par"] = L_par | ||
return data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notebook for testing critical gradient fitting, not jit compatible not up to date