OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
29 : OpalElement(SIZE, "RFCAVITY", "The \"RFCAVITY\" element defines an RF cavity."),
30 obgeo_m(nullptr) {
31 itsAttr[VOLT] = Attributes::makeReal("VOLT", "RF voltage in MV");
32 itsAttr[DVOLT] = Attributes::makeReal("DVOLT", "RF voltage error in MV");
33 itsAttr[FREQ] = Attributes::makeReal("FREQ", "RF frequency in MHz");
34 itsAttr[LAG] = Attributes::makeReal("LAG", "Phase lag (rad)");
35 itsAttr[DLAG] = Attributes::makeReal("DLAG", "Phase lag error (rad)");
36 itsAttr[FMAPFN] = Attributes::makeString("FMAPFN", "Filename of the fieldmap");
37 itsAttr[GEOMETRY] = Attributes::makeString("GEOMETRY", "BoundaryGeometry for Cavities");
38 itsAttr[FAST] = Attributes::makeBool("FAST", "Faster but less accurate", true);
40 "APVETO", "Do not use this cavity in the Autophase procedure", false);
41 itsAttr[RMIN] = Attributes::makeReal("RMIN", " Minimal Radius of a cyclotron cavity [mm]");
42 itsAttr[RMAX] = Attributes::makeReal("RMAX", " Maximal Radius of a cyclotron cavity [mm]");
43 itsAttr[ANGLE] = Attributes::makeReal("ANGLE", "Azimuth position of a cyclotron cavity [deg]");
45 "PDIS", "Shift distance of cavity gap from center of cyclotron [mm]");
46 itsAttr[GAPWIDTH] = Attributes::makeReal("GAPWIDTH", "Gap width of a cyclotron cavity [mm]");
47 itsAttr[PHI0] = Attributes::makeReal("PHI0", "Initial phase of cavity [deg]");
49 Attributes::makeReal("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
50 // attibutes for timedependent values
52 Attributes::makeString("PHASE_MODEL", "The name of the phase time dependence model.");
54 "AMPLITUDE_MODEL", "The name of the amplitude time dependence model.");
56 "FREQUENCY_MODEL", "The name of the frequency time dependence model.");
57
59
60 setElement(new RFCavityRep("RFCAVITY"));
61}
62
63OpalCavity::OpalCavity(const std::string& name, OpalCavity* parent)
64 : OpalElement(name, parent), obgeo_m(nullptr) {
65 setElement(new RFCavityRep(name));
66}
67
69
70OpalCavity* OpalCavity::clone(const std::string& name) { return new OpalCavity(name, this); }
71
74
75 RFCavityRep* rfc = dynamic_cast<RFCavityRep*>(getElement());
76
77 double length = Attributes::getReal(itsAttr[LENGTH]);
78 double peak = Attributes::getReal(itsAttr[VOLT]);
79 double peakError = Attributes::getReal(itsAttr[DVOLT]);
80 double phase = Attributes::getReal(itsAttr[LAG]);
81 double phaseError = Attributes::getReal(itsAttr[DLAG]);
83 std::string fmapfn = Attributes::getString(itsAttr[FMAPFN]);
84 std::string type = Attributes::getString(itsAttr[TYPE]);
85 bool fast = Attributes::getBool(itsAttr[FAST]);
86 bool apVeto = (Attributes::getBool(itsAttr[APVETO]));
87
88 double rmin = Attributes::getReal(itsAttr[RMIN]);
89 double rmax = Attributes::getReal(itsAttr[RMAX]);
90 double angle = Attributes::getReal(itsAttr[ANGLE]);
91 double pdis = Attributes::getReal(itsAttr[PDIS]);
92 double gapwidth = Attributes::getReal(itsAttr[GAPWIDTH]);
93 double phi0 = Attributes::getReal(itsAttr[PHI0]);
94 double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
95
96 rfc->setElementLength(length);
97
98 rfc->setAmplitude(Units::MVpm2Vpm * peak);
99 rfc->setFrequency(freq);
100 rfc->setPhase(phase);
101
102 rfc->dropFieldmaps();
103
104 rfc->setAmplitudem(peak);
105 rfc->setAmplitudeError(peakError);
106 rfc->setFrequencym(freq);
107 rfc->setPhasem(phase);
108 rfc->setPhaseError(phaseError);
109 rfc->setFieldMapFN(fmapfn);
110
111 rfc->setFast(fast);
112 rfc->setAutophaseVeto(apVeto);
113 rfc->setCavityType(type);
114 rfc->setRmin(rmin);
115 rfc->setRmax(rmax);
116 rfc->setAzimuth(angle);
117 rfc->setPerpenDistance(pdis);
118 rfc->setGapWidth(gapwidth);
119 rfc->setPhi0(phi0);
120 rfc->setDesignEnergy(kineticEnergy);
121
125
126 // Transmit "unknown" attributes.
128}
@ SIZE
Definition IndexMap.cpp:179
virtual void setElementLength(double length)
Set design length.
ElementBase * getElement() const
Return the embedded OPALX element.
Definition Element.h:119
void setElement(ElementBase *)
Assign new OPALX element.
Definition Element.h:123
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
virtual ~OpalCavity()
virtual OpalCavity * clone(const std::string &name)
Make clone.
virtual void update()
Update the embedded OPALX cavity.
@ AMPLITUDE_MODEL
Definition OpalCavity.h:47
@ FREQUENCY_MODEL
Definition OpalCavity.h:48
OpalCavity()
Exemplar constructor.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPALX) attributes to OPALX.
virtual void update()
Update the embedded OPALX element.
void registerOwnership() const
virtual void setPhase(double phi)
Set phase.
virtual void setFrequency(double f)
Set frequency.
virtual void setAmplitude(double V)
Set amplitude.
void setPerpenDistance(double pdis)
Definition RFCavity.cpp:297
virtual void setAmplitudeError(double vPeakError)
Definition RFCavity.h:333
void setPhaseModelName(std::string name)
Definition RFCavity.h:375
void setRmin(double rmin)
Definition RFCavity.cpp:291
void setFrequencyModelName(std::string name)
Definition RFCavity.h:383
void setAmplitudeModelName(std::string name)
Definition RFCavity.h:367
virtual void setAmplitudem(double vPeak)
Definition RFCavity.h:329
virtual void setPhaseError(double phaseError)
Definition RFCavity.h:349
virtual void setPhasem(double phase)
Definition RFCavity.h:343
void setPhi0(double phi0)
Definition RFCavity.cpp:301
virtual void setFrequencym(double freq)
Definition RFCavity.h:339
virtual void setFieldMapFN(const std::string &fmapfn)
Set the name of the field map.
Definition RFCavity.h:327
void setAzimuth(double angle)
Definition RFCavity.cpp:295
void setCavityType(const std::string &type)
Definition RFCavity.cpp:319
void dropFieldmaps()
Definition RFCavity.h:325
virtual void setAutophaseVeto(bool veto=true)
Definition RFCavity.h:359
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition RFCavity.h:321
void setGapWidth(double gapwidth)
Definition RFCavity.cpp:299
virtual void setFast(bool fast)
Definition RFCavity.h:355
void setRmax(double rmax)
Definition RFCavity.cpp:293
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:40
constexpr double MHz2Hz
Definition Units.h:113
constexpr double MVpm2Vpm
Definition Units.h:128