Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the roundoff domain in enforcePeriodic. #2679

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Src/Base/AMReX_Geometry.H
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ public:
return {{AMREX_D_DECL(prob_domain.hi(0),prob_domain.hi(1),prob_domain.hi(2))}};
}

GpuArray<Real,AMREX_SPACEDIM> RoundoffLoArray () const noexcept {
return {{AMREX_D_DECL(roundoff_domain.lo(0),roundoff_domain.lo(1),roundoff_domain.lo(2))}};
}

GpuArray<Real,AMREX_SPACEDIM> RoundoffHiArray () const noexcept {
return {{AMREX_D_DECL(roundoff_domain.hi(0),roundoff_domain.hi(1),roundoff_domain.hi(2))}};
}

//! Returns the overall size of the domain by multiplying the ProbLength's together
Real ProbSize () const noexcept
{
Expand Down
6 changes: 4 additions & 2 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
const auto& geom = Geom(0);
const auto plo = geom.ProbLoArray();
const auto phi = geom.ProbHiArray();
const auto rhi = geom.RoundoffHiArray();
const auto is_per = geom.isPeriodicArray();

return enforcePeriodic(p, plo, phi, is_per);
return enforcePeriodic(p, plo, phi, rhi, is_per);
}

template <int NStructReal, int NStructInt, int NArrayReal, int NArrayInt,
Expand Down Expand Up @@ -1211,6 +1212,7 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
Vector<std::map<int, int> > new_sizes(num_levels);
const auto plo = Geom(0).ProbLoArray();
const auto phi = Geom(0).ProbHiArray();
const auto rhi = Geom(0).RoundoffHiArray();
const auto is_per = Geom(0).isPeriodicArray();
for (int lev = lev_min; lev <= finest_lev_particles; ++lev)
{
Expand All @@ -1231,7 +1233,7 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
"perhaps particles have not been initialized correctly?");

int num_stay = partitionParticlesByDest(src_tile, assign_grid, BufferMap(),
plo, phi, is_per, lev, gid, tid,
plo, phi, rhi, is_per, lev, gid, tid,
lev_min, lev_max, nGrow, remove_negative);

int num_move = np - num_stay;
Expand Down
9 changes: 6 additions & 3 deletions Src/Particle/AMReX_ParticleUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool enforcePeriodic (P& p,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& plo,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& phi,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& rhi,
amrex::GpuArray<int,AMREX_SPACEDIM> const& is_per) noexcept
{
bool shifted = false;
Expand All @@ -500,8 +501,9 @@ bool enforcePeriodic (P& p,
p.pos(idim) += static_cast<ParticleReal>(phi[idim] - plo[idim]);
}
// clamp to avoid precision issues;
if (p.pos(idim) == phi[idim]) p.pos(idim) = static_cast<ParticleReal>(plo[idim]);
if (p.pos(idim) > phi[idim]) p.pos(idim) = std::nextafter( (amrex::ParticleReal) phi[idim], (amrex::ParticleReal) plo[idim]);
if (p.pos(idim) >= rhi[idim]) {
p.pos(idim) = static_cast<ParticleReal>(plo[idim]);
}
shifted = true;
}
AMREX_ASSERT( (p.pos(idim) >= plo[idim] ) && ( p.pos(idim) < phi[idim] ));
Expand All @@ -517,6 +519,7 @@ int
partitionParticlesByDest (PTile& ptile, const PLocator& ploc, const ParticleBufferMap& pmap,
const GpuArray<Real,AMREX_SPACEDIM>& plo,
const GpuArray<Real,AMREX_SPACEDIM>& phi,
const GpuArray<Real,AMREX_SPACEDIM>& rhi,
const GpuArray<int ,AMREX_SPACEDIM>& is_per,
int lev, int gid, int /*tid*/,
int lev_min, int lev_max, int nGrow, bool remove_negative)
Expand Down Expand Up @@ -563,7 +566,7 @@ partitionParticlesByDest (PTile& ptile, const PLocator& ploc, const ParticleBuff
else
{
auto p_prime = p;
enforcePeriodic(p_prime, plo, phi, is_per);
enforcePeriodic(p_prime, plo, phi, rhi, is_per);
auto tup_prime = ploc(p_prime, lev_min, lev_max, nGrow);
assigned_grid = amrex::get<0>(tup_prime);
assigned_lev = amrex::get<1>(tup_prime);
Expand Down