OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalKicker.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalKicker.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalKicker
10 // The class of OPAL horizontal orbit correctors.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2001/08/13 15:32:23 $
15 // $Author: jowett $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Elements/OpalKicker.h"
22 #include "Attributes/Attributes.h"
23 // JMJ 18/12/2000 no longer need this, see code commented out below.
24 //#include "Utilities/Options.h"
27 #include "Physics/Physics.h"
28 
29 
30 // Class OpalKicker
31 // ------------------------------------------------------------------------
32 
34  OpalElement(SIZE, "KICKER",
35  "The \"KICKER\" element defines a closed orbit corrector "
36  "acting on both planes.") {
38  ("HKICK", "Horizontal deflection in rad");
40  ("VKICK", "Vertical deflection in rad");
42  ("DESIGNENERGY", "the mean energy of the particles");
44  ("K0", "Normal dipole field in T");
46  ("K0S", "Skew dipole field in T");
47 
48  registerRealAttribute("HKICK");
49  registerRealAttribute("VKICK");
50  registerRealAttribute("DESIGNENERGY");
52  registerRealAttribute("K0S");
53 
55 
56  setElement((new CorrectorRep("KICKER"))->makeWrappers());
57 }
58 
59 
60 OpalKicker::OpalKicker(const std::string &name, OpalKicker *parent):
61  OpalElement(name, parent) {
62  setElement((new CorrectorRep(name))->makeWrappers());
63 }
64 
65 
67 {}
68 
69 
70 OpalKicker *OpalKicker::clone(const std::string &name) {
71  return new OpalKicker(name, this);
72 }
73 
74 
75 void OpalKicker::
77  Inform m("fillRegisteredAttributes ");
78 
80  const CorrectorWrapper *corr =
81  dynamic_cast<const CorrectorWrapper *>(base.removeAlignWrapper());
82  BDipoleField field;
83 
84  if(flag == ERROR_FLAG) {
85  field = corr->errorField();
86  } else if(flag == ACTUAL_FLAG) {
87  field = corr->getField();
88  } else if(flag == IDEAL_FLAG) {
89  field = corr->getDesign().getField();
90  }
91 
92  double scale = Physics::c / OpalData::getInstance()->getP0();
93  attributeRegistry["HKICK"]->setReal(- field.getBy() * scale);
94  attributeRegistry["VKICK"]->setReal(+ field.getBx() * scale);
95 
96  m << "P= " << OpalData::getInstance()->getP0()
97  << " Bx= " << field.getBx()
98  << " By= " << field.getBy() << endl;
99 }
100 
101 
104 
105  CorrectorRep *corr =
106  dynamic_cast<CorrectorRep *>(getElement()->removeWrappers());
107  double length = Attributes::getReal(itsAttr[LENGTH]);
108  double factor = OpalData::getInstance()->getP0() / Physics::c;
109  double hKick = Attributes::getReal(itsAttr[HKICK]);
110  double vKick = Attributes::getReal(itsAttr[VKICK]);
111 
112  corr->setElementLength(length);
113  corr->setBy(- hKick * factor);
114  corr->setBx(vKick * factor);
115 
116  corr->setKickX(hKick);
117  corr->setKickY(vKick);
118  if(itsAttr[DESIGNENERGY]) {
119  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]) * 1e6;
120  corr->setDesignEnergy(kineticEnergy, false);
121  }
122 
123  double Bx = 0.0, By = 0.0;
124  bool fieldSet = false;
125  if (itsAttr[K0]) {
126  Bx = Attributes::getReal(itsAttr[K0]);
127  fieldSet = true;
128  }
129  if (itsAttr[K0S]) {
130  By = Attributes::getReal(itsAttr[K0S]);
131  fieldSet = true;
132  }
133 
134  if (fieldSet) {
135  corr->setKickField(Vector_t(Bx, By, 0));
136  }
137 
138  // Transmit "unknown" attributes.
140 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
Representation of a closed orbit corrector.
Definition: CorrectorRep.h:33
virtual BDipoleField & getField()=0
Return the corrector field.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
The field of a magnetic dipole.
Definition: BDipoleField.h:31
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:623
virtual BDipoleField & errorField() const
Get corrector field error.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual OpalKicker * clone(const std::string &name)
Make clone.
Definition: OpalKicker.cpp:70
virtual ElementBase * removeWrappers()
Return the design element.
void setKickY(double k)
Definition: Corrector.h:137
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual double getBy() const
Get vertical component.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual void setDesignEnergy(const double &ekin, bool changeable=true)
Definition: Corrector.cpp:127
static OpalData * getInstance()
Definition: OpalData.cpp:209
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
virtual BDipoleField & getField()
Get corrector field.
The KICKER element.
Definition: OpalKicker.h:30
void setKickX(double k)
Definition: Corrector.h:132
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
OpalKicker()
Exemplar constructor.
Definition: OpalKicker.cpp:33
Base class for all beam line elements.
Definition: OpalElement.h:41
virtual double getBx() const
Get horizontal component.
virtual const Corrector & getDesign() const
Get design corrector.
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
void registerOwnership() const
virtual void setBy(double)
Set vertical field component in Teslas.
virtual void update()
Update the embedded CLASSIC element.
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
Representation for a perturbed closed orbit corrector.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
virtual void update()
Update the embedded CLASSIC corrector.
Definition: OpalKicker.cpp:102
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Definition: Inform.h:41
virtual void setBx(double)
Set horizontal field component in Teslas.
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.
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Definition: OpalKicker.cpp:76
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
void setKickField(const Vector_t &k0)
Definition: Corrector.h:152
virtual ~OpalKicker()
Definition: OpalKicker.cpp:66