52 [[maybe_unused]]
const int n_rz_azimuthal_modes)
54 using namespace amrex;
59#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER)
60 const double rp = std::sqrt(xp*xp + yp*yp);
61 const double x_bar = (rp - xyzmin.
x)*dinv.
x;
62#elif defined(WARPX_DIM_RSPHERE)
63 const double rp = std::sqrt(xp*xp + yp*yp + zp*zp);
64 const double x_bar = (rp - xyzmin.
x)*dinv.
x;
65#elif !defined(WARPX_DIM_1D_Z)
66 const double x_bar = (xp - xyzmin.
x)*dinv.
x;
68#if defined(WARPX_DIM_3D)
69 const double y_bar = (yp - xyzmin.
y)*dinv.
y;
71#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
72 const double z_bar = (zp - xyzmin.
z)*dinv.
z;
78#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
79 constexpr int zdir = WARPX_ZINDEX;
84 double sz_node[depos_order_perp+1] = {0.};
85 double sz_cell[depos_order_perp+1] = {0.};
86 if (Fx_type[zdir] == NODE || Fy_type[zdir] == NODE) {
87 kp_node = shape_factor_perp(sz_node, z_bar);
89 if (Fx_type[zdir] == CELL || Fy_type[zdir] == CELL) {
90 kp_cell = shape_factor_perp(sz_cell, z_bar - 0.5);
93 const int kp_Fx = ((Fx_type[zdir] == NODE) ? kp_node : kp_cell);
94 const double (&sz_Fx)[depos_order_perp+1] = ((Fx_type[zdir] == NODE) ? sz_node : sz_cell);
96 const int kp_Fy = ((Fy_type[zdir] == NODE) ? kp_node : kp_cell);
97 const double (&sz_Fy)[depos_order_perp+1] = ((Fy_type[zdir] == NODE) ? sz_node : sz_cell);
100 double sz_Fz[depos_order_para+1] = {0.};
101 if (Fz_type[zdir] == NODE) { kp_Fz = shape_factor_para(sz_Fz, z_bar); }
102 else { kp_Fz = shape_factor_para(sz_Fz, z_bar - 0.5); }
105#if !defined(WARPX_DIM_1D_Z)
109 double sx_node[depos_order_perp+1] = {0.};
110 double sx_cell[depos_order_perp+1] = {0.};
111 if (Fy_type[0] == NODE || Fz_type[0] == NODE) {
112 ip_node = shape_factor_perp(sx_node, x_bar);
114 if (Fy_type[0] == CELL || Fz_type[0] == CELL) {
115 ip_cell = shape_factor_perp(sx_cell, x_bar - 0.5);
118 const int ip_Fy = ((Fy_type[0] == NODE) ? ip_node : ip_cell);
119 const double (&sx_Fy)[depos_order_perp+1] = ((Fy_type[0] == NODE) ? sx_node : sx_cell);
121 const int ip_Fz = ((Fz_type[0] == NODE) ? ip_node : ip_cell);
122 const double (&sx_Fz)[depos_order_perp+1] = ((Fz_type[0] == NODE) ? sx_node : sx_cell);
125 double sx_Fx[depos_order_para + 1] = {0.};
126 if (Fx_type[0] == NODE) { ip_Fx = shape_factor_para(sx_Fx, x_bar); }
127 else { ip_Fx = shape_factor_para(sx_Fx, x_bar - 0.5); }
130#if defined(WARPX_DIM_3D)
134 double sy_node[depos_order_perp+1] = {0.};
135 double sy_cell[depos_order_perp+1] = {0.};
136 if (Fx_type[1] == NODE || Fz_type[1] == NODE) {
137 jp_node = shape_factor_perp(sy_node, y_bar);
139 if (Fx_type[1] == CELL || Fz_type[1] == CELL) {
140 jp_cell = shape_factor_perp(sy_cell, y_bar - 0.5);
143 const int jp_Fx = ((Fx_type[1] == NODE) ? jp_node : jp_cell);
144 const double (&sy_Fx)[depos_order_perp+1] = ((Fx_type[1] == NODE) ? sy_node : sy_cell);
146 const int jp_Fz = ((Fz_type[1] == NODE) ? jp_node : jp_cell);
147 const double (&sy_Fz)[depos_order_perp+1] = ((Fz_type[1] == NODE) ? sy_node : sy_cell);
150 double sy_Fy[depos_order_para + 1] = {0.};
151 if (Fy_type[1] == NODE) { jp_Fy = shape_factor_para(sy_Fy, y_bar); }
152 else { jp_Fy = shape_factor_para(sy_Fy, y_bar - 0.5); }
156 for (
int k=0; k<=depos_order_perp; k++) {
157 for (
int j=0; j<=depos_order_perp; j++) {
158 for (
int i=0; i<=depos_order_para; i++) {
159 weight =
static_cast<amrex::Real>(sx_Fx[i]*sy_Fx[j]*sz_Fx[k]);
160 Fxp += Fx_arr(lo.
x+ip_Fx+i, lo.
y+jp_Fx+j, lo.
z+kp_Fx+k)*weight;
164 for (
int k=0; k<=depos_order_perp; k++) {
165 for (
int j=0; j<=depos_order_para; j++) {
166 for (
int i=0; i<=depos_order_perp; i++) {
167 weight =
static_cast<amrex::Real>(sx_Fy[i]*sy_Fy[j]*sz_Fy[k]);
168 Fyp += Fy_arr(lo.
x+ip_Fy+i, lo.
y+jp_Fy+j, lo.
z+kp_Fy+k)*weight;
172 for (
int k=0; k<=depos_order_para; k++) {
173 for (
int j=0; j<=depos_order_perp; j++) {
174 for (
int i=0; i<=depos_order_perp; i++) {
175 weight =
static_cast<amrex::Real>(sx_Fz[i]*sy_Fz[j]*sz_Fz[k]);
176 Fzp += Fz_arr(lo.
x+ip_Fz+i, lo.
y+jp_Fz+j, lo.
z+kp_Fz+k)*weight;
181#elif defined(WARPX_DIM_XZ)
184 for (
int k=0; k<=depos_order_perp; k++) {
185 for (
int i=0; i<=depos_order_para; i++) {
186 const auto weight_Fx =
static_cast<amrex::Real>(sx_Fx[i]*sz_Fx[k]);
187 Fxp += Fx_arr(lo.
x+ip_Fx+i, lo.
y+kp_Fx+k, 0, 0)*weight_Fx;
190 for (
int k=0; k<=depos_order_perp; k++) {
191 for (
int i=0; i<=depos_order_perp; i++) {
192 const auto weight_Fy =
static_cast<amrex::Real>(sx_Fy[i]*sz_Fy[k]);
193 Fyp += Fy_arr(lo.
x+ip_Fy+i, lo.
y+kp_Fy+k, 0, 0)*weight_Fy;
196 for (
int k=0; k<=depos_order_para; k++) {
197 for (
int i=0; i<=depos_order_perp; i++) {
198 const auto weight_Fz =
static_cast<amrex::Real>(sx_Fz[i]*sz_Fz[k]);
199 Fzp += Fz_arr(lo.
x+ip_Fz+i, lo.
y+kp_Fz+k, 0, 0)*weight_Fz;
203#elif defined(WARPX_DIM_RZ)
209 for (
int k=0; k<=depos_order_perp; k++) {
210 for (
int i=0; i<=depos_order_para; i++) {
211 const auto weight_Fr =
static_cast<amrex::Real>(sx_Fx[i]*sz_Fx[k]);
212 Frp += Fx_arr(lo.
x+ip_Fx+i, lo.
y+kp_Fx+k, 0, 0)*weight_Fr;
215 for (
int k=0; k<=depos_order_perp; k++) {
216 for (
int i=0; i<=depos_order_perp; i++) {
217 const auto weight_Fth =
static_cast<amrex::Real>(sx_Fy[i]*sz_Fy[k]);
218 Fthp += Fy_arr(lo.
x+ip_Fy+i, lo.
y+kp_Fy+k, 0, 0)*weight_Fth;
221 for (
int k=0; k<=depos_order_para; k++) {
222 for (
int i=0; i<=depos_order_perp; i++) {
223 const auto weight_Fz =
static_cast<amrex::Real>(sx_Fz[i]*sz_Fz[k]);
224 Fzp += Fz_arr(lo.
x+ip_Fz+i, lo.
y+kp_Fz+k, 0, 0)*weight_Fz;
228 const amrex::Real costheta = (rp > 0. ? xp/rp: 1._rt);
229 const amrex::Real sintheta = (rp > 0. ? yp/rp: 0.);
234 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
236 for (
int k=0; k<=depos_order_perp; k++) {
237 for (
int i=0; i<=depos_order_para; i++) {
238 const auto weight_Fr =
static_cast<amrex::Real>(sx_Fx[i]*sz_Fx[k]);
239 const auto dFr = (+ Fx_arr(lo.
x+ip_Fx+i, lo.
y+kp_Fx+k, 0, 2*imode-1)*xy.
real()
240 - Fx_arr(lo.
x+ip_Fx+i, lo.
y+kp_Fx+k, 0, 2*imode)*xy.
imag());
241 Frp += weight_Fr*dFr;
244 for (
int k=0; k<=depos_order_perp; k++) {
245 for (
int i=0; i<=depos_order_perp; i++) {
246 const auto weight_Fth =
static_cast<amrex::Real>(sx_Fy[i]*sz_Fy[k]);
247 const auto dFth = (+ Fy_arr(lo.
x+ip_Fy+i, lo.
y+kp_Fy+k, 0, 2*imode-1)*xy.
real()
248 - Fy_arr(lo.
x+ip_Fy+i, lo.
y+kp_Fy+k, 0, 2*imode)*xy.
imag());
249 Fthp += weight_Fth*dFth;
252 for (
int k=0; k<=depos_order_para; k++) {
253 for (
int i=0; i<=depos_order_perp; i++) {
254 const auto weight_Fz =
static_cast<amrex::Real>(sx_Fz[i]*sz_Fz[k]);
255 const auto dFz = (+ Fz_arr(lo.
x+ip_Fz+i, lo.
y+kp_Fz+k, 0, 2*imode-1)*xy.
real()
256 - Fz_arr(lo.
x+ip_Fz+i, lo.
y+kp_Fz+k, 0, 2*imode)*xy.
imag());
257 Fzp += weight_Fz*dFz;
265 Fxp += costheta*Frp - sintheta*Fthp;
266 Fyp += costheta*Fthp + sintheta*Frp;
268#elif defined(WARPX_DIM_1D_Z)
271 for (
int k=0; k<=depos_order_perp; k++) {
272 const auto weight_Fx =
static_cast<amrex::Real>(sz_Fx[k]);
273 Fxp += Fx_arr(lo.
x+kp_Fx+k, 0, 0)*weight_Fx;
275 const auto weight_Fy =
static_cast<amrex::Real>(sz_Fy[k]);
276 Fyp += Fy_arr(lo.
x+kp_Fy+k, 0, 0)*weight_Fy;
278 for (
int k=0; k<=depos_order_para; k++) {
279 const auto weight_Fz =
static_cast<amrex::Real>(sz_Fz[k]);
280 Fzp += Fz_arr(lo.
x+kp_Fz+k, 0, 0)*weight_Fz;
283#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
291 for (
int i=0; i<=depos_order_para; i++) {
292 const auto weight_Fx =
static_cast<amrex::Real>(sx_Fx[i]);
293 Frp += Fx_arr(lo.
x+ip_Fx+i, 0, 0)*weight_Fx;
295 for (
int i=0; i<=depos_order_perp; i++) {
296 const auto weight_Fy =
static_cast<amrex::Real>(sx_Fy[i]);
297 Fthetap += Fy_arr(lo.
x+ip_Fy+i, 0, 0)*weight_Fy;
299 const auto weight_Fz =
static_cast<amrex::Real>(sx_Fz[i]);
300 F3p += Fz_arr(lo.
x+ip_Fz+i, 0, 0)*weight_Fz;
303#if defined(WARPX_DIM_RCYLINDER)
305 amrex::Real const costheta = (rp > 0. ? xp/rp: 1._rt);
306 amrex::Real const sintheta = (rp > 0. ? yp/rp: 0.);
309 Fxp += costheta*Frp - sintheta*Fthetap;
310 Fyp += costheta*Fthetap + sintheta*Frp;
313#elif defined(WARPX_DIM_RSPHERE)
316 amrex::Real const costheta = (rpxy > 0. ? xp/rpxy : 1.);
317 amrex::Real const sintheta = (rpxy > 0. ? yp/rpxy : 0.);
318 amrex::Real const cosphi = (rp > 0. ? rpxy/rp : 1.);
322 Fxp += costheta*cosphi*Frp - sintheta*Fthetap - costheta*sinphi*F3p;
323 Fyp += sintheta*cosphi*Frp + costheta*Fthetap - sintheta*sinphi*F3p;
324 Fzp += sinphi*Frp + cosphi*F3p;
374 [[maybe_unused]]
const int n_rz_azimuthal_modes)
376 using namespace amrex;
379 constexpr int zdir = WARPX_ZINDEX;
388 Compute_shape_factor<depos_order - galerkin_interpolation >
const compute_shape_factor_galerkin;
390#if !defined(WARPX_DIM_1D_Z)
393#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER)
396#elif defined(WARPX_DIM_RSPHERE)
397 const amrex::Real rp = std::sqrt(xp*xp + yp*yp + zp*zp);
409 amrex::Real sx_node_galerkin[depos_order + 1 - galerkin_interpolation] = {0._rt};
410 amrex::Real sx_cell_galerkin[depos_order + 1 - galerkin_interpolation] = {0._rt};
416 if ((ey_type[0] == NODE) || (ez_type[0] == NODE) || (bx_type[0] == NODE)) {
417 j_node = compute_shape_factor(sx_node, x);
419 if ((ey_type[0] == CELL) || (ez_type[0] == CELL) || (bx_type[0] == CELL)) {
420 j_cell = compute_shape_factor(sx_cell, x - 0.5_rt);
422 if ((ex_type[0] == NODE) || (by_type[0] == NODE) || (bz_type[0] == NODE)) {
423 j_node_v = compute_shape_factor_galerkin(sx_node_galerkin, x);
425 if ((ex_type[0] == CELL) || (by_type[0] == CELL) || (bz_type[0] == CELL)) {
426 j_cell_v = compute_shape_factor_galerkin(sx_cell_galerkin, x - 0.5_rt);
428 const amrex::Real (&sx_ex)[depos_order + 1 - galerkin_interpolation] = ((ex_type[0] == NODE) ? sx_node_galerkin : sx_cell_galerkin);
429 const amrex::Real (&sx_ey)[depos_order + 1 ] = ((ey_type[0] == NODE) ? sx_node : sx_cell );
430 const amrex::Real (&sx_ez)[depos_order + 1 ] = ((ez_type[0] == NODE) ? sx_node : sx_cell );
431 const amrex::Real (&sx_bx)[depos_order + 1 ] = ((bx_type[0] == NODE) ? sx_node : sx_cell );
432 const amrex::Real (&sx_by)[depos_order + 1 - galerkin_interpolation] = ((by_type[0] == NODE) ? sx_node_galerkin : sx_cell_galerkin);
433 const amrex::Real (&sx_bz)[depos_order + 1 - galerkin_interpolation] = ((bz_type[0] == NODE) ? sx_node_galerkin : sx_cell_galerkin);
434 int const j_ex = ((ex_type[0] == NODE) ? j_node_v : j_cell_v);
435 int const j_ey = ((ey_type[0] == NODE) ? j_node : j_cell );
436 int const j_ez = ((ez_type[0] == NODE) ? j_node : j_cell );
437 int const j_bx = ((bx_type[0] == NODE) ? j_node : j_cell );
438 int const j_by = ((by_type[0] == NODE) ? j_node_v : j_cell_v);
439 int const j_bz = ((bz_type[0] == NODE) ? j_node_v : j_cell_v);
442#if defined(WARPX_DIM_3D)
447 amrex::Real sy_node_v[depos_order + 1 - galerkin_interpolation] = {0._rt};
448 amrex::Real sy_cell_v[depos_order + 1 - galerkin_interpolation] = {0._rt};
453 if ((ex_type[1] == NODE) || (ez_type[1] == NODE) || (by_type[1] == NODE)) {
454 k_node = compute_shape_factor(sy_node, y);
456 if ((ex_type[1] == CELL) || (ez_type[1] == CELL) || (by_type[1] == CELL)) {
457 k_cell = compute_shape_factor(sy_cell, y - 0.5_rt);
459 if ((ey_type[1] == NODE) || (bx_type[1] == NODE) || (bz_type[1] == NODE)) {
460 k_node_v = compute_shape_factor_galerkin(sy_node_v, y);
462 if ((ey_type[1] == CELL) || (bx_type[1] == CELL) || (bz_type[1] == CELL)) {
463 k_cell_v = compute_shape_factor_galerkin(sy_cell_v, y - 0.5_rt);
465 const amrex::Real (&sy_ex)[depos_order + 1 ] = ((ex_type[1] == NODE) ? sy_node : sy_cell );
466 const amrex::Real (&sy_ey)[depos_order + 1 - galerkin_interpolation] = ((ey_type[1] == NODE) ? sy_node_v : sy_cell_v);
467 const amrex::Real (&sy_ez)[depos_order + 1 ] = ((ez_type[1] == NODE) ? sy_node : sy_cell );
468 const amrex::Real (&sy_bx)[depos_order + 1 - galerkin_interpolation] = ((bx_type[1] == NODE) ? sy_node_v : sy_cell_v);
469 const amrex::Real (&sy_by)[depos_order + 1 ] = ((by_type[1] == NODE) ? sy_node : sy_cell );
470 const amrex::Real (&sy_bz)[depos_order + 1 - galerkin_interpolation] = ((bz_type[1] == NODE) ? sy_node_v : sy_cell_v);
471 int const k_ex = ((ex_type[1] == NODE) ? k_node : k_cell );
472 int const k_ey = ((ey_type[1] == NODE) ? k_node_v : k_cell_v);
473 int const k_ez = ((ez_type[1] == NODE) ? k_node : k_cell );
474 int const k_bx = ((bx_type[1] == NODE) ? k_node_v : k_cell_v);
475 int const k_by = ((by_type[1] == NODE) ? k_node : k_cell );
476 int const k_bz = ((bz_type[1] == NODE) ? k_node_v : k_cell_v);
480#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
485 amrex::Real sz_node_v[depos_order + 1 - galerkin_interpolation] = {0._rt};
486 amrex::Real sz_cell_v[depos_order + 1 - galerkin_interpolation] = {0._rt};
491 if ((ex_type[zdir] == NODE) || (ey_type[zdir] == NODE) || (bz_type[zdir] == NODE)) {
492 l_node = compute_shape_factor(sz_node, z);
494 if ((ex_type[zdir] == CELL) || (ey_type[zdir] == CELL) || (bz_type[zdir] == CELL)) {
495 l_cell = compute_shape_factor(sz_cell, z - 0.5_rt);
497 if ((ez_type[zdir] == NODE) || (bx_type[zdir] == NODE) || (by_type[zdir] == NODE)) {
498 l_node_v = compute_shape_factor_galerkin(sz_node_v, z);
500 if ((ez_type[zdir] == CELL) || (bx_type[zdir] == CELL) || (by_type[zdir] == CELL)) {
501 l_cell_v = compute_shape_factor_galerkin(sz_cell_v, z - 0.5_rt);
503 const amrex::Real (&sz_ex)[depos_order + 1 ] = ((ex_type[zdir] == NODE) ? sz_node : sz_cell );
504 const amrex::Real (&sz_ey)[depos_order + 1 ] = ((ey_type[zdir] == NODE) ? sz_node : sz_cell );
505 const amrex::Real (&sz_ez)[depos_order + 1 - galerkin_interpolation] = ((ez_type[zdir] == NODE) ? sz_node_v : sz_cell_v);
506 const amrex::Real (&sz_bx)[depos_order + 1 - galerkin_interpolation] = ((bx_type[zdir] == NODE) ? sz_node_v : sz_cell_v);
507 const amrex::Real (&sz_by)[depos_order + 1 - galerkin_interpolation] = ((by_type[zdir] == NODE) ? sz_node_v : sz_cell_v);
508 const amrex::Real (&sz_bz)[depos_order + 1 ] = ((bz_type[zdir] == NODE) ? sz_node : sz_cell );
509 int const l_ex = ((ex_type[zdir] == NODE) ? l_node : l_cell );
510 int const l_ey = ((ey_type[zdir] == NODE) ? l_node : l_cell );
511 int const l_ez = ((ez_type[zdir] == NODE) ? l_node_v : l_cell_v);
512 int const l_bx = ((bx_type[zdir] == NODE) ? l_node_v : l_cell_v);
513 int const l_by = ((by_type[zdir] == NODE) ? l_node_v : l_cell_v);
514 int const l_bz = ((bz_type[zdir] == NODE) ? l_node : l_cell );
522#if defined(WARPX_DIM_1D_Z)
526 for (
int iz=0; iz<=depos_order; iz++){
528 ey_arr(lo.
x+l_ey+iz, 0, 0, 0);
530 ex_arr(lo.
x+l_ex+iz, 0, 0, 0);
532 bz_arr(lo.
x+l_bz+iz, 0, 0, 0);
538 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
540 ez_arr(lo.
x+l_ez+iz, 0, 0, 0);
542 bx_arr(lo.
x+l_bx+iz, 0, 0, 0);
544 by_arr(lo.
x+l_by+iz, 0, 0, 0);
547#elif defined(WARPX_DIM_XZ)
549 for (
int iz=0; iz<=depos_order; iz++){
550 for (
int ix=0; ix<=depos_order; ix++){
551 Eyp += sx_ey[ix]*sz_ey[iz]*
552 ey_arr(lo.
x+j_ey+ix, lo.
y+l_ey+iz, 0, 0);
557 for (
int iz=0; iz<=depos_order; iz++){
558 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
559 Exp += sx_ex[ix]*sz_ex[iz]*
560 ex_arr(lo.
x+j_ex+ix, lo.
y+l_ex+iz, 0, 0);
561 Bzp += sx_bz[ix]*sz_bz[iz]*
562 bz_arr(lo.
x+j_bz+ix, lo.
y+l_bz+iz, 0, 0);
567 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
568 for (
int ix=0; ix<=depos_order; ix++){
569 Ezp += sx_ez[ix]*sz_ez[iz]*
570 ez_arr(lo.
x+j_ez+ix, lo.
y+l_ez+iz, 0, 0);
571 Bxp += sx_bx[ix]*sz_bx[iz]*
572 bx_arr(lo.
x+j_bx+ix, lo.
y+l_bx+iz, 0, 0);
576 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
577 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
578 Byp += sx_by[ix]*sz_by[iz]*
579 by_arr(lo.
x+j_by+ix, lo.
y+l_by+iz, 0, 0);
583#elif defined(WARPX_DIM_RZ)
591 for (
int iz=0; iz<=depos_order; iz++){
592 for (
int ix=0; ix<=depos_order; ix++){
593 Ethetap += sx_ey[ix]*sz_ey[iz]*
594 ey_arr(lo.
x+j_ey+ix, lo.
y+l_ey+iz, 0, 0);
599 for (
int iz=0; iz<=depos_order; iz++){
600 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
601 Erp += sx_ex[ix]*sz_ex[iz]*
602 ex_arr(lo.
x+j_ex+ix, lo.
y+l_ex+iz, 0, 0);
603 Bzp += sx_bz[ix]*sz_bz[iz]*
604 bz_arr(lo.
x+j_bz+ix, lo.
y+l_bz+iz, 0, 0);
609 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
610 for (
int ix=0; ix<=depos_order; ix++){
611 Ezp += sx_ez[ix]*sz_ez[iz]*
612 ez_arr(lo.
x+j_ez+ix, lo.
y+l_ez+iz, 0, 0);
613 Brp += sx_bx[ix]*sz_bx[iz]*
614 bx_arr(lo.
x+j_bx+ix, lo.
y+l_bx+iz, 0, 0);
618 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
619 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
620 Bthetap += sx_by[ix]*sz_by[iz]*
621 by_arr(lo.
x+j_by+ix, lo.
y+l_by+iz, 0, 0);
637 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
640 for (
int iz=0; iz<=depos_order; iz++){
641 for (
int ix=0; ix<=depos_order; ix++){
642 const amrex::Real dEy = (+ ey_arr(lo.
x+j_ey+ix, lo.
y+l_ey+iz, 0, 2*imode-1)*xy.
real()
643 - ey_arr(lo.
x+j_ey+ix, lo.
y+l_ey+iz, 0, 2*imode)*xy.
imag());
644 Ethetap += sx_ey[ix]*sz_ey[iz]*dEy;
649 for (
int iz=0; iz<=depos_order; iz++){
650 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
651 const amrex::Real dEx = (+ ex_arr(lo.
x+j_ex+ix, lo.
y+l_ex+iz, 0, 2*imode-1)*xy.
real()
652 - ex_arr(lo.
x+j_ex+ix, lo.
y+l_ex+iz, 0, 2*imode)*xy.
imag());
653 Erp += sx_ex[ix]*sz_ex[iz]*dEx;
654 const amrex::Real dBz = (+ bz_arr(lo.
x+j_bz+ix, lo.
y+l_bz+iz, 0, 2*imode-1)*xy.
real()
655 - bz_arr(lo.
x+j_bz+ix, lo.
y+l_bz+iz, 0, 2*imode)*xy.
imag());
656 Bzp += sx_bz[ix]*sz_bz[iz]*dBz;
661 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
662 for (
int ix=0; ix<=depos_order; ix++){
663 const amrex::Real dEz = (+ ez_arr(lo.
x+j_ez+ix, lo.
y+l_ez+iz, 0, 2*imode-1)*xy.
real()
664 - ez_arr(lo.
x+j_ez+ix, lo.
y+l_ez+iz, 0, 2*imode)*xy.
imag());
665 Ezp += sx_ez[ix]*sz_ez[iz]*dEz;
666 const amrex::Real dBx = (+ bx_arr(lo.
x+j_bx+ix, lo.
y+l_bx+iz, 0, 2*imode-1)*xy.
real()
667 - bx_arr(lo.
x+j_bx+ix, lo.
y+l_bx+iz, 0, 2*imode)*xy.
imag());
668 Brp += sx_bx[ix]*sz_bx[iz]*dBx;
672 for (
int iz=0; iz<=depos_order-galerkin_interpolation; iz++){
673 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
674 const amrex::Real dBy = (+ by_arr(lo.
x+j_by+ix, lo.
y+l_by+iz, 0, 2*imode-1)*xy.
real()
675 - by_arr(lo.
x+j_by+ix, lo.
y+l_by+iz, 0, 2*imode)*xy.
imag());
676 Bthetap += sx_by[ix]*sz_by[iz]*dBy;
683 Exp += costheta*Erp - sintheta*Ethetap;
684 Eyp += costheta*Ethetap + sintheta*Erp;
685 Bxp += costheta*Brp - sintheta*Bthetap;
686 Byp += costheta*Bthetap + sintheta*Brp;
688#elif defined(WARPX_DIM_RCYLINDER)
696 for (
int ix=0; ix<=depos_order; ix++){
697 Ethetap += sx_ey[ix]*ey_arr(lo.
x+j_ey+ix, 0, 0, 0);
701 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
702 Erp += sx_ex[ix]*ex_arr(lo.
x+j_ex+ix, 0, 0, 0);
703 Bzp += sx_bz[ix]*bz_arr(lo.
x+j_bz+ix, 0, 0, 0);
707 for (
int ix=0; ix<=depos_order; ix++){
708 Ezp += sx_ez[ix]*ez_arr(lo.
x+j_ez+ix, 0, 0, 0);
709 Brp += sx_bx[ix]*bx_arr(lo.
x+j_bx+ix, 0, 0, 0);
712 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
713 Bthetap += sx_by[ix]*by_arr(lo.
x+j_by+ix, 0, 0, 0);
716 amrex::Real const costheta = (rp > 0. ? xp/rp : 1.);
717 amrex::Real const sintheta = (rp > 0. ? yp/rp : 0.);
720 Exp += costheta*Erp - sintheta*Ethetap;
721 Eyp += costheta*Ethetap + sintheta*Erp;
722 Bxp += costheta*Brp - sintheta*Bthetap;
723 Byp += costheta*Bthetap + sintheta*Brp;
725#elif defined(WARPX_DIM_RSPHERE)
735 for (
int ix=0; ix<=depos_order; ix++){
736 Ethetap += sx_ey[ix]*ey_arr(lo.
x+j_ey+ix, 0, 0, 0);
740 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
741 Erp += sx_ex[ix]*ex_arr(lo.
x+j_ex+ix, 0, 0, 0);
742 Bphip += sx_bz[ix]*bz_arr(lo.
x+j_bz+ix, 0, 0, 0);
746 for (
int ix=0; ix<=depos_order; ix++){
747 Ephip += sx_ez[ix]*ez_arr(lo.
x+j_ez+ix, 0, 0, 0);
748 Brp += sx_bx[ix]*bx_arr(lo.
x+j_bx+ix, 0, 0, 0);
751 for (
int ix=0; ix<=depos_order-galerkin_interpolation; ix++){
752 Bthetap += sx_by[ix]*by_arr(lo.
x+j_by+ix, 0, 0, 0);
756 amrex::Real const costheta = (rpxy > 0. ? xp/rpxy : 1.);
757 amrex::Real const sintheta = (rpxy > 0. ? yp/rpxy : 0.);
758 amrex::Real const cosphi = (rp > 0. ? rpxy/rp : 1.);
762 Exp += costheta*cosphi*Erp - sintheta*Ethetap - costheta*sinphi*Ephip;
763 Eyp += sintheta*cosphi*Erp + costheta*Ethetap - sintheta*sinphi*Ephip;
764 Ezp += sinphi*Erp + cosphi*Ephip;
765 Bxp += costheta*cosphi*Brp - sintheta*Bthetap - costheta*sinphi*Bphip;
766 Byp += sintheta*cosphi*Brp + costheta*Bthetap - sintheta*sinphi*Bphip;
767 Bzp += sinphi*Brp + cosphi*Bphip;
771 for (
int iz=0; iz<=depos_order; iz++){
772 for (
int iy=0; iy<=depos_order; iy++){
773 for (
int ix=0; ix<= depos_order - galerkin_interpolation; ix++){
774 Exp += sx_ex[ix]*sy_ex[iy]*sz_ex[iz]*
775 ex_arr(lo.
x+j_ex+ix, lo.
y+k_ex+iy, lo.
z+l_ex+iz);
780 for (
int iz=0; iz<=depos_order; iz++){
781 for (
int iy=0; iy<= depos_order - galerkin_interpolation; iy++){
782 for (
int ix=0; ix<=depos_order; ix++){
783 Eyp += sx_ey[ix]*sy_ey[iy]*sz_ey[iz]*
784 ey_arr(lo.
x+j_ey+ix, lo.
y+k_ey+iy, lo.
z+l_ey+iz);
789 for (
int iz=0; iz<= depos_order - galerkin_interpolation; iz++){
790 for (
int iy=0; iy<=depos_order; iy++){
791 for (
int ix=0; ix<=depos_order; ix++){
792 Ezp += sx_ez[ix]*sy_ez[iy]*sz_ez[iz]*
793 ez_arr(lo.
x+j_ez+ix, lo.
y+k_ez+iy, lo.
z+l_ez+iz);
798 for (
int iz=0; iz<=depos_order; iz++){
799 for (
int iy=0; iy<= depos_order - galerkin_interpolation; iy++){
800 for (
int ix=0; ix<= depos_order - galerkin_interpolation; ix++){
801 Bzp += sx_bz[ix]*sy_bz[iy]*sz_bz[iz]*
802 bz_arr(lo.
x+j_bz+ix, lo.
y+k_bz+iy, lo.
z+l_bz+iz);
807 for (
int iz=0; iz<= depos_order - galerkin_interpolation; iz++){
808 for (
int iy=0; iy<=depos_order; iy++){
809 for (
int ix=0; ix<= depos_order - galerkin_interpolation; ix++){
810 Byp += sx_by[ix]*sy_by[iy]*sz_by[iz]*
811 by_arr(lo.
x+j_by+ix, lo.
y+k_by+iy, lo.
z+l_by+iz);
816 for (
int iz=0; iz<= depos_order - galerkin_interpolation; iz++){
817 for (
int iy=0; iy<= depos_order - galerkin_interpolation; iy++){
818 for (
int ix=0; ix<=depos_order; ix++){
819 Bxp += sx_bx[ix]*sy_bx[iy]*sz_bx[iz]*
820 bx_arr(lo.
x+j_bx+ix, lo.
y+k_bx+iy, lo.
z+l_bx+iz);
879 const int n_rz_azimuthal_modes)
881 using namespace amrex;
882#if !defined(WARPX_DIM_RZ)
886#if (AMREX_SPACEDIM > 1)
887 Real constexpr one_third = 1.0_rt / 3.0_rt;
888 Real constexpr one_sixth = 1.0_rt / 6.0_rt;
891#if !defined(WARPX_DIM_1D_Z)
894#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
897#if !defined(WARPX_DIM_RCYLINDER)
902#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER)
907 amrex::Real const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new);
908 amrex::Real const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old);
910 double x_new = (rp_new - xyzmin.
x)*dinv.
x;
911 double const x_old = (rp_old - xyzmin.
x)*dinv.
x;
912#elif defined(WARPX_DIM_RSPHERE)
919 amrex::Real const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new + zp_new*zp_new);
920 amrex::Real const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old + zp_old*zp_old);
923 double x_new = (rp_new - xyzmin.
x)*dinv.
x;
924 double const x_old = (rp_old - xyzmin.
x)*dinv.
x;
926#if !defined(WARPX_DIM_1D_Z)
928 double x_new = (xp_np1 - xyzmin.
x)*dinv.
x;
929 double const x_old = (xp_n - xyzmin.
x)*dinv.
x;
932#if defined(WARPX_DIM_3D)
934 double y_new = (yp_np1 - xyzmin.
y)*dinv.
y;
935 double const y_old = (yp_n - xyzmin.
y)*dinv.
y;
937#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
939 double z_new = (zp_np1 - xyzmin.
z)*dinv.
z;
940 double const z_old = (zp_n - xyzmin.
z)*dinv.
z;
946#if defined(WARPX_DIM_3D)
948 domain_double[0][0], domain_double[0][1], do_cropping[0]);
950 domain_double[1][0], domain_double[1][1], do_cropping[1]);
952 domain_double[2][0], domain_double[2][1], do_cropping[2]);
953#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
955 domain_double[0][0], domain_double[0][1], do_cropping[0]);
957 domain_double[1][0], domain_double[1][1], do_cropping[1]);
958#elif defined(WARPX_DIM_1D_Z)
960#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
969#if !defined(WARPX_DIM_1D_Z)
970 double sx_E_new[depos_order + 3] = {0.};
971 double sx_E_old[depos_order + 3] = {0.};
973#if defined(WARPX_DIM_3D)
975 double sy_E_new[depos_order + 3] = {0.};
976 double sy_E_old[depos_order + 3] = {0.};
978#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
980 double sz_E_new[depos_order + 3] = {0.};
981 double sz_E_old[depos_order + 3] = {0.};
984#if defined(WARPX_DIM_3D)
985 double sx_B_new[depos_order + 3] = {0.};
986 double sx_B_old[depos_order + 3] = {0.};
987 double sy_B_new[depos_order + 3] = {0.};
988 double sy_B_old[depos_order + 3] = {0.};
989 double sz_B_new[depos_order + 3] = {0.};
990 double sz_B_old[depos_order + 3] = {0.};
993#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
996 double sx_By_new[depos_order + 2] = {0.};
997 double sx_By_old[depos_order + 2] = {0.};
998 double sz_By_new[depos_order + 2] = {0.};
999 double sz_By_old[depos_order + 2] = {0.};
1008#if !defined(WARPX_DIM_1D_Z)
1009 const int i_E_new = compute_shape_factor(sx_E_new+1, x_new);
1010 const int i_E_old = compute_shifted_shape_factor(sx_E_old, x_old, i_E_new);
1012#if defined(WARPX_DIM_3D)
1013 const int j_E_new = compute_shape_factor(sy_E_new+1, y_new);
1014 const int j_E_old = compute_shifted_shape_factor(sy_E_old, y_old, j_E_new);
1016#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
1017 const int k_E_new = compute_shape_factor(sz_E_new+1, z_new);
1018 const int k_E_old = compute_shifted_shape_factor(sz_E_old, z_old, k_E_new);
1021#if defined(WARPX_DIM_3D)
1022 const int i_B_new = compute_shape_factor(sx_B_new+1, x_new - 0.5_rt);
1023 const int i_B_old = compute_shifted_shape_factor(sx_B_old, x_old - 0.5_rt, i_B_new);
1024 const int j_B_new = compute_shape_factor(sy_B_new+1, y_new - 0.5_rt);
1025 const int j_B_old = compute_shifted_shape_factor(sy_B_old, y_old - 0.5_rt, j_B_new);
1026 const int k_B_new = compute_shape_factor(sz_B_new+1, z_new - 0.5_rt);
1027 const int k_B_old = compute_shifted_shape_factor(sz_B_old, z_old - 0.5_rt, k_B_new);
1031#if !defined(WARPX_DIM_1D_Z)
1032 int dil_E = 1, diu_E = 1;
1033 if (i_E_old < i_E_new) { dil_E = 0; }
1034 if (i_E_old > i_E_new) { diu_E = 0; }
1036#if defined(WARPX_DIM_3D)
1037 int djl_E = 1, dju_E = 1;
1038 if (j_E_old < j_E_new) { djl_E = 0; }
1039 if (j_E_old > j_E_new) { dju_E = 0; }
1041#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
1042 int dkl_E = 1, dku_E = 1;
1043 if (k_E_old < k_E_new) { dkl_E = 0; }
1044 if (k_E_old > k_E_new) { dku_E = 0; }
1047#if defined(WARPX_DIM_3D)
1048 int dil_B = 1, diu_B = 1;
1049 if (i_B_old < i_B_new) { dil_B = 0; }
1050 if (i_B_old > i_B_new) { diu_B = 0; }
1051 int djl_B = 1, dju_B = 1;
1052 if (j_B_old < j_B_new) { djl_B = 0; }
1053 if (j_B_old > j_B_new) { dju_B = 0; }
1054 int dkl_B = 1, dku_B = 1;
1055 if (k_B_old < k_B_new) { dkl_B = 0; }
1056 if (k_B_old > k_B_new) { dku_B = 0; }
1059#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
1062 const int i_By_new = compute_shape_factor_By(sx_By_new+1, x_new - 0.5_rt);
1063 const int i_By_old = compute_shifted_shape_factor_By(sx_By_old, x_old - 0.5_rt, i_By_new);
1064 const int k_By_new = compute_shape_factor_By(sz_By_new+1, z_new - 0.5_rt);
1065 const int k_By_old = compute_shifted_shape_factor_By(sz_By_old, z_old - 0.5_rt, k_By_new);
1066 int dil_By = 1, diu_By = 1;
1067 if (i_By_old < i_By_new) { dil_By = 0; }
1068 if (i_By_old > i_By_new) { diu_By = 0; }
1069 int dkl_By = 1, dku_By = 1;
1070 if (k_By_old < k_By_new) { dkl_By = 0; }
1071 if (k_By_old > k_By_new) { dku_By = 0; }
1074#if defined(WARPX_DIM_3D)
1076 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1077 for (
int j=djl_E; j<=depos_order+2-dju_E; j++) {
1078 const amrex::Real sdzjk = one_third*(sy_E_new[j]*sz_E_new[k] + sy_E_old[j]*sz_E_old[k])
1079 +one_sixth*(sy_E_new[j]*sz_E_old[k] + sy_E_old[j]*sz_E_new[k]);
1081 for (
int i=dil_E; i<=depos_order+1-diu_E; i++) {
1082 sdxi += (sx_E_old[i] - sx_E_new[i]);
1083 auto sdxiov =
static_cast<amrex::Real>((x_new - x_old) == 0. ? 1. : sdxi/(x_new - x_old));
1084 Exp += Ex_arr(lo.
x+i_E_new-1+i, lo.
y+j_E_new-1+j, lo.
z+k_E_new-1+k)*sdxiov*sdzjk;
1088 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1089 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1090 const amrex::Real sdyik = one_third*(sx_E_new[i]*sz_E_new[k] + sx_E_old[i]*sz_E_old[k])
1091 +one_sixth*(sx_E_new[i]*sz_E_old[k] + sx_E_old[i]*sz_E_new[k]);
1093 for (
int j=djl_E; j<=depos_order+1-dju_E; j++) {
1094 sdyj += (sy_E_old[j] - sy_E_new[j]);
1095 auto sdyjov =
static_cast<amrex::Real>((y_new - y_old) == 0. ? 1. : sdyj/(y_new - y_old));
1096 Eyp += Ey_arr(lo.
x+i_E_new-1+i, lo.
y+j_E_new-1+j, lo.
z+k_E_new-1+k)*sdyjov*sdyik;
1100 for (
int j=djl_E; j<=depos_order+2-dju_E; j++) {
1101 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1102 const amrex::Real sdzij = one_third*(sx_E_new[i]*sy_E_new[j] + sx_E_old[i]*sy_E_old[j])
1103 +one_sixth*(sx_E_new[i]*sy_E_old[j] + sx_E_old[i]*sy_E_new[j]);
1105 for (
int k=dkl_E; k<=depos_order+1-dku_E; k++) {
1106 sdzk += (sz_E_old[k] - sz_E_new[k]);
1107 auto sdzkov =
static_cast<amrex::Real>((z_new - z_old) == 0. ? 1. : sdzk/(z_new - z_old));
1108 Ezp += Ez_arr(lo.
x+i_E_new-1+i, lo.
y+j_E_new-1+j, lo.
z+k_E_new-1+k)*sdzkov*sdzij;
1112 for (
int k=dkl_B; k<=depos_order+2-dku_B; k++) {
1113 for (
int j=djl_B; j<=depos_order+2-dju_B; j++) {
1114 const amrex::Real sdzjk = one_third*(sy_B_new[j]*sz_B_new[k] + sy_B_old[j]*sz_B_old[k])
1115 +one_sixth*(sy_B_new[j]*sz_B_old[k] + sy_B_old[j]*sz_B_new[k]);
1117 for (
int i=dil_B; i<=depos_order+1-diu_B; i++) {
1118 sdxi += (sx_B_old[i] - sx_B_new[i]);
1119 auto sdxiov =
static_cast<amrex::Real>((x_new - x_old) == 0. ? 1. : sdxi/(x_new - x_old));
1120 Bxp += Bx_arr(lo.
x+i_B_new-1+i, lo.
y+j_B_new-1+j, lo.
z+k_B_new-1+k)*sdxiov*sdzjk;
1124 for (
int k=dkl_B; k<=depos_order+2-dku_B; k++) {
1125 for (
int i=dil_B; i<=depos_order+2-diu_B; i++) {
1126 const amrex::Real sdyik = one_third*(sx_B_new[i]*sz_B_new[k] + sx_B_old[i]*sz_B_old[k])
1127 +one_sixth*(sx_B_new[i]*sz_B_old[k] + sx_B_old[i]*sz_B_new[k]);
1129 for (
int j=djl_B; j<=depos_order+1-dju_B; j++) {
1130 sdyj += (sy_B_old[j] - sy_B_new[j]);
1131 auto sdyjov =
static_cast<amrex::Real>((y_new - y_old) == 0. ? 1. : sdyj/(y_new - y_old));
1132 Byp += By_arr(lo.
x+i_B_new-1+i, lo.
y+j_B_new-1+j, lo.
z+k_B_new-1+k)*sdyjov*sdyik;
1136 for (
int j=djl_B; j<=depos_order+2-dju_B; j++) {
1137 for (
int i=dil_B; i<=depos_order+2-diu_B; i++) {
1138 const amrex::Real sdzij = one_third*(sx_B_new[i]*sy_B_new[j] + sx_B_old[i]*sy_B_old[j])
1139 +one_sixth*(sx_B_new[i]*sy_B_old[j] + sx_B_old[i]*sy_B_new[j]);
1141 for (
int k=dkl_B; k<=depos_order+1-dku_B; k++) {
1142 sdzk += (sz_B_old[k] - sz_B_new[k]);
1143 auto sdzkov =
static_cast<amrex::Real>((z_new - z_old) == 0. ? 1. : sdzk/(z_new - z_old));
1144 Bzp += Bz_arr(lo.
x+i_B_new-1+i, lo.
y+j_B_new-1+j, lo.
z+k_E_new-1+k)*sdzkov*sdzij;
1149#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
1151 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1152 const amrex::Real sdzk = 0.5_rt*(sz_E_new[k] + sz_E_old[k]);
1154 for (
int i=dil_E; i<=depos_order+1-diu_E; i++) {
1155 sdxi += (sx_E_old[i] - sx_E_new[i]);
1156 auto sdxiov =
static_cast<amrex::Real>((x_new - x_old) == 0. ? 1. : sdxi/(x_new - x_old));
1157 Exp += Ex_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 0)*sdxiov*sdzk;
1158 Bzp += Bz_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 0)*sdxiov*sdzk;
1161 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1162 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1164 one_third*(sx_E_new[i]*sz_E_new[k] + sx_E_old[i]*sz_E_old[k])
1165 +one_sixth*(sx_E_new[i]*sz_E_old[k] + sx_E_old[i]*sz_E_new[k]));
1166 Eyp += Ey_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 0)*sdyj;
1169 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1170 const amrex::Real sdxi = 0.5_rt*(sx_E_new[i] + sx_E_old[i]);
1172 for (
int k=dkl_E; k<=depos_order+1-dku_E; k++) {
1173 sdzk += (sz_E_old[k] - sz_E_new[k]);
1174 auto sdzkov =
static_cast<amrex::Real>((z_new - z_old) == 0. ? 1. : sdzk/(z_new - z_old));
1175 Ezp += Ez_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 0)*sdzkov*sdxi;
1176 Bxp += Bx_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 0)*sdzkov*sdxi;
1179 for (
int k=dkl_By; k<=depos_order+1-dku_By; k++) {
1180 for (
int i=dil_By; i<=depos_order+1-diu_By; i++) {
1182 one_third*(sx_By_new[i]*sz_By_new[k] + sx_By_old[i]*sz_By_old[k])
1183 +one_sixth*(sx_By_new[i]*sz_By_old[k] + sx_By_old[i]*sz_By_new[k]));
1184 Byp += By_arr(lo.
x+i_By_new-1+i, lo.
y+k_By_new-1+k, 0, 0)*sdyj;
1191 const amrex::Real rp_mid = (rp_new + rp_old)/2._rt;
1192 const amrex::Real costheta_mid = (rp_mid > 0. ? xp_mid/rp_mid: 1._rt);
1193 const amrex::Real sintheta_mid = (rp_mid > 0. ? yp_mid/rp_mid: 0.);
1197 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
1201 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1202 const amrex::Real sdzk = 0.5_rt*(sz_E_new[k] + sz_E_old[k]);
1204 for (
int i=dil_E; i<=depos_order+1-diu_E; i++) {
1205 sdxi += (sx_E_old[i] - sx_E_new[i]);
1206 auto sdxiov =
static_cast<amrex::Real>((x_new - x_old) == 0. ? 1. : sdxi/(x_new - x_old));
1207 const amrex::Real dEx = (+ Ex_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode-1)*xy_mid.
real()
1208 - Ex_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode)*xy_mid.
imag());
1209 const amrex::Real dBz = (+ Bz_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode-1)*xy_mid.
real()
1210 - Bz_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode)*xy_mid.
imag());
1211 Exp += dEx*sdxiov*sdzk;
1212 Bzp += dBz*sdxiov*sdzk;
1216 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1217 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1219 one_third*(sx_E_new[i]*sz_E_new[k] + sx_E_old[i]*sz_E_old[k])
1220 +one_sixth*(sx_E_new[i]*sz_E_old[k] + sx_E_old[i]*sz_E_new[k]));
1221 const amrex::Real dEy = (+ Ey_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode-1)*xy_mid.
real()
1222 - Ey_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode)*xy_mid.
imag());
1228 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1229 const amrex::Real sdxi = 0.5_rt*(sx_E_new[i] + sx_E_old[i]);
1231 for (
int k=dkl_E; k<=depos_order+1-dku_E; k++) {
1232 sdzk += (sz_E_old[k] - sz_E_new[k]);
1233 auto sdzkov =
static_cast<amrex::Real>((z_new - z_old) == 0. ? 1. : sdzk/(z_new - z_old));
1234 const amrex::Real dEz = (+ Ez_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode-1)*xy_mid.
real()
1235 - Ez_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode)*xy_mid.
imag());
1236 const amrex::Real dBx = (+ Bx_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode-1)*xy_mid.
real()
1237 - Bx_arr(lo.
x+i_E_new-1+i, lo.
y+k_E_new-1+k, 0, 2*imode)*xy_mid.
imag());
1238 Ezp += dEz*sdzkov*sdxi;
1239 Bxp += dBx*sdzkov*sdxi;
1243 for (
int k=dkl_By; k<=depos_order+1-dku_By; k++) {
1244 for (
int i=dil_By; i<=depos_order+1-diu_By; i++) {
1246 one_third*(sx_By_new[i]*sz_By_new[k] + sx_By_old[i]*sz_By_old[k])
1247 +one_sixth*(sx_By_new[i]*sz_By_old[k] + sx_By_old[i]*sz_By_new[k]));
1248 const amrex::Real dBy = (+ By_arr(lo.
x+i_By_new-1+i, lo.
y+k_By_new-1+k, 0, 2*imode-1)*xy_mid.
real()
1249 - By_arr(lo.
x+i_By_new-1+i, lo.
y+k_By_new-1+k, 0, 2*imode)*xy_mid.
imag());
1253 xy_mid = xy_mid*xy_mid0;
1259 Exp = costheta_mid*Erp - sintheta_mid*Ethp;
1260 Eyp = costheta_mid*Ethp + sintheta_mid*Erp;
1264 Bxp = costheta_mid*Brp - sintheta_mid*Bthp;
1265 Byp = costheta_mid*Bthp + sintheta_mid*Brp;
1269#elif defined(WARPX_DIM_1D_Z)
1271 for (
int k=dkl_E; k<=depos_order+2-dku_E; k++) {
1272 amrex::Real const sdzk = 0.5_rt*(sz_E_old[k] + sz_E_new[k]);
1273 Exp += Ex_arr(lo.
x+k_E_new-1+k, 0, 0, 0)*sdzk;
1274 Eyp += Ey_arr(lo.
x+k_E_new-1+k, 0, 0, 0)*sdzk;
1275 Bzp += Bz_arr(lo.
x+k_E_new-1+k, 0, 0, 0)*sdzk;
1278 for (
int k=dkl_E; k<=depos_order+1-dku_E; k++) {
1279 sdzk += (sz_E_old[k] - sz_E_new[k]);
1280 auto sdzkov =
static_cast<amrex::Real>((z_new - z_old) == 0. ? 1. : sdzk/(z_new - z_old));
1281 Bxp += Bx_arr(lo.
x+k_E_new-1+k, 0, 0, 0)*sdzkov;
1282 Byp += By_arr(lo.
x+k_E_new-1+k, 0, 0, 0)*sdzkov;
1283 Ezp += Ez_arr(lo.
x+k_E_new-1+k, 0, 0, 0)*sdzkov;
1286#elif defined(WARPX_DIM_RCYLINDER)
1290 const amrex::Real rp_mid = (rp_new + rp_old)*0.5_rt;
1291 const amrex::Real costheta_mid = (rp_mid > 0. ? xp_mid/rp_mid: 1._rt);
1292 const amrex::Real sintheta_mid = (rp_mid > 0. ? yp_mid/rp_mid: 0.);
1299 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1300 amrex::Real const sdxi = 0.5_rt*(sx_E_old[i] + sx_E_new[i]);
1301 Brp += Bx_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxi;
1302 Ethetap += Ey_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxi;
1303 Ezp += Ez_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxi;
1306 for (
int i=dil_E; i<=depos_order+1-diu_E; i++) {
1307 sdxi += (sx_E_old[i] - sx_E_new[i]);
1308 auto sdxiov =
static_cast<amrex::Real>((x_new - x_old) == 0. ? 1. : sdxi/(x_new - x_old));
1309 Erp += Ex_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxiov;
1310 Bthetap += By_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxiov;
1311 Bzp += Bz_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxiov;
1315 Exp += costheta_mid*Erp - sintheta_mid*Ethetap;
1316 Eyp += costheta_mid*Ethetap + sintheta_mid*Erp;
1317 Bxp += costheta_mid*Brp - sintheta_mid*Bthetap;
1318 Byp += costheta_mid*Bthetap + sintheta_mid*Brp;
1320#elif defined(WARPX_DIM_RSPHERE)
1325 amrex::Real const rpxy_mid = std::sqrt(xp_mid*xp_mid + yp_mid*yp_mid);
1326 amrex::Real const rp_mid = (rp_new + rp_old)*0.5_rt;
1327 amrex::Real const costheta_mid = (rpxy_mid > 0. ? xp_mid/rpxy_mid : 1._rt);
1328 amrex::Real const sintheta_mid = (rpxy_mid > 0. ? yp_mid/rpxy_mid : 0._rt);
1329 amrex::Real const cosphi_mid = (rp_mid > 0. ? rpxy_mid/rp_mid : 1._rt);
1330 amrex::Real const sinphi_mid = (rp_mid > 0. ? zp_mid/rp_mid : 0._rt);
1339 for (
int i=dil_E; i<=depos_order+2-diu_E; i++) {
1340 amrex::Real const sdxi = 0.5_rt*(sx_E_old[i] + sx_E_new[i]);
1341 Brp += Bx_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxi;
1342 Ethetap += Ey_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxi;
1343 Ephip += Ez_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxi;
1346 for (
int i=dil_E; i<=depos_order+1-diu_E; i++) {
1347 sdxi += (sx_E_old[i] - sx_E_new[i]);
1348 auto sdxiov =
static_cast<amrex::Real>((x_new - x_old) == 0. ? 1. : sdxi/(x_new - x_old));
1349 Erp += Ex_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxiov;
1350 Bthetap += By_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxiov;
1351 Bphip += Bz_arr(lo.
x+i_E_new-1+i, 0, 0, 0)*sdxiov;
1355 Exp += costheta_mid*cosphi_mid*Erp - sintheta_mid*Ethetap - costheta_mid*sinphi_mid*Ephip;
1356 Eyp += sintheta_mid*cosphi_mid*Erp + costheta_mid*Ethetap - sintheta_mid*sinphi_mid*Ephip;
1357 Ezp += sinphi_mid*Erp + cosphi_mid*Ephip;
1358 Bxp += costheta_mid*cosphi_mid*Brp - sintheta_mid*Bthetap - costheta_mid*sinphi_mid*Bphip;
1359 Byp += sintheta_mid*cosphi_mid*Brp + costheta_mid*Bthetap - sintheta_mid*sinphi_mid*Bphip;
1360 Bzp += sinphi_mid*Brp + cosphi_mid*Bphip;
1418 const int n_rz_azimuthal_modes)
1420 using namespace amrex;
1421#if !defined(WARPX_DIM_RZ)
1425#if !defined(WARPX_DIM_1D_Z)
1428#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
1431#if !defined(WARPX_DIM_RCYLINDER)
1435#if (AMREX_SPACEDIM > 1)
1436 Real constexpr one_third = 1.0_rt / 3.0_rt;
1437 Real constexpr one_sixth = 1.0_rt / 6.0_rt;
1441#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER)
1446 amrex::Real const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new);
1447 amrex::Real const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old);
1450 amrex::Real const rp_mid = (rp_new + rp_old)*0.5_rt;
1451 amrex::Real const costheta_mid = (rp_mid > 0. ? xp_mid/rp_mid: 1._rt);
1452 amrex::Real const sintheta_mid = (rp_mid > 0. ? yp_mid/rp_mid: 0.);
1453#if defined(WARPX_DIM_RZ)
1458 double x_new = (rp_new - xyzmin.
x)*dinv.
x;
1459 double const x_old = (rp_old - xyzmin.
x)*dinv.
x;
1460#elif defined(WARPX_DIM_RSPHERE)
1470 amrex::Real const rpxy_mid = std::sqrt(xp_mid*xp_mid + yp_mid*yp_mid);
1471 amrex::Real const rp_new = std::sqrt(xp_new*xp_new + yp_new*yp_new + zp_new*zp_new);
1472 amrex::Real const rp_old = std::sqrt(xp_old*xp_old + yp_old*yp_old + zp_old*zp_old);
1473 amrex::Real const rp_mid = (rp_new + rp_old)*0.5_rt;
1475 amrex::Real const costheta_mid = (rpxy_mid > 0. ? xp_mid/rpxy_mid : 1._rt);
1476 amrex::Real const sintheta_mid = (rpxy_mid > 0. ? yp_mid/rpxy_mid : 0._rt);
1477 amrex::Real const cosphi_mid = (rp_mid > 0. ? rpxy_mid/rp_mid : 1._rt);
1478 amrex::Real const sinphi_mid = (rp_mid > 0. ? zp_mid/rp_mid : 0._rt);
1481 double x_new = (rp_new - xyzmin.
x)*dinv.
x;
1482 double const x_old = (rp_old - xyzmin.
x)*dinv.
x;
1483#elif !defined(WARPX_DIM_1D_Z)
1485 double x_new = (xp_np1 - xyzmin.
x)*dinv.
x;
1486 double const x_old = (xp_n - xyzmin.
x)*dinv.
x;
1488#if defined(WARPX_DIM_3D)
1490 double y_new = (yp_np1 - xyzmin.
y)*dinv.
y;
1491 double const y_old = (yp_n - xyzmin.
y)*dinv.
y;
1493#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
1495 double z_new = (zp_np1 - xyzmin.
z)*dinv.
z;
1496 double const z_old = (zp_n - xyzmin.
z)*dinv.
z;
1501#if !defined(WARPX_DIM_1D_Z)
1502 const double dxp = x_new - x_old;
1504#if defined(WARPX_DIM_3D)
1505 const double dyp = y_new - y_old;
1507#if !defined(WARPX_DIM_RCYLINDER) && !defined(WARPX_DIM_RSPHERE)
1508 const double dzp = z_new - z_old;
1511#if defined(WARPX_DIM_3D)
1513 domain_double[0][0], domain_double[0][1], do_cropping[0]);
1515 domain_double[1][0], domain_double[1][1], do_cropping[1]);
1517 domain_double[2][0], domain_double[2][1], do_cropping[2]);
1518#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
1521#elif defined(WARPX_DIM_1D_Z)
1523#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
1534 int num_segments = 1;
1536 if ( (depos_order % 2) == 0 ) {
shift = 0.5; }
1538#if defined(WARPX_DIM_3D)
1541 const auto i_old =
static_cast<int>(x_old-
shift);
1542 const auto i_new =
static_cast<int>(x_new-
shift);
1543 const int cell_crossings_x = std::abs(i_new-i_old);
1544 num_segments += cell_crossings_x;
1547 const auto j_old =
static_cast<int>(y_old-
shift);
1548 const auto j_new =
static_cast<int>(y_new-
shift);
1549 const int cell_crossings_y = std::abs(j_new-j_old);
1550 num_segments += cell_crossings_y;
1553 const auto k_old =
static_cast<int>(z_old-
shift);
1554 const auto k_new =
static_cast<int>(z_new-
shift);
1555 const int cell_crossings_z = std::abs(k_new-k_old);
1556 num_segments += cell_crossings_z;
1563 const auto dirX_sign =
static_cast<double>(dxp < 0. ? -1. : 1.);
1564 const auto dirY_sign =
static_cast<double>(dyp < 0. ? -1. : 1.);
1565 const auto dirZ_sign =
static_cast<double>(dzp < 0. ? -1. : 1.);
1566 double Xcell = 0., Ycell = 0., Zcell = 0.;
1567 if (num_segments > 1) {
1568 Xcell =
static_cast<double>(i_old) +
shift + 0.5*(1.-dirX_sign);
1569 Ycell =
static_cast<double>(j_old) +
shift + 0.5*(1.-dirY_sign);
1570 Zcell =
static_cast<double>(k_old) +
shift + 0.5*(1.-dirZ_sign);
1576 double dxp_seg, dyp_seg, dzp_seg;
1577 double x0_new, y0_new, z0_new;
1578 double x0_old = x_old;
1579 double y0_old = y_old;
1580 double z0_old = z_old;
1582 for (
int ns=0; ns<num_segments; ns++) {
1584 if (ns == num_segments-1) {
1589 dxp_seg = x0_new - x0_old;
1590 dyp_seg = y0_new - y0_old;
1591 dzp_seg = z0_new - z0_old;
1596 x0_new = Xcell + dirX_sign;
1597 y0_new = Ycell + dirY_sign;
1598 z0_new = Zcell + dirZ_sign;
1599 dxp_seg = x0_new - x0_old;
1600 dyp_seg = y0_new - y0_old;
1601 dzp_seg = z0_new - z0_old;
1603 if ( (dyp == 0. || std::abs(dxp_seg) < std::abs(dxp/dyp*dyp_seg))
1604 && (dzp == 0. || std::abs(dxp_seg) < std::abs(dxp/dzp*dzp_seg)) ) {
1606 dyp_seg = dyp/dxp*dxp_seg;
1607 dzp_seg = dzp/dxp*dxp_seg;
1608 y0_new = y0_old + dyp_seg;
1609 z0_new = z0_old + dzp_seg;
1611 else if (dzp == 0. || std::abs(dyp_seg) < std::abs(dyp/dzp*dzp_seg)) {
1613 dxp_seg = dxp/dyp*dyp_seg;
1614 dzp_seg = dzp/dyp*dyp_seg;
1615 x0_new = x0_old + dxp_seg;
1616 z0_new = z0_old + dzp_seg;
1620 dxp_seg = dxp/dzp*dzp_seg;
1621 dyp_seg = dyp/dzp*dzp_seg;
1622 x0_new = x0_old + dxp_seg;
1623 y0_new = y0_old + dyp_seg;
1629 const auto seg_factor_x =
static_cast<double>(dxp == 0. ? 1. : dxp_seg/dxp);
1630 const auto seg_factor_y =
static_cast<double>(dyp == 0. ? 1. : dyp_seg/dyp);
1631 const auto seg_factor_z =
static_cast<double>(dzp == 0. ? 1. : dzp_seg/dzp);
1634 double sx_cell[depos_order] = {0.};
1635 double sy_cell[depos_order] = {0.};
1636 double sz_cell[depos_order] = {0.};
1637 double const x0_bar = (x0_new + x0_old)/2.0;
1638 double const y0_bar = (y0_new + y0_old)/2.0;
1639 double const z0_bar = (z0_new + z0_old)/2.0;
1640 const int i0_cell = compute_shape_factor_cell( sx_cell, x0_bar-0.5 );
1641 const int j0_cell = compute_shape_factor_cell( sy_cell, y0_bar-0.5 );
1642 const int k0_cell = compute_shape_factor_cell( sz_cell, z0_bar-0.5 );
1644 if constexpr (depos_order >= 3) {
1646 double sx_old_cell[depos_order] = {0.};
1647 double sx_new_cell[depos_order] = {0.};
1648 double sy_old_cell[depos_order] = {0.};
1649 double sy_new_cell[depos_order] = {0.};
1650 double sz_old_cell[depos_order] = {0.};
1651 double sz_new_cell[depos_order] = {0.};
1652 const int i0_cell_2 = compute_shape_factors_cell( sx_old_cell, sx_new_cell, x0_old-0.5, x0_new-0.5 );
1653 const int j0_cell_2 = compute_shape_factors_cell( sy_old_cell, sy_new_cell, y0_old-0.5, y0_new-0.5 );
1654 const int k0_cell_2 = compute_shape_factors_cell( sz_old_cell, sz_new_cell, z0_old-0.5, z0_new-0.5 );
1656 for (
int m=0; m<depos_order; m++) {
1657 sx_cell[m] = (4.0*sx_cell[m] + sx_old_cell[m] + sx_new_cell[m])/6.0;
1658 sy_cell[m] = (4.0*sy_cell[m] + sy_old_cell[m] + sy_new_cell[m])/6.0;
1659 sz_cell[m] = (4.0*sz_cell[m] + sz_old_cell[m] + sz_new_cell[m])/6.0;
1664 double sx_old_node[depos_order+1] = {0.};
1665 double sx_new_node[depos_order+1] = {0.};
1666 double sy_old_node[depos_order+1] = {0.};
1667 double sy_new_node[depos_order+1] = {0.};
1668 double sz_old_node[depos_order+1] = {0.};
1669 double sz_new_node[depos_order+1] = {0.};
1670 const int i0_node = compute_shape_factors_node( sx_old_node, sx_new_node, x0_old, x0_new );
1671 const int j0_node = compute_shape_factors_node( sy_old_node, sy_new_node, y0_old, y0_new );
1672 const int k0_node = compute_shape_factors_node( sz_old_node, sz_new_node, z0_old, z0_new );
1676 for (
int i=0; i<=depos_order-1; i++) {
1677 for (
int j=0; j<=depos_order; j++) {
1678 for (
int k=0; k<=depos_order; k++) {
1679 weight = sx_cell[i]*( sy_old_node[j]*sz_old_node[k]*one_third
1680 + sy_old_node[j]*sz_new_node[k]*one_sixth
1681 + sy_new_node[j]*sz_old_node[k]*one_sixth
1682 + sy_new_node[j]*sz_new_node[k]*one_third )*seg_factor_x;
1683 Exp += Ex_arr(lo.
x+i0_cell+i, lo.
y+j0_node+j, lo.
z+k0_node+k)*weight;
1689 for (
int i=0; i<=depos_order; i++) {
1690 for (
int j=0; j<=depos_order-1; j++) {
1691 for (
int k=0; k<=depos_order; k++) {
1692 weight = sy_cell[j]*( sx_old_node[i]*sz_old_node[k]*one_third
1693 + sx_old_node[i]*sz_new_node[k]*one_sixth
1694 + sx_new_node[i]*sz_old_node[k]*one_sixth
1695 + sx_new_node[i]*sz_new_node[k]*one_third )*seg_factor_y;
1696 Eyp += Ey_arr(lo.
x+i0_node+i, lo.
y+j0_cell+j, lo.
z+k0_node+k)*weight;
1702 for (
int i=0; i<=depos_order; i++) {
1703 for (
int j=0; j<=depos_order; j++) {
1704 for (
int k=0; k<=depos_order-1; k++) {
1705 weight = sz_cell[k]*( sx_old_node[i]*sy_old_node[j]*one_third
1706 + sx_old_node[i]*sy_new_node[j]*one_sixth
1707 + sx_new_node[i]*sy_old_node[j]*one_sixth
1708 + sx_new_node[i]*sy_new_node[j]*one_third )*seg_factor_z;
1709 Ezp += Ez_arr(lo.
x+i0_node+i, lo.
y+j0_node+j, lo.
z+k0_cell+k)*weight;
1715 if (ns < num_segments-1) {
1723#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
1726 const auto i_old =
static_cast<int>(x_old-
shift);
1727 const auto i_new =
static_cast<int>(x_new-
shift);
1728 const int cell_crossings_x = std::abs(i_new-i_old);
1729 num_segments += cell_crossings_x;
1732 const auto k_old =
static_cast<int>(z_old-
shift);
1733 const auto k_new =
static_cast<int>(z_new-
shift);
1734 const int cell_crossings_z = std::abs(k_new-k_old);
1735 num_segments += cell_crossings_z;
1742 const auto dirX_sign =
static_cast<double>(dxp < 0. ? -1. : 1.);
1743 const auto dirZ_sign =
static_cast<double>(dzp < 0. ? -1. : 1.);
1744 double Xcell = 0., Zcell = 0.;
1745 if (num_segments > 1) {
1746 Xcell =
static_cast<double>(i_old) +
shift + 0.5*(1.-dirX_sign);
1747 Zcell =
static_cast<double>(k_old) +
shift + 0.5*(1.-dirZ_sign);
1753 double dxp_seg, dzp_seg;
1754 double x0_new, z0_new;
1755 double x0_old = x_old;
1756 double z0_old = z_old;
1758 for (
int ns=0; ns<num_segments; ns++) {
1760 if (ns == num_segments-1) {
1764 dxp_seg = x0_new - x0_old;
1765 dzp_seg = z0_new - z0_old;
1770 x0_new = Xcell + dirX_sign;
1771 z0_new = Zcell + dirZ_sign;
1772 dxp_seg = x0_new - x0_old;
1773 dzp_seg = z0_new - z0_old;
1775 if (dzp == 0. || std::abs(dxp_seg) < std::abs(dxp/dzp*dzp_seg)) {
1777 dzp_seg = dzp/dxp*dxp_seg;
1778 z0_new = z0_old + dzp_seg;
1782 dxp_seg = dxp/dzp*dzp_seg;
1783 x0_new = x0_old + dxp_seg;
1789 const auto seg_factor_x =
static_cast<double>(dxp == 0. ? 1. : dxp_seg/dxp);
1790 const auto seg_factor_z =
static_cast<double>(dzp == 0. ? 1. : dzp_seg/dzp);
1793 double sx_cell[depos_order] = {0.};
1794 double sz_cell[depos_order] = {0.};
1795 double const x0_bar = (x0_new + x0_old)/2.0;
1796 double const z0_bar = (z0_new + z0_old)/2.0;
1797 const int i0_cell = compute_shape_factor_cell(sx_cell, x0_bar-0.5);
1798 const int k0_cell = compute_shape_factor_cell(sz_cell, z0_bar-0.5);
1800 if constexpr (depos_order >= 3) {
1802 double sx_old_cell[depos_order] = {0.};
1803 double sx_new_cell[depos_order] = {0.};
1804 double sz_old_cell[depos_order] = {0.};
1805 double sz_new_cell[depos_order] = {0.};
1806 const int i0_cell_2 = compute_shape_factors_cell( sx_old_cell, sx_new_cell, x0_old-0.5, x0_new-0.5 );
1807 const int k0_cell_2 = compute_shape_factors_cell( sz_old_cell, sz_new_cell, z0_old-0.5, z0_new-0.5 );
1809 for (
int m=0; m<depos_order; m++) {
1810 sx_cell[m] = (4.0*sx_cell[m] + sx_old_cell[m] + sx_new_cell[m])/6.0;
1811 sz_cell[m] = (4.0*sz_cell[m] + sz_old_cell[m] + sz_new_cell[m])/6.0;
1816 double sx_old_node[depos_order+1] = {0.};
1817 double sx_new_node[depos_order+1] = {0.};
1818 double sz_old_node[depos_order+1] = {0.};
1819 double sz_new_node[depos_order+1] = {0.};
1820 const int i0_node = compute_shape_factors_node( sx_old_node, sx_new_node, x0_old, x0_new );
1821 const int k0_node = compute_shape_factors_node( sz_old_node, sz_new_node, z0_old, z0_new );
1825 for (
int i=0; i<=depos_order-1; i++) {
1826 for (
int k=0; k<=depos_order; k++) {
1827 weight = sx_cell[i]*(sz_old_node[k] + sz_new_node[k])/2.0_rt*seg_factor_x;
1828 Exp += Ex_arr(lo.
x+i0_cell+i, lo.
y+k0_node+k, 0, 0)*weight;
1829#if defined(WARPX_DIM_RZ)
1831 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
1832 const auto dEx = (+ Ex_arr(lo.
x+i0_cell+i, lo.
y+k0_node+k, 0, 2*imode-1)*xy_mid.
real()
1833 - Ex_arr(lo.
x+i0_cell+i, lo.
y+k0_node+k, 0, 2*imode)*xy_mid.
imag());
1835 xy_mid = xy_mid*xy_mid0;
1842 const auto seg_factor_y = std::min(seg_factor_x,seg_factor_z);
1843 for (
int i=0; i<=depos_order; i++) {
1844 for (
int k=0; k<=depos_order; k++) {
1845 weight = ( sx_old_node[i]*sz_old_node[k]*one_third
1846 + sx_old_node[i]*sz_new_node[k]*one_sixth
1847 + sx_new_node[i]*sz_old_node[k]*one_sixth
1848 + sx_new_node[i]*sz_new_node[k]*one_third )*seg_factor_y;
1849 Eyp += Ey_arr(lo.
x+i0_node+i, lo.
y+k0_node+k, 0, 0)*weight;
1850#if defined(WARPX_DIM_RZ)
1852 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
1853 const auto dEy = (+ Ey_arr(lo.
x+i0_node+i, lo.
y+k0_node+k, 0, 2*imode-1)*xy_mid.
real()
1854 - Ey_arr(lo.
x+i0_node+i, lo.
y+k0_node+k, 0, 2*imode)*xy_mid.
imag());
1856 xy_mid = xy_mid*xy_mid0;
1863 for (
int i=0; i<=depos_order; i++) {
1864 for (
int k=0; k<=depos_order-1; k++) {
1865 weight = sz_cell[k]*(sx_old_node[i] + sx_new_node[i])/2.0_rt*seg_factor_z;
1866 Ezp += Ez_arr(lo.
x+i0_node+i, lo.
y+k0_cell+k, 0, 0)*weight;
1867#if defined(WARPX_DIM_RZ)
1869 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
1870 const auto dEz = (+ Ez_arr(lo.
x+i0_node+i, lo.
y+k0_cell+k, 0, 2*imode-1)*xy_mid.
real()
1871 - Ez_arr(lo.
x+i0_node+i, lo.
y+k0_cell+k, 0, 2*imode)*xy_mid.
imag());
1873 xy_mid = xy_mid*xy_mid0;
1880 if (ns < num_segments-1) {
1892 Exp = costheta_mid*Erp - sintheta_mid*Ethp;
1893 Eyp = costheta_mid*Ethp + sintheta_mid*Erp;
1897#elif defined(WARPX_DIM_1D_Z)
1900 const auto k_old =
static_cast<int>(z_old-
shift);
1901 const auto k_new =
static_cast<int>(z_new-
shift);
1902 const int cell_crossings_z = std::abs(k_new-k_old);
1903 num_segments += cell_crossings_z;
1910 const auto dirZ_sign =
static_cast<double>(dzp < 0. ? -1. : 1.);
1911 double Zcell =
static_cast<double>(k_old) +
shift + 0.5*(1.-dirZ_sign);
1918 double z0_old = z_old;
1920 for (
int ns=0; ns<num_segments; ns++) {
1922 if (ns == num_segments-1) {
1924 dzp_seg = z0_new - z0_old;
1927 Zcell = Zcell + dirZ_sign;
1929 dzp_seg = z0_new - z0_old;
1933 const auto seg_factor =
static_cast<double>(dzp == 0. ? 1. : dzp_seg/dzp);
1936 double sz_cell[depos_order] = {0.};
1937 double const z0_bar = (z0_new + z0_old)/2.0;
1938 const int k0_cell = compute_shape_factor_cell( sz_cell, z0_bar-0.5 );
1940 if constexpr (depos_order >= 3) {
1942 double sz_old_cell[depos_order] = {0.};
1943 double sz_new_cell[depos_order] = {0.};
1944 const int k0_cell_2 = compute_shape_factors_cell( sz_old_cell, sz_new_cell, z0_old-0.5, z0_new-0.5 );
1946 for (
int m=0; m<depos_order; m++) {
1947 sz_cell[m] = (4.0*sz_cell[m] + sz_old_cell[m] + sz_new_cell[m])/6.0;
1952 double sz_old_node[depos_order+1] = {0.};
1953 double sz_new_node[depos_order+1] = {0.};
1954 const int k0_node = compute_shape_factors_node( sz_old_node, sz_new_node, z0_old, z0_new );
1957 for (
int k=0; k<=depos_order; k++) {
1958 auto weight = 0.5_rt*(sz_old_node[k] + sz_new_node[k])*seg_factor;
1959 Exp += Ex_arr(lo.
x+k0_node+k, 0, 0)*weight;
1960 Eyp += Ey_arr(lo.
x+k0_node+k, 0, 0)*weight;
1964 for (
int k=0; k<=depos_order-1; k++) {
1965 auto weight = sz_cell[k]*seg_factor;
1966 Ezp += Ez_arr(lo.
x+k0_cell+k, 0, 0)*weight;
1970 if (ns < num_segments-1) {
1976#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
1984 const auto i_old =
static_cast<int>(x_old-
shift);
1985 const auto i_new =
static_cast<int>(x_new-
shift);
1986 const int cell_crossings_x = std::abs(i_new-i_old);
1987 num_segments += cell_crossings_x;
1994 const auto dirX_sign =
static_cast<double>(dxp < 0. ? -1. : 1.);
1995 double Xcell =
static_cast<double>(i_old) +
shift + 0.5*(1.-dirX_sign);
2002 double x0_old = x_old;
2004 for (
int ns=0; ns<num_segments; ns++) {
2006 if (ns == num_segments-1) {
2008 dxp_seg = x0_new - x0_old;
2011 Xcell = Xcell + dirX_sign;
2013 dxp_seg = x0_new - x0_old;
2017 const auto seg_factor =
static_cast<double>(dxp == 0. ? 1. : dxp_seg/dxp);
2020 double sx_cell[depos_order] = {0.};
2021 double const x0_bar = (x0_new + x0_old)/2.0;
2022 const int i0_cell = compute_shape_factor_cell( sx_cell, x0_bar-0.5 );
2024 if constexpr (depos_order >= 3) {
2026 double sx_old_cell[depos_order] = {0.};
2027 double sx_new_cell[depos_order] = {0.};
2028 const int i0_cell_2 = compute_shape_factors_cell( sx_old_cell, sx_new_cell, x0_old-0.5, x0_new-0.5 );
2030 for (
int m=0; m<depos_order; m++) {
2031 sx_cell[m] = (4.0*sx_cell[m] + sx_old_cell[m] + sx_new_cell[m])/6.0;
2036 double sx_old_node[depos_order+1] = {0.};
2037 double sx_new_node[depos_order+1] = {0.};
2038 const int i0_node = compute_shape_factors_node( sx_old_node, sx_new_node, x0_old, x0_new );
2041 for (
int i=0; i<=depos_order; i++) {
2042 auto weight = 0.5_rt*(sx_old_node[i] + sx_new_node[i])*seg_factor;
2043 Ethetap += Ey_arr(lo.
x+i0_node+i, 0, 0)*weight;
2044 E3p += Ez_arr(lo.
x+i0_node+i, 0, 0)*weight;
2048 for (
int i=0; i<=depos_order-1; i++) {
2049 auto weight = sx_cell[i]*seg_factor;
2050 Erp += Ex_arr(lo.
x+i0_cell+i, 0, 0)*weight;
2054 if (ns < num_segments-1) {
2060#if defined(WARPX_DIM_RCYLINDER)
2062 Exp += costheta_mid*Erp - sintheta_mid*Ethetap;
2063 Eyp += costheta_mid*Ethetap + sintheta_mid*Erp;
2066#elif defined(WARPX_DIM_RSPHERE)
2069 Exp += costheta_mid*cosphi_mid*Erp - sintheta_mid*Ethetap - costheta_mid*sinphi_mid*E3p;
2070 Eyp += sintheta_mid*cosphi_mid*Erp + costheta_mid*Ethetap - sintheta_mid*sinphi_mid*E3p;
2071 Ezp += sinphi_mid*Erp + cosphi_mid*E3p;
2080 const int depos_order_perp = 1;
2081 const int depos_order_para = 1;
2083 xp_nph, yp_nph, zp_nph,
2085 Bx_arr, By_arr, Bz_arr,
2086 Bx_type, By_type, Bz_type,
2087 dinv, xyzmin, lo, n_rz_azimuthal_modes );
2133 const int n_rz_azimuthal_modes,
2135 const bool galerkin_interpolation)
2137 if (galerkin_interpolation) {
2139 doGatherShapeN<1,1>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2140 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2141 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2142 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2143 }
else if (nox == 2) {
2144 doGatherShapeN<2,1>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2145 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2146 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2147 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2148 }
else if (nox == 3) {
2149 doGatherShapeN<3,1>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2150 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2151 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2152 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2153 }
else if (nox == 4) {
2154 doGatherShapeN<4,1>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2155 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2156 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2157 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2161 doGatherShapeN<1,0>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2162 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2163 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2164 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2165 }
else if (nox == 2) {
2166 doGatherShapeN<2,0>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2167 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2168 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2169 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2170 }
else if (nox == 3) {
2171 doGatherShapeN<3,0>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2172 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2173 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2174 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2175 }
else if (nox == 4) {
2176 doGatherShapeN<4,0>(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2177 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2178 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2179 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2236 const int n_rz_azimuthal_modes,
2243 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2244 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2245 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2246 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2247 }
else if (nox == 2) {
2249 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2250 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2251 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2252 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2253 }
else if (nox == 3) {
2255 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2256 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2257 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2258 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2259 }
else if (nox == 4) {
2261 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2262 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2263 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2264 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2270 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2271 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2272 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2273 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2274 }
else if (nox == 2) {
2276 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2277 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2278 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2279 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2280 }
else if (nox == 3) {
2282 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2283 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2284 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2285 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2286 }
else if (nox == 4) {
2288 Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2289 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2290 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2291 dinv, xyzmin, domain_double, do_cropping, lo, n_rz_azimuthal_modes);
2296 doGatherShapeN<1,0>(xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2297 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2298 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2299 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2300 }
else if (nox == 2) {
2301 doGatherShapeN<2,0>(xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2302 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2303 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2304 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2305 }
else if (nox == 3) {
2306 doGatherShapeN<3,0>(xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2307 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2308 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2309 dinv, xyzmin, lo, n_rz_azimuthal_modes);
2310 }
else if (nox == 4) {
2311 doGatherShapeN<4,0>(xp_nph, yp_nph, zp_nph, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
2312 ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
2313 ex_type, ey_type, ez_type, bx_type, by_type, bz_type,
2314 dinv, xyzmin, lo, n_rz_azimuthal_modes);