8 #ifndef CURRENTDEPOSITION_H_
9 #define CURRENTDEPOSITION_H_
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,
64 amrex::Real relative_time,
65 const std::array<amrex::Real,3>&
dx,
66 const std::array<amrex::Real,3>& xyzmin,
69 int n_rz_azimuthal_modes,
71 long load_balance_costs_update_algo)
73 using namespace amrex::literals;
75 #if !defined(WARPX_DIM_RZ)
79 #if !defined(AMREX_USE_GPU)
85 const bool do_ionization = ion_lev;
86 const amrex::Real dzi = 1.0_rt/
dx[2];
87 #if defined(WARPX_DIM_1D_Z)
88 const amrex::Real invvol = dzi;
90 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
91 const amrex::Real dxi = 1.0_rt/
dx[0];
92 const amrex::Real invvol = dxi*dzi;
93 #elif defined(WARPX_DIM_3D)
94 const amrex::Real dxi = 1.0_rt/
dx[0];
95 const amrex::Real dyi = 1.0_rt/
dx[1];
96 const amrex::Real invvol = dxi*dyi*dzi;
99 #if (AMREX_SPACEDIM >= 2)
100 const amrex::Real
xmin = xyzmin[0];
102 #if defined(WARPX_DIM_3D)
103 const amrex::Real ymin = xyzmin[1];
105 const amrex::Real zmin = xyzmin[2];
116 constexpr
int zdir = WARPX_ZINDEX;
121 #if defined(WARPX_USE_GPUCLOCK)
122 amrex::Real* cost_real =
nullptr;
131 #if defined(WARPX_USE_GPUCLOCK)
138 const amrex::Real gaminv = 1.0_rt/std::sqrt(1.0_rt + uxp[ip]*uxp[ip]*clightsq
139 + uyp[ip]*uyp[ip]*clightsq
140 + uzp[ip]*uzp[ip]*clightsq);
141 amrex::Real wq = q*wp[ip];
146 amrex::ParticleReal xp, yp, zp;
147 GetPosition(ip, xp, yp, zp);
149 const amrex::Real vx = uxp[ip]*gaminv;
150 const amrex::Real vy = uyp[ip]*gaminv;
151 const amrex::Real vz = uzp[ip]*gaminv;
153 #if defined(WARPX_DIM_RZ)
156 const amrex::Real xpmid = xp + relative_time*vx;
157 const amrex::Real ypmid = yp + relative_time*vy;
158 const amrex::Real rpmid = std::sqrt(xpmid*xpmid + ypmid*ypmid);
159 amrex::Real costheta;
160 amrex::Real sintheta;
162 costheta = xpmid/rpmid;
163 sintheta = ypmid/rpmid;
169 const amrex::Real wqx = wq*invvol*(+vx*costheta + vy*sintheta);
170 const amrex::Real wqy = wq*invvol*(-vx*sintheta + vy*costheta);
172 const amrex::Real wqx = wq*invvol*vx;
173 const amrex::Real wqy = wq*invvol*vy;
175 const amrex::Real wqz = wq*invvol*vz;
179 #if (AMREX_SPACEDIM >= 2)
182 #if defined(WARPX_DIM_RZ)
184 const double xmid = (rpmid -
xmin)*dxi;
186 const double xmid = ((xp -
xmin) + relative_time*vx)*dxi;
193 double sx_node[depos_order + 1] = {0.};
194 double sx_cell[depos_order + 1] = {0.};
197 if (jx_type[0] ==
NODE || jy_type[0] ==
NODE || jz_type[0] ==
NODE) {
198 j_node = compute_shape_factor(sx_node, xmid);
200 if (jx_type[0] == CELL || jy_type[0] == CELL || jz_type[0] == CELL) {
201 j_cell = compute_shape_factor(sx_cell, xmid - 0.5);
204 amrex::Real sx_jx[depos_order + 1] = {0._rt};
205 amrex::Real sx_jy[depos_order + 1] = {0._rt};
206 amrex::Real sx_jz[depos_order + 1] = {0._rt};
207 for (
int ix=0; ix<=depos_order; ix++)
209 sx_jx[ix] = ((jx_type[0] ==
NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
210 sx_jy[ix] = ((jy_type[0] ==
NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
211 sx_jz[ix] = ((jz_type[0] ==
NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
214 int const j_jx = ((jx_type[0] ==
NODE) ? j_node : j_cell);
215 int const j_jy = ((jy_type[0] ==
NODE) ? j_node : j_cell);
216 int const j_jz = ((jz_type[0] ==
NODE) ? j_node : j_cell);
219 #if defined(WARPX_DIM_3D)
222 const double ymid = ((yp - ymin) + relative_time*vy)*dyi;
223 double sy_node[depos_order + 1] = {0.};
224 double sy_cell[depos_order + 1] = {0.};
227 if (jx_type[1] ==
NODE || jy_type[1] ==
NODE || jz_type[1] ==
NODE) {
228 k_node = compute_shape_factor(sy_node, ymid);
230 if (jx_type[1] == CELL || jy_type[1] == CELL || jz_type[1] == CELL) {
231 k_cell = compute_shape_factor(sy_cell, ymid - 0.5);
233 amrex::Real sy_jx[depos_order + 1] = {0._rt};
234 amrex::Real sy_jy[depos_order + 1] = {0._rt};
235 amrex::Real sy_jz[depos_order + 1] = {0._rt};
236 for (
int iy=0; iy<=depos_order; iy++)
238 sy_jx[iy] = ((jx_type[1] ==
NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
239 sy_jy[iy] = ((jy_type[1] ==
NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
240 sy_jz[iy] = ((jz_type[1] ==
NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
242 int const k_jx = ((jx_type[1] ==
NODE) ? k_node : k_cell);
243 int const k_jy = ((jy_type[1] ==
NODE) ? k_node : k_cell);
244 int const k_jz = ((jz_type[1] ==
NODE) ? k_node : k_cell);
249 const double zmid = ((zp - zmin) + relative_time*vz)*dzi;
250 double sz_node[depos_order + 1] = {0.};
251 double sz_cell[depos_order + 1] = {0.};
254 if (jx_type[zdir] ==
NODE || jy_type[zdir] ==
NODE || jz_type[zdir] ==
NODE) {
255 l_node = compute_shape_factor(sz_node, zmid);
257 if (jx_type[zdir] == CELL || jy_type[zdir] == CELL || jz_type[zdir] == CELL) {
258 l_cell = compute_shape_factor(sz_cell, zmid - 0.5);
260 amrex::Real sz_jx[depos_order + 1] = {0._rt};
261 amrex::Real sz_jy[depos_order + 1] = {0._rt};
262 amrex::Real sz_jz[depos_order + 1] = {0._rt};
263 for (
int iz=0; iz<=depos_order; iz++)
265 sz_jx[iz] = ((jx_type[zdir] ==
NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
266 sz_jy[iz] = ((jy_type[zdir] ==
NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
267 sz_jz[iz] = ((jz_type[zdir] ==
NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
269 int const l_jx = ((jx_type[zdir] ==
NODE) ? l_node : l_cell);
270 int const l_jy = ((jy_type[zdir] ==
NODE) ? l_node : l_cell);
271 int const l_jz = ((jz_type[zdir] ==
NODE) ? l_node : l_cell);
274 #if defined(WARPX_DIM_1D_Z)
275 for (
int iz=0; iz<=depos_order; iz++){
277 &jx_arr(lo.
x+l_jx+iz, 0, 0, 0),
280 &jy_arr(lo.
x+l_jy+iz, 0, 0, 0),
283 &jz_arr(lo.
x+l_jz+iz, 0, 0, 0),
287 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
288 for (
int iz=0; iz<=depos_order; iz++){
289 for (
int ix=0; ix<=depos_order; ix++){
291 &jx_arr(lo.
x+j_jx+ix, lo.
y+l_jx+iz, 0, 0),
292 sx_jx[ix]*sz_jx[iz]*wqx);
294 &jy_arr(lo.
x+j_jy+ix, lo.
y+l_jy+iz, 0, 0),
295 sx_jy[ix]*sz_jy[iz]*wqy);
297 &jz_arr(lo.
x+j_jz+ix, lo.
y+l_jz+iz, 0, 0),
298 sx_jz[ix]*sz_jz[iz]*wqz);
299 #if defined(WARPX_DIM_RZ)
301 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
314 #elif defined(WARPX_DIM_3D)
315 for (
int iz=0; iz<=depos_order; iz++){
316 for (
int iy=0; iy<=depos_order; iy++){
317 for (
int ix=0; ix<=depos_order; ix++){
319 &jx_arr(lo.
x+j_jx+ix, lo.
y+k_jx+iy, lo.
z+l_jx+iz),
320 sx_jx[ix]*sy_jx[iy]*sz_jx[iz]*wqx);
322 &jy_arr(lo.
x+j_jy+ix, lo.
y+k_jy+iy, lo.
z+l_jy+iz),
323 sx_jy[ix]*sy_jy[iy]*sz_jy[iz]*wqy);
325 &jz_arr(lo.
x+j_jz+ix, lo.
y+k_jz+iy, lo.
z+l_jz+iz),
326 sx_jz[ix]*sy_jz[iy]*sz_jz[iz]*wqz);
333 #if defined(WARPX_USE_GPUCLOCK)
367 template <
int depos_order>
369 const amrex::ParticleReal *
const wp,
370 const amrex::ParticleReal *
const uxp,
371 const amrex::ParticleReal *
const uyp,
372 const amrex::ParticleReal *
const uzp,
378 const amrex::Real relative_time,
379 const std::array<amrex::Real,3>&
dx,
380 const std::array<amrex::Real,3>& xyzmin,
383 int n_rz_azimuthal_modes,
385 long load_balance_costs_update_algo,
391 using namespace amrex::literals;
393 #if defined(AMREX_USE_HIP) || defined(AMREX_USE_CUDA)
394 using namespace amrex;
405 constexpr
int zdir = WARPX_ZINDEX;
410 #if defined(WARPX_USE_GPUCLOCK)
411 amrex::Real* cost_real =
nullptr;
419 const auto domain = geom.
Domain();
422 sample_tbox.
grow(depos_order);
430 const int nblocks = a_bins.
numBins();
434 const std::size_t shared_mem_bytes = npts*
sizeof(amrex::Real);
438 "Tile size too big for GPU shared memory current deposition");
445 #if defined(WARPX_USE_GPUCLOCK)
450 const int bin_id = blockIdx.x;
451 const unsigned int bin_start = offsets_ptr[bin_id];
452 const unsigned int bin_stop = offsets_ptr[bin_id+1];
454 if (bin_start == bin_stop) {
return; }
459 ParticleReal xp, yp, zp;
460 GetPosition(permutation[bin_start], xp, yp, zp);
461 #if defined(WARPX_DIM_3D)
462 IntVect iv =
IntVect(
int( amrex::Math::floor((xp-plo[0]) * dxiarr[0]) ),
463 int( amrex::Math::floor((yp-plo[1]) * dxiarr[1]) ),
464 int( amrex::Math::floor((zp-plo[2]) * dxiarr[2]) ));
465 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
466 IntVect iv =
IntVect(
int( amrex::Math::floor((xp-plo[0]) * dxiarr[0]) ),
467 int( amrex::Math::floor((zp-plo[1]) * dxiarr[1]) ));
468 #elif defined(WARPX_DIM_1D_Z)
469 IntVect iv =
IntVect(
int( amrex::Math::floor((zp-plo[0]) * dxiarr[0]) ));
471 iv += domain.smallEnd();
475 buffer_box.
grow(depos_order);
481 amrex::Real*
const shared = gsm.
dataPtr();
491 volatile amrex::Real* vs = shared;
492 for (
int i = threadIdx.x;
i < npts;
i += blockDim.x){
496 for (
unsigned int ip_orig = bin_start+threadIdx.x; ip_orig<bin_stop; ip_orig += blockDim.x)
498 const unsigned int ip = permutation[ip_orig];
499 depositComponent<depos_order>(GetPosition, wp, uxp, uyp, uzp, ion_lev, jx_buff, jx_type,
500 relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes,
501 ip, zdir,
NODE, CELL, 0);
505 addLocalToGlobal(tbox_x, jx_arr, jx_buff);
506 for (
int i = threadIdx.x;
i < npts;
i += blockDim.x){
511 for (
unsigned int ip_orig = bin_start+threadIdx.x; ip_orig<bin_stop; ip_orig += blockDim.x)
513 const unsigned int ip = permutation[ip_orig];
514 depositComponent<depos_order>(GetPosition, wp, uxp, uyp, uzp, ion_lev, jy_buff, jy_type,
515 relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes,
516 ip, zdir,
NODE, CELL, 1);
520 addLocalToGlobal(tbox_y, jy_arr, jy_buff);
521 for (
int i = threadIdx.x;
i < npts;
i += blockDim.x){
526 for (
unsigned int ip_orig = bin_start+threadIdx.x; ip_orig<bin_stop; ip_orig += blockDim.x)
528 const unsigned int ip = permutation[ip_orig];
529 depositComponent<depos_order>(GetPosition, wp, uxp, uyp, uzp, ion_lev, jz_buff, jz_type,
530 relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes,
531 ip, zdir,
NODE, CELL, 2);
535 addLocalToGlobal(tbox_z, jz_arr, jz_buff);
537 #if defined(WARPX_USE_GPUCLOCK)
548 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);
579 template <
int depos_order>
581 const amrex::ParticleReal *
const wp,
582 const amrex::ParticleReal *
const uxp,
583 const amrex::ParticleReal *
const uyp,
584 const amrex::ParticleReal *
const uzp,
591 amrex::Real relative_time,
592 const std::array<amrex::Real,3>&
dx,
593 std::array<amrex::Real, 3> xyzmin,
596 int n_rz_azimuthal_modes,
597 amrex::Real *
const cost,
598 long load_balance_costs_update_algo)
600 using namespace amrex;
601 using namespace amrex::literals;
603 #if !defined(WARPX_DIM_RZ)
607 #if !defined(AMREX_USE_GPU)
613 bool const do_ionization = ion_lev;
614 #if !defined(WARPX_DIM_1D_Z)
615 Real
const dxi = 1.0_rt /
dx[0];
617 #if !defined(WARPX_DIM_1D_Z)
618 Real
const xmin = xyzmin[0];
620 #if defined(WARPX_DIM_3D)
621 Real
const dyi = 1.0_rt /
dx[1];
622 Real
const ymin = xyzmin[1];
624 Real
const dzi = 1.0_rt /
dx[2];
625 Real
const zmin = xyzmin[2];
627 #if defined(WARPX_DIM_3D)
628 Real
const invdtdx = 1.0_rt / (
dt*
dx[1]*
dx[2]);
629 Real
const invdtdy = 1.0_rt / (
dt*
dx[0]*
dx[2]);
630 Real
const invdtdz = 1.0_rt / (
dt*
dx[0]*
dx[1]);
631 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
632 Real
const invdtdx = 1.0_rt / (
dt*
dx[2]);
633 Real
const invdtdz = 1.0_rt / (
dt*
dx[0]);
634 Real
const invvol = 1.0_rt / (
dx[0]*
dx[2]);
635 #elif defined(WARPX_DIM_1D_Z)
636 Real
const invdtdz = 1.0_rt / (
dt*
dx[0]);
637 Real
const invvol = 1.0_rt / (
dx[2]);
640 #if defined(WARPX_DIM_RZ)
645 #if !defined(WARPX_DIM_1D_Z)
646 Real constexpr one_third = 1.0_rt / 3.0_rt;
647 Real constexpr one_sixth = 1.0_rt / 6.0_rt;
651 #if defined(WARPX_USE_GPUCLOCK)
652 amrex::Real* cost_real =
nullptr;
661 #if defined(WARPX_USE_GPUCLOCK)
668 Real
const gaminv = 1.0_rt/std::sqrt(1.0_rt + uxp[ip]*uxp[ip]*clightsq
669 + uyp[ip]*uyp[ip]*clightsq
670 + uzp[ip]*uzp[ip]*clightsq);
678 ParticleReal xp, yp, zp;
679 GetPosition(ip, xp, yp, zp);
681 #if !defined(WARPX_DIM_1D_Z)
682 Real
const wqx = wq*invdtdx;
684 #if defined(WARPX_DIM_3D)
685 Real
const wqy = wq*invdtdy;
687 Real
const wqz = wq*invdtdz;
690 #if defined(WARPX_DIM_RZ)
691 Real
const xp_new = xp + (relative_time + 0.5_rt*
dt)*uxp[ip]*gaminv;
692 Real
const yp_new = yp + (relative_time + 0.5_rt*
dt)*uyp[ip]*gaminv;
693 Real
const xp_mid = xp_new - 0.5_rt*
dt*uxp[ip]*gaminv;
694 Real
const yp_mid = yp_new - 0.5_rt*
dt*uyp[ip]*gaminv;
695 Real
const xp_old = xp_new -
dt*uxp[ip]*gaminv;
696 Real
const yp_old = yp_new -
dt*uyp[ip]*gaminv;
697 Real
const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new);
698 Real
const rp_mid = std::sqrt(xp_mid*xp_mid + yp_mid*yp_mid);
699 Real
const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old);
700 Real costheta_new, sintheta_new;
701 if (rp_new > 0._rt) {
702 costheta_new = xp_new/rp_new;
703 sintheta_new = yp_new/rp_new;
705 costheta_new = 1._rt;
706 sintheta_new = 0._rt;
708 amrex::Real costheta_mid, sintheta_mid;
709 if (rp_mid > 0._rt) {
710 costheta_mid = xp_mid/rp_mid;
711 sintheta_mid = yp_mid/rp_mid;
713 costheta_mid = 1._rt;
714 sintheta_mid = 0._rt;
716 amrex::Real costheta_old, sintheta_old;
717 if (rp_old > 0._rt) {
718 costheta_old = xp_old/rp_old;
719 sintheta_old = yp_old/rp_old;
721 costheta_old = 1._rt;
722 sintheta_old = 0._rt;
728 double const x_new = (rp_new -
xmin)*dxi;
729 double const x_old = (rp_old -
xmin)*dxi;
731 #if !defined(WARPX_DIM_1D_Z)
733 double const x_new = (xp -
xmin + (relative_time + 0.5_rt*
dt)*uxp[ip]*gaminv)*dxi;
734 double const x_old = x_new -
dt*dxi*uxp[ip]*gaminv;
737 #if defined(WARPX_DIM_3D)
739 double const y_new = (yp - ymin + (relative_time + 0.5_rt*
dt)*uyp[ip]*gaminv)*dyi;
740 double const y_old = y_new -
dt*dyi*uyp[ip]*gaminv;
743 double const z_new = (zp - zmin + (relative_time + 0.5_rt*
dt)*uzp[ip]*gaminv)*dzi;
744 double const z_old = z_new -
dt*dzi*uzp[ip]*gaminv;
746 #if defined(WARPX_DIM_RZ)
747 Real
const vy = (-uxp[ip]*sintheta_mid + uyp[ip]*costheta_mid)*gaminv;
748 #elif defined(WARPX_DIM_XZ)
749 Real
const vy = uyp[ip]*gaminv;
750 #elif defined(WARPX_DIM_1D_Z)
751 Real
const vx = uxp[ip]*gaminv;
752 Real
const vy = uyp[ip]*gaminv;
760 #if !defined(WARPX_DIM_1D_Z)
761 double sx_new[depos_order + 3] = {0.};
762 double sx_old[depos_order + 3] = {0.};
764 #if defined(WARPX_DIM_3D)
766 double sy_new[depos_order + 3] = {0.};
767 double sy_old[depos_order + 3] = {0.};
770 double sz_new[depos_order + 3] = {0.};
771 double sz_old[depos_order + 3] = {0.};
779 #if !defined(WARPX_DIM_1D_Z)
780 const int i_new = compute_shape_factor(sx_new+1, x_new);
781 const int i_old = compute_shifted_shape_factor(sx_old, x_old, i_new);
783 #if defined(WARPX_DIM_3D)
784 const int j_new = compute_shape_factor(sy_new+1, y_new);
785 const int j_old = compute_shifted_shape_factor(sy_old, y_old, j_new);
787 const int k_new = compute_shape_factor(sz_new+1, z_new);
788 const int k_old = compute_shifted_shape_factor(sz_old, z_old, k_new);
791 #if !defined(WARPX_DIM_1D_Z)
792 int dil = 1, diu = 1;
793 if (i_old < i_new) dil = 0;
794 if (i_old > i_new) diu = 0;
796 #if defined(WARPX_DIM_3D)
797 int djl = 1, dju = 1;
798 if (j_old < j_new) djl = 0;
799 if (j_old > j_new) dju = 0;
801 int dkl = 1, dku = 1;
802 if (k_old < k_new) dkl = 0;
803 if (k_old > k_new) dku = 0;
805 #if defined(WARPX_DIM_3D)
807 for (
int k=dkl; k<=depos_order+2-dku; k++) {
808 for (
int j=djl; j<=depos_order+2-dju; j++) {
809 amrex::Real sdxi = 0._rt;
810 for (
int i=dil;
i<=depos_order+1-diu;
i++) {
811 sdxi += wqx*(sx_old[
i] - sx_new[
i])*(
812 one_third*(sy_new[j]*sz_new[k] + sy_old[j]*sz_old[k])
813 +one_sixth*(sy_new[j]*sz_old[k] + sy_old[j]*sz_new[k]));
818 for (
int k=dkl; k<=depos_order+2-dku; k++) {
819 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
820 amrex::Real sdyj = 0._rt;
821 for (
int j=djl; j<=depos_order+1-dju; j++) {
822 sdyj += wqy*(sy_old[j] - sy_new[j])*(
823 one_third*(sx_new[
i]*sz_new[k] + sx_old[
i]*sz_old[k])
824 +one_sixth*(sx_new[
i]*sz_old[k] + sx_old[
i]*sz_new[k]));
829 for (
int j=djl; j<=depos_order+2-dju; j++) {
830 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
831 amrex::Real sdzk = 0._rt;
832 for (
int k=dkl; k<=depos_order+1-dku; k++) {
833 sdzk += wqz*(sz_old[k] - sz_new[k])*(
834 one_third*(sx_new[
i]*sy_new[j] + sx_old[
i]*sy_old[j])
835 +one_sixth*(sx_new[
i]*sy_old[j] + sx_old[
i]*sy_new[j]));
841 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
843 for (
int k=dkl; k<=depos_order+2-dku; k++) {
844 amrex::Real sdxi = 0._rt;
845 for (
int i=dil;
i<=depos_order+1-diu;
i++) {
846 sdxi += wqx*(sx_old[
i] - sx_new[
i])*0.5_rt*(sz_new[k] + sz_old[k]);
848 #if defined(WARPX_DIM_RZ)
850 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
852 const Complex djr_cmplx = 2._rt *sdxi*xy_mid;
855 xy_mid = xy_mid*xy_mid0;
860 for (
int k=dkl; k<=depos_order+2-dku; k++) {
861 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
862 Real
const sdyj = wq*vy*invvol*(
863 one_third*(sx_new[
i]*sz_new[k] + sx_old[
i]*sz_old[k])
864 +one_sixth*(sx_new[
i]*sz_old[k] + sx_old[
i]*sz_new[k]));
866 #if defined(WARPX_DIM_RZ)
871 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
874 const Complex djt_cmplx = -2._rt * I*(i_new-1 +
i +
xmin*dxi)*wq*invdtdx/(amrex::Real)imode
875 *(
Complex(sx_new[
i]*sz_new[k], 0._rt)*(xy_new - xy_mid)
876 +
Complex(sx_old[
i]*sz_old[k], 0._rt)*(xy_mid - xy_old));
879 xy_new = xy_new*xy_new0;
880 xy_mid = xy_mid*xy_mid0;
881 xy_old = xy_old*xy_old0;
886 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
888 for (
int k=dkl; k<=depos_order+1-dku; k++) {
889 sdzk += wqz*(sz_old[k] - sz_new[k])*0.5_rt*(sx_new[
i] + sx_old[
i]);
891 #if defined(WARPX_DIM_RZ)
893 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
895 const Complex djz_cmplx = 2._rt * sdzk * xy_mid;
898 xy_mid = xy_mid*xy_mid0;
903 #elif defined(WARPX_DIM_1D_Z)
905 for (
int k=dkl; k<=depos_order+2-dku; k++) {
906 amrex::Real
const sdxi = wq*vx*invvol*0.5_rt*(sz_old[k] + sz_new[k]);
909 for (
int k=dkl; k<=depos_order+2-dku; k++) {
910 amrex::Real
const sdyj = wq*vy*invvol*0.5_rt*(sz_old[k] + sz_new[k]);
913 amrex::Real sdzk = 0._rt;
914 for (
int k=dkl; k<=depos_order+1-dku; k++) {
915 sdzk += wqz*(sz_old[k] - sz_new[k]);
921 #if defined(WARPX_USE_GPUCLOCK)
959 template <
int depos_order>
961 const amrex::ParticleReal*
const wp,
962 const amrex::ParticleReal*
const uxp,
963 const amrex::ParticleReal*
const uyp,
964 const amrex::ParticleReal*
const uzp,
965 const int*
const ion_lev,
971 amrex::Real relative_time,
972 const std::array<amrex::Real,3>&
dx,
973 const std::array<amrex::Real,3>& xyzmin,
976 int n_rz_azimuthal_modes,
978 long load_balance_costs_update_algo)
980 using namespace amrex::literals;
982 #if defined(WARPX_DIM_RZ)
984 wp, uxp, uyp, uzp, ion_lev, Dx_fab, Dy_fab, Dz_fab,
985 np_to_depose,
dt, relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes);
989 #if defined(WARPX_DIM_1D_Z)
991 wp, uxp, uyp, uzp, ion_lev, Dx_fab, Dy_fab, Dz_fab,
992 np_to_depose,
dt, relative_time,
dx, xyzmin, lo, q, n_rz_azimuthal_modes);
996 #if !defined(WARPX_USE_GPUCLOCK)
1000 #if !(defined WARPX_DIM_RZ || defined WARPX_DIM_1D_Z)
1004 const bool do_ionization = ion_lev;
1007 const amrex::Real dxi = 1._rt /
dx[0];
1008 const amrex::Real dzi = 1._rt /
dx[2];
1009 #if defined(WARPX_DIM_3D)
1010 const amrex::Real dyi = 1._rt /
dx[1];
1014 const amrex::Real invdt = 1._rt /
dt;
1017 #if defined(WARPX_DIM_XZ)
1018 const amrex::Real invvol = dxi * dzi;
1019 #elif defined(WARPX_DIM_3D)
1020 const amrex::Real invvol = dxi * dyi * dzi;
1024 const amrex::Real
xmin = xyzmin[0];
1025 const amrex::Real zmin = xyzmin[2];
1026 #if defined(WARPX_DIM_3D)
1027 const amrex::Real ymin = xyzmin[1];
1031 #if defined(WARPX_DIM_3D)
1034 #elif defined(WARPX_DIM_XZ)
1050 #if defined(WARPX_USE_GPUCLOCK)
1051 amrex::Real* cost_real =
nullptr;
1059 #if defined(WARPX_USE_GPUCLOCK)
1066 const amrex::Real invgam = 1._rt / std::sqrt(1._rt + uxp[ip] * uxp[ip] * invcsq
1067 + uyp[ip] * uyp[ip] * invcsq
1068 + uzp[ip] * uzp[ip] * invcsq);
1070 amrex::Real wq = q * wp[ip];
1071 if (do_ionization) wq *= ion_lev[ip];
1074 amrex::ParticleReal xp, yp, zp;
1075 GetPosition(ip, xp, yp, zp);
1078 const amrex::Real vx = uxp[ip] * invgam;
1079 const amrex::Real vy = uyp[ip] * invgam;
1080 const amrex::Real vz = uzp[ip] * invgam;
1083 xp += relative_time * vx;
1084 yp += relative_time * vy;
1085 zp += relative_time * vz;
1088 #if defined(WARPX_DIM_XZ)
1089 const amrex::Real wqy = wq * vy * invvol;
1094 double const x_new = (xp -
xmin + 0.5_rt*
dt*vx) * dxi;
1095 double const x_old = (xp -
xmin - 0.5_rt*
dt*vx) * dxi;
1096 #if defined(WARPX_DIM_3D)
1098 double const y_new = (yp - ymin + 0.5_rt*
dt*vy) * dyi;
1099 double const y_old = (yp - ymin - 0.5_rt*
dt*vy) * dyi;
1102 double const z_new = (zp - zmin + 0.5_rt*
dt*vz) * dzi;
1103 double const z_old = (zp - zmin - 0.5_rt*
dt*vz) * dzi;
1107 double sx_new[depos_order+1] = {0.};
1108 double sx_old[depos_order+1] = {0.};
1109 #if defined(WARPX_DIM_3D)
1111 double sy_new[depos_order+1] = {0.};
1112 double sy_old[depos_order+1] = {0.};
1115 double sz_new[depos_order+1] = {0.};
1116 double sz_old[depos_order+1] = {0.};
1123 const int i_new = compute_shape_factor(sx_new, x_new);
1124 #if defined(WARPX_DIM_3D)
1127 const int j_new = compute_shape_factor(sy_new, y_new);
1131 const int k_new = compute_shape_factor(sz_new, z_new);
1137 const int i_old = compute_shape_factor(sx_old, x_old);
1138 #if defined(WARPX_DIM_3D)
1141 const int j_old = compute_shape_factor(sy_old, y_old);
1145 const int k_old = compute_shape_factor(sz_old, z_old);
1148 #if defined(WARPX_DIM_XZ)
1150 for (
int k=0; k<=depos_order; k++) {
1151 for (
int i=0;
i<=depos_order;
i++) {
1155 auto const sxn_szn =
static_cast<amrex::Real
>(sx_new[
i] * sz_new[k]);
1156 auto const sxo_szn =
static_cast<amrex::Real
>(sx_old[
i] * sz_new[k]);
1157 auto const sxn_szo =
static_cast<amrex::Real
>(sx_new[
i] * sz_old[k]);
1158 auto const sxo_szo =
static_cast<amrex::Real
>(sx_old[
i] * sz_old[k]);
1160 if (i_new == i_old && k_new == k_old) {
1163 wq * invvol * invdt * (sxn_szn - sxo_szo));
1166 wq * invvol * invdt * (sxn_szo - sxo_szn));
1170 wqy * 0.25_rt * (sxn_szn + sxn_szo + sxo_szn + sxo_szo));
1174 wq * invvol * invdt * sxn_szn);
1177 - wq * invvol * invdt * sxo_szo);
1180 wq * invvol * invdt * sxn_szo);
1183 - wq * invvol * invdt * sxo_szn);
1187 wqy * 0.25_rt * sxn_szn);
1190 wqy * 0.25_rt * sxn_szo);
1193 wqy * 0.25_rt * sxo_szn);
1196 wqy * 0.25_rt * sxo_szo);
1202 #elif defined(WARPX_DIM_3D)
1204 for (
int k=0; k<=depos_order; k++) {
1205 for (
int j=0; j<=depos_order; j++) {
1207 auto const syn_szn =
static_cast<amrex::Real
>(sy_new[j] * sz_new[k]);
1208 auto const syo_szn =
static_cast<amrex::Real
>(sy_old[j] * sz_new[k]);
1209 auto const syn_szo =
static_cast<amrex::Real
>(sy_new[j] * sz_old[k]);
1210 auto const syo_szo =
static_cast<amrex::Real
>(sy_old[j] * sz_old[k]);
1212 for (
int i=0;
i<=depos_order;
i++) {
1214 auto const sxn_syn_szn =
static_cast<amrex::Real
>(sx_new[
i]) * syn_szn;
1215 auto const sxo_syn_szn =
static_cast<amrex::Real
>(sx_old[
i]) * syn_szn;
1216 auto const sxn_syo_szn =
static_cast<amrex::Real
>(sx_new[
i]) * syo_szn;
1217 auto const sxo_syo_szn =
static_cast<amrex::Real
>(sx_old[
i]) * syo_szn;
1218 auto const sxn_syn_szo =
static_cast<amrex::Real
>(sx_new[
i]) * syn_szo;
1219 auto const sxo_syn_szo =
static_cast<amrex::Real
>(sx_old[
i]) * syn_szo;
1220 auto const sxn_syo_szo =
static_cast<amrex::Real
>(sx_new[
i]) * syo_szo;
1221 auto const sxo_syo_szo =
static_cast<amrex::Real
>(sx_old[
i]) * syo_szo;
1223 if (i_new == i_old && j_new == j_old && k_new == k_old) {
1226 wq * invvol * invdt * (sxn_syn_szn - sxo_syo_szo));
1229 wq * invvol * invdt * (sxn_syn_szo - sxo_syo_szn));
1232 wq * invvol * invdt * (sxn_syo_szn - sxo_syn_szo));
1235 wq * invvol * invdt * (sxo_syn_szn - sxn_syo_szo));
1239 wq * invvol * invdt * sxn_syn_szn);
1242 - wq * invvol * invdt * sxo_syo_szo);
1245 wq * invvol * invdt * sxn_syn_szo);
1248 - wq * invvol * invdt * sxo_syo_szn);
1251 wq * invvol * invdt * sxn_syo_szn);
1254 - wq * invvol * invdt * sxo_syn_szo);
1257 wq * invvol * invdt * sxo_syn_szn);
1260 - wq * invvol * invdt * sxn_syo_szo);
1268 #if defined(WARPX_DIM_3D)
1271 const amrex::Real t_a = temp_arr(
i,j,k,0);
1272 const amrex::Real t_b = temp_arr(
i,j,k,1);
1273 const amrex::Real t_c = temp_arr(
i,j,k,2);
1274 const amrex::Real t_d = temp_arr(
i,j,k,3);
1275 Dx_arr(
i,j,k) += (1._rt/6._rt)*(2_rt*t_a + t_b + t_c - 2._rt*t_d);
1276 Dy_arr(
i,j,k) += (1._rt/6._rt)*(2_rt*t_a + t_b - 2._rt*t_c + t_d);
1277 Dz_arr(
i,j,k) += (1._rt/6._rt)*(2_rt*t_a - 2._rt*t_b + t_c + t_d);
1279 #elif defined(WARPX_DIM_XZ)
1282 const amrex::Real t_a = temp_arr(
i,j,0,0);
1283 const amrex::Real t_b = temp_arr(
i,j,0,1);
1284 Dx_arr(
i,j,0) += (0.5_rt)*(t_a + t_b);
1285 Dz_arr(
i,j,0) += (0.5_rt)*(t_a - t_b);
1292 # if defined(WARPX_USE_GPUCLOCK)
1295 *cost += *cost_real;
#define AMREX_ALWAYS_ASSERT(EX)
#define AMREX_D_DECL(a, b, c)
void doDepositionShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *ion_lev, amrex::FArrayBox &jx_fab, amrex::FArrayBox &jy_fab, amrex::FArrayBox &jz_fab, long np_to_depose, amrex::Real relative_time, const std::array< amrex::Real, 3 > &dx, const std::array< amrex::Real, 3 > &xyzmin, amrex::Dim3 lo, amrex::Real q, int n_rz_azimuthal_modes, amrex::Real *cost, long load_balance_costs_update_algo)
Current Deposition for thread thread_num.
Definition: CurrentDeposition.H:54
void doEsirkepovDepositionShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *ion_lev, const amrex::Array4< amrex::Real > &Jx_arr, const amrex::Array4< amrex::Real > &Jy_arr, const amrex::Array4< amrex::Real > &Jz_arr, long np_to_depose, amrex::Real dt, amrex::Real relative_time, const std::array< amrex::Real, 3 > &dx, std::array< amrex::Real, 3 > xyzmin, amrex::Dim3 lo, amrex::Real q, int n_rz_azimuthal_modes, amrex::Real *const cost, long load_balance_costs_update_algo)
Esirkepov Current Deposition for thread thread_num.
Definition: CurrentDeposition.H:580
void doVayDepositionShapeN(const GetParticlePosition< PIdx > &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, long np_to_depose, amrex::Real dt, amrex::Real relative_time, const std::array< amrex::Real, 3 > &dx, const std::array< amrex::Real, 3 > &xyzmin, amrex::Dim3 lo, amrex::Real q, int n_rz_azimuthal_modes, amrex::Real *cost, 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:960
void doDepositionSharedShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const amrex::ParticleReal *const uxp, const amrex::ParticleReal *const uyp, const amrex::ParticleReal *const uzp, const int *ion_lev, amrex::FArrayBox &jx_fab, amrex::FArrayBox &jy_fab, amrex::FArrayBox &jz_fab, long np_to_depose, const amrex::Real relative_time, const std::array< amrex::Real, 3 > &dx, const std::array< amrex::Real, 3 > &xyzmin, amrex::Dim3 lo, amrex::Real q, int n_rz_azimuthal_modes, amrex::Real *cost, 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:368
#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:243
static int shared_mem_current_tpb
number of threads to use per block in shared deposition
Definition: WarpX.H:240
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:442
tuple dx
lab frame
Definition: stencil.py:429
xmin
Definition: stencil.py:424
Definition: ShapeFactors.H:29
Definition: ShapeFactors.H:84
@ 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