38 const amrex::ParticleReal *
const wp,
46 [[maybe_unused]]
int n_rz_azimuthal_modes)
48 using namespace amrex;
52 const bool do_ionization = ion_lev;
54 const amrex::Real invvol = dinv.
x*dinv.
y*dinv.
z;
67 amrex::Real wq = q*wp[ip]*invvol;
72 amrex::ParticleReal xp, yp, zp;
73 GetPosition(ip, xp, yp, zp);
77#if !defined(WARPX_DIM_1D_Z)
80#if defined(WARPX_DIM_RZ)
81 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
82 const amrex::Real costheta = (rp > 0._rt ? xp/rp : 1._rt);
83 const amrex::Real sintheta = (rp > 0._rt ? yp/rp : 0._rt);
85 const amrex::Real x = (rp - xyzmin.
x)*dinv.
x;
86#elif defined(WARPX_DIM_RCYLINDER)
87 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
88 const amrex::Real x = (rp - xyzmin.
x)*dinv.
x;
89#elif defined(WARPX_DIM_RSPHERE)
90 const amrex::Real rp = std::sqrt(xp*xp + yp*yp + zp*zp);
91 const amrex::Real x = (rp - xyzmin.
x)*dinv.
x;
93 const amrex::Real x = (xp - xyzmin.
x)*dinv.
x;
98 amrex::Real sx[depos_order + 1] = {0._rt};
100 if (rho_type[0] ==
NODE) {
101 i = compute_shape_factor(sx, x);
102 }
else if (rho_type[0] == CELL) {
103 i = compute_shape_factor(sx, x - 0.5_rt);
106#if defined(WARPX_DIM_3D)
108 const amrex::Real y = (yp - xyzmin.
y)*dinv.
y;
109 amrex::Real sy[depos_order + 1] = {0._rt};
111 if (rho_type[1] ==
NODE) {
112 j = compute_shape_factor(sy, y);
113 }
else if (rho_type[1] == CELL) {
114 j = compute_shape_factor(sy, y - 0.5_rt);
117#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
119 const amrex::Real z = (zp - xyzmin.
z)*dinv.
z;
120 amrex::Real sz[depos_order + 1] = {0._rt};
122 if (rho_type[WARPX_ZINDEX] ==
NODE) {
123 k = compute_shape_factor(sz, z);
124 }
else if (rho_type[WARPX_ZINDEX] == CELL) {
125 k = compute_shape_factor(sz, z - 0.5_rt);
130#if defined(WARPX_DIM_1D_Z)
131 for (
int iz=0; iz<=depos_order; iz++){
133 &rho_arr(lo.
x+k+iz, 0, 0, 0),
136#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
137 for (
int ix=0; ix<=depos_order; ix++){
139 &rho_arr(lo.
x+i+ix, 0, 0, 0),
142#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
143 for (
int iz=0; iz<=depos_order; iz++){
144 for (
int ix=0; ix<=depos_order; ix++){
146 &rho_arr(lo.
x+i+ix, lo.
y+k+iz, 0, 0),
148#if defined(WARPX_DIM_RZ)
150 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
159#elif defined(WARPX_DIM_3D)
160 for (
int iz=0; iz<=depos_order; iz++){
161 for (
int iy=0; iy<=depos_order; iy++){
162 for (
int ix=0; ix<=depos_order; ix++){
164 &rho_arr(lo.
x+i+ix, lo.
y+j+iy, lo.
z+k+iz),
165 sx[ix]*sy[iy]*sz[iz]*wq);
197 const amrex::ParticleReal *
const wp,
201 const long np_to_deposit,
206 [[maybe_unused]]
const int n_rz_azimuthal_modes,
214 using namespace amrex;
218#if !defined(AMREX_USE_GPU)
224 const bool do_ionization = ion_lev;
226 const amrex::Real invvol = dinv.
x*dinv.
y*dinv.
z;
229 auto rho_box = rho_fab.
box();
236#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
238 const auto domain = geom.
Domain();
243 sample_tbox_x.
grow(depos_order);
245 const auto npts = sample_tbox_x.
numPts();
247 const int nblocks = a_bins.
numBins();
249 const int threads_per_block = 256;
251 std::size_t shared_mem_bytes = npts*
sizeof(amrex::Real);
256 "Tile size too big for GPU shared memory charge deposition");
259#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
271#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
272 const int bin_id = blockIdx.x;
273 const unsigned int bin_start = offsets_ptr[bin_id];
274 const unsigned int bin_stop = offsets_ptr[bin_id+1];
276 if (bin_start == bin_stop) {
return; }
280 ParticleReal xp, yp, zp;
281 GetPosition(permutation[bin_start], xp, yp, zp);
282#if defined(WARPX_DIM_3D)
284 int(amrex::Math::floor((yp-plo[1])*dinv.
y)),
285 int(amrex::Math::floor((zp-plo[2])*dinv.
z)));
286#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
288 int(amrex::Math::floor((zp-plo[1])*dinv.
z)));
289#elif defined(WARPX_DIM_1D_Z)
291#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
294 iv += domain.smallEnd();
299 tbx.
grow(depos_order);
302 amrex::Real*
const shared = gsm.
dataPtr();
307 volatile amrex::Real* vs = shared;
308 for (
int i = threadIdx.x; i < tbx.
numPts(); i += blockDim.x) {
316#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
318 for (
unsigned int ip_orig = bin_start + threadIdx.x; ip_orig < bin_stop; ip_orig += blockDim.x)
321 const unsigned int ip = permutation[ip_orig];
324 amrex::Real wq = q*wp[ip]*invvol;
329 amrex::ParticleReal xp, yp, zp;
330 GetPosition(ip, xp, yp, zp);
334#if !defined(WARPX_DIM_1D_Z)
337#if defined(WARPX_DIM_RZ)
338 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
339 amrex::Real costheta;
340 amrex::Real sintheta;
349 const amrex::Real x = (rp - xyzmin.
x)*dinv.
x;
350#elif defined(WARPX_DIM_RCYLINDER)
351 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
352 const amrex::Real x = (rp - xyzmin.
x)*dinv.
x;
353#elif defined(WARPX_DIM_RSPHERE)
354 const amrex::Real rp = std::sqrt(xp*xp + yp*yp + zp*zp);
355 const amrex::Real x = (rp - xyzmin.
x)*dinv.
x;
357 const amrex::Real x = (xp - xyzmin.
x)*dinv.
x;
362 amrex::Real sx[depos_order + 1] = {0._rt};
364 if (rho_type[0] ==
NODE) {
365 i = compute_shape_factor(sx, x);
366 }
else if (rho_type[0] == CELL) {
367 i = compute_shape_factor(sx, x - 0.5_rt);
370#if defined(WARPX_DIM_3D)
372 const amrex::Real y = (yp - xyzmin.
y)*dinv.
y;
373 amrex::Real sy[depos_order + 1] = {0._rt};
375 if (rho_type[1] ==
NODE) {
376 j = compute_shape_factor(sy, y);
377 }
else if (rho_type[1] == CELL) {
378 j = compute_shape_factor(sy, y - 0.5_rt);
381#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
383 const amrex::Real z = (zp - xyzmin.
z)*dinv.
z;
384 amrex::Real sz[depos_order + 1] = {0._rt};
386 if (rho_type[WARPX_ZINDEX] ==
NODE) {
387 k = compute_shape_factor(sz, z);
388 }
else if (rho_type[WARPX_ZINDEX] == CELL) {
389 k = compute_shape_factor(sz, z - 0.5_rt);
394#if defined(WARPX_DIM_1D_Z)
395 for (
int iz=0; iz<=depos_order; iz++){
397 &buf(lo.
x+k+iz, 0, 0, 0),
400#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
401 for (
int ix=0; ix<=depos_order; ix++){
403 &buf(lo.
x+i+ix, 0, 0, 0),
406#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
407 for (
int iz=0; iz<=depos_order; iz++){
408 for (
int ix=0; ix<=depos_order; ix++){
410 &buf(lo.
x+i+ix, lo.
y+k+iz, 0, 0),
412#if defined(WARPX_DIM_RZ)
414 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
423#elif defined(WARPX_DIM_3D)
424 for (
int iz=0; iz<=depos_order; iz++){
425 for (
int iy=0; iy<=depos_order; iy++){
426 for (
int ix=0; ix<=depos_order; ix++){
428 &buf(lo.
x+i+ix, lo.
y+j+iy, lo.
z+k+iz),
429 sx[ix]*sy[iy]*sz[iz]*wq);
436#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
439 addLocalToGlobal(tbx, rho_arr, buf);
void doChargeDepositionSharedShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const int *ion_lev, amrex::FArrayBox &rho_fab, const amrex::IntVect &ix_type, const long np_to_deposit, const amrex::XDim3 &dinv, const amrex::XDim3 &xyzmin, const amrex::Dim3 lo, const amrex::Real q, const int n_rz_azimuthal_modes, const amrex::DenseBins< WarpXParticleContainer::ParticleTileType::ParticleTileDataType > &a_bins, const amrex::Box &box, const amrex::Geometry &geom, const amrex::IntVect &a_tbox_max_size, const amrex::IntVect bin_size)
Definition ChargeDeposition.H:196
void doChargeDepositionShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const int *ion_lev, amrex::FArrayBox &rho_fab, long np_to_deposit, const amrex::XDim3 &dinv, const amrex::XDim3 &xyzmin, amrex::Dim3 lo, amrex::Real q, int n_rz_azimuthal_modes)
Definition ChargeDeposition.H:37
#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition TextMsg.H:13
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel.
Definition GetAndSetPosition.H:75