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

kemcom.f

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

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

Variables on this page (8)

abstol, cmin, hcompp, ishort, json, kemmax, reltol, tcut

Purpose

KEMCOM solves the nuclear burning network for one shell, or one convection zone, over a time step: it finds the new mass fractions of H, ³He, ⁴He, ¹²C, ¹³C, ¹⁴N and ¹⁶O simultaneously and implicitly, by Newton iteration, from the reaction rates computed in ENGEB (its comment: "Don VandenBerg's notes explain what the SR is doing"). ¹⁸O is updated explicitly afterwards.

How it fits

  • Who calls it: MIX and ROTMIX, for each radiative shell (IBEGIN = IEND) and each convection zone (IBEGIN < IEND).
  • Inputs: HT ($\log T$), the rates HR1–HR8, HR10–HR12 and the branching ratio HF1 (per Gyr per amu, without the composition factors, as its comment says), HS2 (shell masses), DDAGE (the step in years); the abundances at the start of the step HCOMPP from the module OLDMOD_MOD.
  • Output: the new HCOMP (elements 1–7, 9 and 11; element 3, $Z$, is either reset or set to its zone mean, see step 4) for shells IBEGIN..IEND.
  • Calls: SIMEQC, the linear solver for the 7×8 Newton system.
  • Modules (COMMON blocks until rp_1): NMLPAR_MOD for the settings CMIN, ABSTOL, RELTOL, KEMMAX (formerly /BURTOL/, set by PARMIN) and TCUT(1), the lowest burning temperature (formerly /CTLIM/); OLDMOD_MOD (the previous model: HCOMPP; written by HPOINT and others); IOUNITS_MOD (the output unit).

The method

  1. Mixing. For a convection zone, the starting abundances are the mass-weighted means $\bar x_j = \sum_i x_{j,i}\,\Delta m_i / \sum_i \Delta m_i$ over the zone (elements 1–11), and so are the rates. If the zone's (or shell's) first point is below TCUT(1), it only homogenizes and returns.

    The comment on the first guess is out of date. It still speaks of calls from CRRECT with ITLVL > 1 ("USE THE PREVIOUS RESULT," lines 234–237↗), an argument now removed; the code takes the result for the shell below, or the shell's own HCOMP for shell 1, with no ITLVL branch (lines 238–254↗), as the comment's next lines say (settled from the code, Nov 10, 2026).

    In a burning zone, elements 8 and 10 (¹⁵N and ¹⁷O) are left as they were (suspected bug 2).

From YREC's documentation

Physics Options (Nuclear reaction & burning options) gives the solver's settings: CMIN (1.0D-20), the smallest abundance followed; ABSTOL and RELTOL (1.0D-5, 1.0D-4), the absolute and relative convergence criteria for the changes in abundance; KEMMAX (50), the largest number of substeps; and TCUT(1) (6.5), the $\log T$ above which $\epsilon_\mathrm{nuc}$ is computed, the other TCUT entries being thresholds for later burning stages. Its advice: only TCUT is adjusted from the defaults (6.5 is too high for deuterium burning on the pre-main sequence), and the others should not be changed without good reason.

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. (not reached) The error message gives a fixed limit of 50.

(lines 377–385↗) When the iteration has not converged after KEMMAX iterations, the message says "RUN STOPPED AFTER 50 ATTEMPTS," while the limit is KEMMAX (50 by default, a namelist setting). With another KEMMAX, the message gives the wrong count.

A possible fix:

kemcom.f

@@ lines 377–386 @@
          IF(ICON.GE.KEMMAX) THEN
 C MHP 10/02 IU not defined
 C            WRITE (ISHORT,1000) IU
-            WRITE (ISHORT,1000) IBEGIN
+C 11/09/26 KC via Claude
+C code changed to print the iteration limit KEMMAX, not a fixed 50.
+            WRITE (ISHORT,1000) IBEGIN,KEMMAX
  1000       FORMAT(1X,39('>'),40('<')/1X,'ERROR IN SUBROUTINE KEMCOM'/
      *      1X,'UNABLE TO SOLVE FOR NEW ABUNDANCES IN SHELL',I4/1X,
-     *      'RUN STOPPED AFTER 50 ATTEMPTS')
+     *      'RUN STOPPED AFTER',I4,' ATTEMPTS')
 C 10/30/26 MHP via Claude: bare STOP -> STOP 1, the run-time error code (issue 38).
             STOP 1
          ELSE

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 in any of 34 runs (26 of YREC's cases, from a 0.04 $M_\odot$ brown dwarf and the solar models to 9 $M_\odot$, rotation, and helium burning, and 8 made-up ones): The network always converged within KEMMAX = 50 iterations, the value in every case, so the message was never printed. It is wrong only with another KEMMAX, a namelist setting that no case changes, and then only when the network fails.

2. (never occurred) ¹⁵N and ¹⁷O are not mixed in burning zones.

(lines 400–410↗; lines 121–127↗) When a convection zone burns, loop 40 gives every shell of the zone the new values of nine species but leaves elements 8 and 10 of HCOMP (¹⁵N and ¹⁷O) as they were, whereas the non-burning branch homogenizes all 11 (lines 121–127↗). Within the step nothing repairs it: CRRECT resets HCOMP to HCOMPP before calling MIX at ITLVL > 2 (crrect.f, lines 150–158↗), and MIX's own homogenization (mix.f, lines 360–397↗) runs only with LSEMIC or at ITLVL = 1; after convergence, MIXCZ mixes all 11 species again, over the shells that LC flags convective (main.f, line 977↗; mixcz.f, lines 63–110↗). What follows: ¹⁵N and ¹⁷O can stay unmixed in a burning convection zone. They enter only the Debye–Hückel composition ZDH (with LDH, off by default: crrect.f, lines 141–142↗; coefft.f, lines 212–213↗) and the output.

A possible fix:

kemcom.f

@@ lines 407–412 @@
          HCOMP(9,IU) = W(7)
          HCOMP(3,IU) = Z
          HCOMP(11,IU) = XO18
+C 11/10/26 KC via Claude
+C code changed to give N15 and O17 their zone means, as the
+C non-burning branch does.
+         HCOMP(8,IU) = XSUM(8)
+         HCOMP(10,IU) = XSUM(10)
    40 CONTINUE
   200 RETURN
       END

Checked by running YREC (Nov 10, 2026; a line added at each suspected path counted how often it was taken, the outputs otherwise unchanged): A burning convection zone reached loop 40 11,559 times in the five cases run: 807 times in testsuite/Test_m1p0feh+0p0GS98_base_TAMS, 266 in testsuite/Test_m0p3feh+0p0GS98_base_ZAMS (which sets LDH, so ZDH is read), 1,489 in testsuite/Test_m1p4feh+0p0GS98_dif_TAMS (with diffusion), 4,567 in testsuite/Test_m0p8feh+0p0GS98_rotp8p0d0p1mag1e4std_TAMS (with rotation), and 4,430 in examples/run_standard_solar_model/Test_solarcal_noGS_norot. Not once did a shell's ¹⁵N or ¹⁷O differ from the zone's mean by more than a relative $10^{-10}$: The zones were already uniform in both, so leaving them changed nothing. The fix was not run, since it would move these values by less than that. What would reach it: a burning zone spreading over layers of different ¹⁵N or ¹⁷O, which KEMCOM's network, not following them, cannot make. Intent: The comment calls the two "not currently used" (line 79↗).

Definitions

subroutineKEMCOM

lines 4–412 · GitHub

Implicit Newton solution of the 7-species network over one step (equations above), with explicit ¹⁸O.

Uses modules DIMENSIONS_MOD, IOUNITS_MOD, NMLPAR_MOD, OLDMOD_MOD

Called by MIX ×2, ROTMIX ×2

Flowchart of its calls, in order (1)
if (J1J.NE.0): SIMEQC360

Change log

The changes since rp_1

Changed since rp_1. The EQUIVALENCE of B with A(50..56) removed, B(I) written as A(49+I) (the same storage, so the same results); COMMON blocks to modules, IMPLICIT NONE. No question settled.

Changed since a8a5950. The stop after KEMMAX iterations now exits with status 1 (STOP 1), the run-time error code, instead of a bare STOP, which exited with 0 (KNOWN_ISSUES.md, issue 38).