OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
FM2DMagnetoStatic.h
Go to the documentation of this file.
1#ifndef OPALX_FIELDMAP2DMAGNETOSTATIC_HH
2#define OPALX_FIELDMAP2DMAGNETOSTATIC_HH
3
4#include "Fields/Fieldmap.h"
5
6#include <Kokkos_Core.hpp>
7#include <Kokkos_DualView.hpp>
8
9class FM2DMagnetoStatic : public Fieldmap {
10public:
19 virtual bool getFieldstrength(
21 Vector_t<double, 3>& B) const override;
22
32 virtual bool getFieldDerivative(
34 const DiffDirection& dir) const override;
35
41 virtual void getFieldDimensions(double& zBegin, double& zEnd) const override;
42
53 virtual void getFieldDimensions(
54 double& xIni, double& xFinal, double& yIni, double& yFinal, double& zIni,
55 double& zFinal) const override;
56
58 virtual void swap() override;
59
61 virtual void getInfo(Inform* msg) override;
62
68 virtual double getFrequency() const override;
69
75 virtual void setFrequency(double freq) override;
76
84 bool isInside(const Vector_t<double, 3>& r) const override {
85 return r(2) >= zbegin_m && r(2) < zend_m && sqrt(r(0) * r(0) + r(1) * r(1)) < rend_m;
86 }
87
108 template <class ViewType>
109 KOKKOS_INLINE_FUNCTION static void computeField(
110 const Vector_t<double, 3>& R, Vector_t<double, 3>& B, const ViewType& Bz,
111 const ViewType& Br, double hr, double hz, double zbegin, int num_gridpr,
112 int num_gridpz) {
113 const double RR = sqrt(R(0) * R(0) + R(1) * R(1));
114
115 const int indexr = (int)floor(RR / hr);
116 const double leverr = (RR / hr) - indexr;
117
118 const int indexz = (int)floor((R(2) - zbegin) / hz);
119 const double leverz = (R(2) - zbegin) / hz - indexz;
120
121 if ((indexz < 0) || (indexz + 2 > num_gridpz)) return;
122
123 if (indexr + 2 > num_gridpr) return;
124
125 int index1 = indexz + indexr * num_gridpz;
126 int index2 = index1 + num_gridpz;
127
128 double BfieldR = (1.0 - leverz) * (1.0 - leverr) * Br(index1)
129 + leverz * (1.0 - leverr) * Br(index1 + 1)
130 + (1.0 - leverz) * leverr * Br(index2) + leverz * leverr * Br(index2 + 1);
131
132 double BfieldZ = (1.0 - leverz) * (1.0 - leverr) * Bz(index1)
133 + leverz * (1.0 - leverr) * Bz(index1 + 1)
134 + (1.0 - leverz) * leverr * Bz(index2) + leverz * leverr * Bz(index2 + 1);
135
136 if (RR != 0) {
137 B(0) += BfieldR * R(0) / RR;
138 B(1) += BfieldR * R(1) / RR;
139 }
140 B(2) += BfieldZ;
141 return;
142 }
143
149 void applyField(std::shared_ptr<ParticleContainer_t> pc, double scale = 1.0) override;
150
151private:
152 FM2DMagnetoStatic(std::string aFilename);
154
155 void readMap() override;
156 void freeMap() override;
157
159 Kokkos::DualView<double*> FieldstrengthBz_m;
160 Kokkos::DualView<double*> FieldstrengthBr_m;
161
163 double rbegin_m;
164 double rend_m;
165
167 double zbegin_m;
168 double zend_m;
169
171 double hz_m;
172 double hr_m;
175
176 bool swap_m;
177 friend class Fieldmap;
178};
179
180#endif
ippl::Vector< T, Dim > Vector_t
DiffDirection
Definition Fieldmap.h:54
virtual void swap() override
Swap coordinates.
virtual bool getFieldstrength(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const override
Get the field strength at a given point.
virtual double getFrequency() const override
Get the frequency.
virtual void getFieldDimensions(double &zBegin, double &zEnd) const override
Get the longitudinal dimensions of the field.
void applyField(std::shared_ptr< ParticleContainer_t > pc, double scale=1.0) override
Apply the FM to all the particles.
virtual void getInfo(Inform *msg) override
Print info about the field map.
void freeMap() override
Pure virtual method to free the map data.
void readMap() override
Pure virtual method to read the map data. Called by the public static readMap().
Kokkos::DualView< double * > FieldstrengthBz_m
Fieldstrengths.
static KOKKOS_INLINE_FUNCTION void computeField(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &B, const ViewType &Bz, const ViewType &Br, double hr, double hz, double zbegin, int num_gridpr, int num_gridpz)
Computes the magnetic field B at the position R by interpolating from the fieldmap specified by Bz,...
virtual bool getFieldDerivative(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const override
Get the field derivative with respect to a direction.
virtual void setFrequency(double freq) override
Set the frequency.
bool isInside(const Vector_t< double, 3 > &r) const override
Checks if the given coordinate is inside the volume covered by the fieldmap.
double zbegin_m
Z Bounds relative to element edge.
double rbegin_m
Radius Bounds.
Kokkos::DualView< double * > FieldstrengthBr_m
Abstract base class for all field maps. It acts as a factory for creating specific field map types ba...
Definition Fieldmap.h:62