OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalCyclotron.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalCyclotron.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalCyclotron
10 // The class of OPAL cyclotron.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:39 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include <numeric>
20 
21 #include "Elements/OpalCyclotron.h"
23 #include "Attributes/Attributes.h"
26 #include "Physics/Physics.h"
28 
29 #include "TrimCoils/OpalTrimCoil.h"
30 #include "TrimCoils/TrimCoil.h"
31 
32 // Class OpalCyclotron
33 // ------------------------------------------------------------------------
34 
36  OpalElement(SIZE, "CYCLOTRON",
37  "The \"CYCLOTRON\" defines an cyclotron"),
38  obgeo_m(nullptr) {
40  ("CYHARMON", "the harmonic number of the cyclotron");
41 
43  ("SYMMETRY", "defines how the field is stored");
44 
46  ("RINIT", "Initial radius of the reference particle [mm]");
47 
49  ("PRINIT", "Initial radial momentum of the reference particle, pr = beta_r * gamma");
50 
52  ("PHIINIT", "Initial azimuth of the reference particle [deg]");
53 
55  ("ZINIT", "Initial z-coordinate of the reference particle [mm]. Default = 0 mm", 0.0);
56 
58  ("PZINIT", "Initial vertical momentum of the reference particle pz = beta_z * gamma. Default = 0", 0.0);
59 
61  ("FMAPFN", "Filename for the B fieldmap");
62 
64  ("BSCALE", "Scale factor for the B-field", 1.0);
65 
67  ("RFFREQ", "RF Frequency(ies) [MHz]");
68 
70  ("ESCALE", "Scale factor for the RF field(s)");
71 
73  ("SUPERPOSE", "If TRUE, all of the electric field maps are superposed, only used when TYPE = BANDRF");
74 
76  ("RFMAPFN", "Filename(s) for the RF fieldmap(s)");
77 
79  ("RFFCFN", "Filename(s) for the RF Frequency Coefficients");
80 
82  ("RFVCFN", "Filename(s) for the RF Voltage Coefficients");
83 
85  ("RFPHI", "Initial phase(s) of the electric field map(s) [deg]");
86 
88  ("TYPE", "Used to identify special cyclotron types");
89 
91  ("MINZ","Minimal vertical extent of the machine [mm]",-10000.0);
92 
94  ("MAXZ","Maximal vertical extent of the machine [mm]",10000.0);
95 
97  ("MINR","Minimal radial extent of the machine [mm]", 0.0);
98 
100  ("MAXR","Maximal radial extent of the machine [mm]", 10000.0);
101 
103  ("GEOMETRY", "Boundary Geometry for the Cyclotron");
104 
106  ("FMLOWE", "Minimal Energy [MeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
107 
109  ("FMHIGHE","Maximal Energy [MeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
110 
112  ("SPIRAL","Flag whether or not this is a spiral inflector simulation", false);
113 
115  ("TRIMCOILTHRESHOLD","Minimum magnetic field [T] for which trim coils are applied", 0.0);
116 
118  ("TRIMCOIL", "List of trim coils");
119 
120 
121  registerStringAttribute("FMAPFN");
122  registerStringAttribute("GEOMETRY");
123  registerStringAttribute("RFMAPFN");
124  registerStringAttribute("RFFCFN");
125  registerStringAttribute("RFVCFN");
126  registerStringAttribute("TYPE");
127  registerRealAttribute("CYHARMON");
128  registerRealAttribute("RINIT");
129  registerRealAttribute("PRINIT");
130  registerRealAttribute("PHIINIT");
131  registerRealAttribute("ZINIT");
132  registerRealAttribute("PZINIT");
133  registerRealAttribute("SYMMETRY");
134  registerRealAttribute("RFFREQ");
135  registerRealAttribute("BSCALE");
136  registerRealAttribute("ESCALE");
137  registerRealAttribute("RFPHI");
138  registerRealAttribute("MINZ");
139  registerRealAttribute("MAXZ");
140  registerRealAttribute("MINR");
141  registerRealAttribute("MAXR");
142  registerRealAttribute("FMLOWE");
143  registerRealAttribute("FMHIGHE");
144  registerRealAttribute("TRIMCOILTHRESHOLD");
145 
147 
148  setElement((new CyclotronRep("CYCLOTRON"))->makeAlignWrapper());
149 }
150 
151 OpalCyclotron::OpalCyclotron(const std::string &name, OpalCyclotron *parent):
152  OpalElement(name, parent),
153  obgeo_m(nullptr) {
154  setElement((new CyclotronRep(name))->makeAlignWrapper());
155 }
156 
157 
159 {}
160 
161 
163  return new OpalCyclotron(name, this);
164 }
165 
166 
167 void OpalCyclotron::
170 }
171 
172 
174  CyclotronRep *cycl =
175  dynamic_cast<CyclotronRep *>(getElement()->removeWrappers());
176 
177  std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
178 
179  std::string type = Attributes::getString(itsAttr[TYPE]);
180 
181  double harmnum = Attributes::getReal(itsAttr[CYHARMON]);
182  double symmetry = Attributes::getReal(itsAttr[SYMMETRY]);
183  double rinit = Attributes::getReal(itsAttr[RINIT]);
184  double prinit = Attributes::getReal(itsAttr[PRINIT]);
185  double phiinit = Attributes::getReal(itsAttr[PHIINIT]);
186  double zinit = Attributes::getReal(itsAttr[ZINIT]);
187  double pzinit = Attributes::getReal(itsAttr[PZINIT]);
188  double bscale = Attributes::getReal(itsAttr[BSCALE]);
189 
190  double minz = Attributes::getReal(itsAttr[MINZ]);
191  double maxz = Attributes::getReal(itsAttr[MAXZ]);
192  double minr = Attributes::getReal(itsAttr[MINR]);
193  double maxr = Attributes::getReal(itsAttr[MAXR]);
194 
195  double fmLowE = Attributes::getReal(itsAttr[FMLOWE]);
196  double fmHighE = Attributes::getReal(itsAttr[FMHIGHE]);
197 
198  bool spiral_flag = Attributes::getBool(itsAttr[SPIRAL]);
199  double trimCoilThreshold = Attributes::getReal(itsAttr[TRIMCOILTHRESHOLD]);
200 
201  cycl->setFieldMapFN(fmapfm);
202  cycl->setSymmetry(symmetry);
203 
204  cycl->setRinit(rinit);
205  cycl->setPRinit(prinit);
206  cycl->setPHIinit(phiinit);
207  cycl->setZinit(zinit);
208  cycl->setPZinit(pzinit);
209 
210  cycl->setBScale(bscale);
211 
212  cycl->setType(type);
213  cycl->setCyclHarm(harmnum);
214 
215  cycl->setMinR(minr);
216  cycl->setMaxR(maxr);
217  cycl->setMinZ(minz);
218  cycl->setMaxZ(maxz);
219 
220  cycl->setFMLowE(fmLowE);
221  cycl->setFMHighE(fmHighE);
222 
223  cycl->setSpiralFlag(spiral_flag);
224  cycl->setTrimCoilThreshold(trimCoilThreshold);
225 
226  std::vector<std::string> fm_str = Attributes::getStringArray(itsAttr[RFMAPFN]);
227  std::vector<std::string> rffcfn_str = Attributes::getStringArray(itsAttr[RFFCFN]);
228  std::vector<std::string> rfvcfn_str = Attributes::getStringArray(itsAttr[RFVCFN]);
229  std::vector<double> scale_str = Attributes::getRealArray(itsAttr[ESCALE]);
230  std::vector<double> phi_str = Attributes::getRealArray(itsAttr[RFPHI]);
231  std::vector<double> rff_str = Attributes::getRealArray(itsAttr[RFFREQ]);
232  std::vector<bool> superpose_str = Attributes::getBoolArray(itsAttr[SUPERPOSE]);
233  std::vector<std::string> trimcoil = Attributes::getStringArray(itsAttr[TRIMCOIL]);
234 
235  if ( !trimcoil.empty() ) {
236 
237  std::vector<TrimCoil* > trimcoils;
238 
239  for (std::vector<std::string>::const_iterator tit = trimcoil.begin();
240  tit != trimcoil.end(); ++tit)
241  {
242  OpalTrimCoil *tc = OpalTrimCoil::find(*tit);
243 
244  if ( tc ) {
245  tc->initOpalTrimCoil();
246  trimcoils.push_back(tc->trimcoil_m.get());
247  }
248  }
249  cycl->setTrimCoils(trimcoils);
250  }
251 
252  cycl->setRfPhi(phi_str);
253  cycl->setEScale(scale_str);
254  cycl->setRfFieldMapFN(fm_str);
255  cycl->setRFFCoeffFN(rffcfn_str);
256  cycl->setRFVCoeffFN(rfvcfn_str);
257  cycl->setRfFrequ(rff_str);
258  cycl->setSuperpose(superpose_str);
259 
260  if(itsAttr[GEOMETRY] && obgeo_m == nullptr) {
262  if(obgeo_m) {
264  }
265  }
266 
267  // Transmit "unknown" attributes.
269 }
BoundaryGeometry * obgeo_m
Definition: OpalCyclotron.h:92
void setFMLowE(double e)
Definition: Cyclotron.cpp:335
The OpalCyclotron element.
Definition: OpalCyclotron.h:29
static AttCell * registerStringAttribute(const std::string &name)
Register a ``string&#39;&#39; element attribute.
Interface for basic beam line object.
Definition: ElementBase.h:128
void setRinit(double rinit)
Definition: Cyclotron.cpp:108
void setFMHighE(double e)
Definition: Cyclotron.cpp:338
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
virtual void update()
Update the embedded CLASSIC cavity.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual ElementBase * removeWrappers()
Return the design element.
void setTrimCoils(const std::vector< TrimCoil * > &trimcoils)
Definition: Cyclotron.cpp:331
The TRIMCOIL definition.
Definition: OpalTrimCoil.h:17
void setFieldMapFN(std::string fmapfn)
Definition: Cyclotron.cpp:164
void setRFFCoeffFN(std::vector< std::string > rff_coeff_fn)
Definition: Cyclotron.cpp:176
void setSuperpose(std::vector< bool > flag)
Definition: Cyclotron.cpp:232
void setMaxR(double r)
Definition: Cyclotron.cpp:301
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
Definition: Attributes.cpp:106
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
void setRfFieldMapFN(std::vector< std::string > rffmapfn)
Definition: Cyclotron.cpp:172
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
virtual ~OpalCyclotron()
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Definition: Attributes.cpp:373
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
Definition: Attributes.cpp:101
void setCyclHarm(double h)
Definition: Cyclotron.cpp:261
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
void setMinZ(double z)
Definition: Cyclotron.cpp:314
void setPZinit(double zinit)
Definition: Cyclotron.cpp:140
void setEScale(std::vector< double > bs)
Definition: Cyclotron.cpp:273
void setPRinit(double prinit)
Definition: Cyclotron.cpp:116
void setMinR(double r)
Definition: Cyclotron.cpp:295
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:378
void setRfPhi(std::vector< double > f)
Definition: Cyclotron.cpp:215
static BoundaryGeometry * find(const std::string &name)
Base class for all beam line elements.
Definition: OpalElement.h:41
void setType(std::string t)
Definition: Cyclotron.cpp:249
void setRfFrequ(std::vector< double > f)
Definition: Cyclotron.cpp:219
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:258
std::unique_ptr< TrimCoil > trimcoil_m
Actual implementation.
Definition: OpalTrimCoil.h:49
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
virtual OpalCyclotron * clone(const std::string &name)
Make clone.
void registerOwnership() const
OpalCyclotron()
Exemplar constructor.
void setPHIinit(double phiinit)
Definition: Cyclotron.cpp:124
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
void setZinit(double zinit)
Definition: Cyclotron.cpp:132
void setRFVCoeffFN(std::vector< std::string > rfv_coeff_fn)
Definition: Cyclotron.cpp:180
void setMaxZ(double z)
Definition: Cyclotron.cpp:322
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
Representation for a cyclotron magnet system.
Definition: CyclotronRep.h:32
void setBScale(double bs)
Definition: Cyclotron.cpp:265
void initOpalTrimCoil()
Initialise implementation.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:253
void setSymmetry(double symmetry)
Definition: Cyclotron.cpp:240
void setTrimCoilThreshold(double)
Definition: Cyclotron.cpp:148
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
static OpalTrimCoil * find(const std::string &name)
Find named trim coil.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
void setSpiralFlag(bool spiral_flag)
Definition: Cyclotron.cpp:156
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307