OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 
28 #include "Physics/Physics.h"
30 #include "Attributes/Attributes.h"
36 
37 
39  std::string("The \"VARIABLE_RF_CAVITY_FRINGE_FIELD\" element defines an RF cavity ")+
40  std::string("with time dependent frequency, phase and amplitude.");
41 
43  OpalElement(SIZE, "VARIABLE_RF_CAVITY_FRINGE_FIELD", doc_string.c_str()) {
45  "The name of the phase time dependence model, which should give the phase in [rad].");
46  itsAttr[AMPLITUDE_MODEL] = Attributes::makeString("AMPLITUDE_MODEL",
47  "The name of the amplitude time dependence model, which should give the field in [MV/m]");
48  itsAttr[FREQUENCY_MODEL] = Attributes::makeString("FREQUENCY_MODEL",
49  "The name of the frequency time dependence model, which should give the field in [MHz].");
51  "Full width of the cavity [m].");
53  "Full height of the cavity [m].");
54  itsAttr[CENTRE_LENGTH] = Attributes::makeReal("CENTRE_LENGTH",
55  "Length of the cavity field flat top [m].");
56  itsAttr[END_LENGTH] = Attributes::makeReal("END_LENGTH",
57  "Length of the cavity fringe fields [m].");
58  itsAttr[CAVITY_CENTRE] = Attributes::makeReal("CAVITY_CENTRE",
59  "Offset of the cavity centre from the beginning of the cavity [m].");
60  itsAttr[MAX_ORDER] = Attributes::makeReal("MAX_ORDER",
61  "Maximum power of y that will be evaluated in field calculations.");
62 
64 
65  setElement(new VariableRFCavityFringeField("VARIABLE_RF_CAVITY_FRINGE_FIELD"));
66 }
67 
69  const std::string &name,
71  ) : OpalElement(name, parent) {
72  VariableRFCavityFringeField *cavity = dynamic_cast
75 }
76 
78 }
79 
81  const std::string &name) {
82  return new OpalVariableRFCavityFringeField(name, this);
83 }
84 
86  return new OpalVariableRFCavityFringeField(this->getOpalName(), this);
87 }
88 
91 
92  VariableRFCavityFringeField *cavity = dynamic_cast
94  double length = Attributes::getReal(itsAttr[LENGTH]);
95  cavity->setLength(length);
96  std::string phaseName = Attributes::getString(itsAttr[PHASE_MODEL]);
97  cavity->setPhaseName(phaseName);
98  std::string ampName = Attributes::getString(itsAttr[AMPLITUDE_MODEL]);
99  cavity->setAmplitudeName(ampName);
100  std::string freqName = Attributes::getString(itsAttr[FREQUENCY_MODEL]);
101  cavity->setFrequencyName(freqName);
102  double width = Attributes::getReal(itsAttr[WIDTH]);
103  cavity->setWidth(width);
104  double height = Attributes::getReal(itsAttr[HEIGHT]);
105  cavity->setHeight(height);
106  double maxOrderReal = Attributes::getReal(itsAttr[MAX_ORDER]);
107  size_t maxOrder = convertToUnsigned(maxOrderReal, "MAX_ORDER");
108  cavity->setMaxOrder(maxOrder);
109  double cavity_centre = Attributes::getReal(itsAttr[CAVITY_CENTRE]);
110  cavity->setCavityCentre(cavity_centre); // mm
111  // convert to mm; x0 is double length of flat top so divide 2
112  double centreLength = Attributes::getReal(itsAttr[CENTRE_LENGTH])*1e3;
113  double endLength = Attributes::getReal(itsAttr[END_LENGTH])*1e3;
114  endfieldmodel::Tanh* tanh = new endfieldmodel::Tanh(centreLength/2.,
115  endLength,
116  maxOrder+1);
117  std::shared_ptr<endfieldmodel::EndFieldModel> end(tanh);
118  cavity->setEndField(end);
119 
120  setElement(cavity);
121 }
122 
123 
125  std::string name) {
126  value += unsignedTolerance; // prevent rounding error
127  if (std::abs(std::floor(value) - value) > 2*unsignedTolerance) {
128  throw OpalException("OpalVariableRFCavityFringeField::convertToUnsigned",
129  "Value for "+name+
130  " should be an unsigned int but a real value was found");
131  }
132  if (std::floor(value) < -0.5) {
133  throw OpalException("OpalVariableRFCavityFringeField::convertToUnsigned",
134  "Value for "+name+" should be 0 or more");
135  }
136  size_t ret(std::floor(value));
137  return ret;
138 }
@ SIZE
Definition: IndexMap.cpp:174
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
Definition: TpsMath.h:240
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:733
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
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:281
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