OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
FM2DDynamic.h
Go to the documentation of this file.
1#ifndef OPALX_FIELDMAP2DDYNAMIC_HH
2#define OPALX_FIELDMAP2DDYNAMIC_HH
3
4#include "Fields/Fieldmap.h"
5
6#include <Kokkos_Core.hpp>
7#include <Kokkos_DualView.hpp>
8
9class FM2DDynamic : public Fieldmap {
10public:
19 virtual bool getFieldstrength(
21 Vector_t<double, 3>& B) const override;
22 // virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const;
23
33 virtual bool getFieldDerivative(
35 const DiffDirection& dir) const override;
36 // virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const
37 // DiffDirection &dir) const;
38
44 virtual void getFieldDimensions(double& zBegin, double& zEnd) const override;
45 // virtual void getFieldDimensions(double &zBegin, double &zEnd) const;
46
57 virtual void getFieldDimensions(
58 double& xIni, double& xFinal, double& yIni, double& yFinal, double& zIni,
59 double& zFinal) const override;
60
62 virtual void swap() override;
63
65 virtual void getInfo(Inform* msg) override;
66
72 virtual double getFrequency() const override;
73
79 virtual void setFrequency(double freq) override;
80
88 bool isInside(const Vector_t<double, 3>& r) const override {
89 return r(2) >= zbegin_m && r(2) < zend_m && sqrt(r(0) * r(0) + r(1) * r(1)) < rend_m;
90 }
91
92 template <class ViewType>
93 KOKKOS_INLINE_FUNCTION static void computeField(
95 const ViewType& Ez, const ViewType& Er, const ViewType& Bt, double hr_m, double hz_m,
96 double zbegin_m, int num_gridpr_m, int num_gridpz_m) {
97 const double RR = sqrt(R(0) * R(0) + R(1) * R(1));
98
99 const int indexr = (int)floor(RR / hr_m);
100 const double leverr = (RR / hr_m) - indexr;
101
102 const int indexz = (int)floor((R(2) - zbegin_m) / hz_m);
103 const double leverz = (R(2) - zbegin_m) / hz_m - indexz;
104
105 if ((indexz < 0) || (indexz + 2 > num_gridpz_m)) return;
106
107 if (indexr + 2 > num_gridpr_m) return;
108
109 const int index1 = indexz + indexr * num_gridpz_m;
110 const int index2 = index1 + num_gridpz_m;
111
112 const double EfieldR = (1.0 - leverz) * (1.0 - leverr) * Er(index1)
113 + leverz * (1.0 - leverr) * Er(index1 + 1)
114 + (1.0 - leverz) * leverr * Er(index2)
115 + leverz * leverr * Er(index2 + 1);
116
117 const double EfieldZ = (1.0 - leverz) * (1.0 - leverr) * Ez(index1)
118 + leverz * (1.0 - leverr) * Ez(index1 + 1)
119 + (1.0 - leverz) * leverr * Ez(index2)
120 + leverz * leverr * Ez(index2 + 1);
121
122 const double BfieldT = (1.0 - leverz) * (1.0 - leverr) * Bt(index1)
123 + leverz * (1.0 - leverr) * Bt(index1 + 1)
124 + (1.0 - leverz) * leverr * Bt(index2)
125 + leverz * leverr * Bt(index2 + 1);
126
127 if (RR > 1e-14) {
128 E(0) += EfieldR * R(0) / RR;
129 E(1) += EfieldR * R(1) / RR;
130 B(0) -= BfieldT * R(1) / RR;
131 B(1) += BfieldT * R(0) / RR;
132 }
133 E(2) += EfieldZ;
134 return;
135 }
136
142 void applyField(std::shared_ptr<ParticleContainer_t> pc, double) override;
143
156 void applyRFField(
157 std::shared_ptr<ParticleContainer_t> pc, double electricScale, double magneticScale,
158 double startField, double endField);
159
160 virtual void getOnaxisEz(std::vector<std::pair<double, double> >& F) override;
161
162private:
163 FM2DDynamic(const std::string& filename);
164 ~FM2DDynamic();
165
166 void readMap() override;
167 void freeMap() override;
168
170 Kokkos::DualView<double*> FieldstrengthEz_m;
172 Kokkos::DualView<double*> FieldstrengthEr_m;
173 Kokkos::DualView<double*> FieldstrengthBt_m;
176
178 double rbegin_m;
179 double rend_m;
180
182 double zbegin_m;
183 double zend_m;
184
186 double hz_m;
187 double hr_m;
191 bool swap_m;
192 friend class Fieldmap;
193};
194
195#endif
ippl::Vector< T, Dim > Vector_t
DiffDirection
Definition Fieldmap.h:54
bool isInside(const Vector_t< double, 3 > &r) const override
Checks if the given coordinate is inside the volume covered by the fieldmap.
Definition FM2DDynamic.h:88
double frequency_m
Kokkos::DualView< double * > FieldstrengthEr_m
Kokkos::DualView< double * > FieldstrengthEz_m
Fieldstrengths.
double rbegin_m
Radius Bounds.
Kokkos::DualView< double * > FieldstrengthBt_m
virtual void swap() override
Swap coordinates.
void applyRFField(std::shared_ptr< ParticleContainer_t > pc, double electricScale, double magneticScale, double startField, double endField)
Apply the RF-scaled dynamic field map to all particles.
void freeMap() override
Pure virtual method to free the map data.
double rend_m
double hz_m
Grid.
double zbegin_m
Z Bounds relative to element edge.
virtual double getFrequency() const override
Get the frequency.
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 getInfo(Inform *msg) override
Print info about the field map.
void readMap() override
Pure virtual method to read the map data. Called by the public static readMap().
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) override
Apply the FM to all the particles.
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.
double zend_m
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &F) override
virtual void setFrequency(double freq) override
Set the frequency.
static KOKKOS_INLINE_FUNCTION void computeField(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const ViewType &Ez, const ViewType &Er, const ViewType &Bt, double hr_m, double hz_m, double zbegin_m, int num_gridpr_m, int num_gridpz_m)
Definition FM2DDynamic.h:93
Abstract base class for all field maps. It acts as a factory for creating specific field map types ba...
Definition Fieldmap.h:62