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
257 {
258  auto out = outvar.array();
259  const auto iso = isotropy_zi.const_array();
260  const auto tkh = tkh_zi.const_array();
261  const auto v1 = invar1.const_array();
262  const auto v2 = invar2.const_array();
263  const auto zt = col.zt.const_array();
264  const auto zi = col.zi.const_array();
265  const auto layout = col.layout;
266  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
267  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
268  {
269  for (int k = 1; k < layout.nlev; ++k) {
270  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
271  const Real grid_dz2 = 1.0_rt / (dz_zi * dz_zi);
272  out(ic,k,0) = tunefac * (iso(ic,k,0) * tkh(ic,k,0)) * grid_dz2 *
273  (v1(ic,k-1,0) - v1(ic,k,0)) * (v2(ic,k-1,0) - v2(ic,k,0));
274  }
275  });
276 }
struct @28 out
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);})
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
283 {
284  auto out = vertflux.array();
285  const auto tkh = tkh_zi.const_array();
286  const auto v = invar.const_array();
287  const auto zt = col.zt.const_array();
288  const auto zi = col.zi.const_array();
289  const auto layout = col.layout;
290  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
291  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
292  {
293  for (int k = 1; k < layout.nlev; ++k) {
294  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
295  // E3SM uses top-down vertical indexing. ERF columns are bottom-up,
296  // so the interface gradient must use upper-minus-lower to preserve
297  // the same physical downgradient flux sign.
298  out(ic,k,0) = -(tkh(ic,k,0) / dz_zi) * (v(ic,k,0) - v(ic,k-1,0));
299  }
300  });
301 }
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
361 {
362  auto w3 = w3_fab.array();
363  const auto wsec = w_sec_zi.const_array();
364 
365  const auto layout = col.layout;
366  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
367  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
368  {
369  for (int k = 0; k <= layout.nlev; ++k) {
370  const Real wsec3 = wsec(ic,k,0) * wsec(ic,k,0) * wsec(ic,k,0);
371  const Real clip_cond = shoc_w3clip() * std::sqrt(amrex::max(0.0_rt, 2.0_rt * wsec3));
372  if (amrex::Math::abs(w3(ic,k,0)) > clip_cond) {
373  w3(ic,k,0) = shoc_w3clipdef();
374  }
375  }
376  });
377 }
Here is the call graph for this function:

◆ diagnose_moments()

void ShocMoments::diagnose_moments ( ShocColumnData col,
const ShocRuntimeOptions opts 
)
static
487 {
488  diagnose_second_moments(col, opts);
489  diagnose_third_moments(col, opts);
490 }
static void diagnose_second_moments(ShocColumnData &col, const ShocRuntimeOptions &opts)
Definition: ERF_ShocMoments.cpp:304
static void diagnose_third_moments(ShocColumnData &col, const ShocRuntimeOptions &opts)
Definition: ERF_ShocMoments.cpp:380

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
306 {
307  FArrayBox isotropy_zi, tkh_zi, tk_zi;
308  const Box iface_box(IntVect(0,0,0), IntVect(col.layout.ncell - 1, col.layout.nlev, 0));
309  isotropy_zi.resize(iface_box, 1, The_Async_Arena());
310  tkh_zi.resize(iface_box, 1, The_Async_Arena());
311  tk_zi.resize(iface_box, 1, The_Async_Arena());
312 
313  interpolate_cc_to_iface(col, col.isotropy, isotropy_zi, 0.0);
314  interpolate_cc_to_iface(col, col.tkh, tkh_zi, 0.0);
315  interpolate_cc_to_iface(col, col.tk, tk_zi, 0.0);
316 
317  auto thl_sec = col.thl_sec.array();
318  auto qw_sec = col.qw_sec.array();
319  auto qwthl_sec = col.qwthl_sec.array();
320  auto w_sec = col.w_sec.array();
321 
322  const auto tke = col.tke.const_array();
323  const auto layout = col.layout;
324  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
325  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
326  {
327  for (int k = 0; k < layout.nlev; ++k) {
328  w_sec(ic,k,0) = opts.shoc_1p5tke ? 0.0_rt : opts.w2tune * (2.0_rt / 3.0_rt) * tke(ic,k,0);
329  }
330  });
331 
332  if (opts.shoc_1p5tke) {
333  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
334  {
335  for (int k = 0; k <= layout.nlev; ++k) {
336  thl_sec(ic,k,0) = 0.0_rt;
337  qw_sec(ic,k,0) = 0.0_rt;
338  qwthl_sec(ic,k,0) = 0.0_rt;
339  }
340  });
341  } else {
342  calc_var_or_covar(col, opts.thl2tune, isotropy_zi, tkh_zi, col.thetal, col.thetal, col.thl_sec);
343  calc_var_or_covar(col, opts.qw2tune, isotropy_zi, tkh_zi, col.qw, col.qw, col.qw_sec);
344  calc_var_or_covar(col, opts.qwthl2tune, isotropy_zi, tkh_zi, col.thetal, col.qw, col.qwthl_sec);
345  }
346 
347  calc_vertflux(col, tkh_zi, col.thetal, col.wthl_sec);
348  calc_vertflux(col, tkh_zi, col.qw, col.wqw_sec);
349  calc_vertflux(col, tkh_zi, col.tke, col.wtke_sec);
350  calc_vertflux(col, tk_zi, col.u, col.uw_sec);
351  calc_vertflux(col, tk_zi, col.v, col.vw_sec);
352 
353  apply_second_moment_boundary_conditions(col);
354  apply_top_taper_to_second_moments(col, opts);
355 }
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:250
static void calc_vertflux(const ShocColumnData &col, const amrex::FArrayBox &tkh_zi, const amrex::FArrayBox &invar, amrex::FArrayBox &vertflux)
Definition: ERF_ShocMoments.cpp:279
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
382 {
383  FArrayBox isotropy_zi, brunt_zi, w_sec_zi, thetal_zi;
384  const Box iface_box(IntVect(0,0,0), IntVect(col.layout.ncell - 1, col.layout.nlev, 0));
385  isotropy_zi.resize(iface_box, 1, The_Async_Arena());
386  brunt_zi.resize(iface_box, 1, The_Async_Arena());
387  w_sec_zi.resize(iface_box, 1, The_Async_Arena());
388  thetal_zi.resize(iface_box, 1, The_Async_Arena());
389 
390  interpolate_cc_to_iface(col, col.isotropy, isotropy_zi, 0.0);
391  interpolate_cc_to_iface(col, col.brunt, brunt_zi, shoc_large_neg());
392  interpolate_cc_to_iface(col, col.w_sec, w_sec_zi, (2.0_rt / 3.0_rt) * shoc_min_tke());
393  interpolate_cc_to_iface(col, col.thetal, thetal_zi, 0.0);
394 
395  auto w3 = col.w3.array();
396  const auto w_sec = col.w_sec.const_array();
397  const auto thl_sec = col.thl_sec.const_array();
398  const auto wthl_sec = col.wthl_sec.const_array();
399  const auto tke = col.tke.const_array();
400  const auto dz = col.dz.const_array();
401  const auto isotropy_i = isotropy_zi.const_array();
402  const auto brunt_i = brunt_zi.const_array();
403  const auto w_sec_i = w_sec_zi.const_array();
404  const auto thetal_i = thetal_zi.const_array();
405  const auto zt = col.zt.const_array();
406  const auto zi = col.zi.const_array();
407  const auto layout = col.layout;
408  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
409  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
410  {
411  w3(ic,0,0) = 0.0_rt;
412  w3(ic,layout.nlev,0) = 0.0_rt;
413 
414  for (int k = 1; k < layout.nlev; ++k) {
415  if (opts.shoc_1p5tke) {
416  w3(ic,k,0) = 0.0_rt;
417  continue;
418  }
419 
420  const Real dz_zt_k = amrex::max(dz(ic,k,0), eps());
421  const Real dz_zt_km1 = amrex::max(dz(ic,k-1,0), eps());
422  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
423  const Real thedz = 1.0_rt / dz_zi;
424  const Real thedz2 = 1.0_rt / (dz_zt_k + dz_zt_km1);
425  const Real iso = isotropy_i(ic,k,0);
426  const Real isosq = iso * iso;
427  const Real buoy_sgs2 = isosq * brunt_i(ic,k,0);
428  const Real bet2 = CONST_GRAV / amrex::max(thetal_i(ic,k,0), eps());
429 
430  // E3SM's top-down indexing forms above-minus-below centered
431  // differences here. In ERF's bottom-up ordering, the upper
432  // neighbor is k+1 and the lower neighbor is k-1, while the cell
433  // just above interface k is k and the one below is k-1.
434  const Real thl_sec_diff = thl_sec(ic,amrex::min(k+1, layout.nlev),0) - thl_sec(ic,k-1,0);
435  const Real wthl_sec_diff = wthl_sec(ic,amrex::min(k+1, layout.nlev),0) - wthl_sec(ic,k-1,0);
436  const Real wsec_diff = w_sec(ic,k,0) - w_sec(ic,k-1,0);
437  const Real tke_diff = tke(ic,k,0) - tke(ic,k-1,0);
438 
439  const Real c = opts.c_diag_3rd_mom;
440  const Real a0 = (0.52_rt / (c * c)) / amrex::max(c - 2.0_rt, eps());
441  const Real a1 = 0.87_rt / (c * c);
442  const Real a2 = 0.5_rt / c;
443  const Real a3 = 0.6_rt / (c * amrex::max(c - 2.0_rt, eps()));
444  const Real a4 = 2.4_rt / (3.0_rt * c + 5.0_rt);
445  const Real a5 = 0.6_rt / (c * (3.0_rt + 5.0_rt * c));
446  const Real bet2_sq = bet2 * bet2;
447  const Real bet2_cu = bet2_sq * bet2;
448  const Real iso_cu = isosq * iso;
449 
450  const Real f0 = thedz2 * bet2_cu * isosq * isosq *
451  wthl_sec(ic,k,0) * thl_sec_diff;
452  const Real f1 = thedz2 * bet2_sq * iso_cu *
453  (wthl_sec(ic,k,0) * wthl_sec_diff +
454  0.5_rt * w_sec_i(ic,k,0) * thl_sec_diff);
455  const Real f2 = thedz * bet2 * isosq * wthl_sec(ic,k,0) * wsec_diff +
456  2.0_rt * thedz2 * bet2 * isosq * w_sec_i(ic,k,0) * wthl_sec_diff;
457  const Real f3 = thedz2 * bet2 * isosq * w_sec_i(ic,k,0) * wthl_sec_diff +
458  thedz * bet2 * isosq * (wthl_sec(ic,k,0) * tke_diff);
459  const Real f4 = thedz * iso * w_sec_i(ic,k,0) * (wsec_diff + tke_diff);
460  const Real f5 = thedz * iso * w_sec_i(ic,k,0) * wsec_diff;
461 
462  const Real denom0 = signed_denominator(1.0_rt - (a1 + a3) * buoy_sgs2);
463  const Real omega0 = a4 / signed_denominator(1.0_rt - a5 * buoy_sgs2);
464  const Real omega1 = omega0 / (2.0_rt * c);
465  const Real omega2 = omega1 * f3 + 1.25_rt * omega0 * f4;
466  const Real x0 = (a2 * buoy_sgs2 * (1.0_rt - a3 * buoy_sgs2)) / denom0;
467  const Real y0 = (2.0_rt * a2 * buoy_sgs2 * x0) / signed_denominator(1.0_rt - a3 * buoy_sgs2);
468  const Real x1 = (a0 * f0 + a1 * f1 + a2 * (1.0_rt - a3 * buoy_sgs2) * f2) / denom0;
469  const Real y1 = (2.0_rt * a2 * (buoy_sgs2 * x1 + (a0 / amrex::max(a1, eps())) * f0 + f1)) /
470  signed_denominator(1.0_rt - a3 * buoy_sgs2);
471  const Real aa0 = omega0 * x0 + omega1 * y0;
472  const Real aa1 = omega0 * x1 + omega1 * y1 + omega2;
473 
474  const Real denom = signed_denominator(c - 1.2_rt * x0 + aa0);
475  Real w3_val = (aa1 - 1.2_rt * x1 - 1.5_rt * f5) / denom;
476  w3(ic,k,0) = w3_val;
477  }
478  });
479 
480  clip_third_moments(col, w_sec_zi, col.w3);
481  apply_top_taper_to_third_moments(col, opts);
482 }
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:358
@ 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: