37 unsigned int factorial(
unsigned int n) {
38 static int fact[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320,
39 362880, 3628800, 39916800, 479001600};
54 NormalComponents(right.NormalComponents),
55 NormalComponentErrors(right.NormalComponentErrors),
56 SkewComponents(right.SkewComponents),
57 SkewComponentErrors(right.SkewComponentErrors),
58 max_SkewComponent_m(right.max_SkewComponent_m),
59 max_NormalComponent_m(right.max_NormalComponent_m),
60 nSlices_m(right.nSlices_m) {
66 NormalComponents(1, 0.0),
67 NormalComponentErrors(1, 0.0),
68 SkewComponents(1, 0.0),
69 SkewComponentErrors(1, 0.0),
70 max_SkewComponent_m(1),
71 max_NormalComponent_m(1),
179 B(0) += 4 *
NormalComponents[i] * (Rn[3](0) * Rn[1](1) - Rn[1](0) * Rn[3](1));
180 B(1) +=
NormalComponents[i] * (Rn[4](0) - 6 * Rn[2](0) * Rn[2](1) + Rn[4](1));
185 double powMinusOne = 1;
186 double Bx = 0.0, By = 0.0;
187 for (
int j = 1; j <= (i + 1) / 2; ++ j) {
188 Bx += powMinusOne *
NormalComponents[i] * (Rn[i - 2 * j + 1](0) * fact[i - 2 * j + 1] *
189 Rn[2 * j - 1](1) * fact[2 * j - 1]);
190 By += powMinusOne *
NormalComponents[i] * (Rn[i - 2 * j + 2](0) * fact[i - 2 * j + 2] *
191 Rn[2 * j - 2](1) * fact[2 * j - 2]);
195 if ((i + 1) / 2 == i / 2) {
197 By += powMinusOne *
NormalComponents[i] * (Rn[i - 2 * j + 2](0) * fact[i - 2 * j + 2] *
198 Rn[2 * j - 2](1) * fact[2 * j - 2]);
205 Rn[i + 1](0) = Rn[i](0) *
R(0);
206 Rn[i + 1](1) = Rn[i](1) *
R(1);
207 fact[i + 1] = fact[i] / (i + 1);
239 B(0) -=
SkewComponents[i] * (Rn[4](0) - 6 * Rn[2](0) * Rn[2](1) + Rn[4](1));
240 B(1) += 4 *
SkewComponents[i] * (Rn[3](0) * Rn[1](1) - Rn[1](0) * Rn[3](1));
245 double powMinusOne = 1;
246 double Bx = 0, By = 0;
247 for (
int j = 1; j <= (i + 1) / 2; ++ j) {
248 Bx -= powMinusOne *
SkewComponents[i] * (Rn[i - 2 * j + 2](0) * fact[i - 2 * j + 2] *
249 Rn[2 * j - 2](1) * fact[2 * j - 2]);
250 By += powMinusOne *
SkewComponents[i] * (Rn[i - 2 * j + 1](0) * fact[i - 2 * j + 1] *
251 Rn[2 * j - 1](1) * fact[2 * j - 1]);
255 if ((i + 1) / 2 == i / 2) {
257 Bx -= powMinusOne *
SkewComponents[i] * (Rn[i - 2 * j + 2](0) * fact[i - 2 * j + 2] *
258 Rn[2 * j - 2](1) * fact[2 * j - 2]);
266 Rn[i + 1](0) = Rn[i](0) *
R(0);
267 Rn[i + 1](1) = Rn[i](1) *
R(1);
268 fact[i + 1] = fact[i] / (i + 1);
282 for (
unsigned int d = 0; d < 3; ++ d) {
std::vector< double > NormalComponentErrors
virtual bool isInside(const Vector_t &r) const override
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Multipole.
void setNormalComponent(int, double)
Set normal component.
item[EANGLE] Entrance edge counterclockwise This enables to obtain skew at each point along the its radius is computed such that the reference trajectory always remains in the centre of the magnet In the body of the magnet the radius is set from the LENGTH and ANGLE attributes It is then continuously changed to be proportional to the dipole field on the reference trajectory while entering the end fields This attribute is only to be set TRUE for a non zero dipole component(Default:FALSE)\item[VARSTEP] The step size(meters) used in calculating the reference trajectory for VARRARDIUS
bool isFocusing(unsigned int component) const
Vektor< double, 3 > Vector_t
virtual void finalise() override
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
virtual bool bends() const override
int max_NormalComponent_m
PartBunchBase< double, 3 > * RefPartBunch_m
Interface for general multipole.
void setNSlices(const std::size_t &nSlices)
std::vector< double > NormalComponents
virtual void visitMultipole(const Multipole &)=0
Apply the algorithm to a multipole.
bool getFlagDeleteOnTransverseExit() const
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
std::vector< double > SkewComponents
std::size_t getNSlices() const
virtual void getDimensions(double &zBegin, double &zEnd) const override
void computeField(Vector_t R, Vector_t &E, Vector_t &B)
virtual double getElementLength() const
Get design length.
double getNormalComponent(int n) const
Get normal component.
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
double getChargePerParticle() const
get the macro particle charge
bool isInsideTransverse(const Vector_t &r) const
double getSkewComponent(int n) const
Get skew component.
std::vector< double > SkewComponentErrors
Interface for a single beam element.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
void setSkewComponent(int, double)
Set skew component.
virtual ElementType getType() const override
Get element type std::string.