OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
IdealMapper.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: IdealMapper.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: IdealMapper
10 // The visitor class for building a linear map for a beamline using
11 // linear maps for all elements.
12 //
13 // ------------------------------------------------------------------------
14 //
15 // $Date: 2000/03/27 09:32:33 $
16 // $Author: fci $
17 //
18 // ------------------------------------------------------------------------
19 
20 #include "Algorithms/IdealMapper.h"
21 
23 #include "AbsBeamline/Corrector.h"
24 #include "AbsBeamline/Patch.h"
25 #include "AbsBeamline/Separator.h"
31 #include "Fields/BMultipoleField.h"
32 #include "FixedAlgebra/FTpsMath.h"
33 #include "FixedAlgebra/LinearFun.h"
35 #include "Physics/Physics.h"
36 #include <cmath>
37 
38 using Physics::c;
39 
42 
43 
44 // Class IdealMapper
45 // ------------------------------------------------------------------------
46 
47 IdealMapper::IdealMapper(const Beamline &beamline, const PartData &reference,
48  bool revBeam, bool revTrack):
49  LinearMapper(beamline, reference, revBeam, revTrack)
50 {}
51 
52 
54 {}
55 
56 
58  matrix = itsMap.linearTerms();
59 }
60 
61 
63  itsMap = LinearMap<double, 6>(matrix);
64 }
65 
66 
68  // Ignore any kick for ideal orbit.
70 }
71 
72 
73 void IdealMapper::visitPatch(const Patch &patch) {
74  // Ignore patch for ideal orbit.
75 }
76 
77 
79  // Ignore any kicks for ideal orbit.
81 }
82 
83 
85  // Ignore misalignments.
86  wrap.getElement()->accept(*this);
87 }
88 
89 
91  // Ignore field errors.
92  visitCorrector(wrap.getDesign());
93 }
94 
95 
97  // Ignore field errors.
98  visitMultipole(wrap.getDesign());
99 }
100 
101 
103  // Ignore field errors.
104  visitRBend(wrap.getDesign());
105 }
106 
107 
109  // Ignore field errors.
110  visitSBend(wrap.getDesign());
111 }
112 
113 
114 void IdealMapper::makeFocus(double k, double L, double &c, double &s) {
115  double t = k * L * L;
116  if(std::abs(t) < 1.0e-4) {
117  c = 1.0 - t / 2.0;
118  s = L * (1.0 - t / 6.0);
119  } else if(k > 0.0) {
120  double r = sqrt(k);
121  c = cos(r * L);
122  s = sin(r * L) / r;
123  } else {
124  double r = sqrt(- k);
125  c = cosh(r * L);
126  s = sinh(r * L) / r;
127  }
128 }
129 
130 
132 (double length, double kx, double ks, double ky) {
133  // Extract the phase coordinates.
134  Linear x = itsMap[X];
135  Linear px = itsMap[PX];
136  Linear y = itsMap[Y];
137  Linear py = itsMap[PY];
138 
139  // Test for zero skew quadrupole component.
140  if(ks == 0.0) {
141  // Transport coefficients.
142  double cx, sx, cy, sy;
143  makeFocus(kx, length, cx, sx);
144  makeFocus(ky, length, cy, sy);
145  double wx = - kx * sx;
146  double wy = - ky * sy;
147 
148  // Advance through field.
149  itsMap[X] = cx * x + sx * px;
150  itsMap[PX] = wx * x + cx * px;
151  itsMap[Y] = cy * y + sy * py;
152  itsMap[PY] = wy * y + cy * py;
153  } else {
154  // Find transformation to principal axes.
155  double s1 = (kx + ky) / 2.0;
156  double d1 = (kx - ky) / 2.0;
157  double root = sqrt(d1 * d1 + ks * ks);
158  double c2 = d1 / root;
159  double s2 = ks / root;
160 
161  // Transport coefficients.
162  double cu, su, cv, sv;
163  double ku = s1 + (d1 * d1 - ks * ks) / root;
164  double kv = s1 - (d1 * d1 - ks * ks) / root;
165  makeFocus(ku, length, cu, su);
166  makeFocus(kv, length, cv, sv);
167  double wu = - ku * su;
168  double wv = - kv * sv;
169 
170  // Rotate the coordinates to orientation of quadrupole.
171  Linear u = c2 * x - s2 * y;
172  Linear v = c2 * y + s2 * x;
173  Linear pu = c2 * px - s2 * py;
174  Linear pv = c2 * py + s2 * px;
175 
176  // Advance through field.
177  itsMap[X] = ((cu + cv) * x + (cu - cv) * u + (su + sv) * px + (su - sv) * pu) / 2.0;
178  itsMap[PX] = ((wu + wv) * x + (wu - wv) * u + (cu + cv) * px + (cu - cv) * pu) / 2.0;
179  itsMap[Y] = ((cu + cv) * y - (cu - cv) * v + (su + sv) * py - (su - sv) * pv) / 2.0;
180  itsMap[PY] = ((wu + wv) * y - (wu - wv) * v + (cu + cv) * py - (cu - cv) * pv) / 2.0;
181  }
182 }
183 
184 
186 (double length, double refLength, const BMultipoleField &field, double scale) {
187  double kx = field.normal(2);
188  double ky = - field.normal(2);
189  double ks = field.skew(2);
190  applyLinearMap(length, kx, ks, ky);
191 }
192 
193 
195 (double length, double refLength, double h,
196  const BMultipoleField &field, double scale) {
197  double kx = (h * field.normal(1) + field.normal(2));
198  double ky = - field.normal(2);
199  double ks = field.skew(2);
200  applyLinearMap(length, kx, ks, ky);
201 }
202 
203 
205 (const BMultipoleField &field, double scale) {
206  if(field.order() >= 2) {
207  double kn = scale * field.normal(2);
208  double ks = scale * field.skew(2);
209  itsMap[PX] -= kn * itsMap[X] + ks * itsMap[Y];
210  itsMap[PY] -= ks * itsMap[X] - kn * itsMap[Y];
211  }
212 }
213 
214 
216 (const BMultipoleField &field, double scale, double h) {
217  double kx = (h * field.normal(1) + field.normal(2));
218  double ky = - field.normal(2);
219  double ks = field.skew(2);
220  itsMap[PX] -= kx * itsMap[X] + ks * itsMap[Y];
221  itsMap[PY] -= ks * itsMap[X] + ky * itsMap[Y];
222 }
223 
224 
225 void IdealMapper::applyTransform(const Euclid3D &euclid, double refLength) {
226  applyDrift(- euclid.getZ());
227  itsMap[PX] += euclid.M(2, 0);
228  itsMap[PY] += euclid.M(2, 1);
229 }
virtual void visitPatch(const Patch &pat)
Apply the algorithm to a patch.
Definition: IdealMapper.cpp:73
virtual ElementBase * getElement() const
Return the contained element.
Definition: rbendmap.h:8
virtual const SBend & getDesign() const
Get design SBend.
virtual void visitCorrectorWrapper(const CorrectorWrapper &)
Apply the algorithm to an corrector wrapper..
Definition: IdealMapper.cpp:90
virtual const Multipole & getDesign() const
Get design corrector.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
virtual void visitSeparator(const Separator &)
Apply the algorithm to a Separator.
Definition: IdealMapper.cpp:78
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a Corrector.
Definition: IdealMapper.cpp:67
constexpr double e
The value of .
Definition: Physics.h:40
double normal(int) const
Get component.
virtual void setMatrix(const FMatrix< double, 6, 6 > &)
Reset the linear part of the accumulated map for restart.
Definition: IdealMapper.cpp:62
virtual void applyThinSBend(const BMultipoleField &field, double scale, double h)
Thin SBend kick.
Interface for electrostatic separator.
Definition: Separator.h:33
Definition: rbendmap.h:8
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
Define the position of a misaligned element.
Definition: AlignWrapper.h:39
virtual void visitMultipoleWrapper(const MultipoleWrapper &)
Apply the algorithm to an multipole wrapper..
Definition: IdealMapper.cpp:96
double getZ() const
Get displacement.
Definition: Euclid3D.h:224
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a Multipole.
Particle reference data.
Definition: PartData.h:38
Interface for general corrector.
Definition: Corrector.h:35
Representation of a perturbed multipole.
Definition: rbendmap.h:8
Build a map using a linear map for each element.
Definition: LinearMapper.h:68
double M(int row, int col) const
Get component.
Definition: Euclid3D.h:228
void applyLinearMap(double length, double kx, double ks, double ky)
Apply linear map, defined by the linear coefficients.
virtual ~IdealMapper()
Definition: IdealMapper.cpp:53
LinearMap< double, 6 > itsMap
Definition: LinearMapper.h:213
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
Definition: TpsMath.h:222
virtual void applyTransform(const Euclid3D &, double refLength)
Apply transform.
virtual const RBend & getDesign() const
Get design RBend.
double skew(int) const
Get component.
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:511
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
Displacement and rotation in space.
Definition: Euclid3D.h:68
virtual void visitRBendWrapper(const RBendWrapper &)
Apply the algorithm to an RBend wrapper..
virtual const Corrector & getDesign() const
Get design corrector.
virtual void applyThinMultipole(const BMultipoleField &field, double factor)
Thin multipole kick.
virtual void getMatrix(FMatrix< double, 6, 6 > &) const
Return the linear part of the accumulated map.
Definition: IdealMapper.cpp:57
virtual void visitSBend(const SBend &)
Apply the algorithm to a SBend.
Representation of a perturbed sector bend.
Definition: SBendWrapper.h:37
An abstract sequence of beam line components.
Definition: Beamline.h:37
Representation for a perturbed closed orbit corrector.
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
virtual void applyMultipoleBody(double length, double refLength, const BMultipoleField &field, double scale)
LinearFun< double, 6 > Linear
Definition: IdealMapper.cpp:41
The magnetic field of a multipole.
virtual void visitAlignWrapper(const AlignWrapper &)
Apply the algorithm to an offset beamline object wrapper.
Definition: IdealMapper.cpp:84
virtual void applySBendBody(double length, double refLength, double h, const BMultipoleField &field, double scale)
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
FTps< double, 2 > Series2
FMatrix< T, N, N > linearTerms() const
Extract linear terms at origin.
Definition: LinearMap.hpp:243
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
Linear function in N variables of type T.
Definition: LinearFun.h:39
virtual void visitSBendWrapper(const SBendWrapper &)
Apply the algorithm to an SBend wrapper..
Truncated power series in N variables of type T.
Interface for a geometric patch.
Definition: Patch.h:34
Representation of a perturbed rectangular bend.
Definition: RBendWrapper.h:37
static void makeFocus(double k, double L, double &c, double &s)
Helper function for finding first-order coefficients.
Tps< T > sinh(const Tps< T > &x)
Hyperbolic sine.
Definition: TpsMath.h:204
int order() const
Return order.
void applyDrift(double length)
Apply drift length.
Definition: rbendmap.h:8