OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Distribution.h
Go to the documentation of this file.
1//
2// Class Distribution
3// This class defines the initial beam that is injected or emitted into the simulation.
4//
5// Copyright (c) 2008 - 2022, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef OPAL_Distribution_HH
19#define OPAL_Distribution_HH
20
21#include "Ippl.h"
22
24#include "Algorithms/PartData.h"
26
27#include <memory>
28
30#include "Algorithms/Matrix.h"
33#include "Manager/BaseManager.h"
34#include "Manager/PicManager.h"
39#include "Random/Distribution.h"
40#include "Random/InverseTransformSampling.h"
41#include "Random/NormalDistribution.h"
42#include "Random/Randn.h"
43
44#ifdef WITH_UNIT_TESTS
45#include <gtest/gtest_prod.h>
46#endif
47
48#include <fstream>
49#include <string>
50#include <vector>
51
52class Beam;
53class Beamline;
54class H5PartWrapper;
55
56enum class DistributionType : short {
57 NODIST = -1,
58 GAUSS,
60 FLATTOP,
64};
65
68
69class Distribution : public Definition {
70public:
72
73 virtual ~Distribution();
74
75 using Matrix_t = ippl::Vector<ippl::Vector<double, 6>, 6>;
76
77 virtual bool canReplaceBy(Object* object);
78 virtual Distribution* clone(const std::string& name);
79 virtual void execute();
80
81 size_t getNumOfLocalParticlesToCreate(size_t n);
82
83 // void createOpalT(
84 // PartBunch_t* beam, std::vector<Distribution*> addedDistributions,
85 // size_t& numberOfParticles);
86
87 // void createOpalT(PartBunch_t* beam, size_t& numberOfParticles);
88
89 static Distribution* find(const std::string& name);
90
91 std::string getTypeofDistribution();
93
96 size_t getNumParticles() const;
97
98 Inform& printInfo(Inform& os) const;
99
100 ippl::Vector<double, 3> get_pmean() const;
101 ippl::Vector<double, 3> get_xmean() const;
102
103 ippl::Vector<double, 3> getSigmaR() const;
104 ippl::Vector<double, 3> getSigmaP() const;
105
106 double getSigmaTRise() const;
107 double getSigmaTFall() const;
108 double getTPulseLengthFWHM() const;
109 size_t getEmissionSteps() const;
110
111 double getFTOSCAmplitude() const;
112 double getFTOSCPeriods() const;
113
114 void setDistType();
115
116 void setDist();
117
118 void setAvrgPz(double avrgpz);
119
120 double getAvrgpz() const;
121
122 ippl::Vector<double, 3> getCutoffR() const;
123 ippl::Vector<double, 3> getCutoffP() const;
124
126
129
130 double getTEmission() const;
131 void setTEmission(double tEmission);
132
133 std::string getFilename() const;
134
135private:
136 enum class EmissionModel : unsigned short { NONE, ASTRA, NONEQUIL };
137
138 enum class InputMomentumUnits : unsigned short { NONE, EVOVERC };
139
140#ifdef WITH_UNIT_TESTS
141 FRIEND_TEST(GaussTest, FullSigmaTest1);
142 FRIEND_TEST(GaussTest, FullSigmaTest2);
143#endif
144
145 Distribution(const std::string& name, Distribution* parent);
146
147 // Not implemented.
148 Distribution(const Distribution&) = delete;
149
150 void operator=(const Distribution&) = delete;
151
153
160 // void create(size_t& numberOfParticles, double massIneV, double charge, auto R);
161 void calcPartPerDist(size_t numberOfParticles);
162 void checkParticleNumber(size_t& numberOfParticles);
163
165 size_t getNumberOfParticlesInFile(std::ifstream& inputFile);
166
168 public:
170
171 virtual double get(double rand) = 0;
172 };
173
175 public:
177
178 MDependentBehavior(double a) { ami_m = 1.0 / a; }
179
180 virtual double get(double rand);
181
182 private:
183 double ami_m;
184 };
185
187 public:
188 virtual double get(double rand);
189 };
190
191 //
192 //
193 // void initializeBeam(PartBunch_t* beam);
194 void printDist(Inform& os, size_t numberOfParticles) const;
195 void printDistGauss(Inform& os) const;
196 void printDistMultiVariateGauss(Inform& os) const;
197 void printDistFlatTop(Inform& os) const;
198 void printDistFromFile(Inform& os) const;
199
200 void setAttributes();
201
203
205
207
208 void setSigmaR_m();
209
210 void setSigmaP_m();
211
212 /*
213 private member of Distribution
214 */
215
216 std::string distT_m;
217
220
222
223 ippl::Vector<double, 3> pmean_m, xmean_m, sigmaR_m, sigmaP_m, cutoffR_m, cutoffP_m;
224
228
230
231 double avrgpz_m;
232
235
237};
238
239inline Inform& operator<<(Inform& os, const Distribution& d) { return d.printInfo(os); }
240
241inline ippl::Vector<double, 3> Distribution::getSigmaR() const { return sigmaR_m; }
242
243inline ippl::Vector<double, 3> Distribution::getSigmaP() const { return sigmaP_m; }
244
245inline ippl::Vector<double, 3> Distribution::get_pmean() const { return pmean_m; }
246
247inline ippl::Vector<double, 3> Distribution::get_xmean() const { return xmean_m; }
248
249inline ippl::Vector<double, 3> Distribution::getCutoffR() const { return cutoffR_m; }
250
251inline ippl::Vector<double, 3> Distribution::getCutoffP() const { return cutoffP_m; }
252
253inline double Distribution::getSigmaTRise() const { return sigmaTRise_m; }
254
255inline double Distribution::getSigmaTFall() const { return sigmaTFall_m; }
256
258
259inline double Distribution::getFTOSCAmplitude() const { return FTOSCAmplitude_m; }
260
261inline double Distribution::getFTOSCPeriods() const { return FTOSCPeriods_m; }
262
264
265inline double Distribution::getAvrgpz() const { return avrgpz_m; }
266
268
269inline std::string Distribution::getTypeofDistribution() { return distT_m; }
270
271#endif
272/*
273// OPAL_Distribution_HH
274//
275// Class Distribution
276// This class defines the initial beam that is injected or emitted into the simulation.
277//
278// Copyright (c) 2008 - 2022, Paul Scherrer Institut, Villigen PSI, Switzerland
279// All rights reserved
280//
281// This file is part of OPAL.
282//
283// OPAL is free software: you can redistribute it and/or modify
284// it under the terms of the GNU General Public License as published by
285// the Free Software Foundation, either version 3 of the License, or
286// (at your option) any later version.
287//
288// You should have received a copy of the GNU General Public License
289// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
290//
291#ifndef OPAL_Distribution_HH
292#define OPAL_Distribution_HH
293
294#include "AbstractObjects/Definition.h"
295#include "Algorithms/PartData.h"
296
297#include "Attributes/Attributes.h"
298
299#include "Utilities/Histogram.h"
300#include "Utilities/QuasiRandom.h"
301#include "Utilities/Random.h"
302
303#ifdef WITH_UNIT_TESTS
304#include <gtest/gtest_prod.h>
305#endif
306
307#include <fstream>
308#include <string>
309#include <vector>
310
311class Beam;
312class Beamline;
313
314template <class T, unsigned Dim>
315class PartBunch;
316
317class H5PartWrapper;
318
319enum class DistributionType : short { NODIST = -1, GAUSS };
320
321namespace DISTRIBUTION {
322 enum { TYPE, FNAME, SIGMAX, SIGMAY, SIGMAZ, SIGMAPX, SIGMAPY, SIGMAPZ, SIZE, CUTOFFPX, CUTOFFPY,
323CUTOFFPZ, CUTOFFR };
324}
325
326class Distribution : public Definition {
327public:
328 Distribution();
329
330 virtual ~Distribution();
331
332 virtual bool canReplaceBy(Object* object);
333 virtual Distribution* clone(const std::string& name);
334 virtual void execute();
335 virtual void update();
336
337 // void create(size_t &numberOfParticles, double massIneV, double charge);
338
339 size_t getNumOfLocalParticlesToCreate(size_t n);
340
341 void createOpalT(
342 PartBunch_t* beam, std::vector<Distribution*> addedDistributions,
343 size_t& numberOfParticles);
344 void createOpalT(PartBunch_t* beam, size_t& numberOfParticles);
345
346 static Distribution* find(const std::string& name);
347
348 std::string getTypeofDistribution();
349 DistributionType getType() const;
350
351 Inform& printInfo(Inform& os) const;
352
353 ippl::Vector<double, 3> get_pmean() const;
354 ippl::Vector<double, 3> get_xmean() const;
355
356 void setDistType();
357
358 void setAvrgPz(double avrgpz);
359
360private:
361 enum class EmissionModel : unsigned short { NONE, ASTRA, NONEQUIL };
362
363 enum class InputMomentumUnits : unsigned short { NONE, EVOVERC };
364
365#ifdef WITH_UNIT_TESTS
366 FRIEND_TEST(GaussTest, FullSigmaTest1);
367 FRIEND_TEST(GaussTest, FullSigmaTest2);
368#endif
369
370 Distribution(const std::string& name, Distribution* parent);
371
372 // Not implemented.
373 Distribution(const Distribution&) = delete;
374
375 void operator=(const Distribution&) = delete;
376
377 void addDistributions();
378
380 // Create the particle distribution.
381 // @param numberOfParticles to create
382 // @param massIneV particle charge in eV
383 // @param charge of the particle type in elementary charge
385 void create(size_t& numberOfParticles, double massIneV, double charge);
386 void calcPartPerDist(size_t numberOfParticles);
387 void checkParticleNumber(size_t& numberOfParticles);
388
389 void chooseInputMomentumUnits(InputMomentumUnits inputMoUnits);
390 size_t getNumberOfParticlesInFile(std::ifstream& inputFile);
391
392 class BinomialBehaviorSplitter {
393 public:
394 virtual ~BinomialBehaviorSplitter() {
395 }
396
397 virtual double get(double rand) = 0;
398 };
399
400 class MDependentBehavior : public BinomialBehaviorSplitter {
401 public:
402 MDependentBehavior(const MDependentBehavior& rhs) : ami_m(rhs.ami_m) {
403 }
404
405 MDependentBehavior(double a) {
406 ami_m = 1.0 / a;
407 }
408
409 virtual double get(double rand);
410
411 private:
412 double ami_m;
413 };
414
415 class GaussianLikeBehavior : public BinomialBehaviorSplitter {
416 public:
417 virtual double get(double rand);
418 };
419
420 void createDistributionGauss(size_t numberOfParticles, double massIneV);
421
422 void initializeBeam(PartBunch_t* beam);
423 void printDist(Inform& os, size_t numberOfParticles) const;
424 void printDistGauss(Inform& os) const;
425
426 gsl_qrng* selectRandomGenerator(std::string, unsigned int dimension);
427
428 void setAttributes();
429
430 void setDistParametersGauss(double massIneV);
431
432 void setSigmaR_m();
433
434 void setSigmaP_m();
435
436
437
438 //private member of Distribution
439
440
441 std::string distT_m; /// Distribution type strings.
442
443 PartData particleRefData_m; /// Reference data for particle type (charge,
445
446 gsl_rng* randGen_m; /// Random number generator
447
448 size_t totalNumberParticles_m;
449
450 ippl::Vector<double, 3> pmean_m, xmean_m, sigmaR_m, sigmaP_m;
451
452 DistributionType distrTypeT_m;
453
454 //double avrgpz_m;
455};
456
457inline Inform& operator<<(Inform& os, const Distribution& d) {
458 return d.printInfo(os);
459}
460
461inline ippl::Vector<double, 3> Distribution::get_pmean() const {
462 return pmean_m;
463}
464
465inline ippl::Vector<double, 3> Distribution::get_xmean() const {
466 return xmean_m;
467}
468
469
470inline DistributionType Distribution::getType() const {
471 return distrTypeT_m;
472}
473
474inline std::string Distribution::getTypeofDistribution() {
475 return distT_m;
476}
477
478#endif // OPAL_Distribution_HH
479*/
Inform & operator<<(Inform &os, const Distribution &d)
DistributionType
Definition Beam.h:32
An abstract sequence of beam line components.
Definition Beamline.h:34
The base class for all OPAL definitions.
Definition Definition.h:29
virtual double get(double rand)=0
virtual double get(double rand)
MDependentBehavior(const MDependentBehavior &rhs)
virtual double get(double rand)
static Distribution * find(const std::string &name)
PartData particleRefData_m
Distribution type strings.
ippl::Vector< double, 3 > sigmaR_m
ippl::Vector< double, 3 > xmean_m
void printDistFlatTop(Inform &os) const
ippl::Vector< double, 3 > sigmaP_m
DistributionType getType() const
double FTOSCAmplitude_m
double sigmaTFall_m
double tPulseLengthFWHM_m
virtual void execute()
Execute the command.
double getSigmaTFall() const
double getTEmission() const
Distribution(const Distribution &)=delete
ippl::Vector< double, 3 > getCutoffP() const
void calcPartPerDist(size_t numberOfParticles)
void addDistributions()
size_t getNumberOfParticlesInFile(std::ifstream &inputFile)
virtual bool canReplaceBy(Object *object)
Distribution can only be replaced by another distribution.
double getTPulseLengthFWHM() const
void operator=(const Distribution &)=delete
double FTOSCPeriods_m
ippl::Vector< double, 3 > cutoffR_m
virtual ~Distribution()
std::string getTypeofDistribution()
std::string getFilename() const
DistributionType distrTypeT_m
size_t getNumParticles() const
void setDistParametersMultiVariateGauss()
double getFTOSCAmplitude() const
void printDistFromFile(Inform &os) const
virtual Distribution * clone(const std::string &name)
Return a clone.
void printDistMultiVariateGauss(Inform &os) const
ippl::Vector< double, 3 > cutoffP_m
ippl::Vector< double, 3 > getSigmaP() const
double sigmaTRise_m
ippl::Vector< ippl::Vector< double, 6 >, 6 > Matrix_t
size_t totalNumberParticles_m
void chooseInputMomentumUnits(InputMomentumUnits inputMoUnits)
size_t getNumOfLocalParticlesToCreate(size_t n)
ippl::Vector< double, 3 > pmean_m
void setTEmission(double tEmission)
void setDistParametersFlatTop()
double tEmission_m
ippl::Vector< double, 3 > get_xmean() const
ippl::Vector< double, 3 > get_pmean() const
void printDist(Inform &os, size_t numberOfParticles) const
void setAvrgPz(double avrgpz)
std::string distT_m
ippl::Vector< double, 3 > getSigmaR() const
double getFTOSCPeriods() const
void printDistGauss(Inform &os) const
double getSigmaTRise() const
Inform & printInfo(Inform &os) const
void checkParticleNumber(size_t &numberOfParticles)
double getAvrgpz() const
size_t getEmissionSteps() const
Matrix_t correlationMatrix_m
ippl::Vector< double, 3 > getCutoffR() const
void setDistParametersGauss()
The base class for all OPAL objects.
Definition Object.h:45
Particle reference data.
Definition PartData.h:37
Container for all per-particle (and per-simulation) fields tracked during OPALX tracking.