Skip to content
Open
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
83 changes: 57 additions & 26 deletions src/archetypes/moving_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Dimension D>
struct PrtlRetag_kernel {
array_t<int*> i1, i2, i3;
array_t<short*> tag;
const int ni1, ni2, ni3;

PrtlRetag_kernel(const array_t<int*>& i1,
const array_t<int*>& i2,
const array_t<int*>& i3,
const array_t<short*>& 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.

Expand Down Expand Up @@ -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<M::Dim>(species.i1,
species.i2,
species.i3,
species.tag,
ni1,
ni2,
ni3));
}

#endif
Expand Down
6 changes: 4 additions & 2 deletions src/archetypes/piston.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CartesianMetricClass M>
Inline void Piston(prtlidx_t p,
Expand All @@ -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<M>(p, dt, particles, metric, piston_position, piston_v, true)) {
if (!CrossesPiston<M>(p, dt, particles, metric, piston_position, piston_v, is_left)) {
return;
}
// step 1: calculate the particle 3 velocity
Expand Down
Loading