diff options
Diffstat (limited to 'Source/Particles/PhysicalParticleContainer.cpp')
-rw-r--r-- | Source/Particles/PhysicalParticleContainer.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 4bc0ee16e..9681f3682 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1752,7 +1752,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real for (int lev = 0; lev < nlevs; ++lev) { - const Real* dx = Geom(lev).CellSize(); + const Real* dx = Geom(lev).CellSize(); const Real* plo = Geom(lev).ProbLo(); // first we touch each map entry in serial @@ -1770,6 +1770,8 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { + int counter_for_ParticleCopy = 0; + const Box& box = pti.validbox(); auto index = std::make_pair(pti.index(), pti.LocalTileIndex()); @@ -1800,13 +1802,37 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real Real uzfrm = -WarpX::gamma_boost*WarpX::beta_boost*PhysConst::c; Real inv_c2 = 1.0/PhysConst::c/PhysConst::c; +#ifdef AMREX_USE_GPU + amrex::Gpu::DeviceVector<int> FlagForPartCopy(np); + amrex::Gpu::DeviceVector<int> IndexForPartCopy(np); + +// amrex parallel for to flag particles that need to be copied + amrex::ParallelFor(np, + [=] AMREX_GPU_DEVICE(int i) noexcept + { + FlagForPartCopy[i] = 0; + if ( not (((zp_new[i] >= z_new) && (zp_old[i] <= z_old)) || + ((zp_new[i] <= z_new) && (zp_old[i] >= z_old))) ) + { + FlagForPartCopy[i] = 1; + } + }); +// exclusive scan to obtain location indices in the dst array + amrex::Gpu::exclusive_scan(FlagForPartCopy,FlagForPartCopy+np,IndexForPartCopy); +// Finally copy on the GPU + +#endif + + for (long i = 0; i < np; ++i) { // if the particle did not cross the plane of z_boost in the last // timestep, skip it. + if ( not (((zp_new[i] >= z_new) && (zp_old[i] <= z_old)) || ((zp_new[i] <= z_new) && (zp_old[i] >= z_old))) ) continue; - + + // Lorentz transform particles to lab frame Real gamma_new_p = std::sqrt(1.0 + inv_c2*(uxp_new[i]*uxp_new[i] + uyp_new[i]*uyp_new[i] + uzp_new[i]*uzp_new[i])); Real t_new_p = WarpX::gamma_boost*t_boost - uzfrm*zp_new[i]*inv_c2; @@ -1829,7 +1855,9 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real Real uxp = uxp_old[i]*weight_old + uxp_new[i]*weight_new; Real uyp = uyp_old[i]*weight_old + uyp_new[i]*weight_new; Real uzp = uz_old_p *weight_old + uz_new_p *weight_new; + + ++counter_for_ParticleCopy; diagnostic_particles[lev][index].GetRealData(DiagIdx::w).push_back(wp[i]); diagnostic_particles[lev][index].GetRealData(DiagIdx::x).push_back(xp); @@ -1840,6 +1868,10 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real diagnostic_particles[lev][index].GetRealData(DiagIdx::uy).push_back(uyp); diagnostic_particles[lev][index].GetRealData(DiagIdx::uz).push_back(uzp); } + if (counter_for_ParticleCopy > 0) + { + amrex::Print() << " counter index " << counter_for_ParticleCopy << "\n"; + } } } } |