AMReX-Astro / AMReX-Astro/Castro

Stopping criterion reduction initializes with `numeric_limits::min()` instead of `lowest()`

Open
#3,244 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit bug :bug:
Dominant language
C++
Stars
340
Forks
105
Avg merge
3d 8h
Merged PRs (30d)
8

Description

Summary

Castro::post_timestep initializes max_field_val with std::numeric_limits<Real>::min(), which is the smallest positive normalized value, not the most negative value. For fields that can be negative, this biases the maximum reduction and can trigger incorrect stop decisions.

Location

  • Source/driver/Castro.cpp:2133

Problem Details

Current code:

Real max_field_val = std::numeric_limits<Real>::min();

For a max reduction, the correct identity should be the lowest representable value:

std::numeric_limits<Real>::lowest()

Impact

  • Incorrect stopping behavior when stopping_criterion_field can be negative.
  • Possible false positives if stopping_criterion_value is negative and all field values are below threshold.

Suggested Patch

diff --git a/Source/driver/Castro.cpp b/Source/driver/Castro.cpp
--- a/Source/driver/Castro.cpp
+++ b/Source/driver/Castro.cpp
@@
-        Real max_field_val = std::numeric_limits<Real>::min();
+        Real max_field_val = std::numeric_limits<Real>::lowest();

Prepared by Codex

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 at Source/driver/Castro.cpp:2133 in Castro::post_timestep and inspect how max_field_val is used for the stopping-criterion reduction. Verify the initialization uses the correct lowest representable Real value, then check the stopping behavior for negative field values and thresholds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.