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

Add overload for getParticleCell that returns local cell index #4081

Merged
merged 2 commits into from
Aug 16, 2024
Merged
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
41 changes: 39 additions & 2 deletions Src/Particle/AMReX_ParticleUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename P>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
IntVect getParticleCell (P const& p,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& plo,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& dxi,
const Box& domain) noexcept
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> 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 <typename P>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
IntVect getParticleCell (P const& p,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& plo,
amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& dxi,
const Box& domain) noexcept
{
IntVect iv = getParticleCell(p, plo, dxi);
iv += domain.smallEnd();
return iv;
}
Expand Down
Loading