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

Basis vectors #598

Merged
merged 26 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dbf61ef
git checkout add_all_limits desc/compute/_basis_vectors.py
unalmis Jul 25, 2023
4eb0001
git checkout add_all_limits desc/compute/_core.py
unalmis Jul 25, 2023
055ae48
Include patch from #556 that lets reviewers skip dependency review
unalmis Jul 25, 2023
f0f1d07
Alphabetize basis vectors
unalmis Jul 25, 2023
311ff0a
Add script to sort compute functions
unalmis Jul 25, 2023
fe97a88
simplify matching pattern
unalmis Jul 25, 2023
817c238
Merge branch 'master' into basis_vectors
f0uriest Jul 28, 2023
42777b1
Sort _core using script
unalmis Jul 25, 2023
0ca2226
Merge branch 'master' into basis_vectors and ...
unalmis Jul 31, 2023
9604a83
Merge branch 'master' into basis_vectors
unalmis Jul 31, 2023
a6b8125
Make sort_compute_funs.py more readable
unalmis Jul 31, 2023
720b512
Convert vectors to xyz basis before finite differencing
f0uriest Jul 13, 2023
eff10e6
Fix boundary conditions on 2d finite differencing
f0uriest Jul 13, 2023
d8d882f
Fix mean curvature test
unalmis Jul 31, 2023
267e4a9
Cherry-pick fixes to tests from add_all_limits branch.
unalmis Aug 1, 2023
81e735d
Reduce tolerance for QIC solve test
unalmis Jul 23, 2023
0d24953
Add test for covariant basis vectors
f0uriest Aug 1, 2023
985460c
Fix e_zeta_rtt
unalmis Aug 1, 2023
4d83fda
Merge branch 'master' into basis_vectors
f0uriest Aug 2, 2023
7159dcb
Merge branch 'master' into basis_vectors
unalmis Aug 8, 2023
71bb72f
Fix things due to API updates in last merge...
unalmis Aug 9, 2023
01f8d35
simplify regular expression
unalmis Aug 9, 2023
f3883a7
fix typo in printed message
unalmis Aug 9, 2023
11ce811
Merge branch 'master' into basis_vectors
f0uriest Aug 10, 2023
b8b53ba
Merge branch 'master' into basis_vectors
f0uriest Aug 10, 2023
309c4ef
Merge branch 'master' into basis_vectors
unalmis Aug 11, 2023
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
3,237 changes: 2,988 additions & 249 deletions desc/compute/_basis_vectors.py
unalmis marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions desc/compute/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,15 @@

# Redl eq (14):
X32e = f_t / (
(
1
+ 0.23 * (1 - 0.96 * f_t) * jnp.sqrt(nu_e) / jnp.sqrt(Zeff)
+ 0.13
* (1 - 0.38 * f_t)
* nu_e
/ (Zeff * Zeff)
* (
jnp.sqrt(1 + 2 * jnp.sqrt(Zeff - 1))
+ f_t * f_t * jnp.sqrt((0.075 + 0.25 * (Zeff - 1) ** 2) * nu_e)
)
1
+ 0.23 * (1 - 0.96 * f_t) * jnp.sqrt(nu_e) / jnp.sqrt(Zeff)
+ 0.13
* (1 - 0.38 * f_t)
* nu_e
/ (Zeff * Zeff)
* (
jnp.sqrt(1 + 2 * jnp.sqrt(Zeff - 1))
+ f_t * f_t * jnp.sqrt((0.075 + 0.25 * (Zeff - 1) ** 2) * nu_e)
)
)

Expand Down Expand Up @@ -280,8 +278,8 @@
J_dot_B = dnds_term + dTeds_term + dTids_term

# Store all results in the J_dot_B_data dictionary:
nu_e_star = nu_e
nu_i_star = nu_i
nu_e_star = nu_e # noqa: F841
unalmis marked this conversation as resolved.
Show resolved Hide resolved
nu_i_star = nu_i # noqa: F841

Check warning on line 282 in desc/compute/_bootstrap.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_bootstrap.py#L281-L282

Added lines #L281 - L282 were not covered by tests
variables = [
"rho",
"ne",
Expand Down Expand Up @@ -342,6 +340,7 @@
"Ti",
"Ti_r",
"Zeff",
"rho",
],
helicity="helicity",
)
Expand Down
8 changes: 4 additions & 4 deletions desc/compute/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ def _B0_r(params, transforms, profiles, data, **kwargs):
data=["B0", "B0_r", "iota", "iota_r", "lambda_z", "lambda_rz"],
)
def _B_sup_theta_r(params, transforms, profiles, data, **kwargs):
data["B^theta_r"] = data["B0_r"] * (data["iota"] - data["lambda_z"]) + data[
"B0"
] * (data["iota_r"] - data["lambda_rz"])
data["B^theta_r"] = data["B0_r"] * (data["iota"] - data["lambda_z"]) + (
data["B0"] * (data["iota_r"] - data["lambda_rz"])
)
return data
unalmis marked this conversation as resolved.
Show resolved Hide resolved


Expand Down Expand Up @@ -2223,7 +2223,7 @@ def _B_mag_tz(params, transforms, profiles, data, **kwargs):
"B^zeta_r",
"B_theta_r",
"B_zeta_r",
"B^theta_t",
"B^theta_z",
"B^zeta_z",
"B_theta_z",
"B_zeta_z",
Expand Down
2 changes: 1 addition & 1 deletion desc/compute/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _R0_over_a(params, transforms, profiles, data, **kwargs):
transforms={"grid": []},
profiles=[],
coordinates="",
data=["sqrt(g)", "g_tt"],
data=["sqrt(g)", "g_tt", "R"],
ddudt marked this conversation as resolved.
Show resolved Hide resolved
)
def _a_major_over_a_minor(params, transforms, profiles, data, **kwargs):
max_rho = transforms["grid"].nodes[transforms["grid"].unique_rho_idx[-1], 0]
Expand Down
60 changes: 18 additions & 42 deletions desc/compute/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ def _g_sup_tz(params, transforms, profiles, data, **kwargs):
"e^rho",
"sqrt(g)_r",
"sqrt(g)",
"e_rho",
"e_theta",
"e_rho_r",
"e_theta_r",
"e_zeta_r",
"e_zeta",
],
)
def _g_sup_rr_r(params, transforms, profiles, data, **kwargs):
Expand Down Expand Up @@ -863,16 +863,13 @@ def _g_sup_rz_r(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^theta",
"e^theta",
"sqrt(g)_r",
"sqrt(g)",
"e_theta",
"e_theta",
"e_rho",
"e_theta_r",
"e_theta_r",
"e_rho_r",
"e_zeta_r",
"e_zeta",
],
)
def _g_sup_tt_r(params, transforms, profiles, data, **kwargs):
Expand Down Expand Up @@ -961,15 +958,12 @@ def _g_sup_tz_r(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^zeta",
"e^zeta",
"sqrt(g)_r",
"sqrt(g)",
"e_zeta",
"e_zeta",
"e_theta",
"e_rho",
"e_zeta_r",
"e_zeta_r",
"e_theta_r",
"e_rho_r",
],
)
Expand Down Expand Up @@ -1010,16 +1004,13 @@ def _g_sup_zz_r(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^rho",
"e^rho",
"sqrt(g)_t",
"sqrt(g)",
"e_rho",
"e_rho",
"e_theta",
"e_rho_t",
"e_rho_t",
"e_theta_t",
"e_zeta_t",
"e_zeta",
],
)
def _g_sup_rr_t(params, transforms, profiles, data, **kwargs):
Expand Down Expand Up @@ -1157,15 +1148,12 @@ def _g_sup_rz_t(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^theta",
"e^theta",
"sqrt(g)_t",
"sqrt(g)",
"e_theta",
"e_theta",
"e_zeta",
"e_rho",
"e_theta_t",
"e_theta_t",
"e_zeta_t",
"e_rho_t",
],
)
Expand Down Expand Up @@ -1255,15 +1243,12 @@ def _g_sup_tz_t(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^zeta",
"e^zeta",
"sqrt(g)_t",
"sqrt(g)",
"e_zeta",
"e_zeta",
"e_theta",
"e_rho",
"e_zeta_t",
"e_zeta_t",
"e_theta_t",
"e_rho_t",
],
)
Expand Down Expand Up @@ -1304,15 +1289,12 @@ def _g_sup_zz_t(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^rho",
"e^rho",
"sqrt(g)_z",
"sqrt(g)",
"e_rho",
"e_rho",
"e_zeta",
"e_theta",
"e_rho_z",
"e_rho_z",
"e_zeta_z",
"e_theta_z",
],
)
Expand Down Expand Up @@ -1451,15 +1433,12 @@ def _g_sup_rz_z(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^theta",
"e^theta",
"sqrt(g)_z",
"sqrt(g)",
"e_theta",
"e_theta",
"e_zeta",
"e_rho",
"e_theta_z",
"e_theta_z",
"e_zeta_z",
"e_rho_z",
],
)
Expand Down Expand Up @@ -1549,15 +1528,12 @@ def _g_sup_tz_z(params, transforms, profiles, data, **kwargs):
profiles=[],
coordinates="rtz",
data=[
"e^zeta",
"e^zeta",
"sqrt(g)_z",
"sqrt(g)",
"e_zeta",
"e_zeta",
"e_theta",
"e_rho",
"e_zeta_z",
"e_zeta_z",
"e_theta_z",
"e_rho_z",
],
)
Expand Down
11 changes: 4 additions & 7 deletions desc/compute/_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _psi_rr(params, transforms, profiles, data, **kwargs):
units_long="Webers",
description="Toroidal flux (normalized by 2pi), third radial derivative",
dim=1,
params=["Psi"],
params=[],
transforms={},
profiles=[],
coordinates="r",
Expand Down Expand Up @@ -509,9 +509,9 @@ def _iota(params, transforms, profiles, data, **kwargs):
current_term = put(
current_term, transforms["grid"].axis, limit[transforms["grid"].axis]
)
data["iota"] = (current_term + data["iota_zero_current_num"]) / data[
"iota_zero_current_den"
]
data["iota"] = (current_term + data["iota_zero_current_num"]) / (
data["iota_zero_current_den"]
)
return data


Expand All @@ -530,7 +530,6 @@ def _iota(params, transforms, profiles, data, **kwargs):
"iota",
"psi_r",
"psi_rr",
"iota_zero_current_num",
"iota_zero_current_num_r",
"iota_zero_current_den",
"iota_zero_current_den_r",
Expand Down Expand Up @@ -582,8 +581,6 @@ def _iota_r(params, transforms, profiles, data, **kwargs):
"psi_r",
"psi_rr",
"psi_rrr",
"iota_zero_current_num",
"iota_zero_current_num_r",
"iota_zero_current_num_rr",
"iota_zero_current_den",
"iota_zero_current_den_r",
Expand Down
31 changes: 31 additions & 0 deletions docs/sort_compute_funs.py
ddudt marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Sort the compute functions and print to specified output.

First command line argument is module name, e.g. "_basis_vectors".
Second command line output is file to print to,
e.g. "sorted_basis_vectors.txt".
"""

import inspect
import re
import sys

import desc.compute

# Gather all compute function source code and map quantity name to source code.
source_codes = {}
pattern = re.compile(r"(?<=name=)[^,]+")
for module_name, module in inspect.getmembers(desc.compute, inspect.ismodule):
if module_name == sys.argv[1]:
for _, fun in inspect.getmembers(module, inspect.isfunction):
source_code = inspect.getsource(fun)
# quantities that this function computes
matches = pattern.findall(source_code)
if matches: # skip imported functions
source_codes[matches[0]] = source_code

# Write compute functions sorted by name to file.
with open(sys.argv[2], "w") as output_file:
for name in sorted(source_codes):
output_file.write("\n")
output_file.write(source_codes[name])
output_file.write("\n")
Loading