DESC icon indicating copy to clipboard operation
DESC copied to clipboard

Add Contract Equilibrium Utilities

Open dpanici opened this issue 2 years ago • 9 comments

TODO

  • [x] NO LONGER DOING, is not obvious/well-posed add expand utility (what should this be? should the current surface just be scaled to the larger rho? what about pressure/current/iota, should they be extrapolated? probably not)
  • [x] Make contract utility initialize new equilibrium with Fourier Zernike coefficients such that the new surfaces are the same as the old
    • either through explicitly calculating the new coefficients
    • or through evaluating the R,Z, lambda of the old equilibrium in a volumetric grid that ends at the desired rho value, then passing those points into the new equilibrium for it to fit its new R,Z lambda
    • https://opg.optica.org/josaa/fulltext.cfm?uri=josaa-23-3-539&id=88096 try this formula
    • Ended up just doing a simple fit which works surprisingly well, |B| is exact when compared between the contracted and full eq, and |F| is the same to rtol of 1e-4
  • [x] tests

Resolves #467

dpanici avatar Mar 30 '23 02:03 dpanici

@f0uriest what did you have in mind for the expand utility? it is not as straightforward as contraction because it is not obvious how one should continue the surface, and extrapolate the profiles (pressure may become negative, etc)

dpanici avatar Mar 30 '23 02:03 dpanici

Codecov Report

Attention: Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.75%. Comparing base (50742d8) to head (8506b71). Report is 62 commits behind head on master.

Files with missing lines Patch % Lines
desc/compat.py 95.34% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #470      +/-   ##
==========================================
- Coverage   95.75%   95.75%   -0.01%     
==========================================
  Files         101      101              
  Lines       26563    26605      +42     
==========================================
+ Hits        25436    25476      +40     
- Misses       1127     1129       +2     
Files with missing lines Coverage Δ
desc/compat.py 88.50% <95.34%> (+1.79%) :arrow_up:

... and 2 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 30 '23 04:03 codecov[bot]

For profiles it probably makes the most sense to "stretch" them so that their dependence on rho doesn't change (same for contracting, since we may not want to cut finite pressure at the edge).

For the boundary there are a few methods out there, I think Matt has one in the appendix of the Regcoil paper, and there's also another method in one of the old Hirshman papers.

f0uriest avatar Mar 30 '23 08:03 f0uriest

for vacuum could just do this, ignoring profiles, and use this to evaluate NAE at a low aspect ratio where the pyQSC rootfind fails, and just expand the higher aspect ratio one out to get it to the correct aspect ratio

dpanici avatar Jan 24 '24 21:01 dpanici

@ddudt add your contract util here

dpanici avatar Feb 07 '24 21:02 dpanici

Maybe use constant offset surface for expansion

dpanici avatar Feb 07 '24 21:02 dpanici

just do contract @dpanici

dpanici avatar Apr 10 '24 19:04 dpanici

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -0.66 +/- 8.08     | -3.46e-03 +/- 4.25e-02 |  5.23e-01 +/- 1.7e-02  |  5.27e-01 +/- 3.9e-02  |
 test_equilibrium_init_medres            |     -0.94 +/- 2.56     | -3.52e-02 +/- 9.63e-02 |  3.72e+00 +/- 2.9e-02  |  3.75e+00 +/- 9.2e-02  |
 test_equilibrium_init_highres           |     +0.64 +/- 2.94     | +3.00e-02 +/- 1.38e-01 |  4.73e+00 +/- 1.1e-01  |  4.70e+00 +/- 8.4e-02  |
 test_objective_compile_dshape_current   |     -0.36 +/- 6.15     | -1.03e-02 +/- 1.78e-01 |  2.88e+00 +/- 1.4e-01  |  2.89e+00 +/- 1.1e-01  |
 test_objective_compute_dshape_current   |     -1.50 +/- 2.08     | -5.44e-05 +/- 7.51e-05 |  3.56e-03 +/- 4.9e-05  |  3.62e-03 +/- 5.7e-05  |
 test_objective_jac_dshape_current       |     -2.62 +/- 6.97     | -1.03e-03 +/- 2.74e-03 |  3.82e-02 +/- 2.0e-03  |  3.93e-02 +/- 1.9e-03  |
 test_perturb_2                          |     -4.30 +/- 5.01     | -6.74e-01 +/- 7.86e-01 |  1.50e+01 +/- 3.0e-01  |  1.57e+01 +/- 7.3e-01  |
 test_proximal_jac_atf_with_eq_update    |     -0.39 +/- 0.59     | -6.53e-02 +/- 1.00e-01 |  1.68e+01 +/- 9.2e-02  |  1.69e+01 +/- 4.1e-02  |
 test_proximal_freeb_jac                 |     -0.31 +/- 0.68     | -1.81e-02 +/- 3.94e-02 |  5.75e+00 +/- 2.4e-02  |  5.77e+00 +/- 3.1e-02  |
 test_solve_fixed_iter_compiled          |     -2.02 +/- 3.18     | -3.67e-01 +/- 5.77e-01 |  1.78e+01 +/- 2.8e-01  |  1.81e+01 +/- 5.1e-01  |
 test_LinearConstraintProjection_build   |     -2.66 +/- 4.34     | -2.18e-01 +/- 3.56e-01 |  7.98e+00 +/- 2.1e-01  |  8.20e+00 +/- 2.8e-01  |
 test_objective_compute_ripple_spline    |     -0.46 +/- 3.87     | -1.48e-03 +/- 1.23e-02 |  3.18e-01 +/- 1.2e-02  |  3.19e-01 +/- 4.1e-03  |
 test_objective_grad_ripple_spline       |     -1.69 +/- 2.78     | -2.48e-02 +/- 4.07e-02 |  1.44e+00 +/- 2.1e-02  |  1.46e+00 +/- 3.5e-02  |
 test_build_transform_fft_midres         |     +3.22 +/- 3.97     | +1.87e-02 +/- 2.30e-02 |  5.99e-01 +/- 1.7e-02  |  5.80e-01 +/- 1.5e-02  |
 test_build_transform_fft_highres        |     +1.51 +/- 0.88     | +1.31e-02 +/- 7.63e-03 |  8.80e-01 +/- 6.7e-03  |  8.67e-01 +/- 3.7e-03  |
 test_equilibrium_init_lowres            |     +4.42 +/- 2.48     | +1.69e-01 +/- 9.49e-02 |  4.00e+00 +/- 7.3e-02  |  3.83e+00 +/- 6.0e-02  |
 test_objective_compile_atf              |     +3.71 +/- 1.44     | +2.34e-01 +/- 9.06e-02 |  6.53e+00 +/- 6.8e-02  |  6.29e+00 +/- 5.9e-02  |
 test_objective_compute_atf              |     +1.59 +/- 3.72     | +1.49e-04 +/- 3.49e-04 |  9.53e-03 +/- 2.7e-04  |  9.38e-03 +/- 2.3e-04  |
 test_objective_jac_atf                  |     +2.96 +/- 2.58     | +5.23e-02 +/- 4.57e-02 |  1.82e+00 +/- 3.9e-02  |  1.77e+00 +/- 2.4e-02  |
 test_perturb_1                          |     +4.40 +/- 2.78     | +5.62e-01 +/- 3.55e-01 |  1.33e+01 +/- 3.1e-01  |  1.28e+01 +/- 1.8e-01  |
 test_proximal_jac_atf                   |     -0.12 +/- 1.59     | -9.65e-03 +/- 1.26e-01 |  7.93e+00 +/- 1.1e-01  |  7.94e+00 +/- 5.9e-02  |
 test_proximal_freeb_compute             |     -3.53 +/- 3.73     | -5.80e-03 +/- 6.13e-03 |  1.59e-01 +/- 4.1e-03  |  1.64e-01 +/- 4.6e-03  |
 test_solve_fixed_iter                   |     +1.47 +/- 3.24     | +4.22e-01 +/- 9.30e-01 |  2.92e+01 +/- 8.3e-01  |  2.87e+01 +/- 4.2e-01  |
 test_objective_compute_ripple           |     -0.07 +/- 1.02     | -1.99e-03 +/- 2.89e-02 |  2.82e+00 +/- 2.4e-02  |  2.82e+00 +/- 1.6e-02  |
 test_objective_grad_ripple              |     +0.64 +/- 1.04     | +4.71e-02 +/- 7.59e-02 |  7.36e+00 +/- 4.6e-02  |  7.31e+00 +/- 6.0e-02  |

github-actions[bot] avatar May 08 '24 17:05 github-actions[bot]

if profile type is MTanHProfile, this will return a new MTanHProfile fit of the original profile values up to the specified inner_rho, which is not exactly the intention right, since the new profiile would have a pedestal still at the new edge just due to the functional form of the fit? we would actually rather have the returned profile be the original profile but just cut off at inner_rho...

dpanici avatar Jul 05 '24 14:07 dpanici

Add option to NOT "contract" the profile, as a fallback (or to always make a spline as a fallback if the profile is not a power series or spline) or the user can also specify this.

dpanici avatar Feb 12 '25 21:02 dpanici