AMReX-Astro / AMReX-Astro/Castro

RadSolve::levelFluxFaceToCenter uses wrong neighbor metric indexing and wrong denominator for `idim==1`

Open
#3,208 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Location

Source/radiation/RadSolve.cpp:672, Source/radiation/RadSolve.cpp:678

Problem
  1. r_right is always computed from (i+1,j,k) regardless of direction (idim), which is incorrect for y/z fluxes.
  2. In the idim == 1 branch, both terms divide by r_left; the second should divide by r_right.
Impact
  • Incorrect geometry-weighted flux averaging in non-x directions.
  • Potential directional bias / numerical error in radiation updates.
Steps to Reproduce
  1. Run a spherical/cylindrical radiation case where y/z fluxes are significant.
  2. Compare against a corrected implementation or symmetry expectation.
  3. Observe discrepancies in flux-centered quantities.
Expected Behavior

Neighbor metrics should be computed in the active dimension, and each face term should use its corresponding metric.

Actual Behavior

Right-face metric indexing is hardcoded to x-neighbor; y-branch uses r_left for both terms.

Proposed Fix
int in = i, jn = j, kn = k;
if (idim == 0) ++in;
else if (idim == 1) ++jn;
else ++kn;

edge_center_metric(i, j, k, idim, geomdata, r_left, s_left);
edge_center_metric(in, jn, kn, idim, geomdata, r_right, s_right);

if (idim == 0) {
    t(i,j,k,it) = (f(i,j,k) / (r_left + 1.e-50_rt) + f(i+1,j,k) / r_right) * 0.5_rt;
} else if (idim == 1) {
    t(i,j,k,it) = (f(i,j,k) / r_left + f(i,j+1,k) / r_right) * 0.5_rt;
} else {
    t(i,j,k,it) = (f(i,j,k) + f(i,j,k+1)) * 0.5_rt;
}

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/radiation/RadSolve.cpp:672 and :678 in RadSolve::levelFluxFaceToCenter. Check the neighbor metric indexing for each idim and the denominators used by the y branch, then compare a spherical or cylindrical radiation case against symmetry expectations. Done means the active-direction metrics and corresponding face denominators are used without directional bias.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.