Skip radiation number density during timestep control#2004
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the SKIP_PHOTOCHEMFLUX compile-time option to optimize photochemistry calculations by skipping the tracking of radiation flux variables when they are not needed. It also configures several test problems to use the Rosenbrock integrator. The review feedback highlights two important issues: first, a potential division-by-zero or floating-point overflow in photochemistry.hpp when n_gamma_initial is extremely small, which can be mitigated by using a safer threshold; second, a missing update to the microphysics compilation setup in StromgrenSphereRSLA/CMakeLists.txt to enable the Rosenbrock integrator.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const Real n_gamma_final = photochemstate.rn[0 + MicrophysicsNumRadVarsPerGroup * nn]; | ||
| state(i, j, k, firstChemIndex + Physics_NumVars::numRadVarsPerGroup * nn) = n_gamma_final * chemBandQuanta[nn]; | ||
| #ifdef SKIP_PHOTOCHEMFLUX | ||
| const Real flux_ratio = (n_gamma_initial[nn] > 0.0_rt) ? (n_gamma_final / n_gamma_initial[nn]) : 0.0_rt; |
There was a problem hiding this comment.
Using 0.0_rt as the threshold for n_gamma_initial[nn] can lead to floating-point overflow (to infinity) when n_gamma_initial[nn] is extremely small (e.g., subnormal values close to underflow) and n_gamma_final is clamped to small_x. If the initial flux is 0.0, multiplying it by infinity produces NaN, which will propagate and corrupt the simulation state. Using a safe, physically negligible threshold like 1e-100_rt prevents this overflow and subsequent NaN propagation.
const Real flux_ratio = (n_gamma_initial[nn] > 1e-100_rt) ? (n_gamma_final / n_gamma_initial[nn]) : 0.0_rt;|
|
||
| # this will add #define CHEMISTRY | ||
| target_compile_definitions(${JOB_NAME} PUBLIC PHOTOCHEMISTRY) | ||
| target_compile_definitions(${JOB_NAME} PUBLIC PHOTOCHEMISTRY SKIP_PHOTOCHEMFLUX SKIP_RAD_NUM_CONV) |
There was a problem hiding this comment.
Since StromgrenRSLA.toml has been updated to use integrator.rosenbrock_tableau = 3, the setup_target_for_microphysics_compilation call at the beginning of this file (around line 6) should also be updated to pass "Rosenbrock" as the third argument, similar to the changes made in DTypeFront and StromgrenSphere. Otherwise, the Rosenbrock integrator will not be compiled for this target, leading to build or runtime failures.
|
/azp run |
|
Azure Pipelines successfully started running 4 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 4 pipeline(s). |
Description
This PR skips radiation number density from convergence check in microphysics integration. There's no performance gain when tested on my laptop.

Checklist
Before this pull request can be reviewed, all of these tasks should be completed. Denote completed tasks with an
xinside the square brackets[ ]in the Markdown source below:/azp run.