1 #ifndef AMREX_PARTICLETRANSFORMATION_H_
2 #define AMREX_PARTICLETRANSFORMATION_H_
3 #include <AMReX_Config.H>
29 template <
typename T_ParticleType,
int NAR,
int NAI>
33 int src_i,
int dst_i) noexcept
35 AMREX_ASSERT(dst.m_num_runtime_real == src.m_num_runtime_real);
36 AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int );
38 if constexpr(!T_ParticleType::is_soa_particle) {
39 dst.m_aos[dst_i] = src.m_aos[src_i];
41 dst.m_idcpu[dst_i] = src.m_idcpu[src_i];
43 if constexpr(NAR > 0) {
44 for (
int j = 0; j < NAR; ++j) {
45 dst.m_rdata[j][dst_i] = src.m_rdata[j][src_i];
48 for (
int j = 0; j < dst.m_num_runtime_real; ++j) {
49 dst.m_runtime_rdata[j][dst_i] = src.m_runtime_rdata[j][src_i];
51 if constexpr(NAI > 0) {
52 for (
int j = 0; j < NAI; ++j) {
53 dst.m_idata[j][dst_i] = src.m_idata[j][src_i];
56 for (
int j = 0; j < dst.m_num_runtime_int; ++j) {
57 dst.m_runtime_idata[j][dst_i] = src.m_runtime_idata[j][src_i];
75 template <
typename T_ParticleType,
int NAR,
int NAI>
79 int src_i,
int dst_i) noexcept
81 AMREX_ASSERT(dst.m_num_runtime_real == src.m_num_runtime_real);
82 AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int );
84 if constexpr(T_ParticleType::is_soa_particle) {
85 dst.m_idcpu[dst_i] = src.m_idcpu[src_i];
87 dst.m_aos[dst_i] = src.m_aos[src_i];
89 for (
int j = 0; j < NAR; ++j) {
90 dst.m_rdata[j][dst_i] = src.m_rdata[j][src_i];
92 for (
int j = 0; j < dst.m_num_runtime_real; ++j) {
93 dst.m_runtime_rdata[j][dst_i] = src.m_runtime_rdata[j][src_i];
95 for (
int j = 0; j < NAI; ++j) {
96 dst.m_idata[j][dst_i] = src.m_idata[j][src_i];
98 for (
int j = 0; j < dst.m_num_runtime_int; ++j) {
99 dst.m_runtime_idata[j][dst_i] = src.m_runtime_idata[j][src_i];
117 template <
typename T_ParticleType,
int NAR,
int NAI>
121 int src_i,
int dst_i) noexcept
123 AMREX_ASSERT(dst.m_num_runtime_real == src.m_num_runtime_real);
124 AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int );
126 if constexpr(T_ParticleType::is_soa_particle) {
127 amrex::Swap(src.m_idcpu[src_i], dst.m_idcpu[dst_i]);
131 for (
int j = 0; j < NAR; ++j) {
132 amrex::Swap(dst.m_rdata[j][dst_i], src.m_rdata[j][src_i]);
134 for (
int j = 0; j < dst.m_num_runtime_real; ++j) {
135 amrex::Swap(dst.m_runtime_rdata[j][dst_i], src.m_runtime_rdata[j][src_i]);
137 for (
int j = 0; j < NAI; ++j) {
138 amrex::Swap(dst.m_idata[j][dst_i], src.m_idata[j][src_i]);
140 for (
int j = 0; j < dst.m_num_runtime_int; ++j) {
141 amrex::Swap(dst.m_runtime_idata[j][dst_i], src.m_runtime_idata[j][src_i]);
157 template <
typename DstTile,
typename SrcTile>
160 auto np = src.numParticles();
180 template <
typename DstTile,
typename SrcTile,
typename Index,
typename N,
181 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
183 Index src_start, Index dst_start, N n) noexcept
185 const auto src_data = src.getConstParticleTileData();
186 auto dst_data = dst.getParticleTileData();
190 copyParticle(dst_data, src_data, src_start+i, dst_start+i);
209 template <
typename DstTile,
typename SrcTile,
typename F>
212 auto np = src.numParticles();
234 template <
typename DstTile,
typename SrcTile,
typename Index,
typename N,
typename F,
235 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
237 Index src_start, Index dst_start, N n, F
const&
f) noexcept
239 const auto src_data = src.getConstParticleTileData();
240 auto dst_data = dst.getParticleTileData();
244 f(dst_data, src_data, src_start+i, dst_start+i);
265 template <
typename DstTile1,
typename DstTile2,
typename SrcTile,
typename F>
268 auto np = src.numParticles();
293 template <
typename DstTile1,
typename DstTile2,
typename SrcTile,
294 typename Index,
typename N,
typename F,
295 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
297 Index src_start, Index dst1_start, Index dst2_start, N n, F
const&
f) noexcept
299 const auto src_data = src.getConstParticleTileData();
300 auto dst1_data = dst1.getParticleTileData();
301 auto dst2_data = dst2.getParticleTileData();
305 f(dst1_data, dst2_data, src_data, src_start+i, dst1_start+i, dst2_start+i);
323 template <
typename DstTile,
typename SrcTile,
typename Index,
typename N,
324 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
347 template <
typename DstTile,
typename SrcTile,
typename Index,
typename N,
348 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
350 Index src_start, Index dst_start, N n) noexcept
355 Index last_mask=0, last_offset=0;
359 auto* p_offsets = offsets.
dataPtr();
361 const auto src_data = src.getConstParticleTileData();
362 auto dst_data = dst.getParticleTileData();
366 if (
mask[i]) {
copyParticle(dst_data, src_data, src_start+i, dst_start+p_offsets[i]); }
370 return last_mask + last_offset;
385 template <
typename DstTile,
typename SrcTile,
typename Pred,
386 std::enable_if_t<!std::is_pointer_v<std::decay_t<Pred>>,
int> foo = 0>
389 return filterParticles(dst, src, std::forward<Pred>(p), 0, 0, src.numParticles());
409 template <
typename DstTile,
typename SrcTile,
typename Pred,
typename Index,
typename N,
410 std::enable_if_t<!std::is_pointer_v<std::decay_t<Pred>>,Index> nvccfoo = 0>
412 Index src_start, Index dst_start, N n) noexcept
417 const auto src_data = src.getConstParticleTileData();
424 p_mask[i] = p(src_data, src_start+i, engine);
426 p_mask[i] = p(src_data, src_start+i);
447 template <
typename DstTile,
typename SrcTile,
typename Index,
typename F,
448 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
450 Index src_start, Index dst_start) noexcept
452 auto np = src.numParticles();
456 Index last_mask=0, last_offset=0;
460 auto const* p_offsets = offsets.
dataPtr();
462 const auto src_data = src.getConstParticleTileData();
463 auto dst_data = dst.getParticleTileData();
468 f(dst_data, src_data, src_start+i,
469 dst_start+p_offsets[src_start+i]);
474 return last_mask + last_offset;
492 template <
typename DstTile,
typename SrcTile,
typename Index,
typename F,
493 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
514 template <
typename DstTile,
typename SrcTile,
typename Pred,
typename F,
515 std::enable_if_t<!std::is_pointer_v<std::decay_t<Pred>>,
int> foo = 0>
538 template <
typename DstTile1,
typename DstTile2,
typename SrcTile,
typename Index,
typename F,
539 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
541 const SrcTile& src, Index*
mask, F
const&
f) noexcept
543 auto np = src.numParticles();
547 Index last_mask=0, last_offset=0;
551 auto* p_offsets = offsets.
dataPtr();
553 const auto src_data = src.getConstParticleTileData();
554 auto dst_data1 = dst1.getParticleTileData();
555 auto dst_data2 = dst2.getParticleTileData();
559 if (
mask[i]) {
f(dst_data1, dst_data2, src_data, i, p_offsets[i], p_offsets[i]); }
563 return last_mask + last_offset;
583 template <
typename DstTile1,
typename DstTile2,
typename SrcTile,
typename Pred,
typename F,
584 std::enable_if_t<!std::is_pointer_v<std::decay_t<Pred>>,
int> foo = 0>
586 Pred
const& p, F&&
f) noexcept
588 auto np = src.numParticles();
592 const auto src_data = src.getConstParticleTileData();
599 p_mask[i] = p(src_data, i, engine);
601 p_mask[i] = p(src_data, i);
624 template <
typename DstTile,
typename SrcTile,
typename Pred,
typename F,
typename Index,
625 std::enable_if_t<!std::is_pointer_v<std::decay_t<Pred>>,Index> nvccfoo = 0>
627 Index src_start, Index dst_start) noexcept
629 auto np = src.numParticles();
633 const auto src_data = src.getConstParticleTileData();
640 p_mask[i] = p(src_data, src_start+i, engine);
642 p_mask[i] = p(src_data, src_start+i);
664 template <
typename PTile,
typename N,
typename Index,
665 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
668 const auto src_data = src.getConstParticleTileData();
669 auto dst_data = dst.getParticleTileData();
694 template <
typename PTile,
typename N,
typename Index,
695 std::enable_if_t<std::is_integral_v<Index>,
int> foo = 0>
698 const auto src_data = src.getConstParticleTileData();
699 auto dst_data = dst.getParticleTileData();
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_HOST_DEVICE_FOR_1D(...)
Definition: AMReX_GpuLaunch.nolint.H:49
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Array4< int const > mask
Definition: AMReX_InterpFaceRegister.cpp:93
Definition: AMReX_PODVector.H:246
T * data() noexcept
Definition: AMReX_PODVector.H:593
iterator begin() noexcept
Definition: AMReX_PODVector.H:601
T * dataPtr() noexcept
Definition: AMReX_PODVector.H:597
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:233
OutIter exclusive_scan(InIter begin, InIter end, OutIter result)
Definition: AMReX_Scan.H:1377
static constexpr DeviceToHost deviceToHost
Definition: AMReX_GpuContainers.H:99
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void swapParticle(const ParticleTileData< T_ParticleType, NAR, NAI > &dst, const ParticleTileData< T_ParticleType, NAR, NAI > &src, int src_i, int dst_i) noexcept
A general single particle swapping routine that can run on the GPU.
Definition: AMReX_ParticleTransformation.H:119
void copyParticles(DstTile &dst, const SrcTile &src) noexcept
Copy particles from src to dst. This version copies all the particles, writing them to the beginning ...
Definition: AMReX_ParticleTransformation.H:158
Index filterAndTransformParticles(DstTile &dst, const SrcTile &src, Index *mask, F const &f, Index src_start, Index dst_start) noexcept
Conditionally copy particles from src to dst based on the value of mask. A transformation will also b...
Definition: AMReX_ParticleTransformation.H:449
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Swap(T &t1, T &t2) noexcept
Definition: AMReX_Algorithm.H:75
Index filterParticles(DstTile &dst, const SrcTile &src, const Index *mask) noexcept
Conditionally copy particles from src to dst based on the value of mask.
Definition: AMReX_ParticleTransformation.H:325
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition: AMReX.H:111
void gatherParticles(PTile &dst, const PTile &src, N np, const Index *inds)
Gather particles copies particles into contiguous order from an arbitrary order. Specifically,...
Definition: AMReX_ParticleTransformation.H:666
void transformParticles(DstTile &dst, const SrcTile &src, F &&f) noexcept
Apply the function f to all the particles in src, writing the result to dst. This version does all th...
Definition: AMReX_ParticleTransformation.H:210
void scatterParticles(PTile &dst, const PTile &src, N np, const Index *inds)
Scatter particles copies particles from contiguous order into an arbitrary order. Specifically,...
Definition: AMReX_ParticleTransformation.H:696
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Definition: AMReX_GpuLaunchFunctsC.H:1221
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void copyParticle(const ParticleTileData< T_ParticleType, NAR, NAI > &dst, const ConstParticleTileData< T_ParticleType, NAR, NAI > &src, int src_i, int dst_i) noexcept
A general single particle copying routine that can run on the GPU.
Definition: AMReX_ParticleTransformation.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * dataPtr() const noexcept
Definition: AMReX_Array4.H:238
Definition: AMReX_ParticleTile.H:495
Test if a given type T is callable with arguments of type Args...
Definition: AMReX_TypeTraits.H:201
Definition: AMReX_ParticleTile.H:32
Definition: AMReX_RandomEngine.H:57