OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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"
19 
22 #include "Attributes/Attributes.h"
24 #include "Physics/Physics.h"
25 #include "Physics/Units.h"
27 #include "Structure/OpalWake.h"
28 
29 
31  OpalElement(SIZE, "RFCAVITY",
32  "The \"RFCAVITY\" element defines a RF cavity"),
33  owk_m(nullptr),
34  obgeo_m(nullptr) {
36  ("VOLT", "RF voltage [MV]");
37 
39  ("DVOLT", "RF voltage error [MV]");
40 
42  ("FREQ", "RF frequency [MHz]");
43 
45  ("LAG", "Phase lag [rad]");
46 
48  ("DLAG", "Phase lag error [rad]");
49 
51  ("FMAPFN", "Filename of the fieldmap");
52 
54  ("GEOMETRY", "BoundaryGeometry for Cavities");
55 
57  ("FAST", "Faster but less accurate (default=true)", true);
58 
60  ("APVETO", "Do not use this cavity in the Autophase procedure (default=false)", false);
61 
63  ("RMIN", "Minimal Radius of a cyclotron cavity [mm]");
64 
66  ("RMAX", "Maximal Radius of a cyclotron cavity [mm]");
67 
69  ("ANGLE", "Azimuth position of a cyclotron cavity [deg]");
70 
72  ("PDIS", "Shift distance of cavity gap from center of cyclotron [mm]");
73 
75  ("GAPWIDTH", "Gap width of a cyclotron cavity [mm]");
76 
78  ("PHI0", "Initial phase of cavity [deg]");
79 
81  ("DESIGNENERGY", "The mean energy of the particles at exit", -1.0);
82 
83  // attibutes for timedependent values
85  ("PHASE_MODEL", "The name of the phase time dependence model");
86 
88  ("AMPLITUDE_MODEL", "The name of the amplitude time dependence model");
89 
91  ("FREQUENCY_MODEL", "The name of the frequency time dependence model");
92 
94 
95  setElement(new RFCavityRep("RFCAVITY"));
96 }
97 
98 
99 OpalCavity::OpalCavity(const std::string& name, OpalCavity* parent):
100  OpalElement(name, parent),
101  owk_m(nullptr),
102  obgeo_m(nullptr) {
103  setElement(new RFCavityRep(name));
104 }
105 
106 
108  delete owk_m;
109 }
110 
111 
112 OpalCavity* OpalCavity::clone(const std::string& name) {
113  return new OpalCavity(name, this);
114 }
115 
116 
119 
120  RFCavityRep* rfc = dynamic_cast<RFCavityRep*>(getElement());
121 
122  double length = Attributes::getReal(itsAttr[LENGTH]);
123 
124  double peak = Attributes::getReal(itsAttr[VOLT]);
125  double peakError = Attributes::getReal(itsAttr[DVOLT]);
126 
127  double phase = Attributes::getReal(itsAttr[LAG]);
128  double phaseError = Attributes::getReal(itsAttr[DLAG]);
129 
131 
132  std::string fmapfn = Attributes::getString(itsAttr[FMAPFN]);
133  std::string type = Attributes::getString(itsAttr[TYPE]);
134 
135  bool fast = Attributes::getBool(itsAttr[FAST]);
136  bool apVeto = (Attributes::getBool(itsAttr[APVETO]));
137 
138  double rmin = Units::mm2m * Attributes::getReal(itsAttr[RMIN]);
139  double rmax = Units::mm2m * Attributes::getReal(itsAttr[RMAX]);
141  double pdis = Units::mm2m * Attributes::getReal(itsAttr[PDIS]);
142  double gapwidth = Units::mm2m * Attributes::getReal(itsAttr[GAPWIDTH]);
144  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
145 
146  if(itsAttr[WAKEF] && owk_m == nullptr) {
147  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
148  owk_m->initWakefunction(*rfc);
149  rfc->setWake(owk_m->wf_m);
150  }
151 
152  if(itsAttr[GEOMETRY] && obgeo_m == nullptr) {
154  if(obgeo_m) {
156  }
157  }
158 
159  rfc->setElementLength(length);
160 
161  rfc->setAmplitude(Units::MVpm2Vpm * peak);
162  rfc->setFrequency(freq);
163  rfc->setPhase(phase);
164 
165  rfc->dropFieldmaps();
166 
167  rfc->setAmplitudem(peak);
168  rfc->setAmplitudeError(peakError);
169  rfc->setFrequencym(freq);
170  rfc->setPhasem(phase);
171  rfc->setPhaseError(phaseError);
172  rfc->setFieldMapFN(fmapfn);
173 
174  rfc->setFast(fast);
175  rfc->setAutophaseVeto(apVeto);
176  rfc->setCavityType(type);
177  rfc->setRmin(rmin);
178  rfc->setRmax(rmax);
179  rfc->setAzimuth(angle);
180  rfc->setPerpenDistance(pdis);
181  rfc->setGapWidth(gapwidth);
182  rfc->setPhi0(phi0);
183  rfc->setDesignEnergy(kineticEnergy);
184 
188 
189  // Transmit "unknown" attributes.
191 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
BoundaryGeometry * obgeo_m
Definition: OpalCavity.h:76
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
virtual void setFast(bool fast)
Definition: RFCavity.h:419
WakeFunction * wf_m
Definition: OpalWake.h:56
virtual void setFrequencym(double freq)
Definition: RFCavity.h:379
item[EANGLE] Entrance edge angle(radians).\item[ROTATION] Rotation of the magnet about its central axis(radians
void setPhaseModelName(std::string name)
Definition: RFCavity.h:459
constexpr double MVpm2Vpm
Definition: Units.h:128
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
constexpr double two_pi
The value of .
Definition: Physics.h:33
virtual void setPhase(double phi)
Set phase.
void setCavityType(const std::string &type)
Definition: RFCavity.cpp:332
void setRmax(double rmax)
Definition: RFCavity.cpp:270
virtual void setAmplitude(double V)
Set amplitude.
OpalWake * owk_m
Definition: OpalCavity.h:74
void setAmplitudeModelName(std::string name)
Definition: RFCavity.h:444
void setAzimuth(double angle)
Definition: RFCavity.cpp:274
static BoundaryGeometry * find(const std::string &name)
virtual void setFieldMapFN(const std::string &fmapfn)
Set the name of the field map.
Definition: RFCavity.h:349
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
constexpr double deg2rad
Definition: Units.h:143
constexpr double mm2m
Definition: Units.h:29
void setGapWidth(double gapwidth)
Definition: RFCavity.cpp:282
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:354
void setRmin(double rmin)
Definition: RFCavity.cpp:266
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
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:147
OpalCavity()
Exemplar constructor.
Definition: OpalCavity.cpp:30
void setFrequencyModelName(std::string name)
Definition: RFCavity.h:474
virtual void setAutophaseVeto(bool veto=true)
Definition: RFCavity.h:429
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:310
virtual void setFrequency(double f)
Set frequency.
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
void setPerpenDistance(double pdis)
Definition: RFCavity.cpp:278
virtual ~OpalCavity()
Definition: OpalCavity.cpp:107
const std::string name
constexpr double MHz2Hz
Definition: Units.h:113
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:334
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:419
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
void setPhi0(double phi0)
Definition: RFCavity.cpp:286
virtual void setAmplitudeError(double vPeakError)
Definition: RFCavity.h:364
void dropFieldmaps()
Definition: RFCavity.h:344
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:404
virtual void update()
Update the embedded CLASSIC cavity.
Definition: OpalCavity.cpp:117
virtual OpalCavity * clone(const std::string &name)
Make clone.
Definition: OpalCavity.cpp:112
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:127
SDDS1 &description type
Definition: test.stat:4
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
virtual void setPhasem(double phase)
Definition: RFCavity.h:389