OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
RBend.cpp
Go to the documentation of this file.
1//
2// Class RBend
3// Interface for a rectangular bend magnet.
4//
5// A rectangular bend magnet physically has a rectangular shape.
6//
7// The standard rectangular magnet, for purposes of definitions, has a field in
8// the y direction. This produces a bend in the horizontal (x) plane. Bends in
9// other planes can be accomplished by rotating the magnet about the axes.
10//
11// A positive bend angle is defined as one that bends a beam to the right when
12// looking down (in the negative y direction) so that the beam is bent in the
13// negative x direction. (This definition of a positive bend is the same whether
14// the charge is positive or negative.)
15//
16// A zero degree entrance edge angle is parallel to the x direction in an x/y/s
17// coordinate system. A positive entrance edge angle is defined as one that
18// rotates the positive edge (in x) of the angle toward the positive s axis.
19//
20// Since the magnet geometry is a fixed rectangle, the exit edge angle is
21// defined by the bend angle of the magnet and the entrance edge angle. In
22// general, the exit edge angle is equal to the bend angle minus the entrance
23// edge angle.
24//
25// ------------------------------------------------------------------------
26//
27// This class defines two interfaces:
28//
29// 1) Interface for rectangular magnets for OPAL-MAP.
30//
31// Here we specify multipole components about the curved magnet trajectory.
32//
33// 2) Interface for rectangular magnets for OPAL-T.
34//
35// Here we defined the magnet as a field map.
36//
37// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
38// All rights reserved
39//
40// This file is part of OPAL.
41//
42// OPAL is free software: you can redistribute it and/or modify
43// it under the terms of the GNU General Public License as published by
44// the Free Software Foundation, either version 3 of the License, or
45// (at your option) any later version.
46//
47// You should have received a copy of the GNU General Public License
48// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
49//
50
51#include "AbsBeamline/RBend.h"
54#include "Utilities/Options.h"
55#include "Fields/Fieldmap.h"
57
58#include <iostream>
59#include <fstream>
60#include <cmath>
61
63 RBend("")
64{}
65
66RBend::RBend(const RBend &right):
67 Bend2D(right)
68{
69 setMessageHeader("RBend ");
70}
71
72RBend::RBend(const std::string &name):
74{
75 setMessageHeader("RBend ");
76}
77
79}
80
81void RBend::accept(BeamlineVisitor &visitor) const {
82 visitor.visitRBend(*this);
83}
84
85/*
86 * OPAL-MAP methods
87 * ================
88 */
89double RBend::getNormalComponent(int n) const {
91}
92
93double RBend::getSkewComponent(int n) const {
94 return getField().getSkewComponent(n);
95}
96
97void RBend::setNormalComponent(int n, double v) {
99}
100
101void RBend::setSkewComponent(int n, double v) {
103}
104
105/*
106 * OPAL-T Methods.
107 * ===============
108 */
109
110/*
111 * This function merely repackages the field arrays as type Vector_t and calls
112 * the equivalent method but with the Vector_t data types.
113 */
114
116 return ElementType::RBEND;
117}
118
119void RBend::setBendAngle(double angle) {
122}
123
124void RBend::setEntranceAngle(double entranceAngle) {
125 Bend2D::setEntranceAngle(entranceAngle);
126 setExitAngle(getBendAngle() - entranceAngle);
127}
128
129bool RBend::findChordLength(double &chordLength) {
130
131 /*
132 * Find bend chord length. If this was not set by the user using the
133 * L (length) attribute, infer it from the field map.
134 */
135 const double angle = getBendAngle();
136 if (std::abs(angle) > 0.0) {
137 double E1 = std::copysign(1.0, angle) * getEntranceAngle();
138 chordLength = 2 * getElementLength() * std::sin(0.5 * std::abs(angle)) /
139 (std::sin(E1) + std::sin(std::abs(angle) - E1));
140 } else {
141 double refCharge = RefPartBunch_m->getQ();
142 double amplitude = (fieldAmplitudeY_m != 0.0) ? fieldAmplitudeY_m : fieldAmplitudeX_m;
143 double fieldAmplitude = std::copysign(1.0, refCharge) * std::abs(amplitude);
144 double designRadius = calcDesignRadius(fieldAmplitude);
145 chordLength = std::sin(0.5 * (std::asin(getElementLength() / designRadius - std::sin(getEntranceAngle())) + getEntranceAngle())) * 2 * designRadius;
146 }
147
148 return true;
149}
ElementType
Definition: ElementBase.h:88
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
PETE_TUTree< FnArcSin, typename T::PETE_Expr_t > asin(const PETE_Expr< T > &l)
Definition: PETE.h:726
PETE_TBTree< FnCopysign, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > copysign(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
const std::string name
double getQ() const
Access to reference data.
virtual void visitRBend(const RBend &)=0
Apply the algorithm to a rectangular bend.
Definition: Bend2D.h:51
void setExitAngle(double exitAngle)
Definition: Bend2D.h:341
virtual void setEntranceAngle(double entranceAngle) override
Definition: Bend2D.h:332
void setMessageHeader(const std::string &header)
Definition: Bend2D.h:314
double getBendAngle() const
Definition: BendBase.h:92
double fieldAmplitudeY_m
Definition: BendBase.h:68
virtual void setBendAngle(double angle)
Definition: BendBase.h:87
double getEntranceAngle() const
Definition: BendBase.h:103
double calcDesignRadius(double fieldAmplitude) const
Calculate design radius from design energy and field amplitude.
Definition: BendBase.cpp:61
double fieldAmplitudeX_m
Definition: BendBase.h:66
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:414
Definition: RBend.h:58
virtual void setBendAngle(double angle) override
Definition: RBend.cpp:119
RBend()
Definition: RBend.cpp:62
virtual void accept(BeamlineVisitor &) const override
Apply visitor to RBend.
Definition: RBend.cpp:81
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
double getNormalComponent(int) const
Get normal component.
Definition: RBend.cpp:89
virtual bool findChordLength(double &chordLength) override
Definition: RBend.cpp:129
void setNormalComponent(int, double)
Set normal component.
Definition: RBend.cpp:97
virtual ~RBend()
Definition: RBend.cpp:78
void setSkewComponent(int, double)
Set skew component.
Definition: RBend.cpp:101
double getSkewComponent(int) const
Get skew component.
Definition: RBend.cpp:93
virtual ElementType getType() const override
Get element type std::string.
Definition: RBend.cpp:115
virtual void setEntranceAngle(double entranceAngle) override
Definition: RBend.cpp:124
double getNormalComponent(int n) const
Get component.
double getSkewComponent(int n) const
Get component.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.