OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalRBend.cpp
Go to the documentation of this file.
1//
2// Class OpalRBend
3// The RBEND 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/OpalRBend.h"
19#include <cmath>
24#include "Physics/Physics.h"
26
28 : OpalBend("RBEND", "The \"RBEND\" element defines a rectangular bending magnet.") {
30
31 setElement(new RBendRep("RBEND"));
32}
33
34OpalRBend::OpalRBend(const std::string& name, OpalRBend* parent) : OpalBend(name, parent) {
35 setElement(new RBendRep(name));
36}
37
39
40OpalRBend* OpalRBend::clone(const std::string& name) { return new OpalRBend(name, this); }
41
44
45 // Define geometry.
46 RBendRep* bend = dynamic_cast<RBendRep*>(getElement());
47 double length = Attributes::getReal(itsAttr[LENGTH]);
48 double angle = Attributes::getReal(itsAttr[ANGLE]);
49 double e1 = Attributes::getReal(itsAttr[E1]);
50 RBendGeometry& geometry = bend->getGeometry();
51 geometry.setElementLength(length);
52 if (angle < 0) {
53 }
54 geometry.setBendAngle(angle);
55
56 // Define number of slices for map tracking
58
59 // Define pole face angles.
64
65 // Define integration parameters.
68
69 // Define field.
70 double factor = OpalData::getInstance()->getP0() / Physics::c;
71 BMultipoleField field;
72 double k0 = itsAttr[K0] ? Attributes::getReal(itsAttr[K0])
73 : length ? 2 * sin(angle / 2) / length
74 : angle;
75 double k0s = itsAttr[K0S] ? Attributes::getReal(itsAttr[K0S]) : 0.0;
76 // JMJ 4/10/2000: above line replaced
77 // length ? angle / length : angle;
78 // to avoid closed orbit created by RBEND with defalt K0.
79 field.setNormalComponent(0, factor * k0);
83 field.setNormalComponent(2, factor * Attributes::getReal(itsAttr[K2]) / 2.0);
84 field.setSkewComponent(2, factor * Attributes::getReal(itsAttr[K2S]) / 2.0);
85 field.setNormalComponent(3, factor * Attributes::getReal(itsAttr[K3]) / 6.0);
86 field.setSkewComponent(3, factor * Attributes::getReal(itsAttr[K3S]) / 6.0);
87 bend->setField(field);
88
89 // Set field amplitude or bend angle.
90 if (itsAttr[ANGLE]) {
91 if (bend->isPositioned() && angle < 0.0) {
92 e1 = -e1;
93 angle = -angle;
94
95 Quaternion rotAboutZ(0, 0, 0, 1);
97 bend->releasePosition();
99 CoordinateSystemTrafo(g2l.getOrigin(), rotAboutZ * g2l.getRotation()));
100 bend->fixPosition();
101 }
102 bend->setBendAngle(angle);
103 } else {
104 bend->setFieldAmplitude(k0, k0s);
105 }
106 bend->setEntranceAngle(e1);
107
108 if (itsAttr[ROTATION])
109 throw OpalException(
110 "OpalRBend::update", "ROTATION not supported any more; use PSI instead");
111
112 if (itsAttr[FMAPFN])
114 else if (bend->getName() != "RBEND") {
115 bend->setFieldMapFN("1DPROFILE1-DEFAULT");
116 }
117
118 // Energy in eV.
119 if (itsAttr[DESIGNENERGY]) {
121 }
122
124
125 if (itsAttr[HAPERT]) {
126 double hapert = Attributes::getReal(itsAttr[HAPERT]);
127 bend->setAperture(ApertureType::RECTANGULAR, std::vector<double>({hapert, hapert, 1.0}));
128 }
129
130 if (itsAttr[LENGTH])
132 else
133 bend->setLength(0.0);
134
135 if (itsAttr[WAKEF]) {
136 throw OpalException(
137 "OpalRBend::update", "WAKEF is not supported yet for the OPALX-native RBEND port.");
138 }
139
140 if (itsAttr[K1])
142 else
143 bend->setK1(0.0);
144
146 throw OpalException(
147 "OpalRBend::update",
148 "PARTICLEMATTERINTERACTION is not supported yet for the OPALX-native RBEND port.");
149 }
150
151 // Transmit "unknown" attributes.
153}
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
@ 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
virtual OpalRBend * clone(const std::string &name)
Make clone.
Definition OpalRBend.cpp:40
OpalRBend()
Exemplar constructor.
Definition OpalRBend.cpp:27
virtual void update()
Update the embedded CLASSIC bend.
Definition OpalRBend.cpp:42
virtual ~OpalRBend()
Definition OpalRBend.cpp:38
Quaternion storage and rotation algebra used by OPALX geometry code.
The geometry for a RBend element.
void setBendAngle(double angle)
Set angle.
Concrete OPALX representation of an analytic rectangular bend.
Definition RBendRep.h:13
RBendGeometry & getGeometry() override
Get geometry.
Definition RBendRep.cpp:47
void setField(const BMultipoleField &field)
Definition RBendRep.cpp:51
virtual void setElementLength(double length)
Set design length.
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