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

Integrate on boundary to compute length scale quantities #1094

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

unalmis
Copy link
Collaborator

@unalmis unalmis commented Jul 2, 2024

See #1101, in particular this comment for some of other changes.

Some quantities like the plasma volume V, major radius R0, minor radius a etc. can be computed via stoke's theorem on the last closed flux surface. This pull request modifies the compute functions to default to such an integration on the boundary rather than throughout the volume so that the length scale quantities can be computed accurately on grids other than QuadratureGrid. This lets us avoid building transforms for QuadratureGrid in objectives, saving memory.

Also, might have some improvements in general

  1. Reducing dimensionality of integral makes integration more tractable with faster convergence.
  2. Transforming the integration to one over periodic domains makes it more accurate due to the exponential convergence of the quadrature on periodic domains.

@unalmis unalmis added the performance New feature or request to make the code faster label Jul 2, 2024
@unalmis unalmis changed the base branch from master to fieldline_compute July 2, 2024 19:52
@unalmis unalmis marked this pull request as ready for review July 2, 2024 19:55
@unalmis unalmis marked this pull request as draft July 2, 2024 20:31
Copy link
Contributor

github-actions bot commented Jul 2, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -0.36 +/- 5.26     | -1.92e-03 +/- 2.83e-02 |  5.36e-01 +/- 2.6e-02  |  5.38e-01 +/- 1.0e-02  |
 test_equilibrium_init_medres            |     -0.40 +/- 1.71     | -1.69e-02 +/- 7.25e-02 |  4.22e+00 +/- 5.3e-02  |  4.23e+00 +/- 5.0e-02  |
 test_equilibrium_init_highres           |     -0.20 +/- 1.43     | -1.11e-02 +/- 7.94e-02 |  5.53e+00 +/- 6.1e-02  |  5.54e+00 +/- 5.1e-02  |
 test_objective_compile_dshape_current   |     -0.18 +/- 1.15     | -6.96e-03 +/- 4.58e-02 |  3.96e+00 +/- 2.7e-02  |  3.97e+00 +/- 3.7e-02  |
 test_objective_compute_dshape_current   |     +0.20 +/- 2.46     | +1.03e-05 +/- 1.27e-04 |  5.15e-03 +/- 9.4e-05  |  5.14e-03 +/- 8.4e-05  |
 test_objective_jac_dshape_current       |     -0.09 +/- 8.28     | -3.74e-05 +/- 3.54e-03 |  4.27e-02 +/- 2.4e-03  |  4.27e-02 +/- 2.6e-03  |
 test_perturb_2                          |     -0.21 +/- 1.57     | -4.13e-02 +/- 3.16e-01 |  2.00e+01 +/- 1.9e-01  |  2.01e+01 +/- 2.5e-01  |
 test_proximal_freeb_jac                 |     -0.35 +/- 1.08     | -2.61e-02 +/- 8.04e-02 |  7.41e+00 +/- 4.6e-02  |  7.43e+00 +/- 6.6e-02  |
 test_solve_fixed_iter                   |     -0.54 +/- 2.04     | -1.57e-01 +/- 5.94e-01 |  2.90e+01 +/- 4.0e-01  |  2.91e+01 +/- 4.4e-01  |
 test_LinearConstraintProjection_build   |     -0.24 +/- 0.74     | -5.83e-02 +/- 1.76e-01 |  2.38e+01 +/- 1.5e-01  |  2.39e+01 +/- 8.8e-02  |
 test_build_transform_fft_midres         |     -0.14 +/- 2.00     | -7.98e-04 +/- 1.18e-02 |  5.88e-01 +/- 1.1e-02  |  5.89e-01 +/- 4.6e-03  |
 test_build_transform_fft_highres        |     +0.23 +/- 0.95     | +2.15e-03 +/- 8.98e-03 |  9.50e-01 +/- 7.2e-03  |  9.48e-01 +/- 5.4e-03  |
 test_equilibrium_init_lowres            |     +0.40 +/- 0.78     | +1.49e-02 +/- 2.87e-02 |  3.71e+00 +/- 2.2e-02  |  3.69e+00 +/- 1.9e-02  |
 test_objective_compile_atf              |     -0.09 +/- 3.30     | -6.89e-03 +/- 2.62e-01 |  7.94e+00 +/- 2.6e-01  |  7.94e+00 +/- 5.7e-02  |
 test_objective_compute_atf              |     -2.54 +/- 1.60     | -4.06e-04 +/- 2.56e-04 |  1.56e-02 +/- 1.1e-04  |  1.60e-02 +/- 2.3e-04  |
 test_objective_jac_atf                  |     -2.25 +/- 2.46     | -4.39e-02 +/- 4.80e-02 |  1.91e+00 +/- 4.3e-02  |  1.95e+00 +/- 2.2e-02  |
 test_perturb_1                          |     -0.38 +/- 1.20     | -5.36e-02 +/- 1.71e-01 |  1.42e+01 +/- 1.6e-01  |  1.42e+01 +/- 5.4e-02  |
 test_proximal_jac_atf                   |     -0.16 +/- 0.59     | -1.32e-02 +/- 4.80e-02 |  8.16e+00 +/- 3.3e-02  |  8.17e+00 +/- 3.5e-02  |
 test_proximal_freeb_compute             |     -0.35 +/- 0.81     | -6.88e-04 +/- 1.60e-03 |  1.98e-01 +/- 1.3e-03  |  1.98e-01 +/- 1.0e-03  |
 test_solve_fixed_iter_compiled          |     +0.20 +/- 1.08     | +3.38e-02 +/- 1.81e-01 |  1.68e+01 +/- 1.2e-01  |  1.68e+01 +/- 1.4e-01  |

unalmis added 3 commits July 3, 2024 23:18
These differences are because, prior to the changes in this PR,
these length scale quantities would get computed on a full resolution
quadrature grid in test_compute_everything. Now thare computed on the same
low resolution used in the test that is used for everything else.

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 1.63995582e-05
Max relative difference: 2.03987171e-05
 x: array(0.803967)
 y: array(0.80395)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: S.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.16850603
Max relative difference: 0.00125191
 x: array(134.767312)
 y: array(134.598806)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A(z).
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 0.63797977
Max relative difference: 0.80369303
 x: array([0.763363, 0.763363, 0.763363, 0.763363, 0.763363, 0.763363,
       0.763363, 0.763363, 0.763363, 0.763363, 0.763363, 0.763363,
       0.763363, 0.763363, 0.763363, 0.763363, 0.763363, 0.763363,...
 y: array([0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: R0.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.00011245
Max relative difference: 2.0398301e-05
 x: array(5.51284)
 y: array(5.512953)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A(r).
Mismatched elements: 594 / 660 (90%)
Max absolute difference: 1.63995582e-05
Max relative difference: 2.03987171e-05
 x: array([0.      , 0.      , 0.      , 0.      , 0.      , 0.      ,
       0.010291, 0.010291, 0.010291, 0.010291, 0.010291, 0.010291,
       0.041077, 0.041077, 0.041077, 0.041077, 0.041077, 0.041077,...
 y: array([0.      , 0.      , 0.      , 0.      , 0.      , 0.      ,
       0.010291, 0.010291, 0.010291, 0.010291, 0.010291, 0.010291,
       0.041077, 0.041077, 0.041077, 0.041077, 0.041077, 0.041077,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: a.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 5.15953253e-06
Max relative difference: 1.01993065e-05
 x: array(0.505876)
 y: array(0.505871)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: R0/a.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.00033345
Max relative difference: 3.05972954e-05
 x: array(10.89761)
 y: array(10.897944)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: a_major/a_minor.
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 10.92082022
Max relative difference: 4.88235767
 x: array([ 4.007305,  4.007305,  4.007305,  4.007305,  4.007305,  4.007305,
        4.007305,  4.007305,  4.007305,  4.007305,  4.007305,  4.007305,
        4.007305,  4.007305,  4.007305,  4.007305,  4.007305,  4.007305,...
 y: array([4.009882, 4.009882, 4.009882, 4.009882, 4.009882, 4.009882,
       4.009882, 4.009882, 4.009882, 4.009882, 4.009882, 4.009882,
       4.009882, 4.009882, 4.009882, 4.009882, 4.009882, 4.009882,...
@unalmis unalmis linked an issue Jul 4, 2024 that may be closed by this pull request
unalmis added 2 commits July 11, 2024 16:13
Some of the master compute data changes with this commit.
The changes which are not due to floating point differences or simply grid
resolution differences (recall the grid used in test_compute_everything has
L = 9, M=N=5 which is less than required for convergence to true integral
quantities on that equilbrium) are given below:

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A(z).
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 0.6494644
Max relative difference: 0.81816076
 x: array([0.792591, 0.792591, 0.792591, 0.792591, 0.792591, 0.792591,
       0.792591, 0.792591, 0.792591, 0.792591, 0.792591, 0.792591,
       0.792591, 0.792591, 0.792591, 0.792591, 0.792591, 0.792591,...
 y: array([0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: a_major/a_minor.
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 11.33931768
Max relative difference: 4.99527722
 x: array([ 3.864152,  3.864152,  3.864152,  3.864152,  3.864152,  3.864152,
        3.864152,  3.864152,  3.864152,  3.864152,  3.864152,  3.864152,
        3.864152,  3.864152,  3.864152,  3.864152,  3.864152,  3.864152,...
 y: array([4.057173, 4.057173, 4.057173, 4.057173, 4.057173, 4.057173,
       4.057173, 4.057173, 4.057173, 4.057173, 4.057173, 4.057173,
       4.057173, 4.057173, 4.057173, 4.057173, 4.057173, 4.057173,...

NOTE that both quanties are incorrect, because in general we cannot compute
these quantities accuratly on grids that do not sample the full poloidal
domain.
@unalmis unalmis marked this pull request as ready for review July 11, 2024 22:23
@unalmis unalmis added documentation Add documentation or better warnings etc. bug fix Something was fixed and removed bug fix Something was fixed labels Jul 12, 2024
@unalmis unalmis linked an issue Jul 12, 2024 that may be closed by this pull request
@unalmis unalmis marked this pull request as draft July 12, 2024 22:19
@unalmis unalmis marked this pull request as ready for review July 13, 2024 16:17
# where n is the unit normal such that n dot e_θ|ρ,ϕ = 0 and n dot e_ϕ|R,Z = 0,
# and the labels following | denote those coordinates are fixed.
# Now choose v = [0, 0, Z], and n in the direction (e_θ|ρ,ζ × e_ζ|ρ,θ) ⊗ [1, 0, 1].
n = data["n_rho"]
Copy link
Collaborator Author

@unalmis unalmis Oct 2, 2024

Choose a reason for hiding this comment

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

iirc because n_rho should not be defined on zeta cross section (#1127 ) the task is to rewrite this to obtain normal vector purely from e_theta which is defined on zeta cross section alone. basically like #597 (comment).

@unalmis unalmis changed the base branch from master to grid_resolution_fix October 28, 2024 00:59
@unalmis unalmis assigned f0uriest and dpanici and unassigned unalmis Oct 28, 2024
@PlasmaControl PlasmaControl deleted a comment from dpanici Oct 28, 2024
@PlasmaControl PlasmaControl deleted a comment from dpanici Oct 28, 2024
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Base automatically changed from grid_resolution_fix to master October 28, 2024 20:42
@unalmis unalmis self-assigned this Nov 28, 2024
@unalmis unalmis added P2 Medium Priority, not urgent but should be on the near-term agend and removed P2 Medium Priority, not urgent but should be on the near-term agend labels Dec 4, 2024
@unalmis unalmis added P1 Lowest Priority, will get to eventually and removed P2 Medium Priority, not urgent but should be on the near-term agend labels Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add warning Adds warning to prevent/detect bug P1 Lowest Priority, will get to eventually performance New feature or request to make the code faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change description of S
4 participants