Skip to content

Conversation

@rahulgaur104
Copy link
Collaborator

@rahulgaur104 rahulgaur104 commented Sep 2, 2025

Finite-n stability is important for tokamaks and non-poloidally omnigenous stellarators. Currently, there are no open source codes to solve this problem, much less perform optimization with it.

After a preliminary attempt discretizing and working with the ideal MHD force operator in #1791 , I realized that it would be easier to discretize the energy principle instead. Therefore, this PR creates a variational principle based eigenvalue solver and optimizer.

After discretization, the generalized eigenvalue problem becomes

$$A x = \lambda B x $$

where B is symmetric positive definite and A is symmetric. With some efficient linear algebra we cholesky decompose B and convert the problem above into a standard eigenvalue problem.

$$\tilde{A} x = \lambda x$$

Addresses #1790

TODOs for the current PR:

  • Test different basis for representing radial derivatives. Fourier is fine for toroidal and poloidal derivatives. Finite-difference, or Legendre can be used for radial.
  • Decide the API to use for creating differentiation matrices and ensure that the matrices are not recalculated at each iteration. They only have to be built once and the optimizer should not track their gradients. Tests needed to ensure that.
    Since the fundamental matrices themselves are pretty small (< 100 x 100 ~ few MBs), they can be passed via transforms.
  • Ensure the mass matrix is symmetric positive definite and the stiffness matrix without the instability term is close to symmetric positive definite (no or very small negative eigenvalues). This can then be corrected using Gershgorin circle theorem by adding a small positive value to the diagonal before adding the instability drive and eigendecomposing.
  • Effcient decomposition of the mass matrix. Mass matrix is N x N, so vanilla Cholesky will be O(N^3) which is prohibitive for large N ~ 100 k. However, the structure of the mass matrix allows us to rearrange it so that the cost of doing Cholesky becomes O(N).
  • Enforce incompressibility and make sure it works without polluting the eigenspectrum. Tests needed($\mathbf{\gamma \rightarrow \infty}$ should be equivalent to imposing incompressibility). Observation: Eigenfunctions are smooth when incompressibility is not enforced so perhaps we should optimize without imposing incompressibility (and compare with the incompressible modes post-optimization)
  • New plotting routine needed to plot the eigenfunction and the physical quantities associated with it. Probably needs to be merged in plot_section.
  • Compare and benchmark with another finite-n stability solver, possibly TERPSICHORE.
  • Compare with NIMSTELL Landreman-Buller-Drevlak QH interchange example from Patil et al. Optional.
  • Test the eigenvalue gradient calculation and test the resolution limits that can be fit on a single A100 GPU.
  • Try eigendecomposing with scipy.eigh on a CPU but gradient calculation on a GPU using the Hellman-Feynman formula.
  • ITo study the mode familyN (mod NFP) = 0, we can solve the stability problem in a single-field period, reducing the matrix size $$1/NFP^2$$. Add a separate condition to study this mode family. Future work.

Future PRs

  • Write a custom, matrix-free eigenvalue solver to allow high-resolution stability calculations. This will save a lot of memory but will take longer. Future PR.
  • External mode stability calculation. Future work.

Checkpoints (only for me):

commit 7166c2d
commit 28e41c8

rahulgaur104 and others added 30 commits June 12, 2025 00:16
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

rahulgaur104 and others added 20 commits October 24, 2025 08:22
…_stability compute function; The diffmatrices should now be pre-computed and hopefully jax won't track their gradients
… preconditioner for the incompressible axisymmetric case
… inverting C_zeta; imposing incompressibility using a projection operator for the axisymmetric case as well. More compact code. Should hopefully work better!
…ing a separate function to plot the eigenfunction at different toroidal cross-sections
…till having memory problem which is confusing!
…unning the code; I am trying to understand how iterative solvers work
…unning the code; I am trying to understand how iterative solvers work 2
…unning the code; matfree iterative solver only works if the eigenfunction guess is close to the true eigenfunction within 5%
…unning the code; matfree iterative solver only works if the eigenfunction guess is close to the true eigenfunction within 10%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement General label for enhancement. Please also tag with "Speed", "Interface", "Functionality", etc functionality New feature or request to do things the code can't do now. objectives Adding or improving objective functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A finite-n stability solver in DESC?

4 participants