diff --git a/Src/Particle/AMReX_ParticleUtil.H b/Src/Particle/AMReX_ParticleUtil.H index 6b31db7e99..b09f1d3583 100644 --- a/Src/Particle/AMReX_ParticleUtil.H +++ b/Src/Particle/AMReX_ParticleUtil.H @@ -356,17 +356,54 @@ struct GetParticleBin } }; +/** + * \brief Returns the cell index for a given particle using the + * provided lower bounds and cell sizes. + * + * This version indexes cells starting from 0 at the lower left corner of + * the provided lower bounds, i.e., it returns a local index. + * + * \tparam P a type of AMReX particle. + * + * \param p the particle for which the cell index is calculated + * \param plo the low end of the domain + * \param dxi cell sizes in each dimension + */ template AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE IntVect getParticleCell (P const& p, amrex::GpuArray const& plo, - amrex::GpuArray const& dxi, - const Box& domain) noexcept + amrex::GpuArray const& dxi) noexcept { IntVect iv( AMREX_D_DECL(int(amrex::Math::floor((p.pos(0)-plo[0])*dxi[0])), int(amrex::Math::floor((p.pos(1)-plo[1])*dxi[1])), int(amrex::Math::floor((p.pos(2)-plo[2])*dxi[2])))); + return iv; +} + +/** + * \brief Returns the cell index for a given particle using the + * provided lower bounds, cell sizes and global domain offset. + * + * This version indexes cells starting from 0 at the lower left corner of + * the simulation geometry, i.e., it returns a global index. + * + * \tparam P a type of AMReX particle. + * + * \param p the particle for which the cell index is calculated + * \param plo the low end of the domain + * \param dxi cell sizes in each dimension + * \param domain AMReX box in which the given particle resides + */ +template +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +IntVect getParticleCell (P const& p, + amrex::GpuArray const& plo, + amrex::GpuArray const& dxi, + const Box& domain) noexcept +{ + IntVect iv = getParticleCell(p, plo, dxi); iv += domain.smallEnd(); return iv; }