8#ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPOYTINGFLUX_H_
9#define WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPOYTINGFLUX_H_
35#if defined(WARPX_DIM_3D)
36 const amrex::Real EyBx_dn = Ey_arr(i,j,k,comp)*0.5_rt*(Bx_arr(i,j,k-1,comp) + Bx_arr(i,j,k,comp));
37 const amrex::Real EyBx_up = Ey_arr(i+1,j,k,comp)*0.5_rt*(Bx_arr(i+1,j,k-1,comp) + Bx_arr(i+1,j,k,comp));
38 return 0.5_rt*(EyBx_dn + EyBx_up);
39#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
40 const amrex::Real EyBx_dn = Ey_arr(i,j,k,comp)*0.5_rt*(Bx_arr(i,j-1,k,comp) + Bx_arr(i,j,k,comp));
41 const amrex::Real EyBx_up = Ey_arr(i+1,j,k,comp)*0.5_rt*(Bx_arr(i+1,j-1,k,comp) + Bx_arr(i+1,j,k,comp));
42 return 0.5_rt*(EyBx_dn + EyBx_up);
43#elif defined(WARPX_DIM_1D_Z)
44 return Ey_arr(i,j,k,comp)*0.5_rt*(Bx_arr(i-1,j,k,comp) + Bx_arr(i,j,k,comp));
45#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
56#if defined(WARPX_DIM_3D)
57 const amrex::Real ExBy_dn = Ex_arr(i,j,k,comp)*0.5_rt*(By_arr(i,j,k-1,comp) + By_arr(i,j,k,comp));
58 const amrex::Real ExBy_up = Ex_arr(i,j+1,k,comp)*0.5_rt*(By_arr(i,j+1,k-1,comp) + By_arr(i,j+1,k,comp));
59 return 0.5_rt*(ExBy_dn + ExBy_up);
60#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_1D_Z)
61 return Ex_arr(i,j,k,comp)*0.5_rt*(By_arr(i-1,j,k,comp) + By_arr(i,j,k,comp));
62#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
73#if defined(WARPX_DIM_3D)
74 const amrex::Real EzBx_dn = Ez_arr(i,j,k,comp)*0.5_rt*(Bx_arr(i,j-1,k,comp) + Bx_arr(i,j,k,comp));
75 const amrex::Real EzBx_up = Ez_arr(i+1,j,k,comp)*0.5_rt*(Bx_arr(i+1,j-1,k,comp) + Bx_arr(i+1,j,k,comp));
76 return 0.5_rt*(EzBx_dn + EzBx_up);
88#if defined(WARPX_DIM_3D)
89 const amrex::Real ExBz_dn = Ex_arr(i,j,k,comp)*0.5_rt*(Bz_arr(i,j-1,k,comp) + Bz_arr(i,j,k,comp));
90 const amrex::Real ExBz_up = Ex_arr(i,j,k+1,comp)*0.5_rt*(Bz_arr(i,j-1,k+1,comp) + Bz_arr(i,j,k+1,comp));
91 return 0.5_rt*(ExBz_dn + ExBz_up);
103#if defined(WARPX_DIM_3D)
104 const amrex::Real EyBz_dn = Ey_arr(i,j,k,comp)*0.5_rt*(Bz_arr(i-1,j,k,comp) + Bz_arr(i,j,k,comp));
105 const amrex::Real EyBz_up = Ey_arr(i,j,k+1,comp)*0.5_rt*(Bz_arr(i-1,j,k+1,comp) + Bz_arr(i,j,k+1,comp));
106 return 0.5_rt*(EyBz_dn + EyBz_up);
107#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
108 const amrex::Real EyBz_dn = Ey_arr(i,j,k,comp)*0.5_rt*(Bz_arr(i-1,j,k,comp) + Bz_arr(i,j,k,comp));
109 const amrex::Real EyBz_up = Ey_arr(i,j+1,k,comp)*0.5_rt*(Bz_arr(i-1,j+1,k,comp) + Bz_arr(i,j+1,k,comp));
110 return 0.5_rt*(EyBz_dn + EyBz_up);
111#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
112 return Ey_arr(i,j,k,comp)*0.5_rt*(Bz_arr(i-1,j,k,comp) + Bz_arr(i,j,k,comp));
113#elif defined(WARPX_DIM_1D_Z)
124#if defined(WARPX_DIM_3D)
125 const amrex::Real EzBy_dn = Ez_arr(i,j,k,comp)*0.5_rt*(By_arr(i-1,j,k,comp) + By_arr(i,j,k,comp));
126 const amrex::Real EzBy_up = Ez_arr(i,j+1,k,comp)*0.5_rt*(By_arr(i-1,j+1,k,comp) + By_arr(i,j+1,k,comp));
127 return 0.5_rt*(EzBy_dn + EzBy_up);
128#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
129 return Ez_arr(i,j,k,comp)*0.5_rt*(By_arr(i-1,j,k,comp) + By_arr(i,j,k,comp));
130#elif defined(WARPX_DIM_1D_Z)
145#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_1D_Z)
146 return 0.5_rt*(Ey_arr(i,j,k-1,comp)*Bx_arr(i,j,k-1,comp)
147 + Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp));
148#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
159#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_1D_Z)
160 return 0.5_rt*(Ex_arr(i,j,k-1,comp)*By_arr(i,j,k-1,comp)
161 + Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp));
162#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
173#if defined(WARPX_DIM_3D)
174 return 0.5_rt*(Ez_arr(i,j-1,k,comp)*Bx_arr(i,j-1,k,comp)
175 + Ez_arr(i,j,k,comp)*Bx_arr(i,j,k,comp));
187#if defined(WARPX_DIM_3D)
188 return 0.5_rt*(Ex_arr(i,j-1,k,comp)*Bz_arr(i,j-1,k,comp)
189 + Ex_arr(i,j,k,comp)*Bz_arr(i,j,k,comp));
201#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
202 return 0.5_rt*(Ey_arr(i-1,j,k,comp)*Bz_arr(i-1,j,k,comp)
203 + Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp));
204#elif defined(WARPX_DIM_1D_Z)
215#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
216 return 0.5_rt*(Ez_arr(i-1,j,k,comp)*By_arr(i-1,j,k,comp)
217 + Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp));
218#elif defined(WARPX_DIM_1D_Z)
233#if defined(WARPX_DIM_3D)
234 return 0.25_rt*(Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp)
235 + Ey_arr(i+1,j,k,comp)*Bx_arr(i+1,j,k,comp)
236 + Ey_arr(i,j+1,k,comp)*Bx_arr(i,j+1,k,comp)
237 + Ey_arr(i+1,j+1,k,comp)*Bx_arr(i+1,j+1,k,comp));
238#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
239 return 0.5_rt*(Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp) +
240 Ey_arr(i+1,j,k,comp)*Bx_arr(i+1,j,k,comp));
241#elif defined(WARPX_DIM_1D_Z)
242 return Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp);
243#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
254#if defined(WARPX_DIM_3D)
255 return 0.25_rt*(Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp)
256 + Ex_arr(i+1,j,k,comp)*By_arr(i+1,j,k,comp)
257 + Ex_arr(i,j+1,k,comp)*By_arr(i,j+1,k,comp)
258 + Ex_arr(i+1,j+1,k,comp)*By_arr(i+1,j+1,k,comp));
259#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
260 return 0.5_rt*(Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp)
261 + Ex_arr(i+1,j,k,comp)*By_arr(i+1,j,k,comp));
262#elif defined(WARPX_DIM_1D_Z)
263 return Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp);
264#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
275#if defined(WARPX_DIM_3D)
276 return 0.25_rt*(Ez_arr(i,j,k,comp)*Bx_arr(i,j,k,comp)
277 + Ez_arr(i+1,j,k,comp)*Bx_arr(i+1,j,k,comp)
278 + Ez_arr(i,j,k+1,comp)*Bx_arr(i,j,k+1,comp)
279 + Ez_arr(i+1,j,k+1,comp)*Bx_arr(i+1,j,k+1,comp));
291#if defined(WARPX_DIM_3D)
292 return 0.25_rt*(Ex_arr(i,j,k,comp)*Bz_arr(i,j,k,comp)
293 + Ex_arr(i+1,j,k,comp)*Bz_arr(i+1,j,k,comp)
294 + Ex_arr(i,j,k+1,comp)*Bz_arr(i,j,k+1,comp)
295 + Ex_arr(i+1,j,k+1,comp)*Bz_arr(i+1,j,k+1,comp));
307#if defined(WARPX_DIM_3D)
308 return 0.25_rt*(Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp)
309 + Ey_arr(i,j+1,k,comp)*Bz_arr(i,j+1,k,comp)
310 + Ey_arr(i,j,k+1,comp)*Bz_arr(i,j,k+1,comp)
311 + Ey_arr(i,j+1,k+1,comp)*Bz_arr(i,j+1,k+1,comp));
312#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
313 return 0.5_rt*(Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp)
314 + Ey_arr(i,j+1,k,comp)*Bz_arr(i,j+1,k,comp));
315#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
316 return Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp);
317#elif defined(WARPX_DIM_1D_Z)
328#if defined(WARPX_DIM_3D)
329 return 0.25_rt*(Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp)
330 + Ez_arr(i,j+1,k,comp)*By_arr(i,j+1,k,comp)
331 + Ez_arr(i,j,k+1,comp)*By_arr(i,j,k+1,comp)
332 + Ez_arr(i,j+1,k+1,comp)*By_arr(i,j+1,k+1,comp));
333#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
334 return 0.5_rt*(Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp)
335 + Ez_arr(i,j+1,k,comp)*By_arr(i,j+1,k,comp));
336#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
337 return Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp);
338#elif defined(WARPX_DIM_1D_Z)
348 template<
int normal_dir,
typename T_Algo,
typename AreaFunc>
356 AreaFunc area_factor)
362 reduce_ops.
eval(box, reduce_data,
366 constexpr int comp = 0;
373 if constexpr (normal_dir == 0) {
374 return af*(T_Algo::EyBz(i,j,k,comp,Ey_arr,Bz_arr) - T_Algo::EzBy(i,j,k,comp,Ez_arr,By_arr));
377 else if constexpr (normal_dir == 1) {
378 return af*(T_Algo::EzBx(i,j,k,comp,Ez_arr,Bx_arr) - T_Algo::ExBz(i,j,k,comp,Ex_arr,Bz_arr));
381 else if constexpr (normal_dir == 2) {
382 return af*(T_Algo::ExBy(i,j,k,comp,Ex_arr,By_arr) - T_Algo::EyBx(i,j,k,comp,Ey_arr,Bx_arr));
387 auto r = reduce_data.
value();
#define AMREX_GPU_HOST_DEVICE
void WriteCheckpointData(std::string const &dir) final
Write out checkpoint related data.
Definition FieldPoyntingFlux.cpp:312
FieldPoyntingFlux(const std::string &rd_name)
Constructor.
Definition FieldPoyntingFlux.cpp:43
void ComputePoyntingFlux()
This function computes the electromagnetic Poynting flux, obtained by integrating the electromagnetic...
Definition FieldPoyntingFlux.cpp:117
void ReadCheckpointData(std::string const &dir) final
Read in checkpoint related data.
Definition FieldPoyntingFlux.cpp:328
bool use_mid_step_value
Definition FieldPoyntingFlux.H:434
void ComputeDiagsMidStep(int step) final
Call the routine to compute the Poynting flux at the mid step time level.
Definition FieldPoyntingFlux.cpp:110
void ComputeDiags(int step) final
Call the routine to compute the Poynting flux if needed.
Definition FieldPoyntingFlux.cpp:101
ReducedDiags(const std::string &rd_name)
Definition ReducedDiags.cpp:26
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
ArrayND< T, 4, true > Array4
Definition FieldPoyntingFlux.H:346
amrex::Real Kernel(amrex::Box const &box, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &Bx_arr, amrex::Array4< const amrex::Real > const &By_arr, amrex::Array4< const amrex::Real > const &Bz_arr, AreaFunc area_factor)
Definition FieldPoyntingFlux.H:349
__host__ __device__ void ignore_unused(const Ts &...)
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Definition FieldPoyntingFlux.H:138
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EzBy(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &By_arr)
Definition FieldPoyntingFlux.H:211
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EyBx(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Bx_arr)
Definition FieldPoyntingFlux.H:141
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EzBx(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &Bx_arr)
Definition FieldPoyntingFlux.H:169
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real ExBy(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &By_arr)
Definition FieldPoyntingFlux.H:155
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EyBz(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Bz_arr)
Definition FieldPoyntingFlux.H:197
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real ExBz(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &Bz_arr)
Definition FieldPoyntingFlux.H:183
Definition FieldPoyntingFlux.H:226
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real ExBz(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &Bz_arr)
Definition FieldPoyntingFlux.H:287
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EyBz(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Bz_arr)
Definition FieldPoyntingFlux.H:303
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EzBy(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &By_arr)
Definition FieldPoyntingFlux.H:324
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EzBx(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &Bx_arr)
Definition FieldPoyntingFlux.H:271
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real ExBy(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &By_arr)
Definition FieldPoyntingFlux.H:250
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EyBx(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Bx_arr)
Definition FieldPoyntingFlux.H:229
Definition FieldPoyntingFlux.H:21
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real ExBy(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &By_arr)
Definition FieldPoyntingFlux.H:52
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real ExBz(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ex_arr, amrex::Array4< const amrex::Real > const &Bz_arr)
Definition FieldPoyntingFlux.H:84
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EzBx(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &Bx_arr)
Definition FieldPoyntingFlux.H:69
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EyBz(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Bz_arr)
Definition FieldPoyntingFlux.H:99
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EzBy(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ez_arr, amrex::Array4< const amrex::Real > const &By_arr)
Definition FieldPoyntingFlux.H:120
AMREX_GPU_HOST_DEVICE static AMREX_INLINE amrex::Real EyBx(int i, int j, int k, int comp, amrex::Array4< const amrex::Real > const &Ey_arr, amrex::Array4< const amrex::Real > const &Bx_arr)
Definition FieldPoyntingFlux.H:31