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) {
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
double getChargePerParticle() const
get the macro particle charge
virtual void visitMultipole(const Multipole &)=0
Apply the algorithm to a multipole.
Interface for a single beam element.
PartBunchBase< double, 3 > * RefPartBunch_m
virtual double getElementLength() const
Get design length.
bool isInsideTransverse(const Vector_t &r) const
Interface for general multipole.
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
std::vector< double > SkewComponents
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Multipole.
int max_NormalComponent_m
void computeField(Vector_t R, Vector_t &E, Vector_t &B)
virtual void getDimensions(double &zBegin, double &zEnd) const override
std::vector< double > SkewComponentErrors
virtual void finalise() override
void setNSlices(const std::size_t &nSlices)
virtual bool bends() const override
virtual ElementBase::ElementType getType() const override
Get element type std::string.
bool isFocusing(unsigned int component) const
std::vector< double > NormalComponents
void setNormalComponent(int, double)
Set normal component.
double getSkewComponent(int n) const
Get skew component.
std::size_t getNSlices() const
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
void setSkewComponent(int, double)
Set skew component.
std::vector< double > NormalComponentErrors
double getNormalComponent(int n) const
Get normal component.
virtual bool isInside(const Vector_t &r) const override
Vektor< double, 3 > Vector_t