OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalMultipoleT.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2026, Paul Scherrer Institute, Villigen PSI, Switzerland
3// All rights reserved
4//
5// This file is part of OPAL.
6//
7// OPAL is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// You should have received a copy of the GNU General License
13// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
14//
15
17#include <vector>
20
23 SIZE, "MULTIPOLET",
24 "The \"MULTIPOLET\" element defines a combined function multipole.") {
25 // Attributes for a straight multipole
27 "TP",
28 "Array of multipolar field strengths b_k. The field generated in the "
29 "flat top is B = b_k x^k [T m^(-k)]");
30 itsAttr[LFRINGE] = Attributes::makeReal("LFRINGE", "The length of the left end field [m]");
31 itsAttr[RFRINGE] = Attributes::makeReal("RFRINGE", "The length of the right end field [m]");
32 itsAttr[HAPERT] = Attributes::makeReal("HAPERT", "The aperture width [m]");
33 itsAttr[VAPERT] = Attributes::makeReal("VAPERT", "The aperture height [m]");
35 "MAXFORDER", "Number of terms used in each fringe component", DefaultMAXFORDER);
37 "ROTATION", "Rotation angle about its axis for skew elements [rad]");
38 itsAttr[EANGLE] = Attributes::makeReal("EANGLE", "The entrance angle [rad]");
40 Attributes::makeReal("BBLENGTH", "Distance between centre of magnet and entrance [m]");
41
42 // Further attributes for a constant radius curved multipole
43 itsAttr[ANGLE] =
44 Attributes::makeReal("ANGLE", "The azimuthal angle of the magnet in ring [rad]", 0.0);
46 "MAXXORDER", "Number of terms used in polynomial expansions", DefaultMAXXORDER);
47
48 // Further attributes for a variable radius multipole
50 Attributes::makeBool("VARRADIUS", "Set true if radius of magnet is variable", false);
52 "ENTRYOFFSET", "Longitudinal offset from standard entrance point [m]", 0.0);
53
54 // Time dependence attributes
56 "SCALING_MODEL",
57 "The name of the time dependence model, which should give a scaling factor.");
58
59 // Misalignment attributes
60 itsAttr[MISALIGN_H] = Attributes::makeReal("MISALIGN_H", "Horizontal misalignment [m]", 0.0);
61 itsAttr[MISALIGN_V] = Attributes::makeReal("MISALIGN_V", "Vertical misalignment [m]", 0.0);
62 itsAttr[MISALIGN_S] = Attributes::makeReal("MISALIGN_S", "Longitudinal misalignment [m]", 0.0);
64 "MISALIGN_ROLL", "Roll misalignment [rad] about the longitudinal axis", 0.0);
66 "MISALIGN_PITCH", "Pitch misalignment [rad] about the horizontal axis", 0.0);
68 "MISALIGN_YAW", "Yaw misalignment [rad] about the vertical axis", 0.0);
70 Attributes::makeReal("MISALIGN_AXISOFFSET", "Vertical offset of roll axis [m]", 0.0);
71
73 setElement(new MultipoleT("MULTIPOLET"));
74}
75
76OpalMultipoleT::OpalMultipoleT(const std::string& name, OpalMultipoleT* parent)
77 : OpalElement(name, parent) {
78 setElement(new MultipoleT(name));
79}
80
81OpalMultipoleT* OpalMultipoleT::clone(const std::string& name) {
82 return new OpalMultipoleT(name, this);
83}
84
85void OpalMultipoleT::print(std::ostream& os) const { OpalElement::print(os); }
86
88 // Base class first
90 // Make some sanity checks
91 const auto maxFOrder = Attributes::getReal(itsAttr[MAXFORDER]);
92 if (maxFOrder < MinimumMAXFORDER) {
93 throw OpalException("OpalMultipoleT::Update", "Attribute MAXFORDER must be >= 1.0");
94 }
95 if (maxFOrder > MaximumMAXFORDER) {
96 throw OpalException("OpalMultipoleT::Update", "Attribute MAXFORDER must be <= 9.0");
97 }
98 const double rotation = Attributes::getReal(itsAttr[ROTATION]);
99 const double bendAngle = Attributes::getReal(itsAttr[ANGLE]);
100 if (bendAngle != 0.0 && rotation != 0.0) {
101 throw OpalException(
102 "OpalMultipoleT::Update",
103 "Non-zero ROTATION (a skew multipole) is only "
104 "supported for straight magnets");
105 }
106 const bool varRadius = Attributes::getBool(itsAttr[VARRADIUS]);
107 if (varRadius && bendAngle != 0.0) {
108 throw OpalException("OpalMultipoleT::Update", "Variable radius is not currently supported");
109 }
110 const double entryOffset = Attributes::getReal(itsAttr[ENTRYOFFSET]);
111 if (!varRadius && entryOffset != 0.0) {
112 throw OpalException(
113 "OpalMultipoleT::Update",
114 "The ENTRYOFFSET is only supported for variable radius curved magnets");
115 }
117 // Set the attributes
118 const auto length = Attributes::getReal(itsAttr[LENGTH]);
119 auto* multT = dynamic_cast<MultipoleT*>(getElement());
120 multT->setElementLength(length);
121 multT->setBendAngle(bendAngle, varRadius);
123 multT->setFringeField(
124 length * 0.5, Attributes::getReal(itsAttr[LFRINGE]),
126 multT->setBoundingBoxLength(Attributes::getReal(itsAttr[BBLENGTH]));
127 multT->setTransProfile(tp);
128 multT->setMaxOrder(
129 static_cast<size_t>(maxFOrder),
130 static_cast<size_t>(Attributes::getReal(itsAttr[MAXXORDER])));
131 multT->setRotation(rotation);
132 multT->setEntranceAngle(Attributes::getReal(itsAttr[EANGLE]));
133 multT->setEntryOffset(entryOffset);
134 multT->setScalingName(Attributes::getString(itsAttr[SCALING_MODEL]));
135 // Transmit "unknown" attributes.
137}
@ SIZE
Definition IndexMap.cpp:179
ElementBase * getElement() const
Return the embedded OPALX element.
Definition Element.h:119
void setElement(ElementBase *)
Assign new OPALX element.
Definition Element.h:123
void setElementLength(double length) override
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPALX) attributes to OPALX.
virtual void print(std::ostream &) const
Print the object.
virtual void update()
Update the embedded OPALX element.
void registerOwnership() const
OpalMultipoleT * clone(const std::string &name) override
static constexpr double MaximumMAXFORDER
static constexpr double DefaultMAXXORDER
void update() override
void print(std::ostream &os) const override
Print the object.
static constexpr double DefaultMAXFORDER
static constexpr double MinimumMAXFORDER
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
Attribute makeUpperCaseString(const std::string &name, const std::string &help)
Make uppercase string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
bool getBool(const Attribute &attr)
Return logical value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
std::string getString(const Attribute &attr)
Get string value.