AMReX-Astro / AMReX-Astro/Castro
construct_old_react_source() silently overwrites Sburn in the O4 averaged-input path
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 340
- Forks
- 105
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 8
Description
Summary
construct_old_react_source() takes U_state and R_source, but in the 4th-order averaged-input path it also writes centered reaction data into the class member Sburn. That side effect is not visible in the interface and makes the function unsafe to reuse without knowledge of internal scratch-state conventions.
Affected code
Problem
In the sdc_order == 4 && input_is_average branch, the function computes centered reaction rates and then stores them into Sburn:
Sburn[mfi].copy(R_center, obx, 0, obx, 0, NUM_STATE);
The function signature and header comment only advertise output through R_source, not through Sburn. That means the routine has a hidden dependency on mutable object state and a hidden output channel.
Why this matters
- A future caller can easily assume the function only fills
R_source. - Any code expecting
Sburnto still contain an initial guess or scratch state after the call can be broken implicitly. - The coupling makes the routine harder to reason about, test, or refactor.
Current risk
The current call sites appear to rely on or at least tolerate this behavior, so this may not be an immediate user-visible bug today. But it is a maintenance hazard and an easy source of future regressions.
Suggested fix
Choose one of these and make it explicit:
- Remove the side effect and return/store the centered reaction source through an explicit output argument.
- Rename the function or document clearly that it also populates
Sburn. - Split the responsibilities into two helpers:
- one that computes
R_source - one that optionally caches centered reaction data for plotting or later use
- one that computes
Possible acceptance criteria
- The public declaration/comment reflects every mutated output.
- No helper mutates
Sburnunless that is explicit in the API. - Existing SDC plotfile/reaction-source behavior remains unchanged after the refactor.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the declaration and header comment in Source/sdc/Castro_sdc.H, then inspect construct_old_react_source() at the two cited locations in Source/sdc/Castro_sdc.cpp. Trace its call sites and determine which explicit API or helper split preserves the existing SDC plotfile and reaction-source behavior. Done means mutated outputs are explicit and Sburn is not changed implicitly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- hpc
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100