OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalVerticalFFAMagnet.cpp
Go to the documentation of this file.
1 //
2 // Source file for OpalVerticalFFAMagnet Element
3 //
4 // Copyright (c) 2019 Chris Rogers
5 // All rights reserved.
6 //
7 // OPAL is licensed under GNU GPL version 3.
8 
9 
10 #include "Attributes/Attributes.h"
11 
12 #include "AbsBeamline/EndFieldModel/Tanh.h" // classic
13 #include "AbsBeamline/VerticalFFAMagnet.h" // classic
15 
17  std::string("The \"VerticalFFAMagnet\" element defines a vertical FFA ")+
18  std::string("magnet, which has a field that increases in the vertical ")+
19  std::string("direction while maintaining similar orbits.");
21  OpalElement(SIZE, "VERTICALFFAMAGNET", docstring_m.c_str()) {
23  ("B0", "The nominal dipole field of the magnet at zero height [T].");
24  itsAttr[FIELD_INDEX] = Attributes::makeReal("FIELD_INDEX",
25  "Exponent term in the field index [m^(-1)].");
27  "The full width of the magnet. Particles moving more than WIDTH/2 horizontally, in either direction, are out of the aperture.");
28  itsAttr[MAX_HORIZONTAL_POWER] = Attributes::makeReal("MAX_HORIZONTAL_POWER",
29  "The maximum power in horizontal coordinate that will be considered in the field expansion.");
30  itsAttr[END_LENGTH] = Attributes::makeReal("END_LENGTH",
31  "The end length of the FFA fringe field [m].");
32  itsAttr[CENTRE_LENGTH] = Attributes::makeReal("CENTRE_LENGTH",
33  "The centre length of the FFA (i.e. length of the flat top) [m].");
34  itsAttr[BB_LENGTH] = Attributes::makeReal("BB_LENGTH",
35  "Determines the length of the bounding box. Magnet is situated symmetrically in the bounding box. [m]");
36  itsAttr[HEIGHT_POS_EXTENT] = Attributes::makeReal("HEIGHT_POS_EXTENT",
37  "Height of the magnet above z=0. Particles moving upwards more than HEIGHT_POS_EXTENT are out of the aperture [m].");
38  itsAttr[HEIGHT_NEG_EXTENT] = Attributes::makeReal("HEIGHT_NEG_EXTENT",
39  "Height of the magnet below z=0. Particles moving downwards more than HEIGHT_NEG_EXTENT are out of the aperture [m].");
41  registerRealAttribute("FIELD_INDEX");
42  registerRealAttribute("WIDTH");
43  registerRealAttribute("MAX_HORIZONTAL_POWER");
44  registerRealAttribute("END_LENGTH");
45  registerRealAttribute("CENTRE_LENGTH");
46  registerRealAttribute("BB_LENGTH");
47  registerRealAttribute("HEIGHT_NEG_EXTENT");
48  registerRealAttribute("HEIGHT_POS_EXTENT");
50 
51  VerticalFFAMagnet* magnet = new VerticalFFAMagnet("VerticalFFAMagnet");
52  magnet->setEndField(new endfieldmodel::Tanh(1., 1., 1));
53  setElement(magnet->makeAlignWrapper());
54 }
55 
56 
58  OpalVerticalFFAMagnet *parent) :
59  OpalElement(name, parent) {
60  VerticalFFAMagnet* magnet = new VerticalFFAMagnet(name);
61  magnet->setEndField(new endfieldmodel::Tanh(1., 1., 1));
62  setElement(magnet->makeAlignWrapper());
63 }
64 
65 
67 }
68 
69 
71  return new OpalVerticalFFAMagnet(name, this);
72 }
73 
74 
78 }
79 
80 
82  VerticalFFAMagnet *magnet =
83  dynamic_cast<VerticalFFAMagnet*>(getElement()->removeWrappers());
86  magnet->setMaxOrder(maxOrder);
92 
93  // get centre length and end length in radians
94  endfieldmodel::Tanh* endField = dynamic_cast<endfieldmodel::Tanh*>(magnet->getEndField());
95  double mm = 1e3;
96  double end_length = Attributes::getReal(itsAttr[END_LENGTH])*mm;
97  double centre_length = Attributes::getReal(itsAttr[CENTRE_LENGTH])*mm/2.;
98  endField->setLambda(end_length);
99  // x0 is the distance between B=0.5*B0 and B=B0 i.e. half the centre length
100  endField->setX0(centre_length/2.);
101  endField->setTanhDiffIndices(maxOrder+2);
102  magnet->initialise();
103  setElement(magnet->makeAlignWrapper());
104 }
static void setTanhDiffIndices(size_t n)
Definition: Tanh.cpp:76
void setWidth(double width)
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
void setFieldIndex(double index)
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
static std::string docstring_m
void setEndField(endfieldmodel::EndFieldModel *endField)
virtual ElementBase * removeWrappers()
Return the design element.
void setMaxOrder(size_t maxOrder)
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
void setBBLength(double bbLength)
void setPositiveVerticalExtent(double positiveExtent)
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
void setLambda(double lambda)
Definition: Tanh.h:98
Base class for all beam line elements.
Definition: OpalElement.h:41
virtual OpalVerticalFFAMagnet * clone(const std::string &name)
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void setNegativeVerticalExtent(double negativeExtent)
void registerOwnership() const
void setX0(double x0)
Definition: Tanh.h:101
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
const std::string name
virtual ElementBase * makeAlignWrapper()
Allow misalignment.
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField)
void setB0(double Bz)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:816
endfieldmodel::EndFieldModel * getEndField() const