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

Poincare Boundary Condition #782

Open
wants to merge 327 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
327 commits
Select commit Hold shift + click to select a range
7bf9508
Merge branch 'master' into dp/poincare
YigitElma Feb 8, 2024
62f40a9
fix format
YigitElma Feb 8, 2024
92d6188
fix parse surface for poincare bc
YigitElma Feb 9, 2024
3a8f5a2
fix parse surface for poincare bc
YigitElma Feb 9, 2024
10ea2c1
fix divide by 0 test, local pc doesnt throw error
YigitElma Feb 9, 2024
0dffdf8
revert back setup.cfg
YigitElma Feb 9, 2024
ee1180b
add get_poincare_surface_at function
YigitElma Feb 9, 2024
126d7a7
add Lb_lmn to perturb
YigitElma Feb 9, 2024
0262853
update perturbation and lambda consistency
YigitElma Feb 10, 2024
bb04b2f
Merge branch 'master' into dp/poincare
YigitElma Feb 10, 2024
c6b83fb
fix Lambda basis creation
YigitElma Feb 13, 2024
c5566b5
fix poincare surface
YigitElma Feb 13, 2024
66140e0
fix poincare basis again, dimensions cause problem
YigitElma Feb 13, 2024
1cb7fb8
fix basis resolution consistency
YigitElma Feb 13, 2024
c60852c
Merge branch 'master' into dp/poincare
YigitElma Feb 14, 2024
8f92b7a
fix node pattern error test, SOLOVEV poincare shouldn't give error fo…
YigitElma Feb 14, 2024
fd82c12
change Poincare solution method for tests to my version
YigitElma Feb 14, 2024
fd361a5
change poincare test to HELIOTRON
YigitElma Feb 14, 2024
dc71bb8
fix HELIOTRON poincare test
YigitElma Feb 15, 2024
64b73cc
use heliotron input file for node_pattern warning input file
YigitElma Feb 15, 2024
6a776a0
add missing Lb_lmn
YigitElma Feb 15, 2024
1853b1d
fix typo
YigitElma Feb 15, 2024
28b67db
delete second boundary constraints
YigitElma Feb 15, 2024
098919c
fix Lb_lmn conditions
YigitElma Feb 15, 2024
9b7b36b
add print_summary function for equilibrium
YigitElma Feb 15, 2024
42c5b53
Merge branch 'master' into dp/poincare
YigitElma Feb 15, 2024
9010ec6
delete W7X output
YigitElma Feb 16, 2024
6278d31
add xsection parameter to equilibrium, add new objectives, add Rp, Zp…
YigitElma Feb 16, 2024
e22ebd1
add _xsection not loaded exception
YigitElma Feb 16, 2024
586cbad
add backwards compatibility for xsection
YigitElma Feb 16, 2024
cf45e4e
update outputs for backwards compatibility, add script to automize this
YigitElma Feb 16, 2024
db40974
Merge branch 'master' into dp/poincare
YigitElma Feb 16, 2024
0979f52
fix xsection.isgiven attribute not found
YigitElma Feb 17, 2024
f3f75aa
add errors for continuation functions
YigitElma Feb 17, 2024
4d9de15
fix perturb
YigitElma Feb 17, 2024
20b2809
add checks
YigitElma Feb 18, 2024
2b6d9bd
fix input file not supported for Poincare bc
YigitElma Feb 18, 2024
2ea65fc
update perturb
YigitElma Feb 18, 2024
fe1d9b6
fix some typos
YigitElma Feb 19, 2024
443d88b
add docs to parse_section
YigitElma Feb 19, 2024
78b69aa
add additional xsection setter after initial guess
YigitElma Feb 19, 2024
5dbf8f9
add PoincareSurface to data_index
YigitElma Feb 19, 2024
0011c67
fix parse_section
YigitElma Feb 19, 2024
838afe9
update test h5 input files for xsection
YigitElma Feb 19, 2024
2f60ba4
fix poincare_tests
YigitElma Feb 19, 2024
241b2d5
fix self-consistency constraints
YigitElma Feb 19, 2024
e244731
remove error for solve_continuation with Poincare xs
YigitElma Feb 19, 2024
ceaae2b
Merge branch 'master' into dp/poincare
YigitElma Feb 19, 2024
6c63bfb
fix initial guess from poincare
YigitElma Feb 19, 2024
ab39006
signed commit
YigitElma Feb 19, 2024
754b782
signed commit
YigitElma Feb 19, 2024
aa99440
fix isgiven property setting, fix rescaling
YigitElma Feb 20, 2024
35b7180
Merge branch 'master' into dp/poincare
YigitElma Feb 20, 2024
bec9989
fix spectral indexing for PoincareSurface
YigitElma Feb 20, 2024
db7cacd
Merge branch 'dp/poincare' of github.com:PlasmaControl/DESC into dp/p…
YigitElma Feb 20, 2024
631e102
fix surface sym and spectral indexing
YigitElma Feb 20, 2024
2b2868e
change L,M,N setting
YigitElma Feb 20, 2024
48c6185
fix sym issue
YigitElma Feb 20, 2024
7f2d8ce
fix min input, add xsection to inputs
YigitElma Feb 20, 2024
fc3f07e
increase tolerance, fix poincare test
YigitElma Feb 21, 2024
6ab6044
fix 1d_optimization test, had to add FixSection constraints
YigitElma Feb 21, 2024
258e62d
fix ProximalProjection issue, Rp_lmn not supported
YigitElma Feb 21, 2024
04bca15
fix initial guess from existing equilibrium, fix test_supplied object…
YigitElma Feb 21, 2024
c7842e1
Merge branch 'master' into dp/poincare
YigitElma Feb 22, 2024
5f61fda
Merge branch 'master' into dp/poincare
YigitElma Feb 22, 2024
72da031
fix formatting
YigitElma Feb 22, 2024
825c17f
Merge branch 'master' into dp/poincare
YigitElma Mar 6, 2024
465fdc7
fix formatting
YigitElma Mar 7, 2024
79e9929
Merge branch 'master' into dp/poincare
YigitElma Mar 7, 2024
2feb875
fix merge issues
YigitElma Mar 7, 2024
37ace57
test
YigitElma Mar 7, 2024
d74a645
Merge branch 'master' into dp/poincare
YigitElma Mar 8, 2024
6d8d22f
fix NAE init
YigitElma Mar 8, 2024
580094c
Merge branch 'dp/poincare' of https://github.com/PlasmaControl/DESC i…
YigitElma Mar 8, 2024
d4f5175
fix formatting
YigitElma Mar 8, 2024
f03b92b
fix typo in NAE init
YigitElma Mar 8, 2024
0f644d4
Merge branch 'master' into dp/poincare
YigitElma Mar 8, 2024
b30c74b
remove redundant stuff
YigitElma Mar 11, 2024
e461fdf
remove xsection.isgiven attribute
YigitElma Mar 12, 2024
fe18b8e
fix typo
YigitElma Mar 12, 2024
1b7119b
remove redundant ignore statements
YigitElma Mar 12, 2024
fa9cc41
move update_backwards .. file to devtools
YigitElma Mar 12, 2024
c2dbf45
add omit for backwards compatibility script
YigitElma Mar 12, 2024
a204867
fix parse order, add error if surface and xsection defined at the sam…
YigitElma Mar 12, 2024
7042ac0
Merge branch 'master' into dp/poincare
YigitElma Mar 12, 2024
09bbafc
fix test_dict
YigitElma Mar 13, 2024
037c983
fix test_supplied_objects, set sym from xsection
YigitElma Mar 13, 2024
d7c5288
fix test_solve_with_x_scale
YigitElma Mar 13, 2024
5a5da15
fix test_compute_everything
YigitElma Mar 13, 2024
a83a7b7
Merge branch 'master' into dp/poincare
YigitElma Mar 14, 2024
2d44514
revert DSHAPE without current to old version, update_equilibriums scr…
YigitElma Mar 15, 2024
0b409b5
fix test_compare_quantities_to_vmec, _xsection is not loaded either
YigitElma Mar 15, 2024
1931aae
fix test_load_then_save, needed to set xsection manually
YigitElma Mar 15, 2024
091f4dc
remove redundant set_up call
YigitElma Mar 15, 2024
ab44a83
Merge branch 'master' into dp/poincare
YigitElma Mar 15, 2024
9e748d6
add warning for auto_continuation with Poincare
YigitElma Mar 15, 2024
3d60d0b
Merge branch 'master' into dp/poincare
YigitElma Mar 16, 2024
aaa6ac2
Merge branch 'master' into dp/poincare
YigitElma Mar 16, 2024
0e6f84d
Merge branch 'master' into dp/poincare
YigitElma Mar 18, 2024
86f255b
Merge branch 'master' into dp/poincare
YigitElma Mar 20, 2024
ec41895
make consistency constraint names consistent
YigitElma Mar 20, 2024
5ca453b
make consistency constraint names consistent
YigitElma Mar 20, 2024
f35babd
Merge branch 'master' into dp/poincare
YigitElma Mar 23, 2024
0ab92ed
Merge branch 'master' into dp/poincare
YigitElma Apr 2, 2024
9e64a36
merge branch master into dp/poincare
YigitElma Apr 17, 2024
240f925
Merge branch 'master' into dp/poincare
YigitElma Apr 24, 2024
5b515fa
update output files
YigitElma May 1, 2024
5818321
Merge branch 'master' into dp/poincare
YigitElma May 1, 2024
2c77922
fix formatting
YigitElma May 1, 2024
8b8557a
fix formatting
YigitElma May 1, 2024
faf3794
switch back to old input version
YigitElma May 1, 2024
3ede4a3
fix update script to skip purposely missing outputs
YigitElma May 1, 2024
a8c2219
fix test_omnigenity_qa test, add xsection
YigitElma May 1, 2024
aff6616
fix and rename poincare axisymetry test
YigitElma May 1, 2024
e0fa389
test to see if this works for github actions
YigitElma May 1, 2024
6cec000
fix tests
YigitElma May 1, 2024
2a060c6
fix tests
YigitElma May 1, 2024
b2c7b69
add coverage even if some tests fail
YigitElma May 1, 2024
5517728
run other tests even one fails
YigitElma May 1, 2024
1f844b1
remove fail things
YigitElma May 1, 2024
d9120dc
change arg order, add small checks for resolution and axis
YigitElma May 1, 2024
284f814
remove unused function FourierZernike_to_FourierZernike_no_N_modes
YigitElma May 2, 2024
53e9b69
Merge branch 'dp/poincare' of github.com:PlasmaControl/DESC into dp/p…
YigitElma May 3, 2024
f827eb6
Merge branch 'master' into dp/poincare
YigitElma May 3, 2024
79c3e3e
Merge branch 'master' into dp/poincare
YigitElma May 15, 2024
a172cdd
fix formatting
YigitElma May 15, 2024
0fb3053
make branch consistent with master
YigitElma May 15, 2024
3434fc5
Merge branch 'master' into dp/poincare
YigitElma May 15, 2024
71dcdf3
Merge branch 'master' into dp/poincare
YigitElma May 17, 2024
395b46b
remove ZernikeRZToroidalSection class and merge it into PoincareRZLSe…
YigitElma May 20, 2024
907bb53
update tests
YigitElma May 20, 2024
d4609f4
fix without current issue
YigitElma May 20, 2024
e163d69
Merge branch 'master' into dp/poincare
YigitElma May 20, 2024
029c6a6
Merge branch 'master' into dp/poincare
YigitElma May 26, 2024
16cb342
Merge branch 'master' into dp/poincare
YigitElma Jun 5, 2024
75ddc42
Merge branch 'master' into dp/poincare
YigitElma Jun 18, 2024
0e1f148
update tolerance to adapt for higher matrix sizes
YigitElma Jun 19, 2024
e56db0d
Merge branch 'master' into dp/poincare
YigitElma Jul 3, 2024
62488ca
remove conflict merge pduplicated code
YigitElma Jul 3, 2024
ac3254d
merge conflicts messed up, copy basis vectors compute from master and…
YigitElma Jul 3, 2024
dc95db9
fix naming after merge conflict
YigitElma Jul 3, 2024
f9f893a
remove repeated registries
YigitElma Jul 3, 2024
673109b
remove duplicated code from merge conflict
YigitElma Jul 3, 2024
bd3eaae
reduce tolerance for incompatible constraints warning
YigitElma Jul 3, 2024
895b933
Merge branch 'master' into dp/poincare
YigitElma Jul 26, 2024
faa17af
reduce tol for NAE tests
YigitElma Jul 26, 2024
dd11914
reduce tol for NAE tests
YigitElma Jul 26, 2024
5199802
change tol for NAE test
YigitElma Jul 26, 2024
763af29
change tol for NAE test
YigitElma Jul 26, 2024
4cc6e0b
Merge branch 'master' into dp/poincare
YigitElma Jul 30, 2024
0edf2ac
move poincare tests to regression
YigitElma Aug 2, 2024
8ec6a83
Merge remote-tracking branch 'origin' into dp/poincare
YigitElma Aug 13, 2024
302b298
fix class name change after merge
YigitElma Aug 13, 2024
b31d775
copy master compute pkl from master
YigitElma Aug 13, 2024
5cd6d4a
Merge remote-tracking branch 'origin' into dp/poincare
YigitElma Aug 14, 2024
cf7c18d
copy master_compute from master
YigitElma Aug 14, 2024
ee46c7d
Merge branch 'master' into dp/poincare
YigitElma Aug 15, 2024
fc160a9
Merge branch 'master' into dp/poincare
YigitElma Aug 15, 2024
d95926c
Merge branch 'master' into dp/poincare
YigitElma Aug 18, 2024
7b31675
update notebook
YigitElma Aug 18, 2024
947977f
add force error comparison
YigitElma Aug 18, 2024
8725fa6
update kernel
YigitElma Aug 19, 2024
a4055ca
Merge branch 'master' into dp/poincare
YigitElma Aug 19, 2024
15ee864
make fixed xsection getter consistent with others
YigitElma Aug 19, 2024
634a0ca
make FixSection constraints same as master ones, probably before mast…
YigitElma Aug 19, 2024
446a6b0
Merge branch 'master' into dp/poincare
dpanici Aug 20, 2024
e6ba7f1
Merge branch 'master' into dp/poincare
YigitElma Aug 21, 2024
651641a
increase maxiter for HELIOTRON vacuum
YigitElma Aug 21, 2024
45e1270
Merge branch 'master' into dp/poincare
YigitElma Aug 21, 2024
2b087b4
change name of PoincareRZLSection to ZernikeRZLToroidalSection, remov…
YigitElma Aug 22, 2024
11f20d3
Merge branch 'master' into dp/poincare
YigitElma Aug 22, 2024
5924b37
fix the dummy mistakes and kernel
YigitElma Aug 22, 2024
86fd9a0
fix the update script to skip dshape_without_current
YigitElma Aug 22, 2024
456b59b
reduce tolerance for test
YigitElma Aug 22, 2024
823969a
Merge branch 'master' into dp/poincare
YigitElma Aug 22, 2024
dd2862e
update tolerances for heliotron vacuum test
YigitElma Aug 26, 2024
ee23dcf
Merge branch 'master' into dp/poincare
YigitElma Aug 26, 2024
bd50111
fix print format
YigitElma Aug 26, 2024
c5b0dcd
remove redundat SOLOVEV_poincare, it was not used and wouldn't even w…
YigitElma Aug 28, 2024
9c1494d
Merge branch 'dp/poincare' of github.com:PlasmaControl/DESC into dp/p…
YigitElma Aug 28, 2024
897a64f
Merge branch 'master' into dp/poincare
YigitElma Aug 29, 2024
e361cfa
Merge branch 'master' into dp/poincare
YigitElma Aug 29, 2024
312f7da
add option to not fix lambda at the section
YigitElma Aug 29, 2024
66c11d2
Merge branch 'dp/poincare' of github.com:PlasmaControl/DESC into dp/p…
YigitElma Aug 29, 2024
d886022
Merge branch 'master' into dp/poincare
YigitElma Sep 2, 2024
9dc24c2
Merge remote-tracking branch 'origin/master' into dp/poincare
YigitElma Sep 10, 2024
ff3f8fb
use Poincare variables if only we are solving Poincare, instead of ad…
YigitElma Sep 11, 2024
ff41eff
set the actual xsection after the solve
YigitElma Sep 11, 2024
c785294
Merge branch 'master' into dp/poincare
YigitElma Sep 11, 2024
cdfd422
add checks for self consistency
YigitElma Sep 12, 2024
341b4e9
update the example files
YigitElma Sep 12, 2024
25b0ab5
update poincare solve test, probably much faster now
YigitElma Sep 12, 2024
2a886db
Merge branch 'master' into dp/poincare
YigitElma Sep 12, 2024
7bf8374
add self consistency check for poincare solve, exclude lcfs stuff
YigitElma Sep 12, 2024
a7d9a8f
add todo
YigitElma Sep 12, 2024
57ed1ca
reverse lcfs self consistency change
YigitElma Sep 12, 2024
45a40d1
remove debugging function print_summary
YigitElma Sep 13, 2024
5c7fb31
remove set_poincare_equilibrium method
YigitElma Sep 13, 2024
e6ef23e
update zeta definition for get_basis_poincare and poincare objectives…
YigitElma Sep 13, 2024
090d262
remove debugging function print_modes_coefs
YigitElma Sep 13, 2024
b96f887
Merge branch 'master' into dp/poincare
YigitElma Sep 18, 2024
d35ba0d
Merge branch 'master' into dp/poincare
YigitElma Sep 20, 2024
8e6e06e
clean up equilibrium init
YigitElma Sep 20, 2024
aee0a37
Merge branch 'dp/poincare' of github.com:PlasmaControl/DESC into dp/p…
YigitElma Sep 20, 2024
22f7966
make linear constraint names consistent and clearer, re-order poincar…
YigitElma Sep 21, 2024
c03afda
Merge branch 'master' into dp/poincare
YigitElma Sep 24, 2024
5e99a17
Merge branch 'master' into dp/poincare
dpanici Sep 24, 2024
b6beab4
copy/paste heliotron vacuum from master, it was already the same but …
YigitElma Sep 24, 2024
6b42f21
remove zeta =pi option
YigitElma Sep 25, 2024
c22b75d
remove zeta from get_basis poincare and revert some tol changes
YigitElma Sep 25, 2024
3692f4b
fix test_get_zeta_surface
YigitElma Sep 25, 2024
7b03868
add perturbation test
YigitElma Sep 26, 2024
f9046c3
Merge branch 'master' into dp/poincare
YigitElma Sep 27, 2024
f64ecd7
fix ATF jac_chunk_size again
YigitElma Sep 27, 2024
702faa7
Merge branch 'master' into dp/poincare
YigitElma Sep 27, 2024
972b4b7
Merge branch 'master' into dp/poincare
YigitElma Sep 28, 2024
eb831bf
fix ATF test issue using #1279
YigitElma Sep 29, 2024
5a087dd
Merge branch 'master' into dp/poincare
YigitElma Oct 4, 2024
97989fe
Merge branch 'master' into dp/poincare
YigitElma Oct 8, 2024
92b91fc
Merge branch 'master' into dp/poincare
YigitElma Oct 9, 2024
bb48af4
Merge branch 'master' into dp/poincare
YigitElma Nov 7, 2024
c82039e
remove bdry_mode introduced in from_input_filr
YigitElma Nov 8, 2024
8e9be76
make constraint naming consistent
YigitElma Nov 8, 2024
2811717
Merge branch 'master' into dp/poincare
YigitElma Nov 11, 2024
3fa66ee
Merge branch 'master' into dp/poincare
YigitElma Nov 15, 2024
65511bd
address documentation comments, and change naming of ZernikeRZToroida…
YigitElma Dec 13, 2024
560f9a4
Merge remote-tracking branch 'origin/master' into dp/poincare
YigitElma Dec 13, 2024
e51a578
update examples with poincare section
YigitElma Dec 13, 2024
31566d2
remove redundant change to the notebook
YigitElma Dec 13, 2024
b5bff88
copy examples from master
YigitElma Dec 13, 2024
f8e855b
update the examples
YigitElma Dec 13, 2024
6accb23
fix the rotation test
YigitElma Dec 13, 2024
79e3e5b
fix vmec test
YigitElma Dec 13, 2024
c09d7b4
remove extra self consistency conditionals to test
YigitElma Dec 13, 2024
ca576ca
make maybe_add_self_consistency cleaner
YigitElma Dec 13, 2024
6cc4b4d
update section axis and surface at the end of optimization or solve o…
YigitElma Dec 13, 2024
7cef412
change the update conditions
YigitElma Dec 13, 2024
611410d
reduce toleranca for NAE test
YigitElma Dec 13, 2024
5885d76
fix perturb axis test
YigitElma Dec 13, 2024
54a35de
apply the dummy fix thing to ONLY poincare, applying it to fixed boun…
YigitElma Dec 13, 2024
e25c76b
Merge branch 'master' into dp/poincare
YigitElma Dec 13, 2024
d4fa767
remove dummy fix boundary stuff completely
YigitElma Dec 13, 2024
82a727d
Merge branch 'dp/poincare' of github.com:PlasmaControl/DESC into dp/p…
YigitElma Dec 13, 2024
654d3b3
Merge branch 'master' into dp/poincare
YigitElma Dec 14, 2024
59fb333
fix self consistency stuff better
YigitElma Dec 14, 2024
1803d4c
Merge branch 'master' into dp/poincare
dpanici Dec 18, 2024
3df85bc
Merge remote-tracking branch 'origin/master' into dp/poincare
YigitElma Dec 19, 2024
eff230f
update changelog
YigitElma Dec 19, 2024
b107590
update tutorial
YigitElma Dec 20, 2024
55f037b
Merge branch 'master' into dp/poincare
YigitElma Dec 24, 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
181 changes: 180 additions & 1 deletion desc/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from desc.backend import custom_jvp, fori_loop, gammaln, jit, jnp, sign
from desc.io import IOAble
from desc.utils import flatten_list
from desc.utils import copy_coeffs, flatten_list

__all__ = [
"PowerSeries",
Expand Down Expand Up @@ -1726,3 +1726,182 @@ def zernike_norm(l, m):

"""
return np.sqrt((2 * (l + 1)) / (np.pi * (1 + int(m == 0))))


def get_basis_poincare(X_lmn_3D, basis_3D, zeta=0):
YigitElma marked this conversation as resolved.
Show resolved Hide resolved
"""Convert 3D FourierZernikeBasis to 2D ZernikePolynomial at zeta=0.

Takes a 3D FourierZernike basis and its coefficients X_lmn_3D and evaluates
the coefficients at the zeta=0 or Pi cross-section, returning a 2D ZernikePolynomial
basis and its coefficients X_lmn_2D. The output dimension will not be the same,
only toroidal mode will be N=0.

Parameters
----------
X_lmn_3D : array, size [basis_3D.num_modes,1]
The Fourier-Zernike basis coefficients of the quantity X, that you wish to find
the 2D ZernikePolynomial basis corresponding to the quantity's value at the
zeta=0 cross-section
basis_3D : FourierZernikeBasis
The Fourier-Zernike basis corresponding to the coefficients passed.

Returns
-------
X_lmn_2D : array, size [basis_2D.num_modes,1]
The ZernikePolynomial basis coefficients of the quantity X, such that their
evaluation is the same as the input 3D basis when evaluated at zeta=0.
basis_2D : FourierZernikeBasis
The ZernikePolynomial basis corresponding to the coefficients output. The
radial resolution L and poloidal resolution M are equal to the max radial
and poloidal resolutions of the 3D basis passed as an input.
"""
# Add up all the X_lm(n>=0) modes
# so that the quantity at the zeta=0 surface is described with just lm modes
# and get rid of the toroidal modes
modes_2D = []
X_lmn_2D = (
[]
) # these are corresponding to the 2D modes of the ZernikePolynomial Basis
modes_3D = basis_3D.modes
for i, mode in enumerate(modes_3D):
if zeta == 0:
if mode[-1] < 0:
pass # we do not need the sin(zeta) modes as they = 0 at zeta=0
else:
if (mode[0], mode[1], 0) not in modes_2D:
modes_2D.append((mode[0], mode[1], 0))
l = mode[0]
m = mode[1]

inds = np.where(
np.logical_and(
(modes_3D[:, :2] == [l, m]).all(axis=1),
modes_3D[:, 2] >= 0,
)
)[0]

SUM = np.sum(X_lmn_3D[inds])
X_lmn_2D.append(SUM)
elif zeta == np.pi:
if mode[-1] < 0:
pass # we do not need the sin(zeta) modes as they = 0 at zeta=pi
else:
if (mode[0], mode[1], 0) not in modes_2D:
modes_2D.append((mode[0], mode[1], 0))
l = mode[0]
m = mode[1]

inds = np.where(
np.logical_and(
(modes_3D[:, :2] == [l, m]).all(axis=1),
modes_3D[:, 2] % 2 == 0,
)
)[0]

inds1 = np.where(
np.logical_and(
(modes_3D[:, :2] == [l, m]).all(axis=1),
modes_3D[:, 2] % 2 == 1,
)
)[0]

SUM = np.sum(X_lmn_3D[inds]) - np.sum(X_lmn_3D[inds1])
X_lmn_2D.append(SUM)

X_lmn_2D = np.asarray(X_lmn_2D)
modes_2D = np.asarray(modes_2D)

Lmax = np.max(abs(modes_2D[:, 0]))
Mmax = np.max(abs(modes_2D[:, 1]))
LM_max = max(Lmax, Mmax)
basis_2D = ZernikePolynomial(
L=LM_max,
M=LM_max,
spectral_indexing=basis_3D._spectral_indexing,
sym=basis_3D.sym,
)
X_lmn_2D = copy_coeffs(X_lmn_2D, modes_2D, basis_2D.modes)
return X_lmn_2D, basis_2D


def FourierZernike_to_FourierZernike_no_N_modes(X_lmn_3D, basis_3D, zeta=0):
"""Converts 3D FourierZernikeBasis to the same basis but with no toroidal modes.

Takes a 3D FourierZernike basis and its coefficients X_lmn_3D and evaluates the
coefficients at the zeta=0 cross-section, returning the same 3D FourierZernike
basis but with zero toroidal dependence s.t. the zeta=0 XS is the same as the input
so X_lmn_no_N = 0 for N != 0. Input and output array sizes are the same.

Parameters
----------
X_lmn_3D : array, size [basis_3D.num_modes,1]
The Fourier-Zernike basis coefficients of the quantity X, that you wish to
find the 2D ZernikePolynomial basis
corresponding to the quantity's value at the zeta=0 cross-section
basis_3D : FourierZernikeBasis
The Fourier-Zernike basis corresponding to the coefficients passed.

Returns
-------
X_lmn_no_N : array, size [basis_3D.num_modes,1]
The FourerZernike basis coefficients of the quantity X, such that their
evaluation is the same as the input 3D basis when evaluated at zeta=0.
The coefficients with nonzero toroidal modenumbers are all zero.
basis_3D : FourierZernikeBasis
The Fourier-Zernike basis corresponding to the coefficients passed.
"""
if not (zeta == 0 or zeta == np.pi):
raise ValueError("Unvalid zeta value! Only 0 or pi is supported right now!")

# Add up all the X_lm(n>=0) modes
# so that the quantity at the zeta=0 surface is described with just lm modes
# and set any mode with nonzero toroidal mode numebr = 0
X_lmn_no_N = np.zeros_like(X_lmn_3D)
modes_no_N = []
modes_3D = basis_3D.modes
for i, mode in enumerate(modes_3D):
if zeta == 0:
if mode[-1] < 0:
pass # we do not need the sin(zeta) modes as they = 0 at zeta=0
else:
if (mode[0], mode[1], 0) not in modes_no_N:
modes_no_N.append((mode[0], mode[1], 0))
l = mode[0]
m = mode[1]

inds = np.where(
np.logical_and(
(modes_3D[:, :2] == [l, m]).all(axis=1),
modes_3D[:, 2] >= 0,
)
)[0]

SUM = np.sum(X_lmn_3D[inds])
X_lmn_no_N[i] = SUM
elif zeta == np.pi:
if mode[-1] < 0:
pass # we do not need the sin(zeta) modes as they = 0 at zeta=pi
else:
if (mode[0], mode[1], 0) not in modes_no_N:
modes_no_N.append((mode[0], mode[1], 0))
l = mode[0]
m = mode[1]

inds = np.where(
np.logical_and(
(modes_3D[:, :2] == [l, m]).all(axis=1),
modes_3D[:, 2] % 2 == 0,
)
)[0]

inds1 = np.where(
np.logical_and(
(modes_3D[:, :2] == [l, m]).all(axis=1),
modes_3D[:, 2] % 2 == 1,
)
)[0]

SUM = np.sum(X_lmn_3D[inds]) - np.sum(X_lmn_3D[inds1])
X_lmn_no_N[i] = SUM

return X_lmn_no_N, basis_3D
1 change: 1 addition & 0 deletions desc/compute/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ def body(i, mins):
"Za_n",
"Rb_lmn",
"Zb_lmn",
"Lb_lmn",
)
# map from profile name to equilibrium parameter name
profile_names = {
YigitElma marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
84 changes: 71 additions & 13 deletions desc/equilibrium/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from termcolor import colored

from desc.backend import jnp
from desc.basis import FourierZernikeBasis, fourier, zernike_radial
from desc.basis import FourierZernikeBasis, fourier, get_basis_poincare, zernike_radial
from desc.compat import ensure_positive_jacobian
from desc.compute import compute as compute_fun
from desc.compute import data_index
from desc.compute.utils import get_data_deps, get_params, get_profiles, get_transforms
from desc.geometry import (
FourierRZCurve,
FourierRZToroidalSurface,
PoincareSurface,
Surface,
ZernikeRZToroidalSection,
)
Expand Down Expand Up @@ -143,7 +144,6 @@ class Equilibrium(IOAble, Optimizable):
"_atomic_number",
"_anisotropy",
"_spectral_indexing",
"_bdry_mode",
"_L_grid",
"_M_grid",
"_N_grid",
Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(
self._Z_sym = "sin" if self.sym else False

# surface
self._surface, self._bdry_mode = parse_surface(
self._surface = parse_surface(
YigitElma marked this conversation as resolved.
Show resolved Hide resolved
surface, self.NFP, self.sym, self.spectral_indexing
)

Expand Down Expand Up @@ -423,6 +423,7 @@ def _sort_args(self, args):
"Za_n",
"Rb_lmn",
"Zb_lmn",
"Lb_lmn",
)
assert sorted(args) == sorted(arg_order)
return [arg for arg in arg_order if arg in args]
Expand Down Expand Up @@ -744,6 +745,48 @@ def get_axis(self):
axis = FourierRZCurve(R_n, Z_n, modes_R, modes_Z, NFP=self.NFP, sym=self.sym)
return axis

def set_poincare_equilibrium(self, zeta=0):
YigitElma marked this conversation as resolved.
Show resolved Hide resolved
"""Sets the equilibrium for solving Poincare BC from an existing equilibrium.

Parameters
----------
self : Equilibrium
Some equilibrium to be used for creating Poincare equilibrium
zeta : float (optional)
Zeta angle at which the Poincare section will be fixed
Only 0 and Pi is supported for now

Returns
-------
eq_poincare : Equilibrium
Separate Equilibrium object to be used for Poincare BC problem
"""
surf = self.get_surface_at(zeta=zeta / self.NFP)
Lb_lmn, Lb_basis = get_basis_poincare(self.L_lmn, self.L_basis, zeta)
surface = PoincareSurface(
surface=surf, L_lmn=Lb_lmn, modes_L=Lb_basis.modes, zeta=zeta
)

eq_poincare = Equilibrium(
surface=surface,
pressure=self.pressure,
iota=self.iota,
Psi=self.Psi, # flux (in Webers) within the last closed flux surface
NFP=self.NFP, # number of field periods
L=self.L, # radial spectral resolution
M=self.M, # poloidal spectral resolution
N=self.N, # toroidal spectral resolution
L_grid=self.L_grid, # real space radial resolution, slightly oversampled
M_grid=self.M_grid, # real space poloidal resolution, slightly oversampled
N_grid=self.N_grid, # real space toroidal resolution
sym=True, # explicitly enforce stellarator symmetry
spectral_indexing=self._spectral_indexing,
)

eq_poincare.change_resolution(self.L, self.M, self.N)
eq_poincare.axis = eq_poincare.get_axis()
return eq_poincare

def compute(
self,
names,
Expand Down Expand Up @@ -1165,11 +1208,6 @@ def sym(self):
"""bool: Whether this equilibrium is stellarator symmetric."""
return self._sym

@property
def bdry_mode(self):
"""str: Method for specifying boundary condition."""
return self._bdry_mode

@optimizable_parameter
@property
def Psi(self):
Expand Down Expand Up @@ -1293,6 +1331,31 @@ def Zb_lmn(self):
def Zb_lmn(self, Zb_lmn):
self.surface.Z_lmn = Zb_lmn

@optimizable_parameter
@property
def Lb_lmn(self):
"""ndarray: Spectral coefficients of Lambda at the boundary."""
if isinstance(self.surface, PoincareSurface):
return self.surface.L_lmn
else:
return np.empty(0)

@Lb_lmn.setter
def Lb_lmn(self, Lb_lmn):
self.surface.L_lmn = Lb_lmn

@property
def Lb_basis(self):
"""ndarray: Spectral coefficients of Lambda at the boundary."""
if isinstance(self.surface, PoincareSurface):
return self.surface.L_basis
else:
return np.empty(0)

@Lb_basis.setter
def Lb_basis(self, Lb_basis):
self.surface.L_basis = Lb_basis

@optimizable_parameter
@property
def Ra_n(self):
Expand Down Expand Up @@ -1785,11 +1848,6 @@ def solve(
"yellow",
)
)
if self.bdry_mode == "poincare":
raise NotImplementedError(
"Solving equilibrium with poincare XS as BC is not supported yet "
+ "on master branch."
)

things, result = optimizer.optimize(
self,
Expand Down
Loading
Loading