OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
33#include "Manager/BaseManager.h"
34#include "Manager/PicManager.h"
39
40#ifdef WITH_UNIT_TESTS
41#include <gtest/gtest_prod.h>
42#endif
43
44#include <fstream>
45#include <string>
46#include <vector>
47
48class Beam;
49class Beamline;
50class H5PartWrapper;
51
53
56
57class Distribution : public Definition {
58public:
60
61 virtual ~Distribution();
62
63 using Matrix_t = ippl::Vector< ippl::Vector<double, 6>, 6>;
64
65 virtual bool canReplaceBy(Object* object);
66 virtual Distribution* clone(const std::string& name);
67 virtual void execute();
68 virtual void update();
69
70 void create(size_t &numberOfParticles, double massIneV, double charge, ippl::ParticleAttrib<ippl::Vector<double, 3>>& R, ippl::ParticleAttrib<ippl::Vector<double, 3>>& P, std::shared_ptr<ParticleContainer<double, 3>> &pc, std::shared_ptr<FieldContainer_t> &fc, Vector_t<double, 3> nr);
71
72 size_t getNumOfLocalParticlesToCreate(size_t n);
73
74 // void createOpalT(
75 // PartBunch_t* beam, std::vector<Distribution*> addedDistributions,
76 // size_t& numberOfParticles);
77
78 // void createOpalT(PartBunch_t* beam, size_t& numberOfParticles);
79
80 static Distribution* find(const std::string& name);
81
82 std::string getTypeofDistribution();
84
85 Inform& printInfo(Inform& os) const;
86
87 ippl::Vector<double, 3> get_pmean() const;
88 ippl::Vector<double, 3> get_xmean() const;
89
90 ippl::Vector<double, 3> getSigmaR() const;
91 ippl::Vector<double, 3> getSigmaP() const;
92
93 double getSigmaTRise() const;
94 double getSigmaTFall() const;
95 double getTPulseLengthFWHM() const;
96
97 double getFTOSCAmplitude() const;
98 double getFTOSCPeriods() const;
99
100 void setDistType();
101
102 void setDist();
103
104 void setAvrgPz(double avrgpz);
105
106 double getAvrgpz() const;
107
108 ippl::Vector<double, 3> getCutoffR() const;
109 ippl::Vector<double, 3> getCutoffP() const;
110
112
115
116 double getTEmission() const;
117 void setTEmission(double tEmission);
118
119private:
120 enum class EmissionModel : unsigned short { NONE, ASTRA, NONEQUIL };
121
122 enum class InputMomentumUnits : unsigned short { NONE, EVOVERC };
123
124#ifdef WITH_UNIT_TESTS
125 FRIEND_TEST(GaussTest, FullSigmaTest1);
126 FRIEND_TEST(GaussTest, FullSigmaTest2);
127#endif
128
129 Distribution(const std::string& name, Distribution* parent);
130
131 // Not implemented.
132 Distribution(const Distribution&) = delete;
133
134 void operator=(const Distribution&) = delete;
135
137
144 //void create(size_t& numberOfParticles, double massIneV, double charge, auto R);
145 void calcPartPerDist(size_t numberOfParticles);
146 void checkParticleNumber(size_t& numberOfParticles);
147
149 size_t getNumberOfParticlesInFile(std::ifstream& inputFile);
150
152 public:
154 }
155
156 virtual double get(double rand) = 0;
157 };
158
160 public:
163
165 ami_m = 1.0 / a;
166 }
167
168 virtual double get(double rand);
169
170 private:
171 double ami_m;
172 };
173
175 public:
176 virtual double get(double rand);
177 };
178
179 void createDistributionGauss(size_t numberOfParticles, double massIneV, ippl::ParticleAttrib<ippl::Vector<double, 3>>& R, ippl::ParticleAttrib<ippl::Vector<double, 3>>& P, std::shared_ptr<ParticleContainer<double, 3>> &pc, std::shared_ptr<FieldContainer_t> &fc, Vector_t<double, 3> nr);
180
181 //
182 //
183 // void initializeBeam(PartBunch_t* beam);
184 void printDist(Inform& os, size_t numberOfParticles) const;
185 void printDistGauss(Inform& os) const;
186 void printDistMultiVariateGauss(Inform& os) const;
187 void printDistFlatTop(Inform& os) const;
188
189 void setAttributes();
190
192
194
196
197 void setSigmaR_m();
198
199 void setSigmaP_m();
200
201 /*
202 private member of Distribution
203 */
204
205 std::string distT_m;
206
209
211
212 ippl::Vector<double, 3> pmean_m, xmean_m, sigmaR_m, sigmaP_m, cutoffR_m, cutoffP_m;
213
217
219
220 double avrgpz_m;
221
224
226};
227
228inline Inform& operator<<(Inform& os, const Distribution& d) {
229 return d.printInfo(os);
230}
231
232inline ippl::Vector<double, 3> Distribution::getSigmaR() const {
233 return sigmaR_m;
234}
235
236inline ippl::Vector<double, 3> Distribution::getSigmaP() const {
237 return sigmaP_m;
238}
239
240inline ippl::Vector<double, 3> Distribution::get_pmean() const {
241 return pmean_m;
242}
243
244inline ippl::Vector<double, 3> Distribution::get_xmean() const {
245 return xmean_m;
246}
247
248inline ippl::Vector<double, 3> Distribution::getCutoffR() const {
249 return cutoffR_m;
250}
251
252inline ippl::Vector<double, 3> Distribution::getCutoffP() const {
253 return cutoffP_m;
254}
255
256inline double Distribution::getSigmaTRise() const {
257 return sigmaTRise_m;
258}
259
260inline double Distribution::getSigmaTFall() const {
261 return sigmaTFall_m;
262}
263
265 return tPulseLengthFWHM_m;
266}
267
268inline double Distribution::getFTOSCAmplitude() const {
269 return FTOSCAmplitude_m;
270}
271
272inline double Distribution::getFTOSCPeriods() const {
273 return FTOSCPeriods_m;
274}
275
277 return distrTypeT_m;
278}
279
280inline double Distribution::getAvrgpz() const {
281 return avrgpz_m;
282}
283
285 return distT_m;
286}
287
288#endif
289/*
290// OPAL_Distribution_HH
291//
292// Class Distribution
293// This class defines the initial beam that is injected or emitted into the simulation.
294//
295// Copyright (c) 2008 - 2022, Paul Scherrer Institut, Villigen PSI, Switzerland
296// All rights reserved
297//
298// This file is part of OPAL.
299//
300// OPAL is free software: you can redistribute it and/or modify
301// it under the terms of the GNU General Public License as published by
302// the Free Software Foundation, either version 3 of the License, or
303// (at your option) any later version.
304//
305// You should have received a copy of the GNU General Public License
306// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
307//
308#ifndef OPAL_Distribution_HH
309#define OPAL_Distribution_HH
310
311#include "AbstractObjects/Definition.h"
312#include "Algorithms/PartData.h"
313
314#include "Attributes/Attributes.h"
315
316#include <gsl/gsl_histogram.h>
317#include <gsl/gsl_qrng.h>
318#include <gsl/gsl_rng.h>
319
320#ifdef WITH_UNIT_TESTS
321#include <gtest/gtest_prod.h>
322#endif
323
324#include <fstream>
325#include <string>
326#include <vector>
327
328class Beam;
329class Beamline;
330
331template <class T, unsigned Dim>
332class PartBunch;
333
334class H5PartWrapper;
335
336enum class DistributionType : short { NODIST = -1, GAUSS };
337
338namespace DISTRIBUTION {
339 enum { TYPE, FNAME, SIGMAX, SIGMAY, SIGMAZ, SIGMAPX, SIGMAPY, SIGMAPZ, SIZE, CUTOFFPX, CUTOFFPY, CUTOFFPZ, CUTOFFR };
340}
341
342class Distribution : public Definition {
343public:
344 Distribution();
345
346 virtual ~Distribution();
347
348 virtual bool canReplaceBy(Object* object);
349 virtual Distribution* clone(const std::string& name);
350 virtual void execute();
351 virtual void update();
352
353 // void create(size_t &numberOfParticles, double massIneV, double charge);
354
355 size_t getNumOfLocalParticlesToCreate(size_t n);
356
357 void createOpalT(
358 PartBunch_t* beam, std::vector<Distribution*> addedDistributions,
359 size_t& numberOfParticles);
360 void createOpalT(PartBunch_t* beam, size_t& numberOfParticles);
361
362 static Distribution* find(const std::string& name);
363
364 std::string getTypeofDistribution();
365 DistributionType getType() const;
366
367 Inform& printInfo(Inform& os) const;
368
369 ippl::Vector<double, 3> get_pmean() const;
370 ippl::Vector<double, 3> get_xmean() const;
371
372 void setDistType();
373
374 void setAvrgPz(double avrgpz);
375
376private:
377 enum class EmissionModel : unsigned short { NONE, ASTRA, NONEQUIL };
378
379 enum class InputMomentumUnits : unsigned short { NONE, EVOVERC };
380
381#ifdef WITH_UNIT_TESTS
382 FRIEND_TEST(GaussTest, FullSigmaTest1);
383 FRIEND_TEST(GaussTest, FullSigmaTest2);
384#endif
385
386 Distribution(const std::string& name, Distribution* parent);
387
388 // Not implemented.
389 Distribution(const Distribution&) = delete;
390
391 void operator=(const Distribution&) = delete;
392
393 void addDistributions();
394
396 // Create the particle distribution.
397 // @param numberOfParticles to create
398 // @param massIneV particle charge in eV
399 // @param charge of the particle type in elementary charge
401 void create(size_t& numberOfParticles, double massIneV, double charge);
402 void calcPartPerDist(size_t numberOfParticles);
403 void checkParticleNumber(size_t& numberOfParticles);
404
405 void chooseInputMomentumUnits(InputMomentumUnits inputMoUnits);
406 size_t getNumberOfParticlesInFile(std::ifstream& inputFile);
407
408 class BinomialBehaviorSplitter {
409 public:
410 virtual ~BinomialBehaviorSplitter() {
411 }
412
413 virtual double get(double rand) = 0;
414 };
415
416 class MDependentBehavior : public BinomialBehaviorSplitter {
417 public:
418 MDependentBehavior(const MDependentBehavior& rhs) : ami_m(rhs.ami_m) {
419 }
420
421 MDependentBehavior(double a) {
422 ami_m = 1.0 / a;
423 }
424
425 virtual double get(double rand);
426
427 private:
428 double ami_m;
429 };
430
431 class GaussianLikeBehavior : public BinomialBehaviorSplitter {
432 public:
433 virtual double get(double rand);
434 };
435
436 void createDistributionGauss(size_t numberOfParticles, double massIneV);
437
438 void initializeBeam(PartBunch_t* beam);
439 void printDist(Inform& os, size_t numberOfParticles) const;
440 void printDistGauss(Inform& os) const;
441
442 gsl_qrng* selectRandomGenerator(std::string, unsigned int dimension);
443
444 void setAttributes();
445
446 void setDistParametersGauss(double massIneV);
447
448 void setSigmaR_m();
449
450 void setSigmaP_m();
451
452
453
454 //private member of Distribution
455
456
457 std::string distT_m; /// Distribution type strings.
458
459 PartData particleRefData_m; /// Reference data for particle type (charge,
461
462 gsl_rng* randGen_m; /// Random number generator
463
464 size_t totalNumberParticles_m;
465
466 ippl::Vector<double, 3> pmean_m, xmean_m, sigmaR_m, sigmaP_m;
467
468 DistributionType distrTypeT_m;
469
470 //double avrgpz_m;
471};
472
473inline Inform& operator<<(Inform& os, const Distribution& d) {
474 return d.printInfo(os);
475}
476
477inline ippl::Vector<double, 3> Distribution::get_pmean() const {
478 return pmean_m;
479}
480
481inline ippl::Vector<double, 3> Distribution::get_xmean() const {
482 return xmean_m;
483}
484
485
486inline DistributionType Distribution::getType() const {
487 return distrTypeT_m;
488}
489
490inline std::string Distribution::getTypeofDistribution() {
491 return distT_m;
492}
493
494#endif // OPAL_Distribution_HH
495*/
ParticleContainer< double, 3 > ParticleContainer_t
Definition Component.h:30
ippl::Vector< T, Dim > Vector_t
Inform & operator<<(Inform &os, const Distribution &d)
DistributionType
FieldContainer< double, 3 > FieldContainer_t
const int nr
Definition(int size, const char *name, const char *help)
Constructor for exemplars.
Object(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Object.cpp:354
Particle reference data.
Definition PartData.h:37
An abstract sequence of beam line components.
Definition Beamline.h:34
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()
DistributionType distrTypeT_m
void setDistParametersMultiVariateGauss()
double getFTOSCAmplitude() const
virtual Distribution * clone(const std::string &name)
Return a clone.
virtual void update()
Update this object.
void printDistMultiVariateGauss(Inform &os) const
ippl::Vector< double, 3 > cutoffP_m
ippl::Vector< double, 3 > getSigmaP() const
double sigmaTRise_m
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()
void createDistributionGauss(size_t numberOfParticles, double massIneV, ippl::ParticleAttrib< ippl::Vector< double, 3 > > &R, ippl::ParticleAttrib< ippl::Vector< double, 3 > > &P, std::shared_ptr< ParticleContainer< double, 3 > > &pc, std::shared_ptr< FieldContainer_t > &fc, Vector_t< double, 3 > nr)
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
ippl::Vector< ippl::Vector< double, 6 >, 6 > Matrix_t
Inform & printInfo(Inform &os) const
void checkParticleNumber(size_t &numberOfParticles)
double getAvrgpz() const
void create(size_t &numberOfParticles, double massIneV, double charge, ippl::ParticleAttrib< ippl::Vector< double, 3 > > &R, ippl::ParticleAttrib< ippl::Vector< double, 3 > > &P, std::shared_ptr< ParticleContainer< double, 3 > > &pc, std::shared_ptr< FieldContainer_t > &fc, Vector_t< double, 3 > nr)
Matrix_t correlationMatrix_m
ippl::Vector< double, 3 > getCutoffR() const
void setDistParametersGauss()
virtual double get(double rand)=0
MDependentBehavior(const MDependentBehavior &rhs)
virtual double get(double rand)
virtual double get(double rand)
Definition Beam.h:31