Repository navigation
solver composition corrections - #1112
Merged
Merged
Conversation
Synchronize solver_dx when the native checks correct RSP2 w, clip alpha_RTI, or bound w_div_w_crit_roche. Update dxh_alpha_RTI as well so the RTI time term uses the evaluated alpha_RTI. Replace the unreachable negative alpha_RTI check after max(0, x) with a comparison against the raw trial value. Retain stored changes when the physical variable is unchanged.
Set dX_div_X_limit(1) to 10 by default and keep the relative abundance checks active above 1. Remove redundant 1M controls and the explicit relative limits in the thermohaline and C13 pocket cases. Keep the full 1M runner enabled and preserve PGSTAR. Use fully implicit burning in the 20M case, retain its comparison controls, and restore normal profile intervals with solver progress output off. Remove the run_all restart recommendation from the massive star READMEs.
Debraheem
requested review from
annethoul,
aurimontem,
fxt44 and
wmwolf
as code owners
November 9, 2026 21:32
Include the temperature and density response of the Be7 capture branching fractions in the combined pp rates. Retain the rate values and constant half-branch behavior for negligible capture rates. Validation: the same-state heating derivative discrepancy falls from about 9e-7 to 1e-12 in the scaled energy equation. The rate-value evaluations are unchanged.
The full equation loop already includes composition. Remove the obsolete composition pass so each included residual contributes once to the mean. Maximum residuals, equation weights and the Newton system are unchanged. The older structural loop and separate composition loop were disjoint in r1396. Duplicate counting is present by r3731 and predates public Git history, so no introducing PR has been verified. The extracted sizequ passed 57 numerical checks covering weighted means, ignored equations, maximum residuals and nonfinite inputs.
Debraheem
force-pushed
the
EbF/bugfix/solver_composition_corrections
branch
from
November 9, 2026 21:47
29d3119 to
7f47e7f
Compare
…d partials in 20M, update standard mod files.
…hell merger post-stripping from undoing gamma1 instability and stalling the marger + speed ups
Debraheem
added a commit
that referenced
this pull request
Nov 17, 2026
Integrate the published solver branch from PR #1112 for combined testing. Preserve the diffusion controls and use the solver branch active Newton settings in the 20M case.
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.
With llm machine help, I’ve been delving deep into MESA’s solver for some time and this has led to a somewhat surprising but welcome major bugfix to MESA’s Newton solver. The resulting changes in overall performance and more specifically MESA’s convergence properties are large.
Composition consistency
MESA’s Newton solver had an inconsistency where the solver checks in
check1_chemwould clip/floor negative abundance trials to 0, but wouldn’t updatesolver_dx, so the next solver iteration wouldn’t see the clip and would try to produce a negative or positive abundance change from an isotope with no abundance.This issue is particularly prevalent near moving burning fronts, like the H burning shell climbing up the RGB in a low mass star, since a narrow burning region burns one or a few zones at a time. When an isotope’s abundance in those zones drops to 0, this issue comes out. This is likely one of the reasons why it took so long to get to the He flash in current MESA. The solver needed careful timesteps to resolve the decay to 0 so that sudden clipping of negative trial abundances (
he3in the RGB example) didn’t destabilize the solver.The fix updates the composition components of
solver_dxandxa_sub_xa_startwhen the composition checks change the abundance. This keeps the stored abundance change consistent with the abundance used to evaluate the equations.Tests and run times
The comparisons use the
dedtenergy equation and fully implicit burning. The runs used an Apple M1 Max with MESA SDK 26.6.1 and eight cores, withexport OMP_NUM_THREADS=8. Times include initialization and output, and exclude compilation.The original timing comparisons and figures were produced before the final three followup commits described below. The new limit-50 calculation includes these fixes and the updated helium luminosity defaults.
1M_pre_ms_to_wd: RGB evolutionThese calculations cover the pre-main sequence through the onset of the helium flash. I compare hydrogen abundance change limits of
dX_div_X_limit(1) = 0.9d0,5d0,10d0and50d0during RGB evolution, keepingtime_delta_coeff = 1.dX_div_X_limit(1)rel_run_E_errmagnitudemainmainmainThe table includes model construction and rejected solves. Each calculation has one construction retry on the first model coming out of the pre-ms relaxation. During RGB evolution itself, the limit-10 calculation has 0 retries on the solver correction branch versus 646 on
main. The limit-50 calculation uses a hydrogen abundance change limit of 10 before RGB evolution and 50 during RGB evolution.Compared with
mainat the original limit of 0.9, the solver correction branch at 10 reaches the helium flash 3.8 times faster, using 6.1 times fewer accepted steps, while retaining better numerical energy conservation. With both versions using a limit of 10, the solver correction branch is 2.8 times faster. See the figure below.Generally, I find that reducing the timestep makes each solve less nonlinear, and hence the short timestep limit of this change is analogous to
main. This is reflected in the similar results withdX_div_X_limit(1) = 0.9d0. What this pr does, is allow MESA to take larger timesteps while still converging to the same level. This does not necessarilly mean the calculation is more accurate with larger timesteps, but rather it just means that MESA can find a solution to the precision required by the tolerances and equations supplied.I have also changed the defaults for
lgL_He_burn_minto-0.5d0andlgL_He_burn_relative_limitto5d0, which allows the helium luminosity timestep control to act earlier. With these changes, our most aggressive test withdX_div_X_limit(1) = 50d0reaches the He flash in 906 timesteps from the pre-main sequence, including 611 RGB timesteps with 0 retries. The full calculation takes 11.22 minutes, with 9,400 Newton iterations and one construction retry. See below.This PR also allows the normal
dX_div_X_limitcontrol to be set above 1 and changes the default hydrogen limit todX_div_X_limit(1) = 10d0.He-flash to core-He depletion
I continued both limit-0.9 models through the helium flash and core-helium burning to central helium mass fractions below
1d-4.rel_run_E_errmagnitudemainThe cumulative energy errors include the preceding evolution. Restricting the accumulation to this helium evolution gives relative errors of 3.43e-8 on
mainand 6.02e-9 on the solver correction branch.Over the helium flash, timesteps are primarily controlled by the helium burning luminosity, so the convergence improvements do not manifest as strongly there. The Newton work remains similar, while the cumulative energy error is smaller on the solver correction branch.
20M_pre_ms_to_core_collapseBoth versions start from the same model after central carbon depletion and use the same physical, mesh and timestep controls, with fully implicit burning.
inlist_to_lgTmaxEvolution through a maximum temperature of$10^{9.6}$ K:
maininlist_to_ccEvolution from that point to an iron core infall speed of 100 km/s:
mainBoth inlists combined
mainThe core collapse inlist runs 2.1 times faster, with 54% fewer Newton iterations and 50% fewer retries. Over both inlists, the calculation runs 1.7 times faster, with 40% fewer Newton iterations and 45% fewer retries.
The final
rel_run_E_errmagnitude decreases from 8.57e-4 to 3.57e-4, although the maximum per-steprel_E_errmagnitude is higher on the solver correction branch: 3.56e-5 versus 1.41e-5.The central density and temperature evolution also differs, which could have implications elsewhere.
Other changes on the branch
alam. This did not substantially change my results, but it is certainly a bug to fix.dxsaveand the correction workspace inddxsavebefore either evaluation path. Previously, a failed trial could restore stale or uninitialized solver values when the initial merit evaluation was skipped, such as during the first iterations of a timestep. The correction workspace is also initialized before saving it.Final three followup commits
The original comparison runs predate these changes. Their effects have been small in my subsequent testing, and I can move them into a separate PR if preferred:
Further testing
My guess is that runtime in the
test_suitecan be substantially reduced. In cases such as1M_thermohalineandc13_pocket, I suspect substantial improvements, potentially factors of 2–4, but we’ll have to test and see.The broader implications are still unclear, but this is certainly a bug we need to fix. I checked the history and it appears to have been present for a very long time, potentially since MESA’s inception, although the solver worked slightly differently before.
I have not attempted relaxing
dX_div_X_limit(2) = 0.9d0for helium yet, but it would be the next thing to try relaxing.