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

Critical gradient #1318

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b3c50ad
Creating critical_gradient optimization
kfrybes Oct 7, 2024
aeb2ff8
Changes to turbulence optimization, inluding jnp instead of np
kfrybes Oct 9, 2024
0069348
Jax adaptation and zonal flow notebook
kfrybes Oct 14, 2024
7a62626
Making the effective radius computation jit compatible
kfrybes Oct 22, 2024
5b2de89
Merge branch 'master' into kf/critical_gradient
kfrybes Oct 23, 2024
afc54a3
fixing change I made on objectives/_stability for testing
kfrybes Oct 23, 2024
5eeec7b
updating the effective radius objective to return array of effective…
kfrybes Oct 23, 2024
5000336
Cleaning up the critical_gradient2 notebook to be understandable
kfrybes Oct 23, 2024
08680ab
updating R_eff compute function to take n_wells as kwargs
kfrybes Oct 23, 2024
df9260e
Remove flake8 errors, code formatting
kfrybes Oct 24, 2024
56fdce4
add mask sorting to extract_Kd_wells function
kfrybes Oct 25, 2024
32019fc
fix print name L_par
kfrybes Oct 25, 2024
2ad65de
add absolute value to number of toroidal turns + update notebook
kfrybes Oct 29, 2024
aa6a6c5
Merge branch 'master' into kf/critical_gradient
daniel-dudt Oct 30, 2024
99a6ab4
remove NFP from get_rtz_grid and update notebook
kfrybes Oct 31, 2024
f6a1068
update notebook for testing different boundary modes
kfrybes Nov 1, 2024
b1f772e
move old files to local and update optimization notebook
kfrybes Nov 8, 2024
eb8d2a1
Merge branch 'master' into kf/critical_gradient
dpanici Nov 20, 2024
719e318
Update critical gradient notebook to make it easy to run and undrstand
kfrybes Nov 20, 2024
58ac2f6
Add possibility of accessing length of good curvature regions,
kfrybes Dec 6, 2024
884d659
Add curvature parameter to L_par objective to be able to target both …
kfrybes Dec 9, 2024
d30065a
bug fix
kfrybes Dec 9, 2024
7edb28b
Use arc length coordinate for calculating R_eff
kfrybes Dec 17, 2024
96b63c6
Adapt code to target also good curvature regions
kfrybes Dec 17, 2024
96a42bc
Add xi compute quantity for flux surface spacing turbulence optimization
kfrybes Dec 17, 2024
6e4cf29
Add GradS objective for optimizing turbulence
kfrybes Dec 18, 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
1,143 changes: 1,143 additions & 0 deletions Critical_gradient2.ipynb
Copy link
Collaborator Author

@kfrybes kfrybes Oct 23, 2024

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

Large diffs are not rendered by default.

944 changes: 944 additions & 0 deletions Critical_gradient_optimization.ipynb
Copy link
Collaborator Author

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 optimization

Large diffs are not rendered by default.

927 changes: 927 additions & 0 deletions critical_gradient_jax.ipynb
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

1 change: 1 addition & 0 deletions desc/compute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
_profiles,
_stability,
_surface,
_turbulence,
)
from .data_index import all_kwargs, allowed_kwargs, data_index
from .geom_utils import rpz2xyz, rpz2xyz_vec, xyz2rpz, xyz2rpz_vec
Expand Down
81 changes: 81 additions & 0 deletions desc/compute/_turbulence.py
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
Loading
Loading