OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
OpalVariableRFCavityFringeField.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Chris Rogers
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
29
34#include "Physics/Physics.h"
35#include "Physics/Units.h"
38
39
41 std::string("The \"VARIABLE_RF_CAVITY_FRINGE_FIELD\" element defines an RF cavity ")+
42 std::string("with time dependent frequency, phase and amplitude.");
43
45 OpalElement(SIZE, "VARIABLE_RF_CAVITY_FRINGE_FIELD", doc_string.c_str()) {
47 "The name of the phase time dependence model, which should give the phase in [rad].");
49 "The name of the amplitude time dependence model, which should give the field in [MV/m]");
51 "The name of the frequency time dependence model, which should give the field in [MHz].");
53 "Full width of the cavity [m].");
55 "Full height of the cavity [m].");
57 "Length of the cavity field flat top [m].");
59 "Length of the cavity fringe fields [m].");
61 "Offset of the cavity centre from the beginning of the cavity [m].");
63 "Maximum power of y that will be evaluated in field calculations.");
64
66
67 setElement(new VariableRFCavityFringeField("VARIABLE_RF_CAVITY_FRINGE_FIELD"));
68}
69
71 const std::string &name,
73 ) : OpalElement(name, parent) {
74 VariableRFCavityFringeField *cavity = dynamic_cast
77}
78
80}
81
83 const std::string &name) {
84 return new OpalVariableRFCavityFringeField(name, this);
85}
86
88 return new OpalVariableRFCavityFringeField(this->getOpalName(), this);
89}
90
93
94 VariableRFCavityFringeField *cavity = dynamic_cast
96 double length = Attributes::getReal(itsAttr[LENGTH]);
97 cavity->setLength(length);
98 std::string phaseName = Attributes::getString(itsAttr[PHASE_MODEL]);
99 cavity->setPhaseName(phaseName);
100 std::string ampName = Attributes::getString(itsAttr[AMPLITUDE_MODEL]);
101 cavity->setAmplitudeName(ampName);
102 std::string freqName = Attributes::getString(itsAttr[FREQUENCY_MODEL]);
103 cavity->setFrequencyName(freqName);
104 double width = Attributes::getReal(itsAttr[WIDTH]);
105 cavity->setWidth(width);
106 double height = Attributes::getReal(itsAttr[HEIGHT]);
107 cavity->setHeight(height);
108 double maxOrderReal = Attributes::getReal(itsAttr[MAX_ORDER]);
109 size_t maxOrder = convertToUnsigned(maxOrderReal, "MAX_ORDER");
110 cavity->setMaxOrder(maxOrder);
111 double cavity_centre = Attributes::getReal(itsAttr[CAVITY_CENTRE]);
112 cavity->setCavityCentre(cavity_centre); // mm
113 // convert to mm; x0 is double length of flat top so divide 2
114 double centreLength = Attributes::getReal(itsAttr[CENTRE_LENGTH]) * Units::m2mm;
115 double endLength = Attributes::getReal(itsAttr[END_LENGTH]) * Units::m2mm;
116 endfieldmodel::Tanh* tanh = new endfieldmodel::Tanh(centreLength/2.,
117 endLength,
118 maxOrder+1);
119 std::shared_ptr<endfieldmodel::EndFieldModel> end(tanh);
120 cavity->setEndField(end);
121
122 setElement(cavity);
123}
124
125
127 std::string name) {
128 value += unsignedTolerance; // prevent rounding error
129 if (std::abs(std::floor(value) - value) > 2*unsignedTolerance) {
130 throw OpalException("OpalVariableRFCavityFringeField::convertToUnsigned",
131 "Value for "+name+
132 " should be an unsigned int but a real value was found");
133 }
134 if (std::floor(value) < -0.5) {
135 throw OpalException("OpalVariableRFCavityFringeField::convertToUnsigned",
136 "Value for "+name+" should be 0 or more");
137 }
138 size_t ret(std::floor(value));
139 return ret;
140}
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
Definition: TpsMath.h:240
@ SIZE
Definition: IndexMap.cpp:174
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:733
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
const std::string name
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
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 m2mm
Definition: Units.h:26
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 setPhaseName(std::string phase)
virtual void setHeight(double fullHeight)
virtual void setAmplitudeName(std::string amplitude)
virtual void setLength(double length)
virtual void setWidth(double fullWidth)
virtual void setFrequencyName(std::string frequency)
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.
void registerOwnership() const
static size_t convertToUnsigned(double value, std::string name)
OpalVariableRFCavityFringeField * clone()
The base class for all OPAL exceptions.
Definition: OpalException.h:28