Chemistry–hydro coupling: advected species + carbox reactions + thermochemistry#6
Draft
lorenzobranca wants to merge 3 commits into
Draft
Chemistry–hydro coupling: advected species + carbox reactions + thermochemistry#6lorenzobranca wants to merge 3 commits into
lorenzobranca wants to merge 3 commits into
Conversation
Complete working implementation (species advection + per-cell carbox reaction + KROME-grade thermochemistry). GPL-encumbered (KROME-derived cooling + carbox dependency), so NOT suitable for MIT astronomix main -- preserved here; the MIT-clean mechanism is on feature/chemistry-species-hook. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UhwF9zJfmnzuLeABHu75QW
- Add LICENSE.md marking the _chemistry subtree (and chemistry_setup) as GPL-3.0 (KROME-derived thermochemistry + carbox dependency), distinct from MIT core; note it in the package and _thermochemistry docstrings. - Remove the machine-specific default CO-table path; require the caller to supply co_cooling_table_path when co_cooling is enabled (no KROME data bundled). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UhwF9zJfmnzuLeABHu75QW
lorenzobranca
force-pushed
the
feature/chemistry-full
branch
from
July 15, 2026 10:24
e894829 to
3730715
Compare
The finite-volume MHD state evolution split the magnetic field off the primitive state with `state[:-3]` / `state[-3:]`, assuming B occupies the last three state indices. That holds for pure MHD, but the variable registry appends advected tracers (chemistry species, cosmic-ray number density, wind density) *after* the magnetic block, so with any of those enabled `[-3:]` sliced tracer rows instead of B -- silently corrupting the magnetic update (no error raised). Slice B out of its actual (middle) slot via `magnetic_index` instead, and reinsert it there on return. `magnetic_update` is unchanged: it already takes the gas sub-state and B as separate arguments and only reads density / velocity / pressure from the front of the gas state. For the no-tracer case the new slicing is bit-identical to the old one, so pure MHD is unaffected. Verified with a 32^3 FV MHD box run plain vs. with the chemistry module (thermochemistry off, so species are passive): the magnetic field is bit-identical between the two runs while the species react, whereas before this fix the fields diverged at O(1). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UhwF9zJfmnzuLeABHu75QW
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.
Chemistry ↔ hydro coupling: advected species + carbox reactions + thermochemistry
What it adds
A full operator-split coupling of a chemical network to the fluid, differentiable
and GPU-vmapped end to end:
contiguous state block, advected by the FV solver like the CR/wind tracers
(
registered_variables.py).reaction network over
dtwith a stiff DiffraxKvaerno5solve, vmapped overthe grid (
_chemistry.py).abundances (KROME-grade heating/cooling: cosmic-ray + grain photoelectric + H2
formation heating; Lyman-α + [C II] 158 µm + [O I] 63 µm + Glover-Abel H2 +
Neufeld-Kaufman CO cooling) and written back to the pressure field
(
_thermochemistry.py).ChemistryConfig/ChemistryParams), a gated hook in_iteration_level_updates, and a builderbuild_chemistry_from_network_file.Gated on finite-volume mode; a no-op unless
chemistry=True. The carbox/Diffraximports are lazy, so
import astronomixis unaffected when chemistry is unused.Core fix (MIT code): FV MHD now composes with trailing state tracers
One commit touches MIT core code —
_finite_volume/_state_evolution/evolve_state.py—so flagging it explicitly. The FV MHD evolution split the magnetic field off the
primitive state with
state[-3:], assuming B is the last three state indices. Thatholds only for pure MHD: the registry appends advected tracers (chemistry species,
cosmic-ray density, wind density) after the magnetic block, so with any of them
enabled
[-3:]sliced tracer rows instead of B — silently corrupting the magneticupdate (no error raised). It now slices B out of its actual slot via
magnetic_indexand reinserts it there;
magnetic_updateis unchanged (it already takes the gassub-state and B as separate args). For the no-tracer case the new slicing is
bit-identical to the old, so pure MHD is unaffected. This also fixes MHD + cosmic
rays and MHD + wind, independent of chemistry.
Verified with a 32³ FV MHD box run plain vs. with the (passive) chemistry block: the
magnetic field is bit-identical between the two while the species react — before the
fix the fields diverged at O(1).
Dependencies / data
coolCO.dat, GPL); it isnot bundled — the caller passes
co_cooling_table_path, elseco_coolingmust stay off.
Validation (done during development)
native CPU; species advect + react, non-negative and finite.
jax.gradof final state w.r.t.cosmic_ray_rate.(verbatim Glover-Abel port); the benchmark also caught + fixed a bad
H2-formation heating term.
cold, compressible state (~40 K, broadened density PDF) vs ~240 K without —
the expected thermostat effect.
Known limitations / open items
tabulated data; collisional H2-dissociation cooling not included.
pytests/for the full engine yet (the MIT mechanism has tests — see thecompanion
feature/chemistry-species-hook).Alternatives to full-GPL-in (if you'd rather keep astronomix MIT)
source-term hook (branch
feature/chemistry-species-hook, MIT, with tests)and keep this engine as a separate GPL package that plugs into the hook.
source) so it can be MIT, leaving carbox an optional dependency.
🤖 Generated with Claude Code
https://claude.ai/code/session_01UhwF9zJfmnzuLeABHu75QW