OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalCavity.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalCavity.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalCavity
10 // The class of OPAL RF cavities.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:39 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Elements/OpalCavity.h"
21 #include "Attributes/Attributes.h"
24 #include "Structure/OpalWake.h"
26 #include "Physics/Physics.h"
27 
28 extern Inform *gmsg;
29 
30 // Class OpalCavity
31 // ------------------------------------------------------------------------
32 
34  OpalElement(SIZE, "RFCAVITY",
35  "The \"RFCAVITY\" element defines an RF cavity."),
36  owk_m(NULL),
37  obgeo_m(NULL) {
39  ("VOLT", "RF voltage in MV");
41  ("DVOLT", "RF voltage error in MV");
43  ("FREQ", "RF frequency in MHz");
45  ("LAG", "Phase lag (rad)");
47  ("DLAG", "Phase lag error (rad)");
49  ("HARMON", "Harmonic number");
51  ("BETRF", "beta_RF");
53  ("PG", "RF power in MW");
55  ("SHUNT", "Shunt impedance in MOhm");
57  ("TFILL", "Fill time in microseconds");
59  ("FMAPFN", "Filename of the fieldmap");
61  ("GEOMETRY", "BoundaryGeometry for Cavities");
63  ("FAST", "Faster but less accurate", true);
65  ("APVETO", "Do not use this cavity in the Autophase procedure", false);
67  ("RMIN", " Minimal Radius of a cyclotron cavity [mm]");
69  ("RMAX", " Maximal Radius of a cyclotron cavity [mm]");
71  ("ANGLE", "Azimuth position of a cyclotron cavity [deg]");
73  ("PDIS", "Shift distance of cavity gap from center of cyclotron [mm]");
75  ("GAPWIDTH", "Gap width of a cyclotron cavity [mm]");
77  ("PHI0", "Initial phase of cavity [deg]");
79  ("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
80  // attibutes for timedependent values
82  "The name of the phase time dependence model.");
83  itsAttr[AMPLITUDE_MODEL] = Attributes::makeString("AMPLITUDE_MODEL",
84  "The name of the amplitude time dependence model.");
85  itsAttr[FREQUENCY_MODEL] = Attributes::makeString("FREQUENCY_MODEL",
86  "The name of the frequency time dependence model.");
87 
88  registerRealAttribute("VOLT");
89  registerRealAttribute("DVOLT");
90  registerRealAttribute("FREQ");
91  registerRealAttribute("LAG");
92  registerRealAttribute("DLAG");
93  registerStringAttribute("FMAPFN");
94  registerStringAttribute("GEOMETRY");
95  registerRealAttribute("RMIN");
96  registerRealAttribute("RMAX");
97  registerRealAttribute("ANGLE");
98  registerRealAttribute("PDIS");
99  registerRealAttribute("GAPWIDTH");
100  registerRealAttribute("PHI0");
101  registerRealAttribute("DESIGNENERGY");
102 
103  // attibutes for timedependent values
104  registerStringAttribute("PHASE_MODEL");
105  registerStringAttribute("AMPLITUDE_MODEL");
106  registerStringAttribute("FREQUENCY_MODEL");
107 
109 
110  setElement((new RFCavityRep("RFCAVITY"))->makeAlignWrapper());
111 }
112 
113 
114 OpalCavity::OpalCavity(const std::string &name, OpalCavity *parent):
115  OpalElement(name, parent),
116  owk_m(NULL),
117  obgeo_m(NULL) {
118  setElement((new RFCavityRep(name))->makeAlignWrapper());
119 }
120 
121 
123  if(owk_m)
124  delete owk_m;
125 }
126 
127 
128 OpalCavity *OpalCavity::clone(const std::string &name) {
129  return new OpalCavity(name, this);
130 }
131 
132 
135 
136  if(flag != ERROR_FLAG) {
137  const RFCavityRep *rfc =
138  dynamic_cast<const RFCavityRep *>(base.removeWrappers());
139  attributeRegistry["VOLT"]->setReal(rfc->getAmplitude());
140  attributeRegistry["FREQ"]->setReal(rfc->getFrequency());
141  attributeRegistry["LAG"]->setReal(rfc->getPhase());
142  attributeRegistry["FMAPFN"]->setString(rfc->getFieldMapFN());
143  }
144 }
145 
146 
149 
150  using Physics::two_pi;
151  RFCavityRep *rfc =
152  dynamic_cast<RFCavityRep *>(getElement()->removeWrappers());
153 
154  double length = Attributes::getReal(itsAttr[LENGTH]);
155  double peak = Attributes::getReal(itsAttr[VOLT]);
156  double peakError = Attributes::getReal(itsAttr[DVOLT]);
157  double phase = Attributes::getReal(itsAttr[LAG]);
158  double phaseError = Attributes::getReal(itsAttr[DLAG]);
159  double freq = 1e6 * two_pi * Attributes::getReal(itsAttr[FREQ]);
160  std::string fmapfn = Attributes::getString(itsAttr[FMAPFN]);
161  std::string type = Attributes::getString(itsAttr[TYPE]);
162  bool fast = Attributes::getBool(itsAttr[FAST]);
163  bool apVeto = (Attributes::getBool(itsAttr[APVETO]));
164 
165  double rmin = Attributes::getReal(itsAttr[RMIN]);
166  double rmax = Attributes::getReal(itsAttr[RMAX]);
167  double angle = Attributes::getReal(itsAttr[ANGLE]);
168  double pdis = Attributes::getReal(itsAttr[PDIS]);
169  double gapwidth = Attributes::getReal(itsAttr[GAPWIDTH]);
170  double phi0 = Attributes::getReal(itsAttr[PHI0]);
171  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
172 
173  if(itsAttr[WAKEF] && owk_m == NULL) {
174  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
175  owk_m->initWakefunction(*rfc);
176  rfc->setWake(owk_m->wf_m);
177  }
178 
179  if(itsAttr[GEOMETRY] && obgeo_m == NULL) {
181  if(obgeo_m) {
183  }
184  }
185 
186  rfc->setElementLength(length);
187 
188  rfc->setAmplitude(1e6 * peak);
189  rfc->setFrequency(freq);
190  rfc->setPhase(phase);
191 
192  rfc->dropFieldmaps();
193 
194  rfc->setAmplitudem(peak);
195  rfc->setAmplitudeError(peakError);
196  rfc->setFrequencym(freq);
197  rfc->setPhasem(phase);
198  rfc->setPhaseError(phaseError);
199  rfc->setFieldMapFN(fmapfn);
200 
201  rfc->setFast(fast);
202  rfc->setAutophaseVeto(apVeto);
203  rfc->setCavityType(type);
204  rfc->setComponentType(type);
205  rfc->setRmin(rmin);
206  rfc->setRmax(rmax);
207  rfc->setAzimuth(angle);
208  rfc->setPerpenDistance(pdis);
209  rfc->setGapWidth(gapwidth);
210  rfc->setPhi0(phi0);
211  rfc->setDesignEnergy(kineticEnergy);
212 
216 
217  // Transmit "unknown" attributes.
219 }
virtual std::string getFieldMapFN() const
Definition: RFCavity.h:368
virtual void update()
Update the embedded CLASSIC cavity.
Definition: OpalCavity.cpp:147
virtual void setPhase(double phi)
Set phase.
virtual void setAmplitudeError(double vPeakError)
Definition: RFCavity.h:383
static AttCell * registerStringAttribute(const std::string &name)
Register a ``string&#39;&#39; element attribute.
WakeFunction * wf_m
Definition: OpalWake.h:65
Interface for basic beam line object.
Definition: ElementBase.h:128
void setRmin(double rmin)
Definition: RFCavity.cpp:359
void dropFieldmaps()
Definition: RFCavity.h:358
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
virtual void setAmplitude(double V)
Set amplitude.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
void setPhaseModelName(std::string name)
Definition: RFCavity.h:483
constexpr double two_pi
The value of .
Definition: Physics.h:34
virtual void setFrequency(double f)
Set frequency.
virtual ElementBase * removeWrappers()
Return the design element.
virtual void setComponentType(std::string name) override
Definition: RFCavity.cpp:415
Inform * gmsg
Definition: Main.cpp:21
void setRmax(double rmax)
Definition: RFCavity.cpp:363
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:373
virtual double getPhase() const
Get phase.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual void setFrequencym(double freq)
Definition: RFCavity.h:398
void setFrequencyModelName(std::string name)
Definition: RFCavity.h:498
void setCavityType(std::string type)
Definition: RFCavity.h:433
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
void initWakefunction(ElementBase &element)
Definition: OpalWake.cpp:157
Representation for a RF cavity.
Definition: RFCavityRep.h:32
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
void setPhi0(double phi0)
Definition: RFCavity.cpp:379
BoundaryGeometry * obgeo_m
Definition: OpalCavity.h:88
void setAzimuth(double angle)
Definition: RFCavity.cpp:367
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:136
static BoundaryGeometry * find(const std::string &name)
void setAmplitudeModelName(std::string name)
Definition: RFCavity.h:468
Base class for all beam line elements.
Definition: OpalElement.h:41
void setGapWidth(double gapwidth)
Definition: RFCavity.cpp:375
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
virtual void update()
Update the embedded CLASSIC element.
virtual void setFieldMapFN(std::string fmapfn)
Set the name of the field map.
Definition: RFCavity.h:363
virtual double getAmplitude() const
Get amplitude.
void setPerpenDistance(double pdis)
Definition: RFCavity.cpp:371
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
virtual void setAutophaseVeto(bool veto=true)
Definition: RFCavity.h:453
virtual void setPhasem(double phase)
Definition: RFCavity.h:408
OpalCavity()
Exemplar constructor.
Definition: OpalCavity.cpp:33
virtual void setFast(bool fast)
Definition: RFCavity.h:443
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Definition: OpalCavity.cpp:133
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
virtual ~OpalCavity()
Definition: OpalCavity.cpp:122
virtual OpalCavity * clone(const std::string &name)
Make clone.
Definition: OpalCavity.cpp:128
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:423
virtual double getFrequency() const
Get frequency.
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:346
Definition: Inform.h:41
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
OpalWake * owk_m
Definition: OpalCavity.h:86
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