OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
OpalMultipoleT.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, Titus Dascalu
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
34#include "Expressions/SValue.h"
36#include "Physics/Physics.h"
37#include "Physics/Units.h"
38#include "Utilities/Options.h"
39#include <iostream>
40#include <sstream>
41#include <vector>
42
43
45 OpalElement(SIZE, "MULTIPOLET",
46 "The \"MULTIPOLET\" element defines a combined function multipole.") {
48 ("TP", "Transverse Profile derivatives in T m^(-k)");
50 ("LFRINGE", "The length of the left end field [m]");
52 ("RFRINGE", "The length of the right end field [m]");
54 ("HAPERT", "The aperture width [m]");
56 ("VAPERT", "The aperture height [m]");
58 ("ANGLE", "The azimuthal angle of the magnet in ring [rad]");
60 ("EANGLE", "The entrance angle [rad]");
62 ("MAXFORDER",
63 "Number of terms used in each field component");
65 ("MAXXORDER",
66 "Number of terms used in polynomial expansions");
68 ("ROTATION",
69 "Rotation angle about its axis for skew elements [rad]");
71 ("VARRADIUS",
72 "Set true if radius of magnet is variable");
74 ("BBLENGTH",
75 "Distance between centre of magnet and entrance [m]");
76
78
79 setElement(new MultipoleT("MULTIPOLET"));
80}
81
82
84 OpalMultipoleT *parent):
85 OpalElement(name, parent) {
87}
88
89
91{}
92
93
95 return new OpalMultipoleT(name, this);
96}
97
98
99void OpalMultipoleT::print(std::ostream &os) const {
101}
102
103
106
107 // Magnet length.
108 MultipoleT *multT =
109 dynamic_cast<MultipoleT*>(getElement());
111 double angle = Attributes::getReal(itsAttr[ANGLE]);
112 multT->setElementLength(length);
113 multT->setLength(length);
114 multT->setBendAngle(angle);
121 multT->setVarRadius();
122 }
124 const std::vector<double> transProfile =
126 int transSize = transProfile.size();
127
128 if (transSize == 0) {
129 multT->setTransMaxOrder(0);
130 } else {
131 multT->setTransMaxOrder(transSize - 1);
132 }
137
138 for(int comp = 0; comp < transSize; comp++) {
139 double units = Units::T2kG*gsl_sf_pow_int(Units::mm2m, comp); // T m^-comp -> kG mm^-comp
140 multT->setTransProfile(comp, transProfile[comp]*units);
141 }
142 // Transmit "unknown" attributes.
144 multT->initialise();
145
146 setElement(multT);
147}
@ SIZE
Definition: IndexMap.cpp:174
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
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
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
constexpr double mm2m
Definition: Units.h:29
constexpr double m2mm
Definition: Units.h:26
constexpr double T2kG
Definition: Units.h:56
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:418
void setBendAngle(double angle)
Definition: MultipoleT.h:414
void setRotation(double rot)
Definition: MultipoleT.h:410
void setMaxXOrder(std::size_t maxXOrder)
Definition: MultipoleT.h:393
void setAperture(double vertAp, double horizAp)
Definition: MultipoleT.cpp:410
void setMaxOrder(std::size_t maxOrder)
Definition: MultipoleT.cpp:212
void setEntranceAngle(double entranceAngle)
Definition: MultipoleT.h:363
void setTransMaxOrder(std::size_t transMaxOrder)
Definition: MultipoleT.h:401
void setBoundingBoxLength(const double &boundingBoxLength)
Definition: MultipoleT.h:434
bool setFringeField(double s0, double lambda_left, double lambda_right)
Definition: MultipoleT.cpp:243
void setVarRadius()
Definition: MultipoleT.h:355
void setLength(double length)
Definition: MultipoleT.h:422
void setTransProfile(std::size_t n, double Bn)
Definition: MultipoleT.cpp:235
void initialise(PartBunchBase< double, 3 > *, double &startField, double &endField) override
Definition: MultipoleT.cpp:537
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void print(std::ostream &) const
Print the object.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
virtual ~OpalMultipoleT()
virtual OpalMultipoleT * clone(const std::string &name)
virtual void update()
void print(std::ostream &os) const
Print the object.