ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_AdvectionSrcForScalars.H
Go to the documentation of this file.
1 #ifndef ERF_ADVECTION_SRC_FOR_SCALARS_H_
2 #define ERF_ADVECTION_SRC_FOR_SCALARS_H_
3 
4 #include <AMReX.H>
5 
6 #include <ERF_IndexDefines.H>
7 #include <ERF_Interpolation.H>
8 
9 /**
10  * Build scalar face fluxes with a selected pair of interpolation policies.
11  *
12  * @tparam InterpType_H horizontal interpolation type
13  * @tparam InterpType_V vertical interpolation type
14  * @tparam FaceValue write face values instead of fluxes
15  * @param[in] bx cell-centered box over which scalar fluxes are computed
16  * @param[in] scalar supplied cell-centered scalar view
17  * @param[in] scalar_comp component of the supplied scalar view to reconstruct
18  * @param[out] flx_arr face-flux views
19  * @param[in] flux_comp component of the supplied face-flux views to write
20  * @param[in] avg_xmom x-component of time-averaged mass flux
21  * @param[in] avg_ymom y-component of time-averaged mass flux
22  * @param[in] avg_zmom z-component of time-averaged mass flux
23  * @param[in] upw_x x-face field whose sign picks the upwind side (the mass flux, or a direction)
24  * @param[in] upw_y y-face field whose sign picks the upwind side
25  * @param[in] upw_z z-face field whose sign picks the upwind side
26  * @param[in] horiz_upw_frac horizontal upwind blending fraction
27  * @param[in] vert_upw_frac vertical upwind blending fraction
28  */
29 template<typename InterpType_H, typename InterpType_V, bool FaceValue = false>
30 inline void
32  const amrex::Box& bx,
33  const amrex::Array4<const amrex::Real>& scalar,
34  const int scalar_comp,
35  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
36  const int flux_comp,
37  const amrex::Array4<const amrex::Real>& avg_xmom,
38  const amrex::Array4<const amrex::Real>& avg_ymom,
39  const amrex::Array4<const amrex::Real>& avg_zmom,
40  const amrex::Array4<const amrex::Real>& upw_x,
41  const amrex::Array4<const amrex::Real>& upw_y,
42  const amrex::Array4<const amrex::Real>& upw_z,
43  const amrex::Real horiz_upw_frac,
44  const amrex::Real vert_upw_frac)
45 {
46  InterpType_H interp_h(scalar, horiz_upw_frac);
47  InterpType_V interp_v(scalar, vert_upw_frac);
48 
49  const amrex::Box xbx = amrex::surroundingNodes(bx,0);
50  const amrex::Box ybx = amrex::surroundingNodes(bx,1);
51  const amrex::Box zbx = amrex::surroundingNodes(bx,2);
52 
53  amrex::ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
54  {
55  amrex::Real interpx(zero);
56  interp_h.InterpolateInX(i,j,k,scalar_comp,interpx,upw_x(i,j,k));
57  flx_arr[0](i,j,k,flux_comp) = FaceValue ? interpx : avg_xmom(i,j,k) * interpx;
58  });
59  amrex::ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
60  {
61  amrex::Real interpy(zero);
62  interp_h.InterpolateInY(i,j,k,scalar_comp,interpy,upw_y(i,j,k));
63  flx_arr[1](i,j,k,flux_comp) = FaceValue ? interpy : avg_ymom(i,j,k) * interpy;
64  });
65  amrex::ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
66  {
67  amrex::Real interpz(zero);
68  interp_v.InterpolateInZ(i,j,k,scalar_comp,interpz,upw_z(i,j,k));
69  flx_arr[2](i,j,k,flux_comp) = FaceValue ? interpz : avg_zmom(i,j,k) * interpz;
70  });
71 }
72 
73 /**
74  * Build centered-second-order scalar face fluxes without a reconstruction temporary.
75  *
76  * @tparam FaceValue write face values instead of fluxes
77  * @param[in] bx cell-centered box over which scalar fluxes are computed
78  * @param[in] scalar supplied cell-centered scalar view
79  * @param[in] scalar_comp component of the supplied scalar view to reconstruct
80  * @param[out] flx_arr face-flux views
81  * @param[in] flux_comp component of the supplied face-flux views to write
82  * @param[in] avg_xmom x-component of time-averaged mass flux
83  * @param[in] avg_ymom y-component of time-averaged mass flux
84  * @param[in] avg_zmom z-component of time-averaged mass flux
85  */
86 template<bool FaceValue = false>
87 inline void
89  const amrex::Box& bx,
90  const amrex::Array4<const amrex::Real>& scalar,
91  const int scalar_comp,
92  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
93  const int flux_comp,
94  const amrex::Array4<const amrex::Real>& avg_xmom,
95  const amrex::Array4<const amrex::Real>& avg_ymom,
96  const amrex::Array4<const amrex::Real>& avg_zmom)
97 {
98  const amrex::Box xbx = amrex::surroundingNodes(bx,0);
99  const amrex::Box ybx = amrex::surroundingNodes(bx,1);
100  const amrex::Box zbx = amrex::surroundingNodes(bx,2);
101 
102  amrex::ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
103  {
104  const amrex::Real scalar_on_face = myhalf *
105  (scalar(i,j,k,scalar_comp) + scalar(i-1,j,k,scalar_comp));
106  flx_arr[0](i,j,k,flux_comp) = FaceValue ? scalar_on_face : avg_xmom(i,j,k) * scalar_on_face;
107  });
108  amrex::ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
109  {
110  const amrex::Real scalar_on_face = myhalf *
111  (scalar(i,j,k,scalar_comp) + scalar(i,j-1,k,scalar_comp));
112  flx_arr[1](i,j,k,flux_comp) = FaceValue ? scalar_on_face : avg_ymom(i,j,k) * scalar_on_face;
113  });
114  amrex::ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
115  {
116  const amrex::Real scalar_on_face = myhalf *
117  (scalar(i,j,k,scalar_comp) + scalar(i,j,k-1,scalar_comp));
118  flx_arr[2](i,j,k,flux_comp) = FaceValue ? scalar_on_face : avg_zmom(i,j,k) * scalar_on_face;
119  });
120 }
121 
122 /**
123  * Dispatch scalar face-flux construction for a selected vertical scheme.
124  *
125  * @tparam InterpType_H horizontal interpolation type
126  * @tparam FaceValue write face values instead of fluxes
127  * @param[in] bx cell-centered box over which scalar fluxes are computed
128  * @param[in] scalar supplied scalar view
129  * @param[in] scalar_comp component of the supplied scalar view to reconstruct
130  * @param[out] flx_arr face-flux views
131  * @param[in] flux_comp component of the supplied face-flux views to write
132  * @param[in] avg_xmom x-component of time-averaged mass flux
133  * @param[in] avg_ymom y-component of time-averaged mass flux
134  * @param[in] avg_zmom z-component of time-averaged mass flux
135  * @param[in] upw_x x-face field whose sign picks the upwind side (the mass flux, or a direction)
136  * @param[in] upw_y y-face field whose sign picks the upwind side
137  * @param[in] upw_z z-face field whose sign picks the upwind side
138  * @param[in] horiz_upw_frac horizontal upwind blending fraction
139  * @param[in] vert_upw_frac vertical upwind blending fraction
140  * @param[in] vert_adv_type vertical advection scheme
141  */
142 template<typename InterpType_H, bool FaceValue = false>
143 inline void
145  const amrex::Box& bx,
146  const amrex::Array4<const amrex::Real>& scalar,
147  const int scalar_comp,
148  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
149  const int flux_comp,
150  const amrex::Array4<const amrex::Real>& avg_xmom,
151  const amrex::Array4<const amrex::Real>& avg_ymom,
152  const amrex::Array4<const amrex::Real>& avg_zmom,
153  const amrex::Array4<const amrex::Real>& upw_x,
154  const amrex::Array4<const amrex::Real>& upw_y,
155  const amrex::Array4<const amrex::Real>& upw_z,
156  const amrex::Real horiz_upw_frac,
157  const amrex::Real vert_upw_frac,
158  const AdvType vert_adv_type)
159 {
160  switch (vert_adv_type) {
162  BuildScalarAdvectionFluxesWithPolicy<InterpType_H,CENTERED2,FaceValue>(
163  bx, scalar, scalar_comp, flx_arr, flux_comp,
164  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
165  break;
166  case AdvType::Upwind_3rd:
167  BuildScalarAdvectionFluxesWithPolicy<InterpType_H,UPWIND3,FaceValue>(
168  bx, scalar, scalar_comp, flx_arr, flux_comp,
169  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
170  break;
172  BuildScalarAdvectionFluxesWithPolicy<InterpType_H,UPWIND3SL,FaceValue>(
173  bx, scalar, scalar_comp, flx_arr, flux_comp,
174  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
175  break;
177  BuildScalarAdvectionFluxesWithPolicy<InterpType_H,CENTERED4,FaceValue>(
178  bx, scalar, scalar_comp, flx_arr, flux_comp,
179  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
180  break;
181  case AdvType::Upwind_5th:
182  BuildScalarAdvectionFluxesWithPolicy<InterpType_H,UPWIND5,FaceValue>(
183  bx, scalar, scalar_comp, flx_arr, flux_comp,
184  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
185  break;
187  BuildScalarAdvectionFluxesWithPolicy<InterpType_H,CENTERED6,FaceValue>(
188  bx, scalar, scalar_comp, flx_arr, flux_comp,
189  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
190  break;
191  default:
192  // Not an assert: under NDEBUG that would compile away and leave the
193  // face fluxes unwritten, so the divergence below would silently
194  // consume whatever stale data is in this flux component. Note that
195  // the WENO schemes have no vertical-only variant -- they must be
196  // selected for both the horizontal and the vertical direction.
197  amrex::Abort("Unknown or unsupported vertical advection scheme!");
198  }
199 }
200 
201 /**
202  * Dispatch shared by BuildScalarAdvectionFluxes (FaceValue = false: write the mass flux times
203  * the reconstructed face value) and BuildScalarAdvectionFaceValues (FaceValue = true: write the
204  * reconstructed face value itself).
205  *
206  * @tparam FaceValue write face values instead of fluxes
207  * @param[in] bx cell-centered box over which scalar fluxes are computed
208  * @param[in] scalar supplied cell-centered scalar view
209  * @param[in] scalar_comp component of the supplied scalar view to reconstruct
210  * @param[out] flx_arr face-flux (or face-value) views
211  * @param[in] flux_comp component of the supplied face views to write
212  * @param[in] avg_xmom x-component of time-averaged mass flux
213  * @param[in] avg_ymom y-component of time-averaged mass flux
214  * @param[in] avg_zmom z-component of time-averaged mass flux
215  * @param[in] upw_x x-face field whose sign picks the upwind side (the mass flux, or a direction)
216  * @param[in] upw_y y-face field whose sign picks the upwind side
217  * @param[in] upw_z z-face field whose sign picks the upwind side
218  * @param[in] horiz_adv_type horizontal advection scheme
219  * @param[in] vert_adv_type vertical advection scheme
220  * @param[in] horiz_upw_frac horizontal upwind blending fraction
221  * @param[in] vert_upw_frac vertical upwind blending fraction
222  */
223 template<bool FaceValue>
224 inline void
226  const amrex::Box& bx,
227  const amrex::Array4<const amrex::Real>& scalar,
228  const int scalar_comp,
229  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
230  const int flux_comp,
231  const amrex::Array4<const amrex::Real>& avg_xmom,
232  const amrex::Array4<const amrex::Real>& avg_ymom,
233  const amrex::Array4<const amrex::Real>& avg_zmom,
234  const amrex::Array4<const amrex::Real>& upw_x,
235  const amrex::Array4<const amrex::Real>& upw_y,
236  const amrex::Array4<const amrex::Real>& upw_z,
237  const AdvType horiz_adv_type,
238  const AdvType vert_adv_type,
239  const amrex::Real horiz_upw_frac,
240  const amrex::Real vert_upw_frac)
241 {
242  if (horiz_adv_type == AdvType::Centered_2nd &&
243  vert_adv_type == AdvType::Centered_2nd) {
244  BuildScalarAdvectionFluxesCentered2<FaceValue>(
245  bx, scalar, scalar_comp, flx_arr, flux_comp,
246  avg_xmom, avg_ymom, avg_zmom);
247  return;
248  }
249 
250  switch (horiz_adv_type) {
252  BuildScalarAdvectionFluxesVert<CENTERED2,FaceValue>(
253  bx, scalar, scalar_comp, flx_arr, flux_comp,
254  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac, vert_adv_type);
255  break;
256  case AdvType::Upwind_3rd:
257  BuildScalarAdvectionFluxesVert<UPWIND3,FaceValue>(
258  bx, scalar, scalar_comp, flx_arr, flux_comp,
259  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac, vert_adv_type);
260  break;
262  BuildScalarAdvectionFluxesVert<UPWIND3SL,FaceValue>(
263  bx, scalar, scalar_comp, flx_arr, flux_comp,
264  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac, vert_adv_type);
265  break;
267  BuildScalarAdvectionFluxesVert<CENTERED4,FaceValue>(
268  bx, scalar, scalar_comp, flx_arr, flux_comp,
269  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac, vert_adv_type);
270  break;
271  case AdvType::Upwind_5th:
272  BuildScalarAdvectionFluxesVert<UPWIND5,FaceValue>(
273  bx, scalar, scalar_comp, flx_arr, flux_comp,
274  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac, vert_adv_type);
275  break;
277  BuildScalarAdvectionFluxesVert<CENTERED6,FaceValue>(
278  bx, scalar, scalar_comp, flx_arr, flux_comp,
279  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac, vert_adv_type);
280  break;
281  case AdvType::Weno_3:
282  BuildScalarAdvectionFluxesWithPolicy<WENO3,WENO3,FaceValue>(
283  bx, scalar, scalar_comp, flx_arr, flux_comp,
284  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
285  break;
286  case AdvType::Weno_5:
287  BuildScalarAdvectionFluxesWithPolicy<WENO5,WENO5,FaceValue>(
288  bx, scalar, scalar_comp, flx_arr, flux_comp,
289  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
290  break;
291  case AdvType::Weno_7:
292  BuildScalarAdvectionFluxesWithPolicy<WENO7,WENO7,FaceValue>(
293  bx, scalar, scalar_comp, flx_arr, flux_comp,
294  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
295  break;
296  case AdvType::Weno_3Z:
297  BuildScalarAdvectionFluxesWithPolicy<WENO_Z3,WENO_Z3,FaceValue>(
298  bx, scalar, scalar_comp, flx_arr, flux_comp,
299  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
300  break;
301  case AdvType::Weno_3MZQ:
302  BuildScalarAdvectionFluxesWithPolicy<WENO_MZQ3,WENO_MZQ3,FaceValue>(
303  bx, scalar, scalar_comp, flx_arr, flux_comp,
304  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
305  break;
306  case AdvType::Weno_5Z:
307  BuildScalarAdvectionFluxesWithPolicy<WENO_Z5,WENO_Z5,FaceValue>(
308  bx, scalar, scalar_comp, flx_arr, flux_comp,
309  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
310  break;
311  case AdvType::Weno_7Z:
312  BuildScalarAdvectionFluxesWithPolicy<WENO_Z7,WENO_Z7,FaceValue>(
313  bx, scalar, scalar_comp, flx_arr, flux_comp,
314  avg_xmom, avg_ymom, avg_zmom, upw_x, upw_y, upw_z, horiz_upw_frac, vert_upw_frac);
315  break;
316  default:
317  // See the note in BuildScalarAdvectionFluxesVert: an assert here would
318  // vanish under NDEBUG and leave stale fluxes in place of an error.
319  amrex::Abort("Unknown horizontal advection scheme!");
320  }
321 }
322 
323 /**
324  * Build scalar face fluxes using ERF's compile-time interpolation policies.
325  * WENO schemes intentionally use the same policy horizontally and vertically,
326  * matching the existing native scalar-advection dispatch.
327  *
328  * @param[in] bx cell-centered box over which scalar fluxes are computed
329  * @param[in] scalar supplied cell-centered scalar view
330  * @param[in] scalar_comp component of the supplied scalar view to reconstruct
331  * @param[out] flx_arr face-flux views
332  * @param[in] flux_comp component of the supplied face-flux views to write
333  * @param[in] avg_xmom x-component of time-averaged mass flux
334  * @param[in] avg_ymom y-component of time-averaged mass flux
335  * @param[in] avg_zmom z-component of time-averaged mass flux
336  * @param[in] horiz_adv_type horizontal advection scheme
337  * @param[in] vert_adv_type vertical advection scheme
338  * @param[in] horiz_upw_frac horizontal upwind blending fraction
339  * @param[in] vert_upw_frac vertical upwind blending fraction
340  */
341 inline void
343  const amrex::Box& bx,
344  const amrex::Array4<const amrex::Real>& scalar,
345  const int scalar_comp,
346  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
347  const int flux_comp,
348  const amrex::Array4<const amrex::Real>& avg_xmom,
349  const amrex::Array4<const amrex::Real>& avg_ymom,
350  const amrex::Array4<const amrex::Real>& avg_zmom,
351  const AdvType horiz_adv_type,
352  const AdvType vert_adv_type,
353  const amrex::Real horiz_upw_frac,
354  const amrex::Real vert_upw_frac)
355 {
356  BuildScalarAdvectionFluxesImpl<false>(bx, scalar, scalar_comp, flx_arr, flux_comp,
357  avg_xmom, avg_ymom, avg_zmom,
358  avg_xmom, avg_ymom, avg_zmom,
359  horiz_adv_type, vert_adv_type,
360  horiz_upw_frac, vert_upw_frac);
361 }
362 
363 /**
364  * As above, but with the upwind side on each face picked from the sign of upw_x, upw_y and
365  * upw_z instead of the sign of the mass flux. A pseudo-incompressible level passes the upwind
366  * direction its projection set (see ERF::pi_upw_dir), so that theta is reconstructed on each face
367  * exactly as the projection reconstructed rho0 theta0 / rho.
368  *
369  * @param[in] bx cell-centered box over which scalar fluxes are computed
370  * @param[in] scalar supplied cell-centered scalar view
371  * @param[in] scalar_comp component of the supplied scalar view to reconstruct
372  * @param[out] flx_arr face-flux views
373  * @param[in] flux_comp component of the supplied face-flux views to write
374  * @param[in] avg_xmom x-component of time-averaged mass flux
375  * @param[in] avg_ymom y-component of time-averaged mass flux
376  * @param[in] avg_zmom z-component of time-averaged mass flux
377  * @param[in] upw_x x-face field whose sign picks the upwind side
378  * @param[in] upw_y y-face field whose sign picks the upwind side
379  * @param[in] upw_z z-face field whose sign picks the upwind side
380  * @param[in] horiz_adv_type horizontal advection scheme
381  * @param[in] vert_adv_type vertical advection scheme
382  * @param[in] horiz_upw_frac horizontal upwind blending fraction
383  * @param[in] vert_upw_frac vertical upwind blending fraction
384  */
385 inline void
387  const amrex::Box& bx,
388  const amrex::Array4<const amrex::Real>& scalar,
389  const int scalar_comp,
390  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
391  const int flux_comp,
392  const amrex::Array4<const amrex::Real>& avg_xmom,
393  const amrex::Array4<const amrex::Real>& avg_ymom,
394  const amrex::Array4<const amrex::Real>& avg_zmom,
395  const amrex::Array4<const amrex::Real>& upw_x,
396  const amrex::Array4<const amrex::Real>& upw_y,
397  const amrex::Array4<const amrex::Real>& upw_z,
398  const AdvType horiz_adv_type,
399  const AdvType vert_adv_type,
400  const amrex::Real horiz_upw_frac,
401  const amrex::Real vert_upw_frac)
402 {
403  BuildScalarAdvectionFluxesImpl<false>(bx, scalar, scalar_comp, flx_arr, flux_comp,
404  avg_xmom, avg_ymom, avg_zmom,
405  upw_x, upw_y, upw_z,
406  horiz_adv_type, vert_adv_type,
407  horiz_upw_frac, vert_upw_frac);
408 }
409 
410 /**
411  * The face values of a cell-centered field that BuildScalarAdvectionFluxes would multiply by
412  * the mass flux: the same reconstruction, chosen by the same scheme and upwind fraction, with
413  * the upwind side picked from the sign of the given mass flux (every scheme uses only its sign,
414  * and a zero flux selects the centered blend, as in advection). Writes the face values instead
415  * of the fluxes.
416  *
417  * @param[in] bx cell-centered box over whose faces the values are computed
418  * @param[in] scalar supplied cell-centered field view
419  * @param[in] scalar_comp component of the supplied field view to reconstruct
420  * @param[out] face_arr face-value views
421  * @param[in] face_comp component of the supplied face-value views to write
422  * @param[in] xflux x-face mass flux (its sign picks the upwind side)
423  * @param[in] yflux y-face mass flux (its sign picks the upwind side)
424  * @param[in] zflux z-face mass flux (its sign picks the upwind side)
425  * @param[in] horiz_adv_type horizontal advection scheme
426  * @param[in] vert_adv_type vertical advection scheme
427  * @param[in] horiz_upw_frac horizontal upwind blending fraction
428  * @param[in] vert_upw_frac vertical upwind blending fraction
429  */
430 inline void
432  const amrex::Box& bx,
433  const amrex::Array4<const amrex::Real>& scalar,
434  const int scalar_comp,
435  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& face_arr,
436  const int face_comp,
437  const amrex::Array4<const amrex::Real>& xflux,
438  const amrex::Array4<const amrex::Real>& yflux,
439  const amrex::Array4<const amrex::Real>& zflux,
440  const AdvType horiz_adv_type,
441  const AdvType vert_adv_type,
442  const amrex::Real horiz_upw_frac,
443  const amrex::Real vert_upw_frac)
444 {
445  BuildScalarAdvectionFluxesImpl<true>(bx, scalar, scalar_comp, face_arr, face_comp,
446  xflux, yflux, zflux,
447  xflux, yflux, zflux,
448  horiz_adv_type, vert_adv_type,
449  horiz_upw_frac, vert_upw_frac);
450 
451 }
452 
453 /**
454  * Apply the mapped divergence of component-selected scalar face fluxes.
455  *
456  * @param[in] bx cell-centered box over which the tendency is computed
457  * @param[in] flx_arr face-flux views
458  * @param[in] flux_comp component of the supplied face-flux views to read
459  * @param[out] rhs supplied tendency view
460  * @param[in] rhs_comp component of the supplied tendency view to write
461  * @param[in] detJ metric Jacobian
462  * @param[in] cellSizeInv inverse grid spacing
463  * @param[in] mf_mx x map factor at cell centers
464  * @param[in] mf_my y map factor at cell centers
465  */
466 inline void
468  const amrex::Box& bx,
469  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
470  const int flux_comp,
471  const amrex::Array4<amrex::Real>& rhs,
472  const int rhs_comp,
473  const amrex::Array4<const amrex::Real>& detJ,
474  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
475  const amrex::Array4<const amrex::Real>& mf_mx,
476  const amrex::Array4<const amrex::Real>& mf_my)
477 {
478  const auto dxInv = cellSizeInv[0];
479  const auto dyInv = cellSizeInv[1];
480  const auto dzInv = cellSizeInv[2];
481 
482  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
483  {
484  if (detJ(i,j,k) > zero) {
485  const amrex::Real invdetJ = one / detJ(i,j,k);
486  const amrex::Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
487  rhs(i,j,k,rhs_comp) = - invdetJ * mfsq * (
488  (flx_arr[0](i+1,j,k,flux_comp) - flx_arr[0](i,j,k,flux_comp)) * dxInv +
489  (flx_arr[1](i,j+1,k,flux_comp) - flx_arr[1](i,j,k,flux_comp)) * dyInv +
490  (flx_arr[2](i,j,k+1,flux_comp) - flx_arr[2](i,j,k,flux_comp)) * dzInv);
491  } else {
492  rhs(i,j,k,rhs_comp) = zero;
493  }
494  });
495 }
496 
497 #endif // ERF_ADVECTION_SRC_FOR_SCALARS_H_
void BuildScalarAdvectionFaceValues(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &face_arr, const int face_comp, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac)
Definition: ERF_AdvectionSrcForScalars.H:431
void BuildScalarAdvectionFluxesCentered2(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const int flux_comp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom)
Definition: ERF_AdvectionSrcForScalars.H:88
void BuildScalarAdvectionFluxes(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const int flux_comp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac)
Definition: ERF_AdvectionSrcForScalars.H:342
void BuildScalarAdvectionFluxesWithPolicy(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const int flux_comp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &upw_x, const amrex::Array4< const amrex::Real > &upw_y, const amrex::Array4< const amrex::Real > &upw_z, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac)
Definition: ERF_AdvectionSrcForScalars.H:31
void BuildScalarAdvectionFluxesVert(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const int flux_comp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &upw_x, const amrex::Array4< const amrex::Real > &upw_y, const amrex::Array4< const amrex::Real > &upw_z, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const AdvType vert_adv_type)
Definition: ERF_AdvectionSrcForScalars.H:144
void BuildScalarAdvectionFluxesImpl(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const int flux_comp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &upw_x, const amrex::Array4< const amrex::Real > &upw_y, const amrex::Array4< const amrex::Real > &upw_z, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac)
Definition: ERF_AdvectionSrcForScalars.H:225
void ApplyScalarAdvectionFluxDivergence(const amrex::Box &bx, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const int flux_comp, const amrex::Array4< amrex::Real > &rhs, const int rhs_comp, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
Definition: ERF_AdvectionSrcForScalars.H:467
AdvType
Definition: ERF_IndexDefines.H:329
@ Upwind_3rd_SL
@ Centered_4th
@ Centered_6th
@ Centered_2nd
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41