OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Cyclotron.h
Go to the documentation of this file.
1 //
2 // Class Cyclotron
3 // Defines the abstract interface for a cyclotron.
4 //
5 // Copyright (c) 2007 - 2012, Jianjun Yang and Andreas Adelmann, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // Copyright (c) 2013 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
7 // All rights reserved
8 //
9 // Implemented as part of the PhD thesis
10 // "Beam dynamics in high intensity cyclotrons including neighboring bunch effects"
11 // and the paper
12 // "Beam dynamics in high intensity cyclotrons including neighboring bunch effects:
13 // Model, implementation, and application"
14 // (https://journals.aps.org/prab/pdf/10.1103/PhysRevSTAB.13.064201)
15 //
16 // This file is part of OPAL.
17 //
18 // OPAL is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
25 //
26 #ifndef CLASSIC_Cyclotron_HH
27 #define CLASSIC_Cyclotron_HH
28 
29 #include "AbsBeamline/Component.h"
30 
31 #include <string>
32 #include <vector>
33 
34 class Fieldmap;
35 class LossDataSink;
36 class TrimCoil;
37 
38 
39 struct BfieldData {
40  // known from file: field and three theta derivatives
41  std::vector<double> bfld_m; //Bz
42  std::vector<double> dbt_m; //dBz/dtheta
43  std::vector<double> dbtt_m; //d2Bz/dtheta2
44  std::vector<double> dbttt_m; //d3Bz/dtheta3
45 
46  // to be calculated in getdiffs: all other derivatives:
47  std::vector<double> dbr_m; // dBz/dr
48  std::vector<double> dbrr_m; // ...
49  std::vector<double> dbrrr_m;
50 
51  std::vector<double> dbrt_m;
52  std::vector<double> dbrrt_m;
53  std::vector<double> dbrtt_m;
54 
55  // used to get (Br,Btheta,Bz) at any off-plane point
56  std::vector<double> f2_m; // for Bz
57  std::vector<double> f3_m; // for Br
58  std::vector<double> g3_m; // for Btheta
59 
60  // Grid-Size
61  int nrad_m, ntet_m; // need to be read from inputfile.
62  int ntetS_m; // one more grid line is stored in azimuthal direction
63  int ntot_m; // total grid points number.
64 
65  // Mean and Maximas
67 };
68 
69 struct BPositions {
70  // these 4 parameters are need to be read from field file.
71  double rmin_m, delr_m;
72  double tetmin_m, dtet_m;
73 
74  // Radii and step width of initial Grid
75  std::vector<double> rarr_m;
76 
77  // Multiplication factor for magnetic field
78  double Bfact_m;
79 };
80 
81 
82 class Cyclotron: public Component {
83 
84 public:
85 
86  enum class BFieldType {
87  PSIBF,
88  CARBONBF,
89  ANSYSBF,
90  AVFEQBF,
91  FFABF,
92  BANDRF,
93  SYNCHRO
94  };
95 
97  explicit Cyclotron(const std::string& name);
98 
99  Cyclotron();
100  Cyclotron(const Cyclotron&);
101 
102  virtual ~Cyclotron();
103 
105  virtual void accept(BeamlineVisitor&) const;
106 
108  // Slices and stepsize used to determine integration step.
109  virtual double getSlices() const = 0;
110 
112  // Slices and stepsize used to determine integration step.
113  virtual double getStepsize() const = 0;
114 
115  void setFieldMapFN(std::string fmapfn);
116  virtual std::string getFieldMapFN() const;
117 
118  void setRfFieldMapFN(std::vector<std::string> rffmapfn);
119  void setRFFCoeffFN(std::vector<std::string> rff_coeff_fn);
120  void setRFVCoeffFN(std::vector<std::string> rfv_coeff_fn);
121 
122  void setCyclotronType(std::string t);
123  const std::string &getCyclotronType() const;
124  virtual ElementBase::ElementType getType() const;
125 
126  virtual void getDimensions(double& zBegin, double& zEnd) const;
127 
128  unsigned int getNumberOfTrimcoils() const;
129 
130  void setCyclHarm(double h);
131  virtual double getCyclHarm() const;
132 
133  void setRfPhi(std::vector<double> f);
134  double getRfPhi(unsigned int i) const;
135 
136  void setRfFrequ(std::vector<double> f);
137  double getRfFrequ(unsigned int i) const;
138 
139  void setSymmetry(double symmetry);
140  virtual double getSymmetry() const;
141 
142  void setRinit(double rinit);
143  virtual double getRinit() const;
144 
145  void setPRinit(double prinit);
146  virtual double getPRinit() const;
147 
148  void setPHIinit(double phiinit);
149  virtual double getPHIinit() const;
150 
151  void setZinit(double zinit);
152  virtual double getZinit() const;
153 
154  void setPZinit(double zinit);
155  virtual double getPZinit() const;
156 
157  void setBScale(double bs);
158  virtual double getBScale() const;
159 
160  void setEScale(std::vector<double> bs);
161  virtual double getEScale(unsigned int i) const;
162 
163  void setTrimCoils(const std::vector<TrimCoil*>& trimcoils);
164 
165  void setSuperpose(std::vector<bool> flag);
166  virtual bool getSuperpose(unsigned int i) const;
167 
168  void setMinR(double r);
169  virtual double getMinR() const;
170  void setMaxR(double r);
171  virtual double getMaxR() const;
172 
173  void setMinZ(double z);
174  virtual double getMinZ() const;
175  void setMaxZ(double z);
176  virtual double getMaxZ() const;
177 
178  void setFMLowE(double e);
179  virtual double getFMLowE() const;
180  void setFMHighE(double e);
181  virtual double getFMHighE() const;
182 
183  void setTrimCoilThreshold(double);
184  virtual double getTrimCoilThreshold() const;
185 
186  void setSpiralFlag(bool spiral_flag);
187  virtual bool getSpiralFlag() const;
188 
189  virtual bool apply(const size_t& id, const double& t, Vector_t& E, Vector_t& B);
190 
191  virtual bool apply(const Vector_t& R, const Vector_t& P, const double& t, Vector_t& E, Vector_t& B);
192 
193  virtual void apply(const double& rad, const double& z,
194  const double& tet_rad, double& br,
195  double& bt, double& bz);
196 
197  virtual void initialise(PartBunchBase<double, 3>* bunch, double& startField, double& endField);
198 
199  virtual void initialise(PartBunchBase<double, 3>* bunch, const double& scaleFactor);
200 
201  virtual void finalise();
202 
203  virtual bool bends() const;
204 
205  virtual double getRmax() const;
206 
207  virtual double getRmin() const;
208 
209  bool interpolate(const double& rad,
210  const double& tet_rad,
211  double& br,
212  double& bt,
213  double& bz);
214 
215  void read(const double& scaleFactor);
216 
217  void setBFieldType();
218 
219  void writeOutputFieldFiles();
220 
222 
223 private:
225  void applyTrimCoil (const double r, const double z, const double tet_rad, double& br, double& bz);
227  void applyTrimCoil_m(const double r, const double z, const double tet_rad, double* br, double* bz);
228 
229 
230 protected:
231 
232  void getdiffs();
233  double gutdf5d(double* f, double dx, const int kor, const int krl, const int lpr);
234 
235  void initR(double rmin, double dr, int nrad);
236 
237  void getFieldFromFile_Ring(const double& scaleFactor);
238  void getFieldFromFile_Carbon(const double& scaleFactor);
239  void getFieldFromFile_CYCIAE(const double& scaleFactor);
240  void getFieldFromFile_AVFEQ(const double& scaleFactor);
241  void getFieldFromFile_FFA(const double& scaleFactor);
242  void getFieldFromFile_BandRF(const double& scaleFactor);
243  void getFieldFromFile_Synchrocyclotron(const double& scaleFactor);
244 
245  inline int idx(int irad, int ktet) {return (ktet + Bfield_m.ntetS_m * irad);}
246 
247 
248 private:
249 
250  std::string fmapfn_m;
251  std::vector<double> rffrequ_m;
252  std::vector< std::vector<double> > rffc_m;
253  std::vector<double> rfvrequ_m;
254  std::vector< std::vector<double> > rfvc_m;
255  std::vector<double> rfphi_m;
256  std::vector<double> escale_m;
257  std::vector<bool> superpose_m;
259  double symmetry_m;
260 
261  double rinit_m;
262  double prinit_m;
263  double phiinit_m;
264  double zinit_m;
265  double pzinit_m;
266 
270  std::string typeName_m;
271  double harm_m;
272 
273  double bscale_m;
275  std::vector<TrimCoil*> trimcoils_m;
277  double minr_m;
278  double maxr_m;
279  double minz_m;
280  double maxz_m;
281 
282  double fmLowE_m;
283  double fmHighE_m;
284 
285  // Not implemented.
286  void operator=(const Cyclotron &) = delete;
287 
288  // RF field map handler
289  // Fieldmap *RFfield;
290  std::vector<Fieldmap*> RFfields_m;
291  std::vector<std::string> RFfilename_m;
292  std::vector<std::string> RFFCoeff_fn_m;
293  std::vector<std::string> RFVCoeff_fn_m;
294 
295  std::unique_ptr<LossDataSink> lossDs_m;
297  // Necessary for quick and dirty phase output -DW
298  int waitingGap_m = 1;
299 
300 protected:
301  // object of Matrices including magnetic field map and its derivates
303 
304  // object of parameters about the map grid
306 };
307 
308 #endif // CLASSIC_Cyclotron_HH
const std::string name
constexpr double e
The value of.
Definition: Physics.h:39
T rad(T x)
Convert degrees to radians.
Definition: matheval.hpp:78
Interface for a single beam element.
Definition: Component.h:50
double bacc_m
Definition: Cyclotron.h:66
std::vector< double > dbrrt_m
Definition: Cyclotron.h:52
std::vector< double > g3_m
Definition: Cyclotron.h:58
std::vector< double > dbtt_m
Definition: Cyclotron.h:43
int ntot_m
Definition: Cyclotron.h:63
std::vector< double > dbrtt_m
Definition: Cyclotron.h:53
std::vector< double > f3_m
Definition: Cyclotron.h:57
std::vector< double > dbrr_m
Definition: Cyclotron.h:48
std::vector< double > dbrrr_m
Definition: Cyclotron.h:49
std::vector< double > dbttt_m
Definition: Cyclotron.h:44
double dbtmx_m
Definition: Cyclotron.h:66
std::vector< double > dbrt_m
Definition: Cyclotron.h:51
std::vector< double > dbr_m
Definition: Cyclotron.h:47
std::vector< double > dbt_m
Definition: Cyclotron.h:42
int ntetS_m
Definition: Cyclotron.h:62
int ntet_m
Definition: Cyclotron.h:61
std::vector< double > bfld_m
Definition: Cyclotron.h:41
double dbtttmx_m
Definition: Cyclotron.h:66
std::vector< double > f2_m
Definition: Cyclotron.h:56
double dbttmx_m
Definition: Cyclotron.h:66
int nrad_m
Definition: Cyclotron.h:61
double delr_m
Definition: Cyclotron.h:71
double rmin_m
Definition: Cyclotron.h:71
double dtet_m
Definition: Cyclotron.h:72
double Bfact_m
Definition: Cyclotron.h:78
std::vector< double > rarr_m
Definition: Cyclotron.h:75
double tetmin_m
Definition: Cyclotron.h:72
void setTrimCoilThreshold(double)
Definition: Cyclotron.cpp:162
void setZinit(double zinit)
Definition: Cyclotron.cpp:146
virtual double getStepsize() const =0
Get stepsize.
double minr_m
Definition: Cyclotron.h:277
virtual double getCyclHarm() const
Definition: Cyclotron.cpp:292
double rinit_m
Definition: Cyclotron.h:261
void setBFieldType()
Definition: Cyclotron.cpp:364
virtual void getDimensions(double &zBegin, double &zEnd) const
Definition: Cyclotron.cpp:1485
std::vector< std::string > RFfilename_m
Definition: Cyclotron.h:291
virtual bool getSpiralFlag() const
Definition: Cyclotron.cpp:174
virtual bool bends() const
Definition: Cyclotron.cpp:565
void getFieldFromFile_CYCIAE(const double &scaleFactor)
Definition: Cyclotron.cpp:1321
virtual ElementBase::ElementType getType() const
Get element type std::string.
Definition: Cyclotron.cpp:259
void setSpiralFlag(bool spiral_flag)
Definition: Cyclotron.cpp:170
virtual double getPRinit() const
Definition: Cyclotron.cpp:134
void getFieldFromFile_BandRF(const double &scaleFactor)
Definition: Cyclotron.cpp:1394
double harm_m
Definition: Cyclotron.h:271
void setSuperpose(std::vector< bool > flag)
Definition: Cyclotron.cpp:230
double fmHighE_m
Definition: Cyclotron.h:283
double getRfFrequ(unsigned int i) const
Definition: Cyclotron.cpp:221
void setMinR(double r)
Definition: Cyclotron.cpp:304
virtual double getTrimCoilThreshold() const
Definition: Cyclotron.cpp:166
void setCyclotronType(std::string t)
Definition: Cyclotron.cpp:251
double prinit_m
Definition: Cyclotron.h:262
void setRfPhi(std::vector< double > f)
Definition: Cyclotron.cpp:204
void setRFVCoeffFN(std::vector< std::string > rfv_coeff_fn)
Definition: Cyclotron.cpp:200
bool spiralFlag_m
Definition: Cyclotron.h:267
void setPZinit(double zinit)
Definition: Cyclotron.cpp:154
virtual void accept(BeamlineVisitor &) const
Apply visitor to Cyclotron.
Definition: Cyclotron.cpp:118
virtual double getPZinit() const
Definition: Cyclotron.cpp:158
double symmetry_m
Definition: Cyclotron.h:259
std::string typeName_m
Definition: Cyclotron.h:270
virtual std::string getFieldMapFN() const
Definition: Cyclotron.cpp:182
virtual double getRmin() const
Definition: Cyclotron.cpp:296
void read(const double &scaleFactor)
Definition: Cyclotron.cpp:765
int idx(int irad, int ktet)
Definition: Cyclotron.h:245
double phiinit_m
Definition: Cyclotron.h:263
virtual double getMaxR() const
Definition: Cyclotron.cpp:320
void setEScale(std::vector< double > bs)
Definition: Cyclotron.cpp:275
double zinit_m
Definition: Cyclotron.h:264
void setSymmetry(double symmetry)
Definition: Cyclotron.cpp:243
std::vector< bool > superpose_m
Definition: Cyclotron.h:257
virtual void finalise()
Definition: Cyclotron.cpp:559
std::vector< double > escale_m
Definition: Cyclotron.h:256
std::vector< std::string > RFVCoeff_fn_m
Definition: Cyclotron.h:293
std::vector< double > rffrequ_m
Definition: Cyclotron.h:251
double maxz_m
Definition: Cyclotron.h:280
void getFieldFromFile_AVFEQ(const double &scaleFactor)
Definition: Cyclotron.cpp:1164
virtual bool getSuperpose(unsigned int i) const
Definition: Cyclotron.cpp:234
void setMaxR(double r)
Definition: Cyclotron.cpp:310
virtual double getRmax() const
Definition: Cyclotron.cpp:300
virtual double getFMHighE() const
Definition: Cyclotron.cpp:360
double gutdf5d(double *f, double dx, const int kor, const int krl, const int lpr)
Definition: Cyclotron.cpp:570
double trimCoilThreshold_m
Definition: Cyclotron.h:268
virtual double getMaxZ() const
Definition: Cyclotron.cpp:340
void getdiffs()
Definition: Cyclotron.cpp:815
void setMaxZ(double z)
Definition: Cyclotron.cpp:334
virtual double getBScale() const
Definition: Cyclotron.cpp:271
void operator=(const Cyclotron &)=delete
virtual double getZinit() const
Definition: Cyclotron.cpp:150
void getFieldFromFile_Carbon(const double &scaleFactor)
Definition: Cyclotron.cpp:1254
virtual double getEScale(unsigned int i) const
Definition: Cyclotron.cpp:279
void writeOutputFieldFiles()
Definition: Cyclotron.cpp:1489
virtual double getPHIinit() const
Definition: Cyclotron.cpp:142
double getRfPhi(unsigned int i) const
Definition: Cyclotron.cpp:208
std::vector< TrimCoil * > trimcoils_m
Definition: Cyclotron.h:275
std::vector< std::string > RFFCoeff_fn_m
Definition: Cyclotron.h:292
void setTrimCoils(const std::vector< TrimCoil * > &trimcoils)
Definition: Cyclotron.cpp:344
virtual double getSymmetry() const
Definition: Cyclotron.cpp:247
void setCyclHarm(double h)
Definition: Cyclotron.cpp:263
virtual double getMinZ() const
Definition: Cyclotron.cpp:330
void getFieldFromFile_Synchrocyclotron(const double &scaleFactor)
Definition: Cyclotron.cpp:1409
void applyTrimCoil_m(const double r, const double z, const double tet_rad, double *br, double *bz)
Apply trim coils (calculate field contributions)
Definition: Cyclotron.cpp:96
virtual ~Cyclotron()
Definition: Cyclotron.cpp:92
double minz_m
Definition: Cyclotron.h:279
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField)
Definition: Cyclotron.cpp:932
double fmLowE_m
Definition: Cyclotron.h:282
void getFieldFromFile_FFA(const double &scaleFactor)
Definition: Cyclotron.cpp:1057
std::string fmapfn_m
Definition: Cyclotron.h:250
void initR(double rmin, double dr, int nrad)
Definition: Cyclotron.cpp:924
void setPHIinit(double phiinit)
Definition: Cyclotron.cpp:138
void setRfFrequ(std::vector< double > f)
Definition: Cyclotron.cpp:217
void setPRinit(double prinit)
Definition: Cyclotron.cpp:130
void applyTrimCoil(const double r, const double z, const double tet_rad, double &br, double &bz)
Apply trim coils (calculate field contributions) with smooth field transition.
Definition: Cyclotron.cpp:104
BFieldType fieldType_m
Definition: Cyclotron.h:221
double bscale_m
Definition: Cyclotron.h:273
virtual bool apply(const size_t &id, const double &t, Vector_t &E, Vector_t &B)
Definition: Cyclotron.cpp:385
void setRfFieldMapFN(std::vector< std::string > rffmapfn)
Definition: Cyclotron.cpp:192
bool interpolate(const double &rad, const double &tet_rad, double &br, double &bt, double &bz)
Definition: Cyclotron.cpp:682
void setFMHighE(double e)
Definition: Cyclotron.cpp:356
std::vector< Fieldmap * > RFfields_m
Definition: Cyclotron.h:290
std::vector< double > rfphi_m
Definition: Cyclotron.h:255
std::vector< double > rfvrequ_m
Definition: Cyclotron.h:253
void setMinZ(double z)
Definition: Cyclotron.cpp:324
void setRinit(double rinit)
Definition: Cyclotron.cpp:122
int waitingGap_m
Definition: Cyclotron.h:298
double pzinit_m
Definition: Cyclotron.h:265
double maxr_m
Definition: Cyclotron.h:278
BfieldData Bfield_m
Definition: Cyclotron.h:302
std::vector< std::vector< double > > rfvc_m
Definition: Cyclotron.h:254
void setFieldMapFN(std::string fmapfn)
Definition: Cyclotron.cpp:178
std::vector< std::vector< double > > rffc_m
Definition: Cyclotron.h:252
BPositions BP_m
Definition: Cyclotron.h:305
virtual double getFMLowE() const
Definition: Cyclotron.cpp:352
std::unique_ptr< LossDataSink > lossDs_m
Definition: Cyclotron.h:295
unsigned int getNumberOfTrimcoils() const
Definition: Cyclotron.cpp:288
virtual double getRinit() const
Definition: Cyclotron.cpp:126
void getFieldFromFile_Ring(const double &scaleFactor)
Definition: Cyclotron.cpp:946
virtual double getMinR() const
Definition: Cyclotron.cpp:316
const std::string & getCyclotronType() const
Definition: Cyclotron.cpp:255
void setRFFCoeffFN(std::vector< std::string > rff_coeff_fn)
Definition: Cyclotron.cpp:196
void setFMLowE(double e)
Definition: Cyclotron.cpp:348
void setBScale(double bs)
Definition: Cyclotron.cpp:267
virtual double getSlices() const =0
Get number of slices.