OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalMultipoleTStraight.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 OpalMultipoleTStraight
46 // ------------------------------------------------------------------------
47 
49  OpalElement(SIZE, "MULTIPOLETSTRAIGHT",
50  "The \"MULTIPOLETSTRAIGHT\" element defines a straight, combined function multipole magnet.") {
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  ("EANGLE", "The entrance angle (rad)");
64  ("MAXFORDER",
65  "Number of terms used in each field component");
67  ("ROTATION",
68  "Rotation angle about its axis for skew elements (rad)");
70  ("BBLENGTH",
71  "Distance between centre of magnet and entrance in m");
72 
74 
75  setElement((new MultipoleTStraight("MULTIPOLETSTRAIGHT"))->makeWrappers());
76 }
77 
78 
80  OpalMultipoleTStraight *parent):
81  OpalElement(name, parent) {
82  setElement((new MultipoleTStraight(name))->makeWrappers());
83 }
84 
85 
87 {}
88 
89 
91  return new OpalMultipoleTStraight(name, this);
92 }
93 
94 
95 void OpalMultipoleTStraight::print(std::ostream &os) const {
97 }
98 
99 
103  const MultipoleTStraight *multT =
104  dynamic_cast<const MultipoleTStraight*>(base.removeAlignWrapper());
105 
106  for(unsigned int order = 1; order <= multT->getTransMaxOrder(); order++) {
107  std::ostringstream ss;
108  ss << order;
109  std::string orderString = ss.str();
110  std::string attrName = "TP" + orderString;
111  registerRealAttribute(attrName)->setReal(multT->getTransProfile(order));
112  }
113 
114  registerRealAttribute("LFRINGE")->setReal(multT->getFringeLength().at(0));
115  registerRealAttribute("RFRINGE")->setReal(multT->getFringeLength().at(1));
116  registerRealAttribute("VAPERT")->setReal(multT->getAperture()[0]);
117  registerRealAttribute("HAPERT")->setReal(multT->getAperture()[1]);
118  registerRealAttribute("MAXFORDER")->setReal(multT->getMaxOrder());
119  registerRealAttribute("ROTATION")->setReal(multT->getRotation());
120  registerRealAttribute("EANGLE")->setReal(multT->getEntranceAngle());
121  registerRealAttribute("BBLENGTH")->setReal(multT->getBoundingBoxLength());
122 
123 }
124 
125 
128 
129  // Magnet length.
130  MultipoleTStraight *multT =
131  dynamic_cast<MultipoleTStraight*>(getElement()->removeWrappers());
132  double length = Attributes::getReal(itsAttr[LENGTH]);
133  double boundingBoxLength = Attributes::getReal(itsAttr[BBLENGTH]);
134  multT->setElementLength(length);
135  multT->setLength(length);
138 
139  multT->setFringeField(Attributes::getReal(itsAttr[LENGTH])/2,
143  const std::vector<double> transProfile =
145  int transSize = transProfile.size();
146 
147  multT->setTransMaxOrder(transSize - 1);
151 
152  StraightGeometry &geometry = multT->getGeometry();
153 
154  geometry = StraightGeometry(2 * boundingBoxLength);
155 
156  for(int comp = 0; comp < transSize; comp++) {
157  multT->setTransProfile(comp, transProfile[comp]);
158  }
159  // Transmit "unknown" attributes.
161 
162  setElement(multT->makeWrappers());
163 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
double getEntranceAngle() const
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
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
virtual void setMaxOrder(const std::size_t &maxOrder) override
void setAperture(const double &vertAp, const double &horizAp)
virtual OpalMultipoleTStraight * clone(const std::string &name)
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.
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.
StraightGeometry & getGeometry() override
A geometry representing a straight line.
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 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
void print(std::ostream &os) const
Print the object.
double getTransProfile(const std::size_t &n) const