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

Preserve neighbor particles when sorting particles. #2923

Merged
merged 3 commits into from
Aug 24, 2022
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
32 changes: 18 additions & 14 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,11 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>::So

for(MFIter mfi = MakeMFIter(lev); mfi.isValid(); ++mfi)
{
auto& ptile = ParticlesAt(lev, mfi);
auto& aos = ptile.GetArrayOfStructs();
const size_t np = aos.numParticles();
auto pstruct_ptr = aos().dataPtr();
auto& ptile = ParticlesAt(lev, mfi);
auto& aos = ptile.GetArrayOfStructs();
auto pstruct_ptr = aos().dataPtr();
const size_t np = aos.numParticles();
const size_t np_total = np + aos.numNeighborParticles();

const Box& box = mfi.validbox();

Expand All @@ -1131,40 +1132,40 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>::So

if (memEfficientSort) {
{
ParticleVector tmp_particles(np);
ParticleVector tmp_particles(np_total);
auto src = ptile.getParticleTileData();
ParticleType* dst = tmp_particles.data();

AMREX_HOST_DEVICE_FOR_1D( np, i,
AMREX_HOST_DEVICE_FOR_1D( np_total, i,
{
dst[i] = src.m_aos[inds[i]];
dst[i] = i < np ? src.m_aos[inds[i]] : src.m_aos[i];
});

Gpu::streamSynchronize();
ptile.GetArrayOfStructs()().swap(tmp_particles);
}

RealVector tmp_real(np);
RealVector tmp_real(np_total);
for (int comp = 0; comp < NArrayReal + m_num_runtime_real; ++comp) {
auto src = ptile.GetStructOfArrays().GetRealData(comp).data();
ParticleReal* dst = tmp_real.data();
AMREX_HOST_DEVICE_FOR_1D( np, i,
AMREX_HOST_DEVICE_FOR_1D( np_total, i,
{
dst[i] = src[inds[i]];
dst[i] = i < np ? src[inds[i]] : src[i];
});

Gpu::streamSynchronize();

ptile.GetStructOfArrays().GetRealData(comp).swap(tmp_real);
}

IntVector tmp_int(np);
IntVector tmp_int(np_total);
for (int comp = 0; comp < NArrayInt + m_num_runtime_int; ++comp) {
auto src = ptile.GetStructOfArrays().GetIntData(comp).data();
int* dst = tmp_int.data();
AMREX_HOST_DEVICE_FOR_1D( np, i,
AMREX_HOST_DEVICE_FOR_1D( np_total , i,
{
dst[i] = src[inds[i]];
dst[i] = i < np ? src[inds[i]] : src[i];
});

Gpu::streamSynchronize();
Expand All @@ -1174,8 +1175,11 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>::So
} else {
ParticleTileType ptile_tmp;
ptile_tmp.define(m_num_runtime_real, m_num_runtime_int);
ptile_tmp.resize(np);
ptile_tmp.resize(np_total);
// copy re-ordered particles
gatherParticles(ptile_tmp, ptile, np, m_bins.permutationPtr());
// copy neighbor particles
amrex::copyParticles(ptile_tmp, ptile, np, np, np_total-np);
ptile.swap(ptile_tmp);
}
}
Expand Down