OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalQuadrupole.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalQuadrupole.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalQuadrupole
10 // The class of OPAL Quadrupoles.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2002/12/09 15:06:07 $
15 // $Author: jsberg $
16 //
17 // ------------------------------------------------------------------------
18 
21 #include "Attributes/Attributes.h"
24 #include "Fields/BMultipoleField.h"
25 #include "Physics/Physics.h"
26 #include "Utilities/Options.h"
28 
29 #include <cmath>
30 #include <iostream>
31 #include <sstream>
32 
33 
34 // Class OpalQuadrupole
35 // ------------------------------------------------------------------------
36 
38  OpalElement(SIZE, "QUADRUPOLE",
39  "The \"QUADRUPOLE\" element defines a Quadrupole."),
40  parmatint_m(NULL) {
42  ("K1", "Normalised upright quadrupole coefficient in m^(-2)");
44  ("DK1", "Normalised upright quadrupole coefficient error in m^(-2)");
46  ("K1S", "Normalised skew quadrupole coefficient in m^(-2)");
47 
49  ("DK1S", "Normalised skew quadrupole coefficient error in m^(-2)");
50 
52  ("NSLICES",
53  "The number of slices/ steps for this element in Map Tracking", 1);
54 
56  registerRealAttribute("DK1");
57  registerRealAttribute("K1S");
58  registerRealAttribute("DK1S");
59  registerRealAttribute("NSLICES");
60 
62 
63  setElement((new MultipoleRep("QUADRUPOLE")));
64 }
65 
66 
67 OpalQuadrupole::OpalQuadrupole(const std::string &name, OpalQuadrupole *parent):
68  OpalElement(name, parent),
69  parmatint_m(NULL) {
70  setElement((new MultipoleRep(name)));
71 }
72 
73 
75  if(parmatint_m)
76  delete parmatint_m;
77 }
78 
79 
81  return new OpalQuadrupole(name, this);
82 }
83 
84 
85 void OpalQuadrupole::print(std::ostream &os) const {
87 }
88 
89 
93 
94  // Get the desired field.
95  const MultipoleWrapper *mult =
96  dynamic_cast<const MultipoleWrapper *>(base.removeAlignWrapper());
97  BMultipoleField field;
98 
99  // Get the desired field.
100  if(flag == ERROR_FLAG) {
101  field = mult->errorField();
102  } else if(flag == ACTUAL_FLAG) {
103  field = mult->getField();
104  } else if(flag == IDEAL_FLAG) {
105  field = mult->getDesign().getField();
106  }
107 
108  double length = getLength();
109  double scale = Physics::c / OpalData::getInstance()->getP0();
110  if(length != 0.0) scale *= length;
111 
112  for(int order = 1; order <= field.order(); ++order) {
113  std::ostringstream ss;
114  ss << (order - 1) << std::ends;
115  std::string orderString = ss.str();
116 
117  std::string normName = "K" + orderString + "L";
118  registerRealAttribute(normName)->setReal(scale * field.normal(order));
119 
120  std::string skewName = "K" + orderString + "SL";
121  registerRealAttribute(skewName)->setReal(scale * field.skew(order));
122 
123  scale *= double(order);
124  }
125 }
126 
127 
130 
131  MultipoleRep *quad =
132  dynamic_cast<MultipoleRep *>(getElement()->removeWrappers());
134  double factor = OpalData::getInstance()->getP0() / Physics::c;
135 
136  BMultipoleField field;
137  field.setNormalComponent(2, factor * Attributes::getReal(itsAttr[K1])); // this is for the maps
138  field.setSkewComponent(2, factor * Attributes::getReal(itsAttr[K1S])); // this is for the maps
139  quad->setField(field);
143 
148  }
149 
150  // Transmit "unknown" attributes.
152 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
virtual const Multipole & getDesign() const
Get design corrector.
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.
The QUADRUPOLE element.
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 ~OpalQuadrupole()
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 void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
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
OpalQuadrupole()
Exemplar constructor.
void setSkewComponent(int n, double Bn)
Set component.
virtual void update()
Update the embedded CLASSIC multipole.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
ParticleMatterInteractionHandler * handler_m
static OpalData * getInstance()
Definition: OpalData.cpp:209
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual OpalQuadrupole * clone(const std::string &name)
Make clone.
double skew(int) const
Get component.
void initParticleMatterInteractionHandler(ElementBase &element)
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
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.
ParticleMatterInteraction * parmatint_m
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
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 void print(std::ostream &) const
Print the quadrupole.
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.
int order() const
Return order.
void setNSlices(const std::size_t &nSlices)
Definition: Multipole.cpp:160
virtual void print(std::ostream &) const
Print the object.
virtual void setReal(double)
Store the value.
Definition: AttCell.cpp:34
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307