AMReX-Astro / AMReX-Astro/Castro
`advance_particles` mutates FillPatch density in-place across grown tiles, risking overlap corruption
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 340
- Forks
- 105
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 8
Description
Summary
Castro::advance_particles() inverts density in S[mfi] in-place over mfi.growntilebox(), then reuses S to compute velocities. With tiled iteration and ng > 0, grown tile regions can overlap, so cells in overlap are inverted multiple times (rho -> 1/rho -> rho ...), producing incorrect Ucc values.
Location
Source/particles/CastroParticles.cpp:267Source/particles/CastroParticles.cpp:270
Problem Details
Current code mutates shared FillPatch data per tile:
const Box& bx = mfi.growntilebox();
S[mfi].invert(1.0, bx, 0, 1);
for (int dir=0; dir < AMREX_SPACEDIM; ++dir) {
Ucc[mfi].copy(S[mfi], bx, dir+1, bx, dir, 1);
Ucc[mfi].mult(S[mfi], bx, 0, dir);
}
Because S[mfi] is reused across tiles, overlap makes the result order-dependent.
Impact
- Wrong particle advection velocities near tile boundaries when ghost grows are nonzero.
- Non-deterministic behavior under tiling/OpenMP depending on tile decomposition.
Suggested Patch
Compute Ucc = momentum / rho without mutating S:
diff --git a/Source/particles/CastroParticles.cpp b/Source/particles/CastroParticles.cpp
--- a/Source/particles/CastroParticles.cpp
+++ b/Source/particles/CastroParticles.cpp
@@
for (MFIter mfi(Ucc,true); mfi.isValid(); ++mfi)
{
const Box& bx = mfi.growntilebox();
- S[mfi].invert(1.0, bx, 0, 1);
for (int dir=0; dir < AMREX_SPACEDIM; ++dir) {
Ucc[mfi].copy(S[mfi], bx, dir+1, bx, dir, 1);
- Ucc[mfi].mult(S[mfi], bx, 0, dir);
+ Ucc[mfi].divide(S[mfi], bx, 0, dir, 1);
}
}
Prepared by Codex
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
Read Source/particles/CastroParticles.cpp around lines 267-270 and inspect how advance_particles uses S and Ucc during tiled iteration. Verify the fix avoids mutating shared FillPatch density over mfi.growntilebox() while preserving momentum-to-density velocity calculation across overlapping grown tiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- hpc
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100