AMReX-Astro / AMReX-Astro/Castro

True SDC O4 normalizes species before enforcing positive cell-centered density

Open
#3,385 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

In the 4th-order true SDC path, Castro converts cell averages to cell centers and immediately normalizes species on the centered state before enforcing a positive density. Near sharp gradients, the average-to-center conversion can produce negative or very small centered densities, so the species normalization step can generate invalid partial densities or NaNs before the later burn guards run.

Affected code

Problem

normalize_species_sdc() assumes u(i,j,k,URHO) is valid and positive. It clamps each rho X_k against small_x * rho and then rescales by rho / sum(rho X_k).

That is unsafe immediately after make_cell_center(...), because Castro already recognizes elsewhere that the average-to-center conversion can make rho < 0 near steep gradients. The main computeTemp() path explicitly enforces minimum density after the same conversion before continuing thermodynamics work, but the SDC path does not.

Why this matters

  • Negative centered density can make the clamp bounds nonsensical.
  • Very small or negative rho_xn_sum can lead to large rescaling or NaNs.
  • This happens before okay_to_burn() gets a chance to reject the zone, so the state can already be corrupted.

Likely impact

  • Corrupted species in the O4 true SDC reaction update.
  • Spurious failures or NaNs in difficult zones near discontinuities.
  • Potentially non-reproducible behavior because this depends on local reconstructed centered states.

Suggested fix

Before calling normalize_species_sdc() on a centered state, enforce a positive density first, or fold a density floor into normalize_species_sdc() itself.

At minimum, the following two paths should be protected:

  • The O4 update path after make_cell_center(...) on Sborder
  • construct_old_react_source() when sdc_order == 4 && input_is_average

Possible acceptance criteria

  • Add a regression test or problem setup with a steep interface that exercises the O4 true SDC path.
  • Verify no NaNs appear in the centered state after normalization.
  • Verify species remain bounded and sum to density after the fix.

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 in Source/sdc/Castro_sdc.cpp at the listed make_cell_center and normalize_species_sdc call sites, then read Source/sdc/Castro_sdc_util.H and the density handling in Source/driver/Castro.cpp. Trace both the O4 Sborder update and construct_old_react_source() path for input_is_average, and add or run a steep-interface regression setup. Done means centered density is protected before normalization, no NaNs appear, and species remain bounded while summing to density.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.