OPAL (Object Oriented Parallel Accelerator Library) 2022.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
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 an RF cavity."),
33 owk_m(nullptr),
34 obgeo_m(nullptr) {
36 ("VOLT", "RF voltage in MV");
38 ("DVOLT", "RF voltage error in MV");
40 ("FREQ", "RF frequency in MHz");
42 ("LAG", "Phase lag (rad)");
44 ("DLAG", "Phase lag error (rad)");
46 ("FMAPFN", "Filename of the fieldmap");
48 ("GEOMETRY", "BoundaryGeometry for Cavities");
50 ("FAST", "Faster but less accurate", true);
52 ("APVETO", "Do not use this cavity in the Autophase procedure", false);
54 ("RMIN", " Minimal Radius of a cyclotron cavity [mm]");
56 ("RMAX", " Maximal Radius of a cyclotron cavity [mm]");
58 ("ANGLE", "Azimuth position of a cyclotron cavity [deg]");
60 ("PDIS", "Shift distance of cavity gap from center of cyclotron [mm]");
62 ("GAPWIDTH", "Gap width of a cyclotron cavity [mm]");
64 ("PHI0", "Initial phase of cavity [deg]");
66 ("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
67 // attibutes for timedependent values
69 "The name of the phase time dependence model.");
71 "The name of the amplitude time dependence model.");
73 "The name of the frequency time dependence model.");
74
76
77 setElement(new RFCavityRep("RFCAVITY"));
78}
79
80
81OpalCavity::OpalCavity(const std::string &name, OpalCavity *parent):
82 OpalElement(name, parent),
83 owk_m(nullptr),
84 obgeo_m(nullptr) {
86}
87
88
90 delete owk_m;
91}
92
93
94OpalCavity *OpalCavity::clone(const std::string &name) {
95 return new OpalCavity(name, this);
96}
97
98
101
102 RFCavityRep *rfc =
103 dynamic_cast<RFCavityRep *>(getElement());
104
105 double length = Attributes::getReal(itsAttr[LENGTH]);
106 double peak = Attributes::getReal(itsAttr[VOLT]);
107 double peakError = Attributes::getReal(itsAttr[DVOLT]);
108 double phase = Attributes::getReal(itsAttr[LAG]);
109 double phaseError = Attributes::getReal(itsAttr[DLAG]);
111 std::string fmapfn = Attributes::getString(itsAttr[FMAPFN]);
112 std::string type = Attributes::getString(itsAttr[TYPE]);
113 bool fast = Attributes::getBool(itsAttr[FAST]);
114 bool apVeto = (Attributes::getBool(itsAttr[APVETO]));
115
116 double rmin = Attributes::getReal(itsAttr[RMIN]);
117 double rmax = Attributes::getReal(itsAttr[RMAX]);
118 double angle = Attributes::getReal(itsAttr[ANGLE]);
119 double pdis = Attributes::getReal(itsAttr[PDIS]);
120 double gapwidth = Attributes::getReal(itsAttr[GAPWIDTH]);
121 double phi0 = Attributes::getReal(itsAttr[PHI0]);
122 double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
123
124 if(itsAttr[WAKEF] && owk_m == nullptr) {
125 owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
126 owk_m->initWakefunction(*rfc);
127 rfc->setWake(owk_m->wf_m);
128 }
129
130 if(itsAttr[GEOMETRY] && obgeo_m == nullptr) {
132 if(obgeo_m) {
134 }
135 }
136
137 rfc->setElementLength(length);
138
139 rfc->setAmplitude(Units::MVpm2Vpm * peak);
140 rfc->setFrequency(freq);
141 rfc->setPhase(phase);
142
143 rfc->dropFieldmaps();
144
145 rfc->setAmplitudem(peak);
146 rfc->setAmplitudeError(peakError);
147 rfc->setFrequencym(freq);
148 rfc->setPhasem(phase);
149 rfc->setPhaseError(phaseError);
150 rfc->setFieldMapFN(fmapfn);
151
152 rfc->setFast(fast);
153 rfc->setAutophaseVeto(apVeto);
154 rfc->setCavityType(type);
155 rfc->setRmin(rmin);
156 rfc->setRmax(rmax);
157 rfc->setAzimuth(angle);
158 rfc->setPerpenDistance(pdis);
159 rfc->setGapWidth(gapwidth);
160 rfc->setPhi0(phi0);
161 rfc->setDesignEnergy(kineticEnergy);
162
166
167 // Transmit "unknown" attributes.
169}
@ 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
constexpr double MHz2Hz
Definition: Units.h:113
constexpr double MVpm2Vpm
Definition: Units.h:128
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: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.
Definition: ElementBase.h:418
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:365
void setPhaseModelName(std::string name)
Definition: RFCavity.h:460
void setRmin(double rmin)
Definition: RFCavity.cpp:266
void setFrequencyModelName(std::string name)
Definition: RFCavity.h:475
void setAmplitudeModelName(std::string name)
Definition: RFCavity.h:445
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:355
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:405
virtual void setPhasem(double phase)
Definition: RFCavity.h:390
void setPhi0(double phi0)
Definition: RFCavity.cpp:286
virtual void setFrequencym(double freq)
Definition: RFCavity.h:380
virtual void setFieldMapFN(const std::string &fmapfn)
Set the name of the field map.
Definition: RFCavity.h:350
void setAzimuth(double angle)
Definition: RFCavity.cpp:274
void setCavityType(const std::string &type)
Definition: RFCavity.cpp:322
void dropFieldmaps()
Definition: RFCavity.h:345
virtual void setAutophaseVeto(bool veto=true)
Definition: RFCavity.h:430
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:335
void setGapWidth(double gapwidth)
Definition: RFCavity.cpp:282
virtual void setFast(bool fast)
Definition: RFCavity.h:420
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()
Definition: OpalCavity.cpp:89
virtual OpalCavity * clone(const std::string &name)
Make clone.
Definition: OpalCavity.cpp:94
virtual void update()
Update the embedded CLASSIC cavity.
Definition: OpalCavity.cpp:99
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:30
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:56
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:127
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:147