OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalRBend3D.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalRBend3D.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalRBend3D
10 // The parent class of all OPAL bending magnets.
11 // This class factors out all special behaviour for the DOOM interface
12 // and the printing in OPAL format, as well as the bend attributes.
13 //
14 // ------------------------------------------------------------------------
15 //
16 
17 #include "Elements/OpalRBend3D.h"
18 #include "Attributes/Attributes.h"
19 #include "Structure/OpalWake.h"
21 #include "AbsBeamline/RBend3D.h"
23 
24 #include <iostream>
25 
26 
27 // Class OpalRBend3D
28 // ------------------------------------------------------------------------
29 
31  OpalElement(SIZE, "RBEND3D", "The \"RBEND3D\" element defines an RBEND with 3D field maps"),
32  owk_m(0),
33  parmatint_m(NULL) {
35  ("ANGLE", "Upright dipole coefficient in m^(-1)");
37  ("K0", "Normal dipole coefficient in m^(-1)");
39  ("K0S", "Skew dipole coefficient in m^(-1)");
41  ("E1", "Entry pole face angle in rad", 0.0);
43  ("FMAPFN", "Filename for the fieldmap");
45  ("GAP", "Full gap height of the magnet (m)", 0.0);
47  ("HAPERT", "Bend plane magnet aperture (m)", 0.0);
49  ("DESIGNENERGY", "the mean energy of the particles in MeV");
50 
51  registerRealAttribute("ANGLE");
52  registerRealAttribute("K0L");
53  registerRealAttribute("K0SL");
56  registerStringAttribute("FMAPFN");
57  registerRealAttribute("GAP");
58  registerRealAttribute("HAPERT");
59  registerRealAttribute("DESIGNENERGY");
60 
62 
63  setElement((new RBend3D("RBEND3D"))->makeWrappers());
64 }
65 
66 OpalRBend3D::OpalRBend3D(const std::string &name, OpalRBend3D *parent):
67  OpalElement(name, parent),
68  owk_m(0),
69  parmatint_m(NULL)
70 {
71  setElement((new RBend3D(name))->makeWrappers());
72 }
73 
75  if(owk_m)
76  delete owk_m;
77  if(parmatint_m)
78  delete parmatint_m;
79 }
80 
81 OpalRBend3D *OpalRBend3D::clone(const std::string &name) {
82  return new OpalRBend3D(name, this);
83 }
84 
85 
86 void OpalRBend3D::
89 }
90 
93 
94  // Define geometry.
95  RBend3D *bend =
96  dynamic_cast<RBend3D *>(getElement()->removeWrappers());
97  double length = Attributes::getReal(itsAttr[LENGTH]);
98  double angle = Attributes::getReal(itsAttr[ANGLE]);
99  double e1 = Attributes::getReal(itsAttr[E1]);
100  double k0 =
102  length ? 2 * sin(angle / 2) / length : angle;
103  double k0s = itsAttr[K0S] ? Attributes::getReal(itsAttr[K0S]) : 0.0;
104 
105  // Set field amplitude or bend angle.
106  if(itsAttr[ANGLE]) {
107  if (bend->isPositioned() && angle < 0.0) {
108  e1 = -e1;
109  angle = -angle;
110 
111  Quaternion rotAboutZ(0, 0, 0, 1);
113  bend->releasePosition();
115  rotAboutZ * g2l.getRotation()));
116  bend->fixPosition();
117  }
118  bend->setBendAngle(angle);
119  } else {
120  bend->setFieldAmplitude(k0, k0s);
121  }
122 
123  if(itsAttr[FMAPFN])
125  else if(bend->getName() != "RBEND3D") {
126  ERRORMSG(bend->getName() << ": No filename for a field map given." << endl);
127  throw OpalException("OpalRBend3D::update", bend->getName() + ": No filename for field map given");
128  }
129 
130  bend->setEntranceAngle(e1);
131 
132  // Energy in eV.
133  if(itsAttr[DESIGNENERGY]) {
134  bend->setDesignEnergy(Attributes::getReal(itsAttr[DESIGNENERGY]), false);
135  }
136 
137  bend->setFullGap(Attributes::getReal(itsAttr[GAP]));
138 
139  if(itsAttr[HAPERT]) {
140  double hapert = Attributes::getReal(itsAttr[HAPERT]);
141  bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, hapert, 1.0}));
142  }
143 
144  if(itsAttr[LENGTH]) {
145  bend->setLength(Attributes::getReal(itsAttr[LENGTH]));
146  } else
147  bend->setLength(0.0);
148 
149  if(itsAttr[WAKEF] && itsAttr[DESIGNENERGY] && owk_m == NULL) {
150  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
151  owk_m->initWakefunction(*bend);
152  bend->setWake(owk_m->wf_m);
153  }
154 
159  }
160 
161  // Transmit "unknown" attributes.
163 }
164 
165 void OpalRBend3D::print(std::ostream &os) const {
166 
167  OpalElement::print(os);
168 
169 }
Interface for solenoids.
Definition: RBend3D.h:39
static AttCell * registerStringAttribute(const std::string &name)
Register a ``string&#39;&#39; element attribute.
WakeFunction * wf_m
Definition: OpalWake.h:65
Interface for basic beam line object.
Definition: ElementBase.h:128
OpalRBend3D()
Exemplar constructor.
Definition: OpalRBend3D.cpp:30
void fixPosition()
Definition: ElementBase.h:677
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
virtual ElementBase * removeWrappers()
Return the design element.
void setFullGap(double)
Definition: BendBase.h:102
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual void print(std::ostream &) const
Print the object.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
OpalWake * owk_m
Definition: OpalRBend3D.h:71
void initWakefunction(ElementBase &element)
Definition: OpalWake.cpp:157
virtual void setEntranceAngle(double entranceAngle)
Definition: BendBase.h:91
virtual ~OpalRBend3D()
Definition: OpalRBend3D.cpp:74
virtual void setDesignEnergy(const double &energy, bool changeable=true)
Definition: BendBase.h:112
ParticleMatterInteractionHandler * handler_m
virtual void setBendAngle(double angle)
Definition: BendBase.h:81
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
Quaternion getRotation() const
void initParticleMatterInteractionHandler(ElementBase &element)
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:136
void releasePosition()
Definition: ElementBase.h:672
The RBEND element.
Definition: OpalRBend3D.h:31
Base class for all beam line elements.
Definition: OpalElement.h:41
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
Definition: ElementBase.h:595
void registerOwnership() const
Vector_t getOrigin() const
virtual void update()
Update the embedded CLASSIC element.
void setLength(double length)
Definition: BendBase.h:65
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Definition: OpalRBend3D.cpp:87
bool isPositioned() const
Definition: ElementBase.h:682
const std::string name
void setAperture(const ApertureType &type, const std::vector< double > &args)
Definition: ElementBase.h:625
ParticleMatterInteraction * parmatint_m
Definition: OpalRBend3D.h:72
void setFieldMapFN(std::string fn)
Definition: RBend3D.cpp:73
virtual OpalRBend3D * clone(const std::string &name)
Make clone.
Definition: OpalRBend3D.cpp:81
void setFieldAmplitude(double k0, double k0s)
Definition: BendBase.h:125
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual void update()
Update the embedded CLASSIC bend.
Definition: OpalRBend3D.cpp:91
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
virtual void print(std::ostream &) const
Print the object.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
Definition: ElementBase.h:603