6#ifndef IPPL_INVERSE_TRANSFORM_SAMPLING_H
7#define IPPL_INVERSE_TRANSFORM_SAMPLING_H
25 template <
typename T,
unsigned Dim,
class DeviceType,
class Distribution>
44 template <
class RegionLayout>
50 const typename RegionLayout::host_mirror_type regions =
51 rlayout_r.gethLocalRegions();
55 for (
unsigned d = 0; d <
Dim; ++d) {
56 locrmax[d] = regions(rank)[d].max();
57 locrmin[d] = regions(rank)[d].min();
121 for (
unsigned d = 0; d <
Dim; ++d) {
122 nr_m[d] =
dist_m.getCdf(locrmax[d], d) -
dist_m.getCdf(locrmin[d], d);
123 dr_m[d] =
dist_m.getCdf(rmax[d], d) -
dist_m.getCdf(rmin[d], d);
127 T pnr = std::accumulate(nr_m.
begin(), nr_m.
end(), 1.0, std::multiplies<T>());
128 T pdr = std::accumulate(dr_m.
begin(), dr_m.
end(), 1.0, std::multiplies<T>());
130 T factor = pnr / pdr;
136 int rest = (int)(
ntotal_m - nglobal);
157 for (
unsigned d = 0; d <
Dim; ++d) {
171 template <
class GeneratorPool>
205 KOKKOS_INLINE_FUNCTION
void operator()(
const size_t i)
const {
206 typename GeneratorPool::generator_type rand_gen =
pool_m.get_state();
221 pool_m.free_state(rand_gen);
250 for (
unsigned d = 0; d <
Dim; ++d) {
251 Kokkos::parallel_for(numlocal_m,
fill_random<Kokkos::Random_XorShift64_Pool<>>(
252 targetdist_m, view, rand_pool64,
253 minbound_m, maxbound_m, d));
268 Kokkos::Random_XorShift64_Pool<> rand_pool64) {
272 for (
unsigned d = 0; d <
Dim; ++d) {
273 Kokkos::parallel_for(
274 Kokkos::RangePolicy<>(startIndex, endIndex),
276 targetdist_m, view, rand_pool64, minbound_m, maxbound_m, d));
std::unique_ptr< mpi::Communicator > Comm
The class that represents a distribution.
InverseTransformSampling(Distribution &dist_r, Vector< T, Dim > &rmax_r, Vector< T, Dim > &rmin_r, RegionLayout &rlayout_r, size_type &ntotal_r)
Constructor for InverseTransformSampling class with domain decomposition.
KOKKOS_INLINE_FUNCTION size_type getLocalSamplesNum() const
Get the local number of samples.
ippl::detail::size_type size_type
KOKKOS_INLINE_FUNCTION void setLocalSamplesNum(size_type nlocal)
Set the local number of particles.
typename ippl::detail::ViewType< Vector< T, Dim >, 1 >::view_type view_type
InverseTransformSampling(Distribution &dist_r, Vector< T, Dim > &rmax_r, Vector< T, Dim > &rmin_r, size_type &ntotal_r)
Constructor for InverseTransformSampling class. In this method, we do not consider any domain decompo...
void updateBounds(Vector< T, Dim > &rmax, Vector< T, Dim > &rmin)
Updates the sampling bounds using the CDF without any domain decomposition.
InverseTransformSampling(Distribution &dist_r, Vector< T, Dim > &rmax_r, Vector< T, Dim > &rmin_r, Vector< T, Dim > &locrmax_r, Vector< T, Dim > &locrmin_r, size_type &ntotal_r)
Constructor for InverseTransformSampling class without applying domain decomposition....
void generate(view_type view, Kokkos::Random_XorShift64_Pool<> rand_pool64)
Generate random samples using inverse transform sampling.
void generate(view_type view, size_type startIndex, size_type endIndex, Kokkos::Random_XorShift64_Pool<> rand_pool64)
Generate random samples using inverse transform sampling for a specific range of particles.
void updateBounds(Vector< T, Dim > &rmax, Vector< T, Dim > &rmin, Vector< T, Dim > &locrmax, Vector< T, Dim > &locrmin)
Updates the sampling bounds and reinitializes internal variables.
~InverseTransformSampling()
Deconstructor for InverseTransformSampling class.
Functor that is used for generating samples.
Distribution targetdist_m
Vector< T, Dim > maxbound_m
KOKKOS_INLINE_FUNCTION void operator()(const size_t i) const
Operator to fill random values.
Vector< T, Dim > minbound_m
KOKKOS_FUNCTION fill_random(Distribution &dist_r, view_type &x_r, GeneratorPool &rand_pool_r, Vector< T, Dim > &umin_r, Vector< T, Dim > &umax_r, unsigned int &d_r)
Constructor for the fill_random functor.
Functor for solving equations using the Newton-Raphson method.
KOKKOS_INLINE_FUNCTION void solve(unsigned int d, T &x, T &u)
Solve an equation using the Newton-Raphson method.
KOKKOS_INLINE_FUNCTION constexpr iterator begin()
KOKKOS_INLINE_FUNCTION constexpr iterator end()