33 #include <gsl/gsl_math.h>
39 using namespace endfieldmodel;
43 fringeField_l(endfieldmodel::
Tanh()),
44 fringeField_r(endfieldmodel::
Tanh()),
48 planarArcGeometry_m(1., 1.),
53 variableRadius_m(false),
54 boundingBoxLength_m(0.0),
61 fringeField_l(right.fringeField_l),
62 fringeField_r(right.fringeField_r),
63 maxOrder_m(right.maxOrder_m),
64 maxOrderX_m(right.maxOrderX_m),
65 recursion_VarRadius_m(right.recursion_VarRadius_m),
66 recursion_ConstRadius_m(right.recursion_ConstRadius_m),
67 transMaxOrder_m(right.transMaxOrder_m),
68 transProfile_m(right.transProfile_m),
69 planarArcGeometry_m(right.planarArcGeometry_m),
70 length_m(right.length_m),
71 angle_m(right.angle_m),
72 entranceAngle_m(right.entranceAngle_m),
73 rotation_m(right.rotation_m),
74 variableRadius_m(right.variableRadius_m),
75 boundingBoxLength_m(right.boundingBoxLength_m),
76 verticalApert_m(right.verticalApert_m),
77 horizApert_m(right.horizApert_m),
121 double Bx =
getBx(R_prime);
122 double Bs =
getBs(R_prime);
123 B[0] = Bx *
cos(theta) - Bs *
sin(theta);
124 B[2] = Bx *
sin(theta) + Bs *
cos(theta);
125 B[1] =
getBz(R_prime);
129 for(
int i = 0; i < 3; i++) {
154 R_pprime[1] = R_prime[1];
192 double alpha =
atan(R[2] / (R[0] + radius ));
193 if (alpha != 0.0 &&
angle_m != 0.0) {
194 X[0] = R[2] /
sin(alpha) - radius;
196 X[2] = radius *
alpha;
220 while (maxOrder >= N) {
229 while (maxOrder >= N) {
269 for(std::size_t i = 0; i <=
n; i++) {
273 f_n *= gsl_sf_pow_int(-1.0,
n);
274 Bz += gsl_sf_pow_int(R[1], 2 *
n) / gsl_sf_fact(2 *
n) * f_n;
284 double f_n =
getFn(
n, R[0], R[2]);
285 Bz += gsl_sf_pow_int(R[1], 2 *
n) / gsl_sf_fact(2 *
n) * f_n;
300 for(std::size_t i = 0; i <=
n; i++) {
304 f_n *= gsl_sf_pow_int(-1.0,
n);
305 Bx += gsl_sf_pow_int(R[1], 2 *
n + 1) /
306 gsl_sf_fact(2 *
n + 1) * f_n;
317 Bx += partialX_fn * gsl_sf_pow_int(R[1], 2 *
n + 1)
318 / gsl_sf_fact(2 *
n + 1);
333 for(std::size_t i = 0; i <=
n; i++) {
337 f_n *= gsl_sf_pow_int(-1.0,
n);
338 Bs += gsl_sf_pow_int(R[1], 2 *
n + 1) /
339 gsl_sf_fact(2 *
n + 1) * f_n;
350 Bs += partialS_fn * gsl_sf_pow_int(R[1], 2 *
n + 1)
351 / gsl_sf_fact(2 *
n + 1);
381 for(std::size_t i = 1; i <=
n; i++) {
385 temp[j] = temp[j + 1] * (j + 1);
395 func += temp[k] * gsl_sf_pow_int(x, k);
421 std::vector<double> temp(2, 0.0);
428 std::vector<double> temp(2, 0.0);
437 return centralRadius;
459 double stepSize = 1
e-3;
460 deriv += 1. *
getFn(n, x - 2. * stepSize, s);
461 deriv += -8. *
getFn(n, x - stepSize, s);
462 deriv += 8. *
getFn(n, x + stepSize, s);
463 deriv += -1. *
getFn(n, x + 2. * stepSize, s);
464 deriv /= 12 * stepSize;
473 double stepSize = 1
e-3;
474 deriv += 1. *
getFn(n, x, s - 2. * stepSize);
475 deriv += -8. *
getFn(n, x, s - stepSize);
476 deriv += 8. *
getFn(n, x, s + stepSize);
477 deriv += -1. *
getFn(n, x, s + 2. * stepSize);
478 deriv /= 12 * stepSize;
490 for (std::size_t j = 0;
494 for (std::size_t i = 0;
501 .evaluatePolynomial(x / rho, i, j) *
503 gsl_sf_pow_int(rho, 2 * n - i - 2 * j);
506 func *= gsl_sf_pow_int(-1.0, n);
513 std::vector<double> fringeDerivatives;
514 for (std::size_t j = 0;
519 for (std::size_t i = 0;
523 for (std::size_t j = 0;
527 .evaluatePolynomial(x, y, i, j, fringeDerivatives)
528 * fringeDerivatives.at(j);
532 func *= gsl_sf_pow_int(-1.0, n) * S_0 * rho;
void truncate(std::size_t highestXorder)
std::vector< double > getFringeLength() const
std::vector< double > transProfile_m
virtual void setElementLength(double)
Set length.
double getFn(std::size_t n, double x, double s)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Abstract base class for electromagnetic fields.
double getTransDeriv(std::size_t n, double x)
ParticleAttrib< Vector_t > P
void setDipoleConstant(double B0)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
ElementBase * clone() const override
double getTanh(double x, int n) const
double getFringeDeriv(int n, double s)
A simple arc in the XZ plane.
PartBunchBase< double, 3 > * RefPartBunch_m
void resizeX(const std::size_t &xDerivatives)
void setCurvature(double)
Set curvature.
Vector_t rotateFrame(const Vector_t &R)
double getScaleFactor(double x, double s)
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
endfieldmodel::Tanh fringeField_l
void setMaxOrder(std::size_t maxOrder)
Tps< T > tanh(const Tps< T > &x)
Hyperbolic tangent.
bool bends() const override
void truncate(std::size_t highestXorder)
bool getFlagDeleteOnTransverseExit() const
bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
void setAperture(double vertAp, double horizAp)
double getBz(const Vector_t &R)
double getNegTanh(double x, int n) const
EMField & getField() override
double getFnDerivS(std::size_t n, double x, double s)
endfieldmodel::Tanh fringeField_r
std::vector< double > getTransformation() const
virtual void visitMultipoleT(const MultipoleT &)=0
Apply the algorithm to an arbitrary multipole.
Vector_t transformCoords(const Vector_t &R)
double getBx(const Vector_t &R)
double getRadius(double s)
Tps< T > cos(const Tps< T > &x)
Cosine.
constexpr double alpha
The fine structure constant, no dimension.
Tps< T > log(const Tps< T > &x)
Natural logarithm.
std::vector< double > getAperture() const
double getBs(const Vector_t &R)
MultipoleT(const std::string &name)
double boundingBoxLength_m
bool insideAperture(const Vector_t &R)
std::vector< polynomial::RecursionRelation > recursion_ConstRadius_m
bool setFringeField(double s0, double lambda_left, double lambda_right)
constexpr double e
The value of .
std::size_t transMaxOrder_m
double getFnDerivX(std::size_t n, double x, double s)
void getDimensions(double &zBegin, double &zEnd) const override
Interface for a single beam element.
Tps< T > sin(const Tps< T > &x)
Sine.
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
void setTransProfile(std::size_t n, double Bn)
std::vector< polynomial::RecursionRelationTwo > recursion_VarRadius_m
void resizeX(const std::size_t &xDerivatives)
Vector_t rotateFrameInverse(Vector_t &B)
PlanarArcGeometry planarArcGeometry_m
double integrate(const double &a, const double &s0, const double &lambdaleft, const double &lambdaright, const int &n)
void initialise(PartBunchBase< double, 3 > *, double &startField, double &endField) override
PlanarArcGeometry & getGeometry() override
void accept(BeamlineVisitor &visitor) const override