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

Adding a separate factor for NFP to calculate umbilic configurations #819

Draft
wants to merge 369 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
369 commits
Select commit Hold shift + click to select a range
95ce834
Wrap jit at outer level
unalmis May 27, 2024
fe0b099
Avoid unnecessary intermediate computation in computing ripple
unalmis May 27, 2024
34ff754
Use uniform quadrature over pitch integral because fat banana orbits …
unalmis May 27, 2024
e6183c5
Add neemov gamma_c
unalmis May 28, 2024
c5b5d69
Fix units and naming schemes, remove jit around compute fun
unalmis May 28, 2024
c333a53
Merge branch 'bounce' into ripple
unalmis May 28, 2024
c264cff
Integrate over λ instead of b.
unalmis May 29, 2024
599f895
making progress on neoclassical stuff
unalmis May 29, 2024
bc6b982
Fix math, results look kinda good now
unalmis May 30, 2024
beade78
Merge branch 'bounce' into ripple
unalmis May 31, 2024
808806c
Fix units after change of variables
unalmis May 31, 2024
b87ca1a
Fix comment discussing Nemov and Velasco Gamma_c
unalmis May 31, 2024
169af3a
Add neo comparison utitilies
unalmis May 31, 2024
f2687b6
Merge branch 'bounce' into ripple
unalmis Jun 2, 2024
50a0810
Merge branch 'bounce' into ripple
unalmis Jun 2, 2024
a9feffd
Detach Gamma_c
unalmis Jun 2, 2024
b7bd540
adding new objectives.... testing now
rahulgaur104 Jun 2, 2024
f704326
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jun 2, 2024
34b0857
trying to change files without running
rahulgaur104 Jun 2, 2024
47ee84a
Merge branch 'rg/NFP_fac' of https://github.com/PlasmaControl/DESC in…
rahulgaur104 Jun 2, 2024
7d81004
adding some comments to desc/objectives/_geometry.py
rahulgaur104 Jun 2, 2024
f3a03f4
modifying __init__.py
rahulgaur104 Jun 2, 2024
02e6a25
small changes, bug fixes
rahulgaur104 Jun 2, 2024
a8162e0
small changes, bug fixes2
rahulgaur104 Jun 2, 2024
6dae027
small changes, bug fixes3
rahulgaur104 Jun 2, 2024
59dea2f
fixing mini bugs
rahulgaur104 Jun 3, 2024
ae700f0
Merge branch 'bounce' into ripple
unalmis Jun 3, 2024
b45c0dc
Update things after merge
unalmis Jun 3, 2024
45493ae
Merge branch 'bounce' into ripple
unalmis Jun 3, 2024
f757c43
rerunning examples with NFP_umbilic_factor
rahulgaur104 Jun 4, 2024
bc17c5d
Merge branch 'bounce' into ripple
unalmis Jun 4, 2024
72c61c1
removing NFP_umbilic_factor from equilibrium/surface/boozer plotting …
rahulgaur104 Jun 5, 2024
7f309ba
more changes, trying something else, curve parameters not changing at…
rahulgaur104 Jun 7, 2024
a2903cb
Normalize effective ripple by B_0 = max_tz |B| instead of B_0 = 1.
unalmis Jun 8, 2024
9d58c4e
Merge branch 'bounce' into ripple
unalmis Jun 10, 2024
545d76d
new changes, trying different things
rahulgaur104 Jun 10, 2024
c5b1fbf
Merge branch 'bounce' into ripple
unalmis Jun 11, 2024
57d6f7f
Add test and notes
unalmis Jun 11, 2024
2737194
Add baseline image test for W7-X effective ripple
unalmis Jun 11, 2024
104b3b4
Reduce memory usage in tests_neoclassical
unalmis Jun 11, 2024
4454500
Interpolate |∇ψ| κ_g together since it is smoother than κ_g alone.
unalmis Jun 12, 2024
db8b7be
Merge branch 'bounce' into ripple
unalmis Jun 12, 2024
66b24a5
Add effective ripple objective function
unalmis Jun 13, 2024
bf981dd
Add effective ripple magnetic axis limit
unalmis Jun 13, 2024
3c2aabd
Fix effective ripple label
unalmis Jun 13, 2024
4db2468
Fix doc build, and reduce first order dependency amount for effective…
unalmis Jun 13, 2024
7b5b7c0
Fix wrong alpha_t calculation and add grad(|B|)*b test
unalmis Jun 15, 2024
2dbfeb0
Add quantities in attempt to debug length derivative along field line…
unalmis Jun 17, 2024
2d01ef4
Add finite difference test or parallel gradient
unalmis Jun 17, 2024
cce1018
Merge branch 'bounce' into ripple
unalmis Jun 18, 2024
12b39c9
Fix bug with sign of derivative in effective ripple...
unalmis Jun 18, 2024
2e730bd
Partially undo previous commit --
unalmis Jun 18, 2024
d1c7d4a
Merge branch 'bounce' into ripple
unalmis Jun 18, 2024
9c68b41
No more nan in effective ripple gradient
unalmis Jun 22, 2024
f0ac159
Merge branch 'bounce' into ripple
unalmis Jun 22, 2024
6a3965c
Merge branch 'bounce' into ripple
unalmis Jun 22, 2024
fc1be1c
Add equilibrium.rtz_grid method to avoid circular import and update d…
unalmis Jun 24, 2024
0319dca
Mark test_parallel_grad xfail
unalmis Jun 24, 2024
9dc81b3
Merge branch 'bounce' into ripple
unalmis Jun 25, 2024
38d82a7
average before integration to reduce computation
unalmis Jun 25, 2024
381543f
Merge branch bounce into ripple
unalmis Jun 28, 2024
54dab1a
Merge branch 'bounce' into ripple
unalmis Jul 1, 2024
4b3983e
Do review suggestions, remove Quadrature grid from ripple objective
unalmis Jul 2, 2024
3f75c09
Merge branch 'bounce' into ripple
unalmis Jul 2, 2024
ee437ea
Merge branch 'bounce' into ripple
unalmis Jul 2, 2024
84a4508
merging master + resolving conflicts
rahulgaur104 Jul 2, 2024
fd16fb1
trying to pass tests
rahulgaur104 Jul 2, 2024
e60f186
trying to pass tests 2
rahulgaur104 Jul 2, 2024
470f94c
trying to pass tests 3
rahulgaur104 Jul 2, 2024
363826c
trying to pass tests 4, replacing example h5 files with master
rahulgaur104 Jul 2, 2024
b7ba63e
trying to pass tests 5
rahulgaur104 Jul 3, 2024
4cc2600
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 3, 2024
4d01a27
trying to pass tests 6
rahulgaur104 Jul 3, 2024
3545bf8
Merge branch 'rg/NFP_fac' of https://github.com/PlasmaControl/DESC in…
rahulgaur104 Jul 3, 2024
640c22b
Merge branch 'better_warning' into rg/NFP_fac
unalmis Jul 3, 2024
9bf401f
Add setup method
unalmis Jul 3, 2024
d55002f
Merge branch 'better_warning' into rg/NFP_fac
unalmis Jul 3, 2024
50e467d
trying to pass tests 7; adding NFP_umbilic_factor to FourierRZCurve o…
rahulgaur104 Jul 3, 2024
a79ff5b
trying to pass tests 8; small fixes to geometry and tests
rahulgaur104 Jul 3, 2024
f8d99c2
trying to pass tests 9
rahulgaur104 Jul 3, 2024
891df62
trying to pass tests 10
rahulgaur104 Jul 3, 2024
939c2ee
trying to pass tests 11; focusing on omnigenity
rahulgaur104 Jul 3, 2024
7f6e232
trying to pass tests 12; adding umbilic objective to test_objective_funs
rahulgaur104 Jul 3, 2024
dfabb73
trying to fix tests 13; adding NFP_umbilic_factor to more equilibria
rahulgaur104 Jul 3, 2024
a0f2e56
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 3, 2024
d64c149
trying to fix tests 14; correcting fourier calles from desc/basis.py
rahulgaur104 Jul 3, 2024
74f50e2
Merge branch 'rg/NFP_fac' of https://github.com/PlasmaControl/DESC in…
rahulgaur104 Jul 3, 2024
dd2af9f
trying to fix tests 15; fixed test_from_input_file
rahulgaur104 Jul 4, 2024
a58e3f6
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 4, 2024
11aa91e
trying to fix tests 16
rahulgaur104 Jul 4, 2024
6e74392
trying to fix tests 16; removing warning to forcefully fix tests
rahulgaur104 Jul 4, 2024
06a3810
trying to fix tests 17
rahulgaur104 Jul 4, 2024
06a054a
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 5, 2024
96ac3e9
Merge branch 'bounce' into ripple
unalmis Jul 5, 2024
6827fcd
Fix comment
unalmis Jul 5, 2024
0c995d1
Merge with Clebsch branch
unalmis Jul 8, 2024
ec4d2b9
Merge branch 'dp/hotfix-fourierrzcoil-from-values' into rg/NFP_fac
dpanici Jul 9, 2024
98c6dc1
add umbilic fac to from values of rzcoil
dpanici Jul 9, 2024
d83ef84
Merge branch 'dp/hotfix-fourierrzcoil-from-values' into rg/NFP_fac
dpanici Jul 9, 2024
227ef05
adding UmbilicHighCurvature3 to test a different idea
rahulgaur104 Jul 9, 2024
d324bdc
making changes suggested by @dpanici
rahulgaur104 Jul 9, 2024
33c3322
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 9, 2024
c417568
Replacing the old, bloated logic with a different idea
rahulgaur104 Jul 11, 2024
8a8d9de
Merge branch 'bounce' into ripple and clean up bloated test so that I…
unalmis Jul 11, 2024
85ffee8
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 11, 2024
97e081f
Leftover merge conflicts
unalmis Jul 11, 2024
bbdc694
trying to fix tests 1
rahulgaur104 Jul 11, 2024
9f1371b
Merge branch 'clebsh_basis' into ripple
unalmis Jul 11, 2024
1335af3
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 18, 2024
17a012c
generalizing to any umbilic factor value
rahulgaur104 Jul 19, 2024
bc903fc
Merge branch 'rg/NFP_fac' of https://github.com/PlasmaControl/DESC in…
rahulgaur104 Jul 19, 2024
6430b05
merging master _+ resolving conflicts
rahulgaur104 Jul 20, 2024
3e836a1
better way to tile phi_arr for an umbilic grid
rahulgaur104 Jul 20, 2024
4aab276
trying to pass tests 1
rahulgaur104 Jul 20, 2024
ae1bcdd
merging master again
rahulgaur104 Jul 20, 2024
a3b414c
modifying desc/grid.py and adding suggestion by @unalmis
rahulgaur104 Jul 20, 2024
ce1c280
Merge branch 'bounce' into ripple
unalmis Jul 20, 2024
a28dade
Remove no longer needed jitable argument in get_profiles
unalmis Jul 20, 2024
8b4662f
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 23, 2024
4fec399
fixing bad merge
rahulgaur104 Jul 23, 2024
0fd56fb
Merge branch 'rg/NFP_fac' of https://github.com/PlasmaControl/DESC in…
rahulgaur104 Jul 23, 2024
fd4c90c
trying to pass tests 1
rahulgaur104 Jul 23, 2024
6c6d630
trying to pass tests 2
rahulgaur104 Jul 24, 2024
c434bc9
trying to pass tests 3
rahulgaur104 Jul 24, 2024
2a579e5
small changes; should pass all tests now!
rahulgaur104 Jul 24, 2024
72e87ad
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 24, 2024
ea6e0dc
Merge branch 'bounce' into ripple
unalmis Jul 24, 2024
5409b40
Merge branch 'bounce' into ripple
unalmis Jul 25, 2024
10ac679
Update master compute data
unalmis Jul 25, 2024
f54abb4
Update master compute data again
unalmis Jul 25, 2024
5d61f58
Only get profiles in build of objective
unalmis Jul 25, 2024
51f3eb9
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Jul 25, 2024
3e49a8b
Merge branch 'bounce' into ripple
unalmis Jul 25, 2024
84d1134
Merge branch 'bounce' into ripple
unalmis Jul 25, 2024
68efde6
Add num_wells parameter to increase performance
unalmis Jul 25, 2024
a8bbbc9
Merge branch 'bounce' into ripple
unalmis Jul 25, 2024
5fb62bf
Add num_wells to objective
unalmis Jul 25, 2024
c1c6c16
Merge branch 'bounce' into ripple
unalmis Jul 26, 2024
a603df2
Add num_wells as static variables to compute fun
unalmis Jul 26, 2024
70a3e43
Use kwargs in simpson integral to match API change in quadax from las…
unalmis Jul 26, 2024
d2aa516
merging master + resolving conflicts; test_compute_everything still f…
rahulgaur104 Aug 6, 2024
661e6cd
Merge branch 'bounce' into ripple
unalmis Aug 7, 2024
8e3da2a
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Aug 8, 2024
aa736c6
trying to fix test_compute_everything
rahulgaur104 Aug 8, 2024
7fb4108
merging master
rahulgaur104 Aug 8, 2024
a74ecc7
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Aug 8, 2024
b055f69
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Aug 9, 2024
a3e1ba4
Take mean later since doesn't matter for speed and easier to do multi…
unalmis Aug 18, 2024
fb13f31
Merge branch 'bounce' into ripple
unalmis Aug 18, 2024
cbeda22
Merge branch 'ku/root_3d' into ripple
unalmis Aug 18, 2024
0133d89
merging master manually
rahulgaur104 Aug 19, 2024
060c3df
trying to fix test compute everything
rahulgaur104 Aug 20, 2024
5b0393e
Merge branch 'bounce' into ripple
unalmis Aug 20, 2024
a0e5db1
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Aug 20, 2024
85c0e5a
trying to fix tests 2
rahulgaur104 Aug 21, 2024
dc96488
fixing more tests
rahulgaur104 Aug 21, 2024
7fd499f
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Aug 22, 2024
c1adee8
Update desc/grid.py 1
rahulgaur104 Aug 22, 2024
93cd89b
Update desc/grid.py 2
rahulgaur104 Aug 22, 2024
90f0cf8
merging master
rahulgaur104 Aug 23, 2024
bea5c58
some more changes
rahulgaur104 Aug 23, 2024
2f42c57
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Aug 24, 2024
6d3c6c3
plotting re-change
rahulgaur104 Aug 24, 2024
b1441e1
merging master manually
rahulgaur104 Aug 27, 2024
70017ae
removing UmbilicLowCurvature and adding ability to have any rational …
rahulgaur104 Aug 28, 2024
5495574
merging master manually
rahulgaur104 Aug 28, 2024
b73582c
small changes; desc plotting does not allow FourierRZCurves!
rahulgaur104 Aug 28, 2024
36428d3
Merge branch 'bounce' into ripple
unalmis Sep 1, 2024
d952252
Merge branch 'bounce' into ripple
unalmis Sep 1, 2024
4e9ebb9
Update effective ripple computation for all changes in upstream branches
unalmis Sep 2, 2024
c1e7aec
decoupling umbilic stuff from FourierRZCurve as much as possible; cre…
rahulgaur104 Sep 2, 2024
a526797
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Sep 2, 2024
9ff79da
Merge branch 'utils' into ripple
unalmis Sep 2, 2024
04a0d52
Remove test that is now redue to test with effective ripple
unalmis Sep 2, 2024
b383358
Merge branch 'bounce' into ripple
unalmis Sep 3, 2024
654a5ff
Same as commit f596dc6 and d382df3
unalmis Sep 3, 2024
9e80037
Fixing Pycharm's automated refactor
unalmis Sep 3, 2024
a93a6da
Merge branch 'master' into ripple
unalmis Sep 3, 2024
fb1fe2c
making more changes; adding a registered compute function A for umbil…
rahulgaur104 Sep 3, 2024
8bdcb8f
Merge branch 'rg/NFP_fac' of https://github.com/PlasmaControl/DESC in…
rahulgaur104 Sep 3, 2024
1833a89
commenting parametrization in the register compute function
rahulgaur104 Sep 3, 2024
0f319e0
Merge branch 'utils' into ripple
unalmis Sep 3, 2024
8d5f3d3
Remove adaptive quadrature for now
unalmis Sep 3, 2024
3b1ffc0
Merge branch 'utils' into ripple
unalmis Sep 3, 2024
3b5441f
Allow kwargs to bounce.plot
unalmis Sep 4, 2024
fd914e8
Merge branch 'utils' into ripple
unalmis Sep 4, 2024
f2c26d9
Merge branch 'utils' into ripple
unalmis Sep 4, 2024
9d981ff
Update effective ripple objective to work with recent changes to master
unalmis Sep 4, 2024
a841067
recent changes
rahulgaur104 Sep 4, 2024
f4a94f5
MAJOR REFACTORING HERE! CREATING AN UMBILICURVE CLASS INDEPENDENT OF …
rahulgaur104 Sep 4, 2024
1b17023
MAJOR REFACTORING HERE! CREATING AN UMBILICURVE CLASS INDEPENDENT OF …
rahulgaur104 Sep 4, 2024
6fdff0b
merging master manually
rahulgaur104 Sep 4, 2024
456d1a8
atone for pycharm's bad automated refactor commit number 3
unalmis Sep 4, 2024
a459f4e
changing the umbiliccurve API to directly take in phi and A
rahulgaur104 Sep 5, 2024
df484c0
pre-committing
rahulgaur104 Sep 5, 2024
fc8b393
Merge branch 'master' into ripple
f0uriest Sep 6, 2024
598009f
Merge commit 'fc8b393' into ripple
unalmis Sep 15, 2024
d266505
Merge branch 'master' into ripple
unalmis Sep 15, 2024
9a968e6
Compute quadrature nodes once outside objective.compute
unalmis Sep 15, 2024
b4151d9
Fix nan leak in reverse mode ad for bounce integral
unalmis Sep 15, 2024
8b656f2
Fix comment that one poloidal transit is sufficient if axissymetric
unalmis Sep 15, 2024
3a93117
Use _constants instead of constants
unalmis Sep 15, 2024
52adba9
Improve quadrature over velocity coordiante for effective ripple
unalmis Sep 16, 2024
8d9b605
Cleaner solution to b4151d9
unalmis Sep 16, 2024
5bc4b35
Simplify computation of quad points
unalmis Sep 16, 2024
6146dc4
Remove now unnecessary code
unalmis Sep 16, 2024
0366137
Better quadrature for weakly singular bounce integrals
unalmis Sep 17, 2024
6a46efb
fix comment about change of variable
unalmis Sep 17, 2024
bd68679
Use interior nodes only for more fair test
unalmis Sep 17, 2024
06d5061
Add documentation on which quadrature to use
unalmis Sep 17, 2024
53fd368
Merge branch 'master' into ripple
unalmis Sep 18, 2024
454bf3b
Merge branch 'master' into ripple
unalmis Sep 18, 2024
41f3727
Increase test_compute_everything tolerance
unalmis Sep 18, 2024
6e3b0e7
Merge branch 'master' into ripple
unalmis Sep 19, 2024
e2b58c7
Removing period argument
unalmis Sep 19, 2024
44ef80f
adding another objective to make umbilic curve field aligned
rahulgaur104 Sep 20, 2024
df0590b
Merge branch 'ku/fourier_bounce_part1' into ripple
unalmis Sep 22, 2024
4756c38
Merge branch 'ku/fourier_bounce_part1' into ripple
unalmis Sep 22, 2024
2073547
Avoid redundant computation of bounce points
unalmis Sep 22, 2024
e5d150c
Merge branch 'ku/fourier_bounce_part1' into ripple
unalmis Sep 22, 2024
1edd349
Complete @f0uriest 's request to compare against Neo
unalmis Sep 22, 2024
850001a
Add neo out file to desc repository
unalmis Sep 22, 2024
0ae5c9a
Do remaining review suggestion
unalmis Sep 22, 2024
8cb2a28
Fix linear interpolation for bad neo values
unalmis Sep 22, 2024
21235b4
Fix neo script
unalmis Sep 22, 2024
098db02
Merge branch 'ku/fourier_bounce_part1' into ripple
unalmis Sep 22, 2024
eb3370b
Merge branch 'ku/fourier_bounce_part1' into ripple
unalmis Sep 24, 2024
56a88a8
Update _write_neo
unalmis Sep 24, 2024
9e88270
Merge branch 'master' into ripple
unalmis Sep 24, 2024
8840c9c
Review suggestions
unalmis Sep 24, 2024
2dffde2
Add epsilon 3/2 and effective ripple as distinct
unalmis Sep 25, 2024
73a6b48
Increase entropy of test compute everything to pass test
unalmis Sep 26, 2024
6c1cd12
Fix DESC docs variable name
unalmis Sep 26, 2024
5b4456d
Merge branch 'master' into ripple
unalmis Sep 26, 2024
7d88eac
Simplify latex label
unalmis Sep 26, 2024
c819e32
Merge branch 'master' into ripple
unalmis Sep 26, 2024
157e57b
Add chunk size option
unalmis Sep 26, 2024
883b34d
Merge branch 'master' into ripple
unalmis Sep 27, 2024
1b3b6f2
Fix name in test
unalmis Sep 27, 2024
a2a3d71
Merge branch 'master' into ripple
rahulgaur104 Sep 27, 2024
384670d
manually merging ripple into rg/NFP_fac
rahulgaur104 Sep 28, 2024
3e4c0ab
Review requests and refactor to avoid explicit broadcast
unalmis Sep 29, 2024
998c830
Clean up
unalmis Sep 29, 2024
499a6c7
Move changes from downstream branch here
unalmis Sep 30, 2024
71b42bd
Merge branch 'master' into ripple
unalmis Sep 30, 2024
e5bfd38
Merge branch 'master' into ripple
rahulgaur104 Oct 4, 2024
1466bfb
manually merging ripple into rg/NFP_fac
rahulgaur104 Oct 16, 2024
ae939e9
Merge branch 'master' into ripple
unalmis Oct 17, 2024
1e1089d
Merge branch 'ripple' into rg/NFP_fac
rahulgaur104 Oct 17, 2024
466e478
Merge branch 'master' into rg/NFP_fac
rahulgaur104 Oct 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
3 changes: 3 additions & 0 deletions desc/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
if use_jax: # noqa: C901 - FIXME: simplify this, define globally and then assign?
from jax import custom_jvp, jit, vmap

# --no-verifyfrom jax import custom_jvp, vmap
# --no-verifyjit = lambda func, *args, **kwargs: func

imap = jax.lax.map
from jax.experimental.ode import odeint
from jax.lax import cond, fori_loop, scan, switch, while_loop
Expand Down
83 changes: 68 additions & 15 deletions desc/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class _Basis(IOAble, ABC):
"_M",
"_N",
"_NFP",
# --no-verify "_NFP_umbilic_factor",
"_modes",
"_sym",
"_spectral_indexing",
Expand Down Expand Up @@ -186,6 +187,11 @@ def NFP(self):
"""int: Number of field periods."""
return self.__dict__.setdefault("_NFP", 1)

@property
def NFP_umbilic_factor(self):
"""int: Umbilic factor field periods."""
return self.__dict__.setdefault("_NFP_umbilic_factor", 1)
Copy link
Collaborator

@unalmis unalmis Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to add logic to def _set_up to set this factor for old equilibrium. Sometimes it might be as simple as
self._NFP_umbilic_factor = self.NFP_umbilic_factor

The setup method will be called automatically when you load an old file with examples.get("W7-X"). (The code that does this is here

if hasattr(obj, "_set_up"):
)

You may need to do this for every object that adds the new NFP attribute


@property
def sym(self):
"""str: Type of symmetry."""
Expand Down Expand Up @@ -213,8 +219,14 @@ def __repr__(self):
type(self).__name__
+ " at "
+ str(hex(id(self)))
+ " (L={}, M={}, N={}, NFP={}, sym={}, spectral_indexing={})".format(
self.L, self.M, self.N, self.NFP, self.sym, self.spectral_indexing
+ " (L={}, M={}, N={}, NFP={}, sym={},\
spectral_indexing={})".format(
self.L,
self.M,
self.N,
self.NFP,
self.sym,
self.spectral_indexing,
)
)

Expand All @@ -239,6 +251,7 @@ def __init__(self, L, sym="even"):
self._M = 0
self._N = 0
self._NFP = 1
self._sym = sym
self._sym = bool(sym) if not sym else str(sym)
self._spectral_indexing = "linear"

Expand Down Expand Up @@ -340,18 +353,24 @@ class FourierSeries(_Basis):
Maximum toroidal resolution.
NFP : int
number of field periods
NFP_umbilic_factor : int
Prefactor of the form 1/NFP_umbilic_fac.
This is needed for the umbilic torus design.
sym : {``'cos'``, ``'sin'``, False}
* ``'cos'`` for cos(m*t-n*z) symmetry
* ``'sin'`` for sin(m*t-n*z) symmetry
* ``False`` for no symmetry (Default)

"""

def __init__(self, N, NFP=1, sym=False):
def __init__(self, N, NFP=1, NFP_umbilic_factor=1, sym=False):
self._L = 0
self._M = 0
self._N = check_nonnegint(N, "N", False)
self._NFP = check_posint(NFP, "NFP", False)
self._NFP_umbilic_factor = check_posint(
NFP_umbilic_factor, "NFP_umbilic_factor", False
)
self._sym = bool(sym) if not sym else str(sym)
self._spectral_indexing = "linear"

Expand Down Expand Up @@ -422,13 +441,20 @@ def evaluate(
z = z[zidx]
n = n[nidx]

toroidal = fourier(z[:, np.newaxis], n, self.NFP, derivatives[2])
toroidal = fourier(
z[:, np.newaxis],
n,
self.NFP,
self.NFP_umbilic_factor,
derivatives[2],
)

if unique:
toroidal = toroidal[zoutidx][:, noutidx]

return toroidal

def change_resolution(self, N, NFP=None, sym=None):
def change_resolution(self, N, NFP=None, NFP_umbilic_factor=None, sym=None):
"""Change resolution of the basis to the given resolutions.

Parameters
Expand All @@ -437,12 +463,20 @@ def change_resolution(self, N, NFP=None, sym=None):
Maximum toroidal resolution.
NFP : int
Number of field periods.
NFP_umbilic_factor : float
Prefactor of the form 1/NFP_umbilic_factor.
This is needed for the umbilic torus design.
sym : bool
Whether to enforce stellarator symmetry.

"""
NFP = check_posint(NFP, "NFP")
self._NFP = NFP if NFP is not None else self.NFP
self._NFP_umbilic_factor = (
NFP_umbilic_factor
if NFP_umbilic_factor is not None
else self.NFP_umbilic_factor
)
if N != self.N:
self._N = check_nonnegint(N, "N", False)
self._sym = sym if sym is not None else self.sym
Expand Down Expand Up @@ -561,8 +595,16 @@ def evaluate(
m = m[midx]
n = n[nidx]

poloidal = fourier(t[:, np.newaxis], m, 1, derivatives[1])
toroidal = fourier(z[:, np.newaxis], n, self.NFP, derivatives[2])
poloidal = fourier(
t[:, np.newaxis], m, NFP=1, NFP_umbilic_factor=1, dt=derivatives[1]
)
toroidal = fourier(
z[:, np.newaxis],
n,
NFP=self.NFP,
NFP_umbilic_factor=1,
dt=derivatives[2],
)
if unique:
poloidal = poloidal[toutidx][:, moutidx]
toroidal = toroidal[zoutidx][:, noutidx]
Expand Down Expand Up @@ -770,7 +812,7 @@ def evaluate(
m = m[midx]

radial = zernike_radial(r[:, np.newaxis], lm[:, 0], lm[:, 1], dr=derivatives[0])
poloidal = fourier(t[:, np.newaxis], m, 1, derivatives[1])
poloidal = fourier(t[:, np.newaxis], m, 1, 1, derivatives[1])

if unique:
radial = radial[routidx][:, lmoutidx]
Expand Down Expand Up @@ -902,8 +944,8 @@ def evaluate(
l, m, n = modes.T

radial = chebyshev(r[:, np.newaxis], l, dr=derivatives[0])
poloidal = fourier(t[:, np.newaxis], m, 1, derivatives[1])
toroidal = fourier(z[:, np.newaxis], n, self.NFP, derivatives[2])
poloidal = fourier(t[:, np.newaxis], m, 1, 1, derivatives[1])
toroidal = fourier(z[:, np.newaxis], n, self.NFP, 1, derivatives[2])

return radial * poloidal * toroidal

Expand Down Expand Up @@ -1132,8 +1174,14 @@ def evaluate(
n = n[nidx]

radial = zernike_radial(r[:, np.newaxis], lm[:, 0], lm[:, 1], dr=derivatives[0])
poloidal = fourier(t[:, np.newaxis], m, dt=derivatives[1])
toroidal = fourier(z[:, np.newaxis], n, NFP=self.NFP, dt=derivatives[2])
poloidal = fourier(t[:, np.newaxis], m, 1, 1, dt=derivatives[1])
toroidal = fourier(
z[:, np.newaxis],
n,
NFP=self.NFP,
NFP_umbilic_factor=1,
dt=derivatives[2],
)
if unique:
radial = radial[routidx][:, lmoutidx]
poloidal = poloidal[toutidx][:, moutidx]
Expand Down Expand Up @@ -1652,7 +1700,7 @@ def chebyshev(r, l, dr=0):


@jit
def fourier(theta, m, NFP=1, dt=0):
def fourier(theta, m, NFP=1, NFP_umbilic_factor=1, dt=0):
"""Fourier series.

Parameters
Expand All @@ -1663,6 +1711,9 @@ def fourier(theta, m, NFP=1, dt=0):
poloidal/toroidal mode number(s)
NFP : int
number of field periods (Default = 1)
NFP_umbilic_factor : int
NFP prefactor of the form 1/NFP_umbilic_factor.
This is needed for the umbilic torus design.
dt : int
order of derivative (Default = 0)

Expand All @@ -1672,9 +1723,11 @@ def fourier(theta, m, NFP=1, dt=0):
basis function(s) evaluated at specified points

"""
theta, m, NFP, dt = map(jnp.asarray, (theta, m, NFP, dt))
theta, m, NFP, NFP_umbilic_factor, dt = map(
jnp.asarray, (theta, m, NFP, NFP_umbilic_factor, dt)
)
m_pos = (m >= 0).astype(int)
m_abs = jnp.abs(m) * NFP
m_abs = jnp.abs(m) * NFP / NFP_umbilic_factor
shift = m_pos * jnp.pi / 2 + dt * jnp.pi / 2
return m_abs**dt * jnp.sin(m_abs * theta + shift)

Expand Down
66 changes: 58 additions & 8 deletions desc/coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ def _compute_position(self, params=None, grid=None, dx1=False, **kwargs):
basis = kwargs.get("basis", "xyz")
if basis.lower() == "rpz":
x = x.at[:, :, 1].set(jnp.mod(x[:, :, 1], 2 * jnp.pi))

# --no-verify x = x.at[:, :, 1].set(x[:, :, 1])

if dx1:
return x, x_s
return x
Expand Down Expand Up @@ -533,7 +536,9 @@ def to_SplineXYZ(self, knots=None, grid=None, method="cubic", name="", **kwargs)
self.current, coords, knots=knots, method=method, name=name, basis="xyz"
)

def to_FourierRZ(self, N=10, grid=None, NFP=None, sym=False, name="", **kwargs):
def to_FourierRZ(
self, N=10, grid=None, NFP=None, NFP_umbilic_factor=None, sym=False, name=""
):
"""Convert Coil to FourierRZCoil representation.

Note that some types of coils may not be representable in this basis.
Expand All @@ -560,11 +565,19 @@ def to_FourierRZ(self, N=10, grid=None, NFP=None, sym=False, name="", **kwargs):

"""
NFP = 1 or NFP
NFP_umbilic_factor = 1 or NFP_umbilic_factor
if grid is None:
grid = LinearGrid(N=2 * N + 1)
grid = LinearGrid(N=2 * N + 1, NFP_umbilic_factor=NFP_umbilic_factor)
coords = self.compute("x", grid=grid, basis="xyz")["x"]
return FourierRZCoil.from_values(
self.current, coords, N=N, NFP=NFP, basis="xyz", sym=sym, name=name
self.current,
coords,
N=N,
NFP=NFP,
NFP_umbilic_factor=NFP_umbilic_factor,
basis="xyz",
sym=sym,
name=name,
)

def to_FourierPlanar(self, N=10, grid=None, basis="xyz", name="", **kwargs):
Expand Down Expand Up @@ -616,6 +629,8 @@ class FourierRZCoil(_Coil, FourierRZCurve):
mode numbers associated with Z_n, defaults to modes_R
NFP : int
number of field periods
NFP_umbilic_factor : int
umbilic factor
sym : bool
whether to enforce stellarator symmetry
name : str
Expand Down Expand Up @@ -663,13 +678,26 @@ def __init__(
modes_R=None,
modes_Z=None,
NFP=1,
NFP_umbilic_factor=1,
sym="auto",
name="",
):
super().__init__(current, R_n, Z_n, modes_R, modes_Z, NFP, sym, name)
super().__init__(
current, R_n, Z_n, modes_R, modes_Z, NFP, NFP_umbilic_factor, sym, name
)

@classmethod
def from_values(cls, current, coords, N=10, NFP=1, basis="rpz", sym=False, name=""):
def from_values(
cls,
current,
coords,
N=10,
NFP=1,
NFP_umbilic_factor=1,
basis="rpz",
name="",
sym=False,
):
"""Fit coordinates to FourierRZCoil representation.

Parameters
Expand All @@ -684,6 +712,9 @@ def from_values(cls, current, coords, N=10, NFP=1, basis="rpz", sym=False, name=
NFP : int
Number of field periods, the curve will have a discrete toroidal symmetry
according to NFP.
NFP_umbilic_factor : int
Umbilic factor to fit curves that go around multiple times toroidally before
closing on themselves.
basis : {"rpz", "xyz"}
basis for input coordinates. Defaults to "rpz"
sym : bool
Expand All @@ -699,7 +730,13 @@ def from_values(cls, current, coords, N=10, NFP=1, basis="rpz", sym=False, name=

"""
curve = super().from_values(
coords=coords, N=N, NFP=NFP, basis=basis, sym=sym, name=name
coords,
N=N,
NFP=NFP,
NFP_umbilic_factor=NFP_umbilic_factor,
basis=basis,
sym=sym,
name=name,
)
return FourierRZCoil(
current=current,
Expand All @@ -708,6 +745,7 @@ def from_values(cls, current, coords, N=10, NFP=1, basis="rpz", sym=False, name=
modes_R=curve.R_basis.modes[:, 2],
modes_Z=curve.Z_basis.modes[:, 2],
NFP=NFP,
NFP_umbilic_factor=NFP_umbilic_factor,
sym=curve.sym,
name=name,
)
Expand Down Expand Up @@ -2036,7 +2074,14 @@ def to_FourierPlanar(
)

def to_FourierRZ(
self, N=10, grid=None, NFP=None, sym=False, name="", check_intersection=True
self,
N=10,
grid=None,
NFP=None,
NFP_umbilic_factor=None,
sym=False,
name="",
check_intersection=True,
):
"""Convert all coils to FourierRZCoil representaion.

Expand Down Expand Up @@ -2065,7 +2110,12 @@ def to_FourierRZ(
New representation of the coilset parameterized by a Fourier series for R,Z.

"""
coils = [coil.to_FourierRZ(N=N, grid=grid, NFP=NFP, sym=sym) for coil in self]
coils = [
coil.to_FourierRZ(
N=N, grid=grid, NFP=NFP, NFP_umbilic_factor=NFP_umbilic_factor, sym=sym
)
for coil in self
]
return self.__class__(
*coils,
NFP=self.NFP,
Expand Down
14 changes: 12 additions & 2 deletions desc/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ def rescale(
eq = eq.copy()

# size scaling
grid_L = QuadratureGrid(L=eq.L_grid, M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP)
grid_L = QuadratureGrid(
L=eq.L_grid,
M=eq.M_grid,
N=eq.N_grid,
NFP=eq.NFP,
)
data_L = eq.compute(L_keys, grid=grid_L)
L_old = data_L[L_key]
L_new = L_new or L_old
Expand All @@ -227,7 +232,12 @@ def rescale(
data_B = eq.compute("<|B|>_vol", grid=grid_B)
B_old = data_B["<|B|>_vol"]
elif B_key == "B_max":
grid_B = LinearGrid(M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, rho=1)
grid_B = LinearGrid(
M=eq.M_grid,
N=eq.N_grid,
NFP=eq.NFP,
rho=1,
)
data_B = eq.compute("|B|", grid=grid_B)
B_old = np.max(data_B["|B|"])
B_new = B_new or B_old
Expand Down
2 changes: 2 additions & 0 deletions desc/compute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
_field,
_geometry,
_metric,
_neoclassical,
_omnigenity,
_profiles,
_stability,
_surface,
_umbiliccurve,
)
from .data_index import all_kwargs, allowed_kwargs, data_index
from .geom_utils import rpz2xyz, rpz2xyz_vec, xyz2rpz, xyz2rpz_vec
Expand Down
Loading
Loading