Skip to content

Book the core heat change of a structure update with energy_balance - #1178

Merged
egpbos merged 3 commits into
mainfrom
pb/book-struct-core-heat
Dec 4, 2026
Merged

egpbos merged 3 commits into
mainfrom
pb/book-struct-core-heat

Conversation

@egpbos

@egpbos egpbos commented Dec 3, 2026

Copy link
Copy Markdown
Member

Description

With core_bc = "energy_balance" the core heat content is core_heatcap * tfac_core_avg * M_core times the temperature of the CMB basic node. A structure update carries the mantle entropy by mass parcel onto the new mesh, so that temperature follows the new CMB pressure and the core heat content jumps, with no column booking it. This PR books it, as proposed in the issue; the physics does not change.

  • The structure update books the core heat content after the entropy carry minus before it in step_dE_struct_core_J (new interior_energetics/aragog_core_balance.py, called from AragogRunner._apply_structure_update).
  • An energy_balance call now fills step_dE_core_J (heat content at the end of the call minus at the end of the last kept call) and core_C_eff (the capacity C), so the existing core ledger E_core_residual_J / E_core_residual_frac runs in this mode and closes with the booked term.
  • The node temperature is evaluated as in Aragog's own CMB closure check (_check_cmb_ledger): bottom cell entropy extrapolated half a basic spacing with dSdr_cmb, on the solver's _cmb_node_phase evaluator. This reads private solver attributes, as the core_module path already does.
  • Output reference, schema, docs/Explanations/model.md and docs/How-to/usage_core_evolution.md no longer say the term is 0 in this mode.

Closes #1113

Related open PRs on the same files: #1168 (coupler.py, output.md) and #1149 (interior_energetics/wrapper.py, output.md); expect small conflicts in the generated output reference.

Validation of changes

  • Short real run: input/all_options.toml (1 M_E, Zalmoxis dynamic structure, Aragog energy_balance) with the dummy atmosphere and star, no escape, and solver_method = "radau", to 12 kyr. All 6 structure updates book a positive term (+1.2e28 to +6.3e28 J, 11 to 63 K at C = 1.0017e27 J/K) while P_cmb rises by 1.1 to 3.1 GPa: the sign follows the pressure change in 6 of 6, and the size is in the range the issue measured. With the term the core ledger moves by at most 3e24 J at an update; without it, it would grow by 1.5e29 J over the run. On the 21 rows without an update, step_dE_core_J / (core_C_eff * dT_cmb_node) is 1.0000, so the node temperature used here is the helpfile T_cmb_node.
  • The same run shows one ledger step of 8.7e27 J at t = 988 yr that is not a structure update: Aragog skipped its own CMB closure check for that call (node table slope below 1e-6 of the closure slope, a clamped cell where the CMB node starts to freeze). The new ledger now shows such a call; possibly related to CMB closure check aborts an energy_balance run with a ledger miss 200 times its bound aragog#128, not addressed here.
  • New unit tests (tests/interior_energetics/test_aragog_core_balance.py): the booked heat equals C (T_node(P_new) - T_node(P_old)) at the carried entropy, with guards against a missing tfac_core_avg and against the bottom cell entropy in place of the node entropy; its sign follows the pressure change; an update that moves nothing books exactly 0; the ledger closes over call, update, call, and misses by exactly the booked heat without it. tests/interior_energetics/test_aragog.py checks the order in the runner (heat taken before the reset, booked after the entropy hand-over) and that the columns are written only for a returned call.
  • Mutants: 178 of 181 killed on changed lines; 1 place: aragog_core_balance.py:63 only switches a log line.
  • macOS, Python 3.12, pip install -e ".[develop]": the unit tier passes except tests that need CVODE (scikits_odes_sundials), atmodeller or a full install (test_install_scripts.py, test_installer.py, test_doctor.py); none of them touch the changed code. ruff, validate_test_structure.sh and the four generate_*.py --check pass.

Not checked: the JAX runner (aragog_jax.py) does not write the new columns; a giant-impact re-melt also moves the CMB node and is not booked, so the energy_balance core ledger may show it on impact rows; whether this jump causes the Aragog CMBLedgerMissError stops (FormingWorlds/aragog#128).

Checklist

  • I have followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have checked that the tests still pass on my computer
  • I have updated the docs, as appropriate
  • I have added tests for these changes, as appropriate
  • I have checked that all dependencies have been updated, as required

With core_bc = "energy_balance" the core heat content is
core_heatcap * tfac_core_avg * M_core times the temperature of the CMB
basic node. A structure update carries the mantle entropy by mass parcel
onto the new mesh, so the node temperature changes with the CMB pressure
and the core heat content jumps, with no column booking it.

The update now books the heat content after the carry minus before it
in step_dE_struct_core_J, and the energy_balance call fills step_dE_core_J
(the heat content at the end of the call minus at the end of the last kept
call) and core_C_eff, so the core ledger E_core_residual_J runs in this
mode too and closes with the booked term. No physics changes.

@egpbos egpbos left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 The new module and its registry entries are needed and small; a few parts could be shorter or owned elsewhere: 3 questions, 1 request.
Size: +425/-23, of which 283 lines are tests. No split needed. I did not run the code or a coupled case.

Comment thread src/proteus/utils/coupler.py Resolved

@egpbos egpbos left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💂 3 regressions in 2 files, each with a measured fix (one partly); +425/-23 lines (net +402), 67 % of the added lines in tests.

Metric Base Head Head with the fixes
AragogRunner.run_solver lines (lizard NLOC, limit 50) 55 60 53
interior_energetics/aragog.py lines (aim 500) 3844 3854 3846
core_heat_content docstring / body lines new 7 / 6 5 / 6

No function crosses the complexity limit of 10 (ruff C901); run_solver reaches it (8 to 10). No new unused code (vulture) or duplicated block (symilar). Comment and docstring lines are 34 % of the added source lines (29 of 86), against 36 % in src/proteus at the base.

No fix within the rules: test_a_failed_call_leaves_the_solver_with_the_state_it_started_from grows from 81 to 87 lines and tests/interior_energetics/test_aragog.py from 6118 to 6176 lines, both for new assertions on the runner; tools/_helpfile_scan.py grows from 874 to 875 lines by one registry entry. Not counted: N806 for dE, which the package breaks 2623 times at the base.

Not run: the CVODE test in test_aragog.py (no scikits_odes_sundials here), the JAX runner, and the unit tier outside these two test files.

The structure-update test now checks the energy_balance booking order with
and without a stored entropy, the autouse fixture returns its mock, the
step_dE_struct_core_J description names only what the column holds, and
run_solver uses its core_bc local in place of the repeated config reads.
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.32%. Comparing base (811bb86) to head (3c5fa10).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1178      +/-   ##
==========================================
+ Coverage   96.25%   96.32%   +0.07%     
==========================================
  Files         168      169       +1     
  Lines       28951    29201     +250     
  Branches     4779     4834      +55     
==========================================
+ Hits        27866    28129     +263     
+ Misses        771      768       -3     
+ Partials      314      304      -10     
Flag Coverage Δ
unit-tests 95.17% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timlichtenberg timlichtenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Patrick, this closes the gap in #1113, and the interior output stays unchanged against main. Two things before merge:

After a giant impact the core ledger is not booked and the offset stays. _remelt_aragog sets solver._solution = None (wrapper.py:2260), so end_heat_content returns None at the next structure update and book_core_across_update books nothing.

In a run with one dummy impact of 0.003 M_E at 3 kyr, E_core_residual_J jumps from 8.7e27 to 1.9e29 J at 3100 yr (E_core_residual_frac 0.020 to 0.377) and ends at 0.225, against 0.011 without the impact; step_dE_struct_core_J is 0 on that row. The output reference and the usage page say the update change is booked with energy_balance without exception. Please either book the re-melt step (take the heat content before the solution is dropped), or state in both pages that the ledger is no closure check after an impact.

Please add one test against a real Aragog solver. The new module reads 9 private Aragog attributes on the default core_bc, and the tests only see a stand-in with the same names (test_aragog.py mocks the module for the whole file). A small energy_balance solver from the Aragog test helpers is enough: the core heat content over C equals the basic-node temperature, C dT_node equals the closure term, and an update with an unchanged mesh books exactly 0. Skip it when the EOS tables are missing.

On your question about the CMB node temperature: yes, please open the Aragog issue for a public method. It also takes most of the private reads out of this module, and a follow-up PR is fine for that.

The re-melt drops the Aragog solution, so the structure update after an
impact found no heat content to measure from and booked nothing; the
core ledger kept the jump. The re-melt now keeps the core heat content
at the end of the landing step, and the update after it books the change
to its own start state in step_dE_impact_core_J.

A smoke test checks the heat content against a real energy_balance
solver: the node temperature, the closure term of the Aragog CMB check,
and a zero booking on an unchanged mesh. It skips without P-S tables.
@egpbos

egpbos commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

🤖 Thanks, both points are done in 3c5fa10.

Giant impact. The re-melt now keeps the core heat content at the end of the landing step before it drops the solution. The structure update after the impact books the change from there to its own start state in step_dE_impact_core_J: the re-melt and that update together, as the core_module refit also covers the structure change of its reset. step_dE_struct_core_J is 0 on that row. The output reference, usage_core_evolution.md and model.md say so. In a run like yours (one dummy impact of 0.003 M_E at 3 kyr, Radau, dummy atmosphere), the 3100 yr row books 1.48e29 J and E_core_residual_J moves from 8.73e27 to 8.70e27 J; E_core_residual_frac goes from 0.042 to 0.023 and is 0.031 at 6.3 kyr, where I stopped the run. The two unbooked steps that are left (8.7e27 J at 988 yr and 9.1e27 J at 4126 yr) are calls where Aragog skipped its own CMB closure check (node table slope below 1e-6 of the closure slope), not updates or impacts.

Real Aragog solver. New smoke test tests/interior_energetics/test_aragog_core_balance_smoke.py: a 15-node energy_balance solver with the core cooling boundary that PROTEUS sets, one 50-yr call from a mantle hotter at the base. It checks your three points: the heat content over C equals T_basic[0] (rel 1e-12); C dT_node plus the CMB heat equals the closure term r of _check_cmb_ledger (to 1e-9 of the CMB heat); a reset onto the same mesh books exactly 0. Guards: a missing tfac_core_avg and the bottom cell entropy in place of the node entropy both miss. It skips without P-S tables, found at ARAGOG_TEST_EOS_DIR or $FWL_DATA/aragog/spider_eos as in the Aragog tests. No CI job has those tables now, so it runs only where they exist; it passes here with the tables of a PROTEUS run.

Mutants on the lines of this commit: 85 of 85 killed. The Aragog issue for a public node-temperature method follows.

@timlichtenberg timlichtenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Patrick, both points are addressed. I reran the impact case at 3c5fa10: the impact row now books the core heat change that was missing before, and the residual stays flat across the impact. The two steps that remain unbooked are the calls where Aragog skips its own CMB closure check, as you say. The smoke test passes with real tables and fails when the capacity factor or the node entropy is changed.

One follow-up, not for this PR: no CI job has the P-S tables, so the smoke test is always skipped there. A follow-up that runs it in CI would make it protect the core balance.

@egpbos
egpbos merged commit 89747c5 into main Dec 4, 2026
15 checks passed
@egpbos
egpbos deleted the pb/book-struct-core-heat branch December 4, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

energy_balance does not book the core heat change at a structure update

2 participants