48 bool revBeam,
bool revTrack):
115 double t = k * L * L;
118 s = L * (1.0 - t / 6.0);
124 double r =
sqrt(- k);
132 (
double length,
double kx,
double ks,
double ky) {
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;
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;
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;
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;
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;
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;
187 double kx = field.
normal(2);
188 double ky = - field.
normal(2);
189 double ks = field.
skew(2);
190 applyLinearMap(length, kx, ks, ky);
195 (
double length,
double refLength,
double h,
198 double ky = - field.
normal(2);
199 double ks = field.
skew(2);
200 applyLinearMap(length, kx, ks, ky);
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];
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];
228 itsMap[
PY] += euclid.
M(2, 1);
virtual void visitPatch(const Patch &pat)
Apply the algorithm to a patch.
virtual ElementBase * getElement() const
Return the contained element.
virtual const SBend & getDesign() const
Get design SBend.
virtual void visitCorrectorWrapper(const CorrectorWrapper &)
Apply the algorithm to an corrector wrapper..
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.
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a Corrector.
constexpr double e
The value of .
double normal(int) const
Get component.
virtual void setMatrix(const FMatrix< double, 6, 6 > &)
Reset the linear part of the accumulated map for restart.
virtual void applyThinSBend(const BMultipoleField &field, double scale, double h)
Thin SBend kick.
Interface for electrostatic separator.
Tps< T > sin(const Tps< T > &x)
Sine.
Define the position of a misaligned element.
virtual void visitMultipoleWrapper(const MultipoleWrapper &)
Apply the algorithm to an multipole wrapper..
double getZ() const
Get displacement.
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a Multipole.
Interface for general corrector.
Representation of a perturbed multipole.
Build a map using a linear map for each element.
double M(int row, int col) const
Get component.
void applyLinearMap(double length, double kx, double ks, double ky)
Apply linear map, defined by the linear coefficients.
LinearMap< double, 6 > itsMap
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
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.
constexpr double c
The velocity of light in m/s.
Displacement and rotation in space.
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.
virtual void visitSBend(const SBend &)
Apply the algorithm to a SBend.
Representation of a perturbed sector bend.
An abstract sequence of beam line components.
Representation for a perturbed closed orbit corrector.
Tps< T > sqrt(const Tps< T > &x)
Square root.
virtual void applyMultipoleBody(double length, double refLength, const BMultipoleField &field, double scale)
LinearFun< double, 6 > Linear
The magnetic field of a multipole.
virtual void visitAlignWrapper(const AlignWrapper &)
Apply the algorithm to an offset beamline object wrapper.
virtual void applySBendBody(double length, double refLength, double h, const BMultipoleField &field, double scale)
Tps< T > cos(const Tps< T > &x)
Cosine.
FTps< double, 2 > Series2
FMatrix< T, N, N > linearTerms() const
Extract linear terms at origin.
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
Linear function in N variables of type T.
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.
Representation of a perturbed rectangular bend.
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.
int order() const
Return order.
void applyDrift(double length)
Apply drift length.