OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
MultipoleTCurvedConstRadius.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, Titus Dascalu
3 * Copyright (c) 2018, Martin Duy Tat
4 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. Neither the name of STFC nor the names of its contributors may be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
31#include "gsl/gsl_sf_pow_int.h"
32
33using namespace endfieldmodel;
34
36 const std::string &name):
38 maxOrderX_m(10),
39 planarArcGeometry_m(1.0, 1.0),
40 angle_m(0.0) {
41}
42
44 const MultipoleTCurvedConstRadius &right):
45 MultipoleTBase(right),
46 maxOrderX_m(right.maxOrderX_m),
47 recursion_m(right.recursion_m),
48 planarArcGeometry_m(right.planarArcGeometry_m),
49 angle_m(right.angle_m) {
51}
52
54}
55
57 return new MultipoleTCurvedConstRadius(*this);
58}
59
61 double radius = getLength() / angle_m;
62 double alpha = atan(R[2] / (R[0] + radius ));
63 if (alpha != 0.0 && angle_m != 0.0) {
64 R[0] = R[2] / sin(alpha) - radius;
65 R[2] = radius * alpha;// + getBoundingBoxLength();
66 } else {
67 //R[2] = R[2] + getBoundingBoxLength();
68 }
69}
70
72 const Vector_t &R) {
73 double theta = R[2] * angle_m / getLength();
74 double Bx = B[0];
75 double Bs = B[2];
76 B[0] = Bx * cos(theta) - Bs * sin(theta);
77 B[2] = Bx * sin(theta) + Bs * cos(theta);
78}
79
80void MultipoleTCurvedConstRadius::setMaxOrder(const std::size_t &maxOrder) {
82 std::size_t N = recursion_m.size();
83 while (maxOrder >= N) {
87 recursion_m.push_back(r);
88 N = recursion_m.size();
89 }
90}
91
92double MultipoleTCurvedConstRadius::getRadius(const double &/*s*/) {
93 if (angle_m == 0.0) {
94 return -1.0;
95 } else {
96 return getLength() / angle_m;
97 }
98}
99
101 const double &/*s*/) {
102 return (1 + x * angle_m / getLength());
103}
104
105double MultipoleTCurvedConstRadius::getFn(const std::size_t &n,
106 const double &x,
107 const double &s) {
108 if (n == 0) {
109 return getTransDeriv(0, x) * getFringeDeriv(0, s);
110 }
111 double rho = getLength() / angle_m;
112 double func = 0.0;
113 for (std::size_t j = 0;
114 j <= recursion_m.at(n).getMaxSDerivatives();
115 j++) {
116 double FringeDerivj = getFringeDeriv(2 * j, s);
117 for (std::size_t i = 0;
118 i <= recursion_m.at(n).getMaxXDerivatives();
119 i++) {
120 if (recursion_m.at(n).isPolynomialZero(i, j)) {
121 continue;
122 }
123 func += (recursion_m.at(n).evaluatePolynomial(x / rho, i, j)
124 * getTransDeriv(i, x) * FringeDerivj)
125 / gsl_sf_pow_int(rho, 2 * n - i - 2 * j);
126 }
127 }
128 func *= gsl_sf_pow_int(-1.0, n);
129 return func;
130}
131
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
Definition: PETE.h:727
const std::string name
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:72
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
std::size_t getTransMaxOrder() const
virtual void setMaxOrder(const std::size_t &maxOrder)
double getLength() const
double getTransDeriv(const std::size_t &n, const double &x)
double getFringeDeriv(const std::size_t &n, const double &s)
std::vector< polynomial::RecursionRelation > recursion_m
virtual void transformBField(Vector_t &B, const Vector_t &R) override
virtual double getFn(const std::size_t &n, const double &x, const double &s) override
MultipoleTCurvedConstRadius(const std::string &name)
virtual double getRadius(const double &s) override
virtual void setMaxOrder(const std::size_t &maxOrder) override
virtual void transformCoords(Vector_t &R) override
virtual double getScaleFactor(const double &x, const double &s) override
virtual ElementBase * clone() const override
void resizeX(const std::size_t &xDerivatives)
void truncate(std::size_t highestXorder)