Repository navigation
Variational MHD: relative Newton stopping criteria, en_thermo fix, low-mode TAE examples for the linear models - #824
Merged
Conversation
- Newton/Picard stopping criteria of the variational propagators (PB, QB, density, magnetic field, entropy, viscosity, resistivity) relative to the state at t^n (err < tol^2 min(|state|^2, 1)): the absolute tolerance was far too loose for the small states of the linear and perturbative models (energy drift ~1e-5 per step in the low-mode TAE). Linear solves and inverse-mass error norms are done for normalized vectors, so their tolerances are relative too. New stagnation check (3 iterations without decrease). Shared helpers NewtonConvergence, dot_normalized and inv_norm2 in feec/variational_utilities.py. VariationalMomentumAdvection is unchanged. - Schur solves of VariationalPBEvolve and VariationalQBEvolve preconditioned with the fixed MassMatrixPreconditioner instead of an inner PCG solve (2x faster for the p model). - en_thermo (and en_thermo_l1) of VariationalPerturbativeMHD and VariationalMHD_with_p: int p dx / (gamma - 1) (was int p^3 / sqrt(g) d eta, wrong in curved geometry). - project_div_free_velocity: Mv-orthogonal projection of an H1vec velocity onto the kernel of the discrete divergence of the variational schemes. - Examples examples/VariationalPerturbativeLinearMHD/with_p|with_q/lowmode_tae: the low-mode TAE of LinearMHD for the linear variational models (first order in time, divergence-free initial velocity). - test_same_as_full_f: threshold 1e-6 (the runs agree up to the solver tolerance). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
@nicolominichelli nice! if it is ready for review, please request a review from me, otherwise I will wait. Do you have time comparisons for the 5 linear MHD models already (lowmode_tae)? |
Contributor
Author
|
I am currently trying to improve preconditioning in the variational models since they are currently 20x slower. There seems to be room for improvement without having to move to curlcurl preconditioner yet |
Member
If you want to profile a run I suggest to use the |
spossann
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up of #818, motivated by comparing the linear variational MHD models with
LinearMHDon the low-mode TAE.Relative stopping criteria in the variational propagators
The Newton/Picard iterations stopped at an absolute residual (
err < tol**2). For the small states of the linear and perturbative models (perturbation amplitude 1e-3) this was effectively a relative tolerance of ~1e-4: in the low-mode TAE the energy drifted by ~1e-5 per step, and the iterations stalled at the accuracy of the (also absolute) linear solves, running tomaxiter.VariationalPBEvolve,VariationalQBEvolve,VariationalDensityEvolve,VariationalMagFieldEvolve,VariationalEntropyEvolve,VariationalViscosity,VariationalResistivity: stop whenerr < tol**2 * min(|state at t^n|**2, 1). This is relative for small states and the previous absolute criterion for full models (norm >= 1), so the full models behave as before.NewtonConvergence,dot_normalized,inv_norm2infeec/variational_utilities.py; option docs updated.VariationalMomentumAdvectionis unchanged: its Newton (approximate Jacobian) is not monotone and diverged with the relative criterion; it is not used by the linear models.Preconditioner of the PB/QB Schur solves
VariationalPBEvolveandVariationalQBEvolveprecondition their Schur solves with the fixedMassMatrixPreconditionerofMrhoinstead of an inner PCG solve (not a linear operator, and expensive): ~2x faster per step for the p model, same iteration count. A better preconditioner (the ~170 Schur iterations per step) is left for a separate PR.Thermal energy diagnostic
en_thermo/en_thermo_l1ofVariationalPerturbativeMHDanden_thermoofVariationalMHD_with_pcomputedint p^3 / sqrt(g) d etainstead ofint p dx / (gamma - 1). This is wrong in curved geometry, and inconsistent with the energy conserved byVariationalPBEvolve.Divergence-free initial velocity
project_div_free_velocity: Mv-orthogonal projection of an H1vec velocity onto the kernel of the discrete divergencediv Uvof the variational schemes. Its CG has no preconditioner and stops at its iteration limit on 16x16x8 (|div u|5.7e-5 -> 2.6e-9); this could use the same kind of preconditioner as above.Examples
examples/VariationalPerturbativeLinearMHD/with_p|with_q/lowmode_tae: the low-mode TAE ofexamples/LinearMHD/lowmode_taeforVariationalPerturbativeMHD(_with_q)withlinear=True. They use first-order time stepping likeLinearMHD(implicit_weights=Falsefor q), a divergence-free initial velocity and Dirichlet walls (u.n = 0, b.n = 0). README table updated (also the missingLinearMHD/lowmode_tae).Test change
test_same_as_full_f(perturbative vs full-f q model): threshold 1e-10 -> 1e-6 relative. The two runs agreed to round-off only because the absolute tolerance made both go through the same arithmetic; with relative criteria they agree to the solver tolerance (measured 4e-8). Tighter solver tolerances are not an option: below ~1e-11 the Schur solves break down with NaN (pre-existing, also ondevel; BiCGStab with an inner-iterative preconditioner and no breakdown guard). To be addressed separately.Tests
VariationalMHD,VariationalMHD_with_p,VariationalMHD_with_q,VariationalPerturbativeMHD,VariationalPerturbativeMHD_with_q.test_verif_VariationalPerturbativeMHD_with_q.py(2 ranks): 13 passed.test_variational_dissipation.py(serial; they are skipped under MPI / not MPI-safe): passed.test_examples.pyfor the two new examples: passed.VariationalBarotropicFluid,VariationalCompressibleFluid,VariationalPressurelessFluid,ViscousFluid), which also use these propagators.🤖 Generated with Claude Code