ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Advection.H
Go to the documentation of this file.
1 #ifndef ERF_ADVECTION_H_
2 #define ERF_ADVECTION_H_
3 
4 #include "AMReX.H"
5 #include "AMReX_MultiFab.H"
6 #include "AMReX_iMultiFab.H"
7 #include "AMReX_BCRec.H"
8 #include "AMReX_YAFluxRegister.H"
9 
10 #include "ERF_DataStruct.H"
11 #include "ERF_IndexDefines.H"
12 #include "ERF_SurfaceLayer.H"
13 #include "ERF_EB.H"
14 
15 /** Compute advection tendency for density and averaged momentum fluxes */
16 void AdvectionSrcForRho (const amrex::Box& bx,
17  const amrex::Array4<amrex::Real>& src,
18  const amrex::Array4<const amrex::Real>& rho_u, // These are being used
19  const amrex::Array4<const amrex::Real>& rho_v, // to define the fluxes
20  const amrex::Array4<const amrex::Real>& omega,
21  const amrex::Array4< amrex::Real>& avg_xmom, // These are being defined
22  const amrex::Array4< amrex::Real>& avg_ymom, // from the rho fluxes
23  const amrex::Array4< amrex::Real>& avg_zmom,
24  const amrex::Array4<const amrex::Real>& ax_arr,
25  const amrex::Array4<const amrex::Real>& ay_arr,
26  const amrex::Array4<const amrex::Real>& az_arr,
27  const amrex::Array4<const amrex::Real>& detJ,
28  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
29  const amrex::Array4<const amrex::Real>& mf_mx,
30  const amrex::Array4<const amrex::Real>& mf_my,
31  const amrex::Array4<const amrex::Real>& mf_uy,
32  const amrex::Array4<const amrex::Real>& mf_vx,
33  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
34  const bool fixed_rho);
35 
36 /** Compute advection tendencies for cell-centered scalar components */
37 void AdvectionSrcForScalars (const amrex::Box& bx,
38  const int icomp, const int ncomp,
39  const amrex::Array4<const amrex::Real>& avg_xmom,
40  const amrex::Array4<const amrex::Real>& avg_ymom,
41  const amrex::Array4<const amrex::Real>& avg_zmom,
42  const amrex::Array4<const amrex::Real>& upw_x,
43  const amrex::Array4<const amrex::Real>& upw_y,
44  const amrex::Array4<const amrex::Real>& upw_z,
45  const amrex::Array4<const amrex::Real>& cell_prim,
46  const amrex::Array4<amrex::Real>& src,
47  const amrex::Array4<const amrex::Real>& vf_arr,
48  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
49  const amrex::Array4<const amrex::Real>& mf_mx,
50  const amrex::Array4<const amrex::Real>& mf_my,
51  const AdvType horiz_adv_type, const AdvType vert_adv_type,
52  const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
53  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
54  const amrex::Box& domain,
55  const amrex::BCRec* bc_ptr_h);
56 
57 /** Compute advection tendencies for all components of momentum */
58 void AdvectionSrcForMom (const amrex::MFIter& mfi,
59  const amrex::Box& bxx, const amrex::Box& bxy, const amrex::Box& bxz,
60  const amrex::Vector<amrex::Box>& bxx_grown,
61  const amrex::Vector<amrex::Box>& bxy_grown,
62  const amrex::Vector<amrex::Box>& bxz_grown,
63  const amrex::Array4< amrex::Real>& rho_u_rhs, const amrex::Array4< amrex::Real>& rho_v_rhs,
64  const amrex::Array4< amrex::Real>& rho_w_rhs,
65  const amrex::Array4<const amrex::Real>& rho,
66  const amrex::Array4<const amrex::Real>& u , const amrex::Array4<const amrex::Real>& v,
67  const amrex::Array4<const amrex::Real>& w ,
68  const amrex::Array4<const amrex::Real>& rho_u , const amrex::Array4<const amrex::Real>& rho_v,
69  const amrex::Array4<const amrex::Real>& Omega ,
70  const amrex::Array4<const amrex::Real>& z_nd,
71  const amrex::Array4<const amrex::Real>& ax,
72  const amrex::Array4<const amrex::Real>& ay,
73  const amrex::Array4<const amrex::Real>& az,
74  const amrex::Array4<const amrex::Real>& detJ,
75  amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_d,
76  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
77  const amrex::Array4<const amrex::Real>& mf_mx,
78  const amrex::Array4<const amrex::Real>& mf_ux,
79  const amrex::Array4<const amrex::Real>& mf_vx,
80  const amrex::Array4<const amrex::Real>& mf_my,
81  const amrex::Array4<const amrex::Real>& mf_uy,
82  const amrex::Array4<const amrex::Real>& mf_vy,
83  const AdvType horiz_adv_type, const AdvType vert_adv_type,
84  const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
85  MeshType& mesh_type, TerrainType& terrain_type,
86  const eb_& ebfact,
87  amrex::GpuArray<amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_u_arr,
88  amrex::GpuArray<amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_v_arr,
89  amrex::GpuArray<amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_w_arr,
90  const amrex::Vector<amrex::iMultiFab>& physbnd_mask,
91  const bool already_on_centroids,
92  const int lo_z_face, const int hi_z_face,
93  const amrex::Box& domain,
94  const amrex::BCRec* bc_ptr_h);
95 
96 /** Compute advection tendencies for all components of momentum when dz is constant */
98  const amrex::Box& bxx, const amrex::Box& bxy, const amrex::Box& bxz,
99  const amrex::Array4< amrex::Real>& rho_u_rhs, const amrex::Array4< amrex::Real>& rho_v_rhs,
100  const amrex::Array4< amrex::Real>& rho_w_rhs,
101  const amrex::Array4<const amrex::Real>& u , const amrex::Array4<const amrex::Real>& v,
102  const amrex::Array4<const amrex::Real>& w ,
103  const amrex::Array4<const amrex::Real>& rho_u , const amrex::Array4<const amrex::Real>& rho_v,
104  const amrex::Array4<const amrex::Real>& Omega ,
105  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
106  const amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_d,
107  const amrex::Array4<const amrex::Real>& mf_mx,
108  const amrex::Array4<const amrex::Real>& mf_ux,
109  const amrex::Array4<const amrex::Real>& mf_vx,
110  const amrex::Array4<const amrex::Real>& mf_my,
111  const amrex::Array4<const amrex::Real>& mf_uy,
112  const amrex::Array4<const amrex::Real>& mf_vy,
113  const AdvType horiz_adv_type, const AdvType vert_adv_type,
114  const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
115  TerrainType& terrain_type,
116  const int lo_z_face, const int hi_z_face);
117 
118 /** Compute advection tendencies for all components of momentum when dz is stretched */
120  const amrex::Box& bxx, const amrex::Box& bxy, const amrex::Box& bxz,
121  const amrex::Array4< amrex::Real>& rho_u_rhs, const amrex::Array4< amrex::Real>& rho_v_rhs,
122  const amrex::Array4< amrex::Real>& rho_w_rhs,
123  const amrex::Array4<const amrex::Real>& u , const amrex::Array4<const amrex::Real>& v,
124  const amrex::Array4<const amrex::Real>& w ,
125  const amrex::Array4<const amrex::Real>& rho_u , const amrex::Array4<const amrex::Real>& rho_v,
126  const amrex::Array4<const amrex::Real>& Omega ,
127  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
128  const amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_d,
129  const amrex::Array4<const amrex::Real>& mf_mx,
130  const amrex::Array4<const amrex::Real>& mf_ux,
131  const amrex::Array4<const amrex::Real>& mf_vx,
132  const amrex::Array4<const amrex::Real>& mf_my,
133  const amrex::Array4<const amrex::Real>& mf_uy,
134  const amrex::Array4<const amrex::Real>& mf_vy,
135  const AdvType horiz_adv_type, const AdvType vert_adv_type,
136  const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
137  const int lo_z_face, const int hi_z_face);
138 
139 /** Compute advection tendencies for all components of momentum for TERRAIN-FITTED COORDS only */
141  const amrex::Box& bxx, const amrex::Box& bxy, const amrex::Box& bxz,
142  const amrex::Array4< amrex::Real>& rho_u_rhs, const amrex::Array4< amrex::Real>& rho_v_rhs,
143  const amrex::Array4< amrex::Real>& rho_w_rhs,
144  const amrex::Array4<const amrex::Real>& u , const amrex::Array4<const amrex::Real>& v,
145  const amrex::Array4<const amrex::Real>& w ,
146  const amrex::Array4<const amrex::Real>& rho_u , const amrex::Array4<const amrex::Real>& rho_v,
147  const amrex::Array4<const amrex::Real>& Omega ,
148  const amrex::Array4<const amrex::Real>& z_nd,
149  const amrex::Array4<const amrex::Real>& ax,
150  const amrex::Array4<const amrex::Real>& ay,
151  const amrex::Array4<const amrex::Real>& az,
152  const amrex::Array4<const amrex::Real>& detJ,
153  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
154  const amrex::Array4<const amrex::Real>& mf_mx,
155  const amrex::Array4<const amrex::Real>& mf_ux,
156  const amrex::Array4<const amrex::Real>& mf_vx,
157  const amrex::Array4<const amrex::Real>& mf_my,
158  const amrex::Array4<const amrex::Real>& mf_uy,
159  const amrex::Array4<const amrex::Real>& mf_vy,
160  const AdvType horiz_adv_type, const AdvType vert_adv_type,
161  const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
162  const int lo_z_face, const int hi_z_face);
163 
164 /** Compute advection tendencies for all components of momentum when using EB for terrain */
165 void AdvectionSrcForMom_EB (const amrex::MFIter& mfi,
166  const amrex::Box& bxx, const amrex::Box& bxy, const amrex::Box& bxz,
167  const amrex::Vector<amrex::Box>& bxx_grown,
168  const amrex::Vector<amrex::Box>& bxy_grown,
169  const amrex::Vector<amrex::Box>& bxz_grown,
170  const amrex::Array4< amrex::Real>& rho_u_rhs, const amrex::Array4< amrex::Real>& rho_v_rhs,
171  const amrex::Array4< amrex::Real>& rho_w_rhs,
172  const amrex::Array4<const amrex::Real>& u , const amrex::Array4<const amrex::Real>& v,
173  const amrex::Array4<const amrex::Real>& w ,
174  const amrex::Array4<const amrex::Real>& rho_u , const amrex::Array4<const amrex::Real>& rho_v,
175  const amrex::Array4<const amrex::Real>& Omega ,
176  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
177  const amrex::Array4<const amrex::Real>& mf_mx,
178  const amrex::Array4<const amrex::Real>& mf_ux,
179  const amrex::Array4<const amrex::Real>& mf_vx,
180  const amrex::Array4<const amrex::Real>& mf_my,
181  const amrex::Array4<const amrex::Real>& mf_uy,
182  const amrex::Array4<const amrex::Real>& mf_vy,
183  const AdvType horiz_adv_type, const AdvType vert_adv_type,
184  const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
185  const eb_& ebfact,
186  amrex::GpuArray<amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_u_arr,
187  amrex::GpuArray<amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_v_arr,
188  amrex::GpuArray<amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_w_arr,
189  const amrex::Vector<amrex::iMultiFab>& physbnd_mask,
190  const bool already_on_centroids,
191  const int lo_z_face, const int hi_z_face,
192  const amrex::Box& domain);
193 
194 /**
195  * Shrink a z-momentum box away from the bottom and top of the domain, where no
196  * z-momentum source term is computed.
197  *
198  * The shrink must be applied only at an end that actually coincides with the domain,
199  * which is why this takes `domain` rather than shrinking unconditionally: on a grid
200  * decomposed in z, an unconditional shrink also removes the w-face at every internal
201  * split, and any operator run on the result silently skips those faces.
202  *
203  * `b` is z-nodal; `domain` is cell-centered.
204  */
205 inline amrex::Box
206 ShrinkZmomBoxAtDomainEnds (amrex::Box b, const amrex::Box& domain)
207 {
208  if (b.smallEnd(2) == domain.smallEnd(2)) { b.growLo(2,-1); }
209  if (b.bigEnd(2) == domain.bigEnd(2) + 1) { b.growHi(2,-1); }
210  return b;
211 }
212 
213 /**
214  * Which side of the domain is open in one coordinate direction, as seen by the
215  * cells an open-boundary kernel is about to update.
216  */
217 enum struct OpenSide : int { lo = -1, none = 0, hi = 1 };
218 
219 /** One box on an open lateral boundary, tagged with the side(s) that are open there. */
220 struct OpenBCPatch {
221  amrex::Box box;
224 };
225 
226 /**
227  * Remove from an open-boundary box the cells that also sit on a perpendicular
228  * open boundary, so that no cell is updated by two different open-boundary kernels.
229  *
230  * `b` is trimmed in dimension `dim` only at an end that actually coincides with the
231  * corresponding end of `domain`. The domain-level open flags by themselves are not a
232  * sufficient test: `b` is a per-box (or per-tile) slab whose ends generally lie in
233  * the interior, and trimming those would silently drop interior cells from the
234  * open-boundary treatment and make the answer depend on the grid decomposition.
235  *
236  * `domain` is cell-centered; the index of the boundary is taken in the index space
237  * of `b`, which may be node-centered in `dim`.
238  */
239 inline amrex::Box
240 TrimOpenBCCorner (amrex::Box b,
241  const int dim,
242  const amrex::Box& domain,
243  const bool lo_open,
244  const bool hi_open)
245 {
246  if (!b.ok()) { return b; }
247 
248  const int dom_lo = domain.smallEnd(dim);
249  const int dom_hi = domain.bigEnd(dim) + (b.ixType().nodeCentered(dim) ? 1 : 0);
250 
251  if (lo_open && b.smallEnd(dim) == dom_lo) { b.growLo(dim,-1); }
252  if (hi_open && b.bigEnd(dim) == dom_hi) { b.growHi(dim,-1); }
253 
254  return b;
255 }
256 
257 /**
258  * Build the one-cell-wide box where the `x_side` and `y_side` open boundaries meet,
259  * or an empty box if `b` does not reach both of them.
260  */
261 inline amrex::Box
262 OpenBCCornerBox (amrex::Box b,
263  const amrex::Box& domain,
264  const OpenSide x_side,
265  const OpenSide y_side)
266 {
267  AMREX_ALWAYS_ASSERT(x_side != OpenSide::none && y_side != OpenSide::none);
268 
269  if (!b.ok()) { return amrex::Box(); }
270 
271  const OpenSide side[2] = {x_side, y_side};
272  for (int dim(0); dim < 2; ++dim) {
273  const int idx = (side[dim] == OpenSide::lo) ?
274  domain.smallEnd(dim) :
275  domain.bigEnd(dim) + (b.ixType().nodeCentered(dim) ? 1 : 0);
276  if (idx < b.smallEnd(dim) || idx > b.bigEnd(dim)) { return amrex::Box(); }
277  b = amrex::makeSlab(b, dim, idx);
278  }
279 
280  return b;
281 }
282 
283 /**
284  * Enumerate the boxes on which the open-boundary tangential operator must be applied
285  * for a quantity that has no boundary-normal owner at a lateral corner -- that is,
286  * w and the cell-centered state, both of which are tangent to every lateral boundary.
287  *
288  * The returned boxes are disjoint and together cover every cell of `b` that lies on an
289  * open lateral boundary: the four edges, trimmed so they do not reach into a corner,
290  * plus the corners themselves, which carry both sides so the kernel differences across
291  * neither open boundary there.
292  */
293 inline amrex::Vector<OpenBCPatch>
294 OpenBCTangentPatches (const amrex::Box& b,
295  const amrex::Box& domain,
296  const bool xlo_open,
297  const bool xhi_open,
298  const bool ylo_open,
299  const bool yhi_open)
300 {
301  amrex::Vector<OpenBCPatch> patches;
302  if (!b.ok()) { return patches; }
303  patches.reserve(8);
304 
305  const int dom_xhi = domain.bigEnd(0) + (b.ixType().nodeCentered(0) ? 1 : 0);
306  const int dom_yhi = domain.bigEnd(1) + (b.ixType().nodeCentered(1) ? 1 : 0);
307 
308  // Edges: each is trimmed by the open boundaries perpendicular to it, which own
309  // the corner cells by way of the corner patches added below.
310  if (xlo_open && b.smallEnd(0) == domain.smallEnd(0)) {
311  amrex::Box e = TrimOpenBCCorner(amrex::makeSlab(b,0,domain.smallEnd(0)), 1, domain, ylo_open, yhi_open);
312  if (e.ok()) { patches.push_back({e, OpenSide::lo, OpenSide::none}); }
313  }
314  if (xhi_open && b.bigEnd(0) == dom_xhi) {
315  amrex::Box e = TrimOpenBCCorner(amrex::makeSlab(b,0,dom_xhi), 1, domain, ylo_open, yhi_open);
316  if (e.ok()) { patches.push_back({e, OpenSide::hi, OpenSide::none}); }
317  }
318  if (ylo_open && b.smallEnd(1) == domain.smallEnd(1)) {
319  amrex::Box e = TrimOpenBCCorner(amrex::makeSlab(b,1,domain.smallEnd(1)), 0, domain, xlo_open, xhi_open);
320  if (e.ok()) { patches.push_back({e, OpenSide::none, OpenSide::lo}); }
321  }
322  if (yhi_open && b.bigEnd(1) == dom_yhi) {
323  amrex::Box e = TrimOpenBCCorner(amrex::makeSlab(b,1,dom_yhi), 0, domain, xlo_open, xhi_open);
324  if (e.ok()) { patches.push_back({e, OpenSide::none, OpenSide::hi}); }
325  }
326 
327  // Corners
328  for (OpenSide x_side : {OpenSide::lo, OpenSide::hi}) {
329  if (!((x_side == OpenSide::lo) ? xlo_open : xhi_open)) { continue; }
330  for (OpenSide y_side : {OpenSide::lo, OpenSide::hi}) {
331  if (!((y_side == OpenSide::lo) ? ylo_open : yhi_open)) { continue; }
332  amrex::Box c = OpenBCCornerBox(b, domain, x_side, y_side);
333  if (c.ok()) { patches.push_back({c, x_side, y_side}); }
334  }
335  }
336 
337  return patches;
338 }
339 
340 /** Compute advection tendencies for all normal components of momentum */
341 void
342 AdvectionSrcForOpenBC_Normal (const amrex::Box& bx,
343  const int& dir,
344  const amrex::Array4< amrex::Real>& rhs_arr,
345  const amrex::Array4<const amrex::Real>& vel_norm_arr,
346  const amrex::Array4<const amrex::Real>& cell_data_arr,
347  const amrex::Array4<const amrex::Real>& mf_norm,
348  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxInv,
349  const bool do_lo=false);
350 
351 /** Compute advection tendencies for u momentum tangent to open BC */
352 void
353 AdvectionSrcForOpenBC_Tangent_Xmom (const amrex::Box& bxx,
354  const int& dir,
355  const amrex::Array4< amrex::Real>& rho_u_rhs,
356  const amrex::Array4<const amrex::Real>& u,
357  const amrex::Array4<const amrex::Real>& rho_u,
358  const amrex::Array4<const amrex::Real>& rho_v,
359  const amrex::Array4<const amrex::Real>& Omega,
360  const amrex::Array4<const amrex::Real>& ax,
361  const amrex::Array4<const amrex::Real>& az,
362  const amrex::Array4<const amrex::Real>& detJ,
363  const amrex::Array4<const amrex::Real>& mf_ux,
364  const amrex::Array4<const amrex::Real>& mf_uy,
365  const amrex::Array4<const amrex::Real>& mf_vx,
366  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
367  const bool do_lo=false);
368 
369 /** Compute advection tendencies for v momentum tangent to open BC */
370 void
371 AdvectionSrcForOpenBC_Tangent_Ymom (const amrex::Box& bxy,
372  const int& dir,
373  const amrex::Array4< amrex::Real>& rho_v_rhs,
374  const amrex::Array4<const amrex::Real>& v,
375  const amrex::Array4<const amrex::Real>& rho_u,
376  const amrex::Array4<const amrex::Real>& rho_v,
377  const amrex::Array4<const amrex::Real>& Omega,
378  const amrex::Array4<const amrex::Real>& ay,
379  const amrex::Array4<const amrex::Real>& az,
380  const amrex::Array4<const amrex::Real>& detJ,
381  const amrex::Array4<const amrex::Real>& mf_vx,
382  const amrex::Array4<const amrex::Real>& mf_vy,
383  const amrex::Array4<const amrex::Real>& mf_uy,
384  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
385  const bool do_lo=false);
386 
387 /** Compute advection tendencies for w momentum tangent to open BC
388  * `x_side` and `y_side` say which lateral boundaries the cells being updated lie on;
389  * both are set at a corner, where neither direction may be differenced across. */
390 void
391 AdvectionSrcForOpenBC_Tangent_Zmom (const amrex::Box& bxz,
392  const OpenSide x_side,
393  const OpenSide y_side,
394  const amrex::Array4< amrex::Real>& rho_w_rhs,
395  const amrex::Array4<const amrex::Real>& w,
396  const amrex::Array4<const amrex::Real>& rho_u,
397  const amrex::Array4<const amrex::Real>& rho_v,
398  const amrex::Array4<const amrex::Real>& Omega,
399  const amrex::Array4<const amrex::Real>& ax,
400  const amrex::Array4<const amrex::Real>& ay,
401  const amrex::Array4<const amrex::Real>& az,
402  const amrex::Array4<const amrex::Real>& detJ,
403  const amrex::Array4<const amrex::Real>& mf_mx,
404  const amrex::Array4<const amrex::Real>& mf_my,
405  const amrex::Array4<const amrex::Real>& mf_uy,
406  const amrex::Array4<const amrex::Real>& mf_vx,
407  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
408  const int domhi_z);
409 
410 /** Compute advection tendencies for scalar fields tangential to open BC.
411  *
412  * @param[in] bx box over which scalar tendencies are updated
413  * @param[in] x_side lateral x boundary, if any
414  * @param[in] y_side lateral y boundary, if any
415  * @param[in] scalar_icomp first component of the supplied scalar view to read
416  * @param[in] rhs_icomp first component of the supplied tendency view to write
417  * @param[in] ncomp number of components to update
418  * @param[out] rhs tendency view
419  * @param[in] scalar supplied scalar view
420  * @param[in] avg_xmom x-component of time-averaged mass flux
421  * @param[in] avg_ymom y-component of time-averaged mass flux
422  * @param[in] avg_zmom z-component of time-averaged mass flux
423  * @param[in] detJ metric Jacobian
424  * @param[in] mf_mx x map factor at cell centers
425  * @param[in] mf_my y map factor at cell centers
426  * @param[in] cellSizeInv inverse grid spacing
427  *
428  * At a corner both sides are set, so neither direction is differenced across
429  * its open boundary.
430  */
431 void
433  const OpenSide x_side,
434  const OpenSide y_side,
435  const int scalar_icomp,
436  const int rhs_icomp,
437  const int ncomp,
438  const amrex::Array4< amrex::Real>& rhs,
439  const amrex::Array4<const amrex::Real>& scalar,
440  const amrex::Array4<const amrex::Real>& avg_xmom,
441  const amrex::Array4<const amrex::Real>& avg_ymom,
442  const amrex::Array4<const amrex::Real>& avg_zmom,
443  const amrex::Array4<const amrex::Real>& detJ,
444  const amrex::Array4<const amrex::Real>& mf_mx,
445  const amrex::Array4<const amrex::Real>& mf_my,
446  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv);
447 
448 /** Compute advection tendencies for conserved variables tangential to open BC
449  * `x_side` and `y_side` say which lateral boundaries the cells being updated lie on;
450  * both are set at a corner, where neither direction may be differenced across.
451  * This native adapter maps conserved component `icomp + n` to primitive component
452  * `icomp + n - 1` before calling the component-explicit scalar operation. */
453 void
455  const OpenSide x_side,
456  const OpenSide y_side,
457  const int& icomp,
458  const int& ncomp,
459  const amrex::Array4< amrex::Real>& cell_rhs,
460  const amrex::Array4<const amrex::Real>& cell_prim,
461  const amrex::Array4<const amrex::Real>& avg_xmom,
462  const amrex::Array4<const amrex::Real>& avg_ymom,
463  const amrex::Array4<const amrex::Real>& avg_zmom,
464  const amrex::Array4<const amrex::Real>& detJ,
465  const amrex::Array4<const amrex::Real>& mf_mx,
466  const amrex::Array4<const amrex::Real>& mf_my,
467  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv);
468 
469 /** Compute advection tendencies in the normal direction for variables tangent to open BC */
470 AMREX_GPU_HOST_DEVICE
471 AMREX_FORCE_INLINE
472 amrex::Real
474  const int& j,
475  const int& k,
476  const int& nprim,
477  const int& dir,
478  const amrex::Array4<const amrex::Real>& prim_tang_arr,
479  const amrex::Array4<const amrex::Real>& mom_norm_arr,
480  const amrex::Array4<const amrex::Real>& mf_norm,
481  const amrex::Real& dxInv,
482  const bool do_lo,
483  const bool avg_x,
484  const bool avg_y,
485  const bool avg_z);
486 
487 /** Return the effective advection type used for the requested Runge-Kutta stage. */
488 AMREX_GPU_HOST_DEVICE
489 AMREX_FORCE_INLINE
490 AdvType
491 EfficientAdvType (int nrk, AdvType adv_type)
492 {
493  AdvType eff_adv_type;
494 
495  if (nrk == 0) {
496 
497  eff_adv_type = AdvType::Centered_2nd;
498 
499  } else if (nrk == 1) {
500 
501  if ( (adv_type == AdvType::Centered_2nd) ||
502  (adv_type == AdvType::Upwind_3rd) ||
503  (adv_type == AdvType::Centered_4th) ||
504  (adv_type == AdvType::Weno_3) ||
505  (adv_type == AdvType::Weno_3Z) ||
506  (adv_type == AdvType::Weno_3MZQ) )
507  {
508  eff_adv_type = AdvType::Centered_2nd;
509 
510  } else if ( (adv_type == AdvType::Upwind_5th) ||
511  (adv_type == AdvType::Weno_5) ||
512  (adv_type == AdvType::Weno_5Z) )
513  {
514  eff_adv_type = AdvType::Upwind_3rd;
515 
516  } else { // (adv_type == AdvType::Centered_6th)
517 
518  eff_adv_type = AdvType::Centered_4th;
519  }
520 
521  } else {
522 
523  eff_adv_type = adv_type;
524  }
525 
526  return(eff_adv_type);
527 }
528 #endif
void AdvectionSrcForMom(const amrex::MFIter &mfi, const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Vector< amrex::Box > &bxx_grown, const amrex::Vector< amrex::Box > &bxy_grown, const amrex::Vector< amrex::Box > &bxz_grown, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &rho, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &az, const amrex::Array4< const amrex::Real > &detJ, amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, MeshType &mesh_type, TerrainType &terrain_type, const eb_ &ebfact, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_u_arr, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_v_arr, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_w_arr, const amrex::Vector< amrex::iMultiFab > &physbnd_mask, const bool already_on_centroids, const int lo_z_face, const int hi_z_face, const amrex::Box &domain, const amrex::BCRec *bc_ptr_h)
void AdvectionSrcForRho(const amrex::Box &bx, const amrex::Array4< amrex::Real > &src, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &omega, const amrex::Array4< amrex::Real > &avg_xmom, const amrex::Array4< amrex::Real > &avg_ymom, const amrex::Array4< amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &ax_arr, const amrex::Array4< const amrex::Real > &ay_arr, const amrex::Array4< const amrex::Real > &az_arr, 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, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const bool fixed_rho)
void AdvectionSrcForScalars(const amrex::Box &bx, const int icomp, const int ncomp, 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::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &src, const amrex::Array4< const amrex::Real > &vf_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const amrex::Box &domain, const amrex::BCRec *bc_ptr_h)
amrex::Box TrimOpenBCCorner(amrex::Box b, const int dim, const amrex::Box &domain, const bool lo_open, const bool hi_open)
Definition: ERF_Advection.H:240
void AdvectionSrcForOpenBC_Tangent_Cons(const amrex::Box &bx, const OpenSide x_side, const OpenSide y_side, const int &icomp, const int &ncomp, const amrex::Array4< amrex::Real > &cell_rhs, const amrex::Array4< const amrex::Real > &cell_prim, 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 > &detJ, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv)
amrex::Vector< OpenBCPatch > OpenBCTangentPatches(const amrex::Box &b, const amrex::Box &domain, const bool xlo_open, const bool xhi_open, const bool ylo_open, const bool yhi_open)
Definition: ERF_Advection.H:294
OpenSide
Definition: ERF_Advection.H:217
void AdvectionSrcForMom_EB(const amrex::MFIter &mfi, const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Vector< amrex::Box > &bxx_grown, const amrex::Vector< amrex::Box > &bxy_grown, const amrex::Vector< amrex::Box > &bxz_grown, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const eb_ &ebfact, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_u_arr, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_v_arr, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_w_arr, const amrex::Vector< amrex::iMultiFab > &physbnd_mask, const bool already_on_centroids, const int lo_z_face, const int hi_z_face, const amrex::Box &domain)
void AdvectionSrcForMom_StretchedDz(const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const int lo_z_face, const int hi_z_face)
void AdvectionSrcForOpenBC_Tangent_Scalars(const amrex::Box &bx, const OpenSide x_side, const OpenSide y_side, const int scalar_icomp, const int rhs_icomp, const int ncomp, const amrex::Array4< amrex::Real > &rhs, const amrex::Array4< const amrex::Real > &scalar, 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 > &detJ, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv)
void AdvectionSrcForMom_TF(const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &az, 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_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const int lo_z_face, const int hi_z_face)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real AdvectionSrcForOpenBC_Tangent(const int &i, const int &j, const int &k, const int &nprim, const int &dir, const amrex::Array4< const amrex::Real > &prim_tang_arr, const amrex::Array4< const amrex::Real > &mom_norm_arr, const amrex::Array4< const amrex::Real > &mf_norm, const amrex::Real &dxInv, const bool do_lo, const bool avg_x, const bool avg_y, const bool avg_z)
void AdvectionSrcForOpenBC_Tangent_Ymom(const amrex::Box &bxy, const int &dir, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &az, const amrex::Array4< const amrex::Real > &detJ, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const bool do_lo=false)
void AdvectionSrcForOpenBC_Tangent_Xmom(const amrex::Box &bxx, const int &dir, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &az, const amrex::Array4< const amrex::Real > &detJ, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const bool do_lo=false)
void AdvectionSrcForMom_ConstantDz(const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, TerrainType &terrain_type, const int lo_z_face, const int hi_z_face)
void AdvectionSrcForOpenBC_Tangent_Zmom(const amrex::Box &bxz, const OpenSide x_side, const OpenSide y_side, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &az, const amrex::Array4< const amrex::Real > &detJ, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const int domhi_z)
amrex::Box OpenBCCornerBox(amrex::Box b, const amrex::Box &domain, const OpenSide x_side, const OpenSide y_side)
Definition: ERF_Advection.H:262
void AdvectionSrcForOpenBC_Normal(const amrex::Box &bx, const int &dir, const amrex::Array4< amrex::Real > &rhs_arr, const amrex::Array4< const amrex::Real > &vel_norm_arr, const amrex::Array4< const amrex::Real > &cell_data_arr, const amrex::Array4< const amrex::Real > &mf_norm, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const bool do_lo=false)
amrex::Box ShrinkZmomBoxAtDomainEnds(amrex::Box b, const amrex::Box &domain)
Definition: ERF_Advection.H:206
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE AdvType EfficientAdvType(int nrk, AdvType adv_type)
Definition: ERF_Advection.H:491
Declares the embedded-boundary factory manager used by ERF levels.
AdvType
Definition: ERF_IndexDefines.H:329
@ Centered_4th
@ Centered_2nd
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const bool fixed_rho
Definition: ERF_InitCustomPert_SDMCongestus3D.H:42
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
Owns and exposes cell-centered and face-centered EB factories.
Definition: ERF_EB.H:26
@ rho
Definition: ERF_Kessler.H:25
@ omega
Definition: ERF_Morrison.H:57
Definition: ERF_Advection.H:220
amrex::Box box
Definition: ERF_Advection.H:221
OpenSide y_side
Definition: ERF_Advection.H:223
OpenSide x_side
Definition: ERF_Advection.H:222