OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
MultipoleTStraight.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#include "gsl/gsl_sf_gamma.h"
30#include "gsl/gsl_sf_pow_int.h"
31#include "MultipoleTStraight.h"
32
33using namespace endfieldmodel;
34
39
45
46
49
51 return new MultipoleTStraight(*this);
52}
53
55 //R[2] += getBoundingBoxLength();
56}
57
58void MultipoleTStraight::setMaxOrder(const std::size_t &maxOrder) {
60}
61
63 double Bx = 0.0;
64 for(std::size_t n = 0; n <= getMaxOrder(); n++) {
65 double f_n = 0.0;
66 for(std::size_t i = 0; i <= n; i++) {
67 f_n += gsl_sf_choose(n, i) * getTransDeriv(2 * i + 1, R[0]) *
68 getFringeDeriv(2 * n - 2 * i, R[2]);
69 }
70 f_n *= gsl_sf_pow_int(-1.0, n);
71 Bx += f_n * gsl_sf_pow_int(R[1], 2 * n + 1) / gsl_sf_fact(2 * n + 1);
72 }
73 return Bx;
74}
75
77 double Bs = 0.0;
78 for(std::size_t n = 0; n <= getMaxOrder(); n++) {
79 double f_n = 0.0;
80 for(std::size_t i = 0; i <= n; i++) {
81 f_n += gsl_sf_choose(n, i) * getTransDeriv(2 * i, R[0]) *
82 getFringeDeriv(2 * n - 2 * i + 1, R[2]);
83 }
84 f_n *= gsl_sf_pow_int(-1.0, n);
85 Bs += f_n * gsl_sf_pow_int(R[1], 2 * n + 1) / gsl_sf_fact(2 * n + 1);
86 }
87 return Bs;
88}
89
90double MultipoleTStraight::getFn(const std::size_t &n,
91 const double &x,
92 const double &s) {
93 if (n == 0) {
94 return getTransDeriv(0, x) * getFringeDeriv(0, s);
95 }
96 double f_n = 0.0;
97 for (std::size_t i = 0; i <= n; i++) {
98 f_n += gsl_sf_choose(n, i) * getTransDeriv(2 * i, x) *
99 getFringeDeriv(2 * n - 2 * i, s);
100 }
101 f_n *= gsl_sf_pow_int(-1.0, n);
102 return f_n;
103}
104
ippl::Vector< T, Dim > Vector_t
PartBunch_t * RefPartBunch_m
Definition Component.h:185
ElementBase(const std::string &name)
Constructor with given name.
virtual void setMaxOrder(const std::size_t &maxOrder)
double getLength() const
std::size_t getMaxOrder() const
double getTransDeriv(const std::size_t &n, const double &x)
double getFringeDeriv(const std::size_t &n, const double &s)
virtual double getBs(const Vector_t< double, 3 > &R) override
virtual double getBx(const Vector_t< double, 3 > &R) override
StraightGeometry straightGeometry_m
virtual double getFn(const std::size_t &n, const double &x, const double &s) override
virtual void setMaxOrder(const std::size_t &maxOrder) override
virtual ElementBase * clone() const override
MultipoleTStraight(const std::string &name)
virtual void transformCoords(Vector_t< double, 3 > &R) override