OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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"
35 #include "Expressions/SValue.h"
36 #include "Expressions/SRefExpr.h"
37 #include "Physics/Physics.h"
38 #include "Utilities/Options.h"
39 #include <iostream>
40 #include <sstream>
41 #include <vector>
42 
43 
44 // Class OpalMultipoleT
45 // ------------------------------------------------------------------------
46 
48  OpalElement(SIZE, "MULTIPOLET",
49  "The \"MULTIPOLET\" element defines a combined function multipole.") {
51  ("TP", "Transverse Profile derivatives in T m^(-k)");
53  ("LFRINGE", "The length of the left end field [m]");
55  ("RFRINGE", "The length of the right end field [m]");
57  ("HAPERT", "The aperture width [m]");
59  ("VAPERT", "The aperture height [m]");
61  ("ANGLE", "The azimuthal angle of the magnet in ring [rad]");
63  ("EANGLE", "The entrance angle [rad]");
65  ("MAXFORDER",
66  "Number of terms used in each field component");
68  ("MAXXORDER",
69  "Number of terms used in polynomial expansions");
71  ("ROTATION",
72  "Rotation angle about its axis for skew elements [rad]");
74  ("VARRADIUS",
75  "Set true if radius of magnet is variable");
77  ("BBLENGTH",
78  "Distance between centre of magnet and entrance [m]");
79 
81 
82  setElement((new MultipoleT("MULTIPOLET"))->makeWrappers());
83 }
84 
85 
87  OpalMultipoleT *parent):
88  OpalElement(name, parent) {
89  setElement((new MultipoleT(name))->makeWrappers());
90 }
91 
92 
94 {}
95 
96 
98  return new OpalMultipoleT(name, this);
99 }
100 
101 
102 void OpalMultipoleT::print(std::ostream &os) const {
103  OpalElement::print(os);
104 }
105 
106 
107 void OpalMultipoleT::
110  const MultipoleT *multT =
111  dynamic_cast<const MultipoleT*>(base.removeAlignWrapper());
112  for(unsigned int order = 1; order <= multT->getTransMaxOrder(); order++) {
113  std::ostringstream ss;
114  ss << order;
115  std::string orderString = ss.str();
116  std::string attrName = "TP" + orderString;
117  registerRealAttribute(attrName)->setReal(multT->getTransProfile(order));
118  }
119 
120  registerRealAttribute("LFRINGE")->setReal(multT->getFringeLength().at(0));
121  registerRealAttribute("RFRINGE")->setReal(multT->getFringeLength().at(1));
122  registerRealAttribute("VAPERT")->setReal(multT->getAperture()[0]);
123  registerRealAttribute("HAPERT")->setReal(multT->getAperture()[1]);
124  registerRealAttribute("MAXFORDER")->setReal(multT->getMaxOrder());
125  registerRealAttribute("MAXXORDER")->setReal(multT->getMaxXOrder());
126  registerRealAttribute("ROTATION")->setReal(multT->getRotation());
127  registerRealAttribute("EANGLE")->setReal(multT->getEntranceAngle());
128  //registerRealAttribute("VARRADIUS")->setBool(multT->getVarRadius());
129  registerRealAttribute("BBLENGTH")->setReal(multT->getBoundingBoxLength());
130 }
131 
132 
135 
136  // Magnet length.
137  double mm = 1000.;
138  MultipoleT *multT =
139  dynamic_cast<MultipoleT*>(getElement()->removeWrappers());
140  double length = Attributes::getReal(itsAttr[LENGTH])*mm;
141  double angle = Attributes::getReal(itsAttr[ANGLE]);
142  multT->setElementLength(length);
143  multT->setLength(length);
144  multT->setBendAngle(angle);
147  multT->setFringeField(Attributes::getReal(itsAttr[LENGTH])*mm/2,
151  multT->setVarRadius();
152  }
154  const std::vector<double> transProfile =
156  int transSize = transProfile.size();
157 
158  if (transSize == 0) {
159  multT->setTransMaxOrder(0);
160  } else {
161  multT->setTransMaxOrder(transSize - 1);
162  }
167 
168  for(int comp = 0; comp < transSize; comp++) {
169  double units = 10.*gsl_sf_pow_int(1e-3, comp); // T m^-comp -> kG mm^-comp
170  multT->setTransProfile(comp, transProfile[comp]*units);
171  }
172  // Transmit "unknown" attributes.
174  multT->initialise();
175 
176  setElement(multT->makeWrappers());
177 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
std::size_t getTransMaxOrder() const
Definition: MultipoleT.h:397
void setVarRadius()
Definition: MultipoleT.h:355
constexpr double e
The value of .
Definition: Physics.h:40
void setTransMaxOrder(std::size_t transMaxOrder)
Definition: MultipoleT.h:401
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
double getTransProfile(int n) const
Definition: MultipoleT.h:371
virtual ElementBase * removeWrappers()
Return the design element.
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
bool setFringeField(double s0, double lambda_left, double lambda_right)
Definition: MultipoleT.cpp:243
void print(std::ostream &os) const
Print the object.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
std::size_t getMaxXOrder() const
Definition: MultipoleT.h:388
std::size_t getMaxOrder() const
Definition: MultipoleT.h:383
void setEntranceAngle(double entranceAngle)
Definition: MultipoleT.h:363
virtual void update()
void setBendAngle(double angle)
Definition: MultipoleT.h:414
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
virtual ElementBase * makeWrappers()
Allow errors.
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
void setMaxOrder(std::size_t maxOrder)
Definition: MultipoleT.cpp:212
Base class for all beam line elements.
Definition: OpalElement.h:41
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:258
virtual OpalMultipoleT * clone(const std::string &name)
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
double getEntranceAngle() const
Definition: MultipoleT.h:367
void registerOwnership() const
virtual void update()
Update the embedded CLASSIC element.
void initialise(PartBunchBase< double, 3 > *, double &startField, double &endField) override
Definition: MultipoleT.cpp:537
void setAperture(double vertAp, double horizAp)
Definition: MultipoleT.cpp:410
std::vector< double > getAperture() const
Definition: MultipoleT.cpp:415
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
double getBoundingBoxLength() const
Definition: MultipoleT.h:430
void setTransProfile(std::size_t n, double Bn)
Definition: MultipoleT.cpp:235
void setRotation(double rot)
Definition: MultipoleT.h:410
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
void setLength(double length)
Definition: MultipoleT.h:422
void setMaxXOrder(std::size_t maxXOrder)
Definition: MultipoleT.h:393
virtual ~OpalMultipoleT()
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:253
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
void setBoundingBoxLength(const double &boundingBoxLength)
Definition: MultipoleT.h:434
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
double getRotation() const
Definition: MultipoleT.h:406
std::vector< double > getFringeLength() const
Definition: MultipoleT.cpp:422
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
virtual void print(std::ostream &) const
Print the object.
virtual void setReal(double)
Store the value.
Definition: AttCell.cpp:34