AMReX-Astro / AMReX-Astro/Microphysics

he-burn approximate rates need denominator guard

Open
#1,947 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit
Dominant language
C++
Stars
43
Forks
46
Avg merge
2d 18h
Merged PRs (30d)
15

Description

Approximate effective-rate helpers divide by (r_pg + r_pa) without denominator floor

Summary

Multiple approximate-rate helper functions in he-burn reaclib_rates.H files compute:

dd = 1.0_rt / (r_pg + r_pa)

with no protection against near-zero or zero denominator. Under extreme conditions (very small screened rates), this can produce inf/nan and destabilize RHS/Jacobian evaluation.

Severity

Medium

Affected Code

  • networks/he-burn/*/reaclib_rates.H
    • families of functions named *_approx using dd = 1.0_rt / (r_pg + r_pa)
    • examples:
      • networks/he-burn/ase/reaclib_rates.H (e.g. around lines 1934, 1953, ...)
      • networks/he-burn/cno-he-burn-33a/reaclib_rates.H (e.g. around lines 3824, 3843, ...)

Why This Is a Bug

Even if uncommon, exact/underflow-zero denominator can occur in screened-rate arithmetic, and current code has no numerical guard. A single inf/nan can contaminate burn state and Jacobian entries.

Proposed Patch

Use a denominator floor (and derivative-consistent handling) in all affected helpers:

-    amrex::Real dd = 1.0_rt / (r_pg + r_pa);
+    constexpr amrex::Real denom_floor = 1.0e-300_rt;
+    const amrex::Real denom = amrex::max(r_pg + r_pa, denom_floor);
+    amrex::Real dd = 1.0_rt / denom;

For derivative expressions containing dd * dd, reuse denom consistently.

Validation

  • Add a stress test at low-temperature/high-screening conditions where both channel rates become tiny.
  • Verify no inf/nan in rate or drate_dT and no regressions in standard burn trajectories.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the *_approx helpers in networks/he-burn/ase/reaclib_rates.H and networks/he-burn/cno-he-burn-33a/reaclib_rates.H for denominator calculations using r_pg + r_pa. Review the rate and derivative expressions together, then add the proposed low-temperature/high-screening stress coverage. Done means no inf/nan in rate or drate_dT and no regressions in standard burn trajectories.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.