OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Multipole.h
Go to the documentation of this file.
1 //
2 // Class Multipole
3 // The MULTIPOLE element defines a thick multipole.
4 //
5 // Copyright (c) 2012-2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 
19 #ifndef CLASSIC_Multipole_HH
20 #define CLASSIC_Multipole_HH
21 
22 #include "AbsBeamline/Component.h"
24 #include "Fields/BMultipoleField.h"
25 
26 template <class T, unsigned Dim>
27 class PartBunchBase;
28 class Fieldmap;
29 
30 // Class Multipole
31 // ------------------------------------------------------------------------
33 // Class Multipole defines the abstract interface for magnetic multipoles.
34 // The order n of multipole components runs from 1 to N and is dynamically
35 // adjusted. It is connected with the number of poles by the table
36 //
37 // [tab 2 b]
38 // [ROW]1[&]dipole[/ROW]
39 // [ROW]2[&]quadrupole[/ROW]
40 // [ROW]3[&]sextupole[/ROW]
41 // [ROW]4[&]octupole[/ROW]
42 // [ROW]5[&]decapole[/ROW]
43 // [ROW]n[&]multipole with 2*n poles[/ROW]
44 // [/TAB]
45 // Units for multipole strengths are Teslas / m**(n-1).
46 
47 class Multipole: public Component {
48 
49 public:
50 
52  explicit Multipole(const std::string &name);
53 
54  Multipole();
55  Multipole(const Multipole &);
56  virtual ~Multipole();
57 
59  virtual void accept(BeamlineVisitor &) const override;
60 
61 
63  virtual BMultipoleField &getField() override = 0;
64 
66  virtual const BMultipoleField &getField() const override = 0;
67 
69  // Return the normal component of order [b]n[/b] in T/m**(n-1).
70  // If [b]n[/b] is larger than the maximum order, the return value is zero.
71  double getNormalComponent(int n) const;
72 
74  // Return the skew component of order [b]n[/b] in T/m**(n-1).
75  // If [b]n[/b] is larger than the maximum order, the return value is zero.
76  double getSkewComponent(int n) const;
77 
79  // Set the normal component of order [b]n[/b] in T/m**(n-1).
80  // If [b]n[/b] is larger than the maximum order, the component is created.
81  void setNormalComponent(int, double);
82 
84  // Set the normal component of order [b]n[/b] in T/m**(n-1).
85  // If [b]n[/b] is larger than the maximum order, the component is created.
86  void setNormalComponent(int, double, double);
87 
89  // Set the skew component of order [b]n[/b] in T/m**(n-1).
90  // If [b]n[/b] is larger than the maximum order, the component is created.
91  void setSkewComponent(int, double);
92 
94  // Set the skew component of order [b]n[/b] in T/m**(n-1).
95  // If [b]n[/b] is larger than the maximum order, the component is created.
96  void setSkewComponent(int, double, double);
97 
98  size_t getMaxNormalComponentIndex() const;
99  size_t getMaxSkewComponentIndex() const;
100 
101  //set number of slices for map tracking
102  void setNSlices(const std::size_t& nSlices);
103 
104  //set number of slices for map tracking
105  std::size_t getNSlices() const;
106 
107  bool isFocusing(unsigned int component) const;
108 
110  virtual StraightGeometry &getGeometry() override = 0;
111 
113  virtual const StraightGeometry &getGeometry() const override = 0;
114 
115  virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
116 
117  virtual bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override;
118 
119  virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override;
120 
121  virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override;
122 
123  virtual void finalise() override;
124 
125  virtual bool bends() const override;
126 
127  virtual ElementBase::ElementType getType() const override;
128 
129  virtual void getDimensions(double &zBegin, double &zEnd) const override;
130 
131  virtual bool isInside(const Vector_t &r) const override;
132 private:
133  void computeField(Vector_t R, Vector_t &E, Vector_t &B);
134 
135  // Not implemented.
136  void operator=(const Multipole &);
137  std::vector<double> NormalComponents;
138  std::vector<double> NormalComponentErrors;
139  std::vector<double> SkewComponents;
140  std::vector<double> SkewComponentErrors;
143  std::size_t nSlices_m;
144 };
145 
146 inline
147 void Multipole::setNormalComponent(int n, double v) {
148  setNormalComponent(n, v, 0.0);
149 }
150 
151 inline
152 void Multipole::setSkewComponent(int n, double v) {
153  setSkewComponent(n, v, 0.0);
154 }
155 
156 inline
158  return NormalComponents.size();
159 }
160 
161 inline
163  return SkewComponents.size();
164 }
165 
166 #endif // CLASSIC_Multipole_HH
const std::string name
Interface for a single beam element.
Definition: Component.h:50
Interface for general multipole.
Definition: Multipole.h:47
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Definition: Multipole.cpp:274
std::vector< double > SkewComponents
Definition: Multipole.h:139
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Multipole.
Definition: Multipole.cpp:80
int max_NormalComponent_m
Definition: Multipole.h:142
size_t getMaxSkewComponentIndex() const
Definition: Multipole.h:162
size_t getMaxNormalComponentIndex() const
Definition: Multipole.h:157
virtual BMultipoleField & getField() override=0
Get multipole field.
void computeField(Vector_t R, Vector_t &E, Vector_t &B)
Definition: Multipole.cpp:151
virtual void getDimensions(double &zBegin, double &zEnd) const override
Definition: Multipole.cpp:338
std::vector< double > SkewComponentErrors
Definition: Multipole.h:140
virtual void finalise() override
Definition: Multipole.cpp:329
void setNSlices(const std::size_t &nSlices)
Definition: Multipole.cpp:142
virtual bool bends() const override
Definition: Multipole.cpp:333
virtual ElementBase::ElementType getType() const override
Get element type std::string.
Definition: Multipole.cpp:344
bool isFocusing(unsigned int component) const
Definition: Multipole.cpp:357
virtual const BMultipoleField & getField() const override=0
Get multipole field. Version for const object.
std::vector< double > NormalComponents
Definition: Multipole.h:137
void setNormalComponent(int, double)
Set normal component.
Definition: Multipole.h:147
double getSkewComponent(int n) const
Get skew component.
Definition: Multipole.cpp:93
virtual const StraightGeometry & getGeometry() const override=0
Get geometry.
int max_SkewComponent_m
Definition: Multipole.h:141
std::size_t getNSlices() const
Definition: Multipole.cpp:147
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
Definition: Multipole.cpp:299
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: Multipole.cpp:322
virtual ~Multipole()
Definition: Multipole.cpp:76
void setSkewComponent(int, double)
Set skew component.
Definition: Multipole.h:152
std::vector< double > NormalComponentErrors
Definition: Multipole.h:138
double getNormalComponent(int n) const
Get normal component.
Definition: Multipole.cpp:85
std::size_t nSlices_m
Definition: Multipole.h:143
virtual StraightGeometry & getGeometry() override=0
Get geometry.
void operator=(const Multipole &)
virtual bool isInside(const Vector_t &r) const override
Definition: Multipole.cpp:349
A geometry representing a straight line.
The magnetic field of a multipole.