WarpX
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_GpuContainers.H>
16 
17 #include <string>
18 
19 // Specifies a field that models the field generated by a quadrupole lens,
20 // an axially uniform quadrupole field
21 
23 
26 {
27 
29 
36  void
37  AddElement (amrex::ParmParse & pp_element, amrex::ParticleReal & z_location);
38 
42  void
43  WriteToDevice ();
44 
45  /* The field gradients */
46  /* On the host */
47  std::vector<amrex::ParticleReal> h_dEdx;
48  std::vector<amrex::ParticleReal> h_dBdx;
49  /* On the device */
52 
56  [[nodiscard]] HardEdgedQuadrupoleDevice
57  GetDeviceInstance () const;
58 
59 };
60 
61 // Instance that is trivially copyable to the device.
62 
64 {
65 
72 
73  int nelements = 0;
74 
75  const amrex::ParticleReal* AMREX_RESTRICT d_zs_arr;
76  const amrex::ParticleReal* AMREX_RESTRICT d_ze_arr;
77 
78  const amrex::ParticleReal* AMREX_RESTRICT d_dEdx_arr;
79  const amrex::ParticleReal* AMREX_RESTRICT d_dBdx_arr;
80 
90  void get_field (const int ielement,
91  const amrex::ParticleReal x,
92  const amrex::ParticleReal y,
93  const amrex::ParticleReal z,
94  const amrex::ParticleReal zpvdt,
95  amrex::ParticleReal& Ex,
96  amrex::ParticleReal& Ey,
97  amrex::ParticleReal& Bx,
98  amrex::ParticleReal& By) const
99  {
100 
101  // Calculate the residence correction, the fraction of the time step that the particle
102  // spends inside the hard edged element.
103  amrex::ParticleReal const frac = hard_edged_fraction(z, zpvdt, d_zs_arr[ielement], d_ze_arr[ielement]);
104 
105  const amrex::ParticleReal dEdx = frac*d_dEdx_arr[ielement];
106  const amrex::ParticleReal dBdx = frac*d_dBdx_arr[ielement];
107 
108  Ex = +x*dEdx;
109  Ey = -y*dEdx;
110  Bx = +y*dBdx;
111  By = +x*dBdx;
112 
113  }
114 
115 };
116 
117 #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:25
Definition: HardEdgedQuadrupole.H:64
const amrex::ParticleReal *AMREX_RESTRICT d_dEdx_arr
Definition: HardEdgedQuadrupole.H:78
const amrex::ParticleReal *AMREX_RESTRICT d_dBdx_arr
Definition: HardEdgedQuadrupole.H:79
int nelements
Definition: HardEdgedQuadrupole.H:73
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:90
void InitHardEdgedQuadrupoleDevice(HardEdgedQuadrupole const &h_quad)
Initializes the data and pointer needed to reference the lattice element info.
Definition: HardEdgedQuadrupole.cpp:56
const amrex::ParticleReal *AMREX_RESTRICT d_zs_arr
Definition: HardEdgedQuadrupole.H:75
const amrex::ParticleReal *AMREX_RESTRICT d_ze_arr
Definition: HardEdgedQuadrupole.H:76
Definition: HardEdgedQuadrupole.H:26
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dEdx
Definition: HardEdgedQuadrupole.H:50
HardEdgedQuadrupoleDevice GetDeviceInstance() const
Returns the device level instance with the lattice information.
Definition: HardEdgedQuadrupole.cpp:48
void AddElement(amrex::ParmParse &pp_element, amrex::ParticleReal &z_location)
Read in an element and add it to the lists.
Definition: HardEdgedQuadrupole.cpp:21
void WriteToDevice()
Write the element information to the device.
Definition: HardEdgedQuadrupole.cpp:37
HardEdgedQuadrupole()
Definition: HardEdgedQuadrupole.cpp:15
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dBdx
Definition: HardEdgedQuadrupole.H:51
std::vector< amrex::ParticleReal > h_dBdx
Definition: HardEdgedQuadrupole.H:48
std::vector< amrex::ParticleReal > h_dEdx
Definition: HardEdgedQuadrupole.H:47
Definition: LatticeElementBase.H:18