diff --git a/src/archetypes/moving_window.h b/src/archetypes/moving_window.h index b8dc74fa2..3b9faca6f 100644 --- a/src/archetypes/moving_window.h +++ b/src/archetypes/moving_window.h @@ -134,6 +134,54 @@ namespace arch { } }; +#if defined(MPI_ENABLED) + /** + * @brief Assigns MPI send tags from the particle cell indices. + * @note Particles outside the active domain get the tag of the neighbor they belong to. + */ + template + struct PrtlRetag_kernel { + array_t i1, i2, i3; + array_t tag; + const int ni1, ni2, ni3; + + PrtlRetag_kernel(const array_t& i1, + const array_t& i2, + const array_t& i3, + const array_t& tag, + int ni1, + int ni2, + int ni3) + : i1 { i1 } + , i2 { i2 } + , i3 { i3 } + , tag { tag } + , ni1 { ni1 } + , ni2 { ni2 } + , ni3 { ni3 } {} + + Inline void operator()(prtlidx_t p) const { + if constexpr (D == Dim::_1D) { + tag(p) = mpi::SendTag(tag(p), i1(p) < 0, i1(p) >= ni1); + } else if constexpr (D == Dim::_2D) { + tag(p) = mpi::SendTag(tag(p), + i1(p) < 0, + i1(p) >= ni1, + i2(p) < 0, + i2(p) >= ni2); + } else if constexpr (D == Dim::_3D) { + tag(p) = mpi::SendTag(tag(p), + i1(p) < 0, + i1(p) >= ni1, + i2(p) < 0, + i2(p) >= ni2, + i3(p) < 0, + i3(p) >= ni3); + } + } + }; +#endif // MPI_ENABLED + /** * @brief Updates particle position and fields in the moving window. @@ -213,32 +261,15 @@ namespace arch { : 0; for (auto s { 0u }; s < nspec; ++s) { auto& species = domain.species[s]; - auto i1 = species.i1; - auto i2 = species.i2; - auto i3 = species.i3; - auto tag = species.tag; - Kokkos::parallel_for( - "RetagWindowParticles", - species.rangeActiveParticles(), - Lambda(prtlidx_t p) { - if constexpr (M::Dim == Dim::_1D) { - tag(p) = mpi::SendTag(tag(p), i1(p) < 0, i1(p) >= ni1); - } else if constexpr (M::Dim == Dim::_2D) { - tag(p) = mpi::SendTag(tag(p), - i1(p) < 0, - i1(p) >= ni1, - i2(p) < 0, - i2(p) >= ni2); - } else if constexpr (M::Dim == Dim::_3D) { - tag(p) = mpi::SendTag(tag(p), - i1(p) < 0, - i1(p) >= ni1, - i2(p) < 0, - i2(p) >= ni2, - i3(p) < 0, - i3(p) >= ni3); - } - }); + Kokkos::parallel_for("RetagWindowParticles", + species.rangeActiveParticles(), + PrtlRetag_kernel(species.i1, + species.i2, + species.i3, + species.tag, + ni1, + ni2, + ni3)); } #endif diff --git a/src/archetypes/piston.h b/src/archetypes/piston.h index 66f7160f2..d9d81bb14 100644 --- a/src/archetypes/piston.h +++ b/src/archetypes/piston.h @@ -80,6 +80,7 @@ namespace arch { * @param piston_position Position of the piston at the start of timestep in global coordinates * @param piston_v Velocity of piston at current timestep * @param massive Whether the particle is massive or massless (e.g. photon) + * @param is_left Is piston on the left side of the box or right side of the box */ template Inline void Piston(prtlidx_t p, @@ -88,10 +89,11 @@ namespace arch { const M& metric, real_t piston_position, real_t piston_v, - bool massive) { + bool massive, + bool is_left = true) { // check if particle actually crosses the piston, if not return - if (!CrossesPiston(p, dt, particles, metric, piston_position, piston_v, true)) { + if (!CrossesPiston(p, dt, particles, metric, piston_position, piston_v, is_left)) { return; } // step 1: calculate the particle 3 velocity