8 #ifndef CURRENTDEPOSITION_H_ 9 #define CURRENTDEPOSITION_H_ 51 template <
int depos_order>
53 const amrex::ParticleReal *
const wp,
54 const amrex::ParticleReal *
const uxp,
55 const amrex::ParticleReal *
const uyp,
56 const amrex::ParticleReal *
const uzp,
57 const int *
const ion_lev,
61 const long np_to_depose,
62 const amrex::Real relative_time,
63 const std::array<amrex::Real,3>&
dx,
64 const std::array<amrex::Real,3>& xyzmin,
67 const int n_rz_azimuthal_modes,
69 const long load_balance_costs_update_algo)
71 #if !defined(WARPX_DIM_RZ) 75 #if !defined(AMREX_USE_GPU) 81 const bool do_ionization = ion_lev;
82 const amrex::Real dzi = 1.0_rt/dx[2];
83 #if defined(WARPX_DIM_1D_Z) 84 const amrex::Real invvol = dzi;
86 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) 87 const amrex::Real dxi = 1.0_rt/dx[0];
88 const amrex::Real invvol = dxi*dzi;
89 #elif defined(WARPX_DIM_3D) 90 const amrex::Real dxi = 1.0_rt/dx[0];
91 const amrex::Real dyi = 1.0_rt/dx[1];
92 const amrex::Real invvol = dxi*dyi*dzi;
95 #if (AMREX_SPACEDIM >= 2) 96 const amrex::Real xmin = xyzmin[0];
98 #if defined(WARPX_DIM_3D) 99 const amrex::Real ymin = xyzmin[1];
101 const amrex::Real zmin = xyzmin[2];
112 constexpr
int zdir = WARPX_ZINDEX;
117 #if defined(WARPX_USE_GPUCLOCK) 118 amrex::Real* cost_real =
nullptr;
127 #if defined(WARPX_USE_GPUCLOCK) 128 KernelTimer kernelTimer(cost && load_balance_costs_update_algo
133 const amrex::Real gaminv = 1.0_rt/std::sqrt(1.0_rt + uxp[ip]*uxp[ip]*clightsq
134 + uyp[ip]*uyp[ip]*clightsq
135 + uzp[ip]*uzp[ip]*clightsq);
136 amrex::Real wq = q*wp[ip];
141 amrex::ParticleReal xp, yp, zp;
142 GetPosition(ip, xp, yp, zp);
144 const amrex::Real vx = uxp[ip]*gaminv;
145 const amrex::Real vy = uyp[ip]*gaminv;
146 const amrex::Real vz = uzp[ip]*gaminv;
148 #if defined(WARPX_DIM_RZ) 151 const amrex::Real xpmid = xp + relative_time*vx;
152 const amrex::Real ypmid = yp + relative_time*vy;
153 const amrex::Real rpmid = std::sqrt(xpmid*xpmid + ypmid*ypmid);
154 amrex::Real costheta;
155 amrex::Real sintheta;
157 costheta = xpmid/rpmid;
158 sintheta = ypmid/rpmid;
164 const amrex::Real wqx = wq*invvol*(+vx*costheta + vy*sintheta);
165 const amrex::Real wqy = wq*invvol*(-vx*sintheta + vy*costheta);
167 const amrex::Real wqx = wq*invvol*vx;
168 const amrex::Real wqy = wq*invvol*vy;
170 const amrex::Real wqz = wq*invvol*vz;
174 #if (AMREX_SPACEDIM >= 2) 177 #if defined(WARPX_DIM_RZ) 179 const double xmid = (rpmid - xmin)*dxi;
181 const double xmid = ((xp - xmin) + relative_time*vx)*dxi;
188 double sx_node[depos_order + 1] = {0.};
189 double sx_cell[depos_order + 1] = {0.};
192 if (jx_type[0] == NODE || jy_type[0] == NODE || jz_type[0] == NODE) {
193 j_node = compute_shape_factor(sx_node, xmid);
195 if (jx_type[0] == CELL || jy_type[0] == CELL || jz_type[0] == CELL) {
196 j_cell = compute_shape_factor(sx_cell, xmid - 0.5);
199 amrex::Real sx_jx[depos_order + 1] = {0._rt};
200 amrex::Real sx_jy[depos_order + 1] = {0._rt};
201 amrex::Real sx_jz[depos_order + 1] = {0._rt};
202 for (
int ix=0; ix<=depos_order; ix++)
204 sx_jx[ix] = ((jx_type[0] == NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
205 sx_jy[ix] = ((jy_type[0] == NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
206 sx_jz[ix] = ((jz_type[0] == NODE) ? amrex::Real(sx_node[ix]) : amrex::Real(sx_cell[ix]));
209 int const j_jx = ((jx_type[0] == NODE) ? j_node : j_cell);
210 int const j_jy = ((jy_type[0] == NODE) ? j_node : j_cell);
211 int const j_jz = ((jz_type[0] == NODE) ? j_node : j_cell);
212 #endif //AMREX_SPACEDIM >= 2 214 #if defined(WARPX_DIM_3D) 217 const double ymid = ((yp - ymin) + relative_time*vy)*dyi;
218 double sy_node[depos_order + 1] = {0.};
219 double sy_cell[depos_order + 1] = {0.};
222 if (jx_type[1] == NODE || jy_type[1] == NODE || jz_type[1] == NODE) {
223 k_node = compute_shape_factor(sy_node, ymid);
225 if (jx_type[1] == CELL || jy_type[1] == CELL || jz_type[1] == CELL) {
226 k_cell = compute_shape_factor(sy_cell, ymid - 0.5);
228 amrex::Real sy_jx[depos_order + 1] = {0._rt};
229 amrex::Real sy_jy[depos_order + 1] = {0._rt};
230 amrex::Real sy_jz[depos_order + 1] = {0._rt};
231 for (
int iy=0; iy<=depos_order; iy++)
233 sy_jx[iy] = ((jx_type[1] == NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
234 sy_jy[iy] = ((jy_type[1] == NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
235 sy_jz[iy] = ((jz_type[1] == NODE) ? amrex::Real(sy_node[iy]) : amrex::Real(sy_cell[iy]));
237 int const k_jx = ((jx_type[1] == NODE) ? k_node : k_cell);
238 int const k_jy = ((jy_type[1] == NODE) ? k_node : k_cell);
239 int const k_jz = ((jz_type[1] == NODE) ? k_node : k_cell);
244 const double zmid = ((zp - zmin) + relative_time*vz)*dzi;
245 double sz_node[depos_order + 1] = {0.};
246 double sz_cell[depos_order + 1] = {0.};
249 if (jx_type[zdir] == NODE || jy_type[zdir] == NODE || jz_type[zdir] == NODE) {
250 l_node = compute_shape_factor(sz_node, zmid);
252 if (jx_type[zdir] == CELL || jy_type[zdir] == CELL || jz_type[zdir] == CELL) {
253 l_cell = compute_shape_factor(sz_cell, zmid - 0.5);
255 amrex::Real sz_jx[depos_order + 1] = {0._rt};
256 amrex::Real sz_jy[depos_order + 1] = {0._rt};
257 amrex::Real sz_jz[depos_order + 1] = {0._rt};
258 for (
int iz=0; iz<=depos_order; iz++)
260 sz_jx[iz] = ((jx_type[zdir] == NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
261 sz_jy[iz] = ((jy_type[zdir] == NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
262 sz_jz[iz] = ((jz_type[zdir] == NODE) ? amrex::Real(sz_node[iz]) : amrex::Real(sz_cell[iz]));
264 int const l_jx = ((jx_type[zdir] == NODE) ? l_node : l_cell);
265 int const l_jy = ((jy_type[zdir] == NODE) ? l_node : l_cell);
266 int const l_jz = ((jz_type[zdir] == NODE) ? l_node : l_cell);
269 #if defined(WARPX_DIM_1D_Z) 270 for (
int iz=0; iz<=depos_order; iz++){
272 &jx_arr(lo.
x+l_jx+iz, 0, 0, 0),
275 &jy_arr(lo.
x+l_jy+iz, 0, 0, 0),
278 &jz_arr(lo.
x+l_jz+iz, 0, 0, 0),
282 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) 283 for (
int iz=0; iz<=depos_order; iz++){
284 for (
int ix=0; ix<=depos_order; ix++){
286 &jx_arr(lo.
x+j_jx+ix, lo.
y+l_jx+iz, 0, 0),
287 sx_jx[ix]*sz_jx[iz]*wqx);
289 &jy_arr(lo.
x+j_jy+ix, lo.
y+l_jy+iz, 0, 0),
290 sx_jy[ix]*sz_jy[iz]*wqy);
292 &jz_arr(lo.
x+j_jz+ix, lo.
y+l_jz+iz, 0, 0),
293 sx_jz[ix]*sz_jz[iz]*wqz);
294 #if defined(WARPX_DIM_RZ) 296 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
309 #elif defined(WARPX_DIM_3D) 310 for (
int iz=0; iz<=depos_order; iz++){
311 for (
int iy=0; iy<=depos_order; iy++){
312 for (
int ix=0; ix<=depos_order; ix++){
314 &jx_arr(lo.
x+j_jx+ix, lo.
y+k_jx+iy, lo.
z+l_jx+iz),
315 sx_jx[ix]*sy_jx[iy]*sz_jx[iz]*wqx);
317 &jy_arr(lo.
x+j_jy+ix, lo.
y+k_jy+iy, lo.
z+l_jy+iz),
318 sx_jy[ix]*sy_jy[iy]*sz_jy[iz]*wqy);
320 &jz_arr(lo.
x+j_jz+ix, lo.
y+k_jz+iy, lo.
z+l_jz+iz),
321 sx_jz[ix]*sy_jz[iy]*sz_jz[iz]*wqz);
328 #if defined(WARPX_USE_GPUCLOCK) 363 template <
int depos_order>
365 const amrex::ParticleReal *
const wp,
366 const amrex::ParticleReal *
const uxp,
367 const amrex::ParticleReal *
const uyp,
368 const amrex::ParticleReal *
const uzp,
369 const int *
const ion_lev,
373 const long np_to_depose,
374 const amrex::Real
dt,
375 const amrex::Real relative_time,
376 const std::array<amrex::Real,3>&
dx,
377 const std::array<amrex::Real, 3> xyzmin,
380 const int n_rz_azimuthal_modes,
381 amrex::Real *
const cost,
382 const long load_balance_costs_update_algo)
384 using namespace amrex;
385 #if !defined(WARPX_DIM_RZ) 389 #if !defined(AMREX_USE_GPU) 395 bool const do_ionization = ion_lev;
396 #if !defined(WARPX_DIM_1D_Z) 397 Real
const dxi = 1.0_rt / dx[0];
399 #if !defined(WARPX_DIM_1D_Z) 400 Real
const xmin = xyzmin[0];
402 #if defined(WARPX_DIM_3D) 403 Real
const dyi = 1.0_rt / dx[1];
404 Real
const ymin = xyzmin[1];
406 Real
const dzi = 1.0_rt / dx[2];
407 Real
const zmin = xyzmin[2];
409 #if defined(WARPX_DIM_3D) 410 Real
const invdtdx = 1.0_rt / (dt*dx[1]*dx[2]);
411 Real
const invdtdy = 1.0_rt / (dt*dx[0]*dx[2]);
412 Real
const invdtdz = 1.0_rt / (dt*dx[0]*dx[1]);
413 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) 414 Real
const invdtdx = 1.0_rt / (dt*dx[2]);
415 Real
const invdtdz = 1.0_rt / (dt*dx[0]);
416 Real
const invvol = 1.0_rt / (dx[0]*dx[2]);
417 #elif defined(WARPX_DIM_1D_Z) 418 Real
const invdtdz = 1.0_rt / (dt*dx[0]);
419 Real
const invvol = 1.0_rt / (dx[2]);
422 #if defined(WARPX_DIM_RZ) 427 #if !defined(WARPX_DIM_1D_Z) 428 Real constexpr one_third = 1.0_rt / 3.0_rt;
429 Real constexpr one_sixth = 1.0_rt / 6.0_rt;
433 #if defined(WARPX_USE_GPUCLOCK) 434 amrex::Real* cost_real =
nullptr;
443 #if defined(WARPX_USE_GPUCLOCK) 444 KernelTimer kernelTimer(cost && load_balance_costs_update_algo
449 Real
const gaminv = 1.0_rt/std::sqrt(1.0_rt + uxp[ip]*uxp[ip]*clightsq
450 + uyp[ip]*uyp[ip]*clightsq
451 + uzp[ip]*uzp[ip]*clightsq);
459 ParticleReal xp, yp, zp;
460 GetPosition(ip, xp, yp, zp);
462 #if !defined(WARPX_DIM_1D_Z) 463 Real
const wqx = wq*invdtdx;
465 #if defined(WARPX_DIM_3D) 466 Real
const wqy = wq*invdtdy;
468 Real
const wqz = wq*invdtdz;
471 #if defined(WARPX_DIM_RZ) 472 Real
const xp_new = xp + (relative_time + 0.5_rt*
dt)*uxp[ip]*gaminv;
473 Real
const yp_new = yp + (relative_time + 0.5_rt*
dt)*uyp[ip]*gaminv;
474 Real
const xp_mid = xp_new - 0.5_rt*dt*uxp[ip]*gaminv;
475 Real
const yp_mid = yp_new - 0.5_rt*dt*uyp[ip]*gaminv;
476 Real
const xp_old = xp_new - dt*uxp[ip]*gaminv;
477 Real
const yp_old = yp_new - dt*uyp[ip]*gaminv;
478 Real
const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new);
479 Real
const rp_mid = std::sqrt(xp_mid*xp_mid + yp_mid*yp_mid);
480 Real
const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old);
481 Real costheta_new, sintheta_new;
482 if (rp_new > 0._rt) {
483 costheta_new = xp_new/rp_new;
484 sintheta_new = yp_new/rp_new;
486 costheta_new = 1._rt;
487 sintheta_new = 0._rt;
489 amrex::Real costheta_mid, sintheta_mid;
490 if (rp_mid > 0._rt) {
491 costheta_mid = xp_mid/rp_mid;
492 sintheta_mid = yp_mid/rp_mid;
494 costheta_mid = 1._rt;
495 sintheta_mid = 0._rt;
497 amrex::Real costheta_old, sintheta_old;
498 if (rp_old > 0._rt) {
499 costheta_old = xp_old/rp_old;
500 sintheta_old = yp_old/rp_old;
502 costheta_old = 1._rt;
503 sintheta_old = 0._rt;
509 double const x_new = (rp_new - xmin)*dxi;
510 double const x_old = (rp_old - xmin)*dxi;
512 #if !defined(WARPX_DIM_1D_Z) 514 double const x_new = (xp - xmin + (relative_time + 0.5_rt*
dt)*uxp[ip]*gaminv)*dxi;
515 double const x_old = x_new - dt*dxi*uxp[ip]*gaminv;
518 #if defined(WARPX_DIM_3D) 520 double const y_new = (yp - ymin + (relative_time + 0.5_rt*
dt)*uyp[ip]*gaminv)*dyi;
521 double const y_old = y_new - dt*dyi*uyp[ip]*gaminv;
524 double const z_new = (zp - zmin + (relative_time + 0.5_rt*
dt)*uzp[ip]*gaminv)*dzi;
525 double const z_old = z_new - dt*dzi*uzp[ip]*gaminv;
527 #if defined(WARPX_DIM_RZ) 528 Real
const vy = (-uxp[ip]*sintheta_mid + uyp[ip]*costheta_mid)*gaminv;
529 #elif defined(WARPX_DIM_XZ) 530 Real
const vy = uyp[ip]*gaminv;
531 #elif defined(WARPX_DIM_1D_Z) 532 Real
const vx = uxp[ip]*gaminv;
533 Real
const vy = uyp[ip]*gaminv;
541 #if !defined(WARPX_DIM_1D_Z) 542 double sx_new[depos_order + 3] = {0.};
543 double sx_old[depos_order + 3] = {0.};
545 #if defined(WARPX_DIM_3D) 547 double sy_new[depos_order + 3] = {0.};
548 double sy_old[depos_order + 3] = {0.};
551 double sz_new[depos_order + 3] = {0.};
552 double sz_old[depos_order + 3] = {0.};
560 #if !defined(WARPX_DIM_1D_Z) 561 const int i_new = compute_shape_factor(sx_new+1, x_new);
562 const int i_old = compute_shifted_shape_factor(sx_old, x_old, i_new);
564 #if defined(WARPX_DIM_3D) 565 const int j_new = compute_shape_factor(sy_new+1, y_new);
566 const int j_old = compute_shifted_shape_factor(sy_old, y_old, j_new);
568 const int k_new = compute_shape_factor(sz_new+1, z_new);
569 const int k_old = compute_shifted_shape_factor(sz_old, z_old, k_new);
572 #if !defined(WARPX_DIM_1D_Z) 573 int dil = 1, diu = 1;
574 if (i_old < i_new) dil = 0;
575 if (i_old > i_new) diu = 0;
577 #if defined(WARPX_DIM_3D) 578 int djl = 1, dju = 1;
579 if (j_old < j_new) djl = 0;
580 if (j_old > j_new) dju = 0;
582 int dkl = 1, dku = 1;
583 if (k_old < k_new) dkl = 0;
584 if (k_old > k_new) dku = 0;
586 #if defined(WARPX_DIM_3D) 588 for (
int k=dkl; k<=depos_order+2-dku; k++) {
589 for (
int j=djl; j<=depos_order+2-dju; j++) {
590 amrex::Real sdxi = 0._rt;
591 for (
int i=dil;
i<=depos_order+1-diu;
i++) {
592 sdxi += wqx*(sx_old[
i] - sx_new[
i])*(
593 one_third*(sy_new[j]*sz_new[k] + sy_old[j]*sz_old[k])
594 +one_sixth*(sy_new[j]*sz_old[k] + sy_old[j]*sz_new[k]));
599 for (
int k=dkl; k<=depos_order+2-dku; k++) {
600 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
601 amrex::Real sdyj = 0._rt;
602 for (
int j=djl; j<=depos_order+1-dju; j++) {
603 sdyj += wqy*(sy_old[j] - sy_new[j])*(
604 one_third*(sx_new[
i]*sz_new[k] + sx_old[
i]*sz_old[k])
605 +one_sixth*(sx_new[
i]*sz_old[k] + sx_old[
i]*sz_new[k]));
610 for (
int j=djl; j<=depos_order+2-dju; j++) {
611 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
612 amrex::Real sdzk = 0._rt;
613 for (
int k=dkl; k<=depos_order+1-dku; k++) {
614 sdzk += wqz*(sz_old[k] - sz_new[k])*(
615 one_third*(sx_new[
i]*sy_new[j] + sx_old[
i]*sy_old[j])
616 +one_sixth*(sx_new[
i]*sy_old[j] + sx_old[
i]*sy_new[j]));
622 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) 624 for (
int k=dkl; k<=depos_order+2-dku; k++) {
625 amrex::Real sdxi = 0._rt;
626 for (
int i=dil;
i<=depos_order+1-diu;
i++) {
627 sdxi += wqx*(sx_old[
i] - sx_new[
i])*0.5_rt*(sz_new[k] + sz_old[k]);
629 #if defined(WARPX_DIM_RZ) 631 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
633 const Complex djr_cmplx = 2._rt *sdxi*xy_mid;
636 xy_mid = xy_mid*xy_mid0;
641 for (
int k=dkl; k<=depos_order+2-dku; k++) {
642 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
643 Real
const sdyj = wq*vy*invvol*(
644 one_third*(sx_new[
i]*sz_new[k] + sx_old[
i]*sz_old[k])
645 +one_sixth*(sx_new[
i]*sz_old[k] + sx_old[
i]*sz_new[k]));
647 #if defined(WARPX_DIM_RZ) 652 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
655 const Complex djt_cmplx = -2._rt * I*(i_new-1 +
i + xmin*dxi)*wq*invdtdx/(amrex::Real)imode
656 *(
Complex(sx_new[
i]*sz_new[k], 0._rt)*(xy_new - xy_mid)
657 +
Complex(sx_old[
i]*sz_old[k], 0._rt)*(xy_mid - xy_old));
660 xy_new = xy_new*xy_new0;
661 xy_mid = xy_mid*xy_mid0;
662 xy_old = xy_old*xy_old0;
667 for (
int i=dil;
i<=depos_order+2-diu;
i++) {
669 for (
int k=dkl; k<=depos_order+1-dku; k++) {
670 sdzk += wqz*(sz_old[k] - sz_new[k])*0.5_rt*(sx_new[
i] + sx_old[
i]);
672 #if defined(WARPX_DIM_RZ) 674 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
676 const Complex djz_cmplx = 2._rt * sdzk * xy_mid;
679 xy_mid = xy_mid*xy_mid0;
684 #elif defined(WARPX_DIM_1D_Z) 686 for (
int k=dkl; k<=depos_order+2-dku; k++) {
687 amrex::Real
const sdxi = wq*vx*invvol*0.5_rt*(sz_old[k] + sz_new[k]);
690 for (
int k=dkl; k<=depos_order+2-dku; k++) {
691 amrex::Real
const sdyj = wq*vy*invvol*0.5_rt*(sz_old[k] + sz_new[k]);
694 amrex::Real sdzk = 0._rt;
695 for (
int k=dkl; k<=depos_order+1-dku; k++) {
696 sdzk += wqz*(sz_old[k] - sz_new[k]);
702 #if defined(WARPX_USE_GPUCLOCK) 740 template <
int depos_order>
742 const amrex::ParticleReal*
const wp,
743 const amrex::ParticleReal*
const uxp,
744 const amrex::ParticleReal*
const uyp,
745 const amrex::ParticleReal*
const uzp,
746 const int*
const ion_lev,
750 const long np_to_depose,
751 const amrex::Real
dt,
752 const amrex::Real relative_time,
753 const std::array<amrex::Real,3>&
dx,
754 const std::array<amrex::Real,3>& xyzmin,
757 const int n_rz_azimuthal_modes,
759 const long load_balance_costs_update_algo)
761 #if defined(WARPX_DIM_RZ) 763 wp, uxp, uyp, uzp, ion_lev, Dx_fab, Dy_fab, Dz_fab,
764 np_to_depose, dt, relative_time, dx, xyzmin, lo, q, n_rz_azimuthal_modes);
765 amrex::Abort(
"Vay deposition not implemented in RZ geometry");
768 #if defined(WARPX_DIM_1D_Z) 770 wp, uxp, uyp, uzp, ion_lev, Dx_fab, Dy_fab, Dz_fab,
771 np_to_depose, dt, relative_time, dx, xyzmin, lo, q, n_rz_azimuthal_modes);
772 amrex::Abort(
"Vay deposition not implemented in cartesian 1D geometry");
775 #if !defined(AMREX_USE_GPU) 779 #if !(defined WARPX_DIM_RZ || defined WARPX_DIM_1D_Z) 783 const bool do_ionization = ion_lev;
786 const amrex::Real dxi = 1._rt / dx[0];
787 const amrex::Real dzi = 1._rt / dx[2];
788 #if defined(WARPX_DIM_3D) 789 const amrex::Real dyi = 1._rt / dx[1];
793 const amrex::Real invdt = 1._rt /
dt;
796 #if defined(WARPX_DIM_XZ) 797 const amrex::Real invvol = dxi * dzi;
798 #elif defined(WARPX_DIM_3D) 799 const amrex::Real invvol = dxi * dyi * dzi;
803 const amrex::Real xmin = xyzmin[0];
804 const amrex::Real zmin = xyzmin[2];
805 #if defined(WARPX_DIM_3D) 806 const amrex::Real ymin = xyzmin[1];
810 #if defined(WARPX_DIM_3D) 813 #elif defined(WARPX_DIM_XZ) 829 #if defined(WARPX_USE_GPUCLOCK) 830 amrex::Real* cost_real =
nullptr;
838 #if defined(WARPX_USE_GPUCLOCK) 839 KernelTimer kernelTimer(cost && load_balance_costs_update_algo
844 const amrex::Real invgam = 1._rt / std::sqrt(1._rt + uxp[ip] * uxp[ip] * invcsq
845 + uyp[ip] * uyp[ip] * invcsq
846 + uzp[ip] * uzp[ip] * invcsq);
848 amrex::Real wq = q * wp[ip];
849 if (do_ionization) wq *= ion_lev[ip];
852 amrex::ParticleReal xp, yp, zp;
853 GetPosition(ip, xp, yp, zp);
856 const amrex::Real vx = uxp[ip] * invgam;
857 const amrex::Real vy = uyp[ip] * invgam;
858 const amrex::Real vz = uzp[ip] * invgam;
861 xp += relative_time * vx;
862 yp += relative_time * vy;
863 zp += relative_time * vz;
866 #if defined(WARPX_DIM_XZ) 867 const amrex::Real wqy = wq * vy * invvol;
872 double const x_new = (xp - xmin + 0.5_rt*dt*vx) * dxi;
873 double const x_old = (xp - xmin - 0.5_rt*dt*vx) * dxi;
874 #if defined(WARPX_DIM_3D) 876 double const y_new = (yp - ymin + 0.5_rt*dt*vy) * dyi;
877 double const y_old = (yp - ymin - 0.5_rt*dt*vy) * dyi;
880 double const z_new = (zp - zmin + 0.5_rt*dt*vz) * dzi;
881 double const z_old = (zp - zmin - 0.5_rt*dt*vz) * dzi;
885 double sx_new[depos_order+1] = {0.};
886 double sx_old[depos_order+1] = {0.};
887 #if defined(WARPX_DIM_3D) 889 double sy_new[depos_order+1] = {0.};
890 double sy_old[depos_order+1] = {0.};
893 double sz_new[depos_order+1] = {0.};
894 double sz_old[depos_order+1] = {0.};
901 const int i_new = compute_shape_factor(sx_new, x_new);
902 #if defined(WARPX_DIM_3D) 905 const int j_new = compute_shape_factor(sy_new, y_new);
909 const int k_new = compute_shape_factor(sz_new, z_new);
915 const int i_old = compute_shape_factor(sx_old, x_old);
916 #if defined(WARPX_DIM_3D) 919 const int j_old = compute_shape_factor(sy_old, y_old);
923 const int k_old = compute_shape_factor(sz_old, z_old);
926 #if defined(WARPX_DIM_XZ) 928 for (
int k=0; k<=depos_order; k++) {
929 for (
int i=0;
i<=depos_order;
i++) {
933 auto const sxn_szn =
static_cast<amrex::Real
>(sx_new[
i] * sz_new[k]);
934 auto const sxo_szn =
static_cast<amrex::Real
>(sx_old[
i] * sz_new[k]);
935 auto const sxn_szo =
static_cast<amrex::Real
>(sx_new[
i] * sz_old[k]);
936 auto const sxo_szo =
static_cast<amrex::Real
>(sx_old[
i] * sz_old[k]);
938 if (i_new == i_old && k_new == k_old) {
941 wq * invvol * invdt * (sxn_szn - sxo_szo));
944 wq * invvol * invdt * (sxn_szo - sxo_szn));
948 wqy * 0.25_rt * (sxn_szn + sxn_szo + sxo_szn + sxo_szo));
952 wq * invvol * invdt * sxn_szn);
955 - wq * invvol * invdt * sxo_szo);
958 wq * invvol * invdt * sxn_szo);
961 - wq * invvol * invdt * sxo_szn);
965 wqy * 0.25_rt * sxn_szn);
968 wqy * 0.25_rt * sxn_szo);
971 wqy * 0.25_rt * sxo_szn);
974 wqy * 0.25_rt * sxo_szo);
980 #elif defined(WARPX_DIM_3D) 982 for (
int k=0; k<=depos_order; k++) {
983 for (
int j=0; j<=depos_order; j++) {
985 auto const syn_szn =
static_cast<amrex::Real
>(sy_new[j] * sz_new[k]);
986 auto const syo_szn =
static_cast<amrex::Real
>(sy_old[j] * sz_new[k]);
987 auto const syn_szo =
static_cast<amrex::Real
>(sy_new[j] * sz_old[k]);
988 auto const syo_szo =
static_cast<amrex::Real
>(sy_old[j] * sz_old[k]);
990 for (
int i=0;
i<=depos_order;
i++) {
992 auto const sxn_syn_szn =
static_cast<amrex::Real
>(sx_new[
i]) * syn_szn;
993 auto const sxo_syn_szn =
static_cast<amrex::Real
>(sx_old[
i]) * syn_szn;
994 auto const sxn_syo_szn =
static_cast<amrex::Real
>(sx_new[
i]) * syo_szn;
995 auto const sxo_syo_szn =
static_cast<amrex::Real
>(sx_old[
i]) * syo_szn;
996 auto const sxn_syn_szo =
static_cast<amrex::Real
>(sx_new[
i]) * syn_szo;
997 auto const sxo_syn_szo =
static_cast<amrex::Real
>(sx_old[
i]) * syn_szo;
998 auto const sxn_syo_szo =
static_cast<amrex::Real
>(sx_new[
i]) * syo_szo;
999 auto const sxo_syo_szo =
static_cast<amrex::Real
>(sx_old[
i]) * syo_szo;
1001 if (i_new == i_old && j_new == j_old && k_new == k_old) {
1004 wq * invvol * invdt * (sxn_syn_szn - sxo_syo_szo));
1007 wq * invvol * invdt * (sxn_syn_szo - sxo_syo_szn));
1010 wq * invvol * invdt * (sxn_syo_szn - sxo_syn_szo));
1013 wq * invvol * invdt * (sxo_syn_szn - sxn_syo_szo));
1017 wq * invvol * invdt * sxn_syn_szn);
1020 - wq * invvol * invdt * sxo_syo_szo);
1023 wq * invvol * invdt * sxn_syn_szo);
1026 - wq * invvol * invdt * sxo_syo_szn);
1029 wq * invvol * invdt * sxn_syo_szn);
1032 - wq * invvol * invdt * sxo_syn_szo);
1035 wq * invvol * invdt * sxo_syn_szn);
1038 - wq * invvol * invdt * sxn_syo_szo);
1046 #if defined(WARPX_DIM_3D) 1049 const amrex::Real t_a = temp_arr(i,j,k,0);
1050 const amrex::Real t_b = temp_arr(i,j,k,1);
1051 const amrex::Real t_c = temp_arr(i,j,k,2);
1052 const amrex::Real t_d = temp_arr(i,j,k,3);
1053 Dx_arr(i,j,k) += (1._rt/6._rt)*(2_rt*t_a + t_b + t_c - 2._rt*t_d);
1054 Dy_arr(i,j,k) += (1._rt/6._rt)*(2_rt*t_a + t_b - 2._rt*t_c + t_d);
1055 Dz_arr(i,j,k) += (1._rt/6._rt)*(2_rt*t_a - 2._rt*t_b + t_c + t_d);
1057 #elif defined(WARPX_DIM_XZ) 1060 const amrex::Real t_a = temp_arr(i,j,0,0);
1061 const amrex::Real t_b = temp_arr(i,j,0,1);
1062 Dx_arr(i,j,0) += (0.5_rt)*(t_a + t_b);
1063 Dz_arr(i,j,0) += (0.5_rt)*(t_a - t_b);
1070 # if defined(WARPX_USE_GPUCLOCK) 1073 *cost += *cost_real;
1077 #endif // #if !(defined WARPX_DIM_RZ || defined WARPX_DIM_1D_Z) 1079 #endif // CURRENTDEPOSITION_H_
const Box & box() const noexcept
amrex::GpuComplex< amrex::Real > Complex
Definition: WarpX_Complex.H:22
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:741
AMREX_FORCE_INLINE Array4< Real const > array() const noexcept
static constexpr auto c
vacuum speed of light [m/s]
Definition: constant.H:44
int dx
Definition: compute_domain.py:35
int dt
Definition: Stencil.py:468
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:52
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:364
Definition: ShapeFactors.H:81
virtual void free(void *pt)=0
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
#define AMREX_ALWAYS_ASSERT(EX)
Definition: ShapeFactors.H:26
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T imag() const noexcept
std::enable_if_t< std::is_integral< T >::value > ParallelFor(TypeList< CTOs... >, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
void Abort(const std::string &msg)
Definition: WarpXAlgorithmSelection.H:124
i
Definition: check_interp_points_and_weights.py:174
virtual void * alloc(std::size_t sz)=0
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T real() const noexcept
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:52
void streamSynchronize() noexcept
Defines a timer object to be used on GPU; measures summed thread cycles.
Definition: KernelTimer.H:23
Arena * The_Managed_Arena()