Skip to content

Commit

Permalink
Fix InitRandomPerBox for 1D & 2D (#3527)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
ax3l committed Sep 1, 2023
1 parent 6d862f2 commit b7e8a26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions Src/Base/AMReX_RealBox.H
Expand Up @@ -8,6 +8,7 @@
#include <AMReX_REAL.H>
#include <AMReX_Box.H>
#include <AMReX_RealVect.H>
#include <AMReX_SPACE.H>

#include <iosfwd>
#include <array>
Expand Down
8 changes: 5 additions & 3 deletions Src/Particle/AMReX_ParticleInit.H
Expand Up @@ -1380,9 +1380,11 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
for (Long jcnt = 0; jcnt < icount_per_box; jcnt++) {
for (Long kcnt = 0; kcnt < icount_per_box; kcnt++)
{
p.pos(0) = static_cast<ParticleReal>(grid_box.lo(0) + (dist(mt) + double(icnt)) / double(icount_per_box) * grid_box.length(0));
p.pos(1) = static_cast<ParticleReal>(grid_box.lo(1) + (dist(mt) + double(jcnt)) / double(icount_per_box) * grid_box.length(1));
p.pos(2) = static_cast<ParticleReal>(grid_box.lo(2) + (dist(mt) + double(kcnt)) / double(icount_per_box) * grid_box.length(2));
AMREX_D_TERM(
p.pos(0) = static_cast<ParticleReal>(grid_box.lo(0) + (dist(mt) + double(icnt)) / double(icount_per_box) * grid_box.length(0));,
p.pos(1) = static_cast<ParticleReal>(grid_box.lo(1) + (dist(mt) + double(jcnt)) / double(icount_per_box) * grid_box.length(1));,
p.pos(2) = static_cast<ParticleReal>(grid_box.lo(2) + (dist(mt) + double(kcnt)) / double(icount_per_box) * grid_box.length(2));
);

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

0 comments on commit b7e8a26

Please sign in to comment.