OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OpalMultipoleT.cpp
Go to the documentation of this file.
1 //
2 // Class OpalMultipoleT
3 // The Opal MultipoleT element.
4 //
5 // Copyright (c) 2017 - 2023, Titus Dascalu
6 // 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 
21 #include "AbsBeamline/MultipoleT.h"
24 #include "Attributes/Attributes.h"
25 #include "Expressions/SValue.h"
26 #include "Expressions/SRefExpr.h"
27 #include "Physics/Units.h"
28 
29 #include <iostream>
30 #include <sstream>
31 #include <vector>
32 
33 
35  OpalElement(SIZE, "MULTIPOLET",
36  "The \"MULTIPOLET\" element defines a combined function multipole.") {
38  ("TP", "Transverse Profile derivatives in T m^(-k)");
39 
41  ("LFRINGE", "The length of the left end field [m]");
42 
44  ("RFRINGE", "The length of the right end field [m]");
45 
47  ("HAPERT", "The aperture width [m]");
48 
50  ("VAPERT", "The aperture height [m]");
51 
53  ("ANGLE", "The azimuthal angle of the magnet in ring [rad]");
54 
56  ("EANGLE", "The entrance angle [rad]");
57 
59  ("MAXFORDER", "Number of terms used in each field component");
60 
62  ("MAXXORDER", "Number of terms used in polynomial expansions");
63 
65  ("ROTATION", "Rotation angle about its axis for skew elements [rad]");
66 
68  ("VARRADIUS", "Set true if radius of magnet is variable");
69 
71  ("BBLENGTH", "Distance between centre of magnet and entrance [m]");
72 
74  setElement(new MultipoleT("MULTIPOLET"));
75 }
76 
77 
79  OpalMultipoleT* parent):
80  OpalElement(name, parent) {
81  setElement(new MultipoleT(name));
82 }
83 
84 
86 {}
87 
88 
90  return new OpalMultipoleT(name, this);
91 }
92 
93 
94 void OpalMultipoleT::print(std::ostream& os) const {
96 }
97 
98 
101 
102  MultipoleT* multT = dynamic_cast<MultipoleT*>(getElement());
103 
104  double length = Attributes::getReal(itsAttr[LENGTH]);
106  multT->setElementLength(length);
107  multT->setLength(length);
108  multT->setBendAngle(angle);
111  multT->setFringeField(Attributes::getReal(itsAttr[LENGTH]) * 0.5,
115  multT->setVarRadius();
116  }
118  const std::vector<double> transProfile = Attributes::getRealArray(itsAttr[TP]);
119  int transSize = transProfile.size();
120 
121  if (transSize == 0) {
122  multT->setTransMaxOrder(0);
123  } else {
124  multT->setTransMaxOrder(transSize - 1);
125  }
130 
131  for (int comp = 0; comp < transSize; comp++) {
132  double units = Units::T2kG * gsl_sf_pow_int(1.0, comp); // T m^-comp -> kG mm^-comp
133  multT->setTransProfile(comp, transProfile[comp] * units);
134  }
135  // Transmit "unknown" attributes.
137  multT->initialise();
138 
139  setElement(multT);
140 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
SDDS1 &description units
Definition: test.stat:6
item[EANGLE] Entrance edge angle(radians).\item[ROTATION] Rotation of the magnet about its central axis(radians
void setMaxXOrder(std::size_t maxXOrder)
Definition: MultipoleT.h:393
void setVarRadius()
Definition: MultipoleT.h:355
void setBoundingBoxLength(const double &boundingBoxLength)
Definition: MultipoleT.h:434
virtual OpalMultipoleT * clone(const std::string &name)
void setBendAngle(double angle)
Definition: MultipoleT.h:414
void setTransMaxOrder(std::size_t transMaxOrder)
Definition: MultipoleT.h:401
virtual void print(std::ostream &) const
Print the object.
constexpr double T2kG
Definition: Units.h:56
void setEntranceAngle(double entranceAngle)
Definition: MultipoleT.h:363
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
void setLength(double length)
Definition: MultipoleT.h:422
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
void setMaxOrder(std::size_t maxOrder)
Definition: MultipoleT.cpp:217
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
void setAperture(double vertAp, double horizAp)
Definition: MultipoleT.cpp:415
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void print(std::ostream &os) const
Print the object.
virtual ~OpalMultipoleT()
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
virtual void update()
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
bool setFringeField(double s0, double lambda_left, double lambda_right)
Definition: MultipoleT.cpp:248
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:419
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
void setTransProfile(std::size_t n, double Bn)
Definition: MultipoleT.cpp:240
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
void setRotation(double rot)
Definition: MultipoleT.h:410
void initialise(PartBunchBase< double, 3 > *, double &startField, double &endField) override
Definition: MultipoleT.cpp:542