ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_detail_ShocDriver Namespace Reference

Classes

struct  ShocBadColumnReport
 

Functions

template<typename Fab >
FArrayBox copy_fab_to_host (const Fab &src)
 
void print_shoc_debug_settings_once (const ShocRuntimeOptions &opts)
 
void warn_if_shoc_debug_overrides_active_once (const ShocRuntimeOptions &opts)
 
void require_full_height_shoc_boxes (const BoxArray &ba, const Box &domain)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real weighted_linear_interp (Real x0, Real x1, Real y0, Real y1, Real x)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int face_neighbor_cell (int idx, int domlo, int domhi, bool periodic)
 
void seed_carried_turbulence_impl (Box const &xy_box, ShocColumnLayout layout, Array4< const Real > const &rho_host, Array4< const Real > const &carried, Array4< const Real > const &host_diff, Array4< Real > const &tk, Array4< Real > const &tkh, bool prev_turb_valid)
 
void store_carried_turbulence_impl (Box const &xy_box, ShocColumnLayout layout, Array4< Real > const &carried, Array4< const Real > const &tk, Array4< const Real > const &tkh)
 
void seed_carried_buoyancy_flux_impl (Box const &xy_box, ShocColumnLayout layout, Array4< const Real > const &carried, Array4< Real > const &wthv_sec)
 
void store_carried_buoyancy_flux_impl (Box const &xy_box, ShocColumnLayout layout, Array4< Real > const &carried, Array4< const Real > const &wthv_sec)
 
void sync_face_multifab_impl (MultiFab &mf, const Geometry &geom)
 
void apply_state_update_cons_impl (MultiFab &cons, const MultiFab &theta_tend_cc, const MultiFab &qv_tend_cc, const MultiFab &qc_tend_cc, const MultiFab &qi_tend_cc, const MultiFab &tke_tend_cc, int qv_comp, int qc_comp, int qi_comp, const ShocRuntimeOptions &opts, double dt_d)
 
void apply_state_update_face_velocity_impl (MultiFab &vel, const MultiFab &vel_tend, double dt_d)
 

Variables

constexpr int k_shoc_vertical_diff_comp = EddyDiff::Mom_v
 
constexpr int k_shoc_vertical_diff_count = EddyDiff::Q_v - EddyDiff::Mom_v + 1
 

Function Documentation

◆ apply_state_update_cons_impl()

void erf_detail_ShocDriver::apply_state_update_cons_impl ( MultiFab &  cons,
const MultiFab &  theta_tend_cc,
const MultiFab &  qv_tend_cc,
const MultiFab &  qc_tend_cc,
const MultiFab &  qi_tend_cc,
const MultiFab &  tke_tend_cc,
int  qv_comp,
int  qc_comp,
int  qi_comp,
const ShocRuntimeOptions &  opts,
double  dt_d 
)
249  {
250  Real dt = static_cast<Real>(dt_d);
251 
252  const bool has_qv = shoc_valid_comp(qv_comp, cons.nComp());
253  const bool has_qc = shoc_valid_comp(qc_comp, cons.nComp());
254  const bool has_qi = shoc_valid_comp(qi_comp, cons.nComp());
255 
256  for (MFIter mfi(cons, false); mfi.isValid(); ++mfi) {
257  const auto rho = cons.const_array(mfi);
258  auto cc = cons.array(mfi);
259  const auto theta_tend = theta_tend_cc.const_array(mfi);
260  const auto qv_tend = qv_tend_cc.const_array(mfi);
261  const auto qc_tend = qc_tend_cc.const_array(mfi);
262  const auto qi_tend = qi_tend_cc.const_array(mfi);
263  const auto tke_tend = tke_tend_cc.const_array(mfi);
264 
265  ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
266  const Real rho_val = rho(i,j,k,Rho_comp);
268  cc(i,j,k,RhoTheta_comp) += rho_val * dt * theta_tend(i,j,k);
269  }
271  if (has_qv) {
272  cc(i,j,k,qv_comp) = amrex::max(
273  cc(i,j,k,qv_comp) + rho_val * dt * qv_tend(i,j,k), Real(0.));
274  }
275  if (has_qc) {
276  cc(i,j,k,qc_comp) = amrex::max(
277  cc(i,j,k,qc_comp) + rho_val * dt * qc_tend(i,j,k), Real(0.));
278  }
279  if (has_qi) {
280  cc(i,j,k,qi_comp) = amrex::max(
281  cc(i,j,k,qi_comp) + rho_val * dt * qi_tend(i,j,k), Real(0.));
282  }
283  }
284  if (!opts.debug_disable_tke_state_update) {
285  cc(i,j,k,RhoKE_comp) = amrex::max(
286  cc(i,j,k,RhoKE_comp) + rho_val * dt * tke_tend(i,j,k), Real(0.));
287  }
288  });
289  }
290  }
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
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_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool shoc_valid_comp(int comp, int ncomp)
Definition: ERF_ShocTypes.H:234
@ rho
Definition: ERF_Kessler.H:25
@ cons
Definition: ERF_IndexDefines.H:231
bool debug_disable_moisture_state_update
Definition: ERF_ShocTypes.H:53
bool debug_disable_theta_state_update
Definition: ERF_ShocTypes.H:52
bool debug_disable_tke_state_update
Definition: ERF_ShocTypes.H:54

Referenced by ShocDriver::apply_state_update().

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

◆ apply_state_update_face_velocity_impl()

void erf_detail_ShocDriver::apply_state_update_face_velocity_impl ( MultiFab &  vel,
const MultiFab &  vel_tend,
double  dt_d 
)
295  {
296  Real dt = static_cast<Real>(dt_d);
297  for (MFIter mfi(vel_tend, false); mfi.isValid(); ++mfi) {
298  auto v = vel.array(mfi);
299  const auto tend = vel_tend.const_array(mfi);
300  ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
301  v(i,j,k) += dt * tend(i,j,k);
302  });
303  }
304  }

Referenced by ShocDriver::apply_state_update().

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

◆ copy_fab_to_host()

template<typename Fab >
FArrayBox erf_detail_ShocDriver::copy_fab_to_host ( const Fab &  src)
52  {
53 #ifdef AMREX_USE_GPU
54  FArrayBox dst(src.box(), src.nComp(), amrex::The_Pinned_Arena());
55  const std::size_t nbytes = static_cast<std::size_t>(dst.size()) * sizeof(Real);
56  if (src.arena()->isManaged() || src.arena()->isDevice()) {
57  static bool printed_gpu_path_marker = false;
58  if (!printed_gpu_path_marker) {
59  amrex::Print() << "NATIVE_SHOC_DEBUG_COPY_HELPER_GPU_PATH\n";
60  printed_gpu_path_marker = true;
61  }
62  amrex::Gpu::dtoh_memcpy_async(dst.dataPtr(), src.dataPtr(), nbytes);
63  amrex::Gpu::streamSynchronize();
64  } else {
65  std::memcpy(dst.dataPtr(), src.dataPtr(), nbytes);
66  }
67  return dst;
68 #else
69  FArrayBox dst(src.box(), src.nComp());
70  dst.template copy<RunOn::Host>(src);
71  return dst;
72 #endif
73  }

Referenced by ShocDriver::debug_check_bad_column().

Here is the caller graph for this function:

◆ face_neighbor_cell()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int erf_detail_ShocDriver::face_neighbor_cell ( int  idx,
int  domlo,
int  domhi,
bool  periodic 
)
148  {
149  return periodic ? idx : shoc_clamp(idx, domlo, domhi);
150  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T shoc_clamp(T value, T lo, T hi)
Definition: ERF_ShocTypes.H:242

Referenced by ShocDriver::advance().

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

◆ print_shoc_debug_settings_once()

void erf_detail_ShocDriver::print_shoc_debug_settings_once ( const ShocRuntimeOptions &  opts)
76  {
77  static bool printed = false;
78  if (printed) {
79  return;
80  }
81  printed = true;
82 
83  std::ostringstream os;
84  os << std::boolalpha;
85  os << "SHOC debug thresholds:\n"
86  << " theta_tend=" << opts.debug_bad_column_theta_tend_threshold << "\n"
87  << " q_tend=" << opts.debug_bad_column_q_tend_threshold << "\n"
88  << " brunt=" << opts.debug_bad_column_brunt_threshold << "\n"
89  << " min_dz=" << opts.debug_bad_column_min_dz << "\n"
90  << " scalar_moment=" << opts.debug_bad_column_scalar_moment_threshold << "\n"
91  << "SHOC debug switches:\n"
92  << " debug_bad_column=" << opts.debug_bad_column << "\n"
93  << " debug_bad_column_abort=" << opts.debug_bad_column_abort << "\n"
94  << " debug_disable_pdf_cloud_increment=" << opts.debug_disable_pdf_cloud_increment << "\n"
95  << " debug_disable_theta_state_update=" << opts.debug_disable_theta_state_update << "\n"
96  << " debug_disable_moisture_state_update=" << opts.debug_disable_moisture_state_update << "\n"
97  << " debug_disable_tke_state_update=" << opts.debug_disable_tke_state_update << "\n";
98  amrex::Print() << os.str();
99  }
amrex::Real debug_bad_column_q_tend_threshold
Definition: ERF_ShocTypes.H:47
amrex::Real debug_bad_column_scalar_moment_threshold
Definition: ERF_ShocTypes.H:50
amrex::Real debug_bad_column_min_dz
Definition: ERF_ShocTypes.H:49
bool debug_disable_pdf_cloud_increment
Definition: ERF_ShocTypes.H:51
amrex::Real debug_bad_column_theta_tend_threshold
Definition: ERF_ShocTypes.H:46
bool debug_bad_column
Definition: ERF_ShocTypes.H:43
amrex::Real debug_bad_column_brunt_threshold
Definition: ERF_ShocTypes.H:48
bool debug_bad_column_abort
Definition: ERF_ShocTypes.H:44

Referenced by ShocDriver::debug_check_bad_column(), and ShocDriver::print_debug_summary().

Here is the caller graph for this function:

◆ require_full_height_shoc_boxes()

void erf_detail_ShocDriver::require_full_height_shoc_boxes ( const BoxArray &  ba,
const Box &  domain 
)
127  {
128  // Tile-local SHOC packing and writeback still assume each MFIter tile
129  // spans a complete vertical column.
130  if (!shoc_boxarray_spans_full_height(ba, domain)) {
131  amrex::Abort(
132  "Native SHOC requires each BoxArray box on a SHOC-active level to span the full vertical domain. Z-split boxes are not supported. Increase the vertical max_grid_size/blocking size, or use full-column refined grids.");
133  }
134  }
bool shoc_boxarray_spans_full_height(const BoxArray &ba, const Box &domain)
Definition: ERF_ShocDriver.cpp:20

Referenced by ShocDriver::advance().

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

◆ seed_carried_buoyancy_flux_impl()

void erf_detail_ShocDriver::seed_carried_buoyancy_flux_impl ( Box const &  xy_box,
ShocColumnLayout  layout,
Array4< const Real > const &  carried,
Array4< Real > const &  wthv_sec 
)
202  {
203  ParallelFor(xy_box, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
204  {
205  const int ic = shoc_column_index(layout, i, j);
206  for (int kk = 0; kk < layout.nlev; ++kk) {
207  const int k = layout.kmin + kk;
208  wthv_sec(ic,kk,0) = carried(i,j,k,0);
209  }
210  });
211  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int shoc_column_index(const ShocColumnLayout &layout, int i, int j)
Definition: ERF_ShocColumnData.H:133
int nlev
Definition: ERF_ShocTypes.H:62
int kmin
Definition: ERF_ShocTypes.H:65

Referenced by ShocDriver::seed_carried_buoyancy_flux().

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

◆ seed_carried_turbulence_impl()

void erf_detail_ShocDriver::seed_carried_turbulence_impl ( Box const &  xy_box,
ShocColumnLayout  layout,
Array4< const Real > const &  rho_host,
Array4< const Real > const &  carried,
Array4< const Real > const &  host_diff,
Array4< Real > const &  tk,
Array4< Real > const &  tkh,
bool  prev_turb_valid 
)
161  {
162  ParallelFor(xy_box, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
163  {
164  const int ic = shoc_column_index(layout, i, j);
165  for (int kk = 0; kk < layout.nlev; ++kk) {
166  const int k = layout.kmin + kk;
167  if (prev_turb_valid) {
168  tk(ic,kk,0) = carried(i,j,k,0);
169  tkh(ic,kk,0) = carried(i,j,k,1);
170  } else {
171  const Real rho = amrex::max(rho_host(i,j,k,Rho_comp), 1.0e-12_rt);
172  tk(ic,kk,0) = amrex::max(0.0_rt, host_diff(i,j,k,EddyDiff::Mom_v) / rho);
173  tkh(ic,kk,0) = amrex::max(0.0_rt, host_diff(i,j,k,EddyDiff::Theta_v) / rho);
174  }
175  }
176  });
177  }
@ Theta_v
Definition: ERF_IndexDefines.H:267
@ Mom_v
Definition: ERF_IndexDefines.H:266
@ tk
Definition: ERF_AdvanceWDM6.cpp:273

Referenced by ShocDriver::seed_carried_turbulence().

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

◆ store_carried_buoyancy_flux_impl()

void erf_detail_ShocDriver::store_carried_buoyancy_flux_impl ( Box const &  xy_box,
ShocColumnLayout  layout,
Array4< Real > const &  carried,
Array4< const Real > const &  wthv_sec 
)
218  {
219  ParallelFor(xy_box, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
220  {
221  const int ic = shoc_column_index(layout, i, j);
222  for (int kk = 0; kk < layout.nlev; ++kk) {
223  const int k = layout.kmin + kk;
224  carried(i,j,k,0) = wthv_sec(ic,kk,0);
225  }
226  });
227  }

Referenced by ShocDriver::store_carried_buoyancy_flux().

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

◆ store_carried_turbulence_impl()

void erf_detail_ShocDriver::store_carried_turbulence_impl ( Box const &  xy_box,
ShocColumnLayout  layout,
Array4< Real > const &  carried,
Array4< const Real > const &  tk,
Array4< const Real > const &  tkh 
)
185  {
186  ParallelFor(xy_box, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
187  {
188  const int ic = shoc_column_index(layout, i, j);
189  for (int kk = 0; kk < layout.nlev; ++kk) {
190  const int k = layout.kmin + kk;
191  carried(i,j,k,0) = tk(ic,kk,0);
192  carried(i,j,k,1) = tkh(ic,kk,0);
193  }
194  });
195  }

Referenced by ShocDriver::store_carried_turbulence().

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

◆ sync_face_multifab_impl()

void erf_detail_ShocDriver::sync_face_multifab_impl ( MultiFab &  mf,
const Geometry &  geom 
)
230  {
231  // OverrideSync reconciles duplicate values on overlapping face-centered
232  // tiles before SHOC reads or writes them. It is a no-op for cell-centered
233  // MultiFabs, so the helper can be reused for the face-centered state and
234  // tendency fields without special casing the index type.
235  mf.OverrideSync(geom.periodicity());
236  }

Referenced by ShocDriver::advance().

Here is the caller graph for this function:

◆ warn_if_shoc_debug_overrides_active_once()

void erf_detail_ShocDriver::warn_if_shoc_debug_overrides_active_once ( const ShocRuntimeOptions &  opts)
102  {
103  static bool warned = false;
104  if (warned) {
105  return;
106  }
111  return;
112  }
113  warned = true;
114 
115  std::ostringstream os;
116  os << std::boolalpha;
117  os << "WARNING: native SHOC debug override active:\n"
118  << " debug_disable_pdf_cloud_increment = " << opts.debug_disable_pdf_cloud_increment << "\n"
119  << " debug_disable_theta_state_update = " << opts.debug_disable_theta_state_update << "\n"
120  << " debug_disable_moisture_state_update = " << opts.debug_disable_moisture_state_update << "\n"
121  << " debug_disable_tke_state_update = " << opts.debug_disable_tke_state_update << "\n"
122  << "These options are for debugging only and change native SHOC numerics.\n";
123  amrex::Print() << os.str();
124  }

Referenced by ShocDriver::ShocDriver().

Here is the caller graph for this function:

◆ weighted_linear_interp()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_detail_ShocDriver::weighted_linear_interp ( Real  x0,
Real  x1,
Real  y0,
Real  y1,
Real  x 
)
138  {
139  const Real denom = x1 - x0;
140  if (amrex::Math::abs(denom) <= 1.0e-12_rt) {
141  return 0.5_rt * (y0 + y1);
142  }
143  return y0 + (y1 - y0) * (x - x0) / denom;
144  }

Referenced by ShocDriver::advance(), and ShocStructure::diagnose_length_and_brunt().

Here is the caller graph for this function:

Variable Documentation

◆ k_shoc_vertical_diff_comp

constexpr int erf_detail_ShocDriver::k_shoc_vertical_diff_comp = EddyDiff::Mom_v
constexpr

◆ k_shoc_vertical_diff_count

constexpr int erf_detail_ShocDriver::k_shoc_vertical_diff_count = EddyDiff::Q_v - EddyDiff::Mom_v + 1
constexpr