OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
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
99OpalCavity::OpalCavity(const std::string& name, OpalCavity* parent):
100 OpalElement(name, parent),
101 owk_m(nullptr),
102 obgeo_m(nullptr) {
104}
105
106
108 delete owk_m;
109}
110
111
112OpalCavity* 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
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}
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
bool getBool(const Attribute &attr)
Return logical value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
constexpr double two_pi
The value of.
Definition Physics.h:33
constexpr double mm2m
Definition Units.h:29
constexpr double MHz2Hz
Definition Units.h:113
constexpr double MVpm2Vpm
Definition Units.h:128
constexpr double deg2rad
Definition Units.h:143
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:310
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
virtual void setElementLength(double length)
Set design length.
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
void setPerpenDistance(double pdis)
Definition RFCavity.cpp:278
virtual void setAmplitudeError(double vPeakError)
Definition RFCavity.h:364
void setPhaseModelName(std::string name)
Definition RFCavity.h:459
void setRmin(double rmin)
Definition RFCavity.cpp:266
void setFrequencyModelName(std::string name)
Definition RFCavity.h:474
void setAmplitudeModelName(std::string name)
Definition RFCavity.h:444
virtual void setAmplitudem(double vPeak)
Definition RFCavity.h:354
virtual void setPhaseError(double phaseError)
Definition RFCavity.h:404
virtual void setPhasem(double phase)
Definition RFCavity.h:389
void setPhi0(double phi0)
Definition RFCavity.cpp:286
virtual void setFrequencym(double freq)
Definition RFCavity.h:379
virtual void setFieldMapFN(const std::string &fmapfn)
Set the name of the field map.
Definition RFCavity.h:349
void setAzimuth(double angle)
Definition RFCavity.cpp:274
void setCavityType(const std::string &type)
Definition RFCavity.cpp:332
void dropFieldmaps()
Definition RFCavity.h:344
virtual void setAutophaseVeto(bool veto=true)
Definition RFCavity.h:429
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition RFCavity.h:334
void setGapWidth(double gapwidth)
Definition RFCavity.cpp:282
virtual void setFast(bool fast)
Definition RFCavity.h:419
void setRmax(double rmax)
Definition RFCavity.cpp:270
virtual void setPhase(double phi)
Set phase.
virtual void setFrequency(double f)
Set frequency.
virtual void setAmplitude(double V)
Set amplitude.
virtual ~OpalCavity()
@ AMPLITUDE_MODEL
Definition OpalCavity.h:49
@ FREQUENCY_MODEL
Definition OpalCavity.h:50
virtual OpalCavity * clone(const std::string &name)
Make clone.
virtual void update()
Update the embedded CLASSIC cavity.
BoundaryGeometry * obgeo_m
Definition OpalCavity.h:76
OpalCavity()
Exemplar constructor.
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.
OpalElement(int size, const char *name, const char *help)
Exemplar constructor.
void registerOwnership() const
static BoundaryGeometry * find(const std::string &name)
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition OpalWake.cpp:127