OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalRBend.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalRBend.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalRBend
10 // The class of OPAL rectangular bend magnets.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2004/11/12 20:10:11 $
15 // $Author: adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Elements/OpalRBend.h"
21 #include "Attributes/Attributes.h"
22 #include "BeamlineCore/RBendRep.h"
23 #include "Fields/BMultipoleField.h"
25 #include "Physics/Physics.h"
26 #include "Structure/OpalWake.h"
29 #include <cmath>
30 
31 // Class OpalRBend
32 // ------------------------------------------------------------------------
33 
35  OpalBend("RBEND",
36  "The \"RBEND\" element defines a rectangular bending magnet."),
37  owk_m(0),
38  parmatint_m(NULL) {
39 
41 
42  setElement((new RBendRep("RBEND"))->makeWrappers());
43 }
44 
45 
46 OpalRBend::OpalRBend(const std::string &name, OpalRBend *parent):
47  OpalBend(name, parent),
48  owk_m(0),
49  parmatint_m(NULL) {
50  setElement((new RBendRep(name))->makeWrappers());
51 }
52 
53 
55  if(owk_m)
56  delete owk_m;
57  if(parmatint_m)
58  delete parmatint_m;
59 }
60 
61 
62 OpalRBend *OpalRBend::clone(const std::string &name) {
63  return new OpalRBend(name, this);
64 }
65 
66 
67 void OpalRBend::
70 
71  // Get the desired field.
72  const RBendWrapper *bend =
73  dynamic_cast<const RBendWrapper *>(base.removeAlignWrapper());
74  BMultipoleField field;
75 
76  // Get the desired field.
77  if(flag == ERROR_FLAG) {
78  field = bend->errorField();
79  } else if(flag == ACTUAL_FLAG) {
80  field = bend->getField();
81  } else if(flag == IDEAL_FLAG) {
82  field = bend->getDesign().getField();
83  }
84 
85  double length = getLength();
86  double scale = Physics::c / OpalData::getInstance()->getP0();
87  if(length != 0.0) scale *= length;
88 
89  for(int i = 1; i <= field.order(); ++i) {
90  std::string normName("K0L");
91  normName[1] += (i - 1);
92  attributeRegistry[normName]->setReal(scale * field.normal(i));
93 
94  std::string skewName("K0SL");
95  skewName[1] += (i - 1);
96  attributeRegistry[skewName]->setReal(scale * field.skew(i));
97  scale *= double(i);
98  }
99 
100  // Store pole face information.
101  attributeRegistry["E1"]->setReal(bend->getEntryFaceRotation());
102  attributeRegistry["E2"]->setReal(bend->getExitFaceRotation());
103  attributeRegistry["H1"]->setReal(bend->getEntryFaceCurvature());
104  attributeRegistry["H2"]->setReal(bend->getExitFaceCurvature());
105 
106  // Store integration parameters.
107  attributeRegistry["SLICES"]->setReal(bend->getSlices());
108  attributeRegistry["STEPSIZE"]->setReal(bend->getStepsize());
109 }
110 
111 
114 
115  // Define geometry.
116  RBendRep *bend =
117  dynamic_cast<RBendRep *>(getElement()->removeWrappers());
118  double length = Attributes::getReal(itsAttr[LENGTH]);
119  double angle = Attributes::getReal(itsAttr[ANGLE]);
120  double e1 = Attributes::getReal(itsAttr[E1]);
121  RBendGeometry &geometry = bend->getGeometry();
122  geometry.setElementLength(length);
123  if (angle < 0) {
124 
125  }
126  geometry.setBendAngle(angle);
127 
128  // Define number of slices for map tracking
130 
131  // Define pole face angles.
136 
137  // Define integration parameters.
140 
141  // Define field.
142  double factor = OpalData::getInstance()->getP0() / Physics::c;
143  BMultipoleField field;
144  double k0 =
146  length ? 2 * sin(angle / 2) / length : angle;
147  double k0s = itsAttr[K0S] ? Attributes::getReal(itsAttr[K0S]) : 0.0;
148  //JMJ 4/10/2000: above line replaced
149  // length ? angle / length : angle;
150  // to avoid closed orbit created by RBEND with defalt K0.
151  field.setNormalComponent(1, factor * k0);
152  field.setSkewComponent(1, factor * Attributes::getReal(itsAttr[K0S]));
153  field.setNormalComponent(2, factor * Attributes::getReal(itsAttr[K1]));
154  field.setSkewComponent(2, factor * Attributes::getReal(itsAttr[K1S]));
155  field.setNormalComponent(3, factor * Attributes::getReal(itsAttr[K2]) / 2.0);
156  field.setSkewComponent(3, factor * Attributes::getReal(itsAttr[K2S]) / 2.0);
157  field.setNormalComponent(4, factor * Attributes::getReal(itsAttr[K3]) / 6.0);
158  field.setSkewComponent(4, factor * Attributes::getReal(itsAttr[K3S]) / 6.0);
159  bend->setField(field);
160 
161  // Set field amplitude or bend angle.
162  if(itsAttr[ANGLE]) {
163  if (bend->isPositioned() && angle < 0.0) {
164  e1 = -e1;
165  angle = -angle;
166 
167  Quaternion rotAboutZ(0, 0, 0, 1);
169  bend->releasePosition();
171  rotAboutZ * g2l.getRotation()));
172  bend->fixPosition();
173  }
174  bend->setBendAngle(angle);
175  } else {
176  bend->setFieldAmplitude(k0, k0s);
177  }
178  bend->setEntranceAngle(e1);
179 
180  if(itsAttr[ROTATION])
181  throw OpalException("OpalRBend::update",
182  "ROTATION not supported any more; use PSI instead");
183 
184 
185  if(itsAttr[FMAPFN])
187  else if(bend->getName() != "RBEND") {
188  ERRORMSG(bend->getName() << ": No filename for a field map given. "
189  "Will assume the default map "
190  "\"1DPROFILE1-DEFAULT\"."
191  << endl);
192  bend->setFieldMapFN("1DPROFILE1-DEFAULT");
193  }
194 
195  // Energy in eV.
196  if(itsAttr[DESIGNENERGY]) {
197  bend->setDesignEnergy(Attributes::getReal(itsAttr[DESIGNENERGY]), false);
198  }
199 
200  bend->setFullGap(Attributes::getReal(itsAttr[GAP]));
201 
202  // if(itsAttr[APERT])
203  // throw OpalException("OpalRBend::fillRegisteredAttributes",
204  // "APERTURE in RBEND not supported; use GAP and HAPERT instead");
205 
206  if(itsAttr[HAPERT]) {
207  double hapert = Attributes::getReal(itsAttr[HAPERT]);
208  bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, hapert, 1.0}));
209  }
210 
211  if(itsAttr[LENGTH])
212  bend->setLength(Attributes::getReal(itsAttr[LENGTH]));
213  else
214  bend->setLength(0.0);
215 
216  if(itsAttr[WAKEF] && itsAttr[DESIGNENERGY] && owk_m == NULL) {
217  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
218  owk_m->initWakefunction(*bend);
219  bend->setWake(owk_m->wf_m);
220  }
221 
222  if(itsAttr[K1])
223  bend->setK1(Attributes::getReal(itsAttr[K1]));
224  else
225  bend->setK1(0.0);
226 
231  }
232 
233  // Transmit "unknown" attributes.
235 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
virtual void setEntranceAngle(double entranceAngle) override
Definition: RBend.cpp:141
virtual void update()
Update the embedded CLASSIC bend.
Definition: OpalRBend.cpp:112
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
virtual void setSlices(double sl)
Set number of slices.
Definition: RBendRep.cpp:173
WakeFunction * wf_m
Definition: OpalWake.h:65
Interface for basic beam line object.
Definition: ElementBase.h:128
void fixPosition()
Definition: ElementBase.h:677
Representation for a rectangular bend magnet.
Definition: RBendRep.h:34
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
double normal(int) const
Get component.
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:623
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
void setNormalComponent(int n, double Bn)
Set component.
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 setK1(double k1)
Set quadrupole field component.
Definition: Bend2D.h:330
virtual void setBendAngle(double angle) override
Definition: RBend.cpp:136
void setFullGap(double)
Definition: BendBase.h:102
virtual double getLength() const
Return element length.
virtual void setStepsize(double ds)
Set stepsize.
Definition: RBendRep.cpp:177
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
ParticleMatterInteraction * parmatint_m
Definition: OpalRBend.h:59
virtual void setExitFaceRotation(double e2)
Set exit pole face rotation.
Definition: RBendRep.cpp:144
void setSkewComponent(int n, double Bn)
Set component.
void setNSlices(const std::size_t &nSlices)
Definition: Bend2D.cpp:1684
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
virtual double getEntryFaceRotation() const
Get pole face rotation.
void initWakefunction(ElementBase &element)
Definition: OpalWake.cpp:157
Base class for all bending magnets.
Definition: OpalBend.h:30
virtual void setDesignEnergy(const double &energy, bool changeable=true)
Definition: BendBase.h:112
ParticleMatterInteractionHandler * handler_m
static OpalData * getInstance()
Definition: OpalData.cpp:209
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual const RBend & getDesign() const
Get design RBend.
virtual void setEntryFaceRotation(double e1)
Set pole entry face rotation.
Definition: RBendRep.cpp:140
void setFieldMapFN(std::string fileName)
Definition: BendBase.h:137
double skew(int) const
Get component.
Quaternion getRotation() const
void initParticleMatterInteractionHandler(ElementBase &element)
virtual BMultipoleField & errorField() const
Get multipole field error.
virtual void setElementLength(double length)
Set design length.
OpalRBend()
Exemplar constructor.
Definition: OpalRBend.cpp:34
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:136
virtual double getSlices() const
Get number of slices.
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
void releasePosition()
Definition: ElementBase.h:672
virtual double getExitFaceRotation() const
Get pole face rotation.
OpalWake * owk_m
Definition: OpalRBend.h:58
virtual double getEntryFaceCurvature() const
Get pole face curvature.
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 setEntryFaceCurvature(double h1)
Set entry pole face curvature.
Definition: RBendRep.cpp:156
virtual void setField(const BMultipoleField &field)
Set field.
Definition: RBendRep.cpp:182
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Definition: OpalRBend.cpp:68
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
The geometry for a RBend element.
Definition: RBendGeometry.h:41
virtual void setExitFaceCurvature(double h2)
Set exit pole face curvature.
Definition: RBendRep.cpp:160
virtual BMultipoleField & getField()
Get field.
The magnetic field of a multipole.
void setBendAngle(double angle)
Set angle.
bool isPositioned() const
Definition: ElementBase.h:682
The RBEND element.
Definition: OpalRBend.h:31
const std::string name
void setAperture(const ApertureType &type, const std::vector< double > &args)
Definition: ElementBase.h:625
virtual RBendGeometry & getGeometry()
Get geometry.
Definition: RBendRep.cpp:102
void setFieldAmplitude(double k0, double k0s)
Definition: BendBase.h:125
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual double getExitFaceCurvature() const
Get pole face curvature.
Representation of a perturbed rectangular bend.
Definition: RBendWrapper.h:37
virtual double getStepsize() const
Get stepsize.
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
int order() const
Return order.
virtual OpalRBend * clone(const std::string &name)
Make clone.
Definition: OpalRBend.cpp:62
virtual ~OpalRBend()
Definition: OpalRBend.cpp:54
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
Definition: ElementBase.h:603