8 #ifndef CHARGEDEPOSITION_H_ 9 #define CHARGEDEPOSITION_H_ 38 template <
int depos_order>
40 const amrex::ParticleReal *
const wp,
41 const int *
const ion_lev,
42 amrex::FArrayBox& rho_fab,
43 const long np_to_depose,
44 const std::array<amrex::Real,3>&
dx,
45 const std::array<amrex::Real, 3> xyzmin,
48 const int n_rz_azimuthal_modes,
50 const long load_balance_costs_update_algo)
52 using namespace amrex;
54 #if !defined(AMREX_USE_GPU) 55 amrex::ignore_unused(cost, load_balance_costs_update_algo);
60 const bool do_ionization = ion_lev;
61 const amrex::Real dxi = 1.0_rt/dx[0];
62 const amrex::Real dzi = 1.0_rt/dx[2];
63 #if (AMREX_SPACEDIM == 2) 64 const amrex::Real invvol = dxi*dzi;
65 #elif (defined WARPX_DIM_3D) 66 const amrex::Real dyi = 1.0_rt/dx[1];
67 const amrex::Real invvol = dxi*dyi*dzi;
70 const amrex::Real xmin = xyzmin[0];
71 #if (defined WARPX_DIM_3D) 72 const amrex::Real ymin = xyzmin[1];
74 const amrex::Real zmin = xyzmin[2];
76 amrex::Array4<amrex::Real>
const& rho_arr = rho_fab.array();
77 amrex::IntVect
const rho_type = rho_fab.box().type();
79 constexpr
int zdir = (AMREX_SPACEDIM - 1);
80 constexpr
int NODE = amrex::IndexType::NODE;
81 constexpr
int CELL = amrex::IndexType::CELL;
84 #if defined(WARPX_USE_GPUCLOCK) 85 amrex::Real* cost_real =
nullptr;
87 cost_real = (amrex::Real *) amrex::The_Managed_Arena()->alloc(
sizeof(amrex::Real));
93 [=] AMREX_GPU_DEVICE (
long ip) {
94 #if defined(WARPX_USE_GPUCLOCK) 95 KernelTimer kernelTimer(cost && load_balance_costs_update_algo
99 amrex::Real wq = q*wp[ip]*invvol;
104 amrex::ParticleReal xp, yp, zp;
105 GetPosition(ip, xp, yp, zp);
110 #if (defined WARPX_DIM_RZ) 111 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
112 amrex::Real costheta;
113 amrex::Real sintheta;
122 const amrex::Real
x = (rp - xmin)*dxi;
124 const amrex::Real x = (xp - xmin)*dxi;
129 amrex::Real sx[depos_order + 1] = {0._rt};
132 if (rho_type[0] == NODE) {
133 i = compute_shape_factor(sx, x);
134 }
else if (rho_type[0] == CELL) {
135 i = compute_shape_factor(sx, x - 0.5_rt);
138 #if (defined WARPX_DIM_3D) 140 const amrex::Real y = (yp - ymin)*dyi;
141 amrex::Real sy[depos_order + 1] = {0._rt};
143 if (rho_type[1] == NODE) {
144 j = compute_shape_factor(sy, y);
145 }
else if (rho_type[1] == CELL) {
146 j = compute_shape_factor(sy, y - 0.5_rt);
150 const amrex::Real
z = (zp - zmin)*dzi;
151 amrex::Real sz[depos_order + 1] = {0._rt};
153 if (rho_type[zdir] == NODE) {
154 k = compute_shape_factor(sz, z);
155 }
else if (rho_type[zdir] == CELL) {
156 k = compute_shape_factor(sz, z - 0.5_rt);
160 #if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) 161 for (
int iz=0; iz<=depos_order; iz++){
162 for (
int ix=0; ix<=depos_order; ix++){
163 amrex::Gpu::Atomic::AddNoRet(
164 &rho_arr(lo.x+i+ix, lo.y+k+iz, 0, 0),
166 #if (defined WARPX_DIM_RZ) 168 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
170 amrex::Gpu::Atomic::AddNoRet( &rho_arr(lo.x+i+ix, lo.y+k+iz, 0, 2*imode-1), 2._rt*sx[ix]*sz[iz]*wq*xy.real());
171 amrex::Gpu::Atomic::AddNoRet( &rho_arr(lo.x+i+ix, lo.y+k+iz, 0, 2*imode ), 2._rt*sx[ix]*sz[iz]*wq*xy.imag());
177 #elif (defined WARPX_DIM_3D) 178 for (
int iz=0; iz<=depos_order; iz++){
179 for (
int iy=0; iy<=depos_order; iy++){
180 for (
int ix=0; ix<=depos_order; ix++){
181 amrex::Gpu::Atomic::AddNoRet(
182 &rho_arr(lo.x+i+ix, lo.y+j+iy, lo.z+k+iz),
183 sx[ix]*sy[iy]*sz[iz]*wq);
190 #if defined(WARPX_USE_GPUCLOCK) 192 amrex::Gpu::streamSynchronize();
194 amrex::The_Managed_Arena()->free(cost_real);
199 amrex::ignore_unused(n_rz_azimuthal_modes);
203 #endif // CHARGEDEPOSITION_H_ amrex::GpuComplex< amrex::Real > Complex
Definition: WarpX_Complex.H:22
void doChargeDepositionShapeN(const GetParticlePosition &GetPosition, const amrex::ParticleReal *const wp, const int *const ion_lev, amrex::FArrayBox &rho_fab, const long np_to_depose, const std::array< amrex::Real, 3 > &dx, const std::array< amrex::Real, 3 > xyzmin, const amrex::Dim3 lo, const amrex::Real q, const int n_rz_azimuthal_modes, amrex::Real *cost, const long load_balance_costs_update_algo)
Definition: ChargeDeposition.H:39
def x
Definition: read_lab_particles.py:25
int dx
Definition: compute_domain.py:35
def z
Definition: read_lab_particles.py:26
Definition: ShapeFactors.H:22
i
Definition: check_interp_points_and_weights.py:171
Definition: WarpXAlgorithmSelection.H:93
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:48
Defines a timer object to be used on GPU; measures summed thread cycles.
Definition: KernelTimer.H:19
Definition: BreitWheelerEngineWrapper.H:35