PyREC scaffolding (from YREC development, 7be4133)/ rotmix.fGlossary

rotmix.f

251 lines · 1 definitions · on GitHub (7be4133)

Python version: rotmix.py, 206 lines, on the right (switch to Python above the code).

Variables on this page (14)

cgl, cln, csecyr, delm, dt_gs, ishort, json, ldify, lexcom, lnewdif, sdel, tcut, xmin, ymin

Purpose

Nuclear burning and gravitational settling for one step of the rotational-mixing loop. Its header comment lists the steps: (1) use KEMCOM to solve implicitly for the abundances in radiative regions, shell by shell; (2) solve for the burning in each convection zone as a whole. It then applies the settling of helium and renormalizes the composition.

How it fits

  • Who calls it: MIDMOD (with the temperatures at the current time, HTM, "for thermodynamic consistency," MHP 6/00) and BURSMIX, in their loops of substeps.
  • Inputs: the step DELTS (s), the composition HCOMP(15, ·), shell masses HS2, temperatures HT ($\log T$), densities HD (also used for the rates), and the zone lists MRZONE (radiative) and MXZONE (convective); for the settling, HS, HR, HP, HS1, HSTOT and the convection flags LC. The zone lists come from CONVEC, whose end of the surface radiative zone is misplaced (convec.f, suspected bug 1).
  • The rates: computed here by RATES on the model passed in (HD, HT, and the substep's own composition), as MIX does: the rates HR1…HR13 and the branchings HF1, HF2, set to zero in shells with $\log T \le$ TCUT(1).
  • What it calls: RATES, KEMCOM, then either MICRODIFF (when LNEWDIF is true) or GRSETT (the older Bahcall–Loeb settling).
  • Output: HCOMP, updated in place.
  • Modules, other: NMLPAR_MOD (the namelist parameters LDIFY, which this routine may switch off, DT_GS, XMIN, YMIN, LNEWDIF, TCUT(1) and LEXCOM: 15 species or 11), MDPHY_MOD (DELM), SCRTCH_MOD (SDEL, temporarily overwritten), CONSTANTS_MOD, IOUNITS_MOD (ISHORT), DIMENSIONS_MOD (JSON).

The method

  1. Burning. For each radiative shell above the cut $\log T >$ TCUT(1) (the loop stops at the first shell below it, assuming $T$ falls outward), KEMCOM is called for the shell alone; for each convection zone, for the whole zone at once, which also homogenizes it. The step is passed in years, DDAGE = DELTS/CSECYR.

    The burning loop's early exit skips nothing hot. GOTO 45 leaves both the shell loop and the zone loop at the first shell cooler than TCUT(1) (lines 118–130↗), so a radiative zone listed after it is skipped; but CONVEC lists the radiative zones from the center out (convec.f, lines 185–205↗, with the slip of CONVEC's suspected bug 1 in the last zone's upper edge), and the temperature falls outward, so every later zone is cooler too. MIX exits its loop in the same way (mix.f, line 252↗).

  2. Settling (if LDIFY). It is skipped once the central hydrogen is below XMIN (and LDIFY is then switched off for good), if the star is fully convective, or if $Y <$ YMIN everywhere. It stops the run (exit status 1) if there is no surface convection zone. The outer point JMAX is the top of the last radiative zone; the comment says it is moved down to the first shell with $Y >$ YMIN, but the search moves only J, so JMAX stays the top of the last radiative zone (suspected bug 1). The settling time there is taken from Michaud et al. (1984): $$t_\mathrm{settle} = 4.348\times10^{21}\;\frac{f_M}{T^{3/2}}\ \text{yr},\qquad f_M = \frac{M_* - m(\texttt{JMAX})}{M_*},$$ with $T$ in K at JMAX (the code multiplies by CSECYR to get TSCALE in seconds, the unit of DELTS), and the step is divided into NSTEP substeps of at most DT_GS $\times\,t_\mathrm{settle}$ (one more than INT(DELTS/DTMAX) unless DELTS is an exact multiple of DTMAX). The pressure gradient passed to the settling routine is $$\frac{d\ln P}{dr} = -\frac{G m \rho}{P r^2}\quad(\texttt{HQPR}).$$ During the settling, SDEL(2,·) holds DELM and is restored afterwards.

  3. Renormalization. Every abundance is clipped to $[0, 1]$; $Z$ (HCOMP(3)) is capped at $1 - X - X_3$, and $Y$ is set to $1 - X - Z - X_3$, where $X_3$ is ³He, the fourth species HCOMP(4,·) (as STARIN fills it).

Suspected bugs, checked by running the code

Each bug is marked by what running the code showed: (changes results, large) or (small), the fix moving a run clearly beyond a null change; (stops the run); (wrong output), the fix changing only what is written; (harmless in the runs), within the noise; (never occurred), the code ran but the fault did not; (not reached); (cannot be reached), a guard prevents it; (withdrawn), the suspicion was wrong.

1. (never occurred) The outer point for the settling step is not moved down.

(lines 156–160↗; lines 174–180↗; lines 191–194↗) The comment says the outer boundary is the surface convection zone or "the first point where the helium abundance rises above" YMIN. Loop 140 finds that point as J, but JMAX is never set to it, so FM and TSCALE, and with them the number of settling substeps, are always taken at the top of the last radiative zone. Where $Y \le$ YMIN there, the step limit is set at a point the comment means to skip. Only with LDIFY (off by default); the settling itself does not use JMAX.

A possible fix:

rotmix.f

@@ lines 178–183 @@
 C   Y<YMIN FOR THE WHOLE STAR IF THE CODE GETS HERE.
          GOTO 170
   150    CONTINUE
+C 11/09/26 KC via Claude
+C code changed to move the outer point down to the first shell with
+C Y > YMIN, as the comment above says.
+         JMAX = J
          STOT=EXP(CLN*HSTOT)
          DO 130 I = 1,M
             TEMP(I) = SDEL(2,I)

Checked by running YREC (Nov 9, 2026; a line added at each suspected path counted how often it was taken, the outputs otherwise unchanged): The outer point was searched in the two rotating test cases with settling, 2,217 times in testsuite/Test_m0p8feh+0p0GS98_rotp8p0d0p1mag1e4std_TAMS and 1,658 in testsuite/Test_solarGS98_difrotmixper18p4d1p0, at shells 8 to 527, and the first shell with $Y >$ YMIN was always the top of the last radiative zone itself, so J equaled JMAX and the missing assignment changed nothing. It matters only where the helium abundance there has fallen to YMIN ($10^{-3}$ in every namelist), which no case reaches. Intent: MIX, the same code for runs without rotation, uses J (mix.f, line 441↗, mix.f, line 444↗), so this looks like a slip.

2. (not reached) The stop message names the wrong routine.

(lines 163–169↗) The stop for no surface convection zone prints "STOPPED IN SUBROUTINE MIX" (copied from MIX), though it stops in ROTMIX. Only with LDIFY (off by default).

A possible fix:

rotmix.f

@@ lines 163–170 @@
          IF(.NOT.LC(M))THEN
             WRITE(*,911)
             WRITE(ISHORT,911)
+C 11/09/26 KC via Claude
+C code changed to name ROTMIX in the stop message.
   911       FORMAT(1X,'NO SURFACE CZ - DIFFUSION NOT MEANINGFUL'/
-     *             'STOPPED IN SUBROUTINE MIX')
+     *             'STOPPED IN SUBROUTINE ROTMIX')
 C 10/30/26 MHP via Claude: bare STOP -> STOP 1, the run-time error code (issue 38).
             STOP 1
          ENDIF

Checked by running YREC (Nov 9, 2026; a line added at each suspected path counted how often it was taken, the outputs otherwise unchanged): Not reached. No case run stopped here: The rotating cases with settling (testsuite/Test_m0p8feh+0p0GS98_rotp8p0d0p1mag1e4std_TAMS, testsuite/Test_solarGS98_difrotmixper18p4d1p0) have a surface convection zone, and the 2 and 3 $M_\odot$ rotating cases have LDIFY off. A rotating run with LDIFY for a star without a surface convection zone would reach it, and stop. Intent: The text was copied from MIX, which since 1992 only warns and goes on (mix.f, lines 428–433↗: "DBG 2/92 CHANGED STOP TO JUST A WARNING MESSAGE, EXECUTION CONTINUES").

Definitions

subroutineROTMIX

lines 5–251 · GitHub

Uses modules CONSTANTS_MOD, DIMENSIONS_MOD, IOUNITS_MOD, MDPHY_MOD, NMLPAR_MOD, SCRTCH_MOD

Called by BURSMIX, MIDMOD

Flowchart of its calls, in order (5)
for K = 1,NRZONE (DO 40), lines 118–129
for J = MRZONE(K,1),MRZONE(K,2) (DO 30), lines 119–128
for K = 1,NZONE (DO 50), lines 135–150
if (LDIFY), lines 151–237
for NS = 1,NSTEP (DO 160), lines 224–232
Compiler warnings (1)

gfortran -Wall -Wextra, compiling only; nothing was run.

  • line 207: Inequality comparison for REAL(8) [-Wcompare-reals]

Change log

The changes since rp_1

Changed since rp_1. The two debug writes to unit 69 are commented out (settles former question 1); COMMON blocks to modules (the unused /CTLIM/ dropped), IMPLICIT NONE.

Changed since a8a5950. The rates are computed by RATES on the model passed in, instead of copied from HCOMPM in BURN_MOD (removed since a8a5950), which held the rates MIX found on the previous Newton iterate's end-of-step structure, so that the midpoint substep from MIDMOD burned with end-of-step rates (this settles former question 3, since the copies are gone); the substep count tests MOD(DELTS,DTMAX) (this settles former question 1); the stop for no surface convection zone exits with status 1, the code for run-time errors (KNOWN_ISSUES.md, issue 38). The later questions are renumbered.