29#include "gsl/gsl_sf_pow_int.h"
36 varRadiusGeometry_m(1.0, 1.0, 1.0, 1.0, 1.0) {
84 return {x_rotated, r[1], -z_rotated};
92 return {result[0], result[1], result[2]};
98 double prefactor = rho * (
tanh(s0 / leftFringe) +
tanh(s0 / rightFringe));
99 double theta = leftFringe *
log(
cosh((
R[2] + s0) / leftFringe)) -
100 rightFringe *
log(
cosh((
R[2] - s0) / rightFringe));
102 double Bx = B[0], Bs = B[2];
103 B[0] = Bx *
cos(theta) - Bs *
sin(theta);
104 B[2] = Bx *
sin(theta) + Bs *
cos(theta);
109 while (orderZ >= N) {
123 result += x / radius;
136 std::vector<double> fringeDerivatives;
137 for (std::size_t j = 0; j <=
recursion_m.at(
n).getMaxSDerivatives(); j++) {
140 for (std::size_t i = 0; i <=
recursion_m.at(
n).getMaxXDerivatives(); i++) {
142 for (std::size_t j = 0; j <=
recursion_m.at(
n).getMaxSDerivatives(); j++) {
143 temp +=
recursion_m.at(
n).evaluatePolynomial(x, y, i, j, fringeDerivatives)
144 * fringeDerivatives.at(j);
148 result *= gsl_sf_pow_int(-1.0,
static_cast<int>(
n)) * S_0 * rho;
159 double dx =
c[0] - target[0];
160 double ds =
c[2] - target[2];
161 return sqrt(dx * dx + ds * ds);
173 bool improved =
false;
174 for (
int dim = 0; dim < 2; ++dim) {
175 for (
int dir = -1; dir <= 1; dir += 2) {
178 trial[0] += dir * step;
180 trial[2] += dir * step;
183 if (res < best_res) {
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
Tps< T > sin(const Tps< T > &x)
Sine.
Tps< T > sqrt(const Tps< T > &x)
Square root.
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
constexpr double c
The velocity of light in m/s.
std::size_t getTransMaxOrder() const
Get the maximum order in the given transverse profile.
size_t getMaxFOrder() const
Get the number of terms used in calculation of field components.
double getFringeDeriv(const std::size_t &n, const double &s)
Returns the value of the fringe field n-th derivative at s.
double getLength() const
Get the length of the magnet.
double getTransDeriv(const std::size_t &n, const double &x) const
Returns the value of the transverse field n-th derivative at x Transverse field is a polynomial in x...
size_t getMaxXOrder() const
std::tuple< double, double, double > getFringeField() const
Get the fringe field model.
double getBendAngle() const
Get the bending angle of the magnet.
double getEntryOffset() const
Get the offset of the entry point from the standard position.
void initialise() override
Initialise the element.
std::vector< polynomial::RecursionRelationTwo > recursion_m
Objects for storing differential operator acting on Fn.
void transformBField(Vector_t &, const Vector_t &) override
Transform B-field from Frenet-Serret coordinates to lab coordinates.
double getScaleFactor(double x, double s) override
Returns the scale factor .
double reverseTransformResidual(const Vector_t &r, const Vector_t &target)
static constexpr double TangentStep
double getFn(size_t n, double x, double s) override
Calculate fn(x, s) by expanding the differential operator (from Laplacian and scalar potential) in te...
MultipoleTCurvedVarRadius(MultipoleT *element)
Constructor.
static constexpr size_t ReverseTransformMaxIterations
void setMaxOrder(size_t orderZ, size_t orderX) override
Set the number of terms used in calculation of field components Maximum power of z in Bz is 2 * maxO...
Vector_t localCartesianEntryPoint_
double localCartesianRotation_
VarRadiusGeometry varRadiusGeometry_m
Geometry.
Vector_t localCartesianToCurvilinear(const Vector_t &r)
void transformCoords(Vector_t &) override
Transform to Frenet-Serret coordinates for sector magnets.
static constexpr double ReverseTransformTolerance
Vector_t localCartesianToOpalCartesian(const Vector_t &r) override
Vector_t curvilinearToLocalCartesian(const Vector_t &r)
std::vector< double > getTransformation() const
Returns a list of transformed coordinates.
void truncate(std::size_t highestXorder)
Truncate series in x at highestXorder.
void resizeX(const std::size_t &xDerivatives)
Change number of x-derivatives to xDerivatives.
void setS0(const double &s_0)
Set central fringe field length.
virtual void setElementLength(double length)
Set arc length.
void setLambdaRight(const double &lambda_right)
Set right end fringe field length.
void setLambdaLeft(const double &lambda_left)
Set left end fringe field length.
void setRadius(const double &rho)
Set centre radius of curvature.