ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ScalarDiffusion.H
Go to the documentation of this file.
1 #ifndef ERF_SCALAR_DIFFUSION_H_
2 #define ERF_SCALAR_DIFFUSION_H_
3 
4 #include <type_traits>
5 
6 #include "AMReX_BCRec.H"
7 #include "AMReX_Box.H"
8 #include "AMReX_FArrayBox.H"
9 #include "AMReX_Gpu.H"
10 #include "ERF_DiffStruct.H"
11 #include "ERF_NumericalConstants.H"
12 #include "ERF_TerrainMetrics.H"
14 
15 /**
16  * Coefficients and state-layout mapping at the native ERF adapter boundary.
17  *
18  * The numerical routines below receive the scalar, density, flux, and RHS
19  * components independently. `molecular_coeff` is kinematic alpha for
20  * ConstantAlpha and density-weighted rhoAlpha for Constant. The density
21  * multiplication is selected by the host-side template specialization.
22  */
24 {
25  amrex::Real molecular_coeff = amrex::Real(0.0);
26  int eddy_h_comp = 0;
27  int eddy_v_comp = 0;
28 };
29 
30 static_assert(std::is_trivially_copyable_v<ScalarDiffusionCoefficients>);
31 
32 /** Scalar, density, RHS and flux views with independent component indices. */
34 {
35  amrex::Array4<const amrex::Real> scalar;
36  int scalar_comp = 0;
37  amrex::Array4<const amrex::Real> density;
38  int rho_comp = 0;
39  amrex::Array4<const amrex::Real> mu_turb;
40  amrex::Array4<amrex::Real> xflux;
41  amrex::Array4<amrex::Real> yflux;
42  amrex::Array4<amrex::Real> zflux;
43  int flux_comp = 0;
44  amrex::Array4<amrex::Real> rhs;
45  int rhs_comp = 0;
46 };
47 
48 /** Host-side coefficient form; dispatches to compile-time face kernels. */
50 {
51  bool molecular_is_kinematic = false;
52  bool add_turbulence = false;
53 };
54 
55 /** Explicit face fluxes supplied by an application-specific boundary model. */
57 {
58  bool use_x_on_side = false;
59  bool use_y_on_side = false;
60  bool use_z_on_side = false;
61  bool use_x_on_bottom_z = false;
62  bool use_y_on_bottom_z = false;
63  amrex::Array4<const amrex::Real> x;
64  amrex::Array4<const amrex::Real> y;
65  amrex::Array4<const amrex::Real> z;
66  int x_comp = 0;
67  int y_comp = 0;
68  int z_comp = 0;
69 };
70 
71 /** Optional raw vertical-flux diagnostic, written by the z-face kernel. */
73 {
74  bool enabled = false;
75  bool write_on_surface = false;
76  amrex::Array4<amrex::Real> z;
77  int z_comp = 0;
78 };
79 
80 /** Surface-layer faces that may select prescribed fluxes or zero flux. */
82 {
83  bool xlo = false;
84  bool xhi = false;
85  bool ylo = false;
86  bool yhi = false;
87  bool zlo = false;
88  bool zhi = false;
89 };
90 
91 /** Configuration shared by component-explicit face builders. */
93 {
99 };
100 
101 static_assert(std::is_trivially_copyable_v<ScalarDiffusionFieldViews>);
102 static_assert(std::is_trivially_copyable_v<ScalarDiffusionFluxPolicy>);
103 
104 /**
105  * Density-weighted face transport coefficient. The booleans are compile-time
106  * choices for ConstantAlpha/Constant/None and turbulent/no-turbulence modes;
107  * turbulent coefficients are already density weighted and are never
108  * multiplied by rho here.
109  *
110  * `rho_comp` and the eddy component are independent of the scalar component.
111  */
112 template <bool MultiplyMolecularByDensity, bool AddTurbulence>
113 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
115  const amrex::Array4<const amrex::Real>& rho,
116  const int rho_comp,
117  const amrex::Array4<const amrex::Real>& mu_turb,
118  const ScalarDiffusionCoefficients& coefficients,
119  const int i,
120  const int j,
121  const int k,
122  const int di,
123  const int dj,
124  const int dk,
125  const int eddy_comp) noexcept
126 {
127  amrex::Real coeff = coefficients.molecular_coeff;
128  if constexpr (MultiplyMolecularByDensity) {
129  coeff *= amrex::Real(0.5) *
130  (rho(i, j, k, rho_comp) + rho(i - di, j - dj, k - dk, rho_comp));
131  }
132  if constexpr (AddTurbulence) {
133  coeff += amrex::Real(0.5) * (mu_turb(i, j, k, eddy_comp) +
134  mu_turb(i - di, j - dj, k - dk, eddy_comp));
135  }
136  return coeff;
137 }
138 
139 /** Face-value one-sided derivative weights for an S-grid vertical boundary. */
141 {
142  amrex::Real c1, c2, c3;
143 };
144 
145 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE StretchedDiffusionBoundaryWeights
147  const amrex::Real dz_near, const amrex::Real dz_next) noexcept
148 {
149  const amrex::Real f = dz_next / dz_near + amrex::Real(2.0);
150  const amrex::Real f2 = f * f;
151  const amrex::Real c3 = amrex::Real(2.0) / (f - f2);
152  return {-(amrex::Real(1.0) - f2) * c3, -f2 * c3, c3};
153 }
154 
155 /**
156  * Whether the x (Direction 0) or y (Direction 1) face at (i, j, k) is an open
157  * domain face whose diffusive flux takes the one-sided stencil against the face
158  * value held in the ghost cell: ext_dir, ext_dir_prim, or ext_dir_upwind where
159  * the face velocity `vel` points into the domain. The face index is tested
160  * first, so `vel` is read only on a domain face with ext_dir_upwind (a box away
161  * from the domain face holds no velocity there, and a caller whose BCs never
162  * use ext_dir_upwind may pass an empty array).
163  *
164  * The stencil this selects assumes the ghost cell holds the scalar at the face
165  * point of the same cell row: on a terrain-fitted grid, at that row's height
166  * on the face. A ghost filled at another height (for example a profile
167  * interpolated to flat-grid levels while the boundary terrain is raised) gives
168  * a flux error at the face of order one that does not shrink with dx, about
169  * 8/3 times the error of the two-point difference (erf-model/ERF#5391).
170  */
171 template <int Direction>
172 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void
174  const amrex::BCRec& bc,
175  const amrex::Array4<const amrex::Real>& vel,
176  const int i,
177  const int j,
178  const int k,
179  const amrex::Dim3& dom_lo,
180  const amrex::Dim3& dom_hi,
181  bool& ext_lo,
182  bool& ext_hi) noexcept
183 {
184  static_assert(Direction == 0 || Direction == 1);
185  const int n = Direction == 0 ? i : j;
186  const int face_lo = Direction == 0 ? dom_lo.x : dom_lo.y;
187  const int face_hi = (Direction == 0 ? dom_hi.x : dom_hi.y) + 1;
188  ext_lo = false;
189  ext_hi = false;
190  if (n == face_lo) {
191  const int type = bc.lo(Direction);
192  if (type == ERFBCType::ext_dir || type == ERFBCType::ext_dir_prim) {
193  ext_lo = true;
194  } else if (type == ERFBCType::ext_dir_upwind) {
195  AMREX_ASSERT(vel.dataPtr() != nullptr);
196  ext_lo = vel(i, j, k) >= amrex::Real(0.0);
197  }
198  } else if (n == face_hi) {
199  const int type = bc.hi(Direction);
200  if (type == ERFBCType::ext_dir || type == ERFBCType::ext_dir_prim) {
201  ext_hi = true;
202  } else if (type == ERFBCType::ext_dir_upwind) {
203  AMREX_ASSERT(vel.dataPtr() != nullptr);
204  ext_hi = vel(i, j, k) <= amrex::Real(0.0);
205  }
206  }
207 }
208 
209 /**
210  * The horizontal difference of the scalar at an x (Direction 0) or y
211  * (Direction 1) face: its gradient there times the cell size. At an open domain face
212  * (ext_dir_lo / ext_dir_hi, from ScalarDiffusionLateralExtDir) the ghost cell
213  * holds the face value, half a cell from the edge-cell center, and the
214  * (-8/3, 3, -1/3) stencil gives the gradient to the face to second order;
215  * elsewhere it is the two-point difference.
216  */
217 template <int Direction>
218 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
220  const amrex::Array4<const amrex::Real>& scalar,
221  const int scalar_comp,
222  const int i,
223  const int j,
224  const int k,
225  const bool ext_dir_lo,
226  const bool ext_dir_hi) noexcept
227 {
228  static_assert(Direction == 0 || Direction == 1);
229  constexpr int di = Direction == 0 ? 1 : 0;
230  constexpr int dj = Direction == 1 ? 1 : 0;
231  if (ext_dir_lo) {
232  return -(amrex::Real(8.0) / amrex::Real(3.0)) *
233  scalar(i - di, j - dj, k, scalar_comp) +
234  amrex::Real(3.0) * scalar(i, j, k, scalar_comp) -
235  (amrex::Real(1.0) / amrex::Real(3.0)) *
236  scalar(i + di, j + dj, k, scalar_comp);
237  }
238  if (ext_dir_hi) {
239  return
240  (amrex::Real(8.0) / amrex::Real(3.0)) * scalar(i, j, k, scalar_comp) -
241  amrex::Real(3.0) * scalar(i - di, j - dj, k, scalar_comp) +
242  (amrex::Real(1.0) / amrex::Real(3.0)) *
243  scalar(i - 2 * di, j - 2 * dj, k, scalar_comp);
244  }
245  return scalar(i, j, k, scalar_comp) - scalar(i - di, j - dj, k, scalar_comp);
246 }
247 
248 /**
249  * Compute the existing N-grid signed face flux, F^D=-K grad(chi). `scalar_comp`
250  * selects the intensive scalar and `flux_comp` is applied by the caller to its
251  * independent face-flux view. Horizontal map-factor numerator and denominator
252  * remain separate to preserve the native arithmetic association. Physical
253  * Dirichlet flags select the legacy one-sided stencil; ext_dir_upwind selection
254  * stays in the adapter.
255  */
256 template <int Direction>
257 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
259  const amrex::Array4<const amrex::Real>& scalar,
260  const int scalar_comp,
261  const int i,
262  const int j,
263  const int k,
264  const amrex::Real coeff,
265  const amrex::Real inv_spacing,
266  const amrex::Real map_numerator,
267  const amrex::Real map_denominator,
268  const bool ext_dir_lo,
269  const bool ext_dir_hi) noexcept
270 {
271  static_assert(Direction >= 0 && Direction < 3);
272  amrex::Real grad;
273  if constexpr (Direction == 0 || Direction == 1) {
274  grad = ScalarDiffusionHorizontalDelta<Direction>(
275  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
276  } else {
277  if (ext_dir_lo) {
278  grad = -(amrex::Real(8.0) / amrex::Real(3.0)) *
279  scalar(i, j, k - 1, scalar_comp) +
280  amrex::Real(3.0) * scalar(i, j, k, scalar_comp) -
281  (amrex::Real(1.0) / amrex::Real(3.0)) *
282  scalar(i, j, k + 1, scalar_comp);
283  } else if (ext_dir_hi) {
284  grad =
285  (amrex::Real(8.0) / amrex::Real(3.0)) * scalar(i, j, k, scalar_comp) -
286  amrex::Real(3.0) * scalar(i, j, k - 1, scalar_comp) +
287  (amrex::Real(1.0) / amrex::Real(3.0)) *
288  scalar(i, j, k - 2, scalar_comp);
289  } else {
290  grad = scalar(i, j, k, scalar_comp) - scalar(i, j, k - 1, scalar_comp);
291  }
292  }
293  if constexpr (Direction == 2) {
294  return -coeff * grad * inv_spacing;
295  } else {
296  return -coeff * grad * inv_spacing * map_numerator / map_denominator;
297  }
298 }
299 
300 /** Existing S-grid vertical-center gradient, including boundary and tile-edge
301  * spacing. */
302 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
304  const amrex::Array4<const amrex::Real>& scalar,
305  const int scalar_comp,
306  const int i,
307  const int j,
308  const int k,
309  const amrex::Real* dz,
310  const int klo,
311  const int khi,
312  const bool ext_dir_lo,
313  const bool ext_dir_hi) noexcept
314 {
315  if (ext_dir_lo) {
316  const auto w = StretchedDiffusionDirichletWeights(dz[k], dz[k + 1]);
317  return (amrex::Real(1.0) / dz[k]) *
318  (w.c1 * scalar(i, j, k - 1, scalar_comp) +
319  w.c2 * scalar(i, j, k, scalar_comp) +
320  w.c3 * scalar(i, j, k + 1, scalar_comp));
321  }
322  if (ext_dir_hi) {
323  const auto w = StretchedDiffusionDirichletWeights(dz[k - 1], dz[k - 2]);
324  return (amrex::Real(1.0) / dz[k - 1]) *
325  (-(
326  w.c1 * scalar(i, j, k, scalar_comp) +
327  w.c2 * scalar(i, j, k - 1, scalar_comp) +
328  w.c3 * scalar(i, j, k - 2, scalar_comp)));
329  }
330  const amrex::Real inv = (k == klo) ? amrex::Real(1.0) / dz[k]
331  : (k == khi + 1)
332  ? amrex::Real(1.0) / dz[k - 1]
333  : amrex::Real(2.0) / (dz[k] + dz[k - 1]);
334  return inv *
335  (scalar(i, j, k, scalar_comp) - scalar(i, j, k - 1, scalar_comp));
336 }
337 
338 /** Existing S-grid horizontal raw flux before its separate map-factor
339  * adjustment kernel. The horizontal spacing is uniform, so an open domain face
340  * takes the N-grid one-sided stencil (ScalarDiffusionHorizontalDelta). */
341 template <int Direction>
342 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
344  const amrex::Array4<const amrex::Real>& scalar,
345  const int scalar_comp,
346  const int i,
347  const int j,
348  const int k,
349  const amrex::Real coeff,
350  const amrex::Real inv_spacing,
351  const amrex::Real face_map,
352  const bool ext_dir_lo,
353  const bool ext_dir_hi) noexcept
354 {
355  static_assert(Direction == 0 || Direction == 1);
356  const amrex::Real delta = ScalarDiffusionHorizontalDelta<Direction>(
357  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
358  const amrex::Real gradient = inv_spacing * delta;
359  return -coeff * face_map * gradient;
360 }
361 
362 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
364  const amrex::Real coeff,
365  const amrex::Real face_map,
366  const amrex::Real grad_xi,
367  const amrex::Real h_xi,
368  const amrex::Real grad_z) noexcept
369 {
370  return -coeff * face_map * (grad_xi - h_xi * grad_z);
371 }
372 
373 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
375  const amrex::Real coeff,
376  const amrex::Real face_map,
377  const amrex::Real grad_eta,
378  const amrex::Real h_eta,
379  const amrex::Real grad_z) noexcept
380 {
381  return -coeff * face_map * (grad_eta - h_eta * grad_z);
382 }
383 
384 /**
385  * 1 / (z(k+1) - z(k-1)) on an x (Direction 0) or y (Direction 1) face, with
386  * z(kk) the height of the face center in cell row kk: the mean of the face's
387  * four nodes. The vertical derivative of the face trace at an open domain
388  * face is taken over this spacing, not over the ghost column's, which sits
389  * half a cell outside the face.
390  */
391 template <int Direction>
392 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
394  const amrex::Array4<const amrex::Real>& z_nd,
395  const int i,
396  const int j,
397  const int k) noexcept
398 {
399  static_assert(Direction == 0 || Direction == 1);
400  constexpr int di = Direction == 1 ? 1 : 0;
401  constexpr int dj = Direction == 0 ? 1 : 0;
402  const auto z_face = [&] (const int kk) {
403  return amrex::Real(0.25) *
404  (z_nd(i, j, kk) + z_nd(i + di, j + dj, kk) +
405  z_nd(i, j, kk + 1) + z_nd(i + di, j + dj, kk + 1));
406  };
407  return amrex::Real(1.0) / (z_face(k + 1) - z_face(k - 1));
408 }
409 
410 /**
411  * Terrain x-face raw diffusion flux, including ERF's x-face map factor.
412  * `coeff` is the already selected effective face coefficient. Prescribed
413  * surface flux replacement is boundary policy and is intentionally outside
414  * this geometry primitive. At an open domain face (ext_dir_lo / ext_dir_hi,
415  * from ScalarDiffusionLateralExtDir) the ghost column holds the face trace:
416  * the x derivative takes the one-sided stencil against it, and the vertical
417  * derivative in the cross term is the trace's own, over the face's own height
418  * spacing (TerrainFaceHeightSpacingInv).
419  */
420 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
422  const amrex::Array4<const amrex::Real>& scalar,
423  const int scalar_comp,
424  const amrex::Real coeff,
425  const int i,
426  const int j,
427  const int k,
428  const amrex::Array4<const amrex::Real>& z_nd,
429  const amrex::Array4<const amrex::Real>& z_cc,
430  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
431  const amrex::Array4<const amrex::Real>& mf_ux,
432  const bool ext_dir_lo,
433  const bool ext_dir_hi) noexcept
434 {
435  const amrex::Real h_xi = Compute_h_xi_AtIface(i, j, k, cellSizeInv, z_nd);
436  const amrex::Real idz_hi =
437  amrex::Real(1.0) / (z_cc(i, j, k + 1) - z_cc(i, j, k - 1));
438  const amrex::Real idz_lo =
439  amrex::Real(1.0) / (z_cc(i - 1, j, k + 1) - z_cc(i - 1, j, k - 1));
440  // At an open domain face the ghost column holds the face trace, so the
441  // vertical derivative along the face is that trace's own, over the face's
442  // height spacing; elsewhere it is the average of the two columns.
443  amrex::Real grad_z;
444  if (ext_dir_lo) {
445  grad_z = (scalar(i - 1, j, k + 1, scalar_comp) -
446  scalar(i - 1, j, k - 1, scalar_comp)) *
447  TerrainFaceHeightSpacingInv<0>(z_nd, i, j, k);
448  } else if (ext_dir_hi) {
449  grad_z = (scalar(i, j, k + 1, scalar_comp) -
450  scalar(i, j, k - 1, scalar_comp)) *
451  TerrainFaceHeightSpacingInv<0>(z_nd, i, j, k);
452  } else {
453  grad_z =
454  amrex::Real(0.5) * (scalar(i, j, k + 1, scalar_comp) * idz_hi +
455  scalar(i - 1, j, k + 1, scalar_comp) * idz_lo -
456  scalar(i, j, k - 1, scalar_comp) * idz_hi -
457  scalar(i - 1, j, k - 1, scalar_comp) * idz_lo);
458  }
459  const amrex::Real grad_xi =
460  cellSizeInv[0] * ScalarDiffusionHorizontalDelta<0>(
461  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
462  return ScalarDiffusionFlux_Tx(coeff, mf_ux(i, j, 0), grad_xi, h_xi, grad_z);
463 }
464 
465 /** Terrain y-face raw diffusion flux, including ERF's y-face map factor; open
466  * domain faces as in TerrainScalarDiffusionFluxAtIFace. */
467 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
469  const amrex::Array4<const amrex::Real>& scalar,
470  const int scalar_comp,
471  const amrex::Real coeff,
472  const int i,
473  const int j,
474  const int k,
475  const amrex::Array4<const amrex::Real>& z_nd,
476  const amrex::Array4<const amrex::Real>& z_cc,
477  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
478  const amrex::Array4<const amrex::Real>& mf_vy,
479  const bool ext_dir_lo,
480  const bool ext_dir_hi) noexcept
481 {
482  const amrex::Real h_eta = Compute_h_eta_AtJface(i, j, k, cellSizeInv, z_nd);
483  const amrex::Real idz_hi =
484  amrex::Real(1.0) / (z_cc(i, j, k + 1) - z_cc(i, j, k - 1));
485  const amrex::Real idz_lo =
486  amrex::Real(1.0) / (z_cc(i, j - 1, k + 1) - z_cc(i, j - 1, k - 1));
487  // At an open domain face the ghost column holds the face trace, so the
488  // vertical derivative along the face is that trace's own, over the face's
489  // height spacing; elsewhere it is the average of the two columns.
490  amrex::Real grad_z;
491  if (ext_dir_lo) {
492  grad_z = (scalar(i, j - 1, k + 1, scalar_comp) -
493  scalar(i, j - 1, k - 1, scalar_comp)) *
494  TerrainFaceHeightSpacingInv<1>(z_nd, i, j, k);
495  } else if (ext_dir_hi) {
496  grad_z = (scalar(i, j, k + 1, scalar_comp) -
497  scalar(i, j, k - 1, scalar_comp)) *
498  TerrainFaceHeightSpacingInv<1>(z_nd, i, j, k);
499  } else {
500  grad_z =
501  amrex::Real(0.5) * (scalar(i, j, k + 1, scalar_comp) * idz_hi +
502  scalar(i, j - 1, k + 1, scalar_comp) * idz_lo -
503  scalar(i, j, k - 1, scalar_comp) * idz_hi -
504  scalar(i, j - 1, k - 1, scalar_comp) * idz_lo);
505  }
506  const amrex::Real grad_eta =
507  cellSizeInv[1] * ScalarDiffusionHorizontalDelta<1>(
508  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
509  return ScalarDiffusionFlux_Ty(coeff, mf_vy(i, j, 0), grad_eta, h_eta, grad_z);
510 }
511 
512 /**
513  * Terrain raw vertical diffusion flux at one k face. Dirichlet boundary
514  * stencils are selected explicitly by the caller; surface-layer replacement
515  * remains separate boundary policy.
516  */
517 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
519  const amrex::Array4<const amrex::Real>& scalar,
520  const int scalar_comp,
521  const amrex::Real coeff,
522  const int i,
523  const int j,
524  const int kface,
525  const amrex::Array4<const amrex::Real>& z_nd,
526  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
527  const bool ext_dir_lo,
528  const bool ext_dir_hi) noexcept
529 {
530  amrex::Real grad_z;
531  if (ext_dir_lo) {
532  const amrex::Real zm = Compute_Z_AtWFace(i, j, kface + 1, z_nd);
533  const amrex::Real dz0 = zm - Compute_Z_AtWFace(i, j, kface, z_nd);
534  const amrex::Real dz1 = Compute_Z_AtWFace(i, j, kface + 2, z_nd) - zm;
535  const amrex::Real idz0 = amrex::Real(1.0) / dz0;
536  const amrex::Real f = dz1 / dz0 + amrex::Real(2.0);
537  const amrex::Real f2 = f * f;
538  const amrex::Real c3 = amrex::Real(2.0) / (f - f2);
539  const amrex::Real c2 = -f2 * c3;
540  const amrex::Real c1 = -(amrex::Real(1.0) - f2) * c3;
541  grad_z = idz0 * (c1 * scalar(i, j, kface - 1, scalar_comp) +
542  c2 * scalar(i, j, kface, scalar_comp) +
543  c3 * scalar(i, j, kface + 1, scalar_comp));
544  } else if (ext_dir_hi) {
545  const amrex::Real zm = Compute_Z_AtWFace(i, j, kface - 1, z_nd);
546  const amrex::Real dz0 = Compute_Z_AtWFace(i, j, kface, z_nd) - zm;
547  const amrex::Real dz1 = zm - Compute_Z_AtWFace(i, j, kface - 2, z_nd);
548  const amrex::Real idz0 = amrex::Real(1.0) / dz0;
549  const amrex::Real f = dz1 / dz0 + amrex::Real(2.0);
550  const amrex::Real f2 = f * f;
551  const amrex::Real c3 = amrex::Real(2.0) / (f - f2);
552  const amrex::Real c2 = -f2 * c3;
553  const amrex::Real c1 = -(amrex::Real(1.0) - f2) * c3;
554  grad_z = idz0 * (-(
555  c1 * scalar(i, j, kface, scalar_comp) +
556  c2 * scalar(i, j, kface - 1, scalar_comp) +
557  c3 * scalar(i, j, kface - 2, scalar_comp)));
558  } else {
559  const amrex::Real h_zeta =
560  Compute_h_zeta_AtKface(i, j, kface, cellSizeInv, z_nd);
561  grad_z = (cellSizeInv[2] / h_zeta) * (scalar(i, j, kface, scalar_comp) -
562  scalar(i, j, kface - 1, scalar_comp));
563  }
564  return -coeff * grad_z;
565 }
566 
567 /**
568  * Raw terrain-coordinate F_z and its conservative transformed transfer are
569  * distinct quantities. G_z is the numerator
570  * F_z - m_x h_xi Fbar_x - m_y h_eta Fbar_y; T_z=G_z/(m_x m_y).
571  */
572 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
574  const amrex::Real raw_Fz,
575  const amrex::Real mx,
576  const amrex::Real h_xi,
577  const amrex::Real Fbar_x,
578  const amrex::Real my,
579  const amrex::Real h_eta,
580  const amrex::Real Fbar_y) noexcept
581 {
582  return raw_Fz - h_xi * mx * Fbar_x - h_eta * my * Fbar_y;
583 }
584 
585 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
587  const amrex::Real raw_Fx,
588  const amrex::Real h_zeta,
589  const amrex::Real my) noexcept
590 {
591  return raw_Fx * h_zeta / my;
592 }
593 
594 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
596  const amrex::Real raw_Fy,
597  const amrex::Real h_zeta,
598  const amrex::Real mx) noexcept
599 {
600  return raw_Fy * h_zeta / mx;
601 }
602 
603 /**
604  * Pointwise conversion to ERF's mapped conservative face-transfer convention.
605  * The transfer is an instantaneous rate and includes the supplied face-area
606  * measure; callers must not apply that measure again in the divergence.
607  */
608 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
610  const amrex::Real raw_flux,
611  const amrex::Real face_area) noexcept
612 {
613  return raw_flux * face_area;
614 }
615 
616 /** Convert a raw vertical diffusion flux to the mapped face-transfer space. */
617 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
619  const amrex::Real raw_flux,
620  const amrex::Real mx,
621  const amrex::Real my) noexcept
622 {
623  return raw_flux / (mx * my);
624 }
625 
626 /**
627  * Construct the native terrain numerator G_z at one vertical face. This
628  * helper owns x/y-face interpolation, physical-boundary extrapolation, and
629  * terrain cross terms; native divergence consumes G_z directly.
630  */
631 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
633  const int i,
634  const int j,
635  const int kface,
636  const amrex::Box& domain,
637  const amrex::Array4<const amrex::Real>& raw_xflux,
638  const amrex::Array4<const amrex::Real>& raw_yflux,
639  const amrex::Array4<const amrex::Real>& raw_zflux,
640  const int flux_comp,
641  const amrex::Array4<const amrex::Real>& z_nd,
642  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
643  const amrex::Array4<const amrex::Real>& mf_mx,
644  const amrex::Array4<const amrex::Real>& mf_my) noexcept
645 {
646  const int klo = domain.smallEnd(2);
647  const int khi = domain.bigEnd(2) + 1;
648  amrex::Real xbar, ybar;
649 
650  if (kface == klo) {
651  const amrex::Real xlo = myhalf * (raw_xflux(i, j, klo, flux_comp) +
652  raw_xflux(i + 1, j, klo, flux_comp));
653  const amrex::Real xhi = myhalf * (raw_xflux(i, j, klo + 1, flux_comp) +
654  raw_xflux(i + 1, j, klo + 1, flux_comp));
655  xbar = amrex::Real(1.5) * xlo - myhalf * xhi;
656  const amrex::Real ylo = myhalf * (raw_yflux(i, j, klo, flux_comp) +
657  raw_yflux(i, j + 1, klo, flux_comp));
658  const amrex::Real yhi = myhalf * (raw_yflux(i, j, klo + 1, flux_comp) +
659  raw_yflux(i, j + 1, klo + 1, flux_comp));
660  ybar = amrex::Real(1.5) * ylo - myhalf * yhi;
661  } else if (kface == khi) {
662  const amrex::Real xlo = myhalf * (raw_xflux(i, j, khi - 2, flux_comp) +
663  raw_xflux(i + 1, j, khi - 2, flux_comp));
664  const amrex::Real xhi = myhalf * (raw_xflux(i, j, khi - 1, flux_comp) +
665  raw_xflux(i + 1, j, khi - 1, flux_comp));
666  xbar = amrex::Real(1.5) * xhi - myhalf * xlo;
667  const amrex::Real ylo = myhalf * (raw_yflux(i, j, khi - 2, flux_comp) +
668  raw_yflux(i, j + 1, khi - 2, flux_comp));
669  const amrex::Real yhi = myhalf * (raw_yflux(i, j, khi - 1, flux_comp) +
670  raw_yflux(i, j + 1, khi - 1, flux_comp));
671  ybar = amrex::Real(1.5) * yhi - myhalf * ylo;
672  } else {
673  xbar = fourth * (raw_xflux(i, j, kface, flux_comp) +
674  raw_xflux(i + 1, j, kface, flux_comp) +
675  raw_xflux(i, j, kface - 1, flux_comp) +
676  raw_xflux(i + 1, j, kface - 1, flux_comp));
677  ybar = fourth * (raw_yflux(i, j, kface, flux_comp) +
678  raw_yflux(i, j + 1, kface, flux_comp) +
679  raw_yflux(i, j, kface - 1, flux_comp) +
680  raw_yflux(i, j + 1, kface - 1, flux_comp));
681  }
682 
683  const amrex::Real mx = mf_mx(i, j, 0);
684  const amrex::Real my = mf_my(i, j, 0);
685  const amrex::Real h_xi = Compute_h_xi_AtKface(i, j, kface, cellSizeInv, z_nd);
686  const amrex::Real h_eta =
687  Compute_h_eta_AtKface(i, j, kface, cellSizeInv, z_nd);
688  const amrex::Real Gz = TerrainDiffusionGz(
689  raw_zflux(i, j, kface, flux_comp), mx, h_xi, xbar, my, h_eta, ybar);
690  return Gz;
691 }
692 
693 /**
694  * Complete terrain vertical transfer at one k face. Terrain interpolation,
695  * boundary extrapolation and cross terms remain owned by the Gz helper above.
696  * Set suppress_transfer when the caller's resolved boundary policy suppresses
697  * the complete lower terrain-normal transfer.
698  *
699  * At an interior k face, raw_xflux and raw_yflux must be valid at kface and
700  * kface-1. At the physical bottom or top face, the authoritative Gz helper
701  * uses one-sided extrapolation and needs no out-of-domain z layer.
702  */
703 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
705  const int i,
706  const int j,
707  const int kface,
708  const amrex::Box& domain,
709  const amrex::Array4<const amrex::Real>& raw_xflux,
710  const amrex::Array4<const amrex::Real>& raw_yflux,
711  const amrex::Array4<const amrex::Real>& raw_zflux,
712  const int flux_comp,
713  const amrex::Array4<const amrex::Real>& z_nd,
714  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
715  const amrex::Array4<const amrex::Real>& mf_mx,
716  const amrex::Array4<const amrex::Real>& mf_my,
717  const bool suppress_transfer = false) noexcept
718 {
719  if (suppress_transfer) return amrex::Real(0.0);
720  const amrex::Real Gz = TerrainScalarDiffusionGzAtKFace(
721  i, j, kface, domain, raw_xflux, raw_yflux, raw_zflux, flux_comp, z_nd,
722  cellSizeInv, mf_mx, mf_my);
724  Gz, mf_mx(i, j, 0), mf_my(i, j, 0));
725 }
726 
727 /**
728  * Return the positive geometry-weighted mapped flux divergence. For
729  * detJ_cell <= 0, return zero without dividing. The diffusion array wrapper
730  * subtracts this value from the existing RHS.
731  */
732 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
734  const amrex::Real fx_hi,
735  const amrex::Real fx_lo,
736  const amrex::Real fy_hi,
737  const amrex::Real fy_lo,
738  const amrex::Real fz_hi,
739  const amrex::Real fz_lo,
740  const amrex::Real dx_inv,
741  const amrex::Real dy_inv,
742  const amrex::Real dzeta_inv,
743  const amrex::Real mx,
744  const amrex::Real my,
745  const amrex::Real detJ_cell) noexcept
746 {
747  if (detJ_cell <= amrex::Real(0.0))
748  return amrex::Real(0.0);
749  const amrex::Real map_over_jacobian = (mx * my) / detJ_cell;
750  return map_over_jacobian *
751  ((fx_hi - fx_lo) * dx_inv + (fy_hi - fy_lo) * dy_inv +
752  (fz_hi - fz_lo) * dzeta_inv);
753 }
754 
755 /** Native terrain divergence in the legacy arithmetic association. */
756 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
758  const amrex::Real mapped_Fx_hi,
759  const amrex::Real mapped_Fx_lo,
760  const amrex::Real mapped_Fy_hi,
761  const amrex::Real mapped_Fy_lo,
762  const amrex::Real Gz_hi,
763  const amrex::Real Gz_lo,
764  const amrex::Real dx_inv,
765  const amrex::Real dy_inv,
766  const amrex::Real dz_inv,
767  const amrex::Real mfsq,
768  const amrex::Real detJ_cell) noexcept
769 {
770  amrex::Real stateContrib =
771  (mapped_Fx_hi - mapped_Fx_lo) * dx_inv * mfsq +
772  (mapped_Fy_hi - mapped_Fy_lo) * dy_inv * mfsq +
773  (Gz_hi - Gz_lo) * dz_inv;
774  stateContrib /= detJ_cell;
775  return stateContrib;
776 }
777 
778 /**
779  * Component-explicit N-grid face construction. Boundary-condition selection,
780  * map factors, prescribed surface fluxes and raw-flux diagnostics are explicit
781  * inputs; this operation does not inspect native conserved-state identity.
782  */
783 template <bool MultiplyMolecularByDensity, bool AddTurbulence>
784 inline void
786  const amrex::Box& bx,
787  const amrex::Box& domain,
788  const ScalarDiffusionFieldViews& field,
789  const ScalarDiffusionFluxPolicy& policy,
790  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
791  const amrex::Array4<const amrex::Real>& u,
792  const amrex::Array4<const amrex::Real>& v,
793  const amrex::Array4<const amrex::Real>& mf_ux,
794  const amrex::Array4<const amrex::Real>& mf_uy,
795  const amrex::Array4<const amrex::Real>& mf_vx,
796  const amrex::Array4<const amrex::Real>& mf_vy,
797  const amrex::BCRec* bc_ptr,
798  const int bc_comp)
799 {
800  using namespace amrex;
801  const auto dom_lo = lbound(domain);
802  const auto dom_hi = ubound(domain);
803  const Box xbx = surroundingNodes(bx, 0);
804  const Box ybx = surroundingNodes(bx, 1);
805  const Box zbx = surroundingNodes(bx, 2);
806  const Real dx_inv = cellSizeInv[0];
807  const Real dy_inv = cellSizeInv[1];
808  const Real dz_inv = cellSizeInv[2];
809  const auto coefficients = policy.coefficients;
810  const auto prescribed = policy.prescribed;
811  const auto diagnostic = policy.diagnostic;
812  const auto surface = policy.surface;
813  const int scalar_comp = field.scalar_comp;
814  const int rho_comp = field.rho_comp;
815  const int flux_comp = field.flux_comp;
816  const auto scalar = field.scalar;
817  const auto density = field.density;
818  const auto mu_turb = field.mu_turb;
819  const auto xflux = field.xflux;
820  const auto yflux = field.yflux;
821  const auto zflux = field.zflux;
822 
823  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
824  const Real coeff = ScalarDiffusionFaceCoefficient<
825  MultiplyMolecularByDensity, AddTurbulence>(
826  density, rho_comp, mu_turb, coefficients, i, j, k, 1, 0, 0,
827  coefficients.eddy_h_comp);
828  bool ext_lo, ext_hi;
829  ScalarDiffusionLateralExtDir<0>(bc_ptr[bc_comp], u, i, j, k, dom_lo, dom_hi,
830  ext_lo, ext_hi);
831  const bool on_surface =
832  (surface.xlo && i == dom_lo.x) ||
833  (surface.xhi && i == dom_hi.x + 1);
834 
835  if (ext_lo) {
836  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<0>(
837  scalar, scalar_comp, i, j, k, coeff, dx_inv,
838  mf_ux(i, j, 0), mf_uy(i, j, 0), true, false);
839  } else if (ext_hi) {
840  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<0>(
841  scalar, scalar_comp, i, j, k, coeff, dx_inv,
842  mf_ux(i, j, 0), mf_uy(i, j, 0), false, true);
843  } else if (on_surface && prescribed.use_x_on_side) {
844  xflux(i, j, k, flux_comp) = prescribed.x(i, j, k, prescribed.x_comp);
845  } else {
846  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<0>(
847  scalar, scalar_comp, i, j, k, coeff, dx_inv,
848  mf_ux(i, j, 0), mf_uy(i, j, 0), false, false);
849  }
850  });
851 
852  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
853  const Real coeff = ScalarDiffusionFaceCoefficient<
854  MultiplyMolecularByDensity, AddTurbulence>(
855  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 1, 0,
856  coefficients.eddy_h_comp);
857  bool ext_lo, ext_hi;
858  ScalarDiffusionLateralExtDir<1>(bc_ptr[bc_comp], v, i, j, k, dom_lo, dom_hi,
859  ext_lo, ext_hi);
860  const bool on_surface =
861  (surface.ylo && j == dom_lo.y) ||
862  (surface.yhi && j == dom_hi.y + 1);
863 
864  if (ext_lo) {
865  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<1>(
866  scalar, scalar_comp, i, j, k, coeff, dy_inv,
867  mf_vy(i, j, 0), mf_vx(i, j, 0), true, false);
868  } else if (ext_hi) {
869  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<1>(
870  scalar, scalar_comp, i, j, k, coeff, dy_inv,
871  mf_vy(i, j, 0), mf_vx(i, j, 0), false, true);
872  } else if (on_surface && prescribed.use_y_on_side) {
873  yflux(i, j, k, flux_comp) = prescribed.y(i, j, k, prescribed.y_comp);
874  } else {
875  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<1>(
876  scalar, scalar_comp, i, j, k, coeff, dy_inv,
877  mf_vy(i, j, 0), mf_vx(i, j, 0), false, false);
878  }
879  });
880 
881  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
882  const Real coeff = ScalarDiffusionFaceCoefficient<
883  MultiplyMolecularByDensity, AddTurbulence>(
884  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 0, 1,
885  coefficients.eddy_v_comp);
886  const bool ext_lo =
887  ((bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir) ||
888  (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)) &&
889  k == dom_lo.z;
890  const bool ext_hi =
891  ((bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir) ||
892  (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)) &&
893  k == dom_hi.z + 1;
894  const bool on_surface =
895  (surface.zlo && k == dom_lo.z) ||
896  (surface.zhi && k == dom_hi.z + 1);
897 
898  if (ext_lo) {
899  zflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<2>(
900  scalar, scalar_comp, i, j, k, coeff, dz_inv, Real(1.0), Real(1.0),
901  true, false);
902  } else if (ext_hi) {
903  zflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<2>(
904  scalar, scalar_comp, i, j, k, coeff, dz_inv, Real(1.0), Real(1.0),
905  false, true);
906  } else if (on_surface && prescribed.use_z_on_side) {
907  zflux(i, j, k, flux_comp) = prescribed.z(i, j, k, prescribed.z_comp);
908  } else if (on_surface) {
909  zflux(i, j, k, flux_comp) = Real(0.0);
910  } else {
911  zflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<2>(
912  scalar, scalar_comp, i, j, k, coeff, dz_inv, Real(1.0), Real(1.0),
913  false, false);
914  }
915 
916  if (diagnostic.enabled && (diagnostic.write_on_surface || !on_surface)) {
917  diagnostic.z(i, j, k, diagnostic.z_comp) = zflux(i, j, k, flux_comp);
918  }
919  });
920 }
921 
922 /** Build all native N-grid face fluxes for any intensive scalar field. */
923 inline void
925  const amrex::Box& bx,
926  const amrex::Box& domain,
927  const ScalarDiffusionFieldViews& field,
928  const ScalarDiffusionFluxPolicy& policy,
929  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
930  const amrex::Array4<const amrex::Real>& u,
931  const amrex::Array4<const amrex::Real>& v,
932  const amrex::Array4<const amrex::Real>& mf_ux,
933  const amrex::Array4<const amrex::Real>& mf_uy,
934  const amrex::Array4<const amrex::Real>& mf_vx,
935  const amrex::Array4<const amrex::Real>& mf_vy,
936  const amrex::BCRec* bc_ptr,
937  const int bc_comp)
938 {
939  const auto mode = policy.coefficient_mode;
940  if (mode.molecular_is_kinematic) {
941  if (mode.add_turbulence) {
942  BuildScalarDiffusionFluxes_N_Impl<true, true>(
943  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
944  mf_vy, bc_ptr, bc_comp);
945  } else {
946  BuildScalarDiffusionFluxes_N_Impl<true, false>(
947  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
948  mf_vy, bc_ptr, bc_comp);
949  }
950  } else if (mode.add_turbulence) {
951  BuildScalarDiffusionFluxes_N_Impl<false, true>(
952  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
953  mf_vy, bc_ptr, bc_comp);
954  } else {
955  BuildScalarDiffusionFluxes_N_Impl<false, false>(
956  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
957  mf_vy, bc_ptr, bc_comp);
958  }
959 }
960 
961 template <bool MultiplyMolecularByDensity, bool AddTurbulence>
962 inline void
964  const amrex::Box& bx,
965  const amrex::Box& domain,
966  const ScalarDiffusionFieldViews& field,
967  const ScalarDiffusionFluxPolicy& policy,
968  const amrex::Real dx_inv,
969  const amrex::Real dy_inv,
970  const amrex::Real* dz,
971  const int klo,
972  const int khi,
973  const amrex::Array4<const amrex::Real>& u,
974  const amrex::Array4<const amrex::Real>& v,
975  const amrex::Array4<const amrex::Real>& mf_ux,
976  const amrex::Array4<const amrex::Real>& mf_uy,
977  const amrex::Array4<const amrex::Real>& mf_vx,
978  const amrex::Array4<const amrex::Real>& mf_vy,
979  const amrex::BCRec* bc_ptr,
980  const int bc_comp)
981 {
982  using namespace amrex;
983  const auto dom_lo = lbound(domain);
984  const auto dom_hi = ubound(domain);
985  const Box xbx = surroundingNodes(bx, 0);
986  const Box ybx = surroundingNodes(bx, 1);
987  const Box zbx = surroundingNodes(bx, 2);
988  const auto coefficients = policy.coefficients;
989  const auto prescribed = policy.prescribed;
990  const auto diagnostic = policy.diagnostic;
991  const auto surface = policy.surface;
992  const int scalar_comp = field.scalar_comp;
993  const int rho_comp = field.rho_comp;
994  const int flux_comp = field.flux_comp;
995  const auto scalar = field.scalar;
996  const auto density = field.density;
997  const auto mu_turb = field.mu_turb;
998  const auto xflux = field.xflux;
999  const auto yflux = field.yflux;
1000  const auto zflux = field.zflux;
1001 
1002  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1003  const Real coeff = ScalarDiffusionFaceCoefficient<
1004  MultiplyMolecularByDensity, AddTurbulence>(
1005  density, rho_comp, mu_turb, coefficients, i, j, k, 1, 0, 0,
1006  coefficients.eddy_h_comp);
1007  const bool on_surface =
1008  (surface.xlo && i == dom_lo.x) ||
1009  (surface.xhi && i == dom_hi.x + 1);
1010  bool ext_lo, ext_hi;
1011  ScalarDiffusionLateralExtDir<0>(bc_ptr[bc_comp], u, i, j, k, dom_lo, dom_hi,
1012  ext_lo, ext_hi);
1013  if (on_surface && prescribed.use_x_on_side) {
1014  xflux(i, j, k, flux_comp) = prescribed.x(i, j, k, prescribed.x_comp);
1015  } else {
1016  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_S_Horizontal<0>(
1017  scalar, scalar_comp, i, j, k, coeff, dx_inv, mf_ux(i, j, 0),
1018  ext_lo, ext_hi);
1019  }
1020  });
1021 
1022  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1023  const Real coeff = ScalarDiffusionFaceCoefficient<
1024  MultiplyMolecularByDensity, AddTurbulence>(
1025  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 1, 0,
1026  coefficients.eddy_h_comp);
1027  const bool on_surface =
1028  (surface.ylo && j == dom_lo.y) ||
1029  (surface.yhi && j == dom_hi.y + 1);
1030  bool ext_lo, ext_hi;
1031  ScalarDiffusionLateralExtDir<1>(bc_ptr[bc_comp], v, i, j, k, dom_lo, dom_hi,
1032  ext_lo, ext_hi);
1033  if (on_surface && prescribed.use_y_on_side) {
1034  yflux(i, j, k, flux_comp) = prescribed.y(i, j, k, prescribed.y_comp);
1035  } else {
1036  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_S_Horizontal<1>(
1037  scalar, scalar_comp, i, j, k, coeff, dy_inv, mf_vy(i, j, 0),
1038  ext_lo, ext_hi);
1039  }
1040  });
1041 
1042  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1043  const Real coeff = ScalarDiffusionFaceCoefficient<
1044  MultiplyMolecularByDensity, AddTurbulence>(
1045  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 0, 1,
1046  coefficients.eddy_v_comp);
1047  const bool ext_lo =
1048  ((bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir) ||
1049  (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)) &&
1050  k == dom_lo.z;
1051  const bool ext_hi =
1052  ((bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir) ||
1053  (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)) &&
1054  k == dom_hi.z + 1;
1055  const bool on_surface =
1056  (surface.zlo && k == dom_lo.z) ||
1057  (surface.zhi && k == dom_hi.z + 1);
1058  const Real grad = StretchedScalarGradient(
1059  scalar, scalar_comp, i, j, k, dz, klo, khi, ext_lo, ext_hi);
1060  if (on_surface && prescribed.use_z_on_side) {
1061  zflux(i, j, k, flux_comp) = prescribed.z(i, j, k, prescribed.z_comp);
1062  } else if (on_surface) {
1063  zflux(i, j, k, flux_comp) = Real(0.0);
1064  } else {
1065  zflux(i, j, k, flux_comp) = -coeff * grad;
1066  }
1067  if (diagnostic.enabled && (diagnostic.write_on_surface || !on_surface)) {
1068  diagnostic.z(i, j, k, diagnostic.z_comp) = zflux(i, j, k, flux_comp);
1069  }
1070  });
1071 
1072  // S-grid raw horizontal fluxes are adjusted in the same separate kernels as
1073  // the native implementation before scaling or applying divergence.
1074  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1075  xflux(i, j, k, flux_comp) /= mf_uy(i, j, 0);
1076  });
1077  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1078  yflux(i, j, k, flux_comp) /= mf_vx(i, j, 0);
1079  });
1080 }
1081 
1082 /** Build and map-adjust all native S-grid face fluxes for an intensive field. */
1083 inline void
1085  const amrex::Box& bx,
1086  const amrex::Box& domain,
1087  const ScalarDiffusionFieldViews& field,
1088  const ScalarDiffusionFluxPolicy& policy,
1089  const amrex::Real dx_inv,
1090  const amrex::Real dy_inv,
1091  const amrex::Real* dz,
1092  const int klo,
1093  const int khi,
1094  const amrex::Array4<const amrex::Real>& u,
1095  const amrex::Array4<const amrex::Real>& v,
1096  const amrex::Array4<const amrex::Real>& mf_ux,
1097  const amrex::Array4<const amrex::Real>& mf_uy,
1098  const amrex::Array4<const amrex::Real>& mf_vx,
1099  const amrex::Array4<const amrex::Real>& mf_vy,
1100  const amrex::BCRec* bc_ptr,
1101  const int bc_comp)
1102 {
1103  const auto mode = policy.coefficient_mode;
1104  if (mode.molecular_is_kinematic) {
1105  if (mode.add_turbulence) {
1106  BuildScalarDiffusionFluxes_S_Impl<true, true>(
1107  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1108  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1109  } else {
1110  BuildScalarDiffusionFluxes_S_Impl<true, false>(
1111  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1112  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1113  }
1114  } else if (mode.add_turbulence) {
1115  BuildScalarDiffusionFluxes_S_Impl<false, true>(
1116  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1117  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1118  } else {
1119  BuildScalarDiffusionFluxes_S_Impl<false, false>(
1120  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1121  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1122  }
1123 }
1124 
1125 template <bool MultiplyMolecularByDensity, bool AddTurbulence>
1126 inline void
1128  const amrex::Box& bx,
1129  const amrex::Box& domain,
1130  const ScalarDiffusionFieldViews& field,
1131  const ScalarDiffusionFluxPolicy& policy,
1132  const ScalarDiffusionCoefficients& vertical_coefficients,
1133  const bool rotate,
1134  const amrex::Array4<const amrex::Real>& z_nd,
1135  const amrex::Array4<const amrex::Real>& z_cc,
1136  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1137  const amrex::Array4<const amrex::Real>& u,
1138  const amrex::Array4<const amrex::Real>& v,
1139  const amrex::Array4<const amrex::Real>& mf_ux,
1140  const amrex::Array4<const amrex::Real>& mf_vy,
1141  const amrex::BCRec* bc_ptr,
1142  const int bc_comp)
1143 {
1144  using namespace amrex;
1145  const auto dom_lo = lbound(domain);
1146  const auto dom_hi = ubound(domain);
1147  Box xbx = surroundingNodes(bx, 0);
1148  Box ybx = surroundingNodes(bx, 1);
1149  const Box zbx = surroundingNodes(bx, 2);
1150  if (xbx.smallEnd(2) != dom_lo.z) xbx.growLo(2, 1);
1151  if (ybx.smallEnd(2) != dom_lo.z) ybx.growLo(2, 1);
1152  if (xbx.bigEnd(2) != dom_hi.z) xbx.growHi(2, 1);
1153  if (ybx.bigEnd(2) != dom_hi.z) ybx.growHi(2, 1);
1154 
1155  const auto coefficients = policy.coefficients;
1156  const auto vertical = vertical_coefficients;
1157  const auto prescribed = policy.prescribed;
1158  const auto diagnostic = policy.diagnostic;
1159  const auto surface = policy.surface;
1160  const int scalar_comp = field.scalar_comp;
1161  const int rho_comp = field.rho_comp;
1162  const int flux_comp = field.flux_comp;
1163  const auto scalar = field.scalar;
1164  const auto density = field.density;
1165  const auto mu_turb = field.mu_turb;
1166  const auto xflux = field.xflux;
1167  const auto yflux = field.yflux;
1168  const auto zflux = field.zflux;
1169 
1170  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1171  const Real coeff = ScalarDiffusionFaceCoefficient<
1172  MultiplyMolecularByDensity, AddTurbulence>(
1173  density, rho_comp, mu_turb, coefficients, i, j, k, 1, 0, 0,
1174  coefficients.eddy_h_comp);
1175  const bool on_side =
1176  (surface.xlo && i == dom_lo.x) ||
1177  (surface.xhi && i == dom_hi.x + 1);
1178  const bool on_bottom_z =
1179  surface.zlo && rotate && k == dom_lo.z;
1180 
1181  if (on_side && prescribed.use_x_on_side) {
1182  xflux(i, j, k, flux_comp) = prescribed.x(i, j, k, prescribed.x_comp);
1183  } else if (on_bottom_z && prescribed.use_x_on_bottom_z) {
1184  xflux(i, j, k, flux_comp) = prescribed.x(i, j, 0, prescribed.x_comp);
1185  } else {
1186  bool ext_lo, ext_hi;
1187  ScalarDiffusionLateralExtDir<0>(bc_ptr[bc_comp], u, i, j, k, dom_lo,
1188  dom_hi, ext_lo, ext_hi);
1189  xflux(i, j, k, flux_comp) = TerrainScalarDiffusionFluxAtIFace(
1190  scalar, scalar_comp, coeff, i, j, k, z_nd, z_cc, cellSizeInv, mf_ux,
1191  ext_lo, ext_hi);
1192  }
1193  });
1194 
1195  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1196  const Real coeff = ScalarDiffusionFaceCoefficient<
1197  MultiplyMolecularByDensity, AddTurbulence>(
1198  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 1, 0,
1199  coefficients.eddy_h_comp);
1200  const bool on_side =
1201  (surface.ylo && j == dom_lo.y) ||
1202  (surface.yhi && j == dom_hi.y + 1);
1203  const bool on_bottom_z =
1204  surface.zlo && rotate && k == dom_lo.z;
1205 
1206  if (on_side && prescribed.use_y_on_side) {
1207  yflux(i, j, k, flux_comp) = prescribed.y(i, j, k, prescribed.y_comp);
1208  } else if (on_bottom_z && prescribed.use_y_on_bottom_z) {
1209  yflux(i, j, k, flux_comp) = prescribed.y(i, j, 0, prescribed.y_comp);
1210  } else {
1211  bool ext_lo, ext_hi;
1212  ScalarDiffusionLateralExtDir<1>(bc_ptr[bc_comp], v, i, j, k, dom_lo,
1213  dom_hi, ext_lo, ext_hi);
1214  yflux(i, j, k, flux_comp) = TerrainScalarDiffusionFluxAtJFace(
1215  scalar, scalar_comp, coeff, i, j, k, z_nd, z_cc, cellSizeInv, mf_vy,
1216  ext_lo, ext_hi);
1217  }
1218  });
1219 
1220  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1221  const Real coeff = ScalarDiffusionFaceCoefficient<
1222  MultiplyMolecularByDensity, AddTurbulence>(
1223  density, rho_comp, mu_turb, vertical, i, j, k, 0, 0, 1,
1224  vertical.eddy_v_comp);
1225  const bool ext_lo =
1226  ((bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir) ||
1227  (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)) &&
1228  k == dom_lo.z;
1229  const bool ext_hi =
1230  ((bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir) ||
1231  (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)) &&
1232  k == dom_hi.z + 1;
1233  const bool on_surface =
1234  (surface.zlo && k == dom_lo.z) ||
1235  (surface.zhi && k == dom_hi.z + 1);
1236 
1237  const Real raw_flux = TerrainScalarDiffusionFluxAtKFace(
1238  scalar, scalar_comp, coeff, i, j, k, z_nd, cellSizeInv, ext_lo, ext_hi);
1239 
1240  if (on_surface && prescribed.use_z_on_side) {
1241  zflux(i, j, k, flux_comp) = prescribed.z(i, j, k, prescribed.z_comp);
1242  } else if (on_surface) {
1243  zflux(i, j, k, flux_comp) = Real(0.0);
1244  } else {
1245  zflux(i, j, k, flux_comp) = raw_flux;
1246  }
1247  if (diagnostic.enabled && (diagnostic.write_on_surface || !on_surface)) {
1248  diagnostic.z(i, j, k, diagnostic.z_comp) = zflux(i, j, k, flux_comp);
1249  }
1250  });
1251 }
1252 
1253 /**
1254  * Build all native terrain-grid face fluxes, including the grown horizontal
1255  * face regions needed by the mapped z-face transfer. The x and y faces read
1256  * policy.coefficients and the z faces read `vertical_coefficients` (its
1257  * molecular coefficient and eddy_v_comp). Each raw flux carries the
1258  * coefficient of its own direction before the single terrain mapping, whose
1259  * vertical transfer then combines both. A pass that gives every raw flux the
1260  * vertical coefficient does not produce that transfer, even with K_v = 0.
1261  */
1262 inline void
1264  const amrex::Box& bx,
1265  const amrex::Box& domain,
1266  const ScalarDiffusionFieldViews& field,
1267  const ScalarDiffusionFluxPolicy& policy,
1268  const ScalarDiffusionCoefficients& vertical_coefficients,
1269  const bool rotate,
1270  const amrex::Array4<const amrex::Real>& z_nd,
1271  const amrex::Array4<const amrex::Real>& z_cc,
1272  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1273  const amrex::Array4<const amrex::Real>& u,
1274  const amrex::Array4<const amrex::Real>& v,
1275  const amrex::Array4<const amrex::Real>& mf_ux,
1276  const amrex::Array4<const amrex::Real>& mf_vy,
1277  const amrex::BCRec* bc_ptr,
1278  const int bc_comp)
1279 {
1280  const auto mode = policy.coefficient_mode;
1281  const auto& vertical = vertical_coefficients;
1282  if (mode.molecular_is_kinematic) {
1283  if (mode.add_turbulence) {
1284  BuildScalarDiffusionFluxes_T_Impl<true, true>(
1285  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1286  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1287  } else {
1288  BuildScalarDiffusionFluxes_T_Impl<true, false>(
1289  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1290  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1291  }
1292  } else if (mode.add_turbulence) {
1293  BuildScalarDiffusionFluxes_T_Impl<false, true>(
1294  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1295  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1296  } else {
1297  BuildScalarDiffusionFluxes_T_Impl<false, false>(
1298  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1299  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1300  }
1301 }
1302 
1303 /** As above, with policy.coefficients on every face. */
1304 inline void
1306  const amrex::Box& bx,
1307  const amrex::Box& domain,
1308  const ScalarDiffusionFieldViews& field,
1309  const ScalarDiffusionFluxPolicy& policy,
1310  const bool rotate,
1311  const amrex::Array4<const amrex::Real>& z_nd,
1312  const amrex::Array4<const amrex::Real>& z_cc,
1313  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1314  const amrex::Array4<const amrex::Real>& u,
1315  const amrex::Array4<const amrex::Real>& v,
1316  const amrex::Array4<const amrex::Real>& mf_ux,
1317  const amrex::Array4<const amrex::Real>& mf_vy,
1318  const amrex::BCRec* bc_ptr,
1319  const int bc_comp)
1320 {
1321  BuildScalarDiffusionFluxes_T(bx, domain, field, policy, policy.coefficients,
1322  rotate, z_nd, z_cc, cellSizeInv, u, v, mf_ux, mf_vy,
1323  bc_ptr, bc_comp);
1324 }
1325 
1326 /**
1327  * Materialize the canonical N-grid face transfers. N-grid x/y builder outputs
1328  * already carry their map-factor ratios; only the vertical flux is divided by
1329  * the cell-centered horizontal map-factor product.
1330  */
1331 inline void
1333  const amrex::Box& bx,
1334  const amrex::Array4<const amrex::Real>& raw_x,
1335  const int raw_x_comp,
1336  const amrex::Array4<const amrex::Real>& raw_y,
1337  const int raw_y_comp,
1338  const amrex::Array4<const amrex::Real>& raw_z,
1339  const int raw_z_comp,
1340  const amrex::Array4<amrex::Real>& mapped_x,
1341  const int mapped_x_comp,
1342  const amrex::Array4<amrex::Real>& mapped_y,
1343  const int mapped_y_comp,
1344  const amrex::Array4<amrex::Real>& mapped_z,
1345  const int mapped_z_comp,
1346  const amrex::Array4<const amrex::Real>& mf_mx,
1347  const amrex::Array4<const amrex::Real>& mf_my)
1348 {
1349  const amrex::Box xbx = amrex::surroundingNodes(bx, 0);
1350  const amrex::Box ybx = amrex::surroundingNodes(bx, 1);
1351  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1353  xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1354  mapped_x(i, j, k, mapped_x_comp) =
1356  raw_x(i, j, k, raw_x_comp), amrex::Real(1.0));
1357  });
1359  ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1360  mapped_y(i, j, k, mapped_y_comp) =
1362  raw_y(i, j, k, raw_y_comp), amrex::Real(1.0));
1363  });
1365  zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1366  mapped_z(i, j, k, mapped_z_comp) =
1368  raw_z(i, j, k, raw_z_comp), mf_mx(i, j, 0), mf_my(i, j, 0));
1369  });
1370 }
1371 
1372 /**
1373  * Materialize the canonical S-grid face transfers. ax/ay restore the side
1374  * Jacobian measure omitted by the native S-grid divergence; detJ and the
1375  * computational z spacing are supplied separately to the mapped divergence.
1376  */
1377 inline void
1379  const amrex::Box& bx,
1380  const amrex::Array4<const amrex::Real>& raw_x,
1381  const int raw_x_comp,
1382  const amrex::Array4<const amrex::Real>& raw_y,
1383  const int raw_y_comp,
1384  const amrex::Array4<const amrex::Real>& raw_z,
1385  const int raw_z_comp,
1386  const amrex::Array4<amrex::Real>& mapped_x,
1387  const int mapped_x_comp,
1388  const amrex::Array4<amrex::Real>& mapped_y,
1389  const int mapped_y_comp,
1390  const amrex::Array4<amrex::Real>& mapped_z,
1391  const int mapped_z_comp,
1392  const amrex::Array4<const amrex::Real>& ax,
1393  const amrex::Array4<const amrex::Real>& ay,
1394  const amrex::Array4<const amrex::Real>& mf_mx,
1395  const amrex::Array4<const amrex::Real>& mf_my)
1396 {
1397  const amrex::Box xbx = amrex::surroundingNodes(bx, 0);
1398  const amrex::Box ybx = amrex::surroundingNodes(bx, 1);
1399  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1401  xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1402  mapped_x(i, j, k, mapped_x_comp) =
1404  raw_x(i, j, k, raw_x_comp), ax(i, j, k));
1405  });
1407  ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1408  mapped_y(i, j, k, mapped_y_comp) =
1410  raw_y(i, j, k, raw_y_comp), ay(i, j, k));
1411  });
1413  zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1414  mapped_z(i, j, k, mapped_z_comp) =
1416  raw_z(i, j, k, raw_z_comp), mf_mx(i, j, 0), mf_my(i, j, 0));
1417  });
1418 }
1419 
1420 /**
1421  * Materialize the canonical terrain-following transfers using ERF's existing
1422  * face mappings and authoritative Gz construction. The lower suppression
1423  * switch zeros the complete lower transfer, including terrain cross terms.
1424  *
1425  * Corresponding directional inputs and outputs may alias in place, including
1426  * the same component. The z transfer is launched first on AMReX's ordered
1427  * execution stream so it reads raw x/y fluxes before the x/y mapping launches
1428  * can overwrite them. Cross-direction aliasing is not supported.
1429  *
1430  * For each interior z face mapped from bx, raw_x and raw_y must be valid at
1431  * both kface and kface-1. Thus, if bx.smallEnd(2) is above the domain bottom,
1432  * raw_x/raw_y must include bx.smallEnd(2)-1; if bx.bigEnd(2) is below the
1433  * domain top, they must include bx.bigEnd(2)+1. No outside-domain layer is
1434  * required at a physical bottom/top face because the Gz helper uses one-sided
1435  * extrapolation. Raw candidates produced by BuildScalarDiffusionFluxes_T
1436  * already provide this z coverage.
1437  */
1438 inline void
1440  const amrex::Box& bx,
1441  const amrex::Box& domain,
1442  const amrex::Array4<const amrex::Real>& raw_x,
1443  const amrex::Array4<const amrex::Real>& raw_y,
1444  const amrex::Array4<const amrex::Real>& raw_z,
1445  const int raw_flux_comp,
1446  const amrex::Array4<amrex::Real>& mapped_x,
1447  const int mapped_x_comp,
1448  const amrex::Array4<amrex::Real>& mapped_y,
1449  const int mapped_y_comp,
1450  const amrex::Array4<amrex::Real>& mapped_z,
1451  const int mapped_z_comp,
1452  const amrex::Array4<const amrex::Real>& z_nd,
1453  const amrex::Array4<const amrex::Real>& ax,
1454  const amrex::Array4<const amrex::Real>& ay,
1455  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1456  const amrex::Array4<const amrex::Real>& mf_mx,
1457  const amrex::Array4<const amrex::Real>& mf_uy,
1458  const amrex::Array4<const amrex::Real>& mf_my,
1459  const amrex::Array4<const amrex::Real>& mf_vx,
1460  const bool suppress_lower_surface_z_transfer,
1461  const bool suppress_upper_z_transfer = false)
1462 {
1463  const amrex::Box xbx = amrex::surroundingNodes(bx, 0);
1464  const amrex::Box ybx = amrex::surroundingNodes(bx, 1);
1465  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1466  const amrex::Array4<const amrex::Real> xflux(raw_x);
1467  const amrex::Array4<const amrex::Real> yflux(raw_y);
1468  const amrex::Array4<const amrex::Real> zflux(raw_z);
1470  zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1471  const bool suppress =
1472  (suppress_lower_surface_z_transfer && k == domain.smallEnd(2)) ||
1473  (suppress_upper_z_transfer && k == domain.bigEnd(2) + 1);
1474  mapped_z(i, j, k, mapped_z_comp) =
1476  i, j, k, domain, xflux, yflux, zflux, raw_flux_comp, z_nd,
1477  cellSizeInv, mf_mx, mf_my, suppress);
1478  });
1479  amrex::ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1480  mapped_x(i, j, k, mapped_x_comp) = TerrainDiffusionMappedTx(
1481  raw_x(i, j, k, raw_flux_comp), ax(i, j, k), mf_uy(i, j, 0));
1482  });
1483  amrex::ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1484  mapped_y(i, j, k, mapped_y_comp) = TerrainDiffusionMappedTy(
1485  raw_y(i, j, k, raw_flux_comp), ay(i, j, k), mf_vx(i, j, 0));
1486  });
1487 }
1488 
1489 /**
1490  * Add the divergence of caller-supplied mapped transfers to rhs. Inputs are
1491  * only the accepted face arrays and the mapped cell geometry; in particular,
1492  * this operation cannot reconstruct a raw or terrain diffusion candidate.
1493  * The supplied face arrays and mapped-geometry convention are the same as
1494  * ApplyScalarAdvectionFluxDivergence. This diffusion operation differs in RHS
1495  * semantics: it accumulates -divergence into an existing RHS and leaves cells
1496  * with nonpositive detJ unchanged, whereas advection assigns its output and
1497  * zeroes such cells.
1498  */
1499 inline void
1501  const amrex::Box& bx,
1502  const amrex::Array4<const amrex::Real>& mapped_x,
1503  const int mapped_x_comp,
1504  const amrex::Array4<const amrex::Real>& mapped_y,
1505  const int mapped_y_comp,
1506  const amrex::Array4<const amrex::Real>& mapped_z,
1507  const int mapped_z_comp,
1508  const amrex::Array4<amrex::Real>& rhs,
1509  const int rhs_comp,
1510  const amrex::Array4<const amrex::Real>& detJ,
1511  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1512  const amrex::Array4<const amrex::Real>& mf_mx,
1513  const amrex::Array4<const amrex::Real>& mf_my)
1514 {
1515  const amrex::Real dx_inv = cellSizeInv[0];
1516  const amrex::Real dy_inv = cellSizeInv[1];
1517  const amrex::Real dzeta_inv = cellSizeInv[2];
1519  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1520  if (detJ(i, j, k) > amrex::Real(0.0)) {
1521  rhs(i, j, k, rhs_comp) -= ScalarDiffusionMappedFluxDivergence(
1522  mapped_x(i + 1, j, k, mapped_x_comp),
1523  mapped_x(i, j, k, mapped_x_comp),
1524  mapped_y(i, j + 1, k, mapped_y_comp),
1525  mapped_y(i, j, k, mapped_y_comp),
1526  mapped_z(i, j, k + 1, mapped_z_comp),
1527  mapped_z(i, j, k, mapped_z_comp), dx_inv, dy_inv, dzeta_inv,
1528  mf_mx(i, j, 0), mf_my(i, j, 0), detJ(i, j, k));
1529  }
1530  });
1531 }
1532 
1533 /** Apply native terrain diffusion in one kernel, mapping each face inline. */
1534 inline void
1536  const amrex::Box& bx,
1537  const amrex::Box& domain,
1538  const ScalarDiffusionFieldViews& field,
1539  const amrex::Array4<const amrex::Real>& z_nd,
1540  const amrex::Array4<const amrex::Real>& ax,
1541  const amrex::Array4<const amrex::Real>& ay,
1542  const amrex::Array4<const amrex::Real>& detJ,
1543  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1544  const amrex::Array4<const amrex::Real>& mf_mx,
1545  const amrex::Array4<const amrex::Real>& mf_uy,
1546  const amrex::Array4<const amrex::Real>& mf_my,
1547  const amrex::Array4<const amrex::Real>& mf_vx,
1548  const bool suppress_lower_z_flux,
1549  const bool suppress_upper_z_flux)
1550 {
1551  using namespace amrex;
1552  const auto dom_lo = lbound(domain);
1553  const auto dom_hi = ubound(domain);
1554  const Real dx_inv = cellSizeInv[0];
1555  const Real dy_inv = cellSizeInv[1];
1556  const Real dz_inv = cellSizeInv[2];
1557  const Array4<const Real> xflux(field.xflux);
1558  const Array4<const Real> yflux(field.yflux);
1559  const Array4<const Real> zflux(field.zflux);
1560  const auto rhs = field.rhs;
1561  const int flux_comp = field.flux_comp;
1562  const int rhs_comp = field.rhs_comp;
1563 
1564  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1565  const Real mapped_Fx_lo = TerrainDiffusionMappedTx(
1566  xflux(i, j, k, flux_comp), ax(i, j, k), mf_uy(i, j, 0));
1567  const Real mapped_Fx_hi = TerrainDiffusionMappedTx(
1568  xflux(i + 1, j, k, flux_comp), ax(i + 1, j, k), mf_uy(i + 1, j, 0));
1569  const Real mapped_Fy_lo = TerrainDiffusionMappedTy(
1570  yflux(i, j, k, flux_comp), ay(i, j, k), mf_vx(i, j, 0));
1571  const Real mapped_Fy_hi = TerrainDiffusionMappedTy(
1572  yflux(i, j + 1, k, flux_comp), ay(i, j + 1, k), mf_vx(i, j + 1, 0));
1573  const Real Gz_lo = (suppress_lower_z_flux && k == dom_lo.z)
1574  ? Real(0.0)
1576  i, j, k, domain, xflux, yflux, zflux, flux_comp,
1577  z_nd, cellSizeInv, mf_mx, mf_my);
1578  const Real Gz_hi = (suppress_upper_z_flux && k == dom_hi.z)
1579  ? Real(0.0)
1581  i, j, k + 1, domain, xflux, yflux, zflux, flux_comp,
1582  z_nd, cellSizeInv, mf_mx, mf_my);
1583  const Real mfsq = mf_mx(i, j, 0) * mf_my(i, j, 0);
1584  const Real stateContrib = TerrainDiffusionDivergence_T(
1585  mapped_Fx_hi, mapped_Fx_lo, mapped_Fy_hi, mapped_Fy_lo, Gz_hi, Gz_lo,
1586  dx_inv, dy_inv, dz_inv, mfsq, detJ(i, j, k));
1587  rhs(i, j, k, rhs_comp) -= stateContrib;
1588  });
1589 }
1590 
1591 /**
1592  * Apply the conservative N-grid divergence to a separately selected RHS
1593  * component. Face scratch is component-selected independently in each view.
1594  */
1595 inline void
1597  const amrex::Box& bx,
1598  const amrex::Array4<const amrex::Real>& xflux,
1599  const amrex::Array4<const amrex::Real>& yflux,
1600  const amrex::Array4<const amrex::Real>& raw_Fz,
1601  const int flux_comp,
1602  const amrex::Array4<amrex::Real>& rhs,
1603  const int rhs_comp,
1604  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1605  const amrex::Array4<const amrex::Real>& mf_mx,
1606  const amrex::Array4<const amrex::Real>& mf_my)
1607 {
1608  const amrex::Real dx_inv = cellSizeInv[0];
1609  const amrex::Real dy_inv = cellSizeInv[1];
1610  const amrex::Real dz_inv = cellSizeInv[2];
1611  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1612  const amrex::Real mfsq = mf_mx(i, j, 0) * mf_my(i, j, 0);
1613  rhs(i, j, k, rhs_comp) -=
1614  (xflux(i + 1, j, k, flux_comp) - xflux(i, j, k, flux_comp)) * dx_inv *
1615  mfsq +
1616  (yflux(i, j + 1, k, flux_comp) - yflux(i, j, k, flux_comp)) * dy_inv *
1617  mfsq +
1618  (raw_Fz(i, j, k + 1, flux_comp) - raw_Fz(i, j, k, flux_comp)) * dz_inv;
1619  });
1620 }
1621 
1622 /** S-grid conservative divergence; vertical cell width is the receiver's dz[k].
1623  */
1624 inline void
1626  const amrex::Box& bx,
1627  const amrex::Array4<const amrex::Real>& xflux,
1628  const amrex::Array4<const amrex::Real>& yflux,
1629  const amrex::Array4<const amrex::Real>& raw_Fz,
1630  const int flux_comp,
1631  const amrex::Array4<amrex::Real>& rhs,
1632  const int rhs_comp,
1633  const amrex::Array4<const amrex::Real>& mf_mx,
1634  const amrex::Array4<const amrex::Real>& mf_my,
1635  const amrex::Real dx_inv,
1636  const amrex::Real dy_inv,
1637  const amrex::Real* dz)
1638 {
1639  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1640  const amrex::Real mfsq = mf_mx(i, j, 0) * mf_my(i, j, 0);
1641  const amrex::Real dzk_inv = amrex::Real(1.0) / dz[k];
1642  const amrex::Real stateContrib =
1643  (xflux(i + 1, j, k, flux_comp) - xflux(i, j, k, flux_comp)) * dx_inv *
1644  mfsq +
1645  (yflux(i, j + 1, k, flux_comp) - yflux(i, j, k, flux_comp)) * dy_inv *
1646  mfsq +
1647  (raw_Fz(i, j, k + 1, flux_comp) - raw_Fz(i, j, k, flux_comp)) * dzk_inv;
1648  rhs(i, j, k, rhs_comp) -= stateContrib;
1649  });
1650 }
1651 
1652 /**
1653  * erf.implicit_terrain_metric: the implicit vertical solve also takes the compact
1654  * terrain-metric flux -K_h M_s dphi/dz (ERF_TerrainImplicitMetric.H) on the interior
1655  * zeta faces, so add implicit_fac * K_h M_s dphi/dz to the explicit raw F_z there. K_h
1656  * is the horizontal coefficient of the x/y fluxes, averaged to the z face; the bottom and
1657  * top faces, which carry the boundary condition, are left alone.
1658  */
1659 template <bool MultiplyMolecularByDensity, bool AddTurbulence>
1660 inline void
1662  const amrex::Box& zbx,
1663  const amrex::Box& domain,
1664  const ScalarDiffusionFieldViews& field,
1665  const ScalarDiffusionCoefficients& coefficients,
1666  const amrex::Array4<const amrex::Real>& z_nd,
1667  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1668  const amrex::Array4<const amrex::Real>& mf_mx,
1669  const amrex::Array4<const amrex::Real>& mf_my,
1670  const amrex::Real implicit_fac)
1671 {
1672  using namespace amrex;
1673  const int dom_klo = domain.smallEnd(2);
1674  const int dom_khi = domain.bigEnd(2);
1675  const auto scalar = field.scalar;
1676  const auto density = field.density;
1677  const auto mu_turb = field.mu_turb;
1678  const auto zflux = field.zflux;
1679  const int scalar_comp = field.scalar_comp;
1680  const int rho_comp = field.rho_comp;
1681  const int flux_comp = field.flux_comp;
1682  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1683  if (!TerrainMetricImplicitFace(k, dom_klo, dom_khi)) { return; }
1684  const Real kh = ScalarDiffusionFaceCoefficient<
1685  MultiplyMolecularByDensity, AddTurbulence>(
1686  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 0, 1,
1687  coefficients.eddy_h_comp);
1688  const Real h_zeta = Compute_h_zeta_AtKface(i, j, k, cellSizeInv, z_nd);
1689  const Real grad_z = (cellSizeInv[2] / h_zeta) *
1690  (scalar(i, j, k, scalar_comp) - scalar(i, j, k - 1, scalar_comp));
1691  const Real metric = TerrainMetricScalarFactor(
1692  Compute_h_xi_AtKface(i, j, k, cellSizeInv, z_nd),
1693  Compute_h_eta_AtKface(i, j, k, cellSizeInv, z_nd),
1694  mf_mx(i, j, 0), mf_my(i, j, 0));
1695  zflux(i, j, k, flux_comp) += implicit_fac * kh * metric * grad_z;
1696  });
1697 }
1698 
1699 /** Dispatch SubtractTerrainMetricImplicitPart_T_Impl on the coefficient mode. */
1700 inline void
1702  const amrex::Box& bx,
1703  const amrex::Box& domain,
1704  const ScalarDiffusionFieldViews& field,
1705  const ScalarDiffusionFluxPolicy& policy,
1706  const amrex::Array4<const amrex::Real>& z_nd,
1707  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1708  const amrex::Array4<const amrex::Real>& mf_mx,
1709  const amrex::Array4<const amrex::Real>& mf_my,
1710  const amrex::Real implicit_fac)
1711 {
1712  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1713  const auto mode = policy.coefficient_mode;
1714  if (mode.molecular_is_kinematic) {
1715  if (mode.add_turbulence) {
1716  SubtractTerrainMetricImplicitPart_T_Impl<true, true>(
1717  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1718  } else {
1719  SubtractTerrainMetricImplicitPart_T_Impl<true, false>(
1720  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1721  }
1722  } else if (mode.add_turbulence) {
1723  SubtractTerrainMetricImplicitPart_T_Impl<false, true>(
1724  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1725  } else {
1726  SubtractTerrainMetricImplicitPart_T_Impl<false, false>(
1727  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1728  }
1729 }
1730 
1731 /** Scale only raw F_z for the explicit integration fraction. */
1732 inline void
1734  const amrex::Box& zbx,
1735  const amrex::Array4<amrex::Real>& raw_Fz,
1736  const int flux_comp,
1737  const amrex::Real explicit_fac)
1738 {
1739  amrex::ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1740  raw_Fz(i, j, k, flux_comp) *= explicit_fac;
1741  });
1742 }
1743 
1744 
1745 /**
1746  * Face views into which the diffusive fluxes of each component are accumulated for refluxing,
1747  * indexed by state component, in the convention of the advective fluxes the flux registers
1748  * hold: a state update of -(m_x m_y / detJ) div F. Null when nothing is refluxed.
1749  */
1750 using ScalarDiffusionRefluxViews = amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>;
1751 
1752 /**
1753  * Add the diffusive face fluxes of one component on a flat mesh to the reflux face views.
1754  * ApplyScalarDiffusionFluxDivergence_N applies -(m^2 (dFx/dx + dFy/dy) + dFz/dz), so in the
1755  * advective convention the fluxes are Fx, Fy and Fz / m^2 (m^2 is per column, so it is the
1756  * same on both sides of a z face).
1757  */
1758 inline void
1760  const amrex::Box& bx,
1761  const amrex::Array4<const amrex::Real>& xflux,
1762  const amrex::Array4<const amrex::Real>& yflux,
1763  const amrex::Array4<const amrex::Real>& zflux,
1764  const int flux_comp,
1765  const ScalarDiffusionRefluxViews& reflux,
1766  const int state_comp,
1767  const amrex::Array4<const amrex::Real>& mf_mx,
1768  const amrex::Array4<const amrex::Real>& mf_my)
1769 {
1770  amrex::ParallelFor(amrex::surroundingNodes(bx, 0), amrex::surroundingNodes(bx, 1),
1771  amrex::surroundingNodes(bx, 2),
1772  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1773  reflux[0](i, j, k, state_comp) += xflux(i, j, k, flux_comp);
1774  },
1775  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1776  reflux[1](i, j, k, state_comp) += yflux(i, j, k, flux_comp);
1777  },
1778  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1779  reflux[2](i, j, k, state_comp) += zflux(i, j, k, flux_comp) / (mf_mx(i, j, 0) * mf_my(i, j, 0));
1780  });
1781 }
1782 
1783 /**
1784  * As AddScalarDiffusionRefluxFluxes_N, on a vertically stretched mesh: there detJ = dz[k] / dz,
1785  * and ApplyScalarDiffusionFluxDivergence_S applies -(m^2 (dFx/dx + dFy/dy) + dFz/dz[k]), so the
1786  * fluxes are detJ Fx, detJ Fy and Fz / m^2.
1787  */
1788 inline void
1790  const amrex::Box& bx,
1791  const amrex::Array4<const amrex::Real>& xflux,
1792  const amrex::Array4<const amrex::Real>& yflux,
1793  const amrex::Array4<const amrex::Real>& zflux,
1794  const int flux_comp,
1795  const ScalarDiffusionRefluxViews& reflux,
1796  const int state_comp,
1797  const amrex::Array4<const amrex::Real>& mf_mx,
1798  const amrex::Array4<const amrex::Real>& mf_my,
1799  const amrex::Real* dz,
1800  const amrex::Real dz_inv)
1801 {
1802  amrex::ParallelFor(amrex::surroundingNodes(bx, 0), amrex::surroundingNodes(bx, 1),
1803  amrex::surroundingNodes(bx, 2),
1804  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1805  reflux[0](i, j, k, state_comp) += dz[k] * dz_inv * xflux(i, j, k, flux_comp);
1806  },
1807  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1808  reflux[1](i, j, k, state_comp) += dz[k] * dz_inv * yflux(i, j, k, flux_comp);
1809  },
1810  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1811  reflux[2](i, j, k, state_comp) += zflux(i, j, k, flux_comp) / (mf_mx(i, j, 0) * mf_my(i, j, 0));
1812  });
1813 }
1814 
1815 /**
1816  * As AddScalarDiffusionRefluxFluxes_N, on a terrain-following mesh:
1817  * ApplyScalarDiffusionMappedDivergence_T applies -(1/detJ)(m^2 (dTx/dx + dTy/dy) + dGz/dzeta)
1818  * with the mapped transfers Tx, Ty and the vertical transfer Gz, so the fluxes are Tx, Ty and
1819  * Gz / m^2. suppress_lower_z_flux and suppress_upper_z_flux must be what that divergence was
1820  * given.
1821  */
1822 inline void
1824  const amrex::Box& bx,
1825  const amrex::Box& domain,
1826  const amrex::Array4<const amrex::Real>& xflux,
1827  const amrex::Array4<const amrex::Real>& yflux,
1828  const amrex::Array4<const amrex::Real>& zflux,
1829  const int flux_comp,
1830  const ScalarDiffusionRefluxViews& reflux,
1831  const int state_comp,
1832  const amrex::Array4<const amrex::Real>& z_nd,
1833  const amrex::Array4<const amrex::Real>& ax,
1834  const amrex::Array4<const amrex::Real>& ay,
1835  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& cellSizeInv,
1836  const amrex::Array4<const amrex::Real>& mf_mx,
1837  const amrex::Array4<const amrex::Real>& mf_my,
1838  const amrex::Array4<const amrex::Real>& mf_uy,
1839  const amrex::Array4<const amrex::Real>& mf_vx,
1840  const bool suppress_lower_z_flux,
1841  const bool suppress_upper_z_flux)
1842 {
1843  const int dom_klo = domain.smallEnd(2);
1844  const int dom_khi = domain.bigEnd(2);
1845  amrex::ParallelFor(amrex::surroundingNodes(bx, 0), amrex::surroundingNodes(bx, 1),
1846  amrex::surroundingNodes(bx, 2),
1847  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1848  reflux[0](i, j, k, state_comp) +=
1849  TerrainDiffusionMappedTx(xflux(i, j, k, flux_comp), ax(i, j, k), mf_uy(i, j, 0));
1850  },
1851  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1852  reflux[1](i, j, k, state_comp) +=
1853  TerrainDiffusionMappedTy(yflux(i, j, k, flux_comp), ay(i, j, k), mf_vx(i, j, 0));
1854  },
1855  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1856  const amrex::Real Gz = ((suppress_lower_z_flux && k == dom_klo) ||
1857  (suppress_upper_z_flux && k == dom_khi + 1))
1858  ? amrex::Real(0.0)
1859  : TerrainScalarDiffusionGzAtKFace(i, j, k, domain, xflux, yflux, zflux,
1860  flux_comp, z_nd, cellSizeInv,
1861  mf_mx, mf_my);
1862  reflux[2](i, j, k, state_comp) += Gz / (mf_mx(i, j, 0) * mf_my(i, j, 0));
1863  });
1864 }
1865 
1866 #endif // ERF_SCALAR_DIFFUSION_H_
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
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);})
Dimensionless numeric literals and pure mathematical constants.
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtJFace(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int k, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_vy, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:468
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Tx(const amrex::Real coeff, const amrex::Real face_map, const amrex::Real grad_xi, const amrex::Real h_xi, const amrex::Real grad_z) noexcept
Definition: ERF_ScalarDiffusion.H:363
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_N(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real coeff, const amrex::Real inv_spacing, const amrex::Real map_numerator, const amrex::Real map_denominator, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:258
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE StretchedDiffusionBoundaryWeights StretchedDiffusionDirichletWeights(const amrex::Real dz_near, const amrex::Real dz_next) noexcept
Definition: ERF_ScalarDiffusion.H:146
void BuildScalarDiffusionFluxes_N(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, 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::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:924
void BuildScalarDiffusionFluxes_S(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz, const int klo, const int khi, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, 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::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:1084
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionGz(const amrex::Real raw_Fz, const amrex::Real mx, const amrex::Real h_xi, const amrex::Real Fbar_x, const amrex::Real my, const amrex::Real h_eta, const amrex::Real Fbar_y) noexcept
Definition: ERF_ScalarDiffusion.H:573
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionHorizontalDelta(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:219
void ApplyScalarDiffusionFluxDivergence_N(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &raw_Fz, const int flux_comp, const amrex::Array4< amrex::Real > &rhs, const int rhs_comp, 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_ScalarDiffusion.H:1596
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFaceCoefficient(const amrex::Array4< const amrex::Real > &rho, const int rho_comp, const amrex::Array4< const amrex::Real > &mu_turb, const ScalarDiffusionCoefficients &coefficients, const int i, const int j, const int k, const int di, const int dj, const int dk, const int eddy_comp) noexcept
Definition: ERF_ScalarDiffusion.H:114
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedHorizontalTransfer(const amrex::Real raw_flux, const amrex::Real face_area) noexcept
Definition: ERF_ScalarDiffusion.H:609
void BuildScalarDiffusionMappedTransfers_T(const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_x, const amrex::Array4< const amrex::Real > &raw_y, const amrex::Array4< const amrex::Real > &raw_z, const int raw_flux_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_vx, const bool suppress_lower_surface_z_transfer, const bool suppress_upper_z_transfer=false)
Definition: ERF_ScalarDiffusion.H:1439
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedFluxDivergence(const amrex::Real fx_hi, const amrex::Real fx_lo, const amrex::Real fy_hi, const amrex::Real fy_lo, const amrex::Real fz_hi, const amrex::Real fz_lo, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real dzeta_inv, const amrex::Real mx, const amrex::Real my, const amrex::Real detJ_cell) noexcept
Definition: ERF_ScalarDiffusion.H:733
void BuildScalarDiffusionFluxes_T(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const ScalarDiffusionCoefficients &vertical_coefficients, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:1263
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedVerticalTransfer(const amrex::Real raw_flux, const amrex::Real mx, const amrex::Real my) noexcept
Definition: ERF_ScalarDiffusion.H:618
void BuildScalarDiffusionFluxes_T_Impl(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const ScalarDiffusionCoefficients &vertical_coefficients, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:1127
void BuildScalarDiffusionMappedTransfers_S(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &raw_x, const int raw_x_comp, const amrex::Array4< const amrex::Real > &raw_y, const int raw_y_comp, const amrex::Array4< const amrex::Real > &raw_z, const int raw_z_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
Definition: ERF_ScalarDiffusion.H:1378
void ScaleScalarDiffusionVerticalFlux(const amrex::Box &zbx, const amrex::Array4< amrex::Real > &raw_Fz, const int flux_comp, const amrex::Real explicit_fac)
Definition: ERF_ScalarDiffusion.H:1733
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ScalarDiffusionLateralExtDir(const amrex::BCRec &bc, const amrex::Array4< const amrex::Real > &vel, const int i, const int j, const int k, const amrex::Dim3 &dom_lo, const amrex::Dim3 &dom_hi, bool &ext_lo, bool &ext_hi) noexcept
Definition: ERF_ScalarDiffusion.H:173
void BuildScalarDiffusionMappedTransfers_N(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &raw_x, const int raw_x_comp, const amrex::Array4< const amrex::Real > &raw_y, const int raw_y_comp, const amrex::Array4< const amrex::Real > &raw_z, const int raw_z_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
Definition: ERF_ScalarDiffusion.H:1332
void AddScalarDiffusionRefluxFluxes_N(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const int flux_comp, const ScalarDiffusionRefluxViews &reflux, const int state_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
Definition: ERF_ScalarDiffusion.H:1759
amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > ScalarDiffusionRefluxViews
Definition: ERF_ScalarDiffusion.H:1750
void ApplyScalarDiffusionFluxDivergence_S(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &raw_Fz, const int flux_comp, const amrex::Array4< amrex::Real > &rhs, const int rhs_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz)
Definition: ERF_ScalarDiffusion.H:1625
void SubtractTerrainMetricImplicitPart_T_Impl(const amrex::Box &zbx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionCoefficients &coefficients, const amrex::Array4< const amrex::Real > &z_nd, 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::Real implicit_fac)
Definition: ERF_ScalarDiffusion.H:1661
void ApplyScalarDiffusionMappedDivergence_T(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, 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 > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_vx, const bool suppress_lower_z_flux, const bool suppress_upper_z_flux)
Definition: ERF_ScalarDiffusion.H:1535
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Ty(const amrex::Real coeff, const amrex::Real face_map, const amrex::Real grad_eta, const amrex::Real h_eta, const amrex::Real grad_z) noexcept
Definition: ERF_ScalarDiffusion.H:374
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtKFace(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int kface, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:518
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_S_Horizontal(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real coeff, const amrex::Real inv_spacing, const amrex::Real face_map, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:343
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionMappedTransferAtKFace(const int i, const int j, const int kface, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_xflux, const amrex::Array4< const amrex::Real > &raw_yflux, const amrex::Array4< const amrex::Real > &raw_zflux, const int flux_comp, const amrex::Array4< const amrex::Real > &z_nd, 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 bool suppress_transfer=false) noexcept
Definition: ERF_ScalarDiffusion.H:704
void SubtractTerrainMetricImplicitPart_T(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Array4< const amrex::Real > &z_nd, 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::Real implicit_fac)
Definition: ERF_ScalarDiffusion.H:1701
void BuildScalarDiffusionFluxes_S_Impl(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz, const int klo, const int khi, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, 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::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:963
void ApplyScalarMappedFluxDivergence(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< const amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< const amrex::Real > &mapped_z, const int mapped_z_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_ScalarDiffusion.H:1500
void BuildScalarDiffusionFluxes_N_Impl(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, 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::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:785
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionDivergence_T(const amrex::Real mapped_Fx_hi, const amrex::Real mapped_Fx_lo, const amrex::Real mapped_Fy_hi, const amrex::Real mapped_Fy_lo, const amrex::Real Gz_hi, const amrex::Real Gz_lo, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real dz_inv, const amrex::Real mfsq, const amrex::Real detJ_cell) noexcept
Definition: ERF_ScalarDiffusion.H:757
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtIFace(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int k, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_ux, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:421
void AddScalarDiffusionRefluxFluxes_S(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const int flux_comp, const ScalarDiffusionRefluxViews &reflux, const int state_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Real *dz, const amrex::Real dz_inv)
Definition: ERF_ScalarDiffusion.H:1789
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real StretchedScalarGradient(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real *dz, const int klo, const int khi, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:303
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTy(const amrex::Real raw_Fy, const amrex::Real h_zeta, const amrex::Real mx) noexcept
Definition: ERF_ScalarDiffusion.H:595
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionGzAtKFace(const int i, const int j, const int kface, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_xflux, const amrex::Array4< const amrex::Real > &raw_yflux, const amrex::Array4< const amrex::Real > &raw_zflux, const int flux_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my) noexcept
Definition: ERF_ScalarDiffusion.H:632
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainFaceHeightSpacingInv(const amrex::Array4< const amrex::Real > &z_nd, const int i, const int j, const int k) noexcept
Definition: ERF_ScalarDiffusion.H:393
void AddScalarDiffusionRefluxFluxes_T(const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const int flux_comp, const ScalarDiffusionRefluxViews &reflux, const int state_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, 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 bool suppress_lower_z_flux, const bool suppress_upper_z_flux)
Definition: ERF_ScalarDiffusion.H:1823
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTx(const amrex::Real raw_Fx, const amrex::Real h_zeta, const amrex::Real my) noexcept
Definition: ERF_ScalarDiffusion.H:586
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool TerrainMetricImplicitFace(const int kface, const int dom_lo, const int dom_hi) noexcept
Definition: ERF_TerrainImplicitMetric.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainMetricScalarFactor(const amrex::Real h_xi, const amrex::Real h_eta, const amrex::Real mx, const amrex::Real my) noexcept
Definition: ERF_TerrainImplicitMetric.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtKface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:445
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtJface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:397
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtKface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:468
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtKface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:421
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtWFace(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:741
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtIface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:304
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ ext_dir_prim
Definition: ERF_IndexDefines.H:320
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:325
@ rho
Definition: ERF_Kessler.H:25
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
Definition: ERF_ConsoleIO.cpp:17
real(c_double), parameter c2
Definition: ERF_module_model_constants.F90:35
real(c_double), private c1
Definition: ERF_module_mp_morr_two_moment.F90:212
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182
real(c_double), private di
Definition: ERF_module_mp_morr_two_moment.F90:203
Definition: ERF_ScalarDiffusion.H:50
bool molecular_is_kinematic
Definition: ERF_ScalarDiffusion.H:51
bool add_turbulence
Definition: ERF_ScalarDiffusion.H:52
Definition: ERF_ScalarDiffusion.H:24
int eddy_v_comp
Definition: ERF_ScalarDiffusion.H:27
int eddy_h_comp
Definition: ERF_ScalarDiffusion.H:26
amrex::Real molecular_coeff
Definition: ERF_ScalarDiffusion.H:25
Definition: ERF_ScalarDiffusion.H:34
int rho_comp
Definition: ERF_ScalarDiffusion.H:38
amrex::Array4< amrex::Real > xflux
Definition: ERF_ScalarDiffusion.H:40
amrex::Array4< amrex::Real > rhs
Definition: ERF_ScalarDiffusion.H:44
int rhs_comp
Definition: ERF_ScalarDiffusion.H:45
amrex::Array4< const amrex::Real > scalar
Definition: ERF_ScalarDiffusion.H:35
amrex::Array4< amrex::Real > yflux
Definition: ERF_ScalarDiffusion.H:41
int flux_comp
Definition: ERF_ScalarDiffusion.H:43
amrex::Array4< const amrex::Real > density
Definition: ERF_ScalarDiffusion.H:37
int scalar_comp
Definition: ERF_ScalarDiffusion.H:36
amrex::Array4< amrex::Real > zflux
Definition: ERF_ScalarDiffusion.H:42
amrex::Array4< const amrex::Real > mu_turb
Definition: ERF_ScalarDiffusion.H:39
Definition: ERF_ScalarDiffusion.H:93
ScalarDiffusionRawFluxDiagnostic diagnostic
Definition: ERF_ScalarDiffusion.H:97
ScalarDiffusionPrescribedFluxes prescribed
Definition: ERF_ScalarDiffusion.H:96
ScalarDiffusionCoefficientMode coefficient_mode
Definition: ERF_ScalarDiffusion.H:95
ScalarDiffusionSurfaceFaces surface
Definition: ERF_ScalarDiffusion.H:98
ScalarDiffusionCoefficients coefficients
Definition: ERF_ScalarDiffusion.H:94
Definition: ERF_ScalarDiffusion.H:57
bool use_z_on_side
Definition: ERF_ScalarDiffusion.H:60
int z_comp
Definition: ERF_ScalarDiffusion.H:68
bool use_y_on_bottom_z
Definition: ERF_ScalarDiffusion.H:62
amrex::Array4< const amrex::Real > x
Definition: ERF_ScalarDiffusion.H:63
amrex::Array4< const amrex::Real > z
Definition: ERF_ScalarDiffusion.H:65
bool use_x_on_side
Definition: ERF_ScalarDiffusion.H:58
int y_comp
Definition: ERF_ScalarDiffusion.H:67
bool use_x_on_bottom_z
Definition: ERF_ScalarDiffusion.H:61
amrex::Array4< const amrex::Real > y
Definition: ERF_ScalarDiffusion.H:64
bool use_y_on_side
Definition: ERF_ScalarDiffusion.H:59
int x_comp
Definition: ERF_ScalarDiffusion.H:66
Definition: ERF_ScalarDiffusion.H:73
int z_comp
Definition: ERF_ScalarDiffusion.H:77
amrex::Array4< amrex::Real > z
Definition: ERF_ScalarDiffusion.H:76
bool write_on_surface
Definition: ERF_ScalarDiffusion.H:75
bool enabled
Definition: ERF_ScalarDiffusion.H:74
Definition: ERF_ScalarDiffusion.H:82
bool zlo
Definition: ERF_ScalarDiffusion.H:87
bool xlo
Definition: ERF_ScalarDiffusion.H:83
bool ylo
Definition: ERF_ScalarDiffusion.H:85
bool xhi
Definition: ERF_ScalarDiffusion.H:84
bool yhi
Definition: ERF_ScalarDiffusion.H:86
bool zhi
Definition: ERF_ScalarDiffusion.H:88
Definition: ERF_ScalarDiffusion.H:141
amrex::Real c2
Definition: ERF_ScalarDiffusion.H:142
amrex::Real c3
Definition: ERF_ScalarDiffusion.H:142
amrex::Real c1
Definition: ERF_ScalarDiffusion.H:142