OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
BSingleMultipoleField.h
Go to the documentation of this file.
1#ifndef CLASSIC_BSingleMultipoleField_HH
2#define CLASSIC_BSingleMultipoleField_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: BSingleMultipoleField.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Template class: BSingleMultipoleField
13// Representation for a single multipole field.
14//
15// ------------------------------------------------------------------------
16// Class category: Fields
17// ------------------------------------------------------------------------
18//
19// $Date: 2000/03/27 09:32:35 $
20// $Author: fci $
21//
22// ------------------------------------------------------------------------
23
24#include "Fields/EMField.h"
25#include <cmath>
26#include <complex>
27
28
29// Template class BSingleMultipoleField
30// ------------------------------------------------------------------------
32// The order and the skew flag are encoded in a template parameter.
33// {center}
34// order > 0: normal multipole, order < 0: skew multipole.
35// {/center}
36// Thus the compiler may optimize by unrolling loops on the order.
37// It should also omit some tests and eliminate unreachable code.
38
39template <int order>
41
42public:
43
45 // Constructs a null field.
47
49 virtual ~BSingleMultipoleField();
51
53 // Return the field as a BMultipoleField.
54 operator BMultipoleField() const;
55
57 // Return the magnetic field at point [b]P[/b].
58 virtual BVector Bfield(const Point3D &X) const;
59
61 // Return the magnetic field at time [b]t[/b] in point [b]P[/b].
62 // This default action returns the static part BField(P).
63 virtual BVector Bfield(const Point3D &P, double t) const;
64
66 // Return the single multipole coefficient in T/m**n.
67 virtual double getComponent() const;
68
70 // Assign the single multipole coefficient in T/m**n.
71 virtual void setComponent(double);
72
74 // Multiply the field by [b]scalar[/b].
75 void scale(double scalar);
76
78 int size() const;
79
80private:
81
82 // The field component strength.
83 double strength;
84};
85
86
87// Implementation
88// ------------------------------------------------------------------------
89
90template <int order> inline
92 strength(0.0)
93{}
94
95
96template <int order> inline
98(const BSingleMultipoleField &field):
99 strength(field.strength)
100{}
101
102
103template <int order>
105{}
106
107
108template <int order> inline
110operator=(const BSingleMultipoleField &field) {
111 strength = field.strength;
112 return *this;
113}
114
115
116template <int order> inline
118 BMultipoleField field;
119 if(order > 0) {
120 field.setNormalComponent(order, strength);
121 } else {
122 field.setSkewComponent(order, strength);
123 }
124 return field;
125}
126
127
128template <int order> inline
130Bfield(const Point3D &point) const {
131 std::complex<double> z(point.getX(), point.getY());
132 std::complex<double> B = strength;
133 if(order > 0) {
134 for(int i = 0; i < order; i++) {
135 B *= z;
136 }
137 return BVector(std::real(B), -std::imag(B), 0.0);
138 } else {
139 for(int i = 0; i > order; i--) {
140 B *= z;
141 }
142 return BVector(std::imag(B), std::real(B), 0.0);
143 }
144}
145
146
147template <int order> inline
149Bfield(const Point3D &point, double) const {
150 return Bfield(point);
151}
152
153
154template <int order> inline
156 return strength;
157}
158
159
160template <int order> inline
162 strength = value;
163}
164
165
166template <int order> inline
168 strength *= scalar;
169}
170
171
172template <int order> inline
174 return std::abs(order);
175}
176
177#endif // CLASSIC_BSingleMultipoleField_HH
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
FLieGenerator< T, N > imag(const FLieGenerator< std::complex< T >, N > &)
Take imaginary part of a complex generator.
#define X(arg)
Definition: fftpack.cpp:112
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
The magnetic field of a multipole.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.
Representation for a single magnetic multipole field.
virtual double getComponent() const
Return field coefficient.
virtual void setComponent(double)
Set field coefficient.
virtual BVector Bfield(const Point3D &X) const
Field at a given point.
int size() const
Return order.
void scale(double scalar)
Scale the field.
BSingleMultipoleField & operator=(const BSingleMultipoleField &)
BSingleMultipoleField()
Default constructor.
A point in 3 dimensions.
Definition: EMField.h:33
double getX() const
Return coordinate.
Definition: EMField.cpp:34
double getY() const
Return coordinate.
Definition: EMField.cpp:37
A magnetic field vector.
Definition: EMField.h:97
Abstract base class for electromagnetic fields.
Definition: EMField.h:188