OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Multipole.h
Go to the documentation of this file.
1#ifndef OPALX_Multipole_HH
2#define OPALX_Multipole_HH
3
7
8class Fieldmap;
9constexpr int MAX_MP_ORDER = 5;
10
30class Multipole : public Component {
31public:
32 /* ============================== Constructors ============================== */
33 explicit Multipole(const std::string& name);
34 Multipole();
35 Multipole(const Multipole&);
36 virtual ~Multipole();
37 /* ========================================================================== */
38 /* =========================== Multipole Expansion ========================== */
39
40 // @note n=0 corresponds to the dipol, n=1 to the quadrupole, etc...
41
42 // @returns n-th normal component of the multipole expansion
43 double getNormalComponent(int n) const;
44
45 // @brief Sets the n-th normal component
46 void setNormalComponent(int n, double);
47
48 // @brief Sets the n-th normal component with an error
49 void setNormalComponent(int n, double, double);
50
51 // @returns n-th skew component of the multipole expansion
52 double getSkewComponent(int n) const;
53
54 // @brief Sets the n-th skew component
55 void setSkewComponent(int n, double);
56
57 // @brief Sets the n-th skew component with error
58 void setSkewComponent(int n, double, double);
59
60 // @brief Get index of maximal components
61 size_t getMaxNormalComponentIndex() const;
62 size_t getMaxSkewComponentIndex() const;
63
64 /* ========================================================================== */
65 /* ============================== Apply Functions =========================== */
71 virtual bool apply(const std::shared_ptr<ParticleContainer_t>& pc) override;
72
83 virtual bool apply(
84 const size_t& i, const double& t, Vector_t<double, 3>& E,
85 Vector_t<double, 3>& B) override;
86
98 virtual bool apply(
99 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& t,
101
113 virtual bool applyToReferenceParticle(
114 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& t,
116 /* ========================================================================== */
117 /* ============================== Functions ================================= */
118 // @brief Apply visitor to Multipole.
119 virtual void accept(BeamlineVisitor&) const override;
120
121 // @brief Get multipole field.
122 virtual BMultipoleField& getField() override = 0;
123
124 // @breif Get multipole field. Version for const object.
125 virtual const BMultipoleField& getField() const override = 0;
126
127 // @returns Is the n-th component focusing?
128 bool isFocusing(int n) const;
129
137 virtual void initialise(PartBunch_t* bunch, double& startField, double& endField) override;
138
139 virtual void finalise() override;
140
141 virtual bool bends() const override;
142
143 virtual ElementType getType() const override;
144
145 virtual void getFieldExtend(double& zBegin, double& zEnd) const override;
146
147 virtual bool isInside(const Vector_t<double, 3>& r) const override;
148 /* ========================================================================== */
149 /* =========================== Unused Functions ============================= */
150 // @returns StraightGeometry
151 virtual StraightGeometry& getGeometry() override = 0;
152
153 // @returns StraightGeometry
154 virtual const StraightGeometry& getGeometry() const override = 0;
155
156 // @brief Set number of slices for map tracking
157 void setNSlices(const std::size_t& nSlices);
158
159 // @breif Get number of slices for map tracking
160 std::size_t getNSlices() const;
161
162 // Not implemented.
163 void operator=(const Multipole&);
164
165 /* ========================================================================== */
166private:
180 KOKKOS_INLINE_FUNCTION
181 static void computeField(
183 const Kokkos::View<double*> NormalComponents,
184 const Kokkos::View<double*> SkewComponents, int max_NormalComponent,
185 int max_SkewComponent);
186
196 void computeFieldHost(
198 /* ========================================================================== */
199 /* =========================== Variables ==================================== */
200 Kokkos::View<double*> NormalComponents;
201 Kokkos::View<double*> NormalComponentErrors;
202 Kokkos::View<double*> SkewComponents;
203 Kokkos::View<double*> SkewComponentErrors;
206 /* =========================== Unused Variables ============================= */
207 std::size_t nSlices_m;
208 /* ========================================================================== */
209};
210/* =========================== Inline Functions ============================= */
211// @note Inlined function bodies need to be in the header for libraries
212
213// @returns n-th normal component of the multipole expansion
214inline void Multipole::setNormalComponent(int n, double v) { setNormalComponent(n, v, 0.0); }
215// @returns n-th skew component of the multipole expansion
216inline void Multipole::setSkewComponent(int n, double v) { setSkewComponent(n, v, 0.0); }
217
218// @returns max index of normal components
219inline size_t Multipole::getMaxNormalComponentIndex() const { return NormalComponents.size(); }
220
221// @returns max index of skew components
222inline size_t Multipole::getMaxSkewComponentIndex() const { return SkewComponents.size(); }
223/* ========================================================================== */
224#endif // OPALX_Multipole_HH
Defines the abstract interface for a single beamline component in the accelerator model.
ippl::Vector< T, Dim > Vector_t
ElementType
Definition ElementBase.h:94
constexpr int MAX_MP_ORDER
Definition Multipole.h:9
The magnetic field of a multipole.
Abstract base class for all field maps. It acts as a factory for creating specific field map types ba...
Definition Fieldmap.h:62
Interface for general multipole.
Definition Multipole.h:30
void setSkewComponent(int n, double)
Definition Multipole.h:216
virtual void accept(BeamlineVisitor &) const override
Accepts a BeamlineVisitor.
int max_NormalComponent_m
Definition Multipole.h:205
size_t getMaxSkewComponentIndex() const
Definition Multipole.h:222
size_t getMaxNormalComponentIndex() const
Definition Multipole.h:219
void setNormalComponent(int n, double)
Definition Multipole.h:214
virtual const StraightGeometry & getGeometry() const override=0
Get geometry.
virtual const BMultipoleField & getField() const override=0
Return field.
virtual void initialise(PartBunch_t *bunch, double &startField, double &endField) override
Setup, multipole goes online.
bool isFocusing(int n) const
virtual bool applyToReferenceParticle(const Vector_t< double, 3 > &R, const Vector_t< double, 3 > &P, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) override
Apply to reference particle with position R and momemtum P.
virtual StraightGeometry & getGeometry() override=0
Get geometry.
virtual void finalise() override
void setNSlices(const std::size_t &nSlices)
virtual bool bends() const override
void computeFieldHost(Vector_t< double, 3 > R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const
Computes the E and B field at position R of the reference particle.
Kokkos::View< double * > SkewComponents
Definition Multipole.h:202
virtual ElementType getType() const override
Get element type std::string.
virtual bool isInside(const Vector_t< double, 3 > &r) const override
virtual bool apply(const std::shared_ptr< ParticleContainer_t > &pc) override
Apply to all particles. Kernel launch moved inside the function.
Kokkos::View< double * > SkewComponentErrors
Definition Multipole.h:203
Kokkos::View< double * > NormalComponentErrors
Definition Multipole.h:201
Kokkos::View< double * > NormalComponents
Definition Multipole.h:200
static KOKKOS_INLINE_FUNCTION void computeField(Vector_t< double, 3 > R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const Kokkos::View< double * > NormalComponents, const Kokkos::View< double * > SkewComponents, int max_NormalComponent, int max_SkewComponent)
Computes the E and B field at position R.
double getSkewComponent(int n) const
Gets the n-th skew component of the multipole expansion.
int max_SkewComponent_m
Definition Multipole.h:204
virtual void getFieldExtend(double &zBegin, double &zEnd) const override
Return the field-support extent of the component.
std::size_t getNSlices() const
virtual ~Multipole()
Definition Multipole.cpp:93
double getNormalComponent(int n) const
Gets the n-th normal component of the multipole expansion.
std::size_t nSlices_m
Definition Multipole.h:207
virtual BMultipoleField & getField() override=0
Return field.
void operator=(const Multipole &)
A geometry representing a straight line.