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

Vacuum solver without assuming nested flux surfaces #1360

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

Conversation

unalmis
Copy link
Collaborator

@unalmis unalmis commented Nov 13, 2024

High order accurate method to find unique vacuum potential such that Bdotn = 0 on last closed flux surface given a field that captures the current distribution. Does not assume nested flux surfaces.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 88.80597% with 30 lines in your changes missing coverage. Please review.

Project coverage is 95.71%. Comparing base (13e60ce) to head (a8b2da9).

Files with missing lines Patch % Lines
desc/integrals/_vacuum.py 81.37% 19 Missing ⚠️
desc/integrals/singularities.py 88.88% 10 Missing ⚠️
desc/integrals/quad_utils.py 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1360      +/-   ##
==========================================
- Coverage   95.71%   95.71%   -0.01%     
==========================================
  Files         101      102       +1     
  Lines       26356    26462     +106     
==========================================
+ Hits        25227    25328     +101     
- Misses       1129     1134       +5     
Files with missing lines Coverage Δ
desc/batching.py 90.79% <100.00%> (+0.49%) ⬆️
desc/coils.py 97.99% <ø> (ø)
desc/compute/_basis_vectors.py 100.00% <100.00%> (ø)
desc/compute/_metric.py 100.00% <100.00%> (ø)
desc/compute/_surface.py 100.00% <100.00%> (ø)
desc/compute/utils.py 97.70% <ø> (ø)
desc/equilibrium/equilibrium.py 95.90% <ø> (ø)
desc/geometry/core.py 94.11% <ø> (ø)
desc/integrals/__init__.py 100.00% <100.00%> (ø)
desc/magnetic_fields/_core.py 96.38% <100.00%> (ø)
... and 8 more

... and 1 file with indirect coverage changes

Copy link
Contributor

github-actions bot commented Nov 13, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
-test_build_transform_fft_lowres         |    +12.64 +/- 3.39     | +7.59e-02 +/- 2.04e-02 |  6.77e-01 +/- 1.9e-02  |  6.01e-01 +/- 7.9e-03  |
 test_equilibrium_init_medres            |    +13.47 +/- 14.73    | +5.62e-01 +/- 6.14e-01 |  4.73e+00 +/- 6.1e-01  |  4.17e+00 +/- 3.2e-02  |
 test_equilibrium_init_highres           |     -5.43 +/- 5.41     | -2.99e-01 +/- 2.98e-01 |  5.21e+00 +/- 2.5e-02  |  5.51e+00 +/- 3.0e-01  |
 test_objective_compile_dshape_current   |     -2.06 +/- 5.38     | -8.74e-02 +/- 2.29e-01 |  4.16e+00 +/- 1.3e-01  |  4.25e+00 +/- 1.9e-01  |
 test_objective_compute_dshape_current   |     -0.35 +/- 1.84     | -1.92e-05 +/- 1.00e-04 |  5.41e-03 +/- 6.3e-05  |  5.43e-03 +/- 7.8e-05  |
 test_objective_jac_dshape_current       |     +0.14 +/- 7.26     | +5.90e-05 +/- 3.09e-03 |  4.27e-02 +/- 2.0e-03  |  4.26e-02 +/- 2.3e-03  |
 test_perturb_2                          |     -2.18 +/- 1.77     | -4.53e-01 +/- 3.68e-01 |  2.03e+01 +/- 3.0e-01  |  2.07e+01 +/- 2.1e-01  |
 test_proximal_jac_atf_with_eq_update    |     -1.02 +/- 0.85     | -1.76e-01 +/- 1.47e-01 |  1.71e+01 +/- 1.2e-01  |  1.72e+01 +/- 8.8e-02  |
 test_proximal_freeb_jac                 |     +0.46 +/- 1.08     | +2.27e-02 +/- 5.35e-02 |  4.99e+00 +/- 2.6e-02  |  4.97e+00 +/- 4.7e-02  |
 test_solve_fixed_iter_compiled          |     +2.28 +/- 0.95     | +4.76e-01 +/- 1.98e-01 |  2.14e+01 +/- 1.6e-01  |  2.09e+01 +/- 1.2e-01  |
 test_LinearConstraintProjection_build   |     -1.20 +/- 4.19     | -1.35e-01 +/- 4.71e-01 |  1.11e+01 +/- 3.4e-01  |  1.12e+01 +/- 3.2e-01  |
 test_objective_compute_ripple_spline    |     +0.14 +/- 2.50     | +4.89e-04 +/- 8.62e-03 |  3.46e-01 +/- 3.0e-03  |  3.45e-01 +/- 8.1e-03  |
 test_objective_grad_ripple_spline       |     -1.63 +/- 2.16     | -2.32e-02 +/- 3.08e-02 |  1.41e+00 +/- 2.3e-02  |  1.43e+00 +/- 2.1e-02  |
 test_build_transform_fft_midres         |     +4.30 +/- 6.44     | +2.78e-02 +/- 4.16e-02 |  6.73e-01 +/- 3.4e-02  |  6.45e-01 +/- 2.4e-02  |
 test_build_transform_fft_highres        |     +1.25 +/- 6.92     | +1.18e-02 +/- 6.51e-02 |  9.53e-01 +/- 4.9e-02  |  9.41e-01 +/- 4.3e-02  |
 test_equilibrium_init_lowres            |     +0.10 +/- 2.34     | +3.85e-03 +/- 9.25e-02 |  3.95e+00 +/- 7.4e-02  |  3.95e+00 +/- 5.6e-02  |
 test_objective_compile_atf              |     +1.25 +/- 4.62     | +1.03e-01 +/- 3.84e-01 |  8.40e+00 +/- 2.5e-01  |  8.29e+00 +/- 2.9e-01  |
 test_objective_compute_atf              |     +1.24 +/- 4.55     | +2.02e-04 +/- 7.40e-04 |  1.65e-02 +/- 6.9e-04  |  1.63e-02 +/- 2.6e-04  |
 test_objective_jac_atf                  |     +2.29 +/- 2.27     | +4.43e-02 +/- 4.38e-02 |  1.98e+00 +/- 3.6e-02  |  1.93e+00 +/- 2.4e-02  |
 test_perturb_1                          |     +0.63 +/- 3.82     | +9.50e-02 +/- 5.73e-01 |  1.51e+01 +/- 1.6e-01  |  1.50e+01 +/- 5.5e-01  |
 test_proximal_jac_atf                   |     +1.17 +/- 1.69     | +9.34e-02 +/- 1.35e-01 |  8.08e+00 +/- 1.1e-01  |  7.99e+00 +/- 8.2e-02  |
 test_proximal_freeb_compute             |     +1.29 +/- 1.24     | +2.43e-03 +/- 2.34e-03 |  1.91e-01 +/- 1.8e-03  |  1.88e-01 +/- 1.5e-03  |
 test_solve_fixed_iter                   |     +0.85 +/- 1.79     | +2.77e-01 +/- 5.79e-01 |  3.27e+01 +/- 2.4e-01  |  3.24e+01 +/- 5.3e-01  |
 test_objective_compute_ripple           |     +1.00 +/- 2.00     | +6.88e-03 +/- 1.38e-02 |  6.96e-01 +/- 1.1e-02  |  6.90e-01 +/- 8.9e-03  |
 test_objective_grad_ripple              |     +0.19 +/- 0.85     | +4.94e-03 +/- 2.23e-02 |  2.64e+00 +/- 1.1e-02  |  2.63e+00 +/- 1.9e-02  |

@unalmis unalmis changed the title Laplace solution for vacuum plasma Laplace solution Nov 16, 2024
@unalmis unalmis self-assigned this Nov 18, 2024
@unalmis
Copy link
Collaborator Author

unalmis commented Dec 4, 2024

I'll push the simpler method we talked about. Regardless it is not expected for the current method to not satisfy the lcfs condition.

Am I missing something in the implementation? If you are available, but would like to be caught up on the code or math let me know.

@unalmis unalmis marked this pull request as ready for review February 23, 2025 05:33
@unalmis unalmis added the theory Requires theory work before coding label Feb 23, 2025
Returns
-------
data : dict
Vacuum field ∇Φ stored in ``data["evl"]["grad(Phi)"]``.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you prefer some other api let me know. i was taking care to make these functions pure (recall that is a technical term) so that they play nice with jax

Copy link
Collaborator Author

@unalmis unalmis Feb 23, 2025

Choose a reason for hiding this comment

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

Ideally each method would be a registered compute function, but before I did that we should decide on API. Recall there are 3 grids here.

@unalmis unalmis changed the title Laplace solution Vacuum solver without assuming nested flux surfaces Feb 23, 2025
@@ -97,7 +97,7 @@ Contribute
- `Contributing guidelines <https://github.com/PlasmaControl/DESC/blob/master/CONTRIBUTING.rst>`_
- `Issue Tracker <https://github.com/PlasmaControl/DESC/issues>`_
- `Source Code <https://github.com/PlasmaControl/DESC/>`_
- `Documentation <https://desc-docs.readthedocs.io/>`_
- `Documentation <https://desc-docs.readthedocs.io/en/latest/>`_
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer this to be stable as then it is consistent with our pip package

Base automatically changed from ku/biot to master March 1, 2025 03:47
@unalmis unalmis added the squash squash merge only label Mar 1, 2025
@@ -805,12 +806,15 @@ def _kernel_1_over_r(eval_data, source_data, diag=False):
def _kernel_nr_over_r3(eval_data, source_data, diag=False):
"""Returns n ⋅ −∇G(x,x') = n ⋅ (x−x')|x−x'|⁻³."""
dx = _dx(eval_data, source_data, diag)
n = rpz2xyz_vec(source_data["n_rho"], phi=source_data["phi"])
# Need to use e^rho*sqrt(g) to pass Green's ID test.
# Fourier spectrum is much more concentrated than n_rho for some reason.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

otherwise the w7x one fails, which is interesting because there's many nodes and no truncation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squash squash merge only theory Requires theory work before coding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants