ARTEMIS
HardEdgedQuadrupole.H
Go to the documentation of this file.
1 /* Copyright 2022 David Grote
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGEDQUADRUPOLE_H_
8 #define WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGEDQUADRUPOLE_H_
9 
10 #include "LatticeElementBase.H"
11 #include "HardEdged_K.H"
12 
13 #include <AMReX_REAL.H>
14 #include <AMReX_ParmParse.H>
15 #include <AMReX_Vector.H>
16 #include <AMReX_GpuContainers.H>
17 
18 #include <string>
19 
20 // Specifies a field that models the field generated by a quadrupole lens,
21 // an axially uniform quadrupole field
22 
24 
27 {
28 
30 
31  ~HardEdgedQuadrupole () = default;
32 
39  void
40  AddElement (amrex::ParmParse & pp_element, amrex::ParticleReal & z_location);
41 
45  void
46  WriteToDevice ();
47 
48  /* The field gradients */
49  /* On the host */
50  std::vector<amrex::ParticleReal> h_dEdx;
51  std::vector<amrex::ParticleReal> h_dBdx;
52  /* On the device */
55 
60 
61 
62 };
63 
64 // Instance that is trivially copyable to the device.
65 
67 {
68 
75 
76  int nelements = 0;
77 
78  const amrex::ParticleReal* AMREX_RESTRICT d_zs_arr;
79  const amrex::ParticleReal* AMREX_RESTRICT d_ze_arr;
80 
81  const amrex::ParticleReal* AMREX_RESTRICT d_dEdx_arr;
82  const amrex::ParticleReal* AMREX_RESTRICT d_dBdx_arr;
83 
93  void get_field (const int ielement,
94  const amrex::ParticleReal x,
95  const amrex::ParticleReal y,
96  const amrex::ParticleReal z,
97  const amrex::ParticleReal zpvdt,
98  amrex::ParticleReal& Ex,
99  amrex::ParticleReal& Ey,
100  amrex::ParticleReal& Bx,
101  amrex::ParticleReal& By) const
102  {
103 
104  // Calculate the residence correction, the fraction of the time step that the particle
105  // spends inside the hard edged element.
106  amrex::ParticleReal const frac = hard_edged_fraction(z, zpvdt, d_zs_arr[ielement], d_ze_arr[ielement]);
107 
108  amrex::ParticleReal dEdx = frac*d_dEdx_arr[ielement];
109  amrex::ParticleReal dBdx = frac*d_dBdx_arr[ielement];
110 
111  Ex = +x*dEdx;
112  Ey = -y*dEdx;
113  Bx = +y*dBdx;
114  By = +x*dBdx;
115 
116  }
117 
118 };
119 
120 #endif // WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGEDQUADRUPOLE_H_
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal hard_edged_fraction(const amrex::ParticleReal z, const amrex::ParticleReal zpvdt, const amrex::ParticleReal zs, const amrex::ParticleReal ze)
Calculate the residence correction, the fraction of the time step the particle spends inside of the h...
Definition: HardEdged_K.H:26
def y
Definition: Excitation_Flag_Generator.py:76
def x
Formats datastring to remove "+" at the end of the string #####.
Definition: Excitation_Flag_Generator.py:75
def z
Definition: Excitation_Flag_Generator.py:77
Definition: HardEdgedQuadrupole.H:67
const amrex::ParticleReal *AMREX_RESTRICT d_dEdx_arr
Definition: HardEdgedQuadrupole.H:81
const amrex::ParticleReal *AMREX_RESTRICT d_dBdx_arr
Definition: HardEdgedQuadrupole.H:82
int nelements
Definition: HardEdgedQuadrupole.H:76
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void get_field(const int ielement, const amrex::ParticleReal x, const amrex::ParticleReal y, const amrex::ParticleReal z, const amrex::ParticleReal zpvdt, amrex::ParticleReal &Ex, amrex::ParticleReal &Ey, amrex::ParticleReal &Bx, amrex::ParticleReal &By) const
Fetch the field of the specified element at the given location.
Definition: HardEdgedQuadrupole.H:93
void InitHardEdgedQuadrupoleDevice(HardEdgedQuadrupole const &h_quad)
Initializes the data and pointer needed to reference the lattice element info.
Definition: HardEdgedQuadrupole.cpp:57
const amrex::ParticleReal *AMREX_RESTRICT d_zs_arr
Definition: HardEdgedQuadrupole.H:78
const amrex::ParticleReal *AMREX_RESTRICT d_ze_arr
Definition: HardEdgedQuadrupole.H:79
Definition: HardEdgedQuadrupole.H:27
~HardEdgedQuadrupole()=default
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dEdx
Definition: HardEdgedQuadrupole.H:53
HardEdgedQuadrupoleDevice GetDeviceInstance() const
Returns the device level instance with the lattice information.
Definition: HardEdgedQuadrupole.cpp:49
void AddElement(amrex::ParmParse &pp_element, amrex::ParticleReal &z_location)
Read in an element and add it to the lists.
Definition: HardEdgedQuadrupole.cpp:22
void WriteToDevice()
Write the element information to the device.
Definition: HardEdgedQuadrupole.cpp:38
HardEdgedQuadrupole()
Definition: HardEdgedQuadrupole.cpp:16
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dBdx
Definition: HardEdgedQuadrupole.H:54
std::vector< amrex::ParticleReal > h_dBdx
Definition: HardEdgedQuadrupole.H:51
std::vector< amrex::ParticleReal > h_dEdx
Definition: HardEdgedQuadrupole.H:50
Definition: LatticeElementBase.H:18