OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalOctupole.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalOctupole.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalOctupole
10 // The class of OPAL Octupoles.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2002/12/09 15:06:07 $
15 // $Author: jsberg $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Elements/OpalOctupole.h"
21 #include "Attributes/Attributes.h"
24 #include "Fields/BMultipoleField.h"
25 #include "Physics/Physics.h"
26 #include "Utilities/Options.h"
27 #include <cmath>
28 #include <iostream>
29 #include <sstream>
30 
31 // Class OpalOctupole
32 // ------------------------------------------------------------------------
33 
35  OpalElement(SIZE, "OCTUPOLE",
36  "The \"OCTUPOLE\" element defines a Octupole.") {
38  ("K3", "Normalised upright octupole coefficient in m^(-4)");
40  ("DK3", "Normalised upright octupole coefficient error in m^(-4)");
42  ("K3S", "Normalised skew octupole coefficient in m^(-4)");
44  ("DK3S", "Normalised skew octupole coefficient error in m^(-4)");
45 
47 
48  setElement((new MultipoleRep("OCTUPOLE"))->makeWrappers());
49 }
50 
51 
52 OpalOctupole::OpalOctupole(const std::string &name, OpalOctupole *parent):
53  OpalElement(name, parent) {
54  setElement((new MultipoleRep(name))->makeWrappers());
55 }
56 
57 
59 {}
60 
61 
62 OpalOctupole *OpalOctupole::clone(const std::string &name) {
63  return new OpalOctupole(name, this);
64 }
65 
66 
67 void OpalOctupole::print(std::ostream &os) const {
69 }
70 
71 
72 void OpalOctupole::
75 
76  // Get the desired field.
77  const MultipoleWrapper *mult =
78  dynamic_cast<const MultipoleWrapper *>(base.removeAlignWrapper());
79  BMultipoleField field;
80 
81  // Get the desired field.
82  if(flag == ERROR_FLAG) {
83  field = mult->errorField();
84  } else if(flag == ACTUAL_FLAG) {
85  field = mult->getField();
86  } else if(flag == IDEAL_FLAG) {
87  field = mult->getDesign().getField();
88  }
89 
90  double length = getLength();
91  double scale = Physics::c / OpalData::getInstance()->getP0();
92  if(length != 0.0) scale *= length;
93 
94  for(int order = 1; order <= field.order(); ++order) {
95  std::ostringstream ss;
96  ss << (order - 1) << std::ends;
97  std::string orderString = ss.str();
98 
99  std::string normName = "K" + orderString + "L";
100  registerRealAttribute(normName)->setReal(scale * field.normal(order));
101 
102  std::string skewName = "K" + orderString + "SL";
103  registerRealAttribute(skewName)->setReal(scale * field.skew(order));
104 
105  scale *= double(order);
106  }
107 }
108 
109 
112 
113  MultipoleRep *oct =
114  dynamic_cast<MultipoleRep *>(getElement()->removeWrappers());
116  double factor = OpalData::getInstance()->getP0() / (Physics::c * 6.0);
117  BMultipoleField field;
118  field.setNormalComponent(4, factor * Attributes::getReal(itsAttr[K3]));
119  field.setSkewComponent(4, factor * Attributes::getReal(itsAttr[K3S]));
120  oct->setField(field);
121 
124 
125  // Transmit "unknown" attributes.
127 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
virtual const Multipole & getDesign() const
Get design corrector.
virtual void print(std::ostream &) const
Print the element.
void setSkewComponent(int, double)
Set skew component.
Definition: Multipole.h:155
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
double normal(int) const
Get component.
virtual void setField(const BMultipoleField &field)
Set mulitpole field.
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:623
Representation for a general multipole.
Definition: MultipoleRep.h:31
virtual BMultipoleField & getField() override=0
Get multipole field.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
void setNormalComponent(int n, double Bn)
Set component.
virtual BMultipoleField & getField()
Get field.
virtual ElementBase * removeWrappers()
Return the design element.
void setNormalComponent(int, double)
Set normal component.
Definition: Multipole.h:150
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual double getLength() const
Return element length.
Representation of a perturbed multipole.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual OpalOctupole * clone(const std::string &name)
Make clone.
void setSkewComponent(int n, double Bn)
Set component.
static OpalData * getInstance()
Definition: OpalData.cpp:209
double skew(int) const
Get component.
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Base class for all beam line elements.
Definition: OpalElement.h:41
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
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
The magnetic field of a multipole.
const std::string name
virtual BMultipoleField & errorField() const
Get multipole field error.
virtual ~OpalOctupole()
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.
OpalOctupole()
Exemplar constructor.
int order() const
Return order.
virtual void update()
Update the embedded CLASSIC multipole.
virtual void print(std::ostream &) const
Print the object.
virtual void setReal(double)
Store the value.
Definition: AttCell.cpp:34
The OCTUPOLE element.
Definition: OpalOctupole.h:28