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

HeatingPower objective #1168

Merged
merged 35 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
137859f
initial commit of HeatingPower objective
daniel-dudt Aug 6, 2024
551e906
compute quantity for ni
daniel-dudt Aug 6, 2024
04184af
add <ne>_rho compute quantity
daniel-dudt Aug 6, 2024
5609439
add iota_23 compute quantity
daniel-dudt Aug 6, 2024
515850f
rename 'B0' to 'psi_r/sqrt(g)'
daniel-dudt Aug 6, 2024
e09710d
add new B0 compute quantity
daniel-dudt Aug 6, 2024
a4a5184
update HeatingPower objective
daniel-dudt Aug 6, 2024
8bbba7b
Merge branch 'master' into dd/iss04
ddudt Aug 15, 2024
d97ecfe
rename 'B0' to '<|B|>_axis'
daniel-dudt Aug 15, 2024
b228a5a
make it JAX compatible
daniel-dudt Aug 15, 2024
e51aba1
add normalization
daniel-dudt Aug 15, 2024
039e854
repair tests
daniel-dudt Aug 16, 2024
efde8bc
making Rory's requested changes
daniel-dudt Aug 16, 2024
05047e7
remove unneeded line from test
daniel-dudt Aug 16, 2024
bf9c683
exclude P_ISS04 from axis limit tests
daniel-dudt Aug 16, 2024
3fa64df
more requested changes
daniel-dudt Aug 16, 2024
d4e292e
update label for '<ne>_rho'
daniel-dudt Aug 16, 2024
0eca4f3
Merge branch 'master' into dd/iss04
ddudt Aug 16, 2024
9017d47
update line-average to work with 3D profile
daniel-dudt Aug 16, 2024
7e48df5
rename fx kwarg
daniel-dudt Aug 16, 2024
6267710
Merge branch 'master' into dd/iss04
ddudt Aug 18, 2024
40345c1
Merge branch 'master' into dd/iss04
ddudt Aug 18, 2024
5a959f6
update formula and normalization
daniel-dudt Aug 19, 2024
26f740e
Merge branch 'master' into dd/iss04
dpanici Aug 20, 2024
e5763d9
Merge branch 'master' into dd/iss04
ddudt Aug 22, 2024
1975d73
switch to volume average density
daniel-dudt Aug 22, 2024
19c3d31
update master_compute_data
daniel-dudt Aug 22, 2024
3434eab
update ne_vol function name
daniel-dudt Aug 22, 2024
ec972c4
remove line average test
daniel-dudt Aug 22, 2024
8663b1a
Merge branch 'master' into dd/iss04
ddudt Aug 22, 2024
00bf8ce
Merge branch 'master' into dd/iss04
ddudt Aug 22, 2024
5f4aa26
Merge branch 'master' into dd/iss04
ddudt Aug 22, 2024
de5210f
Merge branch 'master' into dd/iss04
ddudt Aug 23, 2024
a0ce1e3
improved formatting of equation
daniel-dudt Aug 23, 2024
07366ef
Merge branch 'master' into dd/iss04
ddudt Aug 25, 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
358 changes: 220 additions & 138 deletions desc/compute/_field.py

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions desc/compute/_omnigenity.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,22 @@ def _B_modes(params, transforms, profiles, data, **kwargs):
transforms={},
profiles=[],
coordinates="rtz",
data=["iota", "B0", "B_theta", "B_zeta", "|B|_t", "|B|_z", "G", "I", "B*grad(|B|)"],
data=[
"iota",
"psi_r/sqrt(g)",
"B_theta",
"B_zeta",
"|B|_t",
"|B|_z",
"G",
"I",
"B*grad(|B|)",
],
helicity="tuple: Type of quasisymmetry, (M,N). Default (1,0)",
)
def _f_C(params, transforms, profiles, data, **kwargs):
M, N = kwargs.get("helicity", (1, 0))
data["f_C"] = (M * data["iota"] - N) * data["B0"] * (
data["f_C"] = (M * data["iota"] - N) * data["psi_r/sqrt(g)"] * (
data["B_zeta"] * data["|B|_t"] - data["B_theta"] * data["|B|_z"]
) - (M * data["G"] + N * data["I"]) * data["B*grad(|B|)"]
return data
Expand All @@ -359,10 +369,10 @@ def _f_C(params, transforms, profiles, data, **kwargs):
transforms={},
profiles=[],
coordinates="rtz",
data=["B0", "|B|_t", "|B|_z", "(B*grad(|B|))_t", "(B*grad(|B|))_z"],
data=["psi_r/sqrt(g)", "|B|_t", "|B|_z", "(B*grad(|B|))_t", "(B*grad(|B|))_z"],
)
def _f_T(params, transforms, profiles, data, **kwargs):
data["f_T"] = data["B0"] * (
data["f_T"] = data["psi_r/sqrt(g)"] * (
data["|B|_t"] * data["(B*grad(|B|))_z"]
- data["|B|_z"] * data["(B*grad(|B|))_t"]
)
Expand Down
91 changes: 85 additions & 6 deletions desc/compute/_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
expensive computations.
"""

from interpax import interp1d
from scipy.constants import elementary_charge, mu_0

from desc.backend import cond, jnp
Expand Down Expand Up @@ -216,6 +217,26 @@ def _Te_rr(params, transforms, profiles, data, **kwargs):
return data


@register_compute_fun(
name="<ne>_rho",
label="\\bar{n}_e",
units="m^{-3}",
units_long="1 / cubic meters",
description="Line-averaged electron density",
ddudt marked this conversation as resolved.
Show resolved Hide resolved
dim=0,
params=[],
transforms={"grid": []},
profiles=[],
coordinates="",
data=["ne"],
ddudt marked this conversation as resolved.
Show resolved Hide resolved
)
def _bar_ne(params, transforms, profiles, data, **kwargs):
data["<ne>_rho"] = jnp.sum(data["ne"] * transforms["grid"].spacing[:, 0]) / jnp.sum(
transforms["grid"].spacing[:, 0]
)
ddudt marked this conversation as resolved.
Show resolved Hide resolved
return data


@register_compute_fun(
name="ne",
label="n_e",
Expand Down Expand Up @@ -354,6 +375,44 @@ def _Ti_rr(params, transforms, profiles, data, **kwargs):
return data


@register_compute_fun(
name="ni",
label="n_i",
units="m^{-3}",
units_long="1 / cubic meters",
description="Ion density",
dim=1,
params=[],
transforms={"grid": []},
profiles=[],
coordinates="r",
data=["ne", "Zeff"],
)
def _ni(params, transforms, profiles, data, **kwargs):
data["ni"] = data["ne"] / data["Zeff"]
return data


@register_compute_fun(
name="ni_r",
label="\\partial_{\\rho} n_i",
units="m^{-3}",
units_long="1 / cubic meters",
description="Ion density, first radial derivative",
dim=1,
params=[],
transforms={"grid": []},
profiles=[],
coordinates="r",
data=["ne", "ne_r", "Zeff", "Zeff_r"],
)
def _ni_r(params, transforms, profiles, data, **kwargs):
data["ni_r"] = (data["ne_r"] * data["Zeff"] - data["ne"] * data["Zeff_r"]) / data[
"Zeff"
] ** 2
return data


@register_compute_fun(
name="Zeff",
label="Z_{eff}",
Expand Down Expand Up @@ -411,7 +470,7 @@ def _Zeff_r(params, transforms, profiles, data, **kwargs):
transforms={"grid": []},
profiles=["pressure"],
coordinates="r",
data=["Te", "ne", "Ti", "Zeff"],
data=["ne", "ni", "Te", "Ti"],
)
def _p(params, transforms, profiles, data, **kwargs):
if profiles["pressure"] is not None:
Expand All @@ -420,7 +479,7 @@ def _p(params, transforms, profiles, data, **kwargs):
)
else:
data["p"] = elementary_charge * (
data["ne"] * data["Te"] + data["Ti"] * data["ne"] / data["Zeff"]
data["ne"] * data["Te"] + data["ni"] * data["Ti"]
)
return data

Expand All @@ -436,7 +495,7 @@ def _p(params, transforms, profiles, data, **kwargs):
transforms={"grid": []},
profiles=["pressure"],
coordinates="r",
data=["Te", "Te_r", "ne", "ne_r", "Ti", "Ti_r", "Zeff", "Zeff_r"],
data=["ne", "ne_r", "ni", "ni_r", "Te", "Te_r", "Ti", "Ti_r"],
)
def _p_r(params, transforms, profiles, data, **kwargs):
if profiles["pressure"] is not None:
Expand All @@ -447,9 +506,8 @@ def _p_r(params, transforms, profiles, data, **kwargs):
data["p_r"] = elementary_charge * (
data["ne_r"] * data["Te"]
+ data["ne"] * data["Te_r"]
+ data["Ti_r"] * data["ne"] / data["Zeff"]
+ data["Ti"] * data["ne_r"] / data["Zeff"]
- data["Ti"] * data["ne"] * data["Zeff_r"] / data["Zeff"] ** 2
+ data["ni_r"] * data["Ti"]
+ data["ni"] * data["Ti_r"]
)
return data

Expand Down Expand Up @@ -686,6 +744,27 @@ def _gradbeta_a(params, transforms, profiles, data, **kwargs):
return data


@register_compute_fun(
name="iota_23",
label="\\iota_{2/3}",
units="~",
units_long="None",
description="Rotational transform (normalized by 2pi) at rho=2/3",
dim=0,
params=[],
transforms={"grid": []},
profiles=[],
coordinates="",
data=["rho", "iota"],
method="str: Interpolation method. Default 'cubic'.",
)
def _iota_23(params, transforms, profiles, data, **kwargs):
ddudt marked this conversation as resolved.
Show resolved Hide resolved
rho = transforms["grid"].compress(data["rho"], surface_label="rho")
iota = transforms["grid"].compress(data["iota"], surface_label="rho")
data["iota_23"] = interp1d(2 / 3, rho, iota, method=kwargs.get("method", "cubic"))
return data


@register_compute_fun(
name="iota",
label="\\iota",
Expand Down
1 change: 1 addition & 0 deletions desc/objectives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
QuadraticFlux,
ToroidalFlux,
)
from ._confinement import HeatingPower
from ._equilibrium import (
CurrentDensity,
Energy,
Expand Down
Loading
Loading