OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalMultipoleTCurvedConstRadius.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Titus Dascalu
3  * Copyright (c) 2018, Martin Duy Tat
4  * All rights reserved.
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. Neither the name of STFC nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
34 #include "Attributes/Attributes.h"
36 #include "Expressions/SValue.h"
37 #include "Expressions/SRefExpr.h"
38 #include "Physics/Physics.h"
39 #include "Utilities/Options.h"
40 #include <iostream>
41 #include <sstream>
42 #include <vector>
43 
44 
45 // Class OpalMultipoleTCurvedConstRadius
46 // ------------------------------------------------------------------------
47 
49  OpalElement(SIZE, "MULTIPOLETCURVEDCONSTRADIUS",
50  "The \"MULTIPOLETCURVEDCONSTRADIUS\" element defines a curved combined function multipole magnet of constant curvature.") {
52  ("TP", "Transverse Profile derivatives in m^(-k)");
54  ("LFRINGE", "The length of the left end field in m");
56  ("RFRINGE", "The length of the right end field in m");
58  ("HAPERT", "The aperture width in m");
60  ("VAPERT", "The aperture height in m");
62  ("ANGLE", "The azimuthal angle of the magnet in ring (rad)");
64  ("EANGLE", "The entrance angle (rad)");
66  ("MAXFORDER",
67  "Number of terms used in each field component");
69  ("MAXXORDER",
70  "Number of terms used in polynomial expansions");
72  ("ROTATION",
73  "Rotation angle about its axis for skew elements (rad)");
75  ("BBLENGTH",
76  "Distance between centre of magnet and entrance in m");
77 
79 
80 
81  setElement((new MultipoleTCurvedConstRadius("MULTIPOLETCURVEDCONSTRADIUS"))->makeWrappers());
82 }
83 
84 
87  OpalElement(name, parent) {
88  setElement((new MultipoleTCurvedConstRadius(name))->makeWrappers());
89 }
90 
91 
93 {}
94 
95 
97  return new OpalMultipoleTCurvedConstRadius(name, this);
98 }
99 
100 
101 void OpalMultipoleTCurvedConstRadius::print(std::ostream &os) const {
102  OpalElement::print(os);
103 }
104 
105 
109  const MultipoleTCurvedConstRadius *multT =
110  dynamic_cast<const MultipoleTCurvedConstRadius*>(base.removeAlignWrapper());
111 
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("ANGLE")->setReal(multT->getBendAngle());
128  registerRealAttribute("EANGLE")->setReal(multT->getEntranceAngle());
129  registerRealAttribute("BBLENGTH")->setReal(multT->getBoundingBoxLength());
130 
131 }
132 
133 
136 
137  // Magnet length.
140  double length = Attributes::getReal(itsAttr[LENGTH]);
141  double angle = Attributes::getReal(itsAttr[ANGLE]);
142  double boundingBoxLength = Attributes::getReal(itsAttr[BBLENGTH]);
143  multT->setElementLength(length);
144  multT->setLength(length);
145  multT->setBendAngle(angle);
148 
149  multT->setFringeField(Attributes::getReal(itsAttr[LENGTH])/2,
153  const std::vector<double> transProfile =
155  std::size_t transSize = transProfile.size();
156  if (transSize == 0) {
157  multT->setTransMaxOrder(0);
158  } else {
159  multT->setTransMaxOrder(transSize - 1);
160  }
161 
166 
167  PlanarArcGeometry &geometry = multT->getGeometry();
168 
169  if(length) {
170  geometry = PlanarArcGeometry(2 * boundingBoxLength, angle / length);
171  } else {
172  geometry = PlanarArcGeometry(angle);
173  }
174 
175  for(std::size_t comp = 0; comp < transSize; comp++) {
176  multT->setTransProfile(comp, transProfile[comp]);
177  }
178  // Transmit "unknown" attributes.
180 
181  setElement(multT->makeWrappers());
182 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
double getEntranceAngle() const
Interface for basic beam line object.
Definition: ElementBase.h:128
std::vector< double > getFringeLength() const
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
bool setFringeField(const double &s0, const double &lambda_left, const double &lambda_right)
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
void setAperture(const double &vertAp, const double &horizAp)
A simple arc in the XZ plane.
virtual ElementBase * removeWrappers()
Return the design element.
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual void setBendAngle(const double &angle) override
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
void setMaxXOrder(const std::size_t &maxXOrder)
std::size_t getTransMaxOrder() const
void setTransProfile(const std::size_t &n, const double &Bn)
PlanarArcGeometry & getGeometry() override
double getRotation() const
virtual ElementBase * makeWrappers()
Allow errors.
void setTransMaxOrder(const std::size_t &transMaxOrder)
void setEntranceAngle(const double &entranceAngle)
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
void setLength(const double &length)
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
void setBoundingBoxLength(const double &boundingBoxLength)
virtual double getBendAngle() const override
virtual void update()
Update the embedded CLASSIC element.
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
const std::string name
std::size_t getMaxOrder() const
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:253
void print(std::ostream &os) const
Print the object.
void setRotation(const double &rot)
double getBoundingBoxLength() const
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual void setMaxOrder(const std::size_t &maxOrder) override
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
std::vector< double > getAperture() const
virtual OpalMultipoleTCurvedConstRadius * clone(const std::string &name)
virtual void print(std::ostream &) const
Print the object.
virtual void setReal(double)
Store the value.
Definition: AttCell.cpp:34
double getTransProfile(const std::size_t &n) const