7#ifndef WARPX_PARTICLES_COLLISION_SHUFFLE_FISHER_YATES_H_
8#define WARPX_PARTICLES_COLLISION_SHUFFLE_FISHER_YATES_H_
18template <
typename T_index>
24 for (
int i = ie-1; i >=
static_cast<int>(is+1); --i)
42template <
typename index_type>
84 const auto n_part_in_cell_1 = cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell];
85 const auto n_part_in_cell_2 = cell_offsets_2[i_cell+1] - cell_offsets_2[i_cell];
86 p_n_ind_pairs_in_each_cell[i_cell] =
amrex::min(n_part_in_cell_1, n_part_in_cell_2);
90 p_n_ind_pairs_in_each_cell[i_cell] = 0;
117 int i_cell = i < n_cells ? i : i - n_cells;
121 index_type
const cell_start_1 = cell_offsets_1[i_cell];
122 index_type
const cell_stop_1 = cell_offsets_1[i_cell+1];
125 index_type
const cell_start_2 = cell_offsets_2[i_cell];
126 index_type
const cell_stop_2 = cell_offsets_2[i_cell+1];
129 if ( cell_stop_1 - cell_start_1 < 1 ||
130 cell_stop_2 - cell_start_2 < 1 ) {
return; }
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_INLINE void ShuffleFisherYates(T_index *array, T_index const is, T_index const ie, amrex::RandomEngine const &engine)
Definition ShuffleFisherYates.H:20
PODVector< T, ArenaAllocator< T > > DeviceVector
T ExclusiveSum(N n, T const *in, T *out, RetSum a_ret_sum=retSum)
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
unsigned int Random_int(unsigned int n)
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
amrex::Gpu::DeviceVector< index_type > m_coll_offsets
Definition ShuffleFisherYates.H:49
index_type const *AMREX_RESTRICT m_cell_offsets_2
Definition ShuffleFisherYates.H:47
void Initialize()
Definition ShuffleFisherYates.H:73
amrex::Gpu::DeviceVector< index_type > m_n_ind_pairs_in_each_cell
Definition ShuffleFisherYates.H:48
int m_n_cells
Definition ShuffleFisherYates.H:45
int numIndependentPairs() const
Definition ShuffleFisherYates.H:140
index_type const *AMREX_RESTRICT m_cell_offsets_1
Definition ShuffleFisherYates.H:46
void shuffle(index_type *AMREX_RESTRICT a_indices_1, index_type *AMREX_RESTRICT a_indices_2)
Shuffle the particles in each cell using the Fisher-Yates algorithm, for both species.
Definition ShuffleFisherYates.H:106
int m_n_independent_pairs
Definition ShuffleFisherYates.H:50
const index_type * collisionOffsetsPtr() const
Definition ShuffleFisherYates.H:141
IndependentPairHelper(int a_n_cells, index_type const *AMREX_RESTRICT a_cell_offsets_1, index_type const *AMREX_RESTRICT a_cell_offsets_2)
Constructor.
Definition ShuffleFisherYates.H:60