Skip to content

Commit

Permalink
Fix periodic boundary bug in AMReX-Codes#3199 (AMReX-Codes#3243)
Browse files Browse the repository at this point in the history
PR AMReX-Codes#3199 broke the Nyx regression tests. The issue is we require the
particle positions to be in [plo, phi). This won't happen if rhi is
exactly equal to phi. The fix is to make sure rhi is always slightly
inside the domain.

EDIT - fixed this in a different way. Now, when applying periodic
boundaries, the particle positions will be set to be strictly less than
rhi.
  • Loading branch information
atmyers authored and guj committed Jul 13, 2023
1 parent 8ee4a49 commit 06be4d3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Src/Particle/AMReX_ParticleUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ bool enforcePeriodic (P& p,
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
{
if (! is_per[idim]) continue;
if (p.pos(idim) >= phi[idim]) {
while (p.pos(idim) >= phi[idim]) {
if (p.pos(idim) >= rhi[idim]) {
while (p.pos(idim) >= rhi[idim]) {
p.pos(idim) -= static_cast<ParticleReal>(phi[idim] - plo[idim]);
}
// clamp to avoid precision issues;
Expand All @@ -579,13 +579,13 @@ bool enforcePeriodic (P& p,
}
shifted = true;
}
else if (p.pos(idim) < plo[idim]) {
while (p.pos(idim) < plo[idim]) {
else if (p.pos(idim) < rlo[idim]) {
while (p.pos(idim) < rlo[idim]) {
p.pos(idim) += static_cast<ParticleReal>(phi[idim] - plo[idim]);
}
// clamp to avoid precision issues;
if (p.pos(idim) > rhi[idim]) {
p.pos(idim) = rhi[idim];
if (p.pos(idim) >= rhi[idim]) {
p.pos(idim) = std::nextafter(p.pos(idim), rlo[idim]);
}
shifted = true;
}
Expand Down

0 comments on commit 06be4d3

Please sign in to comment.