OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalMultipoleTCurvedVarRadius.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 OpalMultipoleTCurvedVarRadius
46 // ------------------------------------------------------------------------
47 
49  OpalElement(SIZE, "MULTIPOLETCURVEDVARRADIUS",
50  "The \"MULTIPOLETCURVEDVARRADIUS\" element defines a combined function multipole.") {
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  setElement((new MultipoleTCurvedVarRadius("MULTIPOLETCURVEDVARRADIUS"))->makeWrappers());
81 }
82 
83 
86  OpalElement(name, parent) {
87  setElement((new MultipoleTCurvedVarRadius(name))->makeWrappers());
88 }
89 
90 
92 {}
93 
94 
96  return new OpalMultipoleTCurvedVarRadius(name, this);
97 }
98 
99 
100 void OpalMultipoleTCurvedVarRadius::print(std::ostream &os) const {
101  OpalElement::print(os);
102 }
103 
104 
108  const MultipoleTCurvedVarRadius *multT =
109  dynamic_cast<const MultipoleTCurvedVarRadius*>(base.removeAlignWrapper());
110 
111  for(unsigned int order = 1; order <= multT->getTransMaxOrder(); order++) {
112  std::ostringstream ss;
113  ss << order;
114  std::string orderString = ss.str();
115  std::string attrName = "TP" + orderString;
116  registerRealAttribute(attrName)->setReal(multT->getTransProfile(order));
117  }
118 
119  registerRealAttribute("LFRINGE")->setReal(multT->getFringeLength().at(0));
120  registerRealAttribute("RFRINGE")->setReal(multT->getFringeLength().at(1));
121  registerRealAttribute("VAPERT")->setReal(multT->getAperture()[0]);
122  registerRealAttribute("HAPERT")->setReal(multT->getAperture()[1]);
123  registerRealAttribute("MAXFORDER")->setReal(multT->getMaxOrder());
124  registerRealAttribute("MAXXORDER")->setReal(multT->getMaxXOrder());
125  registerRealAttribute("ROTATION")->setReal(multT->getRotation());
126  registerRealAttribute("EANGLE")->setReal(multT->getEntranceAngle());
127  registerRealAttribute("BBLENGTH")->setReal(multT->getBoundingBoxLength());
128 
129 }
130 
131 
134 
135  // Magnet length.
138  double length = Attributes::getReal(itsAttr[LENGTH]);
139  double angle = Attributes::getReal(itsAttr[ANGLE]);
140  double boundingBoxLength = Attributes::getReal(itsAttr[BBLENGTH]);
141  multT->setElementLength(length);
142  multT->setLength(length);
143  multT->setBendAngle(angle);
146 
147  multT->setFringeField(Attributes::getReal(itsAttr[LENGTH])/2,
151  const std::vector<double> transProfile =
153  std::size_t transSize = transProfile.size();
154 
155  if (transSize == 0) {
156  multT->setTransMaxOrder(0);
157  } else {
158  multT->setTransMaxOrder(transSize - 1);
159  }
164 
165  VarRadiusGeometry &geometry = multT->getGeometry();
166 
167  geometry = VarRadiusGeometry(2 * boundingBoxLength,
168  (length / angle),
169  length / 2,
170  Attributes::getReal(itsAttr[LFRINGE]),
171  Attributes::getReal(itsAttr[RFRINGE]));
172 
173  for(std::size_t comp = 0; comp < transSize; comp++) {
174  multT->setTransProfile(comp, transProfile[comp]);
175  }
176  // Transmit "unknown" attributes.
178 
179  setElement(multT->makeWrappers());
180 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
void print(std::ostream &os) const
Print the object.
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)
void setMaxXOrder(const std::size_t &maxXOrder)
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual OpalMultipoleTCurvedVarRadius * clone(const std::string &name)
void setAperture(const double &vertAp, const double &horizAp)
VarRadiusGeometry & getGeometry() override
virtual void setBendAngle(const double &angle) override
virtual ElementBase * removeWrappers()
Return the design element.
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
std::size_t getTransMaxOrder() const
void setTransProfile(const std::size_t &n, const double &Bn)
double getRotation() const
virtual ElementBase * makeWrappers()
Allow errors.
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
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 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
virtual void setMaxOrder(const std::size_t &maxOrder) override
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 setRotation(const double &rot)
double getBoundingBoxLength() const
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
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 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