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 all 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,238 changes: 2,989 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.

1 change: 1 addition & 0 deletions desc/compute/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def j_dot_B_Redl(
"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 @@ -257,7 +257,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 @@ -766,10 +766,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 @@ -907,16 +907,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 @@ -1005,15 +1002,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 @@ -1054,16 +1048,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 @@ -1201,15 +1192,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 @@ -1299,15 +1287,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 @@ -1348,15 +1333,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 @@ -1495,15 +1477,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 @@ -1593,15 +1572,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
39 changes: 39 additions & 0 deletions docs/sort_compute_funs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Sort the compute functions and print to specified output.

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

import inspect
import re
import sys

import desc.compute

preamble = ""

# Gather all compute function source code and map 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]:
# everything in the module until the first compute function
# (import statements, etc.)
preamble = inspect.getsource(module).partition("@register_compute_fun")[0]
for function_name, fun in inspect.getmembers(module, inspect.isfunction):
source_code = inspect.getsource(fun)
matches = pattern.findall(source_code)
if matches: # skip imported functions
# matches[0] is the thing this function says it computes, e.g. x
# while function_name is e.g. _x_ZernikeRZToroidalSection
if function_name in source_codes:
raise ValueError("Can't sort when things have same name.")
source_codes[function_name] = source_code

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