OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalCavity.cpp
Go to the documentation of this file.
1 //
2 // Class OpalCavity
3 // The RFCAVITY 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/OpalCavity.h"
20 #include "Attributes/Attributes.h"
23 #include "Structure/OpalWake.h"
25 #include "Physics/Physics.h"
26 
27 
29  OpalElement(SIZE, "RFCAVITY",
30  "The \"RFCAVITY\" element defines an RF cavity."),
31  owk_m(NULL),
32  obgeo_m(NULL) {
34  ("VOLT", "RF voltage in MV");
36  ("DVOLT", "RF voltage error in MV");
38  ("FREQ", "RF frequency in MHz");
40  ("LAG", "Phase lag (rad)");
42  ("DLAG", "Phase lag error (rad)");
44  ("FMAPFN", "Filename of the fieldmap");
46  ("GEOMETRY", "BoundaryGeometry for Cavities");
48  ("FAST", "Faster but less accurate", true);
50  ("APVETO", "Do not use this cavity in the Autophase procedure", false);
52  ("RMIN", " Minimal Radius of a cyclotron cavity [mm]");
54  ("RMAX", " Maximal Radius of a cyclotron cavity [mm]");
56  ("ANGLE", "Azimuth position of a cyclotron cavity [deg]");
58  ("PDIS", "Shift distance of cavity gap from center of cyclotron [mm]");
60  ("GAPWIDTH", "Gap width of a cyclotron cavity [mm]");
62  ("PHI0", "Initial phase of cavity [deg]");
64  ("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
65  // attibutes for timedependent values
67  "The name of the phase time dependence model.");
68  itsAttr[AMPLITUDE_MODEL] = Attributes::makeString("AMPLITUDE_MODEL",
69  "The name of the amplitude time dependence model.");
70  itsAttr[FREQUENCY_MODEL] = Attributes::makeString("FREQUENCY_MODEL",
71  "The name of the frequency time dependence model.");
72 
74 
75  setElement(new RFCavityRep("RFCAVITY"));
76 }
77 
78 
79 OpalCavity::OpalCavity(const std::string &name, OpalCavity *parent):
80  OpalElement(name, parent),
81  owk_m(NULL),
82  obgeo_m(NULL) {
84 }
85 
86 
88  delete owk_m;
89 }
90 
91 
92 OpalCavity *OpalCavity::clone(const std::string &name) {
93  return new OpalCavity(name, this);
94 }
95 
96 
99 
100  RFCavityRep *rfc =
101  dynamic_cast<RFCavityRep *>(getElement());
102 
103  double length = Attributes::getReal(itsAttr[LENGTH]);
104  double peak = Attributes::getReal(itsAttr[VOLT]);
105  double peakError = Attributes::getReal(itsAttr[DVOLT]);
106  double phase = Attributes::getReal(itsAttr[LAG]);
107  double phaseError = Attributes::getReal(itsAttr[DLAG]);
108  double freq = 1e6 * Physics::two_pi * Attributes::getReal(itsAttr[FREQ]);
109  std::string fmapfn = Attributes::getString(itsAttr[FMAPFN]);
110  std::string type = Attributes::getString(itsAttr[TYPE]);
111  bool fast = Attributes::getBool(itsAttr[FAST]);
112  bool apVeto = (Attributes::getBool(itsAttr[APVETO]));
113 
114  double rmin = Attributes::getReal(itsAttr[RMIN]);
115  double rmax = Attributes::getReal(itsAttr[RMAX]);
116  double angle = Attributes::getReal(itsAttr[ANGLE]);
117  double pdis = Attributes::getReal(itsAttr[PDIS]);
118  double gapwidth = Attributes::getReal(itsAttr[GAPWIDTH]);
119  double phi0 = Attributes::getReal(itsAttr[PHI0]);
120  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
121 
122  if(itsAttr[WAKEF] && owk_m == NULL) {
123  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
124  owk_m->initWakefunction(*rfc);
125  rfc->setWake(owk_m->wf_m);
126  }
127 
128  if(itsAttr[GEOMETRY] && obgeo_m == NULL) {
130  if(obgeo_m) {
132  }
133  }
134 
135  rfc->setElementLength(length);
136 
137  rfc->setAmplitude(1e6 * peak);
138  rfc->setFrequency(freq);
139  rfc->setPhase(phase);
140 
141  rfc->dropFieldmaps();
142 
143  rfc->setAmplitudem(peak);
144  rfc->setAmplitudeError(peakError);
145  rfc->setFrequencym(freq);
146  rfc->setPhasem(phase);
147  rfc->setPhaseError(phaseError);
148  rfc->setFieldMapFN(fmapfn);
149 
150  rfc->setFast(fast);
151  rfc->setAutophaseVeto(apVeto);
152  rfc->setCavityType(type);
153  rfc->setComponentType(type);
154  rfc->setRmin(rmin);
155  rfc->setRmax(rmax);
156  rfc->setAzimuth(angle);
157  rfc->setPerpenDistance(pdis);
158  rfc->setGapWidth(gapwidth);
159  rfc->setPhi0(phi0);
160  rfc->setDesignEnergy(kineticEnergy);
161 
165 
166  // Transmit "unknown" attributes.
168 }
@ SIZE
Definition: IndexMap.cpp:174
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
constexpr double two_pi
The value of.
Definition: Physics.h:33
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:281
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:436
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
void setCavityType(std::string type)
Definition: RFCavity.h:428
void setPerpenDistance(double pdis)
Definition: RFCavity.cpp:281
virtual void setAmplitudeError(double vPeakError)
Definition: RFCavity.h:378
void setPhaseModelName(std::string name)
Definition: RFCavity.h:478
void setRmin(double rmin)
Definition: RFCavity.cpp:269
void setFrequencyModelName(std::string name)
Definition: RFCavity.h:493
void setAmplitudeModelName(std::string name)
Definition: RFCavity.h:463
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:368
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:418
virtual void setPhasem(double phase)
Definition: RFCavity.h:403
virtual void setComponentType(std::string name) override
Definition: RFCavity.cpp:325
void setPhi0(double phi0)
Definition: RFCavity.cpp:289
virtual void setFrequencym(double freq)
Definition: RFCavity.h:393
void setAzimuth(double angle)
Definition: RFCavity.cpp:277
void dropFieldmaps()
Definition: RFCavity.h:353
virtual void setAutophaseVeto(bool veto=true)
Definition: RFCavity.h:448
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:343
void setGapWidth(double gapwidth)
Definition: RFCavity.cpp:285
virtual void setFast(bool fast)
Definition: RFCavity.h:438
void setRmax(double rmax)
Definition: RFCavity.cpp:273
virtual void setFieldMapFN(std::string fmapfn)
Set the name of the field map.
Definition: RFCavity.h:358
virtual void setPhase(double phi)
Set phase.
virtual void setFrequency(double f)
Set frequency.
virtual void setAmplitude(double V)
Set amplitude.
virtual ~OpalCavity()
Definition: OpalCavity.cpp:87
virtual OpalCavity * clone(const std::string &name)
Make clone.
Definition: OpalCavity.cpp:92
virtual void update()
Update the embedded CLASSIC cavity.
Definition: OpalCavity.cpp:97
BoundaryGeometry * obgeo_m
Definition: OpalCavity.h:76
@ AMPLITUDE_MODEL
Definition: OpalCavity.h:49
@ FREQUENCY_MODEL
Definition: OpalCavity.h:50
@ DESIGNENERGY
Definition: OpalCavity.h:47
OpalCavity()
Exemplar constructor.
Definition: OpalCavity.cpp:28
OpalWake * owk_m
Definition: OpalCavity.h:74
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
static BoundaryGeometry * find(const std::string &name)
WakeFunction * wf_m
Definition: OpalWake.h:57
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:125
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:146