8#ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPOYTINGFLUX_H_
9#define WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPOYTINGFLUX_H_
21using namespace amrex::literals;
33 static amrex::Real
EyBx(
int i,
int j,
int k,
int comp,
36#if defined(WARPX_DIM_3D)
37 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));
38 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));
39 return 0.5_rt*(EyBx_dn + EyBx_up);
40#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
41 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));
42 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));
43 return 0.5_rt*(EyBx_dn + EyBx_up);
44#elif defined(WARPX_DIM_1D_Z)
45 return Ey_arr(i,j,k,comp)*0.5_rt*(Bx_arr(i-1,j,k,comp) + Bx_arr(i,j,k,comp));
46#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
53 static amrex::Real
ExBy(
int i,
int j,
int k,
int comp,
56#if defined(WARPX_DIM_3D)
57 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 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)
69 static amrex::Real
EzBx(
int i,
int j,
int k,
int comp,
72#if defined(WARPX_DIM_3D)
73 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));
74 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));
75 return 0.5_rt*(EzBx_dn + EzBx_up);
83 static amrex::Real
ExBz(
int i,
int j,
int k,
int comp,
86#if defined(WARPX_DIM_3D)
87 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));
88 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));
89 return 0.5_rt*(ExBz_dn + ExBz_up);
97 static amrex::Real
EyBz(
int i,
int j,
int k,
int comp,
100#if defined(WARPX_DIM_3D)
101 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));
102 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));
103 return 0.5_rt*(EyBz_dn + EyBz_up);
104#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
105 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));
106 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));
107 return 0.5_rt*(EyBz_dn + EyBz_up);
108#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
109 return Ey_arr(i,j,k,comp)*0.5_rt*(Bz_arr(i-1,j,k,comp) + Bz_arr(i,j,k,comp));
110#elif defined(WARPX_DIM_1D_Z)
117 static amrex::Real
EzBy(
int i,
int j,
int k,
int comp,
120#if defined(WARPX_DIM_3D)
121 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));
122 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));
123 return 0.5_rt*(EzBy_dn + EzBy_up);
124#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
125 return Ez_arr(i,j,k,comp)*0.5_rt*(By_arr(i-1,j,k,comp) + By_arr(i,j,k,comp));
126#elif defined(WARPX_DIM_1D_Z)
137 static amrex::Real
EyBx(
int i,
int j,
int k,
int comp,
140#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_1D_Z)
141 return 0.5_rt*(Ey_arr(i,j,k-1,comp)*Bx_arr(i,j,k-1,comp)
142 + Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp));
143#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
150 static amrex::Real
ExBy(
int i,
int j,
int k,
int comp,
153#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_1D_Z)
154 return 0.5_rt*(Ex_arr(i,j,k-1,comp)*By_arr(i,j,k-1,comp)
155 + Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp));
156#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
163 static amrex::Real
EzBx(
int i,
int j,
int k,
int comp,
166#if defined(WARPX_DIM_3D)
167 return 0.5_rt*(Ez_arr(i,j-1,k,comp)*Bx_arr(i,j-1,k,comp)
168 + Ez_arr(i,j,k,comp)*Bx_arr(i,j,k,comp));
176 static amrex::Real
ExBz(
int i,
int j,
int k,
int comp,
179#if defined(WARPX_DIM_3D)
180 return 0.5_rt*(Ex_arr(i,j-1,k,comp)*Bz_arr(i,j-1,k,comp)
181 + Ex_arr(i,j,k,comp)*Bz_arr(i,j,k,comp));
189 static amrex::Real
EyBz(
int i,
int j,
int k,
int comp,
192#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
193 return 0.5_rt*(Ey_arr(i-1,j,k,comp)*Bz_arr(i-1,j,k,comp)
194 + Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp));
195#elif defined(WARPX_DIM_1D_Z)
202 static amrex::Real
EzBy(
int i,
int j,
int k,
int comp,
205#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
206 return 0.5_rt*(Ez_arr(i-1,j,k,comp)*By_arr(i-1,j,k,comp)
207 + Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp));
208#elif defined(WARPX_DIM_1D_Z)
219 static amrex::Real
EyBx(
int i,
int j,
int k,
int comp,
222#if defined(WARPX_DIM_3D)
223 return 0.25_rt*(Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp)
224 + Ey_arr(i+1,j,k,comp)*Bx_arr(i+1,j,k,comp)
225 + Ey_arr(i,j+1,k,comp)*Bx_arr(i,j+1,k,comp)
226 + Ey_arr(i+1,j+1,k,comp)*Bx_arr(i+1,j+1,k,comp));
227#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
228 return 0.5_rt*(Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp) +
229 Ey_arr(i+1,j,k,comp)*Bx_arr(i+1,j,k,comp));
230#elif defined(WARPX_DIM_1D_Z)
231 return Ey_arr(i,j,k,comp)*Bx_arr(i,j,k,comp);
232#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
239 static amrex::Real
ExBy(
int i,
int j,
int k,
int comp,
242#if defined(WARPX_DIM_3D)
243 return 0.25_rt*(Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp)
244 + Ex_arr(i+1,j,k,comp)*By_arr(i+1,j,k,comp)
245 + Ex_arr(i,j+1,k,comp)*By_arr(i,j+1,k,comp)
246 + Ex_arr(i+1,j+1,k,comp)*By_arr(i+1,j+1,k,comp));
247#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
248 return 0.5_rt*(Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp)
249 + Ex_arr(i+1,j,k,comp)*By_arr(i+1,j,k,comp));
250#elif defined(WARPX_DIM_1D_Z)
251 return Ex_arr(i,j,k,comp)*By_arr(i,j,k,comp);
252#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
259 static amrex::Real
EzBx(
int i,
int j,
int k,
int comp,
262#if defined(WARPX_DIM_3D)
263 return 0.25_rt*(Ez_arr(i,j,k,comp)*Bx_arr(i,j,k,comp)
264 + Ez_arr(i+1,j,k,comp)*Bx_arr(i+1,j,k,comp)
265 + Ez_arr(i,j,k+1,comp)*Bx_arr(i,j,k+1,comp)
266 + Ez_arr(i+1,j,k+1,comp)*Bx_arr(i+1,j,k+1,comp));
274 static amrex::Real
ExBz(
int i,
int j,
int k,
int comp,
277#if defined(WARPX_DIM_3D)
278 return 0.25_rt*(Ex_arr(i,j,k,comp)*Bz_arr(i,j,k,comp)
279 + Ex_arr(i+1,j,k,comp)*Bz_arr(i+1,j,k,comp)
280 + Ex_arr(i,j,k+1,comp)*Bz_arr(i,j,k+1,comp)
281 + Ex_arr(i+1,j,k+1,comp)*Bz_arr(i+1,j,k+1,comp));
289 static amrex::Real
EyBz(
int i,
int j,
int k,
int comp,
292#if defined(WARPX_DIM_3D)
293 return 0.25_rt*(Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp)
294 + Ey_arr(i,j+1,k,comp)*Bz_arr(i,j+1,k,comp)
295 + Ey_arr(i,j,k+1,comp)*Bz_arr(i,j,k+1,comp)
296 + Ey_arr(i,j+1,k+1,comp)*Bz_arr(i,j+1,k+1,comp));
297#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
298 return 0.5_rt*(Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp)
299 + Ey_arr(i,j+1,k,comp)*Bz_arr(i,j+1,k,comp));
300#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
301 return Ey_arr(i,j,k,comp)*Bz_arr(i,j,k,comp);
302#elif defined(WARPX_DIM_1D_Z)
309 static amrex::Real
EzBy(
int i,
int j,
int k,
int comp,
312#if defined(WARPX_DIM_3D)
313 return 0.25_rt*(Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp)
314 + Ez_arr(i,j+1,k,comp)*By_arr(i,j+1,k,comp)
315 + Ez_arr(i,j,k+1,comp)*By_arr(i,j,k+1,comp)
316 + Ez_arr(i,j+1,k+1,comp)*By_arr(i,j+1,k+1,comp));
317#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
318 return 0.5_rt*(Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp)
319 + Ez_arr(i,j+1,k,comp)*By_arr(i,j+1,k,comp));
320#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
321 return Ez_arr(i,j,k,comp)*By_arr(i,j,k,comp);
322#elif defined(WARPX_DIM_1D_Z)
332 template<
int normal_dir,
typename T_Algo,
typename AreaFunc>
340 AreaFunc area_factor)
346 reduce_ops.
eval(box, reduce_data,
350 constexpr int comp = 0;
356 amrex::Real
const af = area_factor(i,j,k);
357 if constexpr (normal_dir == 0) {
358 return af*(T_Algo::EyBz(i,j,k,comp,Ey_arr,Bz_arr) - T_Algo::EzBy(i,j,k,comp,Ez_arr,By_arr));
361 else if constexpr (normal_dir == 1) {
362 return af*(T_Algo::EzBx(i,j,k,comp,Ez_arr,Bx_arr) - T_Algo::ExBz(i,j,k,comp,Ex_arr,Bz_arr));
365 else if constexpr (normal_dir == 2) {
366 return af*(T_Algo::ExBy(i,j,k,comp,Ex_arr,By_arr) - T_Algo::EyBx(i,j,k,comp,Ey_arr,Bx_arr));
371 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:418
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)
Definition FieldPoyntingFlux.H:330
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:333
__host__ __device__ void ignore_unused(const Ts &...)
__host__ __device__ constexpr GpuTupleElement< I, GpuTuple< Ts... > >::type & get(GpuTuple< Ts... > &tup) noexcept
Definition FieldPoyntingFlux.H:134
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:202
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:137
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:163
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:150
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:189
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:176
Definition FieldPoyntingFlux.H:216
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:274
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:289
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:309
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:259
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:239
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:219
Definition FieldPoyntingFlux.H:23
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:53
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:83
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:97
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:117
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:33