OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OpalVariableRFCavityFringeField.cpp
Go to the documentation of this file.
1//
2// Class OpalVariableRFCavityFringeField
3// The class provides the user interface for
4// the VARIABLE_RF_CAVITY_FRINGE_FIELD object.
5//
6// Copyright (c) 2018 - 2023, Chris Rogers, STFC Rutherford Appleton Laboratory, Didcot, UK
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
20
26
27
29 std::string("The \"VARIABLE_RF_CAVITY_FRINGE_FIELD\" element defines an RF cavity ") +
30 std::string("with time dependent frequency, phase and amplitude.");
31
33 OpalElement(SIZE, "VARIABLE_RF_CAVITY_FRINGE_FIELD", doc_string.c_str()) {
35 ("PHASE_MODEL",
36 "The name of the phase time dependence model, which should give the phase in [rad].");
37
39 ("AMPLITUDE_MODEL",
40 "The name of the amplitude time dependence model, which should give the field in [MV/m].");
41
43 ("FREQUENCY_MODEL",
44 "The name of the frequency time dependence model, which should give the field in [MHz].");
45
47 ("WIDTH", "Full width of the cavity [m].");
48
50 ("HEIGHT", "Full height of the cavity [m].");
51
53 ("CENTRE_LENGTH", "Length of the cavity field flat top [m].");
54
56 ("END_LENGTH", "Length of the cavity fringe fields [m].");
57
59 ("CAVITY_CENTRE", "Offset of the cavity centre from the beginning of the cavity [m].");
60
62 ("MAX_ORDER", "Maximum power of y that will be evaluated in field calculations.");
63
65
66 setElement(new VariableRFCavityFringeField("VARIABLE_RF_CAVITY_FRINGE_FIELD"));
67}
68
76
79
83
87
90
92
93 double length = Attributes::getReal(itsAttr[LENGTH]);
94 cavity->setLength(length);
95
96 std::string phaseName = Attributes::getString(itsAttr[PHASE_MODEL]);
97 cavity->setPhaseName(phaseName);
98
99 std::string ampName = Attributes::getString(itsAttr[AMPLITUDE_MODEL]);
100 cavity->setAmplitudeName(ampName);
101
102 std::string freqName = Attributes::getString(itsAttr[FREQUENCY_MODEL]);
103 cavity->setFrequencyName(freqName);
104
105 double width = Attributes::getReal(itsAttr[WIDTH]);
106 cavity->setWidth(width);
107
108 double height = Attributes::getReal(itsAttr[HEIGHT]);
109 cavity->setHeight(height);
110
111 double maxOrderReal = Attributes::getReal(itsAttr[MAX_ORDER]);
112 size_t maxOrder = convertToUnsigned(maxOrderReal, "MAX_ORDER");
113 cavity->setMaxOrder(maxOrder);
114
115 double cavity_centre = Attributes::getReal(itsAttr[CAVITY_CENTRE]);
116 cavity->setCavityCentre(cavity_centre);
117
118 // x0 is double length of flat top so divide 2
119 double centreLength = Attributes::getReal(itsAttr[CENTRE_LENGTH]);
120 double endLength = Attributes::getReal(itsAttr[END_LENGTH]);
121 endfieldmodel::Tanh* tanh = new endfieldmodel::Tanh(centreLength / 2.,
122 endLength,
123 maxOrder + 1);
124 std::shared_ptr<endfieldmodel::EndFieldModel> end(tanh);
125 cavity->setEndField(end);
126
127 setElement(cavity);
128}
129
130
132 const std::string& name) {
133 value += unsignedTolerance; // prevent rounding error
134 if (std::abs(std::floor(value) - value) > 2*unsignedTolerance) {
135 throw OpalException("OpalVariableRFCavityFringeField::convertToUnsigned",
136 "Value for " + name +
137 " should be an unsigned int but a real value was found");
138 }
139 if (std::floor(value) < -0.5) {
140 throw OpalException("OpalVariableRFCavityFringeField::convertToUnsigned",
141 "Value for " + name + " should be 0 or more");
142 }
143 size_t ret(std::floor(value));
144 return ret;
145}
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
Definition TpsMath.h:240
const std::string name
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
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 setHeight(double fullHeight)
virtual void setPhaseName(const std::string &phase)
virtual void setAmplitudeName(const std::string &amplitude)
virtual void setLength(double length)
virtual void setFrequencyName(const std::string &frequency)
virtual void setWidth(double fullWidth)
virtual void setMaxOrder(size_t maxOrder)
virtual void setCavityCentre(double zCentre)
virtual void setEndField(std::shared_ptr< endfieldmodel::EndFieldModel > endField)
virtual void update()
Update the embedded CLASSIC element.
OpalElement(int size, const char *name, const char *help)
Exemplar constructor.
void registerOwnership() const
OpalVariableRFCavityFringeField(const std::string &name, OpalVariableRFCavityFringeField *parent)
OpalVariableRFCavityFringeField * clone()
static size_t convertToUnsigned(double value, const std::string &name)
The base class for all OPAL exceptions.