OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalSBend.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalSBend.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalSBend
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/OpalSBend.h"
21 #include "Attributes/Attributes.h"
22 #include "BeamlineCore/SBendRep.h"
23 #include "Fields/BMultipoleField.h"
25 #include "Physics/Physics.h"
26 #include "Structure/OpalWake.h"
29 #include <cmath>
30 
31 // Class OpalSBend
32 // ------------------------------------------------------------------------
33 
35  OpalBend("SBEND",
36  "The \"SBEND\" element defines a sector bending magnet."),
37  owk_m(NULL),
38  parmatint_m(NULL) {
39 
41 
42  setElement((new SBendRep("SBEND")));
43 }
44 
45 
46 OpalSBend::OpalSBend(const std::string &name, OpalSBend *parent):
47  OpalBend(name, parent),
48  owk_m(NULL),
49  parmatint_m(NULL) {
50  setElement((new SBendRep(name)));
51 }
52 
53 
55  if(owk_m)
56  delete owk_m;
57  if(parmatint_m)
58  delete parmatint_m;
59 }
60 
61 
62 OpalSBend *OpalSBend::clone(const std::string &name) {
63  return new OpalSBend(name, this);
64 }
65 
66 
67 void OpalSBend::
70 
71  // Get the desired field.
72  const SBendWrapper *bend =
73  dynamic_cast<const SBendWrapper *>(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  //attributeRegistry["FMAPFN"]->setString(bend->getFieldMapFN());
110 }
111 
112 
115 
116  // Define geometry.
117  SBendRep *bend = dynamic_cast<SBendRep *>(getElement()->removeWrappers());
118  double length = Attributes::getReal(itsAttr[LENGTH]);
119  double angle = Attributes::getReal(itsAttr[ANGLE]);
120  double e1 = Attributes::getReal(itsAttr[E1]);
121  double e2 = Attributes::getReal(itsAttr[E2]);
122  PlanarArcGeometry &geometry = bend->getGeometry();
123 
124  if(length) {
125  geometry = PlanarArcGeometry(length, angle / length);
126  } else {
127  geometry = PlanarArcGeometry(angle);
128  }
129  // Define number of slices for map tracking
131 
132  // Define pole face angles.
137 
138  // Define integration parameters.
141 
142  // Define field.
143  double factor = OpalData::getInstance()->getP0() / Physics::c;
144  BMultipoleField field;
145  double k0 = itsAttr[K0] ? Attributes::getReal(itsAttr[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 SBEND 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  e2 = -e2;
166  angle = -angle;
167 
168  Quaternion rotAboutZ(0, 0, 0, 1);
170  bend->releasePosition();
172  rotAboutZ * g2l.getRotation()));
173  bend->fixPosition();
174  }
175  bend->setBendAngle(angle);
176  } else {
177  bend->setFieldAmplitude(k0, k0s);
178  }
179 
181  throw OpalException("OpalSBend::update",
182  "GREATERTHANPI not supportet any more");
183 
184  if(itsAttr[ROTATION])
185  throw OpalException("OpalSBend::update",
186  "ROTATION not supportet any more; use PSI instead");
187 
188  if(itsAttr[FMAPFN])
190  else if(bend->getName() != "SBEND") {
191  ERRORMSG(bend->getName() << ": No filename for a field map given. "
192  "Will assume the default map "
193  "\"1DPROFILE1-DEFAULT\"."
194  << endl);
195  bend->setFieldMapFN("1DPROFILE1-DEFAULT");
196  }
197 
198  bend->setEntranceAngle(e1);
199  bend->setExitAngle(e2);
200 
201  // Units are eV.
202  if(itsAttr[DESIGNENERGY]) {
203  bend->setDesignEnergy(Attributes::getReal(itsAttr[DESIGNENERGY]), false);
204  }
205 
206  bend->setFullGap(Attributes::getReal(itsAttr[GAP]));
207 
208  if(itsAttr[APERT])
209  throw OpalException("OpalRBend::fillRegisteredAttributes",
210  "APERTURE in RBEND not supported; use GAP and HAPERT instead");
211 
212  if(itsAttr[HAPERT]) {
213  double hapert = Attributes::getReal(itsAttr[HAPERT]);
214  bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, hapert, 1.0}));
215  }
216 
217  if(itsAttr[LENGTH])
218  bend->setLength(Attributes::getReal(itsAttr[LENGTH]));
219  else
220  bend->setLength(0.0);
221 
222  if(itsAttr[WAKEF] && itsAttr[DESIGNENERGY] && owk_m == NULL) {
223  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
224  owk_m->initWakefunction(*bend);
225  bend->setWake(owk_m->wf_m);
226  }
227 
228  if(itsAttr[K1])
229  bend->setK1(Attributes::getReal(itsAttr[K1]));
230  else
231  bend->setK1(0.0);
232 
237  }
238 
239  // Transmit "unknown" attributes.
241 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
Definition: OpalSBend.cpp:68
virtual double getExitFaceRotation() const
Get pole face rotation.
virtual const SBend & getDesign() const
Get design SBend.
virtual double getSlices() const
Get number of slices.
virtual double getEntryFaceCurvature() const
Get pole face curvature.
WakeFunction * wf_m
Definition: OpalWake.h:65
Interface for basic beam line object.
Definition: ElementBase.h:128
void fixPosition()
Definition: ElementBase.h:677
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
double normal(int) const
Get component.
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
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.
virtual void setExitFaceCurvature(double h2)
Set exit pole face curvature.
Definition: SBendRep.cpp:239
A simple arc in the XZ plane.
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
void setFullGap(double)
Definition: BendBase.h:102
The SBEND element.
Definition: OpalSBend.h:30
virtual double getLength() const
Return element length.
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 ~OpalSBend()
Definition: OpalSBend.cpp:54
void setSkewComponent(int n, double Bn)
Set component.
void setNSlices(const std::size_t &nSlices)
Definition: Bend2D.cpp:1684
virtual double getStepsize() const
Get stepsize.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
virtual void setField(const BMultipoleField &field)
Set field.
Definition: SBendRep.cpp:261
void initWakefunction(ElementBase &element)
Definition: OpalWake.cpp:157
Base class for all bending magnets.
Definition: OpalBend.h:30
virtual void setEntranceAngle(double entranceAngle)
Definition: BendBase.h:91
virtual void setDesignEnergy(const double &energy, bool changeable=true)
Definition: BendBase.h:112
void setExitAngle(double exitAngle)
Definition: Bend2D.h:363
ParticleMatterInteractionHandler * handler_m
virtual void setBendAngle(double angle)
Definition: BendBase.h:81
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 PlanarArcGeometry & getGeometry()
Get geometry.
Definition: SBendRep.cpp:155
void setFieldMapFN(std::string fileName)
Definition: BendBase.h:137
double skew(int) const
Get component.
virtual void setSlices(double sl)
Set number of slices.
Definition: SBendRep.cpp:252
Quaternion getRotation() const
void initParticleMatterInteractionHandler(ElementBase &element)
ParticleMatterInteraction * parmatint_m
Definition: OpalSBend.h:58
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:136
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
virtual BMultipoleField & getField()
Get field.
void releasePosition()
Definition: ElementBase.h:672
OpalWake * owk_m
Definition: OpalSBend.h:57
virtual void setEntryFaceCurvature(double h1)
Set entry pole face curvature.
Definition: SBendRep.cpp:235
virtual void update()
Update the embedded CLASSIC bend.
Definition: OpalSBend.cpp:113
virtual BMultipoleField & errorField() const
Get multipole field error.
OpalSBend()
Exemplar constructor.
Definition: OpalSBend.cpp:34
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
Representation of a perturbed sector bend.
Definition: SBendWrapper.h:37
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
The magnetic field of a multipole.
virtual void setStepsize(double ds)
Set stepsize.
Definition: SBendRep.cpp:256
bool isPositioned() const
Definition: ElementBase.h:682
virtual void setExitFaceRotation(double e2)
Set exit pole face rotation.
Definition: SBendRep.cpp:223
virtual double getExitFaceCurvature() const
Get pole face curvature.
const std::string name
void setAperture(const ApertureType &type, const std::vector< double > &args)
Definition: ElementBase.h:625
virtual double getEntryFaceRotation() const
Get pole face rotation.
virtual OpalSBend * clone(const std::string &name)
Make clone.
Definition: OpalSBend.cpp:62
void setFieldAmplitude(double k0, double k0s)
Definition: BendBase.h:125
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
int order() const
Return order.
virtual void setEntryFaceRotation(double e1)
Set pole entry face rotation.
Definition: SBendRep.cpp:219
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307
Representation for a sector bend magnet.
Definition: SBendRep.h:34
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
Definition: ElementBase.h:603