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

Combine two functions for periodically shifting particles into one and re-use #1152

Merged
merged 2 commits into from
Jul 18, 2020
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
36 changes: 5 additions & 31 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -219,38 +219,12 @@ bool
ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
::PeriodicShift (ParticleType& p) const
{
AMREX_ASSERT(m_gdb != 0);

const Geometry& geom = Geom(0);
const Box& dmn = geom.Domain();
const IntVect& iv = Index(p, 0);
bool shifted = false;

for (int i = 0; i < AMREX_SPACEDIM; i++)
{
if (!geom.isPeriodic(i)) continue;

if (iv[i] > dmn.bigEnd(i))
{
while (p.pos(i) >= (typename ParticleType::RealType) geom.ProbHi(i)) p.pos(i) -= (typename ParticleType::RealType) geom.ProbLength(i);
if (p.pos(i) < (typename ParticleType::RealType) geom.ProbLo(i)) p.pos(i) = (typename ParticleType::RealType) geom.ProbLo(i); // clamp to avoid precision issues;
shifted = true;
}
else if (iv[i] < dmn.smallEnd(i))
{
while (p.pos(i) < (typename ParticleType::RealType) geom.ProbLo(i)) p.pos(i) += (typename ParticleType::RealType) geom.ProbLength(i);

// clamp to avoid precision issues
if ( p.pos(i) == (typename ParticleType::RealType) geom.ProbHi(i)) p.pos(i) = (typename ParticleType::RealType) geom.ProbLo(i);
if ((p.pos(i) > (typename ParticleType::RealType) geom.ProbHi(i)))
p.pos(i) = (typename ParticleType::RealType) geom.ProbHi(i) - std::numeric_limits<typename ParticleType::RealType>::epsilon();

shifted = true;
}
AMREX_ASSERT( (p.pos(i) >= (typename ParticleType::RealType) geom.ProbLo(i) ) and ( p.pos(i) < (typename ParticleType::RealType) geom.ProbHi(i) ));
}
const auto& geom = Geom(0);
const auto plo = geom.ProbLoArray();
const auto phi = geom.ProbHiArray();
const auto is_per = geom.isPeriodicArray();

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

template <int NStructReal, int NStructInt, int NArrayReal, int NArrayInt>
Expand Down
8 changes: 7 additions & 1 deletion Src/Particle/AMReX_ParticleUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ int getParticleGrid (P const& p, amrex::Array4<int> const& mask,

template <typename P>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void enforcePeriodic (P& p,
bool enforcePeriodic (P& p,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& plo,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& phi,
amrex::GpuArray<int,AMREX_SPACEDIM> const& is_per) noexcept
{
bool shifted = false;
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
{
if (not is_per[idim]) continue;
Expand All @@ -214,6 +215,7 @@ void enforcePeriodic (P& p,
}
// clamp to avoid precision issues;
if (p.pos(idim) < plo[idim]) p.pos(idim) = plo[idim];
shifted = true;
}
else if (p.pos(idim) < plo[idim]) {
while (p.pos(idim) < plo[idim]) {
Expand All @@ -222,8 +224,12 @@ void enforcePeriodic (P& p,
// clamp to avoid precision issues;
if (p.pos(idim) == phi[idim]) p.pos(idim) = plo[idim];
if (p.pos(idim) > phi[idim]) p.pos(idim) = std::nextafter( (amrex::ParticleReal) phi[idim], (amrex::ParticleReal) plo[idim]);
shifted = true;
}
AMREX_ASSERT( (p.pos(idim) >= plo[idim] ) and ( p.pos(idim) < phi[idim] ));
}
Copy link
Contributor

@jmsexton03 jmsexton03 Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion from PeriodicShift in terms of enforce_periodic should be:
AMREX_ASSERT( (p.pos(idim) >= plo[idim] ) and ( p.pos(idim) < phi[idim] ));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this back in.


return shifted;
}

#if defined(AMREX_USE_GPU)
Expand Down