OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OpalCyclotron.cpp
Go to the documentation of this file.
1 //
2 // Class OpalCyclotron
3 // The OpalCyclotron element.
4 //
5 // Copyright (c) 200x - 2020, 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 #include "Elements/OpalCyclotron.h"
19 
21 #include "Attributes/Attributes.h"
23 #include "Physics/Units.h"
25 #include "TrimCoils/OpalTrimCoil.h"
26 #include "TrimCoils/TrimCoil.h"
28 
29 #include <numeric>
30 
31 
33  OpalElement(SIZE, "CYCLOTRON",
34  "The \"CYCLOTRON\" defines a cyclotron"),
35  obgeo_m(nullptr) {
37  ("CYHARMON", "The harmonic number of the cyclotron");
38 
40  ("SYMMETRY", "Defines how the field is stored");
41 
43  ("RINIT", "Initial radius of the reference particle [mm]");
44 
46  ("PRINIT", "Initial radial momentum of the reference particle, pr=beta_r*gamma");
47 
49  ("PHIINIT", "Initial azimuth of the reference particle [deg]");
50 
52  ("ZINIT", "Initial z-coordinate of the reference particle [mm] (default=0 mm)", 0.0);
53 
55  ("PZINIT", "Initial vertical momentum of the reference particle, pz=beta_z*gamma (default=0)", 0.0);
56 
58  ("FMAPFN", "Filename for the B fieldmap");
59 
61  ("BSCALE", "Scale factor for the B-field (default=1)", 1.0);
62 
64  ("RFFREQ", "RF Frequency(ies) [MHz]");
65 
67  ("ESCALE", "Scale factor for the RF field(s)");
68 
70  ("SUPERPOSE", "If TRUE, all of the electric field maps are superposed, only used when TYPE=BANDRF");
71 
73  ("RFMAPFN", "Filename(s) for the RF fieldmap(s)");
74 
76  ("RFFCFN", "Filename(s) for the RF Frequency Coefficients");
77 
79  ("RFVCFN", "Filename(s) for the RF Voltage Coefficients");
80 
82  ("RFPHI", "Initial phase(s) of the electric field map(s) [rad]");
83 
85  ("MINZ","Minimal vertical extent of the machine [mm] (default=-10000 mm)",-10000.0);
86 
88  ("MAXZ","Maximal vertical extent of the machine [mm] (default=10000 mm)",10000.0);
89 
91  ("MINR","Minimal radial extent of the machine [mm] (default=0 mm)", 0.0);
92 
94  ("MAXR","Maximal radial extent of the machine [mm] (default=10000 mm)", 10000.0);
95 
97  ("GEOMETRY", "Boundary Geometry for the cyclotron");
98 
100  ("FMLOWE", "Minimal Energy [GeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
101 
103  ("FMHIGHE", "Maximal Energy [GeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
104 
106  ("SPIRAL", "Flag whether or not this is a spiral inflector simulation (default=FALSE)", false);
107 
109  ("TRIMCOILTHRESHOLD", "Minimum magnetic field [T] for which trim coils are applied (default=0.0)", 0.0);
110 
112  ("TRIMCOIL", "List of trim coils");
113 
115 
116  setElement(new CyclotronRep("CYCLOTRON"));
117 }
118 
119 OpalCyclotron::OpalCyclotron(const std::string& name, OpalCyclotron* parent):
120  OpalElement(name, parent),
121  obgeo_m(nullptr) {
122  setElement(new CyclotronRep(name));
123 }
124 
125 
127 {}
128 
129 
131  return new OpalCyclotron(name, this);
132 }
133 
134 
136 
137  CyclotronRep* cycl =
138  dynamic_cast<CyclotronRep*>(getElement());
139 
140  std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
141  std::string type = Attributes::getString(itsAttr[TYPE]);
142 
143  double harmnum = Attributes::getReal(itsAttr[CYHARMON]);
144  double symmetry = Attributes::getReal(itsAttr[SYMMETRY]);
145  double bscale = Attributes::getReal(itsAttr[BSCALE]);
146 
147  double rinit = Units::mm2m * Attributes::getReal(itsAttr[RINIT]);
148  double phiinit = Units::deg2rad * Attributes::getReal(itsAttr[PHIINIT]);
149  double zinit = Units::mm2m * Attributes::getReal(itsAttr[ZINIT]);
150  double prinit = Attributes::getReal(itsAttr[PRINIT]);
151  double pzinit = Attributes::getReal(itsAttr[PZINIT]);
152 
153  double minz = Units::mm2m * Attributes::getReal(itsAttr[MINZ]);
154  double maxz = Units::mm2m * Attributes::getReal(itsAttr[MAXZ]);
155  double minr = Units::mm2m * Attributes::getReal(itsAttr[MINR]);
156  double maxr = Units::mm2m * Attributes::getReal(itsAttr[MAXR]);
157 
158  double fmLowE = Units::GeV2MeV * Attributes::getReal(itsAttr[FMLOWE]);
159  double fmHighE = Units::GeV2MeV * Attributes::getReal(itsAttr[FMHIGHE]);
160 
161  bool spiral_flag = Attributes::getBool(itsAttr[SPIRAL]);
162  double trimCoilThreshold = Units::T2kG * Attributes::getReal(itsAttr[TRIMCOILTHRESHOLD]);
163 
164  cycl->setFieldMapFN(fmapfm);
165  cycl->setSymmetry(symmetry);
166  cycl->setBScale(bscale);
167 
168  cycl->setRinit(rinit);
169  cycl->setPRinit(prinit);
170  cycl->setPHIinit(phiinit);
171  cycl->setZinit(zinit);
172  cycl->setPZinit(pzinit);
173 
174  cycl->setCyclotronType(type);
175  cycl->setCyclHarm(harmnum);
176 
177  cycl->setMinR(minr);
178  cycl->setMaxR(maxr);
179  cycl->setMinZ(minz);
180  cycl->setMaxZ(maxz);
181 
182  cycl->setFMLowE(fmLowE);
183  cycl->setFMHighE(fmHighE);
184 
185  cycl->setSpiralFlag(spiral_flag);
186  cycl->setTrimCoilThreshold(trimCoilThreshold);
187 
189 
190  std::vector<std::string> fm_str = Attributes::getStringArray(itsAttr[RFMAPFN]);
191  std::vector<std::string> rffcfn_str = Attributes::getStringArray(itsAttr[RFFCFN]);
192  std::vector<std::string> rfvcfn_str = Attributes::getStringArray(itsAttr[RFVCFN]);
193  std::vector<double> scale_str = Attributes::getRealArray(itsAttr[ESCALE]);
194  std::vector<double> phi_str = Attributes::getRealArray(itsAttr[RFPHI]);
195  std::vector<double> rff_str = Attributes::getRealArray(itsAttr[RFFREQ]);
196  std::vector<bool> superpose_str = Attributes::getBoolArray(itsAttr[SUPERPOSE]);
197  std::vector<std::string> trimcoil = Attributes::getStringArray(itsAttr[TRIMCOIL]);
198 
199  if ( !trimcoil.empty() ) {
200 
201  std::vector<TrimCoil* > trimcoils;
202 
203  for (std::vector<std::string>::const_iterator tit = trimcoil.begin();
204  tit != trimcoil.end(); ++tit)
205  {
206  OpalTrimCoil *tc = OpalTrimCoil::find(*tit);
207 
208  if ( tc ) {
209  tc->initOpalTrimCoil();
210  trimcoils.push_back(tc->trimcoil_m.get());
211  }
212  }
213  cycl->setTrimCoils(trimcoils);
214  }
215 
216  cycl->setRfPhi(phi_str);
217  cycl->setEScale(scale_str);
218  cycl->setRfFieldMapFN(fm_str);
219  cycl->setRFFCoeffFN(rffcfn_str);
220  cycl->setRFVCoeffFN(rfvcfn_str);
221  cycl->setRfFrequ(rff_str);
222  cycl->setSuperpose(superpose_str);
223 
224  if (itsAttr[GEOMETRY] && obgeo_m == nullptr) {
226  if (obgeo_m) {
228  }
229  }
230 
231  // Transmit "unknown" attributes.
233 }
void setPHIinit(double phiinit)
Definition: Cyclotron.cpp:139
std::unique_ptr< TrimCoil > trimcoil_m
Actual implementation.
Definition: OpalTrimCoil.h:70
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
void setFieldMapFN(const std::string &fmapfn)
Definition: Cyclotron.cpp:179
void setCyclHarm(double h)
Definition: Cyclotron.cpp:268
void setPZinit(double zinit)
Definition: Cyclotron.cpp:155
virtual OpalCyclotron * clone(const std::string &name)
Make clone.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
void setEScale(std::vector< double > bs)
Definition: Cyclotron.cpp:280
void setMaxZ(double z)
Definition: Cyclotron.cpp:343
void setPRinit(double prinit)
Definition: Cyclotron.cpp:131
void setRfPhi(std::vector< double > f)
Definition: Cyclotron.cpp:209
void setSymmetry(double symmetry)
Definition: Cyclotron.cpp:248
void setRfFrequ(std::vector< double > f)
Definition: Cyclotron.cpp:222
void setTrimCoilThreshold(double)
Definition: Cyclotron.cpp:163
void initOpalTrimCoil()
Initialise implementation.
constexpr double T2kG
Definition: Units.h:56
virtual ~OpalCyclotron()
void setZinit(double zinit)
Definition: Cyclotron.cpp:147
static BoundaryGeometry * find(const std::string &name)
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
void setRFVCoeffFN(std::vector< std::string > rfv_coeff_fn)
Definition: Cyclotron.cpp:205
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
void setCyclotronType(const std::string &type)
Definition: Cyclotron.cpp:256
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
Definition: Attributes.cpp:136
void setBScale(double bs)
Definition: Cyclotron.cpp:272
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
virtual void update()
Update the embedded CLASSIC cavity.
void setFMHighE(double e)
Definition: Cyclotron.cpp:368
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Definition: Attributes.cpp:473
constexpr double deg2rad
Definition: Units.h:143
constexpr double mm2m
Definition: Units.h:29
void setOutputFN(std::string fn)
Set output filename.
void setSpiralFlag(bool spiral_flag)
Definition: Cyclotron.cpp:171
void setTrimCoils(const std::vector< TrimCoil * > &trimcoils)
Definition: Cyclotron.cpp:356
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
Definition: Attributes.cpp:141
void setSuperpose(std::vector< bool > flag)
Definition: Cyclotron.cpp:235
constexpr double GeV2MeV
Definition: Units.h:80
void setFMLowE(double e)
Definition: Cyclotron.cpp:360
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
const std::string name
void setRfFieldMapFN(std::vector< std::string > rffmapfn)
Definition: Cyclotron.cpp:197
void setRinit(double rinit)
Definition: Cyclotron.cpp:123
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:478
void setMinZ(double z)
Definition: Cyclotron.cpp:335
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
void setRFFCoeffFN(std::vector< std::string > rff_coeff_fn)
Definition: Cyclotron.cpp:201
void setMinR(double r)
Definition: Cyclotron.cpp:309
void setMaxR(double r)
Definition: Cyclotron.cpp:313
static OpalTrimCoil * find(const std::string &name)
Find named trim coil.
SDDS1 &description type
Definition: test.stat:4
BoundaryGeometry * obgeo_m
Definition: OpalCyclotron.h:79
void registerOwnership() const