8 #ifndef CURRENTDEPOSITION_H_
9 #define CURRENTDEPOSITION_H_
27 using namespace amrex::literals;
53 template <
int depos_order>
55 const amrex::ParticleReal *
const wp,
56 const amrex::ParticleReal *
const uxp,
57 const amrex::ParticleReal *
const uyp,
58 const amrex::ParticleReal *
const uzp,
59 const int *
const ion_lev,
63 const long np_to_depose,
64 const amrex::Real relative_time,
65 const std::array<amrex::Real,3>&
dx,
66 const std::array<amrex::Real,3>& xyzmin,
69 const int n_rz_azimuthal_modes,
71 const long load_balance_costs_update_algo)
73 #if !defined(WARPX_DIM_RZ)
77 #if !defined(AMREX_USE_GPU)
83 const bool do_ionization = ion_lev;
84 const amrex::Real dzi = 1.0_rt/
dx[2];
85 #if defined(WARPX_DIM_1D_Z)
86 const amrex::Real invvol = dzi;
88 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
89 const amrex::Real dxi = 1.0_rt/
dx[0];
90 const amrex::Real invvol = dxi*dzi;
91 #elif defined(WARPX_DIM_3D)
92 const amrex::Real dxi = 1.0_rt/
dx[0];
93 const amrex::Real dyi = 1.0_rt/
dx[1];
94 const amrex::Real invvol = dxi*dyi*dzi;
97 #if (AMREX_SPACEDIM >= 2)
98 const amrex::Real
xmin = xyzmin[0];
100 #if defined(WARPX_DIM_3D)
101 const amrex::Real ymin = xyzmin[1];
103 const amrex::Real zmin = xyzmin[2];
114 constexpr
int zdir = WARPX_ZINDEX;
119 #if defined(WARPX_USE_GPUCLOCK)
120 amrex::Real* cost_real =
nullptr;
129 #if defined(WARPX_USE_GPUCLOCK)
136 const amrex::Real gaminv = 1.0_rt/std::sqrt(1.0_rt + uxp[ip]*uxp[ip]*clightsq
137 + uyp[ip]*uyp[ip]*clightsq
138 + uzp[ip]*uzp[ip]*clightsq);
139 amrex::Real wq = q*wp[ip];
144 amrex::ParticleReal xp, yp, zp;
145 GetPosition(ip, xp, yp, zp);
147 const amrex::Real vx = uxp[ip]*gaminv;
148 const amrex::Real vy = uyp[ip]*gaminv;
149 const amrex::Real vz = uzp[ip]*gaminv;
151 #if defined(WARPX_DIM_RZ)
154 const amrex::Real xpmid = xp + relative_time*vx;
155 const amrex::Real ypmid = yp + relative_time*vy;
156 const amrex::Real rpmid = std::sqrt(xpmid*xpmid + ypmid*ypmid);
157 amrex::Real costheta;
158 amrex::Real sintheta;
160 costheta = xpmid/rpmid;
161 sintheta = ypmid/rpmid;
167 const amrex::Real wqx = wq*invvol*(+vx*costheta + vy*sintheta);
168 const amrex::Real wqy = wq*invvol*(-vx*sintheta + vy*costheta);
170 const amrex::Real wqx = wq*invvol*vx;
171 const amrex::Real wqy = wq*invvol*vy;
173 const amrex::Real wqz = wq*invvol*vz;
177 #if (AMREX_SPACEDIM >= 2)
180 #if defined(WARPX_DIM_RZ)
182 const double xmid = (rpmid -
xmin)*dxi;
184 const double xmid = ((xp -
xmin) + relative_time*vx)*dxi;
191 double sx_node[depos_order + 1] = {0.};
192 double sx_cell[depos_order + 1] = {0.};
195 if (jx_type[0] ==
NODE || jy_type[0] ==
NODE || jz_type[0] ==
NODE) {
196 j_node = compute_shape_factor(sx_node, xmid);
198 if (jx_type[0] == CELL || jy_type[0] == CELL || jz_type[0] == CELL) {
199 j_cell = compute_shape_factor(sx_cell, xmid - 0.5);
202 amrex::Real sx_jx[depos_order + 1] = {0._rt};
203 amrex::Real sx_jy[depos_order + 1] = {0._rt};
204 amrex::Real sx_jz[depos_order + 1] = {0._rt};
205 for (
int ix=0; ix<=depos_order; ix++)
207 sx_jx[ix] = ((jx_type[0] ==
NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
208 sx_jy[ix] = ((jy_type[0] ==
NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
209 sx_jz[ix] = ((jz_type[0] ==
NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
212 int const j_jx = ((jx_type[0] ==
NODE) ? j_node : j_cell);
213 int const j_jy = ((jy_type[0] ==
NODE) ? j_node : j_cell);
214 int const j_jz = ((jz_type[0] ==
NODE) ? j_node : j_cell);
217 #if defined(WARPX_DIM_3D)
220 const double ymid = ((yp - ymin) + relative_time*vy)*dyi;
221 double sy_node[depos_order + 1] = {0.};
222 double sy_cell[depos_order + 1] = {0.};
225 if (jx_type[1] ==
NODE || jy_type[1] ==
NODE || jz_type[1] ==
NODE) {
226 k_node = compute_shape_factor(sy_node, ymid);
228 if (jx_type[1] == CELL || jy_type[1] == CELL || jz_type[1] == CELL) {
229 k_cell = compute_shape_factor(sy_cell, ymid - 0.5);
231 amrex::Real sy_jx[depos_order + 1] = {0._rt};
232 amrex::Real sy_jy[depos_order + 1] = {0._rt};
233 amrex::Real sy_jz[depos_order + 1] = {0._rt};
234 for (
int iy=0; iy<=depos_order; iy++)
236 sy_jx[iy] = ((jx_type[1] ==
NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
237 sy_jy[iy] = ((jy_type[1] ==
NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
238 sy_jz[iy] = ((jz_type[1] ==
NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
240 int const k_jx = ((jx_type[1] ==
NODE) ? k_node : k_cell);
241 int const k_jy = ((jy_type[1] ==
NODE) ? k_node : k_cell);
242 int const k_jz = ((jz_type[1] ==
NODE) ? k_node : k_cell);
247 const double zmid = ((zp - zmin) + relative_time*vz)*dzi;
248 double sz_node[depos_order + 1] = {0.};
249 double sz_cell[depos_order + 1] = {0.};
252 if (jx_type[zdir] ==
NODE || jy_type[zdir] ==
NODE || jz_type[zdir] ==
NODE) {
253 l_node = compute_shape_factor(sz_node, zmid);
255 if (jx_type[zdir] == CELL || jy_type[zdir] == CELL || jz_type[zdir] == CELL) {
256 l_cell = compute_shape_factor(sz_cell, zmid - 0.5);
258 amrex::Real sz_jx[depos_order + 1] = {0._rt};
259 amrex::Real sz_jy[depos_order + 1] = {0._rt};
260 amrex::Real sz_jz[depos_order + 1] = {0._rt};
261 for (
int iz=0; iz<=depos_order; iz++)
263 sz_jx[iz] = ((jx_type[zdir] ==
NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
264 sz_jy[iz] = ((jy_type[zdir] ==
NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
265 sz_jz[iz] = ((jz_type[zdir] ==
NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
267 int const l_jx = ((jx_type[zdir] ==
NODE) ? l_node : l_cell);
268 int const l_jy = ((jy_type[zdir] ==
NODE) ? l_node : l_cell);
269 int const l_jz = ((jz_type[zdir] ==
NODE) ? l_node : l_cell);
272 #if defined(WARPX_DIM_1D_Z)
273 for (
int iz=0; iz<=depos_order; iz++){
275 &jx_arr(lo.
x+l_jx+iz, 0, 0, 0),
278 &jy_arr(lo.
x+l_jy+iz, 0, 0, 0),
281 &jz_arr(lo.
x+l_jz+iz, 0, 0, 0),
285 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
286 for (
int iz=0; iz<=depos_order; iz++){
287 for (
int ix=0; ix<=depos_order; ix++){
289 &jx_arr(lo.
x+j_jx+ix, lo.
y+l_jx+iz, 0, 0),
290 sx_jx[ix]*sz_jx[iz]*wqx);
292 &jy_arr(lo.
x+j_jy+ix, lo.
y+l_jy+iz, 0, 0),
293 sx_jy[ix]*sz_jy[iz]*wqy);
295 &jz_arr(lo.
x+j_jz+ix, lo.
y+l_jz+iz, 0, 0),
296 sx_jz[ix]*sz_jz[iz]*wqz);
297 #if defined(WARPX_DIM_RZ)
299 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
312 #elif defined(WARPX_DIM_3D)
313 for (
int iz=0; iz<=depos_order; iz++){
314 for (
int iy=0; iy<=depos_order; iy++){
315 for (
int ix=0; ix<=depos_order; ix++){
317 &jx_arr(lo.
x+j_jx+ix, lo.
y+k_jx+iy, lo.
z+l_jx+iz),
318 sx_jx[ix]*sy_jx[iy]*sz_jx[iz]*wqx);
320 &jy_arr(lo.
x+j_jy+ix, lo.
y+k_jy+iy, lo.
z+l_jy+iz),
321 sx_jy[ix]*sy_jy[iy]*sz_jy[iz]*wqy);
323 &jz_arr(lo.
x+j_jz+ix, lo.
y+k_jz+iy, lo.
z+l_jz+iz),
324 sx_jz[ix]*sy_jz[iy]*sz_jz[iz]*wqz);
331 #if defined(WARPX_USE_GPUCLOCK)
365 template <
int depos_order>
367 const amrex::ParticleReal *
const wp,
368 const amrex::ParticleReal *
const uxp,
369 const amrex::ParticleReal *
const uyp,
370 const amrex::ParticleReal *
const uzp,
371 const int *
const ion_lev,
375 const long np_to_depose,
376 const amrex::Real relative_time,
377 const std::array<amrex::Real,3>&
dx,
378 const std::array<amrex::Real,3>& xyzmin,
381 const int n_rz_azimuthal_modes,
383 const long load_balance_costs_update_algo,
389 #if defined(AMREX_USE_HIP) || defined(AMREX_USE_CUDA)
390 using namespace amrex;
401 constexpr
int zdir = WARPX_ZINDEX;
406 #if defined(WARPX_USE_GPUCLOCK)
407 amrex::Real* cost_real =
nullptr;
415 const auto domain = geom.
Domain();
418 sample_tbox.
grow(depos_order);
426 const int nblocks = a_bins.
numBins();
430 const std::size_t shared_mem_bytes = npts*
sizeof(amrex::Real);
434 "Tile size too big for GPU shared memory current deposition");
441 #if defined(WARPX_USE_GPUCLOCK)
446 const int bin_id = blockIdx.x;
447 const unsigned int bin_start = offsets_ptr[bin_id];
448 const unsigned int bin_stop = offsets_ptr[bin_id+1];
450 if (bin_start == bin_stop) {
return; }
455 ParticleReal xp, yp, zp;
456 GetPosition(permutation[bin_start], xp, yp, zp);
457 #if defined(WARPX_DIM_3D)
458 IntVect iv =
IntVect(
int( amrex::Math::floor((xp-plo[0]) * dxiarr[0]) ),
459 int( amrex::Math::floor((yp-plo[1]) * dxiarr[1]) ),
460 int( amrex::Math::floor((zp-plo[2]) * dxiarr[2]) ));
461 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
462 IntVect iv =
IntVect(
int( amrex::Math::floor((xp-plo[0]) * dxiarr[0]) ),
463 int( amrex::Math::floor((zp-plo[1]) * dxiarr[1]) ));
464 #elif defined(WARPX_DIM_1D_Z)
465 IntVect iv =
IntVect(
int( amrex::Math::floor((zp-plo[0]) * dxiarr[0]) ));
467 iv += domain.smallEnd();
471 buffer_box.
grow(depos_order);
477 amrex::Real*
const shared = gsm.
dataPtr();
487 volatile amrex::Real* vs = shared;
488 for (
int i = threadIdx.x;
i < npts;
i += blockDim.x){
492 for (
unsigned int ip_orig = bin_start+threadIdx.x; ip_orig<bin_stop; ip_orig += blockDim.x)
494 const unsigned int ip = permutation[ip_orig];
495 depositComponent<depos_order>(GetPosition, wp, uxp, uyp, uzp, ion_lev, jx_buff, jx_type,
496 relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes,
497 ip, zdir,
NODE, CELL, 0);
501 addLocalToGlobal(tbox_x, jx_arr, jx_buff);
502 for (
int i = threadIdx.x;
i < npts;
i += blockDim.x){
507 for (
unsigned int ip_orig = bin_start+threadIdx.x; ip_orig<bin_stop; ip_orig += blockDim.x)
509 const unsigned int ip = permutation[ip_orig];
510 depositComponent<depos_order>(GetPosition, wp, uxp, uyp, uzp, ion_lev, jy_buff, jy_type,
511 relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes,
512 ip, zdir,
NODE, CELL, 1);
516 addLocalToGlobal(tbox_y, jy_arr, jy_buff);
517 for (
int i = threadIdx.x;
i < npts;
i += blockDim.x){
522 for (
unsigned int ip_orig = bin_start+threadIdx.x; ip_orig<bin_stop; ip_orig += blockDim.x)
524 const unsigned int ip = permutation[ip_orig];
525 depositComponent<depos_order>(GetPosition, wp, uxp, uyp, uzp, ion_lev, jz_buff, jz_type,
526 relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes,
527 ip, zdir,
NODE, CELL, 2);
531 addLocalToGlobal(tbox_z, jz_arr, jz_buff);
533 #if defined(WARPX_USE_GPUCLOCK)
544 ignore_unused( GetPosition, wp, uxp, uyp, uzp, ion_lev, jx_fab, jy_fab, jz_fab, np_to_depose, relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes, cost, load_balance_costs_update_algo, a_bins, box, geom, a_tbox_max_size);
575 template <
int depos_order>
577 const amrex::ParticleReal *
const wp,
578 const amrex::ParticleReal *
const uxp,
579 const amrex::ParticleReal *
const uyp,
580 const amrex::ParticleReal *
const uzp,
581 const int *
const ion_lev,
585 const long np_to_depose,
586 const amrex::Real
dt,
587 const amrex::Real relative_time,
588 const std::array<amrex::Real,3>&
dx,
589 const std::array<amrex::Real, 3> xyzmin,
592 const int n_rz_azimuthal_modes,
593 amrex::Real *
const cost,
594 const long load_balance_costs_update_algo)
596 using namespace amrex;
597 #if !defined(WARPX_DIM_RZ)
601 #if !defined(AMREX_USE_GPU)
607 bool const do_ionization = ion_lev;
608 #if !defined(WARPX_DIM_1D_Z)
609 Real
const dxi = 1.0_rt /
dx[0];
611 #if !defined(WARPX_DIM_1D_Z)
612 Real
const xmin = xyzmin[0];
614 #if defined(WARPX_DIM_3D)
615 Real
const dyi = 1.0_rt /
dx[1];
616 Real
const ymin = xyzmin[1];
618 Real
const dzi = 1.0_rt /
dx[2];
619 Real
const zmin = xyzmin[2];
621 #if defined(WARPX_DIM_3D)
622 Real
const invdtdx = 1.0_rt / (
dt*
dx[1]*
dx[2]);
623 Real
const invdtdy = 1.0_rt / (
dt*
dx[0]*
dx[2]);
624 Real
const invdtdz = 1.0_rt / (
dt*
dx[0]*
dx[1]);
625 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
626 Real
const invdtdx = 1.0_rt / (
dt*
dx[2]);
627 Real
const invdtdz = 1.0_rt / (
dt*
dx[0]);
628 Real
const invvol = 1.0_rt / (
dx[0]*
dx[2]);
629 #elif defined(WARPX_DIM_1D_Z)
630 Real
const invdtdz = 1.0_rt / (
dt*
dx[0]);
631 Real
const invvol = 1.0_rt / (
dx[2]);
634 #if defined(WARPX_DIM_RZ)
639 #if !defined(WARPX_DIM_1D_Z)
640 Real constexpr one_third = 1.0_rt / 3.0_rt;
641 Real constexpr one_sixth = 1.0_rt / 6.0_rt;
645 #if defined(WARPX_USE_GPUCLOCK)
646 amrex::Real* cost_real =
nullptr;
655 #if defined(WARPX_USE_GPUCLOCK)
662 Real
const gaminv = 1.0_rt/std::sqrt(1.0_rt + uxp[ip]*uxp[ip]*clightsq
663 + uyp[ip]*uyp[ip]*clightsq
664 + uzp[ip]*uzp[ip]*clightsq);
672 ParticleReal xp, yp, zp;
673 GetPosition(ip, xp, yp, zp);
675 #if !defined(WARPX_DIM_1D_Z)
676 Real
const wqx = wq*invdtdx;
678 #if defined(WARPX_DIM_3D)
679 Real
const wqy = wq*invdtdy;
681 Real
const wqz = wq*invdtdz;
684 #if defined(WARPX_DIM_RZ)
685 Real
const xp_new = xp + (relative_time + 0.5_rt*
dt)*uxp[ip]*gaminv;
686 Real
const yp_new = yp + (relative_time + 0.5_rt*
dt)*uyp[ip]*gaminv;
687 Real
const xp_mid = xp_new - 0.5_rt*
dt*uxp[ip]*gaminv;
688 Real
const yp_mid = yp_new - 0.5_rt*
dt*uyp[ip]*gaminv;
689 Real
const xp_old = xp_new -
dt*uxp[ip]*gaminv;
690 Real
const yp_old = yp_new -
dt*uyp[ip]*gaminv;
691 Real
const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new);
692 Real
const rp_mid = std::sqrt(xp_mid*xp_mid + yp_mid*yp_mid);
693 Real
const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old);
694 Real costheta_new, sintheta_new;
695 if (rp_new > 0._rt) {
696 costheta_new = xp_new/rp_new;
697 sintheta_new = yp_new/rp_new;
699 costheta_new = 1._rt;
700 sintheta_new = 0._rt;
702 amrex::Real costheta_mid, sintheta_mid;
703 if (rp_mid > 0._rt) {
704 costheta_mid = xp_mid/rp_mid;
705 sintheta_mid = yp_mid/rp_mid;
707 costheta_mid = 1._rt;
708 sintheta_mid = 0._rt;
710 amrex::Real costheta_old, sintheta_old;
711 if (rp_old > 0._rt) {
712 costheta_old = xp_old/rp_old;
713 sintheta_old = yp_old/rp_old;
715 costheta_old = 1._rt;
716 sintheta_old = 0._rt;
722 double const x_new = (rp_new -
xmin)*dxi;
723 double const x_old = (rp_old -
xmin)*dxi;
725 #if !defined(WARPX_DIM_1D_Z)
727 double const x_new = (xp -
xmin + (relative_time + 0.5_rt*
dt)*uxp[ip]*gaminv)*dxi;
728 double const x_old = x_new -
dt*dxi*uxp[ip]*gaminv;
731 #if defined(WARPX_DIM_3D)
733 double const y_new = (yp - ymin + (relative_time + 0.5_rt*
dt)*uyp[ip]*gaminv)*dyi;
734 double const y_old = y_new -
dt*dyi*uyp[ip]*gaminv;
737 double const z_new = (zp - zmin + (relative_time + 0.5_rt*
dt)*uzp[ip]*gaminv)*dzi;
738 double const z_old = z_new -
dt*dzi*uzp[ip]*gaminv;
740 #if defined(WARPX_DIM_RZ)
741 Real
const vy = (-uxp[ip]*sintheta_mid + uyp[ip]*costheta_mid)*gaminv;
742 #elif defined(WARPX_DIM_XZ)
743 Real
const vy = uyp[ip]*gaminv;
744 #elif defined(WARPX_DIM_1D_Z)
745 Real
const vx = uxp[ip]*gaminv;
746 Real
const vy = uyp[ip]*gaminv;
754 #if !defined(WARPX_DIM_1D_Z)
755 double sx_new[depos_order + 3] = {0.};
756 double sx_old[depos_order + 3] = {0.};
758 #if defined(WARPX_DIM_3D)
760 double sy_new[depos_order + 3] = {0.};
761 double sy_old[depos_order + 3] = {0.};
764 double sz_new[depos_order + 3] = {0.};
765 double sz_old[depos_order + 3] = {0.};
773 #if !defined(WARPX_DIM_1D_Z)
774 const int i_new = compute_shape_factor(sx_new+1, x_new);
775 const int i_old = compute_shifted_shape_factor(sx_old, x_old, i_new);
777 #if defined(WARPX_DIM_3D)
778 const int j_new = compute_shape_factor(sy_new+1, y_new);
779 const int j_old = compute_shifted_shape_factor(sy_old, y_old, j_new);
781 const int k_new = compute_shape_factor(sz_new+1, z_new);
782 const int k_old = compute_shifted_shape_factor(sz_old, z_old, k_new);
785 #if !defined(WARPX_DIM_1D_Z)
786 int dil = 1, diu = 1;
787 if (i_old < i_new) dil = 0;
788 if (i_old > i_new) diu = 0;
790 #if defined(WARPX_DIM_3D)
791 int djl = 1, dju = 1;
792 if (j_old < j_new) djl = 0;
793 if (j_old > j_new) dju = 0;
795 int dkl = 1, dku = 1;
796 if (k_old < k_new) dkl = 0;
797 if (k_old > k_new) dku = 0;
799 #if defined(WARPX_DIM_3D)
801 for (
int k=dkl; k<=depos_order+2-dku; k++) {
802 for (
int j=djl; j<=depos_order+2-dju; j++) {
803 amrex::Real sdxi = 0._rt;
804 for (
int i=dil;
i<=depos_order+1-diu;
i++) {
805 sdxi += wqx*(sx_old[
i] - sx_new[
i])*(
806 one_third*(sy_new[j]*sz_new[k] + sy_old[j]*sz_old[k])
807 +one_sixth*(sy_new[j]*sz_old[k] + sy_old[j]*sz_new[k]));
812 for (
int k=dkl; k<=depos_order+2-dku; k++) {
813 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
814 amrex::Real sdyj = 0._rt;
815 for (
int j=djl; j<=depos_order+1-dju; j++) {
816 sdyj += wqy*(sy_old[j] - sy_new[j])*(
817 one_third*(sx_new[
i]*sz_new[k] + sx_old[
i]*sz_old[k])
818 +one_sixth*(sx_new[
i]*sz_old[k] + sx_old[
i]*sz_new[k]));
823 for (
int j=djl; j<=depos_order+2-dju; j++) {
824 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
825 amrex::Real sdzk = 0._rt;
826 for (
int k=dkl; k<=depos_order+1-dku; k++) {
827 sdzk += wqz*(sz_old[k] - sz_new[k])*(
828 one_third*(sx_new[
i]*sy_new[j] + sx_old[
i]*sy_old[j])
829 +one_sixth*(sx_new[
i]*sy_old[j] + sx_old[
i]*sy_new[j]));
835 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
837 for (
int k=dkl; k<=depos_order+2-dku; k++) {
838 amrex::Real sdxi = 0._rt;
839 for (
int i=dil;
i<=depos_order+1-diu;
i++) {
840 sdxi += wqx*(sx_old[
i] - sx_new[
i])*0.5_rt*(sz_new[k] + sz_old[k]);
842 #if defined(WARPX_DIM_RZ)
844 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
846 const Complex djr_cmplx = 2._rt *sdxi*xy_mid;
849 xy_mid = xy_mid*xy_mid0;
854 for (
int k=dkl; k<=depos_order+2-dku; k++) {
855 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
856 Real
const sdyj = wq*vy*invvol*(
857 one_third*(sx_new[
i]*sz_new[k] + sx_old[
i]*sz_old[k])
858 +one_sixth*(sx_new[
i]*sz_old[k] + sx_old[
i]*sz_new[k]));
860 #if defined(WARPX_DIM_RZ)
865 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
868 const Complex djt_cmplx = -2._rt * I*(i_new-1 +
i +
xmin*dxi)*wq*invdtdx/(amrex::Real)imode
869 *(
Complex(sx_new[
i]*sz_new[k], 0._rt)*(xy_new - xy_mid)
870 +
Complex(sx_old[
i]*sz_old[k], 0._rt)*(xy_mid - xy_old));
873 xy_new = xy_new*xy_new0;
874 xy_mid = xy_mid*xy_mid0;
875 xy_old = xy_old*xy_old0;
880 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
882 for (
int k=dkl; k<=depos_order+1-dku; k++) {
883 sdzk += wqz*(sz_old[k] - sz_new[k])*0.5_rt*(sx_new[
i] + sx_old[
i]);
885 #if defined(WARPX_DIM_RZ)
887 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
889 const Complex djz_cmplx = 2._rt * sdzk * xy_mid;
892 xy_mid = xy_mid*xy_mid0;
897 #elif defined(WARPX_DIM_1D_Z)
899 for (
int k=dkl; k<=depos_order+2-dku; k++) {
900 amrex::Real
const sdxi = wq*vx*invvol*0.5_rt*(sz_old[k] + sz_new[k]);
903 for (
int k=dkl; k<=depos_order+2-dku; k++) {
904 amrex::Real
const sdyj = wq*vy*invvol*0.5_rt*(sz_old[k] + sz_new[k]);
907 amrex::Real sdzk = 0._rt;
908 for (
int k=dkl; k<=depos_order+1-dku; k++) {
909 sdzk += wqz*(sz_old[k] - sz_new[k]);
915 #if defined(WARPX_USE_GPUCLOCK)
953 template <
int depos_order>
955 const amrex::ParticleReal*
const wp,
956 const amrex::ParticleReal*
const uxp,
957 const amrex::ParticleReal*
const uyp,
958 const amrex::ParticleReal*
const uzp,
959 const int*
const ion_lev,
963 const long np_to_depose,
964 const amrex::Real
dt,
965 const amrex::Real relative_time,
966 const std::array<amrex::Real,3>&
dx,
967 const std::array<amrex::Real,3>& xyzmin,
970 const int n_rz_azimuthal_modes,
972 const long load_balance_costs_update_algo)
974 #if defined(WARPX_DIM_RZ)
976 wp, uxp, uyp, uzp, ion_lev, Dx_fab, Dy_fab, Dz_fab,
977 np_to_depose,
dt, relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes);
981 #if defined(WARPX_DIM_1D_Z)
983 wp, uxp, uyp, uzp, ion_lev, Dx_fab, Dy_fab, Dz_fab,
984 np_to_depose,
dt, relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes);
988 #if !defined(WARPX_USE_GPUCLOCK)
992 #if !(defined WARPX_DIM_RZ || defined WARPX_DIM_1D_Z)
996 const bool do_ionization = ion_lev;
999 const amrex::Real dxi = 1._rt /
dx[0];
1000 const amrex::Real dzi = 1._rt /
dx[2];
1001 #if defined(WARPX_DIM_3D)
1002 const amrex::Real dyi = 1._rt /
dx[1];
1006 const amrex::Real invdt = 1._rt /
dt;
1009 #if defined(WARPX_DIM_XZ)
1010 const amrex::Real invvol = dxi * dzi;
1011 #elif defined(WARPX_DIM_3D)
1012 const amrex::Real invvol = dxi * dyi * dzi;
1016 const amrex::Real
xmin = xyzmin[0];
1017 const amrex::Real zmin = xyzmin[2];
1018 #if defined(WARPX_DIM_3D)
1019 const amrex::Real ymin = xyzmin[1];
1023 #if defined(WARPX_DIM_3D)
1026 #elif defined(WARPX_DIM_XZ)
1042 #if defined(WARPX_USE_GPUCLOCK)
1043 amrex::Real* cost_real =
nullptr;
1051 #if defined(WARPX_USE_GPUCLOCK)
1058 const amrex::Real invgam = 1._rt / std::sqrt(1._rt + uxp[ip] * uxp[ip] * invcsq
1059 + uyp[ip] * uyp[ip] * invcsq
1060 + uzp[ip] * uzp[ip] * invcsq);
1062 amrex::Real wq = q * wp[ip];
1063 if (do_ionization) wq *= ion_lev[ip];
1066 amrex::ParticleReal xp, yp, zp;
1067 GetPosition(ip, xp, yp, zp);
1070 const amrex::Real vx = uxp[ip] * invgam;
1071 const amrex::Real vy = uyp[ip] * invgam;
1072 const amrex::Real vz = uzp[ip] * invgam;
1075 xp += relative_time * vx;
1076 yp += relative_time * vy;
1077 zp += relative_time * vz;
1080 #if defined(WARPX_DIM_XZ)
1081 const amrex::Real wqy = wq * vy * invvol;
1086 double const x_new = (xp -
xmin + 0.5_rt*
dt*vx) * dxi;
1087 double const x_old = (xp -
xmin - 0.5_rt*
dt*vx) * dxi;
1088 #if defined(WARPX_DIM_3D)
1090 double const y_new = (yp - ymin + 0.5_rt*
dt*vy) * dyi;
1091 double const y_old = (yp - ymin - 0.5_rt*
dt*vy) * dyi;
1094 double const z_new = (zp - zmin + 0.5_rt*
dt*vz) * dzi;
1095 double const z_old = (zp - zmin - 0.5_rt*
dt*vz) * dzi;
1099 double sx_new[depos_order+1] = {0.};
1100 double sx_old[depos_order+1] = {0.};
1101 #if defined(WARPX_DIM_3D)
1103 double sy_new[depos_order+1] = {0.};
1104 double sy_old[depos_order+1] = {0.};
1107 double sz_new[depos_order+1] = {0.};
1108 double sz_old[depos_order+1] = {0.};
1115 const int i_new = compute_shape_factor(sx_new, x_new);
1116 #if defined(WARPX_DIM_3D)
1119 const int j_new = compute_shape_factor(sy_new, y_new);
1123 const int k_new = compute_shape_factor(sz_new, z_new);
1129 const int i_old = compute_shape_factor(sx_old, x_old);
1130 #if defined(WARPX_DIM_3D)
1133 const int j_old = compute_shape_factor(sy_old, y_old);
1137 const int k_old = compute_shape_factor(sz_old, z_old);
1140 #if defined(WARPX_DIM_XZ)
1142 for (
int k=0; k<=depos_order; k++) {
1143 for (
int i=0;
i<=depos_order;
i++) {
1147 auto const sxn_szn =
static_cast<amrex::Real
>(sx_new[
i] * sz_new[k]);
1148 auto const sxo_szn =
static_cast<amrex::Real
>(sx_old[
i] * sz_new[k]);
1149 auto const sxn_szo =
static_cast<amrex::Real
>(sx_new[
i] * sz_old[k]);
1150 auto const sxo_szo =
static_cast<amrex::Real
>(sx_old[
i] * sz_old[k]);
1152 if (i_new == i_old && k_new == k_old) {
1155 wq * invvol * invdt * (sxn_szn - sxo_szo));
1158 wq * invvol * invdt * (sxn_szo - sxo_szn));
1162 wqy * 0.25_rt * (sxn_szn + sxn_szo + sxo_szn + sxo_szo));
1166 wq * invvol * invdt * sxn_szn);
1169 - wq * invvol * invdt * sxo_szo);
1172 wq * invvol * invdt * sxn_szo);
1175 - wq * invvol * invdt * sxo_szn);
1179 wqy * 0.25_rt * sxn_szn);
1182 wqy * 0.25_rt * sxn_szo);
1185 wqy * 0.25_rt * sxo_szn);
1188 wqy * 0.25_rt * sxo_szo);
1194 #elif defined(WARPX_DIM_3D)
1196 for (
int k=0; k<=depos_order; k++) {
1197 for (
int j=0; j<=depos_order; j++) {
1199 auto const syn_szn =
static_cast<amrex::Real
>(sy_new[j] * sz_new[k]);
1200 auto const syo_szn =
static_cast<amrex::Real
>(sy_old[j] * sz_new[k]);
1201 auto const syn_szo =
static_cast<amrex::Real
>(sy_new[j] * sz_old[k]);
1202 auto const syo_szo =
static_cast<amrex::Real
>(sy_old[j] * sz_old[k]);
1204 for (
int i=0;
i<=depos_order;
i++) {
1206 auto const sxn_syn_szn =
static_cast<amrex::Real
>(sx_new[
i]) * syn_szn;
1207 auto const sxo_syn_szn =
static_cast<amrex::Real
>(sx_old[
i]) * syn_szn;
1208 auto const sxn_syo_szn =
static_cast<amrex::Real
>(sx_new[
i]) * syo_szn;
1209 auto const sxo_syo_szn =
static_cast<amrex::Real
>(sx_old[
i]) * syo_szn;
1210 auto const sxn_syn_szo =
static_cast<amrex::Real
>(sx_new[
i]) * syn_szo;
1211 auto const sxo_syn_szo =
static_cast<amrex::Real
>(sx_old[
i]) * syn_szo;
1212 auto const sxn_syo_szo =
static_cast<amrex::Real
>(sx_new[
i]) * syo_szo;
1213 auto const sxo_syo_szo =
static_cast<amrex::Real
>(sx_old[
i]) * syo_szo;
1215 if (i_new == i_old && j_new == j_old && k_new == k_old) {
1218 wq * invvol * invdt * (sxn_syn_szn - sxo_syo_szo));
1221 wq * invvol * invdt * (sxn_syn_szo - sxo_syo_szn));
1224 wq * invvol * invdt * (sxn_syo_szn - sxo_syn_szo));
1227 wq * invvol * invdt * (sxo_syn_szn - sxn_syo_szo));
1231 wq * invvol * invdt * sxn_syn_szn);
1234 - wq * invvol * invdt * sxo_syo_szo);
1237 wq * invvol * invdt * sxn_syn_szo);
1240 - wq * invvol * invdt * sxo_syo_szn);
1243 wq * invvol * invdt * sxn_syo_szn);
1246 - wq * invvol * invdt * sxo_syn_szo);
1249 wq * invvol * invdt * sxo_syn_szn);
1252 - wq * invvol * invdt * sxn_syo_szo);
1260 #if defined(WARPX_DIM_3D)
1263 const amrex::Real t_a = temp_arr(
i,j,k,0);
1264 const amrex::Real t_b = temp_arr(
i,j,k,1);
1265 const amrex::Real t_c = temp_arr(
i,j,k,2);
1266 const amrex::Real t_d = temp_arr(
i,j,k,3);
1267 Dx_arr(
i,j,k) += (1._rt/6._rt)*(2_rt*t_a + t_b + t_c - 2._rt*t_d);
1268 Dy_arr(
i,j,k) += (1._rt/6._rt)*(2_rt*t_a + t_b - 2._rt*t_c + t_d);
1269 Dz_arr(
i,j,k) += (1._rt/6._rt)*(2_rt*t_a - 2._rt*t_b + t_c + t_d);
1271 #elif defined(WARPX_DIM_XZ)
1274 const amrex::Real t_a = temp_arr(
i,j,0,0);
1275 const amrex::Real t_b = temp_arr(
i,j,0,1);
1276 Dx_arr(
i,j,0) += (0.5_rt)*(t_a + t_b);
1277 Dz_arr(
i,j,0) += (0.5_rt)*(t_a - t_b);
1284 # if defined(WARPX_USE_GPUCLOCK)
1287 *cost += *cost_real;
#define AMREX_ALWAYS_ASSERT(EX)
#define AMREX_D_DECL(a, b, c)
void doDepositionShapeN(const GetParticlePosition &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *const ion_lev, amrex::FArrayBox &jx_fab, amrex::FArrayBox &jy_fab, amrex::FArrayBox &jz_fab, const long np_to_depose, const amrex::Real relative_time, 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)
Current Deposition for thread thread_num.
Definition: CurrentDeposition.H:54
void doEsirkepovDepositionShapeN(const GetParticlePosition &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *const ion_lev, const amrex::Array4< amrex::Real > &Jx_arr, const amrex::Array4< amrex::Real > &Jy_arr, const amrex::Array4< amrex::Real > &Jz_arr, const long np_to_depose, const amrex::Real dt, const amrex::Real relative_time, 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 *const cost, const long load_balance_costs_update_algo)
Esirkepov Current Deposition for thread thread_num.
Definition: CurrentDeposition.H:576
void doVayDepositionShapeN(const GetParticlePosition &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *const ion_lev, amrex::FArrayBox &Dx_fab, amrex::FArrayBox &Dy_fab, amrex::FArrayBox &Dz_fab, const long np_to_depose, const amrex::Real dt, const amrex::Real relative_time, 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)
Vay current deposition (Vay et al, 2013) for thread thread_num: deposit D in real space and store the...
Definition: CurrentDeposition.H:954
void doDepositionSharedShapeN(const GetParticlePosition &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *const ion_lev, amrex::FArrayBox &jx_fab, amrex::FArrayBox &jy_fab, amrex::FArrayBox &jz_fab, const long np_to_depose, const amrex::Real relative_time, 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, const amrex::DenseBins< WarpXParticleContainer::ParticleType > &a_bins, const amrex::Box &box, const amrex::Geometry &geom, const amrex::IntVect &a_tbox_max_size)
Current Deposition for thread thread_num using shared memory.
Definition: CurrentDeposition.H:366
#define WARPX_ABORT_WITH_MESSAGE(MSG)
Definition: TextMsg.H:15
#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition: TextMsg.H:13
amrex::GpuComplex< amrex::Real > Complex
Definition: WarpX_Complex.H:22
static amrex::IntVect shared_tilesize
tileSize to use for shared current deposition operations
Definition: WarpX.H:251
static int shared_mem_current_tpb
number of threads to use per block in shared deposition
Definition: WarpX.H:248
Defines a timer object to be used on GPU; measures summed thread cycles.
Definition: KernelTimer.H:27
virtual void free(void *pt)=0
virtual void * alloc(std::size_t sz)=0
AMREX_FORCE_INLINE Array4< Real const > array() const noexcept
const Box & box() const noexcept
AMREX_GPU_HOST_DEVICE Long numPts() const noexcept
AMREX_GPU_HOST_DEVICE Box & grow(int i) noexcept
GpuArray< Real, AMREX_SPACEDIM > InvCellSizeArray() const noexcept
index_type * offsetsPtr() noexcept
index_type * permutationPtr() noexcept
Long numBins() const noexcept
GpuArray< Real, AMREX_SPACEDIM > ProbLoArray() const noexcept
const Box & Domain() const noexcept
static std::size_t sharedMemPerBlock() noexcept
static constexpr auto c
vacuum speed of light [m/s]
Definition: constant.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
void streamSynchronize() noexcept
gpuStream_t gpuStream() noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 end(Box const &box) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Box convert(const Box &b, const IntVect &typ) noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 begin(Box const &box) noexcept
void launch(T const &n, L &&f) noexcept
Arena * The_Managed_Arena()
std::enable_if_t< std::is_integral< T >::value > ParallelFor(TypeList< CTOs... >, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int getTileIndex(const IntVect &iv, const Box &box, const bool a_do_tiling, const IntVect &a_tile_size, Box &tbx)
i
Definition: check_interp_points_and_weights.py:174
float dt
Definition: stencil.py:440
tuple dx
lab frame
Definition: stencil.py:427
xmin
Definition: stencil.py:422
Definition: ShapeFactors.H:29
Definition: ShapeFactors.H:84
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel.
Definition: GetAndSetPosition.H:53
@ GpuClock
Definition: WarpXAlgorithmSelection.H:125
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T real() const noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T imag() const noexcept
AMREX_GPU_DEVICE T * dataPtr() noexcept