OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
MultiBunchHandler.h
Go to the documentation of this file.
1//
2// Class MultiBunchHandler
3// Helper class that stores bunch injection
4// information like azimuth, radius etc. of first
5// bunch in multi-bunch mode of ParallelCyclotronTracker.
6//
7// Copyright (c) 2007 - 2014, Jianjun Yang, Paul Scherrer Institut, Villigen PSI, Switzerland
8// Copyright (c) 2012 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
9// All rights reserved
10//
11// Implemented as part of the PhD thesis
12// "Beam dynamics in high intensity cyclotrons including neighboring bunch effects"
13// and the paper
14// "Beam dynamics in high intensity cyclotrons including neighboring bunch effects:
15// Model, implementation, and application"
16// (https://journals.aps.org/prab/pdf/10.1103/PhysRevSTAB.13.064201)
17//
18// This file is part of OPAL.
19//
20// OPAL is free software: you can redistribute it and/or modify
21// it under the terms of the GNU General Public License as published by
22// the Free Software Foundation, either version 3 of the License, or
23// (at your option) any later version.
24//
25// You should have received a copy of the GNU General Public License
26// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
27//
28#ifndef OPAL_MULTI_BUNCH_HANDLER_H
29#define OPAL_MULTI_BUNCH_HANDLER_H
30
32
33#include <vector>
34
36public:
37 struct injection_t {
39 : time(0.0)
40 , pathlength(0.0)
41 , azimuth(0.0)
42 , radius(0.0)
43 { };
44
45 double time; // ns
46 double pathlength; // m
47 double azimuth; // deg
48 double radius; // mm
49 };
50
51 struct beaminfo_t {
52 beaminfo_t(const injection_t& injection = injection_t())
53 : time(injection.time)
54 , azimuth(injection.azimuth)
55 , radius(injection.radius)
56 , prevAzimuth(-1.0)
57 , pathlength(injection.pathlength)
58 , nParticles(0)
59 , ekin(0.0)
60 , dEkin(0.0)
61 , rrms{0.0}
62 , prms{0.0}
63 , emit{0.0}
64 , mean{0.0}
65 , correlation{0.0}
66 , halo{0.0}
67 { };
68
69 double time;
70 double azimuth;
71 double radius;
73 double pathlength;
74 long unsigned int nParticles;
75 double ekin;
76 double dEkin;
77 double rrms[3];
78 double prms[3];
79 double emit[3];
80 double mean[3];
81 double correlation[3];
82 double halo[3];
83 };
84
85 // multi-bunch modes
86 enum class MultiBunchMode: unsigned short {
87 FORCE = 0,
88 AUTO = 1
89 };
90
91 // multi-bunch binning type
92 enum class MultiBunchBinning: unsigned short {
93 GAMMA = 0,
94 BUNCH = 1
95 };
96
97 /*
98 * @param numBunch > 1 --> multi bunch mode
99 * @param eta binning value
100 * @param para only for MultiBunchMode::AUTO
101 * @param mode of multi-bunch
102 * @param binning type of particle binning
103 */
105 const int& numBunch,
106 const double& eta,
107 const double& para,
108 const std::string& mode,
109 const std::string& binning);
110
112
114 const PartData& ref);
115
116 /* Returns:
117 * 0 - if nothing happened
118 * 1 - if bunch got saved
119 * 2 - if bunch got injected
120 */
122 const PartData& ref,
123 bool& flagTransition);
124
126
128 void setMode(const std::string& mbmode);
129
130 // set binning type
131 void setBinning(std::string binning);
132
133 void setRadiusTurns(const double& radius);
134
135 void setNumBunch(short n);
136
137 short getNumBunch() const;
138
139 bool isForceMode() const;
140
141 bool calcBunchBeamParameters(PartBunchBase<double, 3>* beam, short bunchNr);
142
143 beaminfo_t& getBunchInfo(short bunchNr);
144
145 const beaminfo_t& getBunchInfo(short bunchNr) const;
146
147 injection_t& getInjectionValues();
148
149 void updateTime(const double& dt);
150
151 void updatePathLength(const std::vector<double>& lpaths);
152
153private:
154 // store the data of the beam which are required for injecting a
155 // new bunch for multibunch filename
156 std::string onebunch_m;
157
160
161 // parameter for reset bin in multi-bunch run
162 double eta_m;
163
164 // 0 for single bunch (default),
165 // 1 for FORCE,
166 // 2 for AUTO
167 MultiBunchMode mode_m; //multiBunchMode_m;
168
169 // 0 for GAMMA (default),
170 // 1 for BUNCH
171 MultiBunchBinning binning_m; //binningType_m;
172
173 // control parameter for AUTO multi-bunch mode
175
176 // used for automatic injection in multi-bunch mode
179
180 // record how many bunches have already been injected.
182
183 // each list entry belongs to a bunch
184 std::vector<beaminfo_t> binfo_m;
185
186 // global attributes of injection
188};
189
190
191inline
193 bunchCount_m = n;
194}
195
196
197inline
199 return bunchCount_m;
200}
201
202
203inline
205 return (mode_m == MultiBunchMode::FORCE);
206}
207
208
209inline
211 PAssert_GE(bunchNr, 0);
212 PAssert_LT(bunchNr, (short)binfo_m.size());
213 return binfo_m[bunchNr];
214}
215
216
217inline
219 PAssert_GE(bunchNr, 0);
220 PAssert_LT(bunchNr, (short)binfo_m.size());
221 return binfo_m[bunchNr];
222}
223
224
225inline
227 return injection_m;
228}
229
230#endif
#define PAssert_LT(a, b)
Definition: PAssert.h:106
#define PAssert_GE(a, b)
Definition: PAssert.h:109
void saveBunch(PartBunchBase< double, 3 > *beam)
bool calcBunchBeamParameters(PartBunchBase< double, 3 > *beam, short bunchNr)
bool isForceMode() const
MultiBunchHandler(PartBunchBase< double, 3 > *beam, const int &numBunch, const double &eta, const double &para, const std::string &mode, const std::string &binning)
MultiBunchBinning binning_m
beaminfo_t & getBunchInfo(short bunchNr)
void setMode(const std::string &mbmode)
set the working sub-mode for multi-bunch mode: "FORCE" or "AUTO"
void updateTime(const double &dt)
MultiBunchMode mode_m
void setRadiusTurns(const double &radius)
short numBunch_m
The number of bunches specified in TURNS of RUN command.
injection_t & getInjectionValues()
void setNumBunch(short n)
bool readBunch(PartBunchBase< double, 3 > *beam, const PartData &ref)
short getNumBunch() const
void setBinning(std::string binning)
void updatePathLength(const std::vector< double > &lpaths)
short injectBunch(PartBunchBase< double, 3 > *beam, const PartData &ref, bool &flagTransition)
std::vector< beaminfo_t > binfo_m
void updateParticleBins(PartBunchBase< double, 3 > *beam)
beaminfo_t(const injection_t &injection=injection_t())
Particle reference data.
Definition: PartData.h:35