OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 
24 #include "Attributes/Attributes.h"
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 
70  const std::string& name,
72  OpalElement(name, parent) {
73  VariableRFCavityFringeField* cavity = dynamic_cast<VariableRFCavityFringeField*>(parent->getElement());
75 }
76 
78 }
79 
81  return new OpalVariableRFCavityFringeField(name, this);
82 }
83 
85  return new OpalVariableRFCavityFringeField(this->getOpalName(), this);
86 }
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 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
virtual void setEndField(std::shared_ptr< endfieldmodel::EndFieldModel > endField)
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
virtual void setFrequencyName(const std::string &frequency)
virtual void setWidth(double fullWidth)
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
virtual void setCavityCentre(double zCentre)
static size_t convertToUnsigned(double value, const std::string &name)
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
Definition: TpsMath.h:240
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual void setLength(double length)
virtual void setAmplitudeName(const std::string &amplitude)
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
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:310
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
const std::string name
OpalVariableRFCavityFringeField * clone()
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
virtual void setHeight(double fullHeight)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:733
virtual void setMaxOrder(size_t maxOrder)
virtual void setPhaseName(const std::string &phase)
end
Definition: multipole_t.tex:9
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const