OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
BMultipoleField.h
Go to the documentation of this file.
1#ifndef CLASSIC_BMultipoleField_HH
2#define CLASSIC_BMultipoleField_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: BMultipoleField.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: BMultipoleField
13//
14// ------------------------------------------------------------------------
15// Class category: Fields
16// ------------------------------------------------------------------------
17//
18// $Date: 2000/03/27 09:32:35 $
19// $Author: fci $
20//
21// ------------------------------------------------------------------------
22
24
25// Class BMultipoleField
26// ------------------------------------------------------------------------
28// The static components are defined by the equation
29// {center}
30// By + i * Bx = sum (Bn + i * An) (x + i * y) ** (n - 1)
31// {/center}
32// where the index n runs from 1 (dipole) to N (2N-pole).
33// The field component n is stored in the pairs[n-1],
34// The array pairs has the dimension N.
35
37
38public:
39
41 // Constructs a null field.
43
45 virtual ~BMultipoleField();
47
49 // Return the time-independent part of the magnetic field in point [b]P[/b].
50 // This override forces implementation in derived classes.
51 virtual BVector Bfield(const Point3D &P) const;
52
54 // Return the magnetic field at time [b]t[/b] in point [b]P[/b].
55 // This override forces implementation in derived classes.
56 virtual BVector Bfield(const Point3D &P, double t) const;
57
59 // Return the value of the n'th normal multipole component in T/m**(n-1).
60 // If [b]n[/b] is larger than N, the return value is zero.
61 double getNormalComponent(int n) const;
62
64 // Return the value of the n'th skew multipole component in T/m**(n-1).
65 // If [b]n[/b] is larger than N, the return value is zero.
66 double getSkewComponent(int n) const;
67
69 // Assign the value of the n'th normal multipole component in T/m**(n-1).
70 // If [b]n[/b] is larger than N, the new field component is inserted.
71 void setNormalComponent(int n, double Bn);
72
74 // Assign the value of the n'th skew multipole component in T/m**(n-1).
75 // If [b]n[/b] is larger than N, the new field component is inserted.
76 void setSkewComponent(int n, double Bn);
77
79 // Return the value of the n'th normal multipole component in T/m**(n-1).
80 // Fast version: [b]n[/b] is not checked.
81 // the result is undefined if it is larger than N.
82 double normal(int) const;
83
85 // Return the value of the n'th skew multipole component in T/m**(n-1).
86 // Fast version: [b]n[/b] is not checked.
87 // the result is undefined if it is larger than N.
88 double skew(int) const;
89
91 // Return a reference to the n'th normal multipole component in T/m**(n-1).
92 // Fast version: [b]n[/b] is not checked.
93 // the result is undefined if it is larger than N.
94 double &normal(int);
95
97 // Return a reference to the n'th skew multipole component in T/m**(n-1).
98 // Fast version: [b]n[/b] is not checked.
99 // the result is undefined if it is larger than N.
100 double &skew(int);
101
103 // Add [b]field[/b] to the old field; return new field.
105
107 // Subtract [b]field[/b] from the old field; return new field.
109
111 // Multiply the field by [b]scalar[/b].
112 void scale(double scalar);
113
115 int order() const;
116
117private:
118
119 struct Pair {
120 // constructors and destructor
121 Pair();
122 Pair(double normal, double skewed = 0.0);
123 Pair(const Pair &);
124 ~Pair();
125
126 // operators
127 void operator=(const Pair &);
128 Pair operator+(const Pair &) const;
129 Pair operator-(const Pair &) const;
130 Pair operator*(double scale) const;
131 void operator+=(const Pair &);
132 void operator-=(const Pair &);
133 void operator*=(double scale);
134 Pair operator-() const;
135
136 double B; // normal multipole coefficient
137 double A; // skewed multipole coefficient
138 };
139
140 // Reserve space for additional coefficients.
141 void reserve(int n);
142
143 // The array of multipole coefficients.
144 // The dimension is N, where N is the largest order (2N-pole),
145 // and pairs[n-1] is the coefficient for the (2n-pole).
147
148 // The highest order N.
150};
151
152
153// Inline functions
154// ------------------------------------------------------------------------
155
156inline int BMultipoleField::order() const {
157 return itsOrder;
158}
159
160
161inline double BMultipoleField::getNormalComponent(int n) const {
162 if(n > 0 && n <= itsOrder) {
163 return pairs[n-1].B;
164 } else {
165 return 0.0;
166 }
167}
168
169
170inline double BMultipoleField::getSkewComponent(int n) const {
171 if(n > 0 && n <= itsOrder) {
172 return pairs[n-1].A;
173 } else {
174 return 0.0;
175 }
176}
177
178
179inline double &BMultipoleField::normal(int n)
180{ return pairs[n-1].B; }
181
182
183inline double &BMultipoleField::skew(int n)
184{ return pairs[n-1].A; }
185
186
187inline double BMultipoleField::normal(int n) const
188{ return pairs[n-1].B; }
189
190
191inline double BMultipoleField::skew(int n) const
192{ return pairs[n-1].A; }
193
194#endif // CLASSIC_BMultipoleField_HH
The magnetic field of a multipole.
BMultipoleField & addField(const BMultipoleField &field)
Add to field.
int order() const
Return order.
double getNormalComponent(int n) const
Get component.
virtual BVector Bfield(const Point3D &P) const
Get field.
BMultipoleField & operator=(const BMultipoleField &)
BMultipoleField & subtractField(const BMultipoleField &field)
Subtract from field.
BMultipoleField()
Default constructor.
void scale(double scalar)
Scale the field.
virtual ~BMultipoleField()
double getSkewComponent(int n) const
Get component.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.
double normal(int) const
Get component.
double skew(int) const
Get component.
Pair operator+(const Pair &) const
void operator*=(double scale)
void operator-=(const Pair &)
void operator=(const Pair &)
void operator+=(const Pair &)
Pair operator*(double scale) const
A point in 3 dimensions.
Definition: EMField.h:33
A magnetic field vector.
Definition: EMField.h:97
Abstract base class for static magnetic fields.