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
250 {
251  auto out = outvar.array();
252  const auto iso = isotropy_zi.const_array();
253  const auto tkh = tkh_zi.const_array();
254  const auto v1 = invar1.const_array();
255  const auto v2 = invar2.const_array();
256  const auto zt = col.zt.const_array();
257  const auto zi = col.zi.const_array();
258  const auto layout = col.layout;
259  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
260  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
261  {
262  for (int k = 1; k < layout.nlev; ++k) {
263  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
264  const Real grid_dz2 = 1.0_rt / (dz_zi * dz_zi);
265  out(ic,k,0) = tunefac * (iso(ic,k,0) * tkh(ic,k,0)) * grid_dz2 *
266  (v1(ic,k-1,0) - v1(ic,k,0)) * (v2(ic,k-1,0) - v2(ic,k,0));
267  }
268  });
269 }
struct @28 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
276 {
277  auto out = vertflux.array();
278  const auto tkh = tkh_zi.const_array();
279  const auto v = invar.const_array();
280  const auto zt = col.zt.const_array();
281  const auto zi = col.zi.const_array();
282  const auto layout = col.layout;
283  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
284  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
285  {
286  for (int k = 1; k < layout.nlev; ++k) {
287  const Real dz_zi = cell_spacing_at_iface(zt, zi, layout, ic, k);
288  // E3SM uses top-down vertical indexing. ERF columns are bottom-up,
289  // so the interface gradient must use upper-minus-lower to preserve
290  // the same physical downgradient flux sign.
291  out(ic,k,0) = -(tkh(ic,k,0) / dz_zi) * (v(ic,k,0) - v(ic,k-1,0));
292  }
293  });
294 }
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
354 {
355  auto w3 = w3_fab.array();
356  const auto wsec = w_sec_zi.const_array();
357 
358  const auto layout = col.layout;
359  const Box col_box(IntVect(0,0,0), IntVect(layout.ncell - 1, 0, 0));
360  ParallelFor(col_box, [=] AMREX_GPU_DEVICE (int ic, int, int) noexcept
361  {
362  for (int k = 0; k <= layout.nlev; ++k) {
363  const Real wsec3 = wsec(ic,k,0) * wsec(ic,k,0) * wsec(ic,k,0);
364  const Real clip_cond = shoc_w3clip() * std::sqrt(amrex::max(0.0_rt, 2.0_rt * wsec3));
365  if (amrex::Math::abs(w3(ic,k,0)) > clip_cond) {
366  w3(ic,k,0) = shoc_w3clipdef();
367  }
368  }
369  });
370 }
Here is the call graph for this function:

◆ diagnose_moments()

void ShocMoments::diagnose_moments ( ShocColumnData col,
const ShocRuntimeOptions opts 
)
static
480 {
481  diagnose_second_moments(col, opts);
482  diagnose_third_moments(col, opts);
483 }
static void diagnose_second_moments(ShocColumnData &col, const ShocRuntimeOptions &opts)
Definition: ERF_ShocMoments.cpp:297
static void diagnose_third_moments(ShocColumnData &col, const ShocRuntimeOptions &opts)
Definition: ERF_ShocMoments.cpp:373

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