AMReX-Astro / AMReX-Astro/Microphysics

util/hybrj: NaN/Inf handling in enorm can cause false convergence

Open
#1,960 0 comments 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

Summary

enorm() returns 0.0 when any input component is NaN or Inf. In hybrj, fnorm == 0.0 is treated as successful convergence (info = 1). This can incorrectly classify invalid numerical states as converged solves.
 

Affected code

  • util/hybrj/hybrj_enorm.H: early return 0.0_rt for isnan/isinf
  • util/hybrj/hybrj.H: convergence check uses fnorm == 0.0_rt
     

Why this is a problem

A true zero norm and an invalid norm are semantically different. Folding both into 0.0 hides instability and can produce misleading solver status.
 

Expected behavior

Invalid numerical values should lead to a non-converged / invalid-state path, not a successful-convergence code path.
 

Suggested fix

  • Return NaN from enorm() for invalid inputs, or
  • Add an explicit validity flag / status propagation, and
  • Guard convergence checks against NaN/Inf before accepting fnorm == 0.
     

Acceptance criteria

  • Invalid residual entries no longer produce info = 1.
  • Solver reports a deterministic failure/invalid status for NaN/Inf paths.

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

Start by reading the early invalid-value return in util/hybrj/hybrj_enorm.H and the fnorm convergence check in util/hybrj/hybrj.H. Trace how NaN/Inf residuals reach info = 1, then ensure invalid values take a deterministic non-converged or invalid path while true zero norms still converge.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.