OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalFlatTop.h
Go to the documentation of this file.
1
6#ifndef IPPL_OPAL_FLAT_TOP_H
7#define IPPL_OPAL_FLAT_TOP_H
8
9#include <Kokkos_Random.hpp>
10
11#include <algorithm>
12#include <memory>
13#include <random>
14#include <utility>
15#include <vector>
16
17#include "Distribution.h"
18#include "Ippl.h"
19#include "OPALTypes.h"
20#include "SamplingBase.hpp"
21#include "Utilities/Options.h"
22
23using OpalFlatTopGeneratorPool = typename Kokkos::Random_XorShift64_Pool<>;
24
43class OpalFlatTop : public SamplingBase {
44public:
53 std::shared_ptr<ParticleContainer_t> pc, std::shared_ptr<FieldContainer_t> fc,
54 Distribution_t* opalDist);
55
74 std::shared_ptr<ParticleContainer_t> pc, std::shared_ptr<FieldContainer_t> fc,
75 bool emitting, double sigmaTFall, double sigmaTRise, Vector_t<double, 3> cutoff,
76 double tPulseLengthFWHM, Vector_t<double, 3> sigmaR, double ftOscAmplitude = 0.0,
77 double ftOscPeriods = 0.0);
78
85 void generateParticles(size_t& numberOfParticles, Vector_t<double, 3> nr) override;
86
93 void emitParticles(double t, double dt) override;
94
100 bool isEmissionDone(double /*t*/) const override {
102 }
103
109 double getGlobalTimeShift() const override {
110 return std::max(0.0, 0.5 * emissionTime_m - t0_m);
111 }
112
116 bool hasInitialReferenceMomentum() const override { return true; }
117
124
130 double getEmissionTimeStep() const override {
131 return emissionSteps_m > 0 ? emissionTime_m / static_cast<double>(emissionSteps_m) : 0.0;
132 }
133
139 void initDomainDecomp(double BoxIncr) override;
140
146 void setWithDomainDecomp(bool withDomainDecomp) override;
147
151 double getEmissionTime() const { return emissionTime_m; }
152
156 double getDistArea() const { return distArea_m; }
157
161 size_t getInventorySize() const { return birthTimes_m.size(); }
162
166 size_t getNextGlobalIndex() const { return nextGlobalIndex_m; }
167
171 const std::vector<double>& getBirthTimes() const { return birthTimes_m; }
172
178 void setBirthTimesForTest(std::vector<double> birthTimes);
179
180private:
181 using size_type = ippl::detail::size_type;
182
184 std::mt19937_64 host_rng_m;
185
186 double flattopTime_m = 0.0;
188 double distArea_m = 0.0;
189 double sigmaTFall_m = 0.0;
190 double sigmaTRise_m = 0.0;
192 double fallTime_m = 0.0;
193 double riseTime_m = 0.0;
194 bool emitting_m = false;
195 size_t totalN_m = 0;
196 bool withDomainDecomp_m = false;
197 double emissionTime_m = 0.0;
201 double ftOscAmplitude_m = 0.0;
202 double ftOscPeriods_m = 0.0;
203 size_t emissionSteps_m = 100;
204
205 std::vector<double> birthTimes_m;
206 size_t nextGlobalIndex_m = 0;
207 bool inventoryBuilt_m = false;
208
214 static size_t determineRandInit();
215
221 static size_t determineHostSeed();
222
228 void setParameters(Distribution_t* opalDist);
229
243 bool emitting, double sigmaTFall, double sigmaTRise, Vector_t<double, 3> cutoff,
244 double tPulseLengthFWHM, Vector_t<double, 3> sigmaR, double ftOscAmplitude,
245 double ftOscPeriods);
246
252 void buildBirthTimeInventory(size_t numberOfParticles);
253
261 double sampleTruncatedHalfGaussian(double sigma, double limit);
262
269 double toBirthTime(double opalPulseTime) const;
270
277 std::pair<size_t, size_t> computeLocalEmitRange(size_t totalToEmit) const;
278
279public:
294 size_type nlocalBefore, size_t globalBegin, size_t nNew, double tStart, double dt);
295};
296
297#endif // IPPL_OPAL_FLAT_TOP_H
ippl::Vector< T, Dim > Vector_t
const int nr
typename Kokkos::Random_XorShift64_Pool<> OpalFlatTopGeneratorPool
Definition OpalFlatTop.h:23
Implements an old-OPAL-compatible flat-top emitter with precomputed birth times.
Definition OpalFlatTop.h:43
double fallTime_m
Duration represented by the falling flank.
double getGlobalTimeShift() const override
Returns the global time shift needed to center old-OPAL pulse times.
std::pair< size_t, size_t > computeLocalEmitRange(size_t totalToEmit) const
Computes the local contiguous subrange of a global emission batch.
double riseTime_m
Duration represented by the rising flank.
double getEmissionTimeStep() const override
Returns the preferred emission time step.
void initDomainDecomp(double BoxIncr) override
Initializes a domain decomposition large enough for the emitted bunch.
double getDistArea() const
Returns the total area of the normalized flat-top distribution.
double sigmaTRise_m
Standard deviation of the rising flank.
double sampleTruncatedHalfGaussian(double sigma, double limit)
Samples an absolute value from a Gaussian truncated at a limit.
OpalFlatTopGeneratorPool rand_pool_m
Device random number generator pool.
size_t getInventorySize() const
Returns the number of precomputed birth times.
void setBirthTimesForTest(std::vector< double > birthTimes)
Replaces the birth-time inventory for tests.
static size_t determineHostSeed()
Determines the host random seed initialization.
bool emitting_m
Flag for particle emission status.
void setWithDomainDecomp(bool withDomainDecomp) override
Sets whether to use domain decomposition during emission.
std::mt19937_64 host_rng_m
Host generator used to sample birth times.
size_t nextGlobalIndex_m
First global birth-time index not emitted yet.
double sigmaTFall_m
Standard deviation of the falling flank.
std::vector< double > birthTimes_m
Sorted global particle birth times.
const std::vector< double > & getBirthTimes() const
Returns the sorted global birth-time inventory.
double normalizedFlankArea_m
Area of one normalized truncated Gaussian flank.
double flattopTime_m
Time duration of the flat profile section.
Vector_t< double, 3 > hr_m
Grid spacing.
Vector_t< double, 3 > nr_m
Number of grid points per direction.
size_t emissionSteps_m
Number of steps used to derive emission dt.
double ftOscAmplitude_m
Flat-top oscillation amplitude in percent.
void generateParticles(size_t &numberOfParticles, Vector_t< double, 3 > nr) override
Builds the global birth-time inventory for the requested particles.
bool withDomainDecomp_m
Flag for domain decomposition.
size_t getNextGlobalIndex() const
Returns the next global inventory index to be emitted.
double toBirthTime(double opalPulseTime) const
Converts old-OPAL pulse time to tracker birth time.
bool inventoryBuilt_m
True once birthTimes_m is ready for emission.
void emitParticles(double t, double dt) override
Emits all particles whose birth times fall into the current step.
void setParameters(Distribution_t *opalDist)
Reads distribution parameters from the OPALX Distribution object.
void generateLocalParticles(size_type nlocalBefore, size_t globalBegin, size_t nNew, double tStart, double dt)
Generates the local particles assigned to this rank for one emission step.
bool hasInitialReferenceMomentum() const override
Reports that this sampler provides an initial reference momentum.
bool isEmissionDone(double) const override
Returns whether all precomputed particles have been emitted.
void buildBirthTimeInventory(size_t numberOfParticles)
Builds and sorts the global particle birth-time inventory.
Vector_t< double, 3 > cutoffR_m
Cutoff multipliers for distribution support.
double emissionTime_m
Total emission time.
Vector_t< double, 3 > getInitialReferenceMomentum() const override
Returns the initial reference momentum used by the tracker.
void setInternalVariables(bool emitting, double sigmaTFall, double sigmaTRise, Vector_t< double, 3 > cutoff, double tPulseLengthFWHM, Vector_t< double, 3 > sigmaR, double ftOscAmplitude, double ftOscPeriods)
Sets derived flat-top profile and emission parameters.
double getEmissionTime() const
Returns the total emission time.
static size_t determineRandInit()
Determines the device random seed initialization.
size_t totalN_m
Total number of particles in the inventory.
double distArea_m
Total area of the flat-top distribution.
ippl::detail::size_type size_type
Vector_t< double, 3 > sigmaR_m
Semi-axis lengths of the transverse disk.
double ftOscPeriods_m
Number of oscillation periods across the flat top.