OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalSBend.cpp
Go to the documentation of this file.
1 //
2 // Class OpalSBend
3 // The SBEND element.
4 //
5 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #include "Elements/OpalSBend.h"
20 #include "Attributes/Attributes.h"
21 #include "BeamlineCore/SBendRep.h"
22 #include "Fields/BMultipoleField.h"
23 #include "Physics/Physics.h"
24 #include "Structure/OpalWake.h"
27 
29  OpalBend("SBEND",
30  "The \"SBEND\" element defines a sector bending magnet."),
31  owk_m(NULL),
32  parmatint_m(NULL) {
33 
35 
36  setElement((new SBendRep("SBEND")));
37 }
38 
39 
40 OpalSBend::OpalSBend(const std::string& name, OpalSBend* parent):
41  OpalBend(name, parent),
42  owk_m(NULL),
43  parmatint_m(NULL) {
44  setElement((new SBendRep(name)));
45 }
46 
47 
49  delete owk_m;
50  delete parmatint_m;
51 }
52 
53 
54 OpalSBend* OpalSBend::clone(const std::string& name) {
55  return new OpalSBend(name, this);
56 }
57 
58 
61 
62  // Define geometry.
63  SBendRep* bend = dynamic_cast<SBendRep*>(getElement());
64 
65  double length = Attributes::getReal(itsAttr[LENGTH]);
66  double angle = Attributes::getReal(itsAttr[ANGLE]);
67  double e1 = Attributes::getReal(itsAttr[E1]);
68  double e2 = Attributes::getReal(itsAttr[E2]);
69  PlanarArcGeometry &geometry = bend->getGeometry();
70 
71  if (length) {
72  geometry = PlanarArcGeometry(length, angle / length);
73  } else {
74  geometry = PlanarArcGeometry(angle);
75  }
76  // Define number of slices for map tracking
78 
79  // Define pole face angles.
84 
85  // Define integration parameters.
88 
89  // Define field.
90  double factor = OpalData::getInstance()->getP0() / Physics::c;
91  BMultipoleField field;
92  double k0 = itsAttr[K0] ? Attributes::getReal(itsAttr[K0]) :
93  length ? 2 * sin(angle / 2) / length : angle;
94  double k0s = itsAttr[K0S] ? Attributes::getReal(itsAttr[K0S]) : 0.0;
95  //JMJ 4/10/2000: above line replaced
96  // length ? angle / length : angle;
97  // to avoid closed orbit created by SBEND with default K0.
98  field.setNormalComponent(1, factor * k0);
99  field.setSkewComponent(1, factor * Attributes::getReal(itsAttr[K0S]));
100  field.setNormalComponent(2, factor * Attributes::getReal(itsAttr[K1]));
101  field.setSkewComponent(2, factor * Attributes::getReal(itsAttr[K1S]));
102  field.setNormalComponent(3, factor * Attributes::getReal(itsAttr[K2]) / 2.0);
103  field.setSkewComponent(3, factor * Attributes::getReal(itsAttr[K2S]) / 2.0);
104  field.setNormalComponent(4, factor * Attributes::getReal(itsAttr[K3]) / 6.0);
105  field.setSkewComponent(4, factor * Attributes::getReal(itsAttr[K3S]) / 6.0);
106  bend->setField(field);
107 
108  // Set field amplitude or bend angle.
109  if (itsAttr[ANGLE]) {
110  if (bend->isPositioned() && angle < 0.0) {
111  e1 = -e1;
112  e2 = -e2;
113  angle = -angle;
114 
115  Quaternion rotAboutZ(0, 0, 0, 1);
117  bend->releasePosition();
119  rotAboutZ * g2l.getRotation()));
120  bend->fixPosition();
121  }
122  bend->setBendAngle(angle);
123  } else {
124  bend->setFieldAmplitude(k0, k0s);
125  }
126 
127  if (itsAttr[GREATERTHANPI]) {
128  throw OpalException("OpalSBend::update",
129  "GREATERTHANPI not supported anymore");
130  }
131 
132  if (itsAttr[ROTATION]) {
133  throw OpalException("OpalSBend::update",
134  "ROTATION not supported anymore; use PSI instead");
135  }
136 
137  if (itsAttr[FMAPFN]) {
139  } else if (bend->getName() != "SBEND") {
140  ERRORMSG(bend->getName() << ": No filename for a field map given. "
141  "Will assume the default map "
142  "\"1DPROFILE1-DEFAULT\"."
143  << endl);
144  bend->setFieldMapFN("1DPROFILE1-DEFAULT");
145  }
146 
147  bend->setEntranceAngle(e1);
148  bend->setExitAngle(e2);
149 
150  // Units are eV.
153  } else if (bend->getName() != "SBEND") {
154  throw OpalException("OpalSBend::update",
155  "SBend requires non-zero DESIGNENERGY");
156  }
157 
158  double gap = Attributes::getReal(itsAttr[GAP]);
159  bend->setFullGap(gap);
160 
161  if (itsAttr[APERT]) {
162  throw OpalException("OpalSBend::update",
163  "APERTURE in SBEND not supported; use GAP and HAPERT instead");
164  }
165 
166  if (itsAttr[HAPERT]) {
167  double hapert = Attributes::getReal(itsAttr[HAPERT]);
168  bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, gap, 1.0}));
169  } else {
170  bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({0.5, gap, 1.0}));
171  }
172 
173  if (itsAttr[WAKEF] && itsAttr[DESIGNENERGY] && owk_m == NULL) {
174  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
175  owk_m->initWakefunction(*bend);
176  bend->setWake(owk_m->wf_m);
177  }
178 
179  if (itsAttr[K1]) {
181  } else {
182  bend->setK1(0.0);
183  }
184 
186  const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
188  parmatint_m = orig->clone(matterDescriptor);
191  }
192 
193  // Transmit "unknown" attributes.
195 }
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:281
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:569
static OpalData * getInstance()
Definition: OpalData.cpp:195
void setExitAngle(double exitAngle)
Definition: Bend2D.h:341
void setK1(double k1)
Set quadrupole field component.
Definition: Bend2D.h:305
void setNSlices(const std::size_t &nSlices)
Definition: Bend2D.cpp:1636
virtual void setEntranceAngle(double entranceAngle) override
Definition: Bend2D.h:332
void setFieldMapFN(std::string fileName)
Definition: BendBase.h:137
virtual void setDesignEnergy(const double &energy, bool changeable=true)
Definition: BendBase.h:118
void setFullGap(double)
Definition: BendBase.h:108
virtual void setBendAngle(double angle)
Definition: BendBase.h:87
void setFieldAmplitude(double k0, double k0s)
Definition: BendBase.cpp:56
virtual const std::string & getName() const
Get element name.
void fixPosition()
Definition: ElementBase.h:568
void setAperture(const ApertureType &type, const std::vector< double > &args)
Definition: ElementBase.h:536
bool isPositioned() const
Definition: ElementBase.h:573
void releasePosition()
Definition: ElementBase.h:563
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
Definition: ElementBase.h:515
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
Definition: ElementBase.h:508
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
Quaternion getRotation() const
virtual void setEntryFaceCurvature(double h1)
Set entry pole face curvature.
Definition: SBendRep.cpp:189
virtual void setEntryFaceRotation(double e1)
Set pole entry face rotation.
Definition: SBendRep.cpp:173
virtual void setExitFaceCurvature(double h2)
Set exit pole face curvature.
Definition: SBendRep.cpp:193
virtual PlanarArcGeometry & getGeometry()
Get geometry.
Definition: SBendRep.cpp:146
virtual void setSlices(double sl)
Set number of slices.
Definition: SBendRep.cpp:206
virtual void setField(const BMultipoleField &field)
Set field.
Definition: SBendRep.cpp:215
virtual void setExitFaceRotation(double e2)
Set exit pole face rotation.
Definition: SBendRep.cpp:177
virtual void setStepsize(double ds)
Set stepsize.
Definition: SBendRep.cpp:210
A simple arc in the XZ plane.
The magnetic field of a multipole.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.
Base class for all bending magnets.
Definition: OpalBend.h:30
@ GREATERTHANPI
Definition: OpalBend.h:50
@ SLICES
Definition: OpalBend.h:44
@ NSLICES
Definition: OpalBend.h:52
@ ROTATION
Definition: OpalBend.h:48
@ STEPSIZE
Definition: OpalBend.h:44
@ HAPERT
Definition: OpalBend.h:47
@ FMAPFN
Definition: OpalBend.h:45
@ DESIGNENERGY
Definition: OpalBend.h:49
@ ANGLE
Definition: OpalBend.h:36
@ PARTICLEMATTERINTERACTION
Definition: OpalElement.h:39
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
OpalSBend()
Exemplar constructor.
Definition: OpalSBend.cpp:28
virtual void update()
Update the embedded CLASSIC bend.
Definition: OpalSBend.cpp:59
virtual ~OpalSBend()
Definition: OpalSBend.cpp:48
ParticleMatterInteraction * parmatint_m
Definition: OpalSBend.h:51
virtual OpalSBend * clone(const std::string &name)
Make clone.
Definition: OpalSBend.cpp:54
OpalWake * owk_m
Definition: OpalSBend.h:50
WakeFunction * wf_m
Definition: OpalWake.h:57
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:125
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:146
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
ParticleMatterInteractionHandler * handler_m
void initParticleMatterInteractionHandler(ElementBase &element)
The base class for all OPAL exceptions.
Definition: OpalException.h:28