Skip to content

Add a mean gas temperature source (thermostat) beside the mean pressure gradient - #2182

Draft
sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:wave3/mean-thermostat
Draft

sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:wave3/mean-thermostat

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

Adds a mean gas temperature source (thermostat) beside the mean pressure gradient, for chemistry flows in a periodic domain.

Stacked on #2177 (the mean pressure gradient and its controller). Only the top commit is this PR; I will rebase once #2177 merges.

Parameter Meaning
mean_qdot Uniform heat source per unit volume (initial value if controlled; default 0)
mean_temp Target mass-averaged temperature T_b*; enables the controller
mean_temp_gain Controller gain G, required with mean_temp, 0 < G < 4/3

mean_qdot is added to the energy equation. With mean_temp set, the source is updated once per step from the mass-averaged temperature T_b = sum(rho T dV)/sum(rho dV),

qdot^{n+1} = qdot^n + (G <rho c_v>/dt)(T_b* - 2 T_b^n + T_b^{n-1}),

the same integral controller as mean_mflux, scaled by the volume-mean rho c_v. It acts on the temperature, so gas heat release lowers the source needed and the controller holds T_b* net of chemistry (qdot can become negative). mean_temp.dat logs t, T_b, the mixing-cup temperature, qdot and the volume. Chemistry only; Cartesian and periodic in every active direction; immersed boundaries are rejected by the validator (same reason as #2177).

Shared code

The two mean sources share the once-per-step volume reduction (one MPI allreduce for both), the controller update (s_mean_controller), the history-file open (s_open_history) and the validator gain check, so the mean pressure gradient is now a call into the same helper rather than its own copy.

Verification

GPU, current master plus #2177 plus this change:

  • Default unchanged. Shard 2 of 4 of the full suite on MI300A (OpenMP offload): 190 passed, 0 failed, no golden regenerated. The whole Chemistry subset (24 tests) passes.
  • New tests 1D -> Chemistry -> Perfect Reactor -> Thermostat -> Heat Source and ... -> Temperature Controller (the periodic autoigniting H2/O2 reactor at 1600 K with mean_qdot = 1e9 W/m^3, and with mean_temp = 1250 K, G = 0.5). Against the unforced reactor the initial state is identical and the final state moves the right way: the heat source raises the final pressure by 3% and the radical species by about 30%; the controller cools toward 1250 K, lowering the final pressure by 22% and the radicals by about 99%.
  • Frontier, Cray CCE + OpenACC (fresh worktree, clean build): both new tests and both Perfect Reactor tests pass.
  • NVHPC 25.5, --gpu mp, compile-only: simulation builds clean.
  • Validator: 14 unit tests for the two mean sources (periodic, chemistry required, non-periodic, missing/unstable/orphan gain, positive target, immersed boundary).

Not in this PR: the self-similar variant for thermally developed wall-bounded flow (mean_temp_wall), which needs conductivity and an x stencil; I will open it separately.

This PR was made with Claude Code (AI).

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Claude Code Review

Head SHA: 8c43223

Files changed:

  • 12
  • docs/documentation/case.md
  • docs/documentation/equations.md
  • src/simulation/m_body_forces.fpp
  • src/simulation/m_global_parameters.fpp
  • src/simulation/m_start_up.fpp
  • src/simulation/m_time_steppers.fpp
  • toolchain/mfc/case_validator.py
  • toolchain/mfc/lint_docs.py
  • toolchain/mfc/params/definitions.py
  • toolchain/mfc/params/descriptions.py

Findings:
No issues found. Checked in step 4: src/simulation/m_body_forces.fpp, m_global_parameters.fpp, m_time_steppers.fpp, toolchain/mfc/params/descriptions.py, toolchain/mfc/lint_docs.py, docs/documentation/equations.md (plus helper signatures in m_helper_basic.fpp and m_mpi_common.fpp).

…re gradient

mean_qdot adds a uniform heat source per volume to the energy equation.
mean_temp with mean_temp_gain holds the mass-averaged temperature
T_b = sum(rho T dV)/sum(rho dV) with the same integral controller as mean_mflux,
scaled by the mean rho*c_v; it acts on T, so gas heat release lowers the source
needed. Chemistry only. The two mean sources share the once-per-step reduction,
the controller update, the history-file open and the validator gain check;
mean_temp.dat logs t, T_b, the mixing-cup T, qdot and the volume.
Immersed boundaries are rejected by the validator.
@sbryngelson
sbryngelson force-pushed the wave3/mean-thermostat branch from 8c43223 to ff25f33 Compare November 8, 2026 21:49
@sbryngelson

sbryngelson commented Nov 8, 2026 •

Copy link
Copy Markdown
Member Author

NVIDIA + NVHPC hand test: wingtip (Georgia Tech), NVIDIA A100 80GB PCIe (compute capability 8.0), nvfortran 25.11 (NVHPC) with OpenACC, ./mfc.sh test --gpu acc

AMD GPU case optimization: Tuolumne (LLNL), AMD Instinct MI300A (gfx942), amdflang (AFAR 24.3.0, LLVMFlang 24) with OpenMP offload. ./mfc.sh run benchmarks/ibm/case.py --case-optimization --gpu mp -- --gbpp 1 --steps 10 (as in CI's case-optimization job), then the NaN/Inf output check: passes at ff25f33ec.

NVHPC case-optimization results follow when they finish. Posted with Claude Code (AI).

Case optimization on NVIDIA + NVHPC (wingtip, A100, nvfortran 25.11, OpenACC): ./mfc.sh run benchmarks/ibm/case.py --case-optimization --gpu acc -- --gbpp 1 --steps 10 (as in CI's case-optimization job), then the NaN/Inf output check: passes at ff25f33ec merged with master 871148786.

Case optimization on NVIDIA + NVHPC with OpenMP offload (wingtip, A100, nvfortran 25.11), ./mfc.sh run <case> --case-optimization --gpu mp -- --gbpp 1 --steps 10 then the NaN/Inf check: passes for benchmarks/ibm at ff25f33ec merged with master 871148786.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_body_forces.fpp 497 +73
src/simulation/m_global_parameters.fpp 854 +5
Directory Lines Diff
simulation 30251 +78
total 49454 +78

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant