OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Astra1DMagnetoStatic.h
Go to the documentation of this file.
1#ifndef OPALX_AstraFIELDMAP1DMAGNETOSTATIC_HH
2#define OPALX_AstraFIELDMAP1DMAGNETOSTATIC_HH
3
4#include "Fields/Fieldmap.h"
5#include "Physics/Physics.h"
6
7#include <memory>
8
9#include <Kokkos_Core.hpp>
10#include <Kokkos_DualView.hpp>
11
13public:
16 Vector_t<double, 3>& B) const override;
17
18 void getFieldDimensions(double& zBegin, double& zEnd) const override;
19
21 double& xIni, double& xFinal, double& yIni, double& yFinal, double& zIni,
22 double& zFinal) const override;
23
26 const DiffDirection& dir) const override;
27
28 void swap() override;
29
30 void getInfo(Inform* msg) override;
31
32 double getFrequency() const override;
33
34 void setFrequency(double freq) override;
35
36 bool isInside(const Vector_t<double, 3>& r) const override {
37 return r(2) >= zbegin_m && r(2) < zend_m;
38 }
39
40 template <class ViewType>
41 KOKKOS_INLINE_FUNCTION static void computeField(
43 const ViewType& FourCoefs, double zbegin, double length, int accuracy) {
44 const double RR2 = R(0) * R(0) + R(1) * R(1);
45
46 const double two_pi = Physics::two_pi;
47 const double pi = Physics::pi;
48 const double dk = Physics::two_pi / length;
49 const double kz = two_pi * (R(2) - zbegin) / length + pi;
50
51 double bz = FourCoefs(0);
52 double bzp = 0.0;
53 double bzpp = 0.0;
54 double bzppp = 0.0;
55
56 int n = 1;
57 for (int l = 1; l < accuracy; ++l, n += 2) {
58 const double base = dk * l;
59
60 const double coskzl = Kokkos::cos(kz * l);
61 const double sinkzl = Kokkos::sin(kz * l);
62
63 bz += FourCoefs(n) * coskzl - FourCoefs(n + 1) * sinkzl;
64 bzp += base * (-FourCoefs(n) * sinkzl - FourCoefs(n + 1) * coskzl);
65 bzpp += base * base * (-FourCoefs(n) * coskzl + FourCoefs(n + 1) * sinkzl);
66 bzppp += base * base * base * (FourCoefs(n) * sinkzl + FourCoefs(n + 1) * coskzl);
67 }
68
69 const double BfieldR = -bzp / 2.0 + bzppp * RR2 / 16.0;
70
71 B(0) += BfieldR * R(0);
72 B(1) += BfieldR * R(1);
73 B(2) += bz - bzpp * RR2 / 4.0;
74 }
75
76 void applyField(std::shared_ptr<ParticleContainer_t> pc, double scale) override;
77
78private:
79 Astra1DMagnetoStatic(const std::string& filename);
81
82 void readMap() override;
83 void freeMap() override;
84
85 Kokkos::DualView<double*> FourCoefs_m;
86
87 double zbegin_m;
88 double zend_m;
89 double length_m;
90
93
94 friend class Fieldmap;
95};
96
97#endif
ippl::Vector< T, Dim > Vector_t
DiffDirection
Definition Fieldmap.h:54
bool isInside(const Vector_t< double, 3 > &r) const override
Check if a point is inside the field map.
double getFrequency() const override
Get the frequency.
static KOKKOS_INLINE_FUNCTION void computeField(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &, Vector_t< double, 3 > &B, const ViewType &FourCoefs, double zbegin, double length, int accuracy)
Kokkos::DualView< double * > FourCoefs_m
void swap() override
Swap coordinates (implementation dependent).
void freeMap() override
Pure virtual method to free the map data.
void applyField(std::shared_ptr< ParticleContainer_t > pc, double scale) override
Apply the FM to all the particles.
void getInfo(Inform *msg) override
Print info about the field map.
void getFieldDimensions(double &zBegin, double &zEnd) const override
Get the longitudinal dimensions of the field.
bool getFieldstrength(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const override
Get the fieldstrength at position R.
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 derivative of the field at position R.
void setFrequency(double freq) override
Set the frequency.
void readMap() override
Pure virtual method to read the map data. Called by the public static readMap().
Abstract base class for all field maps. It acts as a factory for creating specific field map types ba...
Definition Fieldmap.h:62
constexpr double two_pi
The value of.
Definition Physics.h:40
constexpr double pi
The value of.
Definition Physics.h:36