Skip to content

Commit 8baceed

Browse files
authored
solver composition corrections (#1112)
* Fix composition increments and Newton backtracking state * Keep other solver variables consistent with equation evaluations 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. * Relax the hydrogen timestep limit and update solver test cases 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. * Average composition corrections independently in each cell * Differentiate the ppII and ppIII branching fractions 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. * Count each equation once in the solver residual average 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. * refactor c13_pocket interpulse check, ignore equL in ppisn, disable fd partials in 20M, update standard mod files. * update tzo standard mod file * fix pisn: move c-depletion stopping condiiton further to prevent He-shell merger post-stripping from undoing gamma1 instability and stalling the marger + speed ups * add changelog entry and update ppisn standard mod file * Reduce Newton solver overhead by saving corrections only for line searches
1 parent 20fea6a commit 8baceed

55 files changed

Lines changed: 214 additions & 158 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/source/changelog.rst‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ Other Changes
167167

168168
`mesa/binary` now no longer copies the binary history columns into the star history by default. Set `append_to_star_history = .true.` to reenable this feature. All binary history data is still saved to `history_name` defined in section `&binary_controls`.
169169

170+
Improvements and bug fixes in MESA's Newton solver allow it to converge with
171+
larger timesteps. The default for ``dX_div_X_limit(1)`` has been changed from
172+
0.9 to 10, allowing larger relative changes in hydrogen abundance at moving
173+
burning fronts. The helium luminosity timestep limit acts earlier to resolve
174+
the onset of flashes. The default for ``lgL_He_burn_min`` has been changed
175+
from 2.5 to -0.5, and the default for ``lgL_He_burn_relative_limit`` from 3 to 5.
176+
See `gh-1112 <https://github.com/MESAHub/mesa/pull/1112>`_.
177+
178+
Test Suite
179+
----------
180+
181+
- In ``1M_pre_ms_to_wd``, a run with ``dX_div_X_limit(1) = 50d0`` on the red
182+
giant branch reaches the onset of the core helium flash in an order
183+
of magnitude fewer timesteps. See `gh-1112 <https://github.com/MESAHub/mesa/pull/1112>`_.
184+
- ``20M_pre_ms_to_core_collapse`` uses fully implicit burning through core collapse.
185+
- ``c13_pocket`` counts pulses with third dredge up and starts the pocket
186+
calculation at helium shell ignition after an interpulse. The thermal pulse
187+
cycle completes in half as many timesteps as in previous MESA versions.
188+
170189

171190
Changes in r26.4.1
172191
===================

‎net/private/net_screen.f90‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ subroutine set_combo_screen_rates(num_isos, y, sc, ierr)
319319
integer, intent(out) :: ierr
320320

321321
integer, pointer :: rtab(:)
322-
real(dp) :: rateII, rateIII, rsum, fII, fIII
322+
real(dp) :: rateII, rateIII, rsum, fII, fIII, rate34
323+
real(dp) :: d_rateII_dT, d_rateIII_dT, d_rateII_dRho, d_rateIII_dRho
324+
real(dp) :: d_fII_dT, d_fII_dRho
323325

324326
include 'formats'
325327

@@ -334,35 +336,49 @@ subroutine set_combo_screen_rates(num_isos, y, sc, ierr)
334336
end if
335337
if (rtab(ir_be7_wk_li7) /= 0) then
336338
rateII = rate_screened(rtab(ir_be7_wk_li7))
339+
d_rateII_dT = rate_screened_dT(rtab(ir_be7_wk_li7))
340+
d_rateII_dRho = rate_screened_dRho(rtab(ir_be7_wk_li7))
337341
else if (rtab(irbe7ec_li7_aux) /= 0) then
338342
rateII = rate_screened(rtab(irbe7ec_li7_aux))
343+
d_rateII_dT = rate_screened_dT(rtab(irbe7ec_li7_aux))
344+
d_rateII_dRho = rate_screened_dRho(rtab(irbe7ec_li7_aux))
339345
else
340346
write(*,*) 'need either r_be7_wk_li7 or rbe7ec_li7_aux'
341347
call mesa_error(__FILE__,__LINE__,'set_combo_screen_rates')
342348
end if
343349
if (rtab(ir_be7_pg_b8) /= 0) then
344350
rateIII = y(g% net_iso(ih1)) * rate_screened(rtab(ir_be7_pg_b8))
351+
d_rateIII_dT = y(g% net_iso(ih1)) * rate_screened_dT(rtab(ir_be7_pg_b8))
352+
d_rateIII_dRho = y(g% net_iso(ih1)) * rate_screened_dRho(rtab(ir_be7_pg_b8))
345353
else if (rtab(irbe7pg_b8_aux) /= 0) then
346354
rateIII = y(g% net_iso(ih1)) * rate_screened(rtab(irbe7pg_b8_aux))
355+
d_rateIII_dT = y(g% net_iso(ih1)) * rate_screened_dT(rtab(irbe7pg_b8_aux))
356+
d_rateIII_dRho = y(g% net_iso(ih1)) * rate_screened_dRho(rtab(irbe7pg_b8_aux))
347357
else
348358
write(*,*) 'need either r_be7_pg_b8 or rbe7pg_b8_aux'
349359
call mesa_error(__FILE__,__LINE__,'set_combo_screen_rates')
350360
end if
351361
rsum = rateII + rateIII
352362
if (rsum < 1d-50) then
353363
fII = 0.5d0
364+
d_fII_dT = 0d0
365+
d_fII_dRho = 0d0
354366
else
355367
fII = rateII / rsum
368+
d_fII_dT = (rateIII*d_rateII_dT - rateII*d_rateIII_dT)/(rsum*rsum)
369+
d_fII_dRho = (rateIII*d_rateII_dRho - rateII*d_rateIII_dRho)/(rsum*rsum)
356370
end if
357371
fIII = 1d0 - fII
372+
rate34 = rate_screened(rtab(ir34_pp2))
358373

374+
! Include the response of the ppII and ppIII branching fractions.
359375
rate_screened(rtab(ir34_pp2)) = fII*rate_screened(rtab(ir34_pp2))
360-
rate_screened_dT(rtab(ir34_pp2)) = fII*rate_screened_dT(rtab(ir34_pp2))
361-
rate_screened_dRho(rtab(ir34_pp2)) = fII*rate_screened_dRho(rtab(ir34_pp2))
376+
rate_screened_dT(rtab(ir34_pp2)) = fII*rate_screened_dT(rtab(ir34_pp2)) + rate34*d_fII_dT
377+
rate_screened_dRho(rtab(ir34_pp2)) = fII*rate_screened_dRho(rtab(ir34_pp2)) + rate34*d_fII_dRho
362378

363379
rate_screened(rtab(ir34_pp3)) = fIII*rate_screened(rtab(ir34_pp3))
364-
rate_screened_dT(rtab(ir34_pp3)) = fIII*rate_screened_dT(rtab(ir34_pp3))
365-
rate_screened_dRho(rtab(ir34_pp3)) = fIII*rate_screened_dRho(rtab(ir34_pp3))
380+
rate_screened_dT(rtab(ir34_pp3)) = fIII*rate_screened_dT(rtab(ir34_pp3)) - rate34*d_fII_dT
381+
rate_screened_dRho(rtab(ir34_pp3)) = fIII*rate_screened_dRho(rtab(ir34_pp3)) - rate34*d_fII_dRho
366382

367383
end if
368384

‎net/test/test_output‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
eps_nuc 0.839654151E+13
1111

12-
d_lneps_dlnT 9.328757835
13-
d_lneps_dlnRho 1.009292766
12+
d_lneps_dlnT 9.328756794
13+
d_lneps_dlnRho 1.009292765
1414

1515

1616
energy generation by category

‎star/defaults/controls.defaults‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9859,11 +9859,13 @@
98599859
! ~~~~~~~~~~~~~~
98609860

98619861
! If max ``dX_div_X`` is greater than this,
9862-
! reduce the next timestep by ``dX_limit/max_dX``.
9862+
! reduce the next timestep by ``dX_div_X_limit/max_dX_div_X``.
9863+
! Values greater than 1 allow decreases larger than the end-of-step abundance,
9864+
! which is the denominator of ``dX_div_X``.
98639865

98649866
! ::
98659867

9866-
dX_div_X_limit(1) = 0.9d0
9868+
dX_div_X_limit(1) = 10d0
98679869
dX_div_X_limit(2) = 0.9d0
98689870
dX_div_X_limit(3:) = 1d99
98699871

@@ -10316,7 +10318,7 @@
1031610318

1031710319
! ``L_He_burn`` = integrated power at surface from triple alpha (in Lsun units)
1031810320

10319-
! values for ``lgL_He`` are ``log10(max(1, L_He_burn))``
10321+
! values for ``lgL_He`` are ``log10(L_He_burn)`` for positive luminosities.
1032010322

1032110323

1032210324
! delta_lgL_He_limit
@@ -10347,7 +10349,7 @@
1034710349

1034810350
! ::
1034910351

10350-
lgL_He_burn_min = 2.5d0
10352+
lgL_He_burn_min = -0.5d0
1035110353

1035210354

1035310355
! lgL_He_drop_factor
@@ -10367,7 +10369,7 @@
1036710369

1036810370
! ::
1036910371

10370-
lgL_He_burn_relative_limit = 3
10372+
lgL_He_burn_relative_limit = 5d0
1037110373

1037210374
! ``L_z_burn`` = integrated power at surface from nuclear burning other than H, He, or C (in Lsun units)
1037310375
! excluding photodistintegrations

‎star/private/solver_support.f90‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ subroutine sizequ(s, nvar, equ_norm, equ_max, k_max, j_max, ierr) ! equ = resid
188188
real(dp), intent(out) :: equ_norm, equ_max
189189
integer, intent(out) :: k_max, j_max, ierr
190190

191-
integer :: j, k, num_terms, n, nz, nvar_hydro, nvar_chem, skip_eqn1, skip_eqn2, skip_eqn3
191+
integer :: j, k, num_terms, n, nz, nvar_hydro, skip_eqn1, skip_eqn2, skip_eqn3
192192
real(dp) :: sumequ, absq
193193

194194
logical :: dbg
@@ -205,7 +205,6 @@ subroutine sizequ(s, nvar, equ_norm, equ_max, k_max, j_max, ierr) ! equ = resid
205205
dbg = s% solver_check_everything
206206

207207
nvar_hydro = min(nvar, s% nvar_hydro)
208-
nvar_chem = s% nvar_chem
209208

210209
nz = s% nz
211210
n = nz
@@ -217,6 +216,8 @@ subroutine sizequ(s, nvar, equ_norm, equ_max, k_max, j_max, ierr) ! equ = resid
217216
if (s% convergence_ignore_equL_residuals) skip_eqn1 = s% i_equL
218217
if (s% convergence_ignore_alpha_RTI_residuals) skip_eqn2 = s% i_dalpha_RTI_dt
219218
if (s% do_burn .or. s% do_mix) then
219+
! Count each equation once. The loop over all variables replaced the
220+
! structural sum, so a separate composition pass would count those rows twice.
220221
num_terms = num_terms + nvar*nz
221222
if (skip_eqn1 > 0) num_terms = num_terms - nz
222223
if (skip_eqn2 > 0) num_terms = num_terms - nz
@@ -270,21 +271,6 @@ subroutine sizequ(s, nvar, equ_norm, equ_max, k_max, j_max, ierr) ! equ = resid
270271
end do
271272
end do
272273
end if
273-
if (s% do_burn .or. s% do_mix) then
274-
num_terms = num_terms + nvar_chem*nz
275-
do k = 1, nz
276-
do j = nvar_hydro+1, nvar
277-
absq = abs(s% equ(j,k)*s% residual_weight(j,k))
278-
sumequ = sumequ + absq
279-
if (absq > equ_max) then
280-
equ_max = absq
281-
j_max = j
282-
k_max = k
283-
end if
284-
end do
285-
end do
286-
end if
287-
288274
equ_norm = sumequ/num_terms
289275
if (dbg) write(*,4) trim(s% nameofequ(j_max)) // ' sizequ equ_max norm', &
290276
k_max, s% solver_iter, s% model_number, equ_max, equ_norm
@@ -384,16 +370,17 @@ subroutine sizeB(s, nvar, B, max_correction, correction_norm, max_zone, max_var,
384370
max_zone = 0
385371
max_var = 0
386372
num_terms = 0
387-
num_xa_terms = 0
388373
sum_corr = 0
389-
sum_xa_corr = 0
390374
max_correction = 0
391375
max_abs_correction = 0
392376
x_limit = s% correction_xa_limit
393377
found_NaN = .false.
394378
found_bad_num = .false.
395379
report = s% report_ierr
396380
cell_loop: do k = 1, nz
381+
! Average composition corrections within each cell.
382+
num_xa_terms = 0
383+
sum_xa_corr = 0
397384
max_abs_corr_for_k = 0
398385
max_abs_xa_corr_for_k = 0
399386

@@ -1215,6 +1202,10 @@ subroutine set1(k,report,ierr)
12151202
end if
12161203
if (report) write(*,2) 'bad num w', k, s% w(k)
12171204
end if
1205+
! Keep the solver increment consistent with the corrected w.
1206+
if (s% w(k) /= x(i_w)) then
1207+
s% solver_dx(i_w,k) = s% w(k) - xh_start(i_w,k)
1208+
end if
12181209
s% Hp_face(k) = x(i_Hp)
12191210
if (is_bad_num(s% Hp_face(k))) then
12201211
s% retry_message = 'bad num for Hp_face'
@@ -1267,9 +1258,10 @@ subroutine set1(k,report,ierr)
12671258
if (report) write(*,2) 'bad num alpha_RTI', k, s% alpha_RTI(k)
12681259
ierr = -1
12691260
end if
1270-
if (s% alpha_RTI(k) < 0d0) then
1271-
s% alpha_RTI(k) = 0d0
1272-
x(i_alpha_RTI) = 0d0
1261+
! Use the clipped alpha_RTI in both the solver and time increments.
1262+
if (s% alpha_RTI(k) /= x(i_alpha_RTI)) then
1263+
s% solver_dx(i_alpha_RTI,k) = s% alpha_RTI(k) - xh_start(i_alpha_RTI,k)
1264+
s% dxh_alpha_RTI(k) = s% solver_dx(i_alpha_RTI,k)
12731265
end if
12741266
end if
12751267

@@ -1290,6 +1282,10 @@ subroutine set1(k,report,ierr)
12901282
if (report) write(*,2) 'bad num w_div_w_crit_roche', k, s% w_div_w_crit_roche(k)
12911283
ierr = -1
12921284
end if
1285+
! Keep the solver increment consistent with the clipped rotation fraction.
1286+
if (s% w_div_w_crit_roche(k) /= x(i_w_div_wc)) then
1287+
s% solver_dx(i_w_div_wc,k) = s% w_div_w_crit_roche(k) - xh_start(i_w_div_wc,k)
1288+
end if
12931289
end if
12941290

12951291
if (do_j_rot) then
@@ -1474,6 +1470,14 @@ subroutine check1_chem( &
14741470
end do
14751471
end if
14761472

1473+
if (ierr /= 0) return
1474+
! Keep the solver increments consistent with the corrected abundances.
1475+
do j=1,species
1476+
if (s% xa(j,k) == s% xa_start(j,k) + s% solver_dx(s% nvar_hydro+j,k)) cycle
1477+
s% solver_dx(s% nvar_hydro+j,k) = s% xa(j,k) - s% xa_start(j,k)
1478+
s% xa_sub_xa_start(j,k) = s% solver_dx(s% nvar_hydro+j,k)
1479+
end do
1480+
14771481
end subroutine check1_chem
14781482

14791483

‎star/private/star_solver.f90‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ subroutine adjust_correction( &
870870

871871
! reduce alam and try again
872872
if (first_time) then
873-
tmplam = -slope/(2*(f-fold-slope))
873+
tmplam = -slope*alam*alam/(2*(f-fold-alam*slope))
874874
first_time = .false.
875875
if (dbg_adjust) then
876876
write(*,5) 'slope', k, iter, s% solver_iter, &
@@ -879,8 +879,8 @@ subroutine adjust_correction( &
879879
s% model_number, f
880880
write(*,5) 'fold', k, iter, s% solver_iter, &
881881
s% model_number, fold
882-
write(*,5) '2*(f-fold-slope)', k, iter, s% solver_iter, &
883-
s% model_number, 2*(f-fold-slope)
882+
write(*,5) '2*(f-fold-alam*slope)', k, iter, s% solver_iter, &
883+
s% model_number, 2*(f-fold-alam*slope)
884884
end if
885885
else ! have two prior f values to work with
886886
rhs1 = f - fold - alam*slope
@@ -943,6 +943,8 @@ subroutine adjust_correction( &
943943

944944
end do search_loop
945945

946+
! Restore corrections only if they were saved for the line search.
947+
if (skip_eval_f) return
946948
do k=1,nz
947949
do i=1,nvar
948950
s% solver_dx(i,k) = dxsave(i,k)
@@ -1943,6 +1945,7 @@ subroutine pointers(ierr)
19431945
if (associated(band1)) call fill_with_NaNs(band1)
19441946
end if
19451947

1948+
ddx = 0d0
19461949
dxsave(1:nvar,1:nz) => dxsave1(1:neq)
19471950
ddxsave(1:nvar,1:nz) => ddxsave1(1:neq)
19481951
B(1:nvar,1:nz) => B1(1:neq)

‎star/private/timestep.f90‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,8 @@ integer function check_dX(s, skip_hard_limit, dt, &
506506
if (s% mix_factor == 0d0 .and. s% dxdt_nuc_factor == 0d0) return
507507

508508
do i=1, max_dx_limit_ctrls ! go over all potential species + XYZ
509-
if (s% dX_limit(i) >= 1 .and. & ! as soon as all of these are >= 1
510-
s% dX_hard_limit(i) >= 1 .and. & ! we'd have nothing to do
511-
s% dX_div_X_limit(i) >= 1 .and. &
512-
s% dX_div_X_hard_limit(i) >= 1) then
509+
if (s% dX_limit_min_X(i) > 1d0 .and. &
510+
s% dX_div_X_limit_min_X(i) > 1d0) then
513511
cycle ! go to next
514512
end if
515513

‎star/test_suite/1M_pre_ms_to_wd/inlist_start‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
save_model_filename = 'start.mod'
1010
required_termination_code_string = 'log_L_lower_limit'
1111

12-
!pgstar_flag = .true.
12+
pgstar_flag = .true.
1313

1414
/ ! end of star_job namelist
1515

‎star/test_suite/1M_pre_ms_to_wd/inlist_to_end_agb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
change_D_omega_flag = .true.
1515
new_D_omega_flag = .true.
1616

17-
!pgstar_flag = .true.
17+
pgstar_flag = .true.
1818

1919
/ ! end of star_job namelist
2020

@@ -35,7 +35,7 @@
3535

3636
envelope_mass_limit = 1d-2 ! Msun
3737

38-
energy_eqn_option = 'eps_grav'
38+
energy_eqn_option = 'dedt'
3939
use_gold2_tolerances = .true.
4040

4141
num_trace_history_values = 2

‎star/test_suite/1M_pre_ms_to_wd/inlist_to_end_core_h_burn‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
new_D_omega_flag = .true.
1616

1717

18-
!pgstar_flag = .true.
18+
pgstar_flag = .true.
1919

2020
/ ! end of star_job namelist
2121

@@ -37,7 +37,6 @@
3737
xa_central_lower_limit_species(1) = 'h1'
3838
xa_central_lower_limit(1) = 0.0001
3939

40-
energy_eqn_option = 'dedt'
4140
use_gold2_tolerances = .true.
4241

4342
num_trace_history_values = 2

0 commit comments

Comments
 (0)