OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
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 
30 #include "gsl/gsl_sf_gamma.h"
31 #include "gsl/gsl_sf_pow_int.h"
32 #include "MultipoleTStraight.h"
33 
34 using namespace endfieldmodel;
35 
37  MultipoleTBase(name),
38  straightGeometry_m(getLength()) {
39 }
40 
42  MultipoleTBase(right),
43  straightGeometry_m(right.straightGeometry_m) {
45 }
46 
47 
49 }
50 
52  return new MultipoleTStraight(*this);
53 }
54 
56  //R[2] += getBoundingBoxLength();
57 }
58 
59 void MultipoleTStraight::setMaxOrder(const std::size_t &maxOrder) {
61 }
62 
64  double Bx = 0.0;
65  for(std::size_t n = 0; n <= getMaxOrder(); n++) {
66  double f_n = 0.0;
67  for(std::size_t i = 0; i <= n; i++) {
68  f_n += gsl_sf_choose(n, i) * getTransDeriv(2 * i + 1, R[0]) *
69  getFringeDeriv(2 * n - 2 * i, R[2]);
70  }
71  f_n *= gsl_sf_pow_int(-1.0, n);
72  Bx += f_n * gsl_sf_pow_int(R[1], 2 * n + 1) / gsl_sf_fact(2 * n + 1);
73  }
74  return Bx;
75 }
76 
78  double Bs = 0.0;
79  for(std::size_t n = 0; n <= getMaxOrder(); n++) {
80  double f_n = 0.0;
81  for(std::size_t i = 0; i <= n; i++) {
82  f_n += gsl_sf_choose(n, i) * getTransDeriv(2 * i, R[0]) *
83  getFringeDeriv(2 * n - 2 * i + 1, R[2]);
84  }
85  f_n *= gsl_sf_pow_int(-1.0, n);
86  Bs += f_n * gsl_sf_pow_int(R[1], 2 * n + 1) / gsl_sf_fact(2 * n + 1);
87  }
88  return Bs;
89 }
90 
91 double MultipoleTStraight::getFn(const std::size_t &n,
92  const double &x,
93  const double &s) {
94  if (n == 0) {
95  return getTransDeriv(0, x) * getFringeDeriv(0, s);
96  }
97  double f_n = 0.0;
98  for (std::size_t i = 0; i <= n; i++) {
99  f_n += gsl_sf_choose(n, i) * getTransDeriv(2 * i, x) *
100  getFringeDeriv(2 * n - 2 * i, s);
101  }
102  f_n *= gsl_sf_pow_int(-1.0, n);
103  return f_n;
104 }
105 
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void setMaxOrder(const std::size_t &maxOrder) override
virtual ElementBase * clone() const override
MultipoleTStraight(const std::string &name)
virtual void transformCoords(Vector_t &R) override
virtual double getFn(const std::size_t &n, const double &x, const double &s) override
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:200
double getTransDeriv(const std::size_t &n, const double &x)
const std::string name
double getFringeDeriv(const std::size_t &n, const double &s)
virtual double getBx(const Vector_t &R) override
std::size_t getMaxOrder() const
virtual void setMaxOrder(const std::size_t &maxOrder)
virtual double getBs(const Vector_t &R) override