ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ComputeDiffusivityMRF.cpp File Reference
#include <algorithm>
#include "ERF_SurfaceLayer.H"
#include "ERF_DirectionSelector.H"
#include "ERF_Diffusion.H"
#include "ERF_Constants.H"
#include "ERF_TurbStruct.H"
#include "ERF_PBLModels.H"
#include "ERF_TileNoZ.H"
#include "ERF_MoistUtils.H"
#include "ERF_PBLScaleAwareBlending.H"
#include "ERF_LengthScaleCellSize.H"
#include "ERF_PBLRibCrossing.H"
Include dependency graph for ERF_ComputeDiffusivityMRF.cpp:

Functions

void ComputeDiffusivityMRF (const MultiFab &xvel, const MultiFab &yvel, const MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &turbChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, bool use_terrain_fitted_coords, bool use_moisture, int level, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_sfc_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices, const MultiFab *terrain_blank, const MultiFab *Q_fire_atm, GpuArray< const MultiFab *, 2 > mf_m)
 

Function Documentation

◆ ComputeDiffusivityMRF()

void ComputeDiffusivityMRF ( const MultiFab &  xvel,
const MultiFab &  yvel,
const MultiFab &  cons_in,
MultiFab &  eddyViscosity,
const Geometry &  geom,
const TurbChoice &  turbChoice,
std::unique_ptr< SurfaceLayer > &  SurfLayer,
bool  use_terrain_fitted_coords,
bool  use_moisture,
int  level,
const BCRec *  bc_ptr,
bool  ,
const std::unique_ptr< MultiFab > &  z_phys_nd,
const std::unique_ptr< MultiFab > &  z_sfc_nd,
const std::unique_ptr< MultiFab > &  z_phys_cc,
const MoistureComponentIndices &  moisture_indices,
const MultiFab *  terrain_blank,
const MultiFab *  Q_fire_atm,
GpuArray< const MultiFab *, 2 >  mf_m 
)

Compute vertical diffusivity using the Medium-Range Forecast (MRF) boundary layer scheme.

Parameters
[in]xvelx-velocity field.
[in]yvely-velocity field.
[in]cons_inInput conserved variables.
[out]eddyViscosityEddy viscosity and diffusivity coefficients.
[in]geomGrid geometry.
[in]turbChoiceTurbulence model options.
[in]SurfLayerSurface layer data.
[in]use_terrain_fitted_coordsUse terrain-fitted coordinates.
[in]use_moistureEnable moisture components.
[in]levelCurrent AMR level.
[in]bc_ptrBoundary condition records.
[in]z_phys_ndNodal physical heights.
[in]z_sfc_ndNodal heights of the bottom of the domain
[in]z_phys_ccCell-centered physical heights.
[in]moisture_indicesIndices for moisture variables.
56 {
57  const StratType pbl_strat = turbChoice.pbl_strat_type;
58  /*
59  ============================================================================
60  Medium-Range Forecast (MRF) Boundary Layer Parameterization Scheme
61  ============================================================================
62 
63  Implementation of the MRF (Medium Range Forecast) boundary layer scheme
64  based on Hong and Pan (1996), with enhanced moisture handling and
65  cloud-aware stability corrections developed for ERF.
66 
67  PRIMARY REFERENCES:
68  -------------------
69  - Hong, S. Y., and H.-L. Pan, 1996: Nonlocal Boundary Layer Vertical
70  Diffusion in a Medium-Range Forecast Model. Monthly Weather Review, 124,
71  2322-2339. https://doi.org/10.1175/1520-0493(1996)124<2322:NBLVDI>2.0.CO;2
72 
73  - WRF Reference Implementation: module_bl_mrf.F
74  https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F
75 
76  - Hong, S. Y., Y. Noh, and J. Dudhia, 2006: A new vertical diffusion
77  package with an explicit treatment of entrainment processes. Monthly
78  Weather Review, 134, 2318-2341. https://doi.org/10.1175/MWR3199.1
79  (YSU scheme, used for free atmosphere mixing)
80 
81  CORE ALGORITHM (Hong & Pan 1996):
82  ----------------------------------
83  1. Predictor-Corrector Bulk Richardson Number (Rib) PBL Height Diagnosis
84  - Rib = (g*z*(θ_v(z) - θ_v(0))) / (U²*θ_v(0))
85  - h = min(z where Rib > Rib_critical)
86 
87  2. Nonlocal Countergradient Flux Corrections
88  - HGAMT: thermal excess from sensible heat flux
89  - HGAMQ: moisture excess from latent heat flux
90  - VPERT: virtual potential temperature perturbation
91 
92  3. Stability-Dependent K-Profile in the PBL (used in EVERY stability regime)
93  - K_m = ρ * w_s * κ * z * (1 - (z - z_1)/(h - z_1))², z_1 = first level height
94  - K_t = K_m / Pr_t, and K_q = K_t (WRF diffuses moisture with the heat
95  coefficient XKZH; module_bl_mrf.F L1069, L1180)
96  - Stability enters only through w_s = u_* / φ_m (WRF's WSCALE); as in WRF there
97  is no regime test below the PBL top (module_bl_mrf.F L968-986). The
98  Ri-based mixing ERF used to apply inside stable/neutral PBLs is gone with
99  it; see KNOWN LIMITATION below for what that costs in stable layers.
100 
101  4. Free Atmosphere Mixing via Richardson Number
102  - Uses YSU stability functions (Hong et al. 2006)
103  - Ri-dependent diffusivity above the PBL top only (module_bl_mrf.F L988 on)
104 
105  FIRE COUPLING (ERF_USE_FIRE):
106  -----------------------------
107  Fire heat flux augments the convective velocity scale w* used in the
108  K-profile amplitude: K = rho * w*_eff * kappa * z * (1 - z/h)^2.
109  The PBLH itself (corrector) is NOT modified by fire, only w* is boosted.
110 
111  w*_fire = (g/theta * kbfs_total * h_corr)^(1/3), w*_eff = max(w*_fire, w*)
112 
113  where kbfs_total = kbfs_MOST + Q_fire/(rho*Cp), w* is the Pass 4 velocity
114  scale and h_corr the final corrected PBLH. The boost is applied only in
115  columns where Q_fire exceeds mrf_fire_q_threshold
116  (erf.pbl_mrf_fire_thermal_excess = true); HGAMT/HGAMQ keep the unboosted w*.
117 
118  ENHANCEMENTS IN ERF IMPLEMENTATION:
119  -----------------------------------
120 
121  A. Virtual Potential Temperature (θ_v) Treatment
122  - Proper handling of moisture effects on buoyancy
123  - Important for accurate PBL height and convective strength
124  - Not explicitly detailed in Hong & Pan (1996) but standard practice
125 
126  B. Cloud-Aware Stability Function Adjustments (OPTIONAL)
127  - Physically motivated extension beyond Hong & Pan (1996)
128  - Detects clouds via qc + qi > threshold (0.1 g/kg)
129  - In stable layers with clouds:
130  * Reduces stability damping (φ reduced by 10-20%)
131  * Represents suppressed turbulence due to stable stratification
132  - In unstable layers with clouds:
133  * Slightly increases instability enhancement
134  * Represents latent heat release effects
135  - Disabled by default for backward compatibility
136  - Reference: Conceptually similar to WRF's IMVDIF cloud handling
137 
138  C. Explicit Moisture Sign Convention Handling
139  - q_star uses WRF convention: negative for upward flux (evaporation)
140  - HGAMQ calculation: -const_b * u_* * q_* / w_*
141  - Produces positive HGAMQ for unstable (evaporating) conditions
142  - Corrected with MAX(HGAMQ, 0) to prevent negative values
143  - Land/water discrimination: HGAMQ zeroed over water surfaces
144 
145  D. Improved VPERT (Virtual Potential Temperature Perturbation)
146  Formulation
147  - VPERT = max(HGAMT + 0.61*θ*HGAMQ, 0)
148  - Enhancement vs WRF: Does not limit VPERT to GAMCRT
149  - WRF limits VPERT after adding moisture term (VPERT = min(VPERT, GAMCRT))
150  - This is physically incorrect: moisture contribution can exceed GAMCRT
151  - ERF only limits HGAMT (sensible heat), allowing larger VPERT when
152  both sensible and latent heat create strong surface heating
153  - This produces more realistic PBL heights in moist convection
154 
155  E. Prandtl Number with Stability Correction
156  - Pr_t = φ_t/φ_m + const_b * κ * sf
157  - Bounded: 0.5 ≤ Pr_t ≤ 4.0
158  - Consistency with WRF: const_b = 7.8, sf = 0.1
159  - Reference: Hong et al. (2006), Pr0 defined with Equation A4
160 
161  PARAMETER DEFAULTS (Matching WRF):
162  -----------------------------------
163  - const_b = 7.8 (heat flux weight in countergradient)
164  - sf = 0.1 (surface layer / PBL height ratio in stability functions)
165  - GAMCRT = 3.0 K (maximum heat countergradient)
166  - GAMCRQ = 2.0e-3 kg/kg (maximum moisture countergradient)
167  - Rib_crit = 0.5 (critical bulk Richardson number for PBL height)
168  - Pr_min = 0.5, Pr_max = 4.0 (Prandtl number bounds)
169  - Kmin = 0.1 m²/s, Kmax = 300 m²/s (diffusivity bounds, Hong & Pan 1996)
170 
171  STABILITY FUNCTIONS:
172  --------------------
173  Unstable (L < 0, HOL < 0):
174  phi_m = (1 - 8 * sf * h/L)^(-1/3)
175  phi_t = (1 - 16 * sf * h/L)^(-1/2)
176 
177  Stable (L > 0, HOL > 0):
178  Default: phi_m = phi_t = 1 + 5 * sf * h/L
179  QNSE (if enable_qnse_stable_functions=true):
180  phi_m = (1 + qnse_am * zeta) / (1 + qnse_bm * zeta)
181  phi_t = (1 + qnse_ah * zeta) / (1 + qnse_bh * zeta)
182  where zeta = sf * h/L, and default coefficients are from
183  Sukoriansky, Galperin & Perov (2005): qnse_am=2.5, qnse_bm=0.2,
184  qnse_ah=2.5, qnse_bh=0.2. QNSE functions remain bounded as zeta→∞,
185  avoiding over-mixing suppression in very stable conditions.
186 
187  MIXING ABOVE PBL (Free Atmosphere):
188  -----------------------------------
189  Uses YSU scheme (Hong et al. 2006, Appendix A) for Richardson number
190  dependent mixing. This avoids MRF oscillations in stable conditions.
191  It is applied above the PBL top only, as in WRF; below the top the
192  K-profile of item 3 above is used in every stability regime.
193 
194  Gradient Richardson number: Ri_g = (g/theta_v) * (dtheta_v/dz) / ((du/dz)^2 + (dv/dz)^2)
195 
196  For Ri_g > 0 (stable):
197  f_m = 1 / ((1 + 5*Ri_g)^2)
198  f_t = 1 / ((1 + 5*Ri_g)^2)
199  Pr_t = 1 + 2.1*Ri_g, bounded to [0.25, 4.0]
200 
201  For Ri_g < 0 (unstable):
202  f_m = 1 - 8*Ri_g / (1 + 1.746*sqrt(-Ri_g))
203  f_t = 1 - 8*Ri_g / (1 + 1.286*sqrt(-Ri_g))
204 
205  NUMERICAL CONSIDERATIONS:
206  -------------------------
207  - GPU-optimized with parallel_for loops
208  - Safe bounds on shear and vertical derivatives
209  - Gradient Richardson number limited: -100 <= Ri_g <= 100
210  - Avoids division by zero with minimum shear threshold (1e-10)
211  - theta_v_klo and theta_v guarded against zero/negative values
212 
213  KNOWN LIMITATION (stable layers):
214  ---------------------------------
215  With the K-profile applied in every regime, this scheme inherits WRF MRF's
216  over-mixing of stable boundary layers: on GABLS1 its peak K_m is roughly
217  2.1x YSU. That is the behavior Hong et al. (2006) set out to fix in YSU,
218  so stable cases that need the weaker mixing should use the YSU scheme
219  (erf.pbl_type = YSU).
220 
221  TESTING & VALIDATION:
222  ---------------------
223  - Tested against WRF_ideal unstable/stable ABL cases
224  - Backward compatible when enhancements are disabled
225  - Cloud detection threshold: qc + qi > 1e-4 kg/kg (0.1 g/kg)
226  */
227 
228  // Domain extent in z-dir
229  int klo = geom.Domain().smallEnd(2);
230  int khi = geom.Domain().bigEnd(2);
231 
232 
233 
234 // Collect MRF-computed PBLH for writing back to SurfaceLayer
235 MultiFab pblh_mf(eddyViscosity.boxArray(), eddyViscosity.DistributionMap(), 1, 0);
236 pblh_mf.setVal(0.0);
237 
238 // PBLH smoothing reads one column per pass outside the cells it writes, so the
239 // planar work arrays have to carry that many columns of halo and the PBLH passes
240 // have to fill them: otherwise the stencil reads off the end of the tile and the
241 // answer depends on the decomposition. With smoothing off this is the single
242 // column of halo the diffusivity kernels already use, so nothing changes.
243 const int ng_pblh = (turbChoice.enable_pblh_smoothing)
244  ? std::max(1, turbChoice.pblh_smoothing_passes) : 1;
245 
246 // The surface-layer fields carry one column of halo on the bottom surface; with more
247 // smoothing passes than that, the PBLH passes read them from copies widened to ng_pblh
248 // (see WidenForPBLH). Otherwise the fields are read directly.
249 const auto widen_sfc = [&] (const MultiFab* mf) -> std::unique_ptr<MultiFab> {
250  if (mf == nullptr || std::min(mf->nGrowVect()[0], mf->nGrowVect()[1]) >= ng_pblh) {
251  return nullptr;
252  }
253  return WidenForPBLH(*mf, ng_pblh,
254  [&] (MultiFab& wide) { SurfLayer->fill_planar_boundary(level, wide); });
255 };
256 const std::unique_ptr<MultiFab> u_star_wide = widen_sfc(SurfLayer->get_u_star(level));
257 const std::unique_ptr<MultiFab> t_star_wide = widen_sfc(SurfLayer->get_t_star(level));
258 const std::unique_ptr<MultiFab> q_star_wide = widen_sfc(SurfLayer->get_q_star(level));
259 const std::unique_ptr<MultiFab> olen_wide = widen_sfc(SurfLayer->get_olen(level));
260 const MultiFab* u_star_src = (u_star_wide) ? u_star_wide.get() : SurfLayer->get_u_star(level);
261 const MultiFab* t_star_src = (t_star_wide) ? t_star_wide.get() : SurfLayer->get_t_star(level);
262 const MultiFab* q_star_src = (q_star_wide) ? q_star_wide.get() : SurfLayer->get_q_star(level);
263 const MultiFab* olen_src = (olen_wide) ? olen_wide.get() : SurfLayer->get_olen(level);
264 
265 if (ng_pblh > 1) {
266  int ng_avail = std::min({cons_in.nGrowVect()[0], cons_in.nGrowVect()[1],
267  xvel.nGrowVect()[0], xvel.nGrowVect()[1],
268  yvel.nGrowVect()[0], yvel.nGrowVect()[1],
269  u_star_src->nGrowVect()[0], u_star_src->nGrowVect()[1],
270  olen_src->nGrowVect()[0], olen_src->nGrowVect()[1],
271  (terrain_blank) ? terrain_blank->nGrowVect()[0] : 1000,
272  (terrain_blank) ? terrain_blank->nGrowVect()[1] : 1000});
273  // The PBLH passes also read these fields over the same widened region;
274  // a field that is not allocated (nullptr) is not read.
275  auto limit_by = [&ng_avail] (const auto* mf) {
276  if (mf) { ng_avail = std::min({ng_avail, mf->nGrowVect()[0], mf->nGrowVect()[1]}); }
277  };
278  limit_by(t_star_src);
279  limit_by(q_star_src);
280  limit_by(SurfLayer->get_mac_avg(level, 3));
281  limit_by(SurfLayer->get_mac_avg(level, 4));
282  limit_by(SurfLayer->get_lmask(level));
283  limit_by((use_terrain_fitted_coords) ? z_phys_nd.get() : nullptr);
284  limit_by((use_terrain_fitted_coords) ? z_sfc_nd.get() : nullptr);
285  if (ng_pblh > ng_avail) {
286  amrex::Abort("erf.pblh_smoothing_passes = " + std::to_string(turbChoice.pblh_smoothing_passes)
287  + " needs " + std::to_string(ng_pblh) + " halo columns, but the fields the "
288  "PBLH passes read carry only " + std::to_string(ng_avail)
289  + "; reduce erf.pblh_smoothing_passes to at most " + std::to_string(ng_avail));
290  }
291 }
292 // The fire heat flux (erf.pbl_mrf_fire_thermal_excess) is read in every column the
293 // passes cover, the halo included, so it has to carry that many ghost columns.
294 if (Q_fire_atm != nullptr && turbChoice.mrf_fire_thermal_excess) {
295  const int ng_fire = std::min(Q_fire_atm->nGrowVect()[0], Q_fire_atm->nGrowVect()[1]);
296  if (ng_fire < ng_pblh) {
297  amrex::Abort("erf.pbl_mrf_fire_thermal_excess reads the fire heat flux in "
298  + std::to_string(ng_pblh) + " halo columns, but the flux carries only "
299  + std::to_string(ng_fire) + "; reduce erf.pblh_smoothing_passes to at most "
300  + std::to_string(ng_fire));
301  }
302 }
303 
304 // Maxima over the level of the fire w* boost, printed once below
305 const bool use_fire_correction = (Q_fire_atm != nullptr) && turbChoice.mrf_fire_thermal_excess;
306 Real fire_pblh_max_pred = Real(0);
307 Real fire_pblh_max_corr = Real(0);
308 Real fire_wstar_max = Real(0);
309 Real fire_kbfs_max = Real(0);
310 
311 #ifdef _OPENMP
312 #pragma omp parallel if (Gpu::notInLaunchRegion()) \
313  reduction(max:fire_pblh_max_pred,fire_pblh_max_corr,fire_wstar_max,fire_kbfs_max)
314 #endif
315 
316  for (MFIter mfi(eddyViscosity, TileNoZ()); mfi.isValid(); ++mfi) {
317 
318  // Box operated on must span fill domain in z-dir
319  const Box& gbx = mfi.growntilebox(IntVect(1,1,0));
320  AMREX_ALWAYS_ASSERT( gbx.smallEnd(2) == klo &&
321  gbx.bigEnd(2) == khi );
322 
323  // create flattened boxes to store PBL height and related quantities
324  const GeometryData gdata = geom.data();
325  const Box xybx = PerpendicularBox<ZDir>(gbx, IntVect{0, 0, 0});
326 
327  // The PBLH passes run on the region the smoothing stencil will consume
328  // (see ng_pblh above). growntilebox() is no use here: it does not grow at
329  // an interior tile edge, so a tile in the middle of a box gets no halo at
330  // all -- which is exactly how the stencil came to read off the end of the
331  // array. Grow the tile box explicitly instead, which costs a little
332  // duplicated work in the overlaps. With smoothing off this is xybx and
333  // nothing is duplicated.
334  const Box gbx_work = (turbChoice.enable_pblh_smoothing)
335  ? amrex::grow(mfi.tilebox(), IntVect(ng_pblh,ng_pblh,0)) : gbx;
336  const Box xybx_work = PerpendicularBox<ZDir>(gbx_work, IntVect{0, 0, 0});
337  const Box xybx_tile = PerpendicularBox<ZDir>(mfi.tilebox(), IntVect{0, 0, 0});
338 
339  // Pass 1 (predictor): PBLH with base surface temperature, no VPERT
340  // Pass 2 (wstar/VPERT): compute wstar, HGAMT, HGAMQ, VPERT from predictor height
341  // Pass 3 (corrector): PBLH with VPERT-enhanced surface temperature (WRF-consistent)
342  // WRF reference (module_bl_mrf.F lines 813-964):
343  // https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F#L813-L964
344  FArrayBox pbl_height_predictor(xybx_work, 1, The_Async_Arena()); // Pass 1: base t_layer_v
345  FArrayBox pbl_height_corrector(xybx_work, 1, The_Async_Arena()); // Pass 3: VPERT-enhanced
346  IArrayBox pbl_index(xybx_work, 1, The_Async_Arena());
347  IArrayBox pbl_index_zero_ri(xybx_work, 1, The_Async_Arena()); // Index for zero-Ri diagnostic pass
348  FArrayBox hgamt_fab(xybx_work, 1, The_Async_Arena()); // Store HGAMT/h (normalized countergradient)
349  FArrayBox hgamq_fab(xybx_work, 1, The_Async_Arena()); // Store HGAMQ/h (normalized countergradient)
350  FArrayBox wstar_fab(xybx_work, 1, The_Async_Arena()); // Convective velocity scale
351  FArrayBox vpert_fab(xybx_work, 1, The_Async_Arena()); // Virtual temperature perturbation VPERT
352  FArrayBox kbfs_fire_fab(xybx_work, 1, The_Async_Arena()); // Fire kinematic buoyancy flux [K m/s] per column
353  FArrayBox pblh_floor_fab(xybx_work, 1, The_Async_Arena()); // Floor of the corrected height per column, reapplied after the smoothing
354  const auto& pblh_pred_arr = pbl_height_predictor.array(); // predictor (base t_layer_v)
355  const auto& pblh_corr_arr = pbl_height_corrector.array(); // corrector (VPERT-enhanced)
356  const auto& pblh_floor_arr = pblh_floor_fab.array();
357  const auto& pbli_arr = pbl_index.array();
358  const auto& pbli_zero_arr = pbl_index_zero_ri.array(); // Zero-Ri diagnostic PBL index
359  const auto& hgamt_arr = hgamt_fab.array();
360  const auto& hgamq_arr = hgamq_fab.array();
361  const auto& wstar_arr = wstar_fab.array();
362  const auto& vpert_arr = vpert_fab.array();
363  const auto& kbfs_fire_arr = kbfs_fire_fab.array(); // Fire kinematic buoyancy flux
364 
365  // Get some data in arrays
366  const auto& cell_data = cons_in.const_array(mfi);
367  const auto& uvel = xvel.const_array(mfi);
368  const auto& vvel = yvel.const_array(mfi);
369 
370  const Real Ribcr = turbChoice.pbl_mrf_Ribcr;
371  const auto& u_star_arr = u_star_src->const_array(mfi);
372  const auto& t_star_arr = t_star_src->const_array(mfi);
373  const auto& l_obuk_arr = olen_src->const_array(mfi);
374  const auto& t10av_arr = SurfLayer->get_mac_avg(level, 3)->const_array(mfi);
375  const auto& q10av_arr = SurfLayer->get_mac_avg(level, 4)->const_array(mfi);
376  const auto& lmask_arr = (SurfLayer->get_lmask(level)) ?
377  SurfLayer->get_lmask(level)->const_array(mfi) :
378  Array4<int>{};
379  // Only retrieve z_phys_nd array if terrain-fitted coordinates are in use
380  const Array4<Real const> z_nd_arr = use_terrain_fitted_coords ? z_phys_nd->array(mfi)
381  : Array4<Real const>{};
382  const Array4<Real const> z_sfc_arr = use_terrain_fitted_coords ? z_sfc_nd->const_array(mfi)
383  : Array4<Real const>{};
384  const PBLDerivativeDzInv_T pbl_derivative_dz_inv{z_phys_cc->const_array(mfi)};
385 
386  // Fire heat flux array and flags
387  const Array4<Real const> Q_fire_arr = use_fire_correction
388  ? Q_fire_atm->const_array(mfi)
389  : Array4<Real const>{};
390  const Real mrf_fire_q_thresh = turbChoice.mrf_fire_q_threshold;
391 
392  //
393  // PASS 1 (PREDICTOR): Compute PBL height using base surface virtual temperature.
394  // No thermal excess (VPERT = 0). Produces pblh_pred_arr and pbli_arr.
395  // WRF reference (module_bl_mrf.F lines 813-842):
396  // https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F#L813-L842
397  //
398  // FIX: guard against null dereference of q_star when use_moisture is false (dry case)
399  // get_q_star can return null pointer when the field is not allocated
400  const amrex::MultiFab* q_star_mf = q_star_src;
401  Array4<Real const> q_star_arr = (q_star_mf != nullptr) ? q_star_mf->const_array(mfi)
402  : Array4<Real const>{};
403 
404  // --------------------------------------------------------------------
405  // Immersed-boundary awareness (turbChoice.pbl_ib_aware): per column,
406  // the first fluid cell above the immersed solid (ksurf) and its height
407  // above the domain bottom (zib). Every height below is measured from
408  // it, the diffusivities vanish inside the solid, and the surface
409  // scales of a column with solid cells are a neutral log law at its
410  // top instead of the ground surface layer's values (which come from
411  // cells inside the solid there). With the option off, or without
412  // immersed cells, ksurf = klo, zib = 0 and the scales are copies, so
413  // the arithmetic below is unchanged.
414  // --------------------------------------------------------------------
415  const bool l_ib = turbChoice.pbl_ib_aware && (terrain_blank != nullptr);
416  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!(l_ib && use_terrain_fitted_coords),
417  "erf.pbl_ib_aware is not supported with terrain-fitted coordinates");
418  const Array4<Real const> blank_arr = l_ib ? terrain_blank->const_array(mfi) : Array4<Real const>{};
419  IArrayBox ksurf_fab(xybx_work, 1, The_Async_Arena());
420  FArrayBox zib_fab(xybx_work, 1, The_Async_Arena());
421  FArrayBox us_eff_fab(xybx_work, 1, The_Async_Arena()), ts_eff_fab(xybx_work, 1, The_Async_Arena());
422  FArrayBox qs_eff_fab(xybx_work, 1, The_Async_Arena()), ol_eff_fab(xybx_work, 1, The_Async_Arena());
423  FArrayBox t10_eff_fab(xybx_work, 1, The_Async_Arena()), q10_eff_fab(xybx_work, 1, The_Async_Arena());
424  const auto& ksurf_arr = ksurf_fab.array();
425  const auto& zib_arr = zib_fab.array();
426  const auto& us_eff_arr = us_eff_fab.array(); const auto& ts_eff_arr = ts_eff_fab.array();
427  const auto& qs_eff_arr = qs_eff_fab.array(); const auto& ol_eff_arr = ol_eff_fab.array();
428  const auto& t10_eff_arr = t10_eff_fab.array(); const auto& q10_eff_arr = q10_eff_fab.array();
429  {
430  const Real dz_ib = geom.CellSize(2);
431  const Real z0_ib = turbChoice.pbl_ib_z0;
432  const Array4<Real const>& uv_ib = xvel.const_array(mfi);
433  const Array4<Real const>& vv_ib = yvel.const_array(mfi);
434  const bool have_qstar = (q_star_mf != nullptr);
435  ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
436  {
437  int ks = klo;
438  if (l_ib) {
439  for (int kk = klo; kk <= khi; ++kk) { if (blank_arr(i, j, kk) >= Real(0.5)) { ks = kk + 1; } }
440  if (ks > khi) { ks = khi; }
441  }
442  ksurf_arr(i, j, 0) = ks;
443  zib_arr(i, j, 0) = (ks - klo) * dz_ib;
444  if (ks > klo) {
445  // Column with immersed solid: neutral log law at its top.
446  const Real u_top = myhalf * (uv_ib(i, j, ks) + uv_ib(i + 1, j, ks));
447  const Real v_top = myhalf * (vv_ib(i, j, ks) + vv_ib(i, j + 1, ks));
448  const Real ws_top = std::sqrt(u_top * u_top + v_top * v_top);
449  us_eff_arr(i, j, 0) = amrex::max(KAPPA * ws_top / std::log(myhalf * dz_ib / z0_ib), Real(1.0e-3));
450  ts_eff_arr(i, j, 0) = Real(0);
451  qs_eff_arr(i, j, 0) = Real(0);
452  ol_eff_arr(i, j, 0) = immersed_neutral_obukhov_length;
453  t10_eff_arr(i, j, 0) = cell_data(i, j, ks, RhoTheta_comp) / cell_data(i, j, ks, Rho_comp);
454  q10_eff_arr(i, j, 0) = (use_moisture && moisture_indices.qv >= 0)
455  ? cell_data(i, j, ks, moisture_indices.qv) / cell_data(i, j, ks, Rho_comp) : Real(0);
456  } else {
457  us_eff_arr(i, j, 0) = u_star_arr(i, j, 0);
458  ts_eff_arr(i, j, 0) = t_star_arr(i, j, 0);
459  qs_eff_arr(i, j, 0) = have_qstar ? q_star_arr(i, j, 0) : Real(0);
460  ol_eff_arr(i, j, 0) = l_obuk_arr(i, j, 0);
461  t10_eff_arr(i, j, 0) = t10av_arr(i, j, 0);
462  q10_eff_arr(i, j, 0) = use_moisture ? q10av_arr(i, j, 0) : Real(0);
463  }
464  });
465  }
466 
467  // For the thickness of the first fluid cell in the PBL-height floor of both Rib passes
468  // (the same expression as in YSU, so the two floors are equal to the last bit)
469  const GpuArray<Real, AMREX_SPACEDIM> dxInv_floor = geom.InvCellSizeArray();
470 
471  ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
472  {
473  const int ksrf = ksurf_arr(i, j, 0); // local surface: first fluid cell of the column
474  const Real zib = zib_arr(i, j, 0); // its height, subtracted from every height below
475  amrex::ignore_unused(zib);
476  const Real t_layer = t10_eff_arr(i, j, 0);
477  const Real moisture_fraction = use_moisture ? q10_eff_arr(i, j, 0) : Real(0);
478  const Real t_layer_v = t_layer * (one + epsv * moisture_fraction);
479 
480  Real zval, Rib;
481  int kpbl = ksrf;
482 
483  {
484  zval = (use_terrain_fitted_coords)
485  ? Compute_Zrel_AtCellCenter(i, j, kpbl, z_sfc_arr, z_nd_arr)
486  : ((kpbl + myhalf) * gdata.CellSize(2) - zib);
487  const Real theta_v = GetThetav(i, j, kpbl, cell_data, moisture_indices);
488  const Real theta_v_klo = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), Real(1.0));
489  const Real ws2_raw = fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
490  (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
491  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
492  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
493  // Vogelezang & Holtslag (1996): Add shear correction term to denominator instead of ad-hoc floor
494  // to better represent shear associated with surface-layer turbulence at low wind speeds.
495  // Reference: Vogelezang, D.H.P., and A.A.M. Holtslag, 1996: Evaluation and model impacts of
496  // alternative boundary-layer height formulations. Boundary-Layer Meteorology, 81, 245–269.
497  const Real ws2 = (turbChoice.enable_vh96_shear_correction)
498  ? (ws2_raw + turbChoice.vh96_shear_const_b * us_eff_arr(i,j,0) * us_eff_arr(i,j,0))
499  : amrex::max(ws2_raw, Real(1.0));
500  Rib = CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
501  }
502 
503  Real zval0 = zval, Rib0 = Rib;
504  bool above_critical = false;
505  while (!above_critical && ((kpbl + 1) <= khi)) {
506  zval0 = zval;
507  Rib0 = Rib;
508  kpbl += 1;
509 
510  zval = (use_terrain_fitted_coords)
511  ? Compute_Zrel_AtCellCenter(i, j, kpbl, z_sfc_arr, z_nd_arr)
512  : ((kpbl + myhalf) * gdata.CellSize(2) - zib);
513  const Real theta_v = GetThetav(i, j, kpbl, cell_data, moisture_indices);
514  const Real theta_v_klo = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), Real(1.0));
515  const Real ws2_raw = fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
516  (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
517  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
518  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
519  // Vogelezang & Holtslag (1996): Add shear correction term to denominator instead of ad-hoc floor
520  // to better represent shear associated with surface-layer turbulence at low wind speeds.
521  const Real ws2 = (turbChoice.enable_vh96_shear_correction)
522  ? (ws2_raw + turbChoice.vh96_shear_const_b * us_eff_arr(i,j,0) * us_eff_arr(i,j,0))
523  : amrex::max(ws2_raw, Real(1.0));
524  Rib = CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
525  above_critical = (Rib >= Ribcr);
526  }
527 
528  // The floor is the top face of the column's first fluid cell (see pblh_floor),
529  // as in YSU: zl1 is the height of that cell's center above the local surface
530  // and dz1 its thickness, on every mesh type.
531  const Real zl1 = (use_terrain_fitted_coords)
532  ? Compute_Zrel_AtCellCenter(i, j, ksrf, z_sfc_arr, z_nd_arr)
533  : myhalf * gdata.CellSize(2);
534  const Real dz1 = (use_terrain_fitted_coords)
535  ? Compute_h_zeta_AtCellCenter(i, j, ksrf, dxInv_floor, z_nd_arr) / dxInv_floor[2]
536  : gdata.CellSize(2);
537  const Real z_max = (use_terrain_fitted_coords)
538  ? Compute_Zrel_AtCellCenter(i, j, khi, z_sfc_arr, z_nd_arr)
539  : ((khi + myhalf) * gdata.CellSize(2) - zib);
540  const Real pblh_max = Real(0.9) * z_max;
541  const Real pblh_min = pblh_floor(zl1, dz1);
542 
543  if (above_critical) {
544  Real pblh_interp;
545  const Real rib_diff = Rib - Rib0;
546  if (Rib0 >= Ribcr) {
547  // The level below was at or above Ribcr too (only the surface cell can be):
548  // WRF brint = 0, the height of that level, not an extrapolation above it
549  pblh_interp = zval0;
550  } else if (std::abs(rib_diff) > Real(1.0e-10)) {
551  pblh_interp = zval0 + (zval - zval0) / rib_diff * (Ribcr - Rib0);
552  } else {
553  // If Rib not changing, use zval0 as PBL height
554  pblh_interp = zval0;
555  }
556  pblh_pred_arr(i, j, 0) = amrex::max(amrex::min(pblh_interp, pblh_max), pblh_min);
557  pbli_arr(i, j, 0) = kpbl;
558  } else {
559  // No crossing up to khi: the scan ended there with zval = z(khi), the top of
560  // the scan, capped by pblh_max, and kpbl = khi, so the K profile and the
561  // countergradient gates below cover the column (WRF module_bl_mrf.F, brint = 1).
562  pblh_pred_arr(i, j, 0) = amrex::max(amrex::min(zval, pblh_max), pblh_min);
563  pbli_arr(i, j, 0) = kpbl;
564  }
565  });
566 
567  const Real const_b = turbChoice.pbl_mrf_const_b;
568  const Real sf = turbChoice.pbl_mrf_sf;
569  constexpr Real prmin = Real(0.5);
570  constexpr Real prmax = Real(4.0);
571  constexpr Real GAMCRT = Real(3.0);
572  constexpr Real GAMCRQ = Real(2.e-3);
573  const bool enable_mrf_countergradient = turbChoice.enable_mrf_countergradient;
574  const bool enable_mrf_unbounded_vpert = turbChoice.enable_mrf_unbounded_vpert;
575 
576  //
577  // PASS 2 (WSTAR / VPERT): Compute wstar, HGAMT, HGAMQ, VPERT using the
578  // predictor PBL height (pblh_pred_arr). VPERT will be fed into the corrector
579  // Rib search in Pass 3 to raise the effective surface temperature.
580  // WRF reference (module_bl_mrf.F lines 857-880):
581  // https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F#L857-L880
582  //
583  ParallelFor(xybx_work, [=,zero_d=zero] AMREX_GPU_DEVICE(int i, int j, int) noexcept
584  {
585  const int ksrf = ksurf_arr(i, j, 0); // local surface: first fluid cell of the column
586  const Real zib = zib_arr(i, j, 0); // its height, subtracted from every height below
587  amrex::ignore_unused(zib);
588  const Real t_layer = t10_eff_arr(i, j, 0);
589  Real obuk_val = ol_eff_arr(i, j, 0);
590  if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
591  obuk_val = (obuk_val >= zero_d) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
592  }
593 
594  // HOL computed from predictor height (WRF uses predictor height for wstar/VPERT)
595  const Real HOL = sf * pblh_pred_arr(i, j, 0) / obuk_val;
596  const Real HOL_bounded = amrex::max(amrex::min(HOL, Real(100.0)), Real(-100.0));
597  // |HOL|, so the base 1 + 16*HOL_abs of the unstable arm below equals its
598  // 1 - 16*HOL there and is at least 1 for every HOL; a guard written inside the
599  // arm gets folded away by the optimizer and the pow hoisted (see sqrt_neg_Ri).
600  const Real HOL_abs = std::abs(HOL_bounded);
601  const Real one_quarter = Real(0.25);
602  const Real phiM = (obuk_val > 0)
603  ? (1 + 5 * HOL_bounded)
604  : std::pow(1 + 16 * HOL_abs, -one_quarter);
605  const Real phiM_safe = amrex::max(phiM, Real(0.01));
606 
607  // wstar = u* / phi_m
608  // Absolute bounds [0.01, 5.0] m/s: prevent division-by-zero (floor) and
609  // free-convection blow-up (ceiling), independent of u* for u*->0 safety.
610  // BOOTSTRAP NOTE: pblh_pred_arr must be finite (not sentinel) before this
611  // kernel runs. On cold start, pblh_pred_arr is computed in Pass 1 above;
612  // on regrid, SurfaceLayer PBLH may be sentinel — callers must re-run
613  // ComputeDiffusivityMRF before consuming wstar or Beljaars correction after regrid.
614  // Deardorff (1972) convective velocity scale — well-behaved as u_star -> 0.
615  // wstar_conv = (g/theta_v0 * zi * wthv0)^(1/3)
616  const Real theta_v0 = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), Real(1.0));
617  const Real wthv0 = amrex::max(-us_eff_arr(i,j,0) * ts_eff_arr(i,j,0), Real(0.0)); // surface buoyancy flux, unstable only
618  const Real zi = amrex::max(pblh_pred_arr(i, j, 0), Real(10.0)); // predictor: Pass 3 has not run yet
619  const Real wstar_conv = std::cbrt(CONST_GRAV / theta_v0 * zi * wthv0);
620 
621  Real wstar_shear = us_eff_arr(i, j, 0) / phiM_safe;
622 
623  // Blend: standard convective/shear combination (WRF YSU-style),
624  // weighted by cube sum so either term can dominate smoothly
625  Real wstar = std::cbrt(wstar_shear*wstar_shear*wstar_shear +
626  wstar_conv*wstar_conv*wstar_conv);
627 
628  wstar = amrex::max(wstar, Real(0.01));
629  wstar = amrex::min(wstar, Real(5.0));
630 
631  // Fire kinematic buoyancy flux [K m/s] for the w* boost in Pass 4,
632  // kbfs_fire = Q_fire / (rho_sfc * Cp_d). Fire does not enter the PBLH.
633  // (FLARE's value of Cp_d, kept so its fire runs do not change; ERF_Constants has 1004.5)
634  constexpr Real Cp_d_fire = Real(1004.64);
635  Real kbfs_fire = zero_d;
636  if (use_fire_correction && Q_fire_arr) {
637  const Real rho_sfc = cell_data(i, j, ksrf, Rho_comp);
638  const Real q_fire = Q_fire_arr(i, j, 0);
639  if (q_fire > mrf_fire_q_thresh && rho_sfc > zero_d) {
640  // max() keeps the division valid if it is evaluated speculatively
641  kbfs_fire = q_fire / (amrex::max(rho_sfc, Real(1.0e-10)) * Cp_d_fire);
642  }
643  }
644  kbfs_fire_arr(i, j, 0) = kbfs_fire;
645 
646  bool SFCFLG = (obuk_val <= zero_d);
647  const Real HGAMT = (SFCFLG && enable_mrf_countergradient)
648  ? amrex::min(-const_b * us_eff_arr(i, j, 0) * ts_eff_arr(i, j, 0) / wstar, GAMCRT)
649  : zero_d;
650 
651  Real HGAMQ = Real(0);
652  if (SFCFLG && use_moisture && enable_mrf_countergradient) {
653  const Real q_star = qs_eff_arr(i, j, 0);
654  const Real HGAMQ_calc = -const_b * us_eff_arr(i, j, 0) * q_star / wstar;
655  HGAMQ = amrex::max(amrex::min(HGAMQ_calc, GAMCRQ), Real(0));
656 
657  if (lmask_arr) {
658  bool is_land = (lmask_arr(i,j,0) == 1);
659  if (!is_land) HGAMQ = zero_d;
660  }
661 
662  if (moisture_indices.qv >= 0) {
663  Real qv_klo = cell_data(i, j, ksrf, moisture_indices.qv) / cell_data(i, j, ksrf, Rho_comp);
664  Real T_klo = getTgivenRandRTh(cell_data(i, j, ksrf, Rho_comp),
665  cell_data(i, j, ksrf, RhoTheta_comp), qv_klo);
666  Real p_klo = getPgivenRTh(cell_data(i, j, ksrf, RhoTheta_comp), qv_klo) * Real(0.01);
667  Real qsat_klo = zero_d;
668  erf_qsatw(T_klo, p_klo, qsat_klo);
669  Real rh_klo = (qsat_klo > Real(1.0e-10)) ? (qv_klo / qsat_klo) : Real(0);
670  if (rh_klo > Real(0.95)) {
671  Real rh_scaling = amrex::max(zero_d, (Real(1) - rh_klo) / Real(0.05));
672  HGAMQ *= rh_scaling;
673  }
674  }
675  }
676 
677  // Compute VPERT = HGAMT + 0.61*theta*HGAMQ (virtual temperature perturbation)
678  // This will be added to the surface temperature in the corrector Rib search.
679  // WRF Reference: module_bl_mrf.F lines 879-880
680  if (pbli_arr(i, j, 0) <= ksrf + 1 || !enable_mrf_countergradient) {
681  vpert_arr(i, j, 0) = zero_d;
682  } else {
683  const Real VPERT_raw = HGAMT + epsv * t_layer * HGAMQ;
684  const Real VPERT_capped = enable_mrf_unbounded_vpert
685  ? VPERT_raw
686  : amrex::min(VPERT_raw, GAMCRT);
687  vpert_arr(i, j, 0) = amrex::max(VPERT_capped, zero_d);
688  }
689  });
690 
691  //
692  // PASS 3 (CORRECTOR): Recompute PBL height with VPERT-enhanced surface temperature.
693  // theta_s = theta_va + VPERT (Hong & Pan 1996, Eq. 4)
694  // This is the WRF-consistent corrector pass. pblh_corr_arr is used for the
695  // K-profile shape function K = rho*wstar*kappa*z*(1-z/h)^2.
696  // WRF reference (module_bl_mrf.F lines 932-964):
697  // https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F#L932-L964
698  //
699  ParallelFor(xybx_work, [=,one_d=one]
700  AMREX_GPU_DEVICE(int i, int j, int) noexcept
701  {
702  const int ksrf = ksurf_arr(i, j, 0); // local surface: first fluid cell of the column
703  const Real zib = zib_arr(i, j, 0); // its height, subtracted from every height below
704  amrex::ignore_unused(zib);
705  const Real t_layer = t10_eff_arr(i, j, 0);
706  const Real moisture_fraction = use_moisture ? q10_eff_arr(i, j, 0) : Real(0);
707  // VPERT-enhanced surface virtual temperature (WRF THERMAL variable)
708  const Real t_layer_v = t_layer * (one + epsv * moisture_fraction)
709  + vpert_arr(i, j, 0);
710 
711  Real obuk_val = ol_eff_arr(i, j, 0);
712  if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
713  obuk_val = (obuk_val >= zero) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
714  }
715 
716  int kpbl = ksrf;
717  Real zval, Rib;
718  {
719  zval = (use_terrain_fitted_coords)
720  ? Compute_Zrel_AtCellCenter(i, j, kpbl, z_sfc_arr, z_nd_arr)
721  : ((kpbl + myhalf) * gdata.CellSize(2) - zib);
722  const Real theta_v = GetThetav(i, j, kpbl, cell_data, moisture_indices);
723  const Real theta_v_klo = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
724  const Real ws2_raw = fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
725  (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
726  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
727  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
728  // Vogelezang & Holtslag (1996): Add shear correction term to denominator instead of ad-hoc floor
729  const Real ws2 = (turbChoice.enable_vh96_shear_correction)
730  ? (ws2_raw + turbChoice.vh96_shear_const_b * us_eff_arr(i,j,0) * us_eff_arr(i,j,0))
731  : amrex::max(ws2_raw, one_d);
732  Rib = CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
733  }
734  Real zval0 = zval, Rib0 = Rib;
735 
736  bool above_critical = false;
737  while (!above_critical && ((kpbl + 1) <= khi)) {
738  zval0 = zval;
739  Rib0 = Rib;
740  kpbl += 1;
741 
742  zval = (use_terrain_fitted_coords)
743  ? Compute_Zrel_AtCellCenter(i, j, kpbl, z_sfc_arr, z_nd_arr)
744  : ((kpbl + myhalf) * gdata.CellSize(2) - zib);
745  const Real theta_v = GetThetav(i, j, kpbl, cell_data, moisture_indices);
746  const Real theta_v_klo = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
747  const Real ws2_raw = fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
748  (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
749  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
750  (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
751  // Vogelezang & Holtslag (1996): Add shear correction term to denominator instead of ad-hoc floor
752  const Real ws2 = (turbChoice.enable_vh96_shear_correction)
753  ? (ws2_raw + turbChoice.vh96_shear_const_b * us_eff_arr(i,j,0) * us_eff_arr(i,j,0))
754  : amrex::max(ws2_raw, one_d);
755  Rib = CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
756  above_critical = (Rib >= Ribcr);
757  }
758 
759  // The floor is the top face of the column's first fluid cell (see pblh_floor),
760  // as in YSU: zl1 is the height of that cell's center above the local surface
761  // and dz1 its thickness, on every mesh type.
762  const Real zl1 = (use_terrain_fitted_coords)
763  ? Compute_Zrel_AtCellCenter(i, j, ksrf, z_sfc_arr, z_nd_arr)
764  : myhalf * gdata.CellSize(2);
765  const Real dz1 = (use_terrain_fitted_coords)
766  ? Compute_h_zeta_AtCellCenter(i, j, ksrf, dxInv_floor, z_nd_arr) / dxInv_floor[2]
767  : gdata.CellSize(2);
768  const Real z_max = (use_terrain_fitted_coords)
769  ? Compute_Zrel_AtCellCenter(i, j, khi, z_sfc_arr, z_nd_arr)
770  : ((khi + myhalf) * gdata.CellSize(2) - zib);
771  const Real pblh_max = Real(0.9) * z_max;
772  const Real pblh_min = pblh_floor(zl1, dz1);
773 
774  if (above_critical) {
775  Real pblh_interp;
776  const Real rib_diff = Rib - Rib0;
777  if (Rib0 >= Ribcr) {
778  // The level below was at or above Ribcr too (only the surface cell can be):
779  // WRF brint = 0, the height of that level, not an extrapolation above it
780  pblh_interp = zval0;
781  } else if (std::abs(rib_diff) > Real(1.0e-10)) {
782  pblh_interp = zval0 + (zval - zval0) / rib_diff * (Ribcr - Rib0);
783  } else {
784  // If Rib not changing, use zval0 as PBL height
785  pblh_interp = zval0;
786  }
787  pblh_corr_arr(i, j, 0) = amrex::max(amrex::min(pblh_interp, pblh_max), pblh_min);
788  pbli_arr(i, j, 0) = kpbl;
789  } else {
790  // No crossing up to khi: the scan ended there with zval = z(khi), the top of
791  // the scan, capped by pblh_max, and kpbl = khi, so the K profile and the
792  // countergradient gates below cover the column (WRF module_bl_mrf.F, brint = 1).
793  pblh_corr_arr(i, j, 0) = amrex::max(amrex::min(zval, pblh_max), pblh_min);
794  pbli_arr(i, j, 0) = kpbl;
795  }
796  pblh_floor_arr(i, j, 0) = pblh_min;
797  });
798 
799 
800  // Apply PBLH spatial smoothing if enabled (Seibert et al. 2000 methodology)
801  // Seibert et al. (2000): Review and intercomparison of operational methods
802  // for the determination of the mixing height. Atmospheric Environment, 34, 1001-1027.
803  // Spatial smoothing removes unphysical grid-to-grid noise from discrete Rib-crossing detection
804  if (turbChoice.enable_pblh_smoothing) {
805  // Smooth the tile's own columns, reading the halo the passes above
806  // filled. The result is the same however the domain is split.
807  // The stencil mixes neighboring columns, so it runs on the
808  // absolute height (the stored convention): the column's surface
809  // height zib goes on over the work box first and comes off
810  // after, and the result is kept at or above the column's floor.
811  // zib is zero without erf.pbl_ib_aware.
812  ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept {
813  pblh_corr_arr(i, j, 0) += zib_arr(i, j, 0);
814  });
815  ApplyPBLHSmoothing(pbl_height_corrector, xybx_tile,
816  turbChoice.pblh_smoothing_weight,
817  turbChoice.pblh_smoothing_passes,
818  geom.Domain(), geom.periodicity());
819  ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept {
820  pblh_corr_arr(i, j, 0) = amrex::max(pblh_corr_arr(i, j, 0) - zib_arr(i, j, 0), pblh_floor_arr(i, j, 0));
821  });
822  }
823 
824  // Copy corrected PBL height into pblh_mf for SurfaceLayer storage.
825  // pbl_height_corrector only covers this tile (grown by one), so loop over
826  // the tile, not the valid box: with tiling in x/y the valid box reaches
827  // past it. Under TileNoZ the tile spans the full column, and pblh_mf has
828  // no ghost cells, so the tiles together still fill every cell.
829  {
830  auto pblh_out = pblh_mf.array(mfi);
831  const Box& tbx = mfi.tilebox();
832  // The scheme measures its height from the top of an immersed column
833  // (zib); the stored field is the absolute height above the domain
834  // bottom, the convention of YSU and of every consumer of
835  // SurfaceLayer::get_pblh(). zib is zero without erf.pbl_ib_aware.
836  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
837  pblh_out(i, j, k) = pblh_corr_arr(i, j, 0) + zib_arr(i, j, 0);
838  });
839  }
840  //
841  // PASS 4 (WSTAR RECOMPUTE): Recompute wstar, HGAMT, HGAMQ using the corrected
842  // PBL height (pblh_corr_arr) to ensure internal consistency between the K-profile
843  // amplitude and the countergradient fluxes. HOL = sf*h/L uses pblh_corr_arr.
844  // WRF reference (module_bl_mrf.F lines 857-880):
845  // https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F#L857-L880
846  //
847  ParallelFor(xybx, [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
848  {
849  const int ksrf = ksurf_arr(i, j, 0); // local surface: first fluid cell of the column
850  const Real zib = zib_arr(i, j, 0); // its height, subtracted from every height below
851  amrex::ignore_unused(zib);
852  //const Real t_layer = t10_eff_arr(i, j, 0);
853  Real obuk_val = ol_eff_arr(i, j, 0);
854  if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
855  obuk_val = (obuk_val >= Real(0)) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
856  }
857 
858  // HOL now uses corrected PBLH for full internal consistency
859  const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
860  const Real HOL_bounded = amrex::max(amrex::min(HOL, Real(100.0)), Real(-100.0));
861  // |HOL|, so the base 1 + 16*HOL_abs of the unstable arm below equals its
862  // 1 - 16*HOL there and is at least 1 for every HOL; a guard written inside the
863  // arm gets folded away by the optimizer and the pow hoisted (see sqrt_neg_Ri).
864  const Real HOL_abs = std::abs(HOL_bounded);
865  const Real one_quarter = Real(0.25);
866  // Enable QNSE stable functions if requested, otherwise use default linear form
867  const Real enable_qnse_d = (turbChoice.enable_qnse_stable_functions) ? Real(1.0) : Real(0.0);
868  const Real qnse_am_d = turbChoice.qnse_am;
869  const Real qnse_bm_d = turbChoice.qnse_bm;
870  const Real phiM = (obuk_val > 0)
871  ? (enable_qnse_d > Real(0.5)
872  ? (1 + qnse_am_d * HOL_bounded) / (1 + qnse_bm_d * HOL_bounded)
873  : (1 + 5 * HOL_bounded))
874  : std::pow(1 + 16 * HOL_abs, -one_quarter);
875  const Real phiM_safe = amrex::max(phiM, Real(0.01));
876 
877  // Absolute bounds [0.01, 5.0] m/s
878  // Deardorff (1972) convective velocity scale — well-behaved as u_star -> 0.
879  // wstar_conv = (g/theta_v0 * zi * wthv0)^(1/3)
880  const Real theta_v0 = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), Real(1.0));
881  const Real wthv0 = amrex::max(-us_eff_arr(i,j,0) * ts_eff_arr(i,j,0), Real(0.0)); // surface buoyancy flux, unstable only
882  // Corrected height: this pass exists to make the K-profile amplitude and the
883  // countergradient fluxes consistent with the height Pass 3 produced, and HOL
884  // above already uses it. (Pass 2 has only the predictor height to work with.)
885  const Real zi = amrex::max(pblh_corr_arr(i, j, 0), Real(10.0));
886  const Real wstar_conv = std::cbrt(CONST_GRAV / theta_v0 * zi * wthv0);
887 
888  Real wstar_shear = us_eff_arr(i, j, 0) / phiM_safe;
889 
890  // Blend: standard convective/shear combination (WRF YSU-style),
891  // weighted by cube sum so either term can dominate smoothly
892  Real wstar = std::cbrt(wstar_shear*wstar_shear*wstar_shear +
893  wstar_conv*wstar_conv*wstar_conv);
894  //Real wstar = us_eff_arr(i, j, 0) / phiM_safe;
895  wstar = amrex::max(wstar, Real(0.01));
896  wstar = amrex::min(wstar, Real(5.0));
897 
898  // Fire boost (Deardorff 1970): where Pass 2 found a fire flux, use the
899  // convective scale of the surface plus fire buoyancy flux over the
900  // corrected PBLH if it is larger. Fire only increases w*; HGAMT/HGAMQ
901  // below keep the unboosted w*. An immersed column (erf.pbl_ib_aware) takes
902  // its own surface scales, as the rest of the pass. Every input is valid for every column,
903  // so nothing traps if the arm is evaluated speculatively.
904  const Real kbfs_fire = kbfs_fire_arr(i, j, 0);
905  const Real kbfs_total = amrex::max(-us_eff_arr(i, j, 0) * ts_eff_arr(i, j, 0) + kbfs_fire,
906  Real(0));
907  const Real wstar_fire = std::cbrt(CONST_GRAV / amrex::max(t10_eff_arr(i, j, 0), Real(1.0))
908  * kbfs_total * pblh_corr_arr(i, j, 0));
909  wstar_arr(i, j, 0) = (kbfs_fire > Real(0)) ? amrex::max(wstar_fire, wstar) : wstar;
910  bool SFCFLG = (obuk_val <= Real(0));
911  // WRF caps the heat countergradient at GAMCRT and then floors it at zero:
912  // HGAMT(I)=MIN(GAMFAC*HFX(I)/CPM(I),GAMCRT) (module_bl_mrf.F L874)
913  // HGAMT(I)=MAX(HGAMT(I),0.0) (module_bl_mrf.F L880)
914  // The floor is not redundant here. The unstable branch is selected on
915  // sign(L), but the numerator is the sensible flux -u_* theta_* alone: over
916  // water with a small downward sensible flux and a large latent flux, L is
917  // negative while -u_* theta_* is not. Without the floor the term would then
918  // add to the down-gradient flux rather than oppose it. VPERT in Pass 2 is
919  // deliberately built from the unfloored value, as in WRF (L877 precedes L880).
920  const Real HGAMT = (SFCFLG && enable_mrf_countergradient)
921  ? amrex::max(amrex::min(-const_b * us_eff_arr(i, j, 0)
922  * ts_eff_arr(i, j, 0) / wstar, GAMCRT), Real(0))
923  : Real(0);
924 
925  Real HGAMQ = Real(0);
926  if (SFCFLG && use_moisture && enable_mrf_countergradient) {
927  const Real q_star = qs_eff_arr(i, j, 0);
928  const Real HGAMQ_calc = -const_b * us_eff_arr(i, j, 0) * q_star / wstar;
929  HGAMQ = amrex::max(amrex::min(HGAMQ_calc, GAMCRQ), Real(0));
930 
931  if (lmask_arr) {
932  bool is_land = (lmask_arr(i,j,0) == 1);
933  if (!is_land) HGAMQ = Real(0);
934  }
935 
936  if (moisture_indices.qv >= 0) {
937  Real qv_klo = cell_data(i, j, ksrf, moisture_indices.qv) / cell_data(i, j, ksrf, Rho_comp);
938  Real T_klo = getTgivenRandRTh(cell_data(i, j, ksrf, Rho_comp),
939  cell_data(i, j, ksrf, RhoTheta_comp), qv_klo);
940  Real p_klo = getPgivenRTh(cell_data(i, j, ksrf, RhoTheta_comp), qv_klo) * Real(0.01);
941  Real qsat_klo = Real(0);
942  erf_qsatw(T_klo, p_klo, qsat_klo);
943  Real rh_klo = (qsat_klo > Real(1.0e-10)) ? (qv_klo / qsat_klo) : Real(0);
944  if (rh_klo > Real(0.95)) {
945  Real rh_scaling = amrex::max(Real(0), (Real(1) - rh_klo) / Real(0.05));
946  HGAMQ *= rh_scaling;
947  }
948  }
949  }
950 
951  if (pbli_arr(i, j, 0) <= ksrf + 1) {
952  hgamt_arr(i, j, 0) = Real(0);
953  hgamq_arr(i, j, 0) = Real(0);
954  } else {
955  const Real pblh = pblh_corr_arr(i, j, 0);
956  if (pblh > Real(1.0e-10)) {
957  hgamt_arr(i, j, 0) = (enable_mrf_countergradient) ? HGAMT / pblh : Real(0);
958  hgamq_arr(i, j, 0) = (enable_mrf_countergradient && use_moisture) ? HGAMQ / pblh : Real(0);
959  } else {
960  hgamt_arr(i, j, 0) = Real(0);
961  hgamq_arr(i, j, 0) = Real(0);
962  }
963  }
964  });
965  //
966  // PASS 5 (ZERO-RI): Diagnostic PBL height with Ribcr=0, VPERT-enhanced surface temp.
967  // Used optionally (pbl_mrf_use_zero_ri_extent) to extend the nonlocal mixing region.
968  // WRF reference (module_bl_mrf.F lines 932-964):
969  // https://github.com/wrf-model/WRF/blob/master/phys/module_bl_mrf.F#L932-L964
970  //
971  constexpr Real Ribcr_zero = Real(0);
972  ParallelFor(xybx, [=,one_d=one]
973  AMREX_GPU_DEVICE(int i, int j, int) noexcept
974  {
975  const int ksrf = ksurf_arr(i, j, 0); // local surface: first fluid cell of the column
976  const Real zib = zib_arr(i, j, 0); // its height, subtracted from every height below
977  amrex::ignore_unused(zib);
978  const Real t_layer = t10_eff_arr(i, j, 0);
979  const Real moisture_fraction = use_moisture ? q10_eff_arr(i, j, 0) : zero;
980  const Real t_layer_v = t_layer * (one + epsv * moisture_fraction);
981  const Real t_layer_v_enhanced = t_layer_v + vpert_arr(i, j, 0);
982 
983  int kpbl_zero = ksrf;
984  Real zval_zero, Rib_zero;
985  {
986  zval_zero = (use_terrain_fitted_coords)
987  ? Compute_Zrel_AtCellCenter(i, j, kpbl_zero, z_sfc_arr, z_nd_arr)
988  : ((kpbl_zero + myhalf) * gdata.CellSize(2) - zib);
989  const Real theta_v = GetThetav(i, j, kpbl_zero, cell_data, moisture_indices);
990  const Real theta_v_klo = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
991  const Real ws2_raw = fourth * ( (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) *
992  (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) +
993  (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) *
994  (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) );
995  // Vogelezang & Holtslag (1996): Add shear correction term to denominator instead of ad-hoc floor
996  const Real ws2 = (turbChoice.enable_vh96_shear_correction)
997  ? (ws2_raw + turbChoice.vh96_shear_const_b * us_eff_arr(i,j,0) * us_eff_arr(i,j,0))
998  : amrex::max(ws2_raw, one_d);
999  Rib_zero = CONST_GRAV * zval_zero * (theta_v - t_layer_v_enhanced) / (ws2 * theta_v_klo);
1000  }
1001 
1002  bool above_critical_zero = false;
1003  while (!above_critical_zero && ((kpbl_zero + 1) <= khi)) {
1004  kpbl_zero += 1;
1005  zval_zero = (use_terrain_fitted_coords)
1006  ? Compute_Zrel_AtCellCenter(i, j, kpbl_zero, z_sfc_arr, z_nd_arr)
1007  : ((kpbl_zero + myhalf) * gdata.CellSize(2) - zib);
1008  const Real theta_v = GetThetav(i, j, kpbl_zero, cell_data, moisture_indices);
1009  const Real theta_v_klo = amrex::max(GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
1010  const Real ws2_raw = fourth * ( (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) *
1011  (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) +
1012  (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) *
1013  (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) );
1014  // Vogelezang & Holtslag (1996): Add shear correction term to denominator instead of ad-hoc floor
1015  const Real ws2 = (turbChoice.enable_vh96_shear_correction)
1016  ? (ws2_raw + turbChoice.vh96_shear_const_b * us_eff_arr(i,j,0) * us_eff_arr(i,j,0))
1017  : amrex::max(ws2_raw, one_d);
1018  Rib_zero = CONST_GRAV * zval_zero * (theta_v - t_layer_v_enhanced) / (ws2 * theta_v_klo);
1019  above_critical_zero = (Rib_zero >= Ribcr_zero);
1020  }
1021 
1022  if (above_critical_zero) {
1023  pbli_zero_arr(i, j, 0) = kpbl_zero;
1024  } else {
1025  // No Ri = 0 crossing up to khi: the extent is the top of the scan, as for
1026  // pbli_arr above (WRF module_bl_mrf.F, brint = 1)
1027  pbli_zero_arr(i, j, 0) = kpbl_zero;
1028  }
1029  });
1030 
1031  // Fire diagnostics, after the final corrector and the w* boost
1032  if (use_fire_correction) {
1033  fire_pblh_max_pred = amrex::max(fire_pblh_max_pred, pbl_height_predictor.max<RunOn::Device>(0));
1034  fire_pblh_max_corr = amrex::max(fire_pblh_max_corr, pbl_height_corrector.max<RunOn::Device>(0));
1035  fire_wstar_max = amrex::max(fire_wstar_max, wstar_fab.max<RunOn::Device>(0));
1036  fire_kbfs_max = amrex::max(fire_kbfs_max, kbfs_fire_fab.max<RunOn::Device>(0));
1037  }
1038 
1039  // -- Compute diffusion coefficients --
1040 
1041  const Array4<Real>& K_turb = eddyViscosity.array(mfi);
1042 
1043  bool c_ext_dir_on_zlo = ((bc_ptr[BCVars::cons_bc].lo(2) == ERFBCType::ext_dir));
1044  bool c_ext_dir_on_zhi = ((bc_ptr[BCVars::cons_bc].hi(2) == ERFBCType::ext_dir));
1045  bool u_ext_dir_on_zlo = ((bc_ptr[BCVars::xvel_bc].lo(2) == ERFBCType::ext_dir));
1046  bool u_ext_dir_on_zhi = ((bc_ptr[BCVars::xvel_bc].hi(2) == ERFBCType::ext_dir));
1047  bool v_ext_dir_on_zlo = ((bc_ptr[BCVars::yvel_bc].lo(2) == ERFBCType::ext_dir));
1048  bool v_ext_dir_on_zhi = ((bc_ptr[BCVars::yvel_bc].hi(2) == ERFBCType::ext_dir));
1049 
1050  const auto& dxInv = geom.InvCellSizeArray();
1051  const Real dz_inv = geom.InvCellSize(2);
1052  const int izmin = geom.Domain().smallEnd(2);
1053  const int izmax = geom.Domain().bigEnd(2);
1054 
1055  // Blending parameters captured as scalars for GPU lambda.
1056  const amrex::Real l_blend_length = turbChoice.pbl_blend_length;
1057  const amrex::Real l_blend_cs = turbChoice.pbl_blend_cs;
1058  const amrex::Real l_blend_cmax = turbChoice.pbl_blend_c_max;
1059  // The scalars' Schmidt number relative to Pr_t (erf.pbl_mrf_Sc_t; 0: as heat)
1060  const amrex::Real scalar_Sc_t = turbChoice.pbl_mrf_Sc_t;
1061  const amrex::Real Pr_t_in = turbChoice.Pr_t;
1062  //const bool l_use_smag_ceil= turbChoice.pbl_blend_use_smag;
1063  // dx: use horizontal spacing at this level (assume dx = dy for regular grids); dy on a
1064  // domain with one cell in x, where dx is arbitrary
1065  // (computational spacing; the physical spacing divides it by sqrt(m_x m_y))
1066  const amrex::Real l_dx = LengthScaleCellSize(geom)[0];
1067  const bool l_use_mf = (mf_m[0] != nullptr && mf_m[1] != nullptr);
1068  const Array4<const Real> mf_mx = (l_use_mf) ? mf_m[0]->const_array(mfi) : Array4<const Real>{};
1069  const Array4<const Real> mf_my = (l_use_mf) ? mf_m[1]->const_array(mfi) : Array4<const Real>{};
1070 
1071  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1072  {
1073  const int ksrf = ksurf_arr(i, j, 0); // local surface: first fluid cell of the column
1074  const Real zib = zib_arr(i, j, 0); // its height, subtracted from every height below
1075  amrex::ignore_unused(zib);
1076  Real obuk_val = ol_eff_arr(i, j, 0);
1077  if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
1078  obuk_val = (obuk_val >= Real(0)) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
1079  }
1080 
1081  const Real zval = (use_terrain_fitted_coords)
1082  ? Compute_Zrel_AtCellCenter(i, j, k, z_sfc_arr, z_nd_arr)
1083  : ((k + myhalf) * gdata.CellSize(2) - zib);
1084  const Real rho = cell_data(i, j, k, Rho_comp);
1085  // Guard: skip lateral ghost cells that may have uninitialized density.
1086  // Prevents division-by-zero inside GetThetav at lateral ghost cells of gbx.
1087  // REGRID NOTE: On regrid, SurfaceLayer is reallocated and PBLH returns to sentinel.
1088  // The driver must call ComputeDiffusivityMRF (or an equivalent bootstrap pass)
1089  // before consuming PBLH in update_fluxes() or Beljaars correction after any regrid.
1090  if (rho <= Real(0) || k < ksrf) { // no diffusivity inside an immersed solid
1091  K_turb(i, j, k, EddyDiff::Mom_v) = Real(0);
1092  K_turb(i, j, k, EddyDiff::Theta_v) = Real(0);
1093  K_turb(i, j, k, EddyDiff::Q_v) = Real(0);
1094  K_turb(i, j, k, EddyDiff::Scalar_v) = Real(0);
1095  K_turb(i, j, k, EddyDiff::HGAMT_v) = Real(0);
1096  K_turb(i, j, k, EddyDiff::HGAMQ_v) = Real(0);
1097  K_turb(i, j, k, EddyDiff::Turb_lengthscale) = Real(0);
1098  return;
1099  }
1100  const Real met_h_zeta = (use_terrain_fitted_coords)
1101  ? Compute_h_zeta_AtCellCenter(i, j, k, dxInv, z_nd_arr) : Real(1);
1102  const Real dz_terrain = met_h_zeta / dz_inv;
1103 
1104  constexpr Real qc_threshold = Real(1.0e-4); // Cloud water/ice threshold (kg/kg)
1105  Real qc_mix = Real(0);
1106  Real qi_mix = Real(0);
1107  if (use_moisture) {
1108  if (moisture_indices.qc >= 0) {
1109  qc_mix = cell_data(i, j, k, moisture_indices.qc) / rho;
1110  }
1111  if (moisture_indices.qi >= 0) {
1112  qi_mix = cell_data(i, j, k, moisture_indices.qi) / rho;
1113  }
1114  }
1115  const Real total_qcloud = qc_mix + qi_mix;
1116  const bool has_cloud = turbChoice.enable_mrf_cloud_adjustment && (total_qcloud > qc_threshold);
1117 
1118  const int pbli_extent = turbChoice.pbl_mrf_use_zero_ri_extent ? pbli_zero_arr(i, j, 0) : pbli_arr(i, j, 0);
1119 
1120  if (k < pbli_extent) {
1121  const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
1122  const Real HOL_bounded = amrex::max(amrex::min(HOL, Real(100.0)), Real(-100.0));
1123  // |HOL|, so the base 1 + 16*HOL_abs of the unstable arm below equals its
1124  // 1 - 16*HOL there and is at least 1 for every HOL; a guard written inside the
1125  // arm gets folded away by the optimizer and the pow hoisted (see sqrt_neg_Ri).
1126  const Real HOL_abs = std::abs(HOL_bounded);
1127 
1128  const Real one_quarter = Real(0.25);
1129  // Enable QNSE stable functions if requested, otherwise use default linear form.
1130  const Real enable_qnse_d = (turbChoice.enable_qnse_stable_functions) ? Real(1.0) : Real(0.0);
1131  const Real qnse_am_d = turbChoice.qnse_am;
1132  const Real qnse_bm_d = turbChoice.qnse_bm;
1133  const Real qnse_ah_d = turbChoice.qnse_ah;
1134  const Real qnse_bh_d = turbChoice.qnse_bh;
1135  const Real phiM = (obuk_val > 0)
1136  ? (enable_qnse_d > Real(0.5)
1137  ? (1 + qnse_am_d * HOL_bounded) / (1 + qnse_bm_d * HOL_bounded)
1138  : (1 + 5 * HOL_bounded))
1139  : std::pow(1 + 16 * HOL_abs, -one_quarter);
1140  const Real phit = (obuk_val > 0)
1141  ? (enable_qnse_d > Real(0.5)
1142  ? (1 + qnse_ah_d * HOL_bounded) / (1 + qnse_bh_d * HOL_bounded)
1143  : (1 + 5 * HOL_bounded))
1144  : std::pow(1 + 16 * HOL_abs, -Real(0.5));
1145 
1146  Real phit_cloud = phit;
1147  Real phiM_cloud = phiM;
1148  if (has_cloud && obuk_val > Real(0)) {
1149  Real reduction_factor = Real(1) - Real(0.15) * amrex::min(total_qcloud / qc_threshold, Real(1));
1150  // Apply cloud reduction on top of QNSE if enabled
1151  if (enable_qnse_d > Real(0.5)) {
1152  phiM_cloud = ((1 + qnse_am_d * HOL_bounded * reduction_factor) / (1 + qnse_bm_d * HOL_bounded));
1153  phit_cloud = ((1 + qnse_ah_d * HOL_bounded * reduction_factor) / (1 + qnse_bh_d * HOL_bounded));
1154  } else {
1155  phiM_cloud = Real(1) + Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1156  phit_cloud = Real(1) + Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1157  }
1158  } else if (has_cloud && obuk_val <= Real(0)) {
1159  Real cloud_boost = Real(1.0) + Real(0.05) * amrex::min(total_qcloud / qc_threshold, Real(1));
1160  phiM_cloud = std::pow(Real(1) + Real(16.0) * HOL_abs / cloud_boost, -one_quarter);
1161  phit_cloud = std::pow(Real(1) + Real(16.0) * HOL_abs / cloud_boost, -Real(0.5));
1162  }
1163 
1164  const Real phiM_eff = phiM_cloud;
1165  const Real phit_eff = phit_cloud;
1166 
1167  Real Prt_base = phit_eff / phiM_eff;
1168  const Real Prt = amrex::min(amrex::max(Prt_base + const_b * KAPPA * sf, prmin), prmax);
1169 
1170  // wstar is WRF's WSCALE: u_*/phi_m in a stable or neutral column (the
1171  // convective part is floored at zero by the surface buoyancy flux), and
1172  // the cube-sum blend with w_* when the surface flux is upward.
1173  const Real wstar = wstar_arr(i, j, 0);
1174 
1175  // K-profile: K = rho * wstar * kappa * z * (1 - (z - zl1)/(h - zl1))^2
1176  //
1177  // The first-level offset ZL1 belongs to ZFAC alone: the linear factor
1178  // is the full height above the surface, ZQ(I,K). Subtracting zl1 from
1179  // both drives K_m to exactly zero in the first fluid cell.
1180  // The YSU K profile (ERF_ComputeDiffusivityYSU.cpp, Step 5) splits them the same way.
1181  //
1182  // zval already measures height from the top of an immersed column (zib
1183  // was subtracted where it was formed), so it is that height directly;
1184  // zl1 is zval evaluated at the column's first fluid cell, so zval - zl1
1185  // is exactly zero there in both the terrain and the non-terrain path.
1186  const Real zl1 = (use_terrain_fitted_coords)
1187  ? Compute_Zrel_AtCellCenter(i, j, ksrf, z_sfc_arr, z_nd_arr)
1188  : ((ksrf + myhalf) * gdata.CellSize(2) - zib);
1189  const Real pblh = pblh_corr_arr(i, j, 0);
1190  // The Rib passes floor pblh at the top face of the first fluid cell
1191  // (pblh_floor), half a cell above zl1, so pblh - zl1 is positive. The
1192  // lower bound below is kept as a guard, as in the YSU K profile; before
1193  // the floor moved from zl1 to that face it kept 0/0 out of the first
1194  // cell of a column on the floor.
1195  const Real pblh_rel = amrex::max(pblh - zl1, Real(1.0e-4));
1196  const Real zfac = amrex::max(Real(1) - (zval - zl1) / pblh_rel, Real(1.0e-8));
1197 
1198  K_turb(i, j, k, EddyDiff::Mom_v) = rho * wstar * KAPPA * zval * zfac * zfac;
1199  K_turb(i, j, k, EddyDiff::Theta_v) = K_turb(i, j, k, EddyDiff::Mom_v) / Prt;
1200  K_turb(i, j, k, EddyDiff::Q_v) = K_turb(i, j, k, EddyDiff::Theta_v);
1201  // The passive scalars (rhoadv_0, dust, smoke) mix as heat does
1202  K_turb(i, j, k, EddyDiff::Scalar_v) = K_turb(i, j, k, EddyDiff::Theta_v);
1203  } else if (k >= pbli_extent) {
1204  // Free atmosphere above the PBL top. This is the only branch left that
1205  // reads resolved vertical gradients, but they are not evaluated anywhere
1206  // near the surface.
1207  const Real lambda = Real(150.0);
1208  const Real lscale = (KAPPA * zval * lambda) / (KAPPA * zval + lambda);
1209  Real dthetadz, dudz, dvdz;
1210  ComputeVerticalDerivativesPBL(i, j, k, uvel, vvel, cell_data, izmin, izmax, pbl_derivative_dz_inv(i,j,k),
1211  c_ext_dir_on_zlo, c_ext_dir_on_zhi, u_ext_dir_on_zlo,
1212  u_ext_dir_on_zhi, v_ext_dir_on_zlo, v_ext_dir_on_zhi, dthetadz,
1213  dudz, dvdz, moisture_indices, pbl_strat);
1214 
1215  const Real dudz_safe = (k < izmax) ? dudz : Real(0);
1216  const Real dvdz_safe = (k < izmax) ? dvdz : Real(0);
1217  const Real wind_shear = dudz_safe * dudz_safe + dvdz_safe * dvdz_safe;
1218  const Real wind_shear_safe = std::max(wind_shear, Real(1.0e-8));
1219  const Real theta_v = amrex::max(GetThetav(i, j, k, cell_data, moisture_indices), Real(1.0));
1220  const Real dtheta_v_dz = dthetadz;
1221 
1222  Real grad_Ri = CONST_GRAV / theta_v * dtheta_v_dz / wind_shear_safe;
1223  grad_Ri = std::max(std::min(grad_Ri, Real(100.0)), -Real(100.0));
1224 
1225  const Real grad_Ri_safe = amrex::max(grad_Ri, -Real(100.0));
1226  // sqrt(|Ri|), which equals the sqrt(-Ri) of the unstable arm below and is valid
1227  // for every Ri. Written as max(-Ri, 0) inside the arm, the optimizer used the
1228  // arm's condition to drop the max and then hoisted the bare sqrt above the
1229  // selection, where Ri can be positive; written as min(Ri, 0) it folded the
1230  // sqrt into the arms of the min. Either way an invalid operation whose
1231  // result is discarded but whose flag kills the run under
1232  // amrex.fpe_trap_invalid. There is nothing to fold in the absolute value.
1233  const Real sqrt_neg_Ri = std::sqrt(std::abs(grad_Ri_safe));
1234  Real Pr = Real(1) + Real(2.1) * grad_Ri;
1235  const Real fm = (grad_Ri_safe > 0)
1236  ? Real(1) / ((Real(1) + Real(5.0) * grad_Ri_safe) * (Real(1) + Real(5.0) * grad_Ri_safe))
1237  : 1 - 8 * grad_Ri_safe / (1 + Real(1.746) * sqrt_neg_Ri);
1238  const Real ft = (grad_Ri_safe > 0)
1239  ? Real(1) / ((Real(1) + Real(5.0) * grad_Ri_safe) * (Real(1) + Real(5.0) * grad_Ri_safe))
1240  : 1 - 8 * grad_Ri_safe / (1 + Real(1.286) * sqrt_neg_Ri);
1241  const Real rl2wsp = rho * lscale * lscale * std::sqrt(wind_shear);
1242 
1243  Pr = std::max(amrex::Real(0.25), std::min(Pr, Real(4.0)));
1244 
1245  // In the stable regime, fm and ft are the same function, so the Prandtl
1246  // number has to be applied explicitly or momentum and heat mix
1247  // identically.
1248  //
1249  // In the unstable regime, fm and ft already differ (1.746 vs 1.286) and
1250  // WRF applies no Prandtl factor there.
1251  const Real Pr_mom = (grad_Ri_safe > 0) ? Pr : Real(1);
1252 
1253  K_turb(i, j, k, EddyDiff::Mom_v) = rl2wsp * fm * Pr_mom;
1254  K_turb(i, j, k, EddyDiff::Theta_v) = rl2wsp * ft;
1255  K_turb(i, j, k, EddyDiff::Q_v) = K_turb(i, j, k, EddyDiff::Theta_v);
1256  K_turb(i, j, k, EddyDiff::Scalar_v) = K_turb(i, j, k, EddyDiff::Theta_v);
1257  }
1258 
1259  // Scale-aware blending for gray-zone resolution (Boutle et al. 2014).
1260  // ERF_PBLScaleAwareBlending.H. Gated by pbl_blend_length > 0.
1261  // Applied to Theta_v and Q_v. Mom_v is not modified.
1262  //
1263  // K_turb holds rho*K [kg/m/s], but the ceiling applied inside
1264  // pbl_kh_blend_and_cap is a bare diffusivity [m^2/s]. Hand the helper the
1265  // kinematic value and restore the density weighting on the way out; passing
1266  // rho*K straight through would make the effective cap scale like 1/rho and
1267  // hence increase with height (issue #3580).
1268  if (l_blend_length > 0.0) {
1269  const Real rho_inv = Real(1.0) / rho;
1270  const Real l_dx_phys = (l_use_mf) ? l_dx / std::sqrt(mf_mx(i,j,0) * mf_my(i,j,0)) : l_dx;
1271 
1272  // For MRF, use power-law ceiling (SmnSmn not available)
1273  K_turb(i, j, k, EddyDiff::Theta_v) = rho * pbl_kh_blend_and_cap(
1274  K_turb(i, j, k, EddyDiff::Theta_v) * rho_inv,
1275  l_dx_phys, l_blend_length, l_blend_cs, l_blend_cmax,
1276  amrex::Real(-1.0), false);
1277 
1278  K_turb(i, j, k, EddyDiff::Q_v) = rho * pbl_kh_blend_and_cap(
1279  K_turb(i, j, k, EddyDiff::Q_v) * rho_inv,
1280  l_dx_phys, l_blend_length, l_blend_cs, l_blend_cmax,
1281  amrex::Real(-1.0), false);
1282 
1283  K_turb(i, j, k, EddyDiff::Scalar_v) = rho * pbl_kh_blend_and_cap(
1284  K_turb(i, j, k, EddyDiff::Scalar_v) * rho_inv,
1285  l_dx_phys, l_blend_length, l_blend_cs, l_blend_cmax,
1286  amrex::Real(-1.0), false);
1287  }
1288 
1289  // Limit diffusion coefficients to physical bounds
1290  // Hong & Pan (1996): Kmin=0.1, Kmax=300 m^2/s (module_bl_mrf.F lines 1014-1025)
1291  // Hong et al. (2006): Kmin=ckz*dz*rho, Kmax=1000 m^2/s (high-res option)
1292  Real rhoKmin, rhoKmax;
1293  if (turbChoice.pbl_mrf_highres_bounds) {
1294  constexpr Real ckz = Real(0.001);
1295  constexpr Real Kmax = Real(1000.0);
1296  rhoKmin = ckz * dz_terrain * rho;
1297  rhoKmax = rho * Kmax;
1298  } else {
1299  constexpr Real Kmin = Real(0.1);
1300  constexpr Real Kmax = Real(300.0);
1301  rhoKmin = rho * Kmin;
1302  rhoKmax = rho * Kmax;
1303  }
1304 
1305  K_turb(i, j, k, EddyDiff::Mom_v) = std::max(
1306  std::min(K_turb(i, j, k, EddyDiff::Mom_v), rhoKmax), rhoKmin);
1307  K_turb(i, j, k, EddyDiff::Theta_v) = std::max(
1308  std::min(K_turb(i, j, k, EddyDiff::Theta_v), rhoKmax), rhoKmin);
1309  K_turb(i, j, k, EddyDiff::Q_v) = std::max(
1310  std::min(K_turb(i, j, k, EddyDiff::Q_v), rhoKmax), rhoKmin);
1311  K_turb(i, j, k, EddyDiff::Scalar_v) = std::max(
1312  std::min(K_turb(i, j, k, EddyDiff::Scalar_v), rhoKmax), rhoKmin);
1313  // erf.pbl_mrf_Sc_t: the scalars' turbulent Schmidt number, relative to the
1314  // Prandtl number erf.Pr_t; unset (0), they mix as heat does
1315  if (scalar_Sc_t > Real(0)) {
1316  K_turb(i, j, k, EddyDiff::Scalar_v) *= Pr_t_in / scalar_Sc_t;
1317  }
1318  K_turb(i, j, k, EddyDiff::Turb_lengthscale) = pblh_corr_arr(i, j, 0) + zib; // absolute height, as stored
1319 
1320  // IMPORTANT — units convention for HGAMT_v / HGAMQ_v:
1321  // These are stored as (countergradient term / pblh), i.e. already
1322  // divided by the PBL height, NOT as a raw physical gradient needing
1323  // an extra 1/dz scaling downstream.
1324  //
1325  // The implicit solver (ERF_ImplicitDiff_T.cpp, ImplicitDiffForStateLU_T)
1326  // multiplies this stored value by `Fact = implicit_fac * dt * dz_inv`
1327  // and `rhoAlpha / met_h_zeta` ONLY — it must NOT apply an additional
1328  // dz_inv factor. `Fact` already carries the single grid-spacing
1329  // factor needed to convert the countergradient correction into a
1330  // flux-divergence contribution consistent with the K*d(phi)/dz terms
1331  // it is being added alongside. Adding a second dz_inv
1332  // double-counts the grid spacing and is
1333  // dimensionally incorrect — do NOT "fix" this by inserting dz_inv
1334  // into the RHS_a += Fact * gam_hi/lo terms in ERF_ImplicitDiff_T.cpp.
1335  if (k < pbli_extent) {
1336  K_turb(i, j, k, EddyDiff::HGAMT_v) = hgamt_arr(i, j, 0);
1337  K_turb(i, j, k, EddyDiff::HGAMQ_v) = hgamq_arr(i, j, 0);
1338  } else {
1339  K_turb(i, j, k, EddyDiff::HGAMT_v) = Real(0);
1340  K_turb(i, j, k, EddyDiff::HGAMQ_v) = Real(0);
1341  }
1342  });
1343 
1344  // FOEXTRAP top and bottom ghost cells
1345  ParallelFor(xybx, [=] AMREX_GPU_DEVICE(int i, int j, int ) noexcept
1346  {
1347  K_turb(i, j, klo-1, EddyDiff::Mom_v ) = K_turb(i, j, klo, EddyDiff::Mom_v );
1348  K_turb(i, j, klo-1, EddyDiff::Theta_v) = K_turb(i, j, klo, EddyDiff::Theta_v);
1349  K_turb(i, j, klo-1, EddyDiff::Q_v ) = K_turb(i, j, klo, EddyDiff::Q_v );
1350  K_turb(i, j, klo-1, EddyDiff::Scalar_v) = K_turb(i, j, klo, EddyDiff::Scalar_v);
1351  K_turb(i, j, klo-1, EddyDiff::HGAMT_v) = K_turb(i, j, klo, EddyDiff::HGAMT_v);
1352  K_turb(i, j, klo-1, EddyDiff::HGAMQ_v) = K_turb(i, j, klo, EddyDiff::HGAMQ_v);
1353  K_turb(i, j, klo-1, EddyDiff::Turb_lengthscale) = K_turb(i, j, klo, EddyDiff::Turb_lengthscale);
1354  K_turb(i, j, khi+1, EddyDiff::Mom_v ) = K_turb(i, j, khi, EddyDiff::Mom_v );
1355  K_turb(i, j, khi+1, EddyDiff::Theta_v) = K_turb(i, j, khi, EddyDiff::Theta_v);
1356  K_turb(i, j, khi+1, EddyDiff::Q_v ) = K_turb(i, j, khi, EddyDiff::Q_v );
1357  K_turb(i, j, khi+1, EddyDiff::Scalar_v) = K_turb(i, j, khi, EddyDiff::Scalar_v);
1358  K_turb(i, j, khi+1, EddyDiff::HGAMT_v) = K_turb(i, j, khi, EddyDiff::HGAMT_v);
1359  K_turb(i, j, khi+1, EddyDiff::HGAMQ_v) = K_turb(i, j, khi, EddyDiff::HGAMQ_v);
1360  K_turb(i, j, khi+1, EddyDiff::Turb_lengthscale) = K_turb(i, j, khi, EddyDiff::Turb_lengthscale);
1361  });
1362  }// mfi
1363 
1364  if (use_fire_correction) {
1365  ParallelDescriptor::ReduceRealMax({fire_pblh_max_pred, fire_pblh_max_corr,
1366  fire_wstar_max, fire_kbfs_max});
1367  amrex::Print() << "[MRF FIRE] level " << level << " fire w* boost"
1368  << " pblh_predictor_max=" << fire_pblh_max_pred << " m"
1369  << " pblh_corrector_max=" << fire_pblh_max_corr << " m"
1370  << " wstar_max=" << fire_wstar_max << " m/s"
1371  << " kbfs_fire_max=" << fire_kbfs_max << " K m/s\n";
1372  }
1373 
1374  // Write MRF-computed PBLH back into SurfaceLayer so Beljaars correction
1375  // and diagnostics can use it, and update_pblh no longer aborts for MRF type.
1376  SurfLayer->set_pblh(level, pblh_mf);
1377 }
constexpr amrex::Real epsv
Definition: ERF_Constants.H:56
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
constexpr amrex::Real immersed_neutral_obukhov_length
Definition: ERF_Constants.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:127
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:265
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetav(const int &i, const int &j, const int &k, const amrex::Array4< amrex::Real const > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_MoistUtils.H:93
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
std::unique_ptr< amrex::MultiFab > WidenForPBLH(const amrex::MultiFab &src, const int ng, const std::function< void(amrex::MultiFab &)> &fill)
Definition: ERF_PBLModels.H:789
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void ComputeVerticalDerivativesPBL(int i, int j, int k, const amrex::Array4< const amrex::Real > &uvel, const amrex::Array4< const amrex::Real > &vvel, const amrex::Array4< const amrex::Real > &cell_data, const int izmin, const int izmax, const PBLDerivativeDzInv &dz_inv, const bool c_ext_dir_on_zlo, const bool c_ext_dir_on_zhi, const bool u_ext_dir_on_zlo, const bool u_ext_dir_on_zhi, const bool v_ext_dir_on_zlo, const bool v_ext_dir_on_zhi, amrex::Real &dthetadz, amrex::Real &dudz, amrex::Real &dvdz, const MoistureComponentIndices &moisture_indices, const StratType strat=StratType::thetav)
Definition: ERF_PBLModels.H:291
void ApplyPBLHSmoothing(amrex::FArrayBox &pblh_fab, const amrex::Box &xybx_valid, const amrex::Real weight, const int passes, const amrex::Box &domain, const amrex::Periodicity &periodicity)
Apply spatial smoothing to PBLH field using 5-point stencil.
Definition: ERF_PBLModels.H:706
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pblh_floor(amrex::Real zl1, amrex::Real dz1) noexcept
Definition: ERF_PBLRibCrossing.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pbl_kh_blend_and_cap(amrex::Real K_h, amrex::Real dx, amrex::Real L_blend, amrex::Real C_s, amrex::Real c_max, amrex::Real SmnSmn, bool use_smag) noexcept
Apply scale-aware blending and ceiling to a single K_h value.
Definition: ERF_PBLScaleAwareBlending.H:132
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Zrel_AtCellCenter(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_sfc_nd, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:764
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtCellCenter(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:202
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ yvel_bc
Definition: ERF_IndexDefines.H:139
@ cons_bc
Definition: ERF_IndexDefines.H:122
@ xvel_bc
Definition: ERF_IndexDefines.H:138
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ Theta_v
Definition: ERF_IndexDefines.H:267
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:271
@ Scalar_v
Definition: ERF_IndexDefines.H:269
@ Q_v
Definition: ERF_IndexDefines.H:270
@ Mom_v
Definition: ERF_IndexDefines.H:266
@ HGAMQ_v
Definition: ERF_IndexDefines.H:278
@ HGAMT_v
Definition: ERF_IndexDefines.H:277
@ ks
Definition: ERF_SLM.H:76
@ rho
Definition: ERF_Kessler.H:25
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233
@ zi
Definition: ERF_AdvanceWDM6.cpp:277
int qi
cloud ice
Definition: ERF_DataStruct.H:292
int qv
water vapor
Definition: ERF_DataStruct.H:290
int qc
cloud liquid water
Definition: ERF_DataStruct.H:291
Functor for inverse vertical spacings for terrain-following grids using cell-center heights.
Definition: ERF_PBLModels.H:652
amrex::Real pbl_mrf_Sc_t
MRF turbulent Schmidt number of the passive scalars (erf.pbl_mrf_Sc_t): their vertical diffusivity is...
Definition: ERF_TurbStruct.H:1128
bool enable_mrf_unbounded_vpert
Whether MRF leaves VPERT unlimited by GAMCRT.
Definition: ERF_TurbStruct.H:1129
amrex::Real pbl_blend_length
Boutle blending length L [m]. 0 = off.
Definition: ERF_TurbStruct.H:1119
bool pbl_mrf_use_zero_ri_extent
Whether MRF uses the Ri=0 K-profile extent.
Definition: ERF_TurbStruct.H:1130
amrex::Real qnse_ah
Definition: ERF_TurbStruct.H:1142
amrex::Real mrf_fire_q_threshold
Definition: ERF_TurbStruct.H:1132
StratType pbl_strat_type
Definition: ERF_TurbStruct.H:951
bool enable_vh96_shear_correction
Whether Vogelezang & Holtslag (1996) shear-correction term is enabled.
Definition: ERF_TurbStruct.H:1106
bool enable_mrf_cloud_adjustment
Whether MRF cloud-aware stability adjustments are enabled.
Definition: ERF_TurbStruct.H:1126
amrex::Real pbl_mrf_const_b
MRF constant used to compute PBL height.
Definition: ERF_TurbStruct.H:1114
amrex::Real pblh_smoothing_weight
Center-cell weight in PBLH smoothing stencil (must be in [0,1]).
Definition: ERF_TurbStruct.H:1110
amrex::Real pbl_blend_cs
Smagorinsky coeff for K_h ceiling.
Definition: ERF_TurbStruct.H:1120
amrex::Real qnse_bm
Definition: ERF_TurbStruct.H:1141
amrex::Real pbl_blend_c_max
Power-law ceiling coeff [m^(2/3)/s].
Definition: ERF_TurbStruct.H:1121
amrex::Real qnse_bh
Definition: ERF_TurbStruct.H:1143
bool enable_qnse_stable_functions
Definition: ERF_TurbStruct.H:1138
bool enable_mrf_countergradient
Whether MRF countergradient corrections are enabled.
Definition: ERF_TurbStruct.H:1123
bool enable_pblh_smoothing
Whether spatial smoothing of diagnosed PBLH is enabled.
Definition: ERF_TurbStruct.H:1108
int pblh_smoothing_passes
Number of PBLH smoothing iterations to apply.
Definition: ERF_TurbStruct.H:1109
amrex::Real pbl_ib_z0
Definition: ERF_TurbStruct.H:1125
bool pbl_ib_aware
Definition: ERF_TurbStruct.H:1124
bool pbl_mrf_highres_bounds
Whether MRF applies high-resolution grid-dependent diffusivity bounds.
Definition: ERF_TurbStruct.H:1127
bool mrf_fire_thermal_excess
Definition: ERF_TurbStruct.H:1131
amrex::Real vh96_shear_const_b
Vogelezang & Holtslag (1996) shear-correction constant b.
Definition: ERF_TurbStruct.H:1107
amrex::Real pbl_mrf_Ribcr
Critical bulk Richardson number for the MRF PBL scheme.
Definition: ERF_TurbStruct.H:1113
amrex::Real qnse_am
Definition: ERF_TurbStruct.H:1140
amrex::Real pbl_mrf_sf
MRF surface flux value used to compute PBL height.
Definition: ERF_TurbStruct.H:1115
amrex::Real Pr_t
Turbulent Prandtl number.
Definition: ERF_TurbStruct.H:912

Referenced by ComputeTurbulentViscosity().

Here is the call graph for this function:
Here is the caller graph for this function: