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 
30  ~HardEdgedQuadrupole () = default;
31 
38  void
39  AddElement (amrex::ParmParse & pp_element, amrex::ParticleReal & z_location);
40 
44  void
45  WriteToDevice ();
46 
47  /* The field gradients */
48  /* On the host */
49  std::vector<amrex::ParticleReal> h_dEdx;
50  std::vector<amrex::ParticleReal> h_dBdx;
51  /* On the device */
54 
59 
60 
61 };
62 
63 // Instance that is trivially copyable to the device.
64 
66 {
67 
74 
75  int nelements = 0;
76 
77  const amrex::ParticleReal* AMREX_RESTRICT d_zs_arr;
78  const amrex::ParticleReal* AMREX_RESTRICT d_ze_arr;
79 
80  const amrex::ParticleReal* AMREX_RESTRICT d_dEdx_arr;
81  const amrex::ParticleReal* AMREX_RESTRICT d_dBdx_arr;
82 
92  void get_field (const int ielement,
93  const amrex::ParticleReal x,
94  const amrex::ParticleReal y,
95  const amrex::ParticleReal z,
96  const amrex::ParticleReal zpvdt,
97  amrex::ParticleReal& Ex,
98  amrex::ParticleReal& Ey,
99  amrex::ParticleReal& Bx,
100  amrex::ParticleReal& By) const
101  {
102 
103  // Calculate the residence correction, the fraction of the time step that the particle
104  // spends inside the hard edged element.
105  amrex::ParticleReal const frac = hard_edged_fraction(z, zpvdt, d_zs_arr[ielement], d_ze_arr[ielement]);
106 
107  const amrex::ParticleReal dEdx = frac*d_dEdx_arr[ielement];
108  const amrex::ParticleReal dBdx = frac*d_dBdx_arr[ielement];
109 
110  Ex = +x*dEdx;
111  Ey = -y*dEdx;
112  Bx = +y*dBdx;
113  By = +x*dBdx;
114 
115  }
116 
117 };
118 
119 #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:66
const amrex::ParticleReal *AMREX_RESTRICT d_dEdx_arr
Definition: HardEdgedQuadrupole.H:80
const amrex::ParticleReal *AMREX_RESTRICT d_dBdx_arr
Definition: HardEdgedQuadrupole.H:81
int nelements
Definition: HardEdgedQuadrupole.H:75
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:92
void InitHardEdgedQuadrupoleDevice(HardEdgedQuadrupole const &h_quad)
Initializes the data and pointer needed to reference the lattice element info.
Definition: HardEdgedQuadrupole.cpp:55
const amrex::ParticleReal *AMREX_RESTRICT d_zs_arr
Definition: HardEdgedQuadrupole.H:77
const amrex::ParticleReal *AMREX_RESTRICT d_ze_arr
Definition: HardEdgedQuadrupole.H:78
Definition: HardEdgedQuadrupole.H:26
~HardEdgedQuadrupole()=default
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dEdx
Definition: HardEdgedQuadrupole.H:52
HardEdgedQuadrupoleDevice GetDeviceInstance() const
Returns the device level instance with the lattice information.
Definition: HardEdgedQuadrupole.cpp:47
void AddElement(amrex::ParmParse &pp_element, amrex::ParticleReal &z_location)
Read in an element and add it to the lists.
Definition: HardEdgedQuadrupole.cpp:20
void WriteToDevice()
Write the element information to the device.
Definition: HardEdgedQuadrupole.cpp:36
HardEdgedQuadrupole()
Definition: HardEdgedQuadrupole.cpp:14
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dBdx
Definition: HardEdgedQuadrupole.H:53
std::vector< amrex::ParticleReal > h_dBdx
Definition: HardEdgedQuadrupole.H:50
std::vector< amrex::ParticleReal > h_dEdx
Definition: HardEdgedQuadrupole.H:49
Definition: LatticeElementBase.H:18