ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ShocMoments Class Reference

#include <ERF_ShocMoments.H>

Static Public Member Functions

static void calc_var_or_covar (const ShocColumnData &col, amrex::Real tunefac, const amrex::FArrayBox &isotropy_zi, const amrex::FArrayBox &tkh_zi, const amrex::FArrayBox &invar1, const amrex::FArrayBox &invar2, amrex::FArrayBox &outvar)
 
static void calc_vertflux (const ShocColumnData &col, const amrex::FArrayBox &tkh_zi, const amrex::FArrayBox &invar, amrex::FArrayBox &vertflux)
 
static void diagnose_second_moments (ShocColumnData &col, const ShocRuntimeOptions &opts)
 
static void clip_third_moments (const ShocColumnData &col, const amrex::FArrayBox &w_sec_zi, amrex::FArrayBox &w3)
 
static void diagnose_third_moments (ShocColumnData &col, const ShocRuntimeOptions &opts)
 
static void diagnose_moments (ShocColumnData &col, const ShocRuntimeOptions &opts)
 

Member Function Documentation

◆ calc_var_or_covar()

void ShocMoments::calc_var_or_covar ( const ShocColumnData col,
amrex::Real  tunefac,
const amrex::FArrayBox &  isotropy_zi,
const amrex::FArrayBox &  tkh_zi,
const amrex::FArrayBox &  invar1,
const amrex::FArrayBox &  invar2,
amrex::FArrayBox &  outvar 
)
static
255 {
256  auto out = outvar.array();
257  const auto iso = isotropy_zi.const_array();
258  const auto tkh = tkh_zi.const_array();
259  const auto v1 = invar1.const_array();
260  const auto v2 = invar2.const_array();
261  const auto zt = col.zt.const_array();
262  const auto zi = col.zi.const_array();
263  const auto layout = col.layout;
264  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
265  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
266  {
267  for (int k = 1; k < layout.nlev; ++k) {
268  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
269  const Real grid_dz2 = 1.0_rt / (dz_zi * dz_zi);
270  out(ic,k,0) = tunefac * (iso(ic,k,0) * tkh(ic,k,0)) * grid_dz2 *
271  (v1(ic,k-1,0) - v1(ic,k,0)) * (v2(ic,k-1,0) - v2(ic,k,0));
272  }
273  });
274 }
struct @29 out
ParallelFor(grown_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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ zi
Definition: ERF_AdvanceWSM6.cpp:133
ShocColumnLayout layout
Definition: ERF_ShocTypes.H:205
amrex::FArrayBox zi
Definition: ERF_ShocTypes.H:209
amrex::FArrayBox zt
Definition: ERF_ShocTypes.H:208
Here is the call graph for this function:

◆ calc_vertflux()

void ShocMoments::calc_vertflux ( const ShocColumnData col,
const amrex::FArrayBox &  tkh_zi,
const amrex::FArrayBox &  invar,
amrex::FArrayBox &  vertflux 
)
static
281 {
282  auto out = vertflux.array();
283  const auto tkh = tkh_zi.const_array();
284  const auto v = invar.const_array();
285  const auto zt = col.zt.const_array();
286  const auto zi = col.zi.const_array();
287  const auto layout = col.layout;
288  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
289  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
290  {
291  for (int k = 1; k < layout.nlev; ++k) {
292  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
293  // E3SM uses top-down vertical indexing. ERF columns are bottom-up,
294  // so the interface gradient must use upper-minus-lower to preserve
295  // the same physical downgradient flux sign.
296  out(ic,k,0) = -(tkh(ic,k,0) / dz_zi) * (v(ic,k,0) - v(ic,k-1,0));
297  }
298  });
299 }
Here is the call graph for this function:

◆ clip_third_moments()

void ShocMoments::clip_third_moments ( const ShocColumnData col,
const amrex::FArrayBox &  w_sec_zi,
amrex::FArrayBox &  w3 
)
static
359 {
360  auto w3 = w3_fab.array();
361  const auto wsec = w_sec_zi.const_array();
362 
363  const auto layout = col.layout;
364  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
365  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
366  {
367  for (int k = 0; k <= layout.nlev; ++k) {
368  const Real wsec3 = wsec(ic,k,0) * wsec(ic,k,0) * wsec(ic,k,0);
369  const Real clip_cond = shoc_w3clip() * std::sqrt(amrex::max(0.0_rt, 2.0_rt * wsec3));
370  if (amrex::Math::abs(w3(ic,k,0)) > clip_cond) {
371  w3(ic,k,0) = shoc_w3clipdef();
372  }
373  }
374  });
375 }
Here is the call graph for this function:

◆ diagnose_moments()

void ShocMoments::diagnose_moments ( ShocColumnData col,
const ShocRuntimeOptions opts 
)
static
485 {
486  diagnose_second_moments(col, opts);
487  diagnose_third_moments(col, opts);
488 }
static void diagnose_second_moments(ShocColumnData &col, const ShocRuntimeOptions &opts)
Definition: ERF_ShocMoments.cpp:302
static void diagnose_third_moments(ShocColumnData &col, const ShocRuntimeOptions &opts)
Definition: ERF_ShocMoments.cpp:378

Referenced by ShocDiagnostics::diagnose_post_implicit().

Here is the caller graph for this function:

◆ diagnose_second_moments()

void ShocMoments::diagnose_second_moments ( ShocColumnData col,
const ShocRuntimeOptions opts 
)
static
304 {
305  FArrayBox isotropy_zi, tkh_zi, tk_zi;
306  const Box iface_box(IntVect(0,0,0), IntVect(col.layout.ncell - 1, col.layout.nlev, 0));
307  isotropy_zi.resize(iface_box, 1, The_Async_Arena());
308  tkh_zi.resize(iface_box, 1, The_Async_Arena());
309  tk_zi.resize(iface_box, 1, The_Async_Arena());
310 
311  interpolate_cc_to_iface(col, col.isotropy, isotropy_zi, 0.0);
312  interpolate_cc_to_iface(col, col.tkh, tkh_zi, 0.0);
313  interpolate_cc_to_iface(col, col.tk, tk_zi, 0.0);
314 
315  auto thl_sec = col.thl_sec.array();
316  auto qw_sec = col.qw_sec.array();
317  auto qwthl_sec = col.qwthl_sec.array();
318  auto w_sec = col.w_sec.array();
319 
320  const auto tke = col.tke.const_array();
321  const auto layout = col.layout;
322  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
323  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
324  {
325  for (int k = 0; k < layout.nlev; ++k) {
326  w_sec(ic,k,0) = opts.shoc_1p5tke ? 0.0_rt : opts.w2tune * (2.0_rt / 3.0_rt) * tke(ic,k,0);
327  }
328  });
329 
330  if (opts.shoc_1p5tke) {
331  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
332  {
333  for (int k = 0; k <= layout.nlev; ++k) {
334  thl_sec(ic,k,0) = 0.0_rt;
335  qw_sec(ic,k,0) = 0.0_rt;
336  qwthl_sec(ic,k,0) = 0.0_rt;
337  }
338  });
339  } else {
340  calc_var_or_covar(col, opts.thl2tune, isotropy_zi, tkh_zi, col.thetal, col.thetal, col.thl_sec);
341  calc_var_or_covar(col, opts.qw2tune, isotropy_zi, tkh_zi, col.qw, col.qw, col.qw_sec);
342  calc_var_or_covar(col, opts.qwthl2tune, isotropy_zi, tkh_zi, col.thetal, col.qw, col.qwthl_sec);
343  }
344 
345  calc_vertflux(col, tkh_zi, col.thetal, col.wthl_sec);
346  calc_vertflux(col, tkh_zi, col.qw, col.wqw_sec);
347  calc_vertflux(col, tkh_zi, col.tke, col.wtke_sec);
348  calc_vertflux(col, tk_zi, col.u, col.uw_sec);
349  calc_vertflux(col, tk_zi, col.v, col.vw_sec);
350 
351  apply_second_moment_boundary_conditions(col);
352  apply_top_taper_to_second_moments(col, opts);
353 }
static void calc_var_or_covar(const ShocColumnData &col, amrex::Real tunefac, const amrex::FArrayBox &isotropy_zi, const amrex::FArrayBox &tkh_zi, const amrex::FArrayBox &invar1, const amrex::FArrayBox &invar2, amrex::FArrayBox &outvar)
Definition: ERF_ShocMoments.cpp:248
static void calc_vertflux(const ShocColumnData &col, const amrex::FArrayBox &tkh_zi, const amrex::FArrayBox &invar, amrex::FArrayBox &vertflux)
Definition: ERF_ShocMoments.cpp:277
amrex::FArrayBox w_sec
Definition: ERF_ShocTypes.H:258
amrex::FArrayBox tk
Definition: ERF_ShocTypes.H:236
amrex::FArrayBox vw_sec
Definition: ERF_ShocTypes.H:255
amrex::FArrayBox wqw_sec
Definition: ERF_ShocTypes.H:253
amrex::FArrayBox uw_sec
Definition: ERF_ShocTypes.H:254
amrex::FArrayBox isotropy
Definition: ERF_ShocTypes.H:235
amrex::FArrayBox tke
Definition: ERF_ShocTypes.H:223
amrex::FArrayBox qw_sec
Definition: ERF_ShocTypes.H:250
amrex::FArrayBox tkh
Definition: ERF_ShocTypes.H:237
amrex::FArrayBox qw
Definition: ERF_ShocTypes.H:221
amrex::FArrayBox v
Definition: ERF_ShocTypes.H:225
amrex::FArrayBox wtke_sec
Definition: ERF_ShocTypes.H:256
amrex::FArrayBox u
Definition: ERF_ShocTypes.H:224
amrex::FArrayBox wthl_sec
Definition: ERF_ShocTypes.H:252
amrex::FArrayBox thl_sec
Definition: ERF_ShocTypes.H:249
amrex::FArrayBox qwthl_sec
Definition: ERF_ShocTypes.H:251
amrex::FArrayBox thetal
Definition: ERF_ShocTypes.H:217
int nlev
Definition: ERF_ShocTypes.H:196
int ncell
Definition: ERF_ShocTypes.H:195
bool shoc_1p5tke
Definition: ERF_ShocTypes.H:99
amrex::Real w2tune
Definition: ERF_ShocTypes.H:90
amrex::Real qwthl2tune
Definition: ERF_ShocTypes.H:89
amrex::Real thl2tune
Definition: ERF_ShocTypes.H:87
amrex::Real qw2tune
Definition: ERF_ShocTypes.H:88
Here is the call graph for this function:

◆ diagnose_third_moments()

void ShocMoments::diagnose_third_moments ( ShocColumnData col,
const ShocRuntimeOptions opts 
)
static
380 {
381  FArrayBox isotropy_zi, brunt_zi, w_sec_zi, thetal_zi;
382  const Box iface_box(IntVect(0,0,0), IntVect(col.layout.ncell - 1, col.layout.nlev, 0));
383  isotropy_zi.resize(iface_box, 1, The_Async_Arena());
384  brunt_zi.resize(iface_box, 1, The_Async_Arena());
385  w_sec_zi.resize(iface_box, 1, The_Async_Arena());
386  thetal_zi.resize(iface_box, 1, The_Async_Arena());
387 
388  interpolate_cc_to_iface(col, col.isotropy, isotropy_zi, 0.0);
389  interpolate_cc_to_iface(col, col.brunt, brunt_zi, shoc_large_neg());
390  interpolate_cc_to_iface(col, col.w_sec, w_sec_zi, (2.0_rt / 3.0_rt) * shoc_min_tke());
391  interpolate_cc_to_iface(col, col.thetal, thetal_zi, 0.0);
392 
393  auto w3 = col.w3.array();
394  const auto w_sec = col.w_sec.const_array();
395  const auto thl_sec = col.thl_sec.const_array();
396  const auto wthl_sec = col.wthl_sec.const_array();
397  const auto tke = col.tke.const_array();
398  const auto dz = col.dz.const_array();
399  const auto isotropy_i = isotropy_zi.const_array();
400  const auto brunt_i = brunt_zi.const_array();
401  const auto w_sec_i = w_sec_zi.const_array();
402  const auto thetal_i = thetal_zi.const_array();
403  const auto zt = col.zt.const_array();
404  const auto zi = col.zi.const_array();
405  const auto layout = col.layout;
406  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
407  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
408  {
409  w3(ic,0,0) = 0.0_rt;
410  w3(ic,layout.nlev,0) = 0.0_rt;
411 
412  for (int k = 1; k < layout.nlev; ++k) {
413  if (opts.shoc_1p5tke) {
414  w3(ic,k,0) = 0.0_rt;
415  continue;
416  }
417 
418  const Real dz_zt_k = amrex::max(dz(ic,k,0), eps());
419  const Real dz_zt_km1 = amrex::max(dz(ic,k-1,0), eps());
420  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
421  const Real thedz = 1.0_rt / dz_zi;
422  const Real thedz2 = 1.0_rt / (dz_zt_k + dz_zt_km1);
423  const Real iso = isotropy_i(ic,k,0);
424  const Real isosq = iso * iso;
425  const Real buoy_sgs2 = isosq * brunt_i(ic,k,0);
426  const Real bet2 = CONST_GRAV / amrex::max(thetal_i(ic,k,0), eps());
427 
428  // E3SM's top-down indexing forms above-minus-below centered
429  // differences here. In ERF's bottom-up ordering, the upper
430  // neighbor is k+1 and the lower neighbor is k-1, while the cell
431  // just above interface k is k and the one below is k-1.
432  const Real thl_sec_diff = thl_sec(ic,amrex::min(k+1, layout.nlev),0) - thl_sec(ic,k-1,0);
433  const Real wthl_sec_diff = wthl_sec(ic,amrex::min(k+1, layout.nlev),0) - wthl_sec(ic,k-1,0);
434  const Real wsec_diff = w_sec(ic,k,0) - w_sec(ic,k-1,0);
435  const Real tke_diff = tke(ic,k,0) - tke(ic,k-1,0);
436 
437  const Real c = opts.c_diag_3rd_mom;
438  const Real a0 = (0.52_rt / (c * c)) / amrex::max(c - 2.0_rt, eps());
439  const Real a1 = 0.87_rt / (c * c);
440  const Real a2 = 0.5_rt / c;
441  const Real a3 = 0.6_rt / (c * amrex::max(c - 2.0_rt, eps()));
442  const Real a4 = 2.4_rt / (3.0_rt * c + 5.0_rt);
443  const Real a5 = 0.6_rt / (c * (3.0_rt + 5.0_rt * c));
444  const Real bet2_sq = bet2 * bet2;
445  const Real bet2_cu = bet2_sq * bet2;
446  const Real iso_cu = isosq * iso;
447 
448  const Real f0 = thedz2 * bet2_cu * isosq * isosq *
449  wthl_sec(ic,k,0) * thl_sec_diff;
450  const Real f1 = thedz2 * bet2_sq * iso_cu *
451  (wthl_sec(ic,k,0) * wthl_sec_diff +
452  0.5_rt * w_sec_i(ic,k,0) * thl_sec_diff);
453  const Real f2 = thedz * bet2 * isosq * wthl_sec(ic,k,0) * wsec_diff +
454  2.0_rt * thedz2 * bet2 * isosq * w_sec_i(ic,k,0) * wthl_sec_diff;
455  const Real f3 = thedz2 * bet2 * isosq * w_sec_i(ic,k,0) * wthl_sec_diff +
456  thedz * bet2 * isosq * (wthl_sec(ic,k,0) * tke_diff);
457  const Real f4 = thedz * iso * w_sec_i(ic,k,0) * (wsec_diff + tke_diff);
458  const Real f5 = thedz * iso * w_sec_i(ic,k,0) * wsec_diff;
459 
460  const Real denom0 = signed_denominator(1.0_rt - (a1 + a3) * buoy_sgs2);
461  const Real omega0 = a4 / signed_denominator(1.0_rt - a5 * buoy_sgs2);
462  const Real omega1 = omega0 / (2.0_rt * c);
463  const Real omega2 = omega1 * f3 + 1.25_rt * omega0 * f4;
464  const Real x0 = (a2 * buoy_sgs2 * (1.0_rt - a3 * buoy_sgs2)) / denom0;
465  const Real y0 = (2.0_rt * a2 * buoy_sgs2 * x0) / signed_denominator(1.0_rt - a3 * buoy_sgs2);
466  const Real x1 = (a0 * f0 + a1 * f1 + a2 * (1.0_rt - a3 * buoy_sgs2) * f2) / denom0;
467  const Real y1 = (2.0_rt * a2 * (buoy_sgs2 * x1 + (a0 / amrex::max(a1, eps())) * f0 + f1)) /
468  signed_denominator(1.0_rt - a3 * buoy_sgs2);
469  const Real aa0 = omega0 * x0 + omega1 * y0;
470  const Real aa1 = omega0 * x1 + omega1 * y1 + omega2;
471 
472  const Real denom = signed_denominator(c - 1.2_rt * x0 + aa0);
473  Real w3_val = (aa1 - 1.2_rt * x1 - 1.5_rt * f5) / denom;
474  w3(ic,k,0) = w3_val;
475  }
476  });
477 
478  clip_third_moments(col, w_sec_zi, col.w3);
479  apply_top_taper_to_third_moments(col, opts);
480 }
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:64
static void clip_third_moments(const ShocColumnData &col, const amrex::FArrayBox &w_sec_zi, amrex::FArrayBox &w3)
Definition: ERF_ShocMoments.cpp:356
@ dz
Definition: ERF_AdvanceWSM6.cpp:104
real(c_double), parameter a2
Definition: ERF_module_model_constants.F90:95
real(c_double), parameter a3
Definition: ERF_module_model_constants.F90:96
real(c_double), parameter a4
Definition: ERF_module_model_constants.F90:97
amrex::FArrayBox dz
Definition: ERF_ShocTypes.H:210
amrex::FArrayBox w3
Definition: ERF_ShocTypes.H:257
amrex::FArrayBox brunt
Definition: ERF_ShocTypes.H:234
amrex::Real c_diag_3rd_mom
Definition: ERF_ShocTypes.H:93
Here is the call graph for this function:

The documentation for this class was generated from the following files: