OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 
33 #include "Attributes/Attributes.h"
34 #include "Expressions/SValue.h"
35 #include "Expressions/SRefExpr.h"
36 #include "Physics/Physics.h"
37 #include "Utilities/Options.h"
38 #include <iostream>
39 #include <sstream>
40 #include <vector>
41 
42 
44  OpalElement(SIZE, "MULTIPOLET",
45  "The \"MULTIPOLET\" element defines a combined function multipole.") {
47  ("TP", "Transverse Profile derivatives in T m^(-k)");
49  ("LFRINGE", "The length of the left end field [m]");
51  ("RFRINGE", "The length of the right end field [m]");
53  ("HAPERT", "The aperture width [m]");
55  ("VAPERT", "The aperture height [m]");
57  ("ANGLE", "The azimuthal angle of the magnet in ring [rad]");
59  ("EANGLE", "The entrance angle [rad]");
61  ("MAXFORDER",
62  "Number of terms used in each field component");
64  ("MAXXORDER",
65  "Number of terms used in polynomial expansions");
67  ("ROTATION",
68  "Rotation angle about its axis for skew elements [rad]");
70  ("VARRADIUS",
71  "Set true if radius of magnet is variable");
73  ("BBLENGTH",
74  "Distance between centre of magnet and entrance [m]");
75 
77 
78  setElement(new MultipoleT("MULTIPOLET"));
79 }
80 
81 
83  OpalMultipoleT *parent):
84  OpalElement(name, parent) {
86 }
87 
88 
90 {}
91 
92 
94  return new OpalMultipoleT(name, this);
95 }
96 
97 
98 void OpalMultipoleT::print(std::ostream &os) const {
100 }
101 
102 
105 
106  // Magnet length.
107  double mm = 1000.;
108  MultipoleT *multT =
109  dynamic_cast<MultipoleT*>(getElement());
110  double length = Attributes::getReal(itsAttr[LENGTH])*mm;
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 = 10.*gsl_sf_pow_int(1e-3, 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 e
The value of.
Definition: Physics.h:39
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:436
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.