OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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"
19#include <cmath>
24#include "Physics/Physics.h"
26
28 : OpalBend("SBEND", "The \"SBEND\" element defines a sector bending magnet.") {
30
31 setElement((new SBendRep("SBEND")));
32}
33
34OpalSBend::OpalSBend(const std::string& name, OpalSBend* parent) : OpalBend(name, parent) {
35 setElement((new SBendRep(name)));
36}
37
39
40OpalSBend* OpalSBend::clone(const std::string& name) { return new OpalSBend(name, this); }
41
44
45 // Define geometry.
46 SBendRep* bend = dynamic_cast<SBendRep*>(getElement());
47 double length = Attributes::getReal(itsAttr[LENGTH]);
48 double angle = Attributes::getReal(itsAttr[ANGLE]);
49 double e1 = Attributes::getReal(itsAttr[E1]);
50 double e2 = Attributes::getReal(itsAttr[E2]);
51 PlanarArcGeometry& geometry = bend->getGeometry();
52
53 if (length) {
54 geometry = PlanarArcGeometry(length, angle / length);
55 } else {
56 geometry = PlanarArcGeometry(angle);
57 }
58 // Define number of slices for map tracking
60
61 // Define pole face angles.
66
67 // Define integration parameters.
70
71 // Define field.
72 double factor = OpalData::getInstance()->getP0() / Physics::c;
73 BMultipoleField field;
74 double k0 = itsAttr[K0] ? Attributes::getReal(itsAttr[K0])
75 : length ? 2 * sin(angle / 2) / length
76 : angle;
77 double k0s = itsAttr[K0S] ? Attributes::getReal(itsAttr[K0S]) : 0.0;
78 // JMJ 4/10/2000: above line replaced
79 // length ? angle / length : angle;
80 // to avoid closed orbit created by SBEND with defalt K0.
81 field.setNormalComponent(0, factor * k0);
85 field.setNormalComponent(2, factor * Attributes::getReal(itsAttr[K2]) / 2.0);
86 field.setSkewComponent(2, factor * Attributes::getReal(itsAttr[K2S]) / 2.0);
87 field.setNormalComponent(3, factor * Attributes::getReal(itsAttr[K3]) / 6.0);
88 field.setSkewComponent(3, factor * Attributes::getReal(itsAttr[K3S]) / 6.0);
89 bend->setField(field);
90
91 // Set field amplitude or bend angle.
92 if (itsAttr[ANGLE]) {
93 if (bend->isPositioned() && angle < 0.0) {
94 e1 = -e1;
95 e2 = -e2;
96 angle = -angle;
97
98 Quaternion rotAboutZ(0, 0, 0, 1);
100 bend->releasePosition();
102 CoordinateSystemTrafo(g2l.getOrigin(), rotAboutZ * g2l.getRotation()));
103 bend->fixPosition();
104 }
105 bend->setBendAngle(angle);
106 } else {
107 bend->setFieldAmplitude(k0, k0s);
108 }
109
111 throw OpalException("OpalSBend::update", "GREATERTHANPI not supportet any more");
112
113 if (itsAttr[ROTATION])
114 throw OpalException(
115 "OpalSBend::update", "ROTATION not supportet any more; use PSI instead");
116
117 if (itsAttr[FMAPFN])
119 else if (bend->getName() != "SBEND") {
120 bend->setFieldMapFN("1DPROFILE1-DEFAULT");
121 }
122
123 bend->setEntranceAngle(e1);
124 bend->setExitAngle(e2);
125
126 // Units are eV.
127 if (itsAttr[DESIGNENERGY]) {
129 }
130
132
133 if (itsAttr[APERT])
134 throw OpalException(
135 "OpalSBend::update", "APERTURE in SBEND not supported; use GAP and HAPERT instead");
136
137 if (itsAttr[HAPERT]) {
138 double hapert = Attributes::getReal(itsAttr[HAPERT]);
139 bend->setAperture(ApertureType::RECTANGULAR, std::vector<double>({hapert, hapert, 1.0}));
140 }
141
142 if (itsAttr[LENGTH])
144 else
145 bend->setLength(0.0);
146
147 if (itsAttr[WAKEF]) {
148 throw OpalException(
149 "OpalSBend::update", "WAKEF is not supported yet for the OPALX-native SBEND port.");
150 }
151
152 if (itsAttr[K1])
154 else
155 bend->setK1(0.0);
156
158 throw OpalException(
159 "OpalSBend::update",
160 "PARTICLEMATTERINTERACTION is not supported yet for the OPALX-native SBEND port.");
161 }
162
163 // Transmit "unknown" attributes.
165}
The magnetic field of a multipole.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.
void setFieldMapFN(std::string fileName)
Definition BendBase.h:221
void setExitFaceCurvature(double curvature)
Definition BendBase.h:241
void setLength(double length)
Set the nominal body length.
Definition BendBase.h:186
virtual void setEntranceAngle(double entranceAngle)
Definition BendBase.h:194
void setK1(double k1)
Definition BendBase.h:257
virtual void setBendAngle(double angle)
Definition BendBase.h:190
void setFullGap(double gap)
Definition BendBase.h:200
void setSlices(double slices)
Definition BendBase.h:245
void setExitFaceRotation(double rotation)
Definition BendBase.h:233
void setDesignEnergy(const double &energy, bool changeable=true) override
Definition BendBase.h:204
void setEntryFaceCurvature(double curvature)
Definition BendBase.h:237
void setStepsize(double stepSize)
Definition BendBase.h:249
void setNSlices(const std::size_t &nSlices)
Definition BendBase.h:253
void setFieldAmplitude(double k0, double k0s)
Store the dipole design amplitudes used by the analytic field.
Definition BendBase.h:213
void setEntryFaceRotation(double rotation)
Definition BendBase.h:229
Rigid spatial transform between a parent frame and a local frame.
ippl::Vector< double, 3 > getOrigin() const
Quaternion getRotation() const
virtual const std::string & getName() const
Get element name.
void fixPosition()
void setAperture(const ApertureType &type, const std::vector< double > &args)
bool isPositioned() const
void releasePosition()
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
ElementBase * getElement() const
Return the embedded OPALX element.
Definition Element.h:119
void setElement(ElementBase *)
Assign new OPALX element.
Definition Element.h:123
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
Base class for all bending magnets.
Definition OpalBend.h:29
@ GREATERTHANPI
Definition OpalBend.h:55
@ NSLICES
Definition OpalBend.h:57
@ ROTATION
Definition OpalBend.h:53
@ STEPSIZE
Definition OpalBend.h:49
@ DESIGNENERGY
Definition OpalBend.h:54
double getP0() const
Return value of global reference momentum.
Definition OpalData.cpp:479
static OpalData * getInstance()
Definition OpalData.cpp:193
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPALX) attributes to OPALX.
@ PARTICLEMATTERINTERACTION
Definition OpalElement.h:40
virtual void update()
Update the embedded OPALX element.
void registerOwnership() const
OpalSBend()
Exemplar constructor.
Definition OpalSBend.cpp:27
virtual void update()
Update the embedded CLASSIC bend.
Definition OpalSBend.cpp:42
virtual ~OpalSBend()
Definition OpalSBend.cpp:38
virtual OpalSBend * clone(const std::string &name)
Make clone.
Definition OpalSBend.cpp:40
A simple arc in the XZ plane.
Quaternion storage and rotation algebra used by OPALX geometry code.
Concrete OPALX representation of an analytic sector bend.
Definition SBendRep.h:13
void setField(const BMultipoleField &field)
Definition SBendRep.cpp:51
PlanarArcGeometry & getGeometry() override
Get geometry.
Definition SBendRep.cpp:47
void setExitAngle(double exitAngle) override
Definition SBend.cpp:17
double getReal(const Attribute &attr)
Return real value.
std::string getString(const Attribute &attr)
Get string value.
constexpr double c
The velocity of light in m/s.
Definition Physics.h:60