OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalTravelingWave.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalTravelingWave.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalTravelingWave
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 
21 #include "Attributes/Attributes.h"
23 #include "Structure/OpalWake.h"
24 #include "Physics/Physics.h"
25 
26 
27 // Class OpalTravelingWave
28 // ------------------------------------------------------------------------
29 
31  OpalElement(SIZE, "TRAVELINGWAVE",
32  "The \"TRAVELINGWAVE\" element defines a traveling wave structure."),
33  owk_m(NULL) {
35  ("VOLT", "RF voltage in MV/m");
37  ("DVOLT", "RF voltage error in MV/m");
39  ("FREQ", "RF frequency in MHz");
41  ("LAG", "Phase lag in rad");
43  ("DLAG", "Phase lag error in rad");
45  ("HARMON", "Harmonic number");
47  ("BETRF", "beta_RF");
49  ("PG", "RF power in MW");
51  ("SHUNT", "Shunt impedance in MOhm");
53  ("TFILL", "Fill time in microseconds");
55  ("FMAPFN", "Filename for the fieldmap");
57  ("FAST", "Faster but less accurate", true);
59  ("APVETO", "Do not use this cavity in the Autophase procedure", false);
61  ("CAVITYTYPE", "STANDING or TRAVELING wave cavity in photoinjector and LINAC; SINGLEGAP or DOUBLEGAP cavity in cyclotron");
63  ("NUMCELLS", "Number of cells in a TW structure");
65  ("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
67  ("MODE", "The phase shift between neighboring cells in 2*pi", 1.0/3.0);
68 
69  registerRealAttribute("VOLT");
70  registerRealAttribute("DVOLT");
71  registerRealAttribute("FREQ");
72  registerRealAttribute("LAG");
73  registerRealAttribute("DLAG");
74  registerStringAttribute("FMAPFN");
75  registerStringAttribute("CAVITYTYPE");
76  registerRealAttribute("NUMCELLS");
77  registerRealAttribute("DESIGNENERGY");
78  registerRealAttribute("MODE");
79 
81 
82  setElement((new TravelingWaveRep("TRAVELINGWAVE"))->makeAlignWrapper());
83 }
84 
85 
87  OpalElement(name, parent),
88  owk_m(NULL) {
89  setElement((new TravelingWaveRep(name))->makeAlignWrapper());
90 }
91 
92 
94  if(owk_m)
95  delete owk_m;
96 }
97 
98 
100  return new OpalTravelingWave(name, this);
101 }
102 
103 
107 
108  if(flag != ERROR_FLAG) {
109  const TravelingWaveRep *rfc =
110  dynamic_cast<const TravelingWaveRep *>(base.removeWrappers());
111  attributeRegistry["VOLT"]->setReal(rfc->getAmplitude());
112  attributeRegistry["DVOLT"]->setReal(rfc->getAmplitudeError());
113  attributeRegistry["FREQ"]->setReal(rfc->getFrequency());
114  attributeRegistry["LAG"]->setReal(rfc->getPhase());
115  attributeRegistry["DLAG"]->setReal(rfc->getPhaseError());
116  attributeRegistry["FMAPFN"]->setString(rfc->getFieldMapFN());
117  }
118 }
119 
120 
122  using Physics::two_pi;
123 
125 
126  TravelingWaveRep *rfc =
127  dynamic_cast<TravelingWaveRep *>(getElement()->removeWrappers());
128 
129  double length = Attributes::getReal(itsAttr[LENGTH]);
130  double vPeak = Attributes::getReal(itsAttr[VOLT]);
131  double vPeakError = Attributes::getReal(itsAttr[DVOLT]);
132  double phase = Attributes::getReal(itsAttr[LAG]);
133  double phaseError = Attributes::getReal(itsAttr[DLAG]);
134  double freq = (1.0e6 * two_pi) * Attributes::getReal(itsAttr[FREQ]);
135  std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
136  bool fast = Attributes::getBool(itsAttr[FAST]);
137  bool apVeto = Attributes::getBool(itsAttr[APVETO]);
138 
139  // std::string type = Attributes::getString(itsAttr[TYPE]);
140  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
141 
142  rfc->setElementLength(length);
143  rfc->setAmplitude(1.0e6 * vPeak);
144  rfc->setFrequency(freq);
145  rfc->setPhase(phase);
146 
147  rfc->setFieldMapFN(fmapfm);
148  rfc->setFast(fast);
149  rfc->setAutophaseVeto(apVeto);
150  rfc->setAmplitudem(vPeak);
151  rfc->setAmplitudeError(vPeakError);
152  rfc->setFrequencym(freq);
153  rfc->setPhasem(phase);
154  rfc->setPhaseError(phaseError);
157  rfc->setDesignEnergy(kineticEnergy);
158 
159  if(itsAttr[WAKEF] && owk_m == NULL) {
160  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
161  owk_m->initWakefunction(*rfc);
162  rfc->setWake(owk_m->wf_m);
163  }
164 
165  // Transmit "unknown" attributes.
167 }
virtual std::string getFieldMapFN() const
Definition: RFCavity.h:368
virtual void setPhasem(double phase) override
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
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
Representation for a RF cavity.
constexpr double two_pi
The value of .
Definition: Physics.h:34
virtual ElementBase * removeWrappers()
Return the design element.
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:373
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual void setFrequencym(double freq)
Definition: RFCavity.h:398
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
void initWakefunction(ElementBase &element)
Definition: OpalWake.cpp:157
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
OpalTravelingWave()
Exemplar constructor.
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
The RFCAVITY element.
virtual double getAmplitudeError() const
Definition: RFCavity.h:388
virtual void setPhase(double phi)
Set phase.
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:136
void setNumCells(int NumCells)
Base class for all beam line elements.
Definition: OpalElement.h:41
virtual double getPhaseError() const
Definition: RFCavity.h:428
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 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 setFrequency(double f)
Set frequency.
virtual void setFast(bool fast)
Definition: RFCavity.h:443
virtual double getPhase() const
Get phase.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
void setMode(double mode)
virtual double getAmplitude() const
Get amplitude.
virtual OpalTravelingWave * clone(const std::string &name)
Make clone.
virtual double getFrequency() const
Get frequency.
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:423
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual void update()
Update the embedded CLASSIC cavity.
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:346
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
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
virtual void setAmplitude(double V)
Set amplitude.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307