Skip to content

Commit b7e8a26

Browse files
authored
Fix InitRandomPerBox for 1D & 2D (#3527)
## Summary Fixing an array bounds violation for `RealBox` in <3D for `InitRandomPerBox`. RealBox: SPACE include added for nD macros used within it. ## Additional background Seen in pyAMReX 1D and 2D builds. ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate
1 parent 6d862f2 commit b7e8a26

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Src/Base/AMReX_RealBox.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <AMReX_REAL.H>
99
#include <AMReX_Box.H>
1010
#include <AMReX_RealVect.H>
11+
#include <AMReX_SPACE.H>
1112

1213
#include <iosfwd>
1314
#include <array>

Src/Particle/AMReX_ParticleInit.H

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,11 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
13801380
for (Long jcnt = 0; jcnt < icount_per_box; jcnt++) {
13811381
for (Long kcnt = 0; kcnt < icount_per_box; kcnt++)
13821382
{
1383-
p.pos(0) = static_cast<ParticleReal>(grid_box.lo(0) + (dist(mt) + double(icnt)) / double(icount_per_box) * grid_box.length(0));
1384-
p.pos(1) = static_cast<ParticleReal>(grid_box.lo(1) + (dist(mt) + double(jcnt)) / double(icount_per_box) * grid_box.length(1));
1385-
p.pos(2) = static_cast<ParticleReal>(grid_box.lo(2) + (dist(mt) + double(kcnt)) / double(icount_per_box) * grid_box.length(2));
1383+
AMREX_D_TERM(
1384+
p.pos(0) = static_cast<ParticleReal>(grid_box.lo(0) + (dist(mt) + double(icnt)) / double(icount_per_box) * grid_box.length(0));,
1385+
p.pos(1) = static_cast<ParticleReal>(grid_box.lo(1) + (dist(mt) + double(jcnt)) / double(icount_per_box) * grid_box.length(1));,
1386+
p.pos(2) = static_cast<ParticleReal>(grid_box.lo(2) + (dist(mt) + double(kcnt)) / double(icount_per_box) * grid_box.length(2));
1387+
);
13861388

13871389
for (int i = 0; i < AMREX_SPACEDIM; i++) {
13881390
AMREX_ASSERT(p.pos(i) < grid_box.hi(i));

0 commit comments

Comments
 (0)