15 std::shared_ptr<FieldContainer_t> &fc,
16 std::shared_ptr<Distribution_t> &opalDist)
48 *
gmsg <<
"* Seed = " << randInit <<
" on all ranks" <<
endl;
74 for (
int i = 0; i < 3; i++) {
77 rmin(i) = (rmin(i) + mu[i]) *
sigmaR_m[i];
78 rmax(i) = (rmax(i) + mu[i]) *
sigmaR_m[i];
82 const double par[6] = {mu[0], sd[0], mu[1], sd[1], mu[2], sd[2]};
88 MPI_Comm comm = MPI_COMM_WORLD;
90 MPI_Comm_size(comm, &nranks);
91 MPI_Comm_rank(comm, &rank);
93 size_t nlocal = floor(numberOfParticles / nranks);
94 size_t remaining = numberOfParticles - nlocal * nranks;
96 if (remaining > 0 && rank == 0) {
100 sampling_t sampling(dist, rmax, rmin, rmax, rmin, nlocal);
101 nlocal = sampling.getLocalSamplesNum();
102 pc_m->create(nlocal);
103 sampling.generate(Rview, rand_pool64);
107 double meanR[3], loc_meanR[3];
108 for(
int i=0; i<3; i++){
114 "calc moments of particle distr.", nlocal,
116 const int k,
double& cent0,
double& cent1,
double& cent2) {
117 cent0 += Rview(k)[0];
118 cent1 += Rview(k)[1];
119 cent2 += Rview(k)[2];
121 Kokkos::Sum<double>(loc_meanR[0]), Kokkos::Sum<double>(loc_meanR[1]), Kokkos::Sum<double>(loc_meanR[2]));
124 MPI_Allreduce(loc_meanR, meanR, 3, MPI_DOUBLE, MPI_SUM,
ippl::Comm->getCommunicator());
127 for(
int i=0; i<3; i++){
128 meanR[i] = meanR[i]/(1.0*numberOfParticles);
132 nlocal, KOKKOS_LAMBDA(
134 Rview(k)[0] -= meanR[0];
135 Rview(k)[1] -= meanR[1];
136 Rview(k)[2] -= meanR[2];
142 for (
int i = 0; i < 3; i++) {
157 KOKKOS_LAMBDA(
const int k) {
158 Pview(k)[2] += avrgpz;
typename Kokkos::Random_XorShift64_Pool<> GeneratorPool
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
Inform & endl(Inform &inf)
int seed
The current random seed.
void parallel_for(const std::string &name, const ExecPolicy &policy, const FunctorType &functor)
void parallel_reduce(const std::string &name, const ExecPolicy &policy, const FunctorType &functor, ReducerArgument &&... reducer)
std::unique_ptr< mpi::Communicator > Comm
Vector_t< double, 3 > sigmaP_m
Vector_t< double, 3 > sigmaR_m
Standard deviations for position and momentum distributions.
void initRandomPool()
Initializes the random number generator pool.
void setCutoffR(const Vector_t< double, 3 > &cutoffR)
double avrgpz_m
Average momentum in the z-direction.
void setFixMeanR(bool fixMeanR)
bool fixMeanR_m
Flag to exactly fix the mean position of particles after sampling.
void setSigmaR(const Vector_t< double, 3 > &sigmaR)
void generateParticles(size_t &numberOfParticles, Vector_t< double, 3 > nr) override
Generates particles with a Gaussian distribution.
Vector_t< double, 3 > cutoffR_m
Cutoff multiplier for position distribution.
GeneratorPool randPool_m
Pool of random number generators for parallel sampling.
Gaussian(std::shared_ptr< ParticleContainer_t > &pc, std::shared_ptr< FieldContainer_t > &fc, std::shared_ptr< Distribution_t > &opalDist)
Constructor for the Gaussian sampler.
void setAvrgpz(double avrgpz)
void setSigmaP(const Vector_t< double, 3 > &sigmaP)
IpplTimings::TimerRef samperTimer_m
Timer for performance profiling.
std::shared_ptr< ParticleContainer_t > pc_m
A class for inverse transform sampling.
Functor to generate random numbers from a normal distribution.
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)