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

LinkingCurrent objective #1222

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

LinkingCurrent objective #1222

wants to merge 28 commits into from

Conversation

ddudt
Copy link
Collaborator

@ddudt ddudt commented Aug 23, 2024

This is a nonlinear form of the existing linear objective FixSumCoilCurrent. It ensures the total current through the coils matches the poloidal current of the equilibrium. This is necessary for single-stage optimization where the equilibrium and coils are changing simultaneously.

@ddudt ddudt added objectives Adding or improving objective functions coil stuff relating to coils and coil optimization labels Aug 23, 2024
@ddudt ddudt self-assigned this Aug 23, 2024
Copy link
Contributor

github-actions bot commented Aug 23, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_midres         |     +5.82 +/- 4.75     | +3.48e-02 +/- 2.84e-02 |  6.33e-01 +/- 1.8e-02  |  5.99e-01 +/- 2.2e-02  |
 test_build_transform_fft_highres        |     +2.85 +/- 5.18     | +2.75e-02 +/- 5.00e-02 |  9.92e-01 +/- 4.4e-02  |  9.64e-01 +/- 2.4e-02  |
 test_equilibrium_init_lowres            |     +7.16 +/- 7.23     | +2.78e-01 +/- 2.80e-01 |  4.16e+00 +/- 4.0e-02  |  3.88e+00 +/- 2.8e-01  |
 test_objective_compile_atf              |     +2.79 +/- 3.71     | +2.19e-01 +/- 2.92e-01 |  8.09e+00 +/- 2.2e-01  |  7.87e+00 +/- 1.9e-01  |
 test_objective_compute_atf              |     +3.80 +/- 1.76     | +3.98e-04 +/- 1.84e-04 |  1.09e-02 +/- 1.5e-04  |  1.05e-02 +/- 1.0e-04  |
 test_objective_jac_atf                  |     +3.37 +/- 1.61     | +6.30e-02 +/- 3.01e-02 |  1.93e+00 +/- 2.4e-02  |  1.87e+00 +/- 1.8e-02  |
-test_perturb_1                          |     +7.24 +/- 2.34     | +1.02e+00 +/- 3.29e-01 |  1.51e+01 +/- 6.1e-02  |  1.40e+01 +/- 3.2e-01  |
 test_proximal_jac_atf                   |     +0.76 +/- 1.18     | +6.16e-02 +/- 9.52e-02 |  8.15e+00 +/- 7.9e-02  |  8.09e+00 +/- 5.4e-02  |
 test_proximal_freeb_compute             |     -0.78 +/- 0.76     | -1.53e-03 +/- 1.48e-03 |  1.94e-01 +/- 1.1e-03  |  1.96e-01 +/- 1.0e-03  |
 test_solve_fixed_iter_compiled          |     -0.37 +/- 2.13     | -6.30e-02 +/- 3.58e-01 |  1.68e+01 +/- 1.6e-01  |  1.68e+01 +/- 3.2e-01  |
 test_build_transform_fft_lowres         |     -0.90 +/- 5.43     | -5.04e-03 +/- 3.06e-02 |  5.57e-01 +/- 2.1e-02  |  5.62e-01 +/- 2.2e-02  |
 test_equilibrium_init_medres            |     -0.79 +/- 6.99     | -3.49e-02 +/- 3.10e-01 |  4.40e+00 +/- 2.2e-01  |  4.44e+00 +/- 2.2e-01  |
 test_equilibrium_init_highres           |     +2.46 +/- 5.34     | +1.37e-01 +/- 2.97e-01 |  5.71e+00 +/- 1.9e-01  |  5.57e+00 +/- 2.3e-01  |
 test_objective_compile_dshape_current   |     -1.12 +/- 6.91     | -4.43e-02 +/- 2.73e-01 |  3.91e+00 +/- 2.2e-01  |  3.95e+00 +/- 1.6e-01  |
 test_objective_compute_dshape_current   |     +0.68 +/- 2.37     | +2.46e-05 +/- 8.54e-05 |  3.63e-03 +/- 5.1e-05  |  3.60e-03 +/- 6.8e-05  |
 test_objective_jac_dshape_current       |     -0.27 +/- 7.72     | -1.14e-04 +/- 3.22e-03 |  4.16e-02 +/- 1.5e-03  |  4.17e-02 +/- 2.8e-03  |
 test_perturb_2                          |     +0.11 +/- 3.42     | +2.21e-02 +/- 6.85e-01 |  2.01e+01 +/- 3.1e-01  |  2.01e+01 +/- 6.1e-01  |
 test_proximal_freeb_jac                 |     -0.30 +/- 2.06     | -2.33e-02 +/- 1.57e-01 |  7.64e+00 +/- 9.3e-02  |  7.66e+00 +/- 1.3e-01  |
 test_solve_fixed_iter                   |     -0.37 +/- 3.61     | -1.07e-01 +/- 1.05e+00 |  2.90e+01 +/- 8.9e-01  |  2.91e+01 +/- 5.5e-01  |
 test_LinearConstraintProjection_build   |     -0.50 +/- 1.99     | -1.16e-01 +/- 4.62e-01 |  2.30e+01 +/- 2.9e-01  |  2.32e+01 +/- 3.6e-01  |

@dpanici
Copy link
Collaborator

dpanici commented Aug 28, 2024

do #1231

@dpanici
Copy link
Collaborator

dpanici commented Sep 24, 2024

Any progress on this @daniel-dudt ?

@dpanici
Copy link
Collaborator

dpanici commented Sep 25, 2024

Use Linking number calc for linear objective for sum coil currents as well, to use as weights for sum

@dpanici
Copy link
Collaborator

dpanici commented Sep 28, 2024

I think an equivalent sort of objective to ensure that the coils are creating the necessary current, without needing the linking number calculation (though I'd still like that in sometime), is to directly calculate $\int_{o}^{2\pi/NFP} \mathbf{B}{coil} \cdot \mathbf{e}{\zeta} d\zeta - \int_{o}^{2\pi/NFP} \mathbf{B}{DESC} \cdot \mathbf{e}{\zeta} d\zeta$ which is the relation that Ampere's law tells us (the second term here is $G(\rho=1)$, possibly sans a $2\pi$ factor).

This being zero means the coils are consistent with Ampere's law and avoids needing to worry about the linking currents (though this is a bit more expensive, as it relies on biot-savart integration over the coils to get $\mathbf{B}_{coil}$

@f0uriest f0uriest changed the base branch from master to rc/linking_number October 11, 2024 19:33
@f0uriest f0uriest changed the base branch from rc/linking_number to master October 15, 2024 04:06
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.63%. Comparing base (005c4f8) to head (815ad41).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1222      +/-   ##
==========================================
+ Coverage   95.59%   95.63%   +0.03%     
==========================================
  Files          96       96              
  Lines       24601    24675      +74     
==========================================
+ Hits        23518    23597      +79     
+ Misses       1083     1078       -5     
Files with missing lines Coverage Δ
desc/coils.py 97.98% <100.00%> (+0.20%) ⬆️
desc/objectives/__init__.py 100.00% <ø> (ø)
desc/objectives/_coils.py 99.34% <100.00%> (+0.06%) ⬆️

... and 2 files with indirect coverage changes

@f0uriest f0uriest marked this pull request as ready for review October 15, 2024 22:01
@f0uriest f0uriest requested review from a team and rahulgaur104 and removed request for a team October 15, 2024 22:01
@f0uriest
Copy link
Member

We had talked about adding the linking number stuff to FixSumCoilCurrents, but it might be easier to just add an eq_fixed option to this, in which case we precompute G and set self._linear = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coil stuff relating to coils and coil optimization objectives Adding or improving objective functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants