WarpX
HardEdgedPlasmaLens.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_HARDEDGEDPLASMALENS_H_
8 #define WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGEDPLASMALENS_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 plasma lens,
20 // an axially uniform radius dependent radial force
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]] HardEdgedPlasmaLensDevice GetDeviceInstance () const;
57 
58 
59 };
60 
61 // Instance that is trivially copyable to the device.
62 
64 {
65 
71  void InitHardEdgedPlasmaLensDevice (HardEdgedPlasmaLens const& h_plasmalens);
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_HARDEDGEDPLASMALENS_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: HardEdgedPlasmaLens.H:64
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: HardEdgedPlasmaLens.H:90
const amrex::ParticleReal *AMREX_RESTRICT d_ze_arr
Definition: HardEdgedPlasmaLens.H:76
const amrex::ParticleReal *AMREX_RESTRICT d_dBdx_arr
Definition: HardEdgedPlasmaLens.H:79
int nelements
Definition: HardEdgedPlasmaLens.H:73
void InitHardEdgedPlasmaLensDevice(HardEdgedPlasmaLens const &h_plasmalens)
Initializes the data and pointer needed to reference the lattice element info.
Definition: HardEdgedPlasmaLens.cpp:56
const amrex::ParticleReal *AMREX_RESTRICT d_zs_arr
Definition: HardEdgedPlasmaLens.H:75
const amrex::ParticleReal *AMREX_RESTRICT d_dEdx_arr
Definition: HardEdgedPlasmaLens.H:78
Definition: HardEdgedPlasmaLens.H:26
std::vector< amrex::ParticleReal > h_dEdx
Definition: HardEdgedPlasmaLens.H:47
HardEdgedPlasmaLensDevice GetDeviceInstance() const
Returns the device level instance with the lattice information.
Definition: HardEdgedPlasmaLens.cpp:48
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dBdx
Definition: HardEdgedPlasmaLens.H:51
void WriteToDevice()
Write the element information to the device.
Definition: HardEdgedPlasmaLens.cpp:37
HardEdgedPlasmaLens()
Definition: HardEdgedPlasmaLens.cpp:15
void AddElement(amrex::ParmParse &pp_element, amrex::ParticleReal &z_location)
Read in an element and add it to the lists.
Definition: HardEdgedPlasmaLens.cpp:21
std::vector< amrex::ParticleReal > h_dBdx
Definition: HardEdgedPlasmaLens.H:48
amrex::Gpu::DeviceVector< amrex::ParticleReal > d_dEdx
Definition: HardEdgedPlasmaLens.H:50
Definition: LatticeElementBase.H:18