Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Src/Extern/HDF5/AMReX_ParticleHDF5.H
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
++rptr;
}

locateParticle(ptemp, pld, 0, finestLevel(), 0);
locateParticle(ptemp, pld, 0, finestLevel(), IntVect::TheZeroVector());

std::pair<int, int> ind(grd, pld.m_tile);

Expand Down
21 changes: 15 additions & 6 deletions Src/Particle/AMReX_ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ public:
void Redistribute (int lev_min = 0, int lev_max = -1, int nGrow = 0, int local=0,
bool remove_negative=true);

void Redistribute (int lev_min, int lev_max, IntVect nGrow, int local=0,
bool remove_negative=true);


/**
* \brief Reorder particles on the tile given by lev and mfi using a the permutations array.
Expand Down Expand Up @@ -569,6 +572,8 @@ public:
*/
bool OK (int lev_min = 0, int lev_max = -1, int nGrow = 0) const;

bool OK (int lev_min, int lev_max, IntVect nGrow) const;

std::array<Long, 3> ByteSpread () const;

std::array<Long, 3> PrintCapacity () const;
Expand Down Expand Up @@ -646,6 +651,8 @@ public:
*/
void AddParticlesAtLevel (AoS& particles, int level, int nGrow=0);

void AddParticlesAtLevel (AoS& particles, int level, IntVect nGrow);

/**
* \brief Creates virtual particles for a given level that represent
* in some capacity all particles at finer levels
Expand Down Expand Up @@ -674,6 +681,8 @@ public:
*/
void AddParticlesAtLevel (ParticleTileType& particles, int level, int nGrow=0);

void AddParticlesAtLevel (ParticleTileType& particles, int level, IntVect nGrow);


/**
* \brief Clear all the particles in this container. This does not free memory.
Expand Down Expand Up @@ -1279,10 +1288,10 @@ public:
return doUnlink;
}

void RedistributeCPU (int lev_min = 0, int lev_max = -1, int nGrow = 0, int local=0,
void RedistributeCPU (int lev_min = 0, int lev_max = -1, IntVect nGrow = IntVect::TheZeroVector(), int local=0,
bool remove_negative=true);

void Redistribute_impl (int lev_min = 0, int lev_max = -1, int nGrow = 0, int local=0,
void Redistribute_impl (int lev_min = 0, int lev_max = -1, IntVect nGrow = IntVect::TheZeroVector(), int local=0,
bool remove_negative=true);

void ReserveForRedistribute (ParticleCopyPlan const& plan);
Expand Down Expand Up @@ -1455,7 +1464,7 @@ protected:
*/
template <typename P>
bool Where (const P& prt, ParticleLocData& pld,
int lev_min = 0, int lev_max = -1, int nGrow=0, int local_grid=-1) const;
int lev_min = 0, int lev_max = -1, IntVect nGrow=IntVect::TheZeroVector(), int local_grid=-1) const;


/**
Expand Down Expand Up @@ -1543,12 +1552,12 @@ private:
int /*grid*/, const ParticleType& /*p*/) {}

void RedistributeMPI (std::map<int, Vector<char> >& not_ours,
int lev_min = 0, int lev_max = 0, int nGrow = 0, int local=0);
int lev_min = 0, int lev_max = 0, IntVect nGrow = IntVect::TheZeroVector(), int local=0);

AMREX_FORCE_INLINE
int hostPartitionTile (ParticleTileType& src_tile,
int lev, int gid, int tid,
int lev_min, int lev_max, int nGrow, int local,
int lev_min, int lev_max, IntVect nGrow, int local,
bool remove_negative, int myproc,
Gpu::DeviceVector<int>& boxes,
Gpu::DeviceVector<int>& levels,
Expand All @@ -1558,7 +1567,7 @@ private:

template <typename P>
void locateParticle (P& p, ParticleLocData& pld,
int lev_min, int lev_max, int nGrow, int local_grid=-1) const;
int lev_min, int lev_max, IntVect nGrow, int local_grid=-1) const;

void Initialize ();

Expand Down
57 changes: 45 additions & 12 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
ParticleLocData& pld,
int lev_min,
int lev_max,
int nGrow,
IntVect nGrow,
int local_grid) const
{

Expand All @@ -230,7 +230,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig

AMREX_ASSERT(lev_max <= finestLevel());

AMREX_ASSERT(nGrow == 0 || (nGrow >= 0 && lev_min == lev_max));
AMREX_ASSERT(nGrow == IntVect::TheZeroVector() || (nGrow.min() >= 0 && lev_min == lev_max));

std::vector< std::pair<int, Box> > isects;

Expand All @@ -254,17 +254,15 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
AMREX_ASSERT(ba.ixType().cellCentered());

if (local_grid < 0) {
bool findfirst = (nGrow == 0) ? true : false;
bool findfirst = (nGrow == IntVect::TheZeroVector());
ba.intersections(Box(iv, iv), isects, findfirst, nGrow);
grid = isects.empty() ? -1 : isects[0].first;
if (nGrow > 0 && std::ssize(isects) > 1) {
if (!findfirst && std::ssize(isects) > 1) {
for (auto & isect : isects) {
Box bx = ba.getCellCenteredBox(isect.first);
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
Box gbx = bx;
IntVect gr(IntVect::TheZeroVector());
gr[dir] = nGrow;
gbx.grow(gr);
gbx.grow(dir, nGrow[dir]);
if (gbx.contains(iv)) {
grid = isect.first;
}
Expand Down Expand Up @@ -445,7 +443,7 @@ template <typename ParticleType, int NArrayReal, int NArrayInt,
template <typename P>
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::locateParticle (P& p, ParticleLocData& pld,
int lev_min, int lev_max, int nGrow, int local_grid) const
int lev_min, int lev_max, IntVect nGrow, int local_grid) const
{
bool success;
if (Geom(0).outsideRoundoffDomain(AMREX_D_DECL(p.pos(0), p.pos(1), p.pos(2))))
Expand All @@ -461,12 +459,12 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
}
else
{
success = Where(p, pld, lev_min, lev_max, 0, local_grid);
success = Where(p, pld, lev_min, lev_max, IntVect::TheZeroVector(), local_grid);
}

if (!success)
{
success = (nGrow > 0) && Where(p, pld, lev_min, lev_min, nGrow);
success = (nGrow != IntVect::TheZeroVector()) && Where(p, pld, lev_min, lev_min, nGrow);
pld.m_grown_gridbox = pld.m_gridbox; // reset grown box for subsequent calls.
}

Expand Down Expand Up @@ -1237,6 +1235,15 @@ template <typename ParticleType, int NArrayReal, int NArrayInt,
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::Redistribute (int lev_min, int lev_max, int nGrow, int local, bool remove_negative)
{
Redistribute(lev_min, lev_max, IntVect(nGrow), local, remove_negative);
}

template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::Redistribute (int lev_min, int lev_max, IntVect nGrow, int local, bool remove_negative)
{
BL_PROFILE_SYNC_START_TIMED("SyncBeforeComms: Redist");

Expand Down Expand Up @@ -1353,7 +1360,7 @@ int
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::hostPartitionTile (ParticleTileType& src_tile,
int lev, int gid, int tid,
int lev_min, int lev_max, int nGrow, int local,
int lev_min, int lev_max, IntVect nGrow, int local,
bool remove_negative, int myproc,
Gpu::DeviceVector<int>& boxes,
Gpu::DeviceVector<int>& levels,
Expand Down Expand Up @@ -1440,7 +1447,7 @@ template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::Redistribute_impl (int lev_min, int lev_max, int nGrow, int local, bool remove_negative)
::Redistribute_impl (int lev_min, int lev_max, IntVect nGrow, int local, bool remove_negative)
{
if (local) { AMREX_ASSERT(numParticlesOutOfRange(*this, lev_min, lev_max, local) == 0); }

Expand Down Expand Up @@ -1784,6 +1791,14 @@ template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
bool
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::OK (int lev_min, int lev_max, int nGrow) const
{
return OK(lev_min, lev_max, IntVect(nGrow));
}

template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
bool
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::OK (int lev_min, int lev_max, IntVect nGrow) const
{
BL_PROFILE("ParticleContainer::OK()");

Expand All @@ -1799,6 +1814,15 @@ template <typename ParticleType, int NArrayReal, int NArrayInt,
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::AddParticlesAtLevel (AoS& particles, int level, int nGrow)
{
AddParticlesAtLevel(particles, level, IntVect(nGrow));
}

template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::AddParticlesAtLevel (AoS& particles, int level, IntVect nGrow)
{
ParticleTileType ptile;
ptile.GetArrayOfStructs().swap(particles);
Expand All @@ -1810,6 +1834,15 @@ template <typename ParticleType, int NArrayReal, int NArrayInt,
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::AddParticlesAtLevel (ParticleTileType& particles, int level, int nGrow)
{
AddParticlesAtLevel(particles, level, IntVect(nGrow));
}

template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
::AddParticlesAtLevel (ParticleTileType& particles, int level, IntVect nGrow)
{
BL_PROFILE("ParticleContainer::AddParticlesAtLevel()");

Expand Down
2 changes: 1 addition & 1 deletion Src/Particle/AMReX_ParticleIO.H
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
++rptr;
}

locateParticle(ptemp, pld, 0, finestLevel(), 0);
locateParticle(ptemp, pld, 0, finestLevel(), IntVect::TheZeroVector());

std::pair<int, int> ind(grd, pld.m_tile);

Expand Down
23 changes: 12 additions & 11 deletions Src/Particle/AMReX_ParticleLocator.H
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ struct AssignGrid

template <typename P, typename Assignor = DefaultAssignor>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
std::pair<int, int> operator() (const P& p, int nGrow=0, Assignor const& assignor = Assignor{}) const noexcept
std::pair<int, int> operator() (const P& p, IntVect nGrow=IntVect::TheZeroVector(), Assignor const& assignor = Assignor{}) const noexcept
{
const auto iv = assignor(p, m_plo, m_dxi, m_domain);
return this->operator()(iv, nGrow);
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
std::pair<int, int> operator() (const IntVect& iv, int nGrow=0) const noexcept
std::pair<int, int> operator() (const IntVect& iv, IntVect nGrow=IntVect::TheZeroVector()) const noexcept
{
if (AMREX_D_TERM((m_num_bins.x == 0), && (m_num_bins.y == 0), && (m_num_bins.z == 0))) {
return {-1, -1};
}
const auto lo = iv.dim3();
int ix_lo = amrex::max((lo.x - nGrow - m_lo.x) / m_bin_size.x - 1, 0);
int iy_lo = amrex::max((lo.y - nGrow - m_lo.y) / m_bin_size.y - 1, 0);
int iz_lo = amrex::max((lo.z - nGrow - m_lo.z) / m_bin_size.z - 1, 0);
int ix_lo = amrex::max((lo.x - nGrow[0] - m_lo.x) / m_bin_size.x - 1, 0);
int iy_lo = amrex::max((lo.y - nGrow[1] - m_lo.y) / m_bin_size.y - 1, 0);
int iz_lo = amrex::max((lo.z - nGrow[2] - m_lo.z) / m_bin_size.z - 1, 0);

int ix_hi = amrex::min((lo.x + nGrow - m_lo.x) / m_bin_size.x, m_num_bins.x-1);
int iy_hi = amrex::min((lo.y + nGrow - m_lo.y) / m_bin_size.y, m_num_bins.y-1);
int iz_hi = amrex::min((lo.z + nGrow - m_lo.z) / m_bin_size.z, m_num_bins.z-1);
int ix_hi = amrex::min((lo.x + nGrow[0] - m_lo.x) / m_bin_size.x, m_num_bins.x-1);
int iy_hi = amrex::min((lo.y + nGrow[1] - m_lo.y) / m_bin_size.y, m_num_bins.y-1);
int iz_hi = amrex::min((lo.z + nGrow[2] - m_lo.z) / m_bin_size.z, m_num_bins.z-1);
int loc_gid = -1;
int loc_tid = -1;
for (int kk = iz_lo; kk <= iz_hi; ++kk) {
Expand All @@ -103,7 +103,7 @@ struct AssignGrid
// Prefer particle not in corner ghost cells
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
Box gdbx = bx;
gdbx.grow(dir, nGrow);
gdbx.grow(dir, nGrow[dir]);
if (gdbx.contains(iv)) {
loc_gid = nbor.first;
loc_tid = tile;
Expand Down Expand Up @@ -255,15 +255,16 @@ struct AmrAssignGrid

template <typename P, typename Assignor = DefaultAssignor>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
GpuTuple<int, int, int> operator() (const P& p, int lev_min=-1, int lev_max=-1, int nGrow=0,
GpuTuple<int, int, int> operator() (const P& p, int lev_min=-1, int lev_max=-1,
IntVect nGrow=IntVect::TheZeroVector(),
Assignor const& assignor = {}) const noexcept
{
lev_min = (lev_min == -1) ? 0 : lev_min;
lev_max = (lev_max == -1) ? m_size - 1 : lev_max;

for (int lev = lev_max; lev >= lev_min; --lev)
{
auto grid_tile = m_funcs[lev](p, 0, assignor);
auto grid_tile = m_funcs[lev](p, IntVect::TheZeroVector(), assignor);
if (grid_tile.first >= 0) { return makeTuple(grid_tile.first, grid_tile.second, lev); }
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Particle/AMReX_ParticleUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ partitionParticlesByDest (PTile& ptile, const PLocator& ploc, CellAssignor const
const GpuArray<ParticleReal,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)
int lev_min, int lev_max, IntVect nGrow, bool remove_negative)
{
auto getPID = pmap.getPIDFunctor();
int pid = ParallelContext::MyProcSub();
Expand Down
Loading