OPAL (Object Oriented Parallel Accelerator Library)  2024.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 - 2023, 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 
36 public:
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; // s
46  double pathlength; // m
47  double azimuth; // deg
48  double radius; // m
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;
72  double prevAzimuth;
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  enum class MultiBunchMode: unsigned short {
86  FORCE = 0,
87  AUTO = 1
88  };
89 
90  enum class MultiBunchBinning: unsigned short {
91  GAMMA = 0,
92  BUNCH = 1
93  };
94 
95  /*
96  * @param numBunch > 1 --> multi bunch mode
97  * @param eta binning value
98  * @param para only for MultiBunchMode::AUTO
99  * @param mode of multi-bunch
100  * @param binning type of particle binning
101  */
103  const int& numBunch,
104  const double& eta,
105  const double& para,
106  const std::string& mode,
107  const std::string& binning);
108 
110 
112  const PartData& ref);
113 
114  /* Returns:
115  * 0 - if nothing happened
116  * 1 - if bunch got saved
117  * 2 - if bunch got injected
118  */
120  const PartData& ref,
121  bool& flagTransition);
122 
124 
125  void setMode(const std::string& mbmode);
126 
127  void setBinning(const std::string& binning);
128 
129  void setRadiusTurns(const double& radius);
130 
131  void setNumBunch(short n);
132 
133  short getNumBunch() const;
134 
135  bool isForceMode() const;
136 
137  bool calcBunchBeamParameters(PartBunchBase<double, 3>* beam, short bunchNr);
138 
139  beaminfo_t& getBunchInfo(short bunchNr);
140 
141  const beaminfo_t& getBunchInfo(short bunchNr) const;
142 
143  injection_t& getInjectionValues();
144 
145  void updateTime(const double& dt);
146 
147  void updatePathLength(const std::vector<double>& lpaths);
148 
149 private:
150  // store the data of the beam which are required for injecting a
151  // new bunch for multibunch filename
152  std::string onebunch_m;
153 
155  short numBunch_m;
156 
157  // parameter for reset bin in multi-bunch run
158  double eta_m;
159 
160  // 0 for single bunch (default),
161  // 1 for FORCE,
162  // 2 for AUTO
163  MultiBunchMode mode_m; //multiBunchMode_m;
164 
165  // 0 for GAMMA (default),
166  // 1 for BUNCH
167  MultiBunchBinning binning_m; //binningType_m;
168 
169  // control parameter for AUTO multi-bunch mode
171 
172  // used for automatic injection in multi-bunch mode
175 
176  // record how many bunches have already been injected.
178 
179  // each list entry belongs to a bunch
180  std::vector<beaminfo_t> binfo_m;
181 
182  // global attributes of injection
184 };
185 
186 
187 inline
189  bunchCount_m = n;
190 }
191 
192 inline
194  return bunchCount_m;
195 }
196 
197 inline
199  return (mode_m == MultiBunchMode::FORCE);
200 }
201 
202 inline
204  PAssert_GE(bunchNr, 0);
205  PAssert_LT(bunchNr, (short)binfo_m.size());
206  return binfo_m[bunchNr];
207 }
208 
209 inline
211  PAssert_GE(bunchNr, 0);
212  PAssert_LT(bunchNr, (short)binfo_m.size());
213  return binfo_m[bunchNr];
214 }
215 
216 inline
218  return injection_m;
219 }
220 
221 #endif
#define PAssert_GE(a, b)
Definition: PAssert.h:109
void setMode(const std::string &mbmode)
short numBunch_m
The number of bunches specified in TURNS of RUN command.
void saveBunch(PartBunchBase< double, 3 > *beam)
short injectBunch(PartBunchBase< double, 3 > *beam, const PartData &ref, bool &flagTransition)
short getNumBunch() const
void setNumBunch(short n)
#define PAssert_LT(a, b)
Definition: PAssert.h:106
std::vector< beaminfo_t > binfo_m
injection_t & getInjectionValues()
bool readBunch(PartBunchBase< double, 3 > *beam, const PartData &ref)
if write to the Free Software Temple MA USA Also add information on how to contact you by electronic and paper mail If the program is make it output a short notice like this when it starts in an interactive mode
Definition: LICENSE:307
void updateTime(const double &dt)
bool calcBunchBeamParameters(PartBunchBase< double, 3 > *beam, short bunchNr)
MultiBunchBinning binning_m
beaminfo_t & getBunchInfo(short bunchNr)
MultiBunchMode mode_m
MultiBunchHandler(PartBunchBase< double, 3 > *beam, const int &numBunch, const double &eta, const double &para, const std::string &mode, const std::string &binning)
void setRadiusTurns(const double &radius)
void setBinning(const std::string &binning)
void updateParticleBins(PartBunchBase< double, 3 > *beam)
bool isForceMode() const
void updatePathLength(const std::vector< double > &lpaths)