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

Magnetic axis limits and new variables #556

Merged
merged 142 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 141 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
753ee67
Update basis vectors for new toroidal stream function
f0uriest Apr 11, 2023
cc01178
Add compute functions for toroidal stream function
f0uriest Apr 11, 2023
866cfc6
Add toroidal stream function to equilibrium and objectives etc
f0uriest Apr 11, 2023
fec2a53
Add constraint to fix omega at boundary
f0uriest Apr 11, 2023
d2a350e
Add analytic derivatives wrt misc coordinates
f0uriest Apr 26, 2023
00b5646
Add new function for mapping between coordinate systems
f0uriest Apr 26, 2023
bea0d7a
Merge branch 'master' into rc/toroidal_angle
f0uriest Apr 26, 2023
b111d00
Start adding toroidal stream function to surfaces
f0uriest Apr 26, 2023
b7cca7a
Finish adding toroidal stream function to surfaces
f0uriest May 5, 2023
1918075
Merge branch 'master' into rc/toroidal_angle
f0uriest May 29, 2023
77515dd
Fix calculation of alpha, theta_PEST, sqrt(g)_PEST etc
f0uriest May 29, 2023
63a9264
Copy iota compute fun refactor from PR #448
unalmis Jun 1, 2023
8948ee1
Update iota for toroidal stream function
unalmis Jun 1, 2023
7fefcfd
started updating _field.py for toroidal angle
unalmis Jun 1, 2023
34fe673
Merge branch 'master' into rc/toroidal_angle
f0uriest Jun 8, 2023
01c340b
Add new contravariant magnetic field qtys
f0uriest Jun 8, 2023
8bc4bf9
Add Wb_mn to perturbation functions
f0uriest Jun 8, 2023
a9fcd8f
Merge branch 'master' into rc/toroidal_angle
unalmis Jun 16, 2023
a23d44b
Merge branch 'function_integral' into add_all_limits
unalmis Jun 22, 2023
bb4d761
Create checkpoint for axis limit side quest
unalmis Jun 25, 2023
c80a9d7
first pass for adding magnetic field limits
unalmis Jun 26, 2023
39512f5
Merge branch 'master' into add_all_limits
unalmis Jun 26, 2023
d9279de
add more axis limits
unalmis Jun 27, 2023
2c0af13
Merge branch 'master' into add_all_limits
unalmis Jun 27, 2023
0123d39
update axis_limits test
unalmis Jun 28, 2023
7d9a3ca
add limits and update api
unalmis Jul 3, 2023
1b4ca01
Fix norm bug in n_rho computation
unalmis Jul 4, 2023
17bf5cb
update limit api to lambda function
unalmis Jul 4, 2023
3f797ee
add more limtis
unalmis Jul 5, 2023
026348b
make compress and expand grid object methods
unalmis Jul 5, 2023
4f57efd
refactor surface utils tests
unalmis Jul 5, 2023
8dd1293
clean up code, fix bugs in grid.py related to change_resolution
unalmis Jul 6, 2023
c3d67c4
update contravariant metrics with limits
unalmis Jul 7, 2023
4945449
add iota deriv limits
unalmis Jul 9, 2023
6598c48
Note bug in denominator limit
unalmis Jul 10, 2023
17e1561
start detangle process
unalmis Jul 10, 2023
a812ff2
detangle with rc/toroidal_angle
unalmis Jul 10, 2023
733bbce
set omega to dummy variable of 0
unalmis Jul 10, 2023
14e10b0
remove and comment
unalmis Jul 10, 2023
5b7ab09
Merge branch 'master' into add_all_limits
unalmis Jul 10, 2023
cd83609
remove remaining references to omega bdry modes
unalmis Jul 10, 2023
6310993
Merge branch 'master' into add_all_limits
unalmis Jul 10, 2023
55025ee
fix test
unalmis Jul 10, 2023
d577b5a
do black formatting and remove reference to removed function
unalmis Jul 10, 2023
b4a124c
add data deps test
unalmis Jul 11, 2023
e3f2652
fix up stuff
unalmis Jul 11, 2023
ca74912
Fix limit tests and improve speed significantly
unalmis Jul 13, 2023
5a6232f
fix grad(B) test
unalmis Jul 13, 2023
a3bac54
update tests
unalmis Jul 13, 2023
7be37cb
Fix iota derivatives limits
unalmis Jul 16, 2023
de73385
fix return type
unalmis Jul 16, 2023
6a8b626
update axis limit tests
unalmis Jul 16, 2023
bab5ad7
Use boolean and for qs function
unalmis Jul 16, 2023
dadc1cc
Fix up tests for axis limits and plotting
unalmis Jul 16, 2023
9185546
Merge branch 'master' into add_all_limits
unalmis Jul 16, 2023
c3aee53
Remove testing crutch
unalmis Jul 16, 2023
03c23d4
Resolve merge conflicts, fix logic bug in plotting
unalmis Jul 17, 2023
886c262
resolve flake linting comments
unalmis Jul 17, 2023
14835f6
Convert vectors to xyz basis before finite differencing
f0uriest Jul 13, 2023
0cac8c2
Fix boundary conditions on 2d finite differencing
f0uriest Jul 13, 2023
48f54cc
Update tests/test_constrain_current.py
unalmis Jul 17, 2023
b5f4fc1
Update plotting limit
unalmis Jul 17, 2023
c93a5b8
make plotting fsa limit more robust
unalmis Jul 17, 2023
ac7eb79
Revert changes to transform to resolve in different PR
unalmis Jul 17, 2023
0ecfd34
Fix test constrain current test for higher order derivatives
unalmis Jul 18, 2023
4657eb4
Resolve github actions
unalmis Jul 18, 2023
5bb120c
cosmetic change
unalmis Jul 19, 2023
73d436b
Merge branch 'master' into add_all_limits
unalmis Jul 19, 2023
e4d236a
Merge branch 'higher_order_deriv' into add_all_limits
unalmis Jul 19, 2023
5cb82ca
Allow fourth order radial derivs in profiles...
unalmis Jul 19, 2023
3ed6cff
Fix failing tests
unalmis Jul 21, 2023
25df43c
Merge branch 'master' into add_all_limits
unalmis Jul 21, 2023
464a2a4
Ignore division by zero warnings in compute funs
unalmis Jul 21, 2023
9a258f5
Recreate transforms in equilibrium set_up for current...
unalmis Jul 21, 2023
0248ed0
Python 3.8 compatible dict union
unalmis Jul 21, 2023
38df04d
Fix magnetic field derivative and add test...
unalmis Jul 21, 2023
fddc199
Make sure axis limit test can identify dicontinuities
unalmis Jul 21, 2023
780ba18
Decrease tolerance for optimizer test until review
unalmis Jul 21, 2023
248e158
Mark augmented lagrangian test xfail..
unalmis Jul 22, 2023
dbc4331
Vmec test durations, generalize a test_constrain_current
unalmis Jul 22, 2023
c58e610
Add test_toroidal_current test
unalmis Jul 22, 2023
0c80f6d
Merge branch 'higher_order_deriv' into add_all_limits
unalmis Jul 22, 2023
9ba77f0
Fix Heliotron vac usage in TestConstrainCurrent
unalmis Jul 23, 2023
f10e7c3
Reduce tolerance for QIC solve test
unalmis Jul 23, 2023
2ca4454
Update test durations
unalmis Jul 23, 2023
0f77e1c
Revert adding axis to boozer plot functions
unalmis Jul 23, 2023
e7d8c85
Regenerate plotting test baselines
unalmis Jul 23, 2023
44fd582
Pull request review suggestions number 1...
unalmis Jul 25, 2023
e6ea383
Update test durations after renaming test_compute_utils
unalmis Jul 25, 2023
d7f3c04
Make logic to plot axis limit in plot_fsa more clear
unalmis Jul 25, 2023
d138435
Revert unneeded change
unalmis Jul 25, 2023
bf27e10
Update names as requested in PR review
unalmis Jul 25, 2023
ac8113c
sort _core using script to make next merge easier
unalmis Aug 1, 2023
2a1cfb7
Merge branch 'master' into add_all_limits
unalmis Aug 1, 2023
d8821e9
Sort _basis_vectors to prepare for later merge
unalmis Aug 1, 2023
57e2a2e
Prevent registering same function twice
unalmis Aug 1, 2023
1e3a7f8
Implement new limits
unalmis Aug 1, 2023
e5bb5db
Fix calls to data_index in plotting.py
unalmis Aug 1, 2023
1fe56f6
Fix calls to data_index in plotting.py
unalmis Aug 1, 2023
6e5e992
Fix calls to data_index in tests/test_plotting.py
unalmis Aug 1, 2023
55fdde4
Fix e_zeta_rtt
unalmis Aug 1, 2023
5864bf2
tighten limit test tolerance
unalmis Aug 1, 2023
da10561
switch to better fitting method
unalmis Aug 1, 2023
f56dfd0
use dedicated variable in test_axis_limits test
unalmis Aug 1, 2023
256fbb0
Merge branch 'master' into add_all_limits
dpanici Aug 2, 2023
d7dd933
Fix plot_fsa handling of nan in surface average
unalmis Aug 4, 2023
b16400f
Merge branch 'master' into add_all_limits
unalmis Aug 8, 2023
4605ad1
Add new surface quantities needed after merging #583...
unalmis Aug 9, 2023
8987a73
Reduce resolution of map_coordinates test to avoid memory issues on CI
f0uriest Aug 4, 2023
72e49f7
update duration to match rename
unalmis Aug 9, 2023
8e6ebbe
remove tests for older JAX versions, increase test split to 3 to avoi…
dpanici Aug 5, 2023
0176c66
Change vmec save to regression to try avoid OOM issue
unalmis Aug 9, 2023
47428a1
Merge branch 'master' into add_all_limits...
unalmis Aug 10, 2023
766ffc6
Merge branch 'master' into add_all_limits...
unalmis Aug 10, 2023
88c18c9
switch docstring to cdots instead of ldots
unalmis Aug 10, 2023
a56cd54
Consolidate tests per Rory's suggestion
unalmis Aug 11, 2023
8feb914
Merge branch 'basis_vectors' into add_all_limits
unalmis Aug 11, 2023
c91ed8f
Merge branch 'master' into add_all_limits
dpanici Aug 11, 2023
2546383
Merge remote-tracking branch 'refs/remotes/origin/add_all_limits' int…
unalmis Aug 11, 2023
a34cebf
Merge branch 'master' into add_all_limits
unalmis Aug 11, 2023
8b1902c
Correct comments in curvature limit computation
unalmis Aug 11, 2023
e2850b8
sort .test_durations to reduce diff size
unalmis Aug 12, 2023
42e6358
Merge branch 'master' into add_all_limits
unalmis Aug 14, 2023
6f469e8
fix conflict from old cherry-pick
unalmis Aug 14, 2023
6e15796
Merge branch 'master' into add_all_limits...
unalmis Aug 15, 2023
fe56f4d
Merge branch 'master' into add_all_limits
unalmis Aug 15, 2023
097500c
Set multivalued limits to nan
unalmis Aug 16, 2023
a25f135
Update adding_compute_fun for axis limit example
unalmis Aug 16, 2023
49eceeb
Merge branch 'master' into add_all_limits
unalmis Aug 16, 2023
df90d2a
Continue to compute functions which are multivalued at magnetic axis
unalmis Aug 18, 2023
97cf821
Merge branch 'master' into add_all_limits
unalmis Aug 18, 2023
7c34329
Unicode latexify comments
unalmis Aug 18, 2023
19cd967
Merge branch 'master' into add_all_limits
unalmis Aug 18, 2023
bb843be
Add test to checks compuation values against master branch
unalmis Aug 18, 2023
0acb6a3
Change units as requested...
unalmis Aug 18, 2023
da35935
Add atol due to rounding errors from different machines
unalmis Aug 18, 2023
5e49354
Add justification for limit of current density J
unalmis Aug 19, 2023
299352d
Enforce cross product of mixed partial derivatives is 0 in
unalmis Aug 19, 2023
8f4d606
Remove D_current and D_shear from not_finite_limits by assuming
unalmis Aug 22, 2023
5be7dbe
Add units to iota_psi
unalmis Aug 22, 2023
2a8f941
Remove unneeded dependencies from D_current for now
unalmis Aug 22, 2023
092d6a3
add missing lambda function to iota_psi
unalmis Aug 23, 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
861 changes: 443 additions & 418 deletions .test_durations

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions desc/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
val = body_fun(i, val)
return val

def cond(pred, true_fun, false_fun, operand):
def cond(pred, true_fun, false_fun, *operand):

Check warning on line 204 in desc/backend.py

View check run for this annotation

Codecov / codecov/patch

desc/backend.py#L204

Added line #L204 was not covered by tests
"""Conditionally apply true_fun or false_fun.

This version is for the numpy backend, for jax backend see jax.lax.cond
Expand All @@ -227,9 +227,9 @@

"""
if pred:
return true_fun(operand)
return true_fun(*operand)

Check warning on line 230 in desc/backend.py

View check run for this annotation

Codecov / codecov/patch

desc/backend.py#L230

Added line #L230 was not covered by tests
else:
return false_fun(operand)
return false_fun(*operand)

Check warning on line 232 in desc/backend.py

View check run for this annotation

Codecov / codecov/patch

desc/backend.py#L232

Added line #L232 was not covered by tests

def switch(index, branches, operand):
"""Apply exactly one of branches given by index.
Expand Down
10 changes: 5 additions & 5 deletions desc/compute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Parameters
----------
params : dict of ndarray
Parameters from the equilibrium, such as R_lmn, Z_lmn, i_l, p_l, etc
Parameters from the equilibrium, such as R_lmn, Z_lmn, i_l, p_l, etc.
transforms : dict of Transform
Transforms for R, Z, lambda, etc
Transforms for R, Z, lambda, etc.
profiles : dict of Profile
Profile objects for pressure, iota, current, etc
Profile objects for pressure, iota, current, etc.
data : dict of ndarray
Data computed so far, generally output from other compute functions
kwargs : dict
Expand Down Expand Up @@ -59,8 +59,8 @@
# import the compute module.
def _build_data_index():

for p in data_index.keys():
for key in data_index[p].keys():
for p in data_index:
for key in data_index[p]:
full = {
"data": get_data_deps(key, p, has_axis=False),
"transforms": get_derivs(key, p, has_axis=False),
Expand Down
52 changes: 42 additions & 10 deletions desc/compute/_basis_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
transforms={},
profiles=[],
coordinates="rtz",
data=["B"],
data=["B", "|B|"],
)
def _b(params, transforms, profiles, data, **kwargs):
data["b"] = (data["B"].T / jnp.linalg.norm(data["B"], axis=-1)).T
data["b"] = (data["B"].T / data["|B|"]).T

Check warning on line 32 in desc/compute/_basis_vectors.py

View check run for this annotation

Codecov / codecov/patch

desc/compute/_basis_vectors.py#L32

Added line #L32 was not covered by tests
return data


Expand All @@ -47,6 +47,8 @@
data=["e_theta/sqrt(g)", "e_zeta"],
)
def _e_sup_rho(params, transforms, profiles, data, **kwargs):
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞^ρ | ρ=0 }.
data["e^rho"] = cross(data["e_theta/sqrt(g)"], data["e_zeta"])
return data

Expand Down Expand Up @@ -196,8 +198,14 @@
profiles=[],
coordinates="rtz",
data=["e_rho", "e_zeta"],
parameterization=[
"desc.equilibrium.equilibrium.Equilibrium",
"desc.geometry.core.Surface",
],
)
def _e_sup_theta_times_sqrt_g(params, transforms, profiles, data, **kwargs):
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞^θ √g | ρ=0 }.
data["e^theta*sqrt(g)"] = cross(data["e_zeta"], data["e_rho"])
return data

Expand Down Expand Up @@ -299,6 +307,8 @@
data=["e_rho", "e_theta/sqrt(g)"],
)
def _e_sup_zeta(params, transforms, profiles, data, **kwargs):
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞^ζ | ρ=0 }.
data["e^zeta"] = cross(data["e_rho"], data["e_theta/sqrt(g)"])
return data

Expand Down Expand Up @@ -453,6 +463,8 @@
data=["R", "R_r", "Z_r", "omega_r"],
)
def _e_sub_rho(params, transforms, profiles, data, **kwargs):
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞ᵨ | ρ=0 }.
data["e_rho"] = jnp.array([data["R_r"], data["R"] * data["omega_r"], data["Z_r"]]).T
return data

Expand Down Expand Up @@ -1386,6 +1398,8 @@
axis_limit_data=["e_theta_r", "sqrt(g)_r"],
)
def _e_sub_theta_over_sqrt_g(params, transforms, profiles, data, **kwargs):
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞_θ / √g | ρ=0 }.
data["e_theta/sqrt(g)"] = transforms["grid"].replace_at_axis(
(data["e_theta"].T / data["sqrt(g)"]).T,
lambda: (data["e_theta_r"].T / data["sqrt(g)_r"]).T,
Expand Down Expand Up @@ -1426,6 +1440,8 @@
data=["R", "R_r", "R_rt", "R_t", "Z_rt", "omega_r", "omega_rt", "omega_t"],
)
def _e_sub_theta_r(params, transforms, profiles, data, **kwargs):
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { ∂ᵨ 𝐞_θ | ρ=0 }
data["e_theta_r"] = jnp.array(
[
-data["R"] * data["omega_t"] * data["omega_r"] + data["R_rt"],
Expand Down Expand Up @@ -3428,16 +3444,22 @@
profiles=[],
coordinates="rtz",
data=["e_theta", "e_zeta", "|e_theta x e_zeta|"],
axis_limit_data=["e_theta_r", "|e_theta x e_zeta|_r"],
parameterization=[
"desc.equilibrium.equilibrium.Equilibrium",
"desc.geometry.core.Surface",
],
)
def _n_rho(params, transforms, profiles, data, **kwargs):
# equal to e^rho / |e^rho| but works correctly for surfaces as well that don't have
# contravariant basis defined
data["n_rho"] = (
cross(data["e_theta"], data["e_zeta"]) / data["|e_theta x e_zeta|"][:, None]
# Equal to 𝐞^ρ / ‖𝐞^ρ‖ but works correctly for surfaces as well that don't
# have contravariant basis defined.
data["n_rho"] = transforms["grid"].replace_at_axis(
(cross(data["e_theta"], data["e_zeta"]).T / data["|e_theta x e_zeta|"]).T,
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞^ρ / ‖𝐞^ρ‖ | ρ=0 }.
lambda: (
cross(data["e_theta_r"], data["e_zeta"]).T / data["|e_theta x e_zeta|_r"]
dpanici marked this conversation as resolved.
Show resolved Hide resolved
).T,
)
return data

Expand All @@ -3460,9 +3482,11 @@
],
)
def _n_theta(params, transforms, profiles, data, **kwargs):
# Equal to 𝐞^θ / ‖𝐞^θ‖ but works correctly for surfaces as well that don't
# have contravariant basis defined.
data["n_theta"] = (
cross(data["e_zeta"], data["e_rho"]) / data["|e_zeta x e_rho|"][:, None]
)
cross(data["e_zeta"], data["e_rho"]).T / data["|e_zeta x e_rho|"]
).T
return data


Expand All @@ -3478,13 +3502,21 @@
profiles=[],
coordinates="rtz",
data=["e_rho", "e_theta", "|e_rho x e_theta|"],
axis_limit_data=["e_theta_r", "|e_rho x e_theta|_r"],
parameterization=[
"desc.equilibrium.equilibrium.Equilibrium",
"desc.geometry.core.Surface",
],
)
def _n_zeta(params, transforms, profiles, data, **kwargs):
data["n_zeta"] = (
cross(data["e_rho"], data["e_theta"]) / data["|e_rho x e_theta|"][:, None]
# Equal to 𝐞^ζ / ‖𝐞^ζ‖ but works correctly for surfaces as well that don't
# have contravariant basis defined.
data["n_zeta"] = transforms["grid"].replace_at_axis(
(cross(data["e_rho"], data["e_theta"]).T / data["|e_rho x e_theta|"]).T,
# At the magnetic axis, this function returns the multivalued map whose
# image is the set { 𝐞^ζ / ‖𝐞^ζ‖ | ρ=0 }.
lambda: (
cross(data["e_rho"], data["e_theta_r"]).T / data["|e_rho x e_theta|_r"]
).T,
)
return data
Loading
Loading