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

Classes

struct  DeviceGroupInfo
 
struct  MatchingGroup
 
struct  LocalPropertySupport
 

Typedefs

using FaceArraySet = GpuArray< Array4< const Real >, AMREX_SPACEDIM >
 

Functions

bool is_matched_coordinate (const ConstraintGroup &group, const SBMLayout &layout, const int constraint_index)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real clamp_unit (const Real value) noexcept
 
void build_intensive (MultiFab &intensive, const MultiFab &state, const MultiFab &conserved, const amrex::Periodicity &periodicity, const char *what)
 
void fill_physical_ghosts (MultiFab &field, const amrex::Geometry &geometry, const SBMPhysicalBoundaryConfig &boundaries, const Real *inflow_device)
 
void clear_outside_physical_domain (MultiFab &mask, const int component, const amrex::Geometry &geometry)
 
void apply_physical_donor_band (erf_auxiliary::MappedFaceFluxRate &high, const erf_auxiliary::MappedFaceFluxRate &low, const amrex::Geometry &geometry)
 
amrex::Box physical_face_slab (const amrex::Box &face_valid, const amrex::Box &domain, const int dir, const bool low)
 
void add_low_order_mixing (erf_auxiliary::MappedFaceFluxRate &low, erf_auxiliary::MappedFaceFluxRate &scratch, const erf_auxiliary::MappedFaceTransmissibility &transmissibility, const amrex::Geometry &geometry, const MultiFab &base_intensive, const std::vector< int > &components)
 
void add_high_order_mixing (erf_auxiliary::MappedFaceFluxRate &high, erf_auxiliary::MappedFaceFluxRate &scratch, const ParticleMixingConfig &config, const SBMStageMixingInputs &inputs, const amrex::BCRec *bc, const erf_auxiliary::MappedDiffusionBoundary &boundary, const amrex::Geometry &geometry, const MultiFab &input_intensive, const MultiFab &input_conserved, const std::vector< int > &components)
 
int extend_wall_ghosts (MultiFab &scalar, const int ncomp, const MultiFab &z_cc, const amrex::Geometry &geometry)
 
void fill_side_open_mask (MultiFab &mask, const int dir, const erf_auxiliary::MappedDiffusionBoundary &boundary, const amrex::Geometry &geometry)
 
void build_terrain_high_order_mixing (erf_auxiliary::MappedFaceFluxRate &diffusive, MultiFab &scalar, std::array< MultiFab, AMREX_SPACEDIM > &raw, const std::array< MultiFab, 2 > &side_open, const ParticleMixingConfig &config, const SBMStageMixingInputs &inputs, const amrex::BCRec *bc, const amrex::Geometry &geometry, const MultiFab &input_intensive, const MultiFab &input_conserved, const std::vector< int > &components)
 
Real shared_copy_mismatch (const MultiFab &field, const amrex::Periodicity &period)
 
std::string shared_metric_mismatch (const erf_auxiliary::MappedDiffusionMetrics &metrics, const amrex::Geometry &geometry)
 
void add_matched_terrain_mixing (erf_auxiliary::MappedFaceFluxRate &low, erf_auxiliary::MappedFaceFluxRate &high, const erf_auxiliary::MappedFaceFluxRate &diffusive, const erf_auxiliary::MappedFaceTransmissibility &transmissibility, const amrex::Geometry &geometry, const MultiFab &base_intensive, const int *chunk_components, const MatchingGroup *groups, const int group_count, const int *members, const ConstraintDescriptor *coordinates, const ConstraintTerm *terms, const bool match)
 
void open_face_ratio_ghosts (MultiFab &ratios, const amrex::Geometry &geometry, const SBMPhysicalBoundaryConfig &boundaries)
 
void check_physical_face_carriers (const std::array< const MultiFab *, AMREX_SPACEDIM > &carrier, const amrex::Geometry &geometry, const SBMPhysicalBoundaryConfig &boundaries, const int level, const int stage)
 
void accumulate_boundary_rates (const erf_auxiliary::MappedFaceFluxRate &accepted, const int *components, const int component_count, const amrex::Geometry &geometry, const MultiFab *covered, const int ncomp, double *partial, double &face_terms)
 
bool coarse_stage_theta (const double requested_time, const double coarse_old_time, const double coarse_new_time, const double dt_min, double &theta, std::string &diagnostic)
 
bool coarse_stage_endpoints_valid (const MultiFab &coarse_stage, const int component_count, const int new_offset, const int rho_old_local, const amrex::Box &coarse_region)
 
void fill_coarse_parent_ghosts (MultiFab &destination, MultiFab &missing_fine_ghosts, const MultiFab &coarse_old_spectrum, const MultiFab &coarse_new_spectrum, const MultiFab &fine_source_state, const MultiFab &fine_source_conserved, const SBMAMRStageParent &parent, const amrex::Geometry &fine_geometry, const std::vector< ConstraintClosureChunk > &chunks, const int max_chunk_components, const double requested_time, const double coarse_old_spectrum_time, const double coarse_new_spectrum_time, const int level, const int stage, const char *role, MultiFab &coarse_pack, MultiFab &coarse_stage, const SBMAMRStageGhostProbe *probe=nullptr, std::array< bool, 2 > *split_values_checked=nullptr)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real face_correction (const erf_sbm::ConstraintDescriptor &descriptor, const erf_sbm::ConstraintTerm *terms, const FaceArraySet &low, const FaceArraySet &high, const int i, const int j, const int k, const int dir, const int side, const Real tau, const GpuArray< Real, AMREX_SPACEDIM > &dx_inv) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real face_gross (const erf_sbm::ConstraintDescriptor &descriptor, const erf_sbm::ConstraintTerm *terms, const FaceArraySet &low, const FaceArraySet &high, const int i, const int j, const int k, const int dir, const int side, const Real tau, const GpuArray< Real, AMREX_SPACEDIM > &dx_inv) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real pair_face_gross (const int first, const int second, const Real first_coefficient, const Real second_coefficient, const FaceArraySet &low, const FaceArraySet &high, const int i, const int j, const int k, const int dir, const int side, const Real tau, const GpuArray< Real, AMREX_SPACEDIM > &dx_inv) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real budget_ratio (const Real margin, const Real adverse, const Real scale, const Real roundoff) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real canonical_reserve_face_correction (const int mass_component, const int number_component, const Real mass_coefficient, const Real number_coefficient, const FaceArraySet &low, const FaceArraySet &high, const int i, const int j, const int k, const int dir, const int side, const Real tau, const GpuArray< Real, AMREX_SPACEDIM > &dx_inv) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real property_face_correction (const LocalPropertySupport &support, const FaceArraySet &low, const FaceArraySet &high, const int i, const int j, const int k, const int dir, const int side, const Real tau, const GpuArray< Real, AMREX_SPACEDIM > &dx_inv, const Real slope, const bool upper) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void consider_donor_ratio (const Array4< const Real > &field, const int i, const int j, const int k, const LocalPropertySupport &support, Real &lower, Real &upper, int &found) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void include_neighbourhood (const Array4< const Real > &field, const int i, const int j, const int k, const LocalPropertySupport &support, Real &lower, Real &upper, int &found) noexcept
 
void sample_probe_endpoint_value (const SBMAMRStageGhostProbe *probe, const int stage, const MultiFab &endpoint_input)
 
void sample_probe_stencil (const SBMAMRStageGhostProbe *probe, const int stage, const MultiFab &physical_input, const MultiFab &endpoint_input)
 
void sample_probe_face_rates (const SBMAMRStageGhostProbe *probe, const int stage, const std::vector< int > &members, const std::vector< int > &global_to_local, const erf_auxiliary::MappedFaceFluxRate &accepted_rate, const erf_auxiliary::MappedFaceFluxRate &high_rate, const erf_auxiliary::MappedFaceFluxRate &low_rate, const erf_auxiliary::MappedFaceFluxRate &face_lambda)
 

Typedef Documentation

◆ FaceArraySet

using erf_sbm::erf_detail_SBMTransport::FaceArraySet = typedef GpuArray<Array4<const Real>, AMREX_SPACEDIM>

Function Documentation

◆ accumulate_boundary_rates()

void erf_sbm::erf_detail_SBMTransport::accumulate_boundary_rates ( const erf_auxiliary::MappedFaceFluxRate &  accepted,
const int *  components,
const int  component_count,
const amrex::Geometry &  geometry,
const MultiFab *  covered,
const int  ncomp,
double *  partial,
double &  face_terms 
)
896 {
897  const amrex::Box& domain = geometry.Domain();
898  const auto cell_size = geometry.CellSizeArray();
899  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
900  if (geometry.isPeriodic(dir)) continue;
901  const auto& rate_dir = accepted.dir(dir);
902  Real area = Real(1.0);
903  for (int other = 0; other < AMREX_SPACEDIM; ++other) {
904  if (other != dir) area *= cell_size[other];
905  }
906  for (const auto side : {amrex::Orientation::low, amrex::Orientation::high}) {
907  const int face = amrex::Orientation(dir, side);
908  const bool low = side == amrex::Orientation::low;
909  const Real outward_sign = low ? Real(-1.0) : Real(1.0);
910  const int cell_index = low ? domain.smallEnd(dir) : domain.bigEnd(dir);
911  for (amrex::MFIter mfi(rate_dir, false); mfi.isValid(); ++mfi) {
912  const amrex::Box slab =
913  physical_face_slab(mfi.validbox(), domain, dir, low);
914  if (!slab.ok()) continue;
915  face_terms += static_cast<double>(slab.numPts());
916  const auto rate = rate_dir.const_array(mfi);
917  const bool masked = covered != nullptr;
918  const auto mask = masked ? covered->const_array(mfi)
919  : Array4<const Real>{};
920  double* box_face = partial +
921  static_cast<std::ptrdiff_t>(mfi.LocalIndex() * physical_face_count + face) *
922  2 * ncomp;
923  amrex::ParallelFor(component_count,
924  [=] AMREX_GPU_DEVICE(int n) noexcept {
925  double outward = 0.0;
926  double gross = 0.0;
927  amrex::Loop(slab, [&] (int i, int j, int k) noexcept {
928  Real open = Real(1.0);
929  if (masked) {
930  amrex::IntVect cell(AMREX_D_DECL(i, j, k));
931  cell[dir] = cell_index;
932  open = Real(1.0) - mask(cell, 0);
933  }
934  const Real transfer =
935  outward_sign * area * rate(i, j, k, n) * open;
936  outward += static_cast<double>(transfer);
937  gross += static_cast<double>(amrex::Math::abs(transfer));
938  });
939  box_face[2 * components[n]] = outward;
940  box_face[2 * components[n] + 1] = gross;
941  });
942  }
943  }
944  }
945 }
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::MultiFab & dir(const int direction)
Definition: ERF_AuxiliaryMappedTransport.H:46
@ open
Definition: ERF_IndexDefines.H:324
amrex::Box physical_face_slab(const amrex::Box &face_valid, const amrex::Box &domain, const int dir, const bool low)
Definition: ERF_SBMTransport.cpp:259
constexpr int physical_face_count
Definition: ERF_SBMPhysicalBoundary.H:19

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ add_high_order_mixing()

void erf_sbm::erf_detail_SBMTransport::add_high_order_mixing ( erf_auxiliary::MappedFaceFluxRate &  high,
erf_auxiliary::MappedFaceFluxRate &  scratch,
const ParticleMixingConfig &  config,
const SBMStageMixingInputs &  inputs,
const amrex::BCRec *  bc,
const erf_auxiliary::MappedDiffusionBoundary &  boundary,
const amrex::Geometry &  geometry,
const MultiFab &  input_intensive,
const MultiFab &  input_conserved,
const std::vector< int > &  components 
)
303 {
305  std::string diagnostic;
306  if (!particle_mixing_coefficients(config, coefficients, diagnostic)) {
307  amrex::Abort("SBM high-order particle mixing: " + diagnostic);
308  }
309  const auto& metrics = inputs.metrics;
310  const bool stretched = metrics.mesh == erf_auxiliary::DiffusionMesh::StretchedDz;
311  const amrex::Box& domain = geometry.Domain();
312  const auto dx_inv = geometry.InvCellSizeArray();
313  const int ncomp = static_cast<int>(components.size());
314  const auto& h = coefficients.horizontal;
315  const auto& v = coefficients.vertical;
316  // The native builder takes one coefficient set for every face, so
317  // distinct horizontal and vertical sets take one pass each.
318  const bool one_pass = h.molecular_coeff == v.molecular_coeff &&
319  h.eddy_h_comp == v.eddy_h_comp &&
320  h.eddy_v_comp == v.eddy_v_comp;
321  struct Pass {
322  ScalarDiffusionCoefficients coefficients;
323  std::array<bool, AMREX_SPACEDIM> keep;
324  };
325  std::vector<Pass> passes;
326  if (one_pass) {
327  passes.push_back({h, {true, true, true}});
328  } else {
329  passes.push_back({v, {false, false, true}});
330  passes.push_back({h, {true, true, false}});
331  }
332  for (const auto& pass : passes) {
334  policy.coefficients = pass.coefficients;
335  policy.coefficient_mode = coefficients.mode;
336  // Untiled: the mapped transfers below rescale the face fluxes in place.
337  for (amrex::MFIter mfi(input_intensive, false); mfi.isValid(); ++mfi) {
338  const amrex::Box bx = mfi.validbox();
339  const auto xflux = scratch.dir(0).array(mfi);
340  const auto yflux = scratch.dir(1).array(mfi);
341  const auto zflux = scratch.dir(2).array(mfi);
342  const auto mf_ux = metrics.mf_ux->const_array(mfi);
343  const auto mf_uy = metrics.mf_uy->const_array(mfi);
344  const auto mf_vx = metrics.mf_vx->const_array(mfi);
345  const auto mf_vy = metrics.mf_vy->const_array(mfi);
346  const auto mf_mx = metrics.mf_mx->const_array(mfi);
347  const auto mf_my = metrics.mf_my->const_array(mfi);
348  for (int local = 0; local < ncomp; ++local) {
350  field.scalar = input_intensive.const_array(mfi);
351  field.scalar_comp = components[static_cast<std::size_t>(local)];
352  field.density = input_conserved.const_array(mfi);
353  field.rho_comp = Rho_comp;
354  field.mu_turb = inputs.eddy_diffusivity != nullptr
355  ? inputs.eddy_diffusivity->const_array(mfi)
356  : amrex::Array4<const Real>{};
357  field.xflux = xflux;
358  field.yflux = yflux;
359  field.zflux = zflux;
360  field.flux_comp = local;
361  if (stretched) {
363  bx, domain, field, policy, dx_inv[0], dx_inv[1],
364  metrics.stretched_dz, domain.smallEnd(2), domain.bigEnd(2),
365  amrex::Array4<const Real>{}, amrex::Array4<const Real>{},
366  mf_ux, mf_uy, mf_vx, mf_vy, bc, 0);
368  bx, xflux, local, yflux, local, zflux, local,
369  xflux, local, yflux, local, zflux, local,
370  metrics.ax->const_array(mfi), metrics.ay->const_array(mfi),
371  mf_mx, mf_my);
372  } else {
374  bx, domain, field, policy, dx_inv,
375  amrex::Array4<const Real>{}, amrex::Array4<const Real>{},
376  mf_ux, mf_uy, mf_vx, mf_vy, bc, 0);
378  bx, xflux, local, yflux, local, zflux, local,
379  xflux, local, yflux, local, zflux, local, mf_mx, mf_my);
380  }
381  }
382  }
383  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
384  if (!pass.keep[static_cast<std::size_t>(dir)]) { continue; }
385  const int lo = domain.smallEnd(dir);
386  const int hi = domain.bigEnd(dir);
387  const bool periodic = geometry.isPeriodic(dir);
388  const auto kind_lo = boundary.kind[static_cast<std::size_t>(dir)];
389  const auto kind_hi = boundary.kind[static_cast<std::size_t>(dir + AMREX_SPACEDIM)];
390  const MultiFab* carrier_field = boundary.carrier[static_cast<std::size_t>(dir)];
391  for (amrex::MFIter mfi(high.dir(dir), amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
392  const amrex::Box bx = mfi.tilebox();
393  const auto out = high.dir(dir).array(mfi);
394  const auto add = scratch.dir(dir).const_array(mfi);
395  const auto carrier = carrier_field != nullptr ? carrier_field->const_array(mfi)
396  : amrex::Array4<const Real>{};
397  amrex::ParallelFor(bx, ncomp,
398  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
399  const int index = dir == 0 ? i : (dir == 1 ? j : k);
400  const bool open =
401  periodic || (index != lo && index != hi + 1) ||
402  erf_auxiliary::DiffusionDomainFaceIsOpen(index == lo, kind_lo,
403  kind_hi, carrier, i, j, k);
404  if (open) {
405  out(i, j, k, n) += add(i, j, k, n);
406  }
407  });
408  }
409  if (!high.dir(dir).is_finite(0, ncomp, 0)) {
410  amrex::Abort("SBM high-order particle mixing produced a nonfinite "
411  "rate; check the stage-input density and eddy diffusivity");
412  }
413  }
414  }
415 }
#define Rho_comp
Definition: ERF_IndexDefines.H:61
const auto config
Definition: ERF_InitCustomPert_CloudChamber.H:38
void BuildScalarDiffusionFluxes_N(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:924
void BuildScalarDiffusionFluxes_S(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz, const int klo, const int khi, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:1084
void BuildScalarDiffusionMappedTransfers_S(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &raw_x, const int raw_x_comp, const amrex::Array4< const amrex::Real > &raw_y, const int raw_y_comp, const amrex::Array4< const amrex::Real > &raw_z, const int raw_z_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
Definition: ERF_ScalarDiffusion.H:1378
void BuildScalarDiffusionMappedTransfers_N(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &raw_x, const int raw_x_comp, const amrex::Array4< const amrex::Real > &raw_y, const int raw_y_comp, const amrex::Array4< const amrex::Real > &raw_z, const int raw_z_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
Definition: ERF_ScalarDiffusion.H:1332
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool DiffusionDomainFaceIsOpen(const bool low_face, const DiffusionFaceKind kind_lo, const DiffusionFaceKind kind_hi, const amrex::Array4< const amrex::Real > &carrier, const int i, const int j, const int k) noexcept
Definition: ERF_AuxiliaryDiffusionFace.H:39
bool particle_mixing_coefficients(const ParticleMixingConfig &config, erf_auxiliary::MappedDiffusionCoefficients &coefficients, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:247
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182
Definition: ERF_ScalarDiffusion.H:24
amrex::Real molecular_coeff
Definition: ERF_ScalarDiffusion.H:25
Definition: ERF_ScalarDiffusion.H:34
int rho_comp
Definition: ERF_ScalarDiffusion.H:38
amrex::Array4< amrex::Real > xflux
Definition: ERF_ScalarDiffusion.H:40
amrex::Array4< const amrex::Real > scalar
Definition: ERF_ScalarDiffusion.H:35
amrex::Array4< amrex::Real > yflux
Definition: ERF_ScalarDiffusion.H:41
int flux_comp
Definition: ERF_ScalarDiffusion.H:43
amrex::Array4< const amrex::Real > density
Definition: ERF_ScalarDiffusion.H:37
int scalar_comp
Definition: ERF_ScalarDiffusion.H:36
amrex::Array4< amrex::Real > zflux
Definition: ERF_ScalarDiffusion.H:42
amrex::Array4< const amrex::Real > mu_turb
Definition: ERF_ScalarDiffusion.H:39
Definition: ERF_ScalarDiffusion.H:93
ScalarDiffusionCoefficientMode coefficient_mode
Definition: ERF_ScalarDiffusion.H:95
ScalarDiffusionCoefficients coefficients
Definition: ERF_ScalarDiffusion.H:94
std::array< DiffusionFaceKind, 2 *AMREX_SPACEDIM > kind
Definition: ERF_AuxiliaryDiffusion.H:103
std::array< const amrex::MultiFab *, AMREX_SPACEDIM > carrier
Definition: ERF_AuxiliaryDiffusion.H:104
Definition: ERF_AuxiliaryDiffusion.H:63
ScalarDiffusionCoefficients vertical
Definition: ERF_AuxiliaryDiffusion.H:65
ScalarDiffusionCoefficientMode mode
Definition: ERF_AuxiliaryDiffusion.H:66
ScalarDiffusionCoefficients horizontal
Definition: ERF_AuxiliaryDiffusion.H:64

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ add_low_order_mixing()

void erf_sbm::erf_detail_SBMTransport::add_low_order_mixing ( erf_auxiliary::MappedFaceFluxRate &  low,
erf_auxiliary::MappedFaceFluxRate &  scratch,
const erf_auxiliary::MappedFaceTransmissibility &  transmissibility,
const amrex::Geometry &  geometry,
const MultiFab &  base_intensive,
const std::vector< int > &  components 
)
278 {
279  std::string diagnostic;
280  if (!erf_auxiliary::BuildLowOrderDiffusionRate(scratch, transmissibility, geometry,
281  base_intensive, components, diagnostic)) {
282  amrex::Abort("SBM low-order particle mixing: " + diagnostic);
283  }
284  const int ncomp = static_cast<int>(components.size());
285  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
286  MultiFab::Add(low.dir(dir), scratch.dir(dir), 0, 0, ncomp, 0);
287  }
288 }
bool BuildLowOrderDiffusionRate(MappedFaceFluxRate &rate, const MappedFaceTransmissibility &transmissibility, const amrex::Geometry &geom, const MultiFab &intensive, const std::vector< int > &components, std::string &diagnostic)
Definition: ERF_AuxiliaryDiffusion.cpp:462

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ add_matched_terrain_mixing()

void erf_sbm::erf_detail_SBMTransport::add_matched_terrain_mixing ( erf_auxiliary::MappedFaceFluxRate &  low,
erf_auxiliary::MappedFaceFluxRate &  high,
const erf_auxiliary::MappedFaceFluxRate &  diffusive,
const erf_auxiliary::MappedFaceTransmissibility &  transmissibility,
const amrex::Geometry &  geometry,
const MultiFab &  base_intensive,
const int *  chunk_components,
const MatchingGroup *  groups,
const int  group_count,
const int *  members,
const ConstraintDescriptor *  coordinates,
const ConstraintTerm *  terms,
const bool  match 
)
723 {
724  const amrex::Box& domain = geometry.Domain();
725  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
726  const int lo = domain.smallEnd(dir);
727  const int hi = domain.bigEnd(dir);
728  const bool periodic = geometry.isPeriodic(dir);
729  const amrex::IntVect shift = amrex::IntVect::TheDimensionVector(dir);
730  for (amrex::MFIter mfi(low.dir(dir), amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
731  const auto low_out = low.dir(dir).array(mfi);
732  const auto high_out = high.dir(dir).array(mfi);
733  const auto d = diffusive.dir(dir).const_array(mfi);
734  const auto t = transmissibility.dir(dir).const_array(mfi);
735  const auto z = base_intensive.const_array(mfi);
736  amrex::ParallelFor(mfi.tilebox(), [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
737  const amrex::IntVect cell(AMREX_D_DECL(i, j, k));
738  const amrex::IntVect left = cell - shift;
739  const Real tf = t(i, j, k, 0);
740  // A closed domain face reads no ghost; an open one has T > 0.
741  const bool exchange = periodic || (cell[dir] != lo && cell[dir] != hi + 1) ||
742  tf != Real(0.0);
743  for (int g = 0; g < group_count; ++g) {
744  const MatchingGroup group = groups[g];
745  Real theta = Real(1.0);
746  if (match && exchange) {
747  bool finite = true;
748  for (int c = 0; c < group.coordinates_count; ++c) {
749  const auto& form = coordinates[group.coordinates_begin + c];
750  Real nominal_rate = Real(0.0);
751  Real native_rate = Real(0.0);
752  for (int s = 0; s < form.term_count; ++s) {
753  const auto& term = terms[form.term_offset + s];
754  const int global = chunk_components[term.component];
755  const Real nominal = -tf * (z(cell, global) - z(left, global));
756  nominal_rate = std::fma(term.coefficient, nominal, nominal_rate);
757  native_rate = std::fma(term.coefficient,
758  d(i, j, k, term.component), native_rate);
759  }
760  const Real fraction =
761  matched_diffusion_fraction(native_rate, nominal_rate);
762  if (amrex::Math::isnan(fraction)) { finite = false; }
763  theta = amrex::min(theta, fraction);
764  }
765  if (!finite) { theta = std::numeric_limits<Real>::quiet_NaN(); }
766  }
767  for (int m = 0; m < group.members_count; ++m) {
768  const int local = members[group.members_begin + m];
769  const int global = chunk_components[local];
770  const Real nominal = exchange
771  ? -tf * (z(cell, global) - z(left, global)) : Real(0.0);
772  low_out(i, j, k, local) += theta * nominal;
773  high_out(i, j, k, local) += d(i, j, k, local);
774  }
775  }
776  });
777  }
778  if (!low.dir(dir).is_finite(0, low.nComp(), 0)) {
779  amrex::Abort("SBM terrain particle mixing produced a nonfinite low-order rate; "
780  "check the limiter-trial base, including the ghost cells read "
781  "across periodic and open faces");
782  }
783  }
784 }
int nComp() const noexcept
Definition: ERF_AuxiliaryMappedTransport.H:44
@ theta
Definition: ERF_Kessler.H:26
@ t
Definition: ERF_WSM6.H:295
bool finite(amrex::Real value) noexcept
Definition: ERF_CloudChamber.H:362
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real matched_diffusion_fraction(const amrex::Real high, const amrex::Real low) noexcept
Definition: ERF_SBMParticleMixing.H:170
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ apply_physical_donor_band()

void erf_sbm::erf_detail_SBMTransport::apply_physical_donor_band ( erf_auxiliary::MappedFaceFluxRate &  high,
const erf_auxiliary::MappedFaceFluxRate &  low,
const amrex::Geometry &  geometry 
)
229 {
230  const amrex::Box& domain = geometry.Domain();
231  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
232  if (geometry.isPeriodic(dir)) continue;
233  auto& high_dir = high.dir(dir);
234  const auto& low_dir = low.dir(dir);
235  const int ncomp = high_dir.nComp();
236  const std::array<std::pair<int, int>, 2> bands{
237  {{domain.smallEnd(dir), domain.smallEnd(dir) + 1},
238  {domain.bigEnd(dir), domain.bigEnd(dir) + 1}}};
239  for (amrex::MFIter mfi(high_dir, false); mfi.isValid(); ++mfi) {
240  const auto high_values = high_dir.array(mfi);
241  const auto low_values = low_dir.const_array(mfi);
242  for (const auto& band : bands) {
243  amrex::Box faces = mfi.validbox();
244  faces.setSmall(dir, std::max(faces.smallEnd(dir), band.first));
245  faces.setBig(dir, std::min(faces.bigEnd(dir), band.second));
246  if (!faces.ok()) continue;
248  faces, ncomp,
249  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
250  high_values(i, j, k, n) = low_values(i, j, k, n);
251  });
252  }
253  }
254  }
255 }

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ budget_ratio()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::budget_ratio ( const Real  margin,
const Real  adverse,
const Real  scale,
const Real  roundoff 
)
noexcept
1667 {
1668  if (!(adverse > Real(0.0))) { return Real(1.0); }
1669  return clamp_unit((margin - roundoff * scale) / adverse);
1670 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real clamp_unit(const Real value) noexcept
Definition: ERF_SBMTransport.cpp:110

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ build_intensive()

void erf_sbm::erf_detail_SBMTransport::build_intensive ( MultiFab &  intensive,
const MultiFab &  state,
const MultiFab &  conserved,
const amrex::Periodicity &  periodicity,
const char *  what 
)
121 {
122  AMREX_ALWAYS_ASSERT(intensive.nComp() == state.nComp());
123  AMREX_ALWAYS_ASSERT(conserved.nComp() > Rho_comp);
125  AMREX_ALWAYS_ASSERT(erf_auxiliary::SameCellLayout(intensive, conserved));
126  std::string diagnostic;
128  diagnostic)) {
129  amrex::Abort(std::string("SBM ") + what + " density: " + diagnostic);
130  }
131  for (amrex::MFIter mfi(intensive, amrex::TilingIfNotGPU()); mfi.isValid();
132  ++mfi) {
133  const amrex::Box bx = mfi.tilebox();
134  const auto u = state.const_array(mfi);
135  const auto rho = conserved.const_array(mfi);
136  const auto out = intensive.array(mfi);
137  const int ncomp = state.nComp();
139  bx, ncomp,
140  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
141  out(i, j, k, n) = u(i, j, k, n) / rho(i, j, k, Rho_comp);
142  });
143  }
144  intensive.FillBoundary(periodicity);
145  if (!intensive.is_finite(0, intensive.nComp(), 0)) {
146  amrex::Abort(std::string("SBM ") + what +
147  " intensive state is nonfinite");
148  }
149 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
@ rho
Definition: ERF_Kessler.H:25
bool ValidatePositiveFiniteComponent(const amrex::MultiFab &field, const int component, std::string &diagnostic)
Definition: ERF_AuxiliaryMappedTransport.cpp:291
bool SameCellLayout(const amrex::MultiFab &lhs, const amrex::MultiFab &rhs)
Definition: ERF_AuxiliaryMappedTransport.cpp:33

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ build_terrain_high_order_mixing()

void erf_sbm::erf_detail_SBMTransport::build_terrain_high_order_mixing ( erf_auxiliary::MappedFaceFluxRate &  diffusive,
MultiFab &  scalar,
std::array< MultiFab, AMREX_SPACEDIM > &  raw,
const std::array< MultiFab, 2 > &  side_open,
const ParticleMixingConfig &  config,
const SBMStageMixingInputs &  inputs,
const amrex::BCRec *  bc,
const amrex::Geometry &  geometry,
const MultiFab &  input_intensive,
const MultiFab &  input_conserved,
const std::vector< int > &  components 
)
543 {
545  std::string diagnostic;
546  if (!particle_mixing_coefficients(config, coefficients, diagnostic)) {
547  amrex::Abort("SBM terrain particle mixing: " + diagnostic);
548  }
549  const auto& metrics = inputs.metrics;
550  const amrex::Box& domain = geometry.Domain();
551  const auto dx_inv = geometry.InvCellSizeArray();
552  const int ncomp = static_cast<int>(components.size());
553  for (int local = 0; local < ncomp; ++local) {
554  MultiFab::Copy(scalar, input_intensive, components[static_cast<std::size_t>(local)],
555  local, 1, 2);
556  }
557  const int bad_columns = extend_wall_ghosts(scalar, ncomp, *inputs.z_cc, geometry);
558  if (bad_columns != 0) {
559  amrex::Abort("SBM terrain particle mixing cannot extend the stage input past a wall in " +
560  std::to_string(bad_columns) + " columns: the three cell-centre heights "
561  "nearest each wall must be finite, increase away from it, and have gaps "
562  "within a factor of 4 of the ghost cell's");
563  }
565  policy.coefficients = coefficients.horizontal;
566  policy.coefficient_mode = coefficients.mode;
567  for (amrex::MFIter mfi(scalar, false); mfi.isValid(); ++mfi) {
568  const amrex::Box bx = mfi.validbox();
569  const auto q = scalar.const_array(mfi);
570  const auto rho = input_conserved.const_array(mfi);
571  const auto mu = inputs.eddy_diffusivity != nullptr
572  ? inputs.eddy_diffusivity->const_array(mfi)
573  : Array4<const Real>{};
574  const auto z_nd = metrics.z_nd->const_array(mfi);
575  const auto z_cc = inputs.z_cc->const_array(mfi);
576  const auto mf_ux = metrics.mf_ux->const_array(mfi);
577  const auto mf_vy = metrics.mf_vy->const_array(mfi);
578  for (int local = 0; local < ncomp; ++local) {
580  field.scalar = q;
581  field.scalar_comp = local;
582  field.density = rho;
583  field.rho_comp = Rho_comp;
584  field.mu_turb = mu;
585  field.xflux = raw[0].array(mfi);
586  field.yflux = raw[1].array(mfi);
587  field.zflux = raw[2].array(mfi);
588  field.flux_comp = local;
589  // The mixing BCs use ext_dir and foextrap only, so no velocity is read.
590  BuildScalarDiffusionFluxes_T(bx, domain, field, policy, coefficients.vertical,
591  false, z_nd, z_cc, dx_inv, Array4<const Real>{},
592  Array4<const Real>{}, mf_ux, mf_vy, bc, 0);
593  }
594  for (int dir = 0; dir < 2; ++dir) {
595  if (geometry.isPeriodic(dir)) {
596  continue;
597  }
598  const auto out = raw[static_cast<std::size_t>(dir)].array(mfi);
599  const auto open = side_open[static_cast<std::size_t>(dir)].const_array(mfi);
600  const int lo = domain.smallEnd(dir);
601  const int hi = domain.bigEnd(dir);
602  for (const int face : {lo, hi + 1}) {
603  amrex::Box faces = raw[static_cast<std::size_t>(dir)][mfi].box();
604  if (face < faces.smallEnd(dir) || face > faces.bigEnd(dir)) {
605  continue;
606  }
607  faces.setRange(dir, face, 1);
608  faces.setSmall(2, std::max(faces.smallEnd(2), domain.smallEnd(2)));
609  faces.setBig(2, std::min(faces.bigEnd(2), domain.bigEnd(2)));
610  amrex::ParallelFor(faces, ncomp,
611  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
612  if (open(i, j, k, 0) == Real(0.0)) { out(i, j, k, n) = Real(0.0); }
613  });
614  }
615  }
616  for (int local = 0; local < ncomp; ++local) {
618  bx, domain, raw[0].const_array(mfi), raw[1].const_array(mfi),
619  raw[2].const_array(mfi), local, diffusive.dir(0).array(mfi), local,
620  diffusive.dir(1).array(mfi), local, diffusive.dir(2).array(mfi), local,
621  z_nd, metrics.ax->const_array(mfi), metrics.ay->const_array(mfi), dx_inv,
622  metrics.mf_mx->const_array(mfi), metrics.mf_uy->const_array(mfi),
623  metrics.mf_my->const_array(mfi), metrics.mf_vx->const_array(mfi),
624  true, true);
625  }
626  }
627  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
628  if (!diffusive.dir(dir).is_finite(0, ncomp, 0)) {
629  amrex::Abort("SBM terrain particle mixing produced a nonfinite high-order rate; "
630  "check the stage-input density, eddy diffusivity and terrain metrics");
631  }
632  }
633 }
void BuildScalarDiffusionMappedTransfers_T(const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_x, const amrex::Array4< const amrex::Real > &raw_y, const amrex::Array4< const amrex::Real > &raw_z, const int raw_flux_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_vx, const bool suppress_lower_surface_z_transfer, const bool suppress_upper_z_transfer=false)
Definition: ERF_ScalarDiffusion.H:1439
void BuildScalarDiffusionFluxes_T(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const ScalarDiffusionCoefficients &vertical_coefficients, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:1263
@ mu
Definition: ERF_AdvanceMorrison.cpp:94
@ q
Definition: ERF_WSM6.H:296
int extend_wall_ghosts(MultiFab &scalar, const int ncomp, const MultiFab &z_cc, const amrex::Geometry &geometry)
Definition: ERF_SBMTransport.cpp:426

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ canonical_reserve_face_correction()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::canonical_reserve_face_correction ( const int  mass_component,
const int  number_component,
const Real  mass_coefficient,
const Real  number_coefficient,
const FaceArraySet &  low,
const FaceArraySet &  high,
const int  i,
const int  j,
const int  k,
const int  dir,
const int  side,
const Real  tau,
const GpuArray< Real, AMREX_SPACEDIM > &  dx_inv 
)
noexcept
1687 {
1688  const int fi = i + (dir == 0 && side > 0 ? 1 : 0);
1689  const int fj = j + (dir == 1 && side > 0 ? 1 : 0);
1690  const int fk = k + (dir == 2 && side > 0 ? 1 : 0);
1691  const Real dmass = high[dir](fi, fj, fk, mass_component) -
1692  low[dir](fi, fj, fk, mass_component);
1693  const Real dnumber = high[dir](fi, fj, fk, number_component) -
1694  low[dir](fi, fj, fk, number_component);
1695  const Real g_flux = std::fma(mass_coefficient, dmass,
1696  number_coefficient * dnumber);
1697  const Real outward_sign = side > 0 ? Real(1.0) : Real(-1.0);
1698  return -outward_sign * tau * dx_inv[dir] * g_flux;
1699 }
@ fi
Definition: ERF_AdvanceMorrison.cpp:109

Referenced by erf_sbm::SBMTransport::advance_stage().

Here is the caller graph for this function:

◆ check_physical_face_carriers()

void erf_sbm::erf_detail_SBMTransport::check_physical_face_carriers ( const std::array< const MultiFab *, AMREX_SPACEDIM > &  carrier,
const amrex::Geometry &  geometry,
const SBMPhysicalBoundaryConfig &  boundaries,
const int  level,
const int  stage 
)
830 {
831  const amrex::Box& domain = geometry.Domain();
832  std::array<int, physical_face_count> violation{};
833  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
834  if (geometry.isPeriodic(dir)) continue;
835  for (const auto side : {amrex::Orientation::low, amrex::Orientation::high}) {
836  const int face = amrex::Orientation(dir, side);
837  const bool low = side == amrex::Orientation::low;
838  const AdvectionFaceKind kind = boundaries.kind[static_cast<std::size_t>(face)];
839  const Real outward_sign = low ? Real(-1.0) : Real(1.0);
840  amrex::ReduceOps<amrex::ReduceOpMax> reduce_op;
841  amrex::ReduceData<int> reduce_data(reduce_op);
842  using ReduceTuple = typename decltype(reduce_data)::Type;
843  for (amrex::MFIter mfi(*carrier[static_cast<std::size_t>(dir)], false);
844  mfi.isValid(); ++mfi) {
845  const amrex::Box slab =
846  physical_face_slab(mfi.validbox(), domain, dir, low);
847  if (!slab.ok()) continue;
848  const auto flux = carrier[static_cast<std::size_t>(dir)]->const_array(mfi);
849  reduce_op.eval(slab, reduce_data,
850  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept -> ReduceTuple {
851  const Real outward = outward_sign * flux(i, j, k, 0);
852  if (kind == AdvectionFaceKind::ImpermeableWall) {
853  return {outward != Real(0.0) ? 1 : 0};
854  }
855  AdvectionFacePolicyInput input;
856  input.kind = kind;
857  input.outward_carrier = outward;
858  input.explicit_spectral_state_present = true;
859  input.explicit_spectral_group_complete = true;
860  return {make_advection_face_policy(input).accepted() ? 0 : 2};
861  });
862  }
863  // A rank with no slab on this face reduces to the lowest int.
864  violation[static_cast<std::size_t>(face)] =
865  std::max(0, amrex::get<0>(reduce_data.value(reduce_op)));
866  }
867  }
868  amrex::ParallelAllReduce::Max(violation.data(), physical_face_count,
869  amrex::ParallelContext::CommunicatorSub());
870  for (int face = 0; face < physical_face_count; ++face) {
871  const int code = violation[static_cast<std::size_t>(face)];
872  if (code == 0) continue;
873  std::ostringstream message;
874  message << (code == 1 ? "SBM impermeable wall " : "SBM advective outflow ")
875  << face_name(face)
876  << (code == 1 ? " has a nonzero dry-air carrier"
877  : " received an inward dry-air carrier")
878  << " (level=" << level << ", stage=" << stage << ')';
879  amrex::Abort(message.str());
880  }
881 }
std::string message
Definition: ERF_InputPreflight.cpp:25
std::string code
Definition: ERF_InputPreflight.cpp:25
std::string input
Definition: ERF_InputPreflight.cpp:29
constexpr AMREX_GPU_HOST_DEVICE AdvectionFacePolicy make_advection_face_policy(const AdvectionFacePolicyInput &input) noexcept
Definition: ERF_SBMAdvectionBoundary.H:60
const char * face_name(const int face) noexcept
Definition: ERF_SBMPhysicalBoundary.cpp:70
AdvectionFaceKind
Definition: ERF_SBMAdvectionBoundary.H:10
constexpr AMREX_GPU_HOST_DEVICE bool accepted() const noexcept
Definition: ERF_SBMAdvectionBoundary.H:45

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ clamp_unit()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::clamp_unit ( const Real  value)
noexcept
111 {
112  return amrex::max(Real(0.0), amrex::min(Real(1.0), value));
113 }

Referenced by erf_sbm::SBMTransport::advance_stage(), and budget_ratio().

Here is the caller graph for this function:

◆ clear_outside_physical_domain()

void erf_sbm::erf_detail_SBMTransport::clear_outside_physical_domain ( MultiFab &  mask,
const int  component,
const amrex::Geometry &  geometry 
)
202 {
203  const amrex::Box& domain = geometry.Domain();
204  for (amrex::MFIter mfi(mask, false); mfi.isValid(); ++mfi) {
205  const auto values = mask.array(mfi);
206  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
207  if (geometry.isPeriodic(dir)) continue;
208  amrex::Box below = mfi.fabbox();
209  below.setBig(dir, domain.smallEnd(dir) - 1);
210  amrex::Box above = mfi.fabbox();
211  above.setSmall(dir, domain.bigEnd(dir) + 1);
212  for (const amrex::Box& ghost : {below, above}) {
213  if (!ghost.ok()) continue;
215  ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
216  values(i, j, k, component) = Real(0.0);
217  });
218  }
219  }
220  }
221 }

Referenced by fill_coarse_parent_ghosts().

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

◆ coarse_stage_endpoints_valid()

bool erf_sbm::erf_detail_SBMTransport::coarse_stage_endpoints_valid ( const MultiFab &  coarse_stage,
const int  component_count,
const int  new_offset,
const int  rho_old_local,
const amrex::Box &  coarse_region 
)
995 {
996  amrex::ReduceOps<amrex::ReduceOpMin> reduce_op;
997  amrex::ReduceData<int> reduce_data(reduce_op);
998  using ReduceTuple = typename decltype(reduce_data)::Type;
999  for (amrex::MFIter mfi(coarse_stage, false); mfi.isValid(); ++mfi) {
1000  const amrex::Box staged = mfi.fabbox() & coarse_region;
1001  if (!staged.ok()) continue;
1002  const auto values = coarse_stage.const_array(mfi);
1003  reduce_op.eval(staged, reduce_data,
1004  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept -> ReduceTuple {
1005  const Real rho_old = values(i, j, k, rho_old_local);
1006  const Real rho_new = values(i, j, k, rho_old_local + 1);
1007  bool ok = amrex::Math::isfinite(rho_old) &&
1008  amrex::Math::isfinite(rho_new) &&
1009  rho_old > Real(0.0) && rho_new > Real(0.0);
1010  for (int n = 0; n < component_count && ok; ++n) {
1011  ok = amrex::Math::isfinite(values(i, j, k, n)) &&
1012  amrex::Math::isfinite(values(i, j, k, new_offset + n));
1013  }
1014  return {ok ? 1 : 0};
1015  });
1016  }
1017  int all_valid = amrex::get<0>(reduce_data.value(reduce_op));
1018  amrex::ParallelDescriptor::ReduceIntMin(all_valid);
1019  return all_valid != 0;
1020 }

Referenced by fill_coarse_parent_ghosts().

Here is the caller graph for this function:

◆ coarse_stage_theta()

bool erf_sbm::erf_detail_SBMTransport::coarse_stage_theta ( const double  requested_time,
const double  coarse_old_time,
const double  coarse_new_time,
const double  dt_min,
double &  theta,
std::string &  diagnostic 
)
954 {
955  diagnostic.clear();
956  theta = 0.0;
957  if (!std::isfinite(requested_time) ||
958  !std::isfinite(coarse_old_time) ||
959  !std::isfinite(coarse_new_time) ||
960  !std::isfinite(dt_min) || !(dt_min > 0.0) ||
961  !(coarse_new_time > coarse_old_time)) {
962  diagnostic = "coarse SBM stage bracket has invalid times or timestep";
963  return false;
964  }
965  if (semantic_time_matches(requested_time, coarse_old_time, dt_min)) {
966  theta = 0.0;
967  return true;
968  }
969  if (semantic_time_matches(requested_time, coarse_new_time, dt_min)) {
970  theta = 1.0;
971  return true;
972  }
973  if (!(requested_time > coarse_old_time &&
974  requested_time < coarse_new_time)) {
975  diagnostic = "fine SBM stage time is outside the accepted coarse bracket";
976  return false;
977  }
978  theta = (requested_time - coarse_old_time) /
979  (coarse_new_time - coarse_old_time);
980  if (!std::isfinite(theta) || !(theta > 0.0 && theta < 1.0)) {
981  diagnostic = "fine SBM stage interpolation fraction is invalid";
982  return false;
983  }
984  return true;
985 }
bool semantic_time_matches(const double lhs, const double rhs, const double dt_min) noexcept
Definition: ERF_SBMAMRTime.H:14

Referenced by fill_coarse_parent_ghosts().

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

◆ consider_donor_ratio()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_sbm::erf_detail_SBMTransport::consider_donor_ratio ( const Array4< const Real > &  field,
const int  i,
const int  j,
const int  k,
const LocalPropertySupport &  support,
Real &  lower,
Real &  upper,
int &  found 
)
noexcept
1737 {
1738  const Real carrier = field(i, j, k, support.carrier_global);
1739  const Real property = field(i, j, k, support.property_global);
1740  if (!amrex::Math::isfinite(carrier) || !amrex::Math::isfinite(property) ||
1741  carrier < Real(0.0) || property < Real(0.0)) {
1742  return;
1743  }
1744  if (carrier == Real(0.0)) {
1745  return;
1746  }
1747  const Real ratio = property / carrier;
1748  if (!amrex::Math::isfinite(ratio) || ratio < Real(0.0)) {
1749  return;
1750  }
1751  lower = found == 0 ? ratio : amrex::min(lower, ratio);
1752  upper = found == 0 ? ratio : amrex::max(upper, ratio);
1753  found = 1;
1754 }

Referenced by include_neighbourhood().

Here is the caller graph for this function:

◆ extend_wall_ghosts()

int erf_sbm::erf_detail_SBMTransport::extend_wall_ghosts ( MultiFab &  scalar,
const int  ncomp,
const MultiFab &  z_cc,
const amrex::Geometry &  geometry 
)
428 {
429  const amrex::Box& domain = geometry.Domain();
430  amrex::ReduceOps<amrex::ReduceOpSum> reduce_op;
431  amrex::ReduceData<int> reduce_data(reduce_op);
432  using ReduceTuple = typename decltype(reduce_data)::Type;
433  for (amrex::MFIter mfi(scalar, false); mfi.isValid(); ++mfi) {
434  amrex::Box columns = mfi.fabbox();
435  for (int dir = 0; dir < 2; ++dir) {
436  if (geometry.isPeriodic(dir)) {
437  continue;
438  }
439  columns.setSmall(dir, std::max(columns.smallEnd(dir), domain.smallEnd(dir)));
440  columns.setBig(dir, std::min(columns.bigEnd(dir), domain.bigEnd(dir)));
441  }
442  const auto q = scalar.array(mfi);
443  const auto z = z_cc.const_array(mfi);
444  for (const bool low : {true, false}) {
445  const int ghost = low ? domain.smallEnd(2) - 1 : domain.bigEnd(2) + 1;
446  if (ghost < columns.smallEnd(2) || ghost > columns.bigEnd(2)) {
447  continue;
448  }
449  const int step = low ? 1 : -1;
450  const int k0 = ghost + step;
451  const int k1 = k0 + step;
452  const int k2 = k1 + step;
453  amrex::Box layer = columns;
454  layer.setRange(2, ghost, 1);
455  reduce_op.eval(layer, reduce_data,
456  [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept -> ReduceTuple {
457  const Real zg = z(i, j, ghost);
458  const Real z0 = z(i, j, k0);
459  const Real z1 = z(i, j, k1);
460  const Real z2 = z(i, j, k2);
461  const Real sign = Real(step);
462  const Real g0 = sign * (z0 - zg);
463  const Real g1 = sign * (z1 - z0);
464  const Real g2 = sign * (z2 - z1);
465  const Real gap_min = amrex::min(g0, amrex::min(g1, g2));
466  const Real gap_max = amrex::max(g0, amrex::max(g1, g2));
467  if (!(amrex::Math::isfinite(zg) && amrex::Math::isfinite(z2) &&
468  gap_min > Real(0.0) && amrex::Math::isfinite(gap_max) &&
469  gap_max <= Real(4.0) * gap_min)) {
470  return {1};
471  }
472  const Real w0 = (zg - z1) * (zg - z2) / ((z0 - z1) * (z0 - z2));
473  const Real w1 = (zg - z0) * (zg - z2) / ((z1 - z0) * (z1 - z2));
474  const Real w2 = (zg - z0) * (zg - z1) / ((z2 - z0) * (z2 - z1));
475  for (int n = 0; n < ncomp; ++n) {
476  q(i, j, ghost, n) =
477  w0 * q(i, j, k0, n) + w1 * q(i, j, k1, n) + w2 * q(i, j, k2, n);
478  }
479  return {0};
480  });
481  }
482  }
483  int count = amrex::get<0>(reduce_data.value(reduce_op));
484  amrex::ParallelAllReduce::Sum(count, amrex::ParallelContext::CommunicatorSub());
485  return count;
486 }
int count
Definition: ERF_ActuatorSpreading.cpp:264
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
real(c_double), private k1
Definition: ERF_module_mp_morr_two_moment.F90:213

Referenced by build_terrain_high_order_mixing().

Here is the caller graph for this function:

◆ face_correction()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::face_correction ( const erf_sbm::ConstraintDescriptor &  descriptor,
const erf_sbm::ConstraintTerm *  terms,
const FaceArraySet &  low,
const FaceArraySet &  high,
const int  i,
const int  j,
const int  k,
const int  dir,
const int  side,
const Real  tau,
const GpuArray< Real, AMREX_SPACEDIM > &  dx_inv 
)
noexcept
1587 {
1588  const int fi = i + (dir == 0 && side > 0 ? 1 : 0);
1589  const int fj = j + (dir == 1 && side > 0 ? 1 : 0);
1590  const int fk = k + (dir == 2 && side > 0 ? 1 : 0);
1591  Real g_flux = Real(0.0);
1592  for (int t = 0; t < descriptor.term_count; ++t) {
1593  const auto& term = terms[descriptor.term_offset + t];
1594  g_flux = std::fma(term.coefficient,
1595  high[dir](fi, fj, fk, term.component) -
1596  low[dir](fi, fj, fk, term.component),
1597  g_flux);
1598  }
1599  const Real outward_sign = side > 0 ? Real(1.0) : Real(-1.0);
1600  return -outward_sign * tau * dx_inv[dir] * g_flux;
1601 }
DiagnosticDescriptor descriptor
Definition: ERF_Plotfile2DCatalog.cpp:142

Referenced by erf_sbm::SBMTransport::advance_stage().

Here is the caller graph for this function:

◆ face_gross()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::face_gross ( const erf_sbm::ConstraintDescriptor &  descriptor,
const erf_sbm::ConstraintTerm *  terms,
const FaceArraySet &  low,
const FaceArraySet &  high,
const int  i,
const int  j,
const int  k,
const int  dir,
const int  side,
const Real  tau,
const GpuArray< Real, AMREX_SPACEDIM > &  dx_inv 
)
noexcept
1617 {
1618  const int fi = i + (dir == 0 && side > 0 ? 1 : 0);
1619  const int fj = j + (dir == 1 && side > 0 ? 1 : 0);
1620  const int fk = k + (dir == 2 && side > 0 ? 1 : 0);
1621  Real gross = Real(0.0);
1622  for (int t = 0; t < descriptor.term_count; ++t) {
1623  const auto& term = terms[descriptor.term_offset + t];
1624  const Real l = low[dir](fi, fj, fk, term.component);
1625  const Real h = high[dir](fi, fj, fk, term.component);
1626  gross += amrex::Math::abs(term.coefficient) *
1627  (amrex::Math::abs(l) + amrex::Math::abs(h - l));
1628  }
1629  return tau * dx_inv[dir] * gross;
1630 }

Referenced by erf_sbm::SBMTransport::advance_stage().

Here is the caller graph for this function:

◆ fill_coarse_parent_ghosts()

void erf_sbm::erf_detail_SBMTransport::fill_coarse_parent_ghosts ( MultiFab &  destination,
MultiFab &  missing_fine_ghosts,
const MultiFab &  coarse_old_spectrum,
const MultiFab &  coarse_new_spectrum,
const MultiFab &  fine_source_state,
const MultiFab &  fine_source_conserved,
const SBMAMRStageParent &  parent,
const amrex::Geometry &  fine_geometry,
const std::vector< ConstraintClosureChunk > &  chunks,
const int  max_chunk_components,
const double  requested_time,
const double  coarse_old_spectrum_time,
const double  coarse_new_spectrum_time,
const int  level,
const int  stage,
const char *  role,
MultiFab &  coarse_pack,
MultiFab &  coarse_stage,
const SBMAMRStageGhostProbe *  probe = nullptr,
std::array< bool, 2 > *  split_values_checked = nullptr 
)
1043 {
1044  using ProfileClock = std::chrono::steady_clock;
1045  const bool profile_parent_fill = parent.profile_parent_fill;
1046  const auto fill_start = profile_parent_fill ? ProfileClock::now()
1047  : ProfileClock::time_point{};
1048  double parallel_copy_seconds = 0.0;
1049  int parallel_copy_calls = 0;
1050  const int current_role = std::strcmp(role, "input") == 0 ? 0
1051  : (std::strcmp(role, "limiter-base") == 0 ? 1 : 2);
1052  const bool probe_this_role = probe == nullptr ||
1053  probe->requested_role == current_role;
1054  bool inject_rank_local_store_fault = false;
1055 #ifdef ERF_SBM_AMR_QUALIFICATION
1056  // Rank 0 skips component 0's actual store at its first coarse-only ghost
1057  // while keeping the independent wrote_components tally.
1058  inject_rank_local_store_fault =
1059  parent.inject_parent_store_fault && level == 1 && stage == 0 &&
1060  current_role == 0 && amrex::ParallelDescriptor::MyProc() == 0;
1061 #endif
1062  const double coarse_dt = parent.new_time - parent.old_time;
1063  const double dt_min = std::min(parent.fine_step_dt, coarse_dt);
1064  double theta = 0.0;
1065  std::string diagnostic;
1066  if (!coarse_stage_theta(requested_time, parent.old_time, parent.new_time,
1067  dt_min, theta, diagnostic)) {
1068  amrex::Abort("SBM coarse/fine stage interpolation: " + diagnostic);
1069  }
1070  if (!semantic_time_matches(coarse_old_spectrum_time, parent.old_time,
1071  dt_min) ||
1072  !semantic_time_matches(coarse_new_spectrum_time, parent.new_time,
1073  dt_min)) {
1074  amrex::Abort("SBM coarse spectrum and host density endpoints do not "
1075  "share semantic times");
1076  }
1077  if (parent.conserved_old == nullptr || parent.conserved_new == nullptr ||
1078  !parent.refinement_ratio.allGT(0) ||
1079  coarse_old_spectrum.nComp() != destination.nComp() ||
1080  coarse_new_spectrum.nComp() != destination.nComp() ||
1081  parent.conserved_old->nComp() <= Rho_comp ||
1082  parent.conserved_new->nComp() <= Rho_comp ||
1083  !erf_auxiliary::SameCellLayout(coarse_old_spectrum,
1084  coarse_new_spectrum) ||
1085  !erf_auxiliary::SameCellLayout(coarse_old_spectrum,
1086  *parent.conserved_old) ||
1087  !erf_auxiliary::SameCellLayout(coarse_old_spectrum,
1088  *parent.conserved_new) ||
1089  !erf_auxiliary::SameCellLayout(destination, missing_fine_ghosts) ||
1090  missing_fine_ghosts.nComp() < 3 ||
1091  !destination.nGrowVect().allGE(amrex::IntVect(2)) ||
1092  !missing_fine_ghosts.nGrowVect().allGE(amrex::IntVect(2))) {
1093  amrex::Abort("SBM coarse/fine stage interpolation received an "
1094  "incompatible layout");
1095  }
1096 
1097  amrex::BoxArray coarse_on_fine_ba = destination.boxArray();
1098  coarse_on_fine_ba.coarsen(parent.refinement_ratio);
1099  const amrex::IntVect coarse_ghosts(2);
1100  if (coarse_stage.nComp() != 2 * max_chunk_components + 2 ||
1101  coarse_stage.boxArray() != coarse_on_fine_ba ||
1102  coarse_stage.DistributionMap() != destination.DistributionMap() ||
1103  coarse_stage.nGrowVect() != coarse_ghosts) {
1104  coarse_stage.define(coarse_on_fine_ba, destination.DistributionMap(),
1105  2 * max_chunk_components + 2, coarse_ghosts);
1106  }
1107  coarse_stage.setVal(std::numeric_limits<Real>::quiet_NaN());
1108  const bool componentwise_parent_fill = parent.componentwise_parent_fill;
1109  if (!componentwise_parent_fill) {
1110  if (coarse_pack.nComp() != 2 * max_chunk_components + 2 ||
1111  coarse_pack.boxArray() != coarse_old_spectrum.boxArray() ||
1112  coarse_pack.DistributionMap() !=
1113  coarse_old_spectrum.DistributionMap()) {
1114  coarse_pack.define(coarse_old_spectrum.boxArray(),
1115  coarse_old_spectrum.DistributionMap(),
1116  2 * max_chunk_components + 2, 0);
1117  coarse_pack.setVal(std::numeric_limits<Real>::quiet_NaN());
1118  }
1119  }
1120 
1121  amrex::Box coarse_domain = fine_geometry.Domain();
1122  coarse_domain.coarsen(parent.refinement_ratio);
1123  // Wrap only periodic directions: a parent beyond a physical face does not exist.
1124  amrex::IntVect coarse_period(0);
1125  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
1126  if (fine_geometry.isPeriodic(dir)) coarse_period[dir] = coarse_domain.length(dir);
1127  }
1128  const amrex::Periodicity coarse_periodicity(coarse_period);
1129  amrex::Box coarse_region = coarse_domain;
1130  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
1131  if (fine_geometry.isPeriodic(dir)) coarse_region.grow(dir, coarse_ghosts[dir]);
1132  }
1133  const int rho_old_local = 2 * max_chunk_components;
1134  const int rho_new_local = rho_old_local + 1;
1135  auto timed_parallel_copy = [&] (auto&& operation) {
1136  if (profile_parent_fill) {
1137  const auto copy_start = ProfileClock::now();
1138  operation();
1139  parallel_copy_seconds +=
1140  std::chrono::duration<double>(ProfileClock::now() - copy_start).count();
1141  } else {
1142  operation();
1143  }
1144  ++parallel_copy_calls;
1145  };
1146 
1147  // Component 0 marks coarse-only ghosts, component 1 counts component
1148  // writes in this role, and component 2 marks an unrepresentable quotient.
1149  // Seed the ghost region, clear valid cells, then exchange the valid mask:
1150  // same-level and periodic donor ghosts become zero while coarse-only
1151  // ghosts stay marked. Fine valid data and fine-fine/periodic donors are
1152  // never poisoned or replaced by parent values.
1153  missing_fine_ghosts.setVal(Real(0.0), 0, 3, 2);
1154  missing_fine_ghosts.setVal(Real(1.0), 0, 1, 2);
1155  missing_fine_ghosts.setVal(Real(0.0), 0, 1, 0);
1156  missing_fine_ghosts.FillBoundary(0, 1, fine_geometry.periodicity());
1157  clear_outside_physical_domain(missing_fine_ghosts, 0, fine_geometry);
1158  amrex::IntVect fault_cell(std::numeric_limits<int>::min());
1159 #ifdef ERF_SBM_AMR_QUALIFICATION
1160  if (inject_rank_local_store_fault) {
1161  fault_cell = qualification::first_coarse_only_ghost(missing_fine_ghosts);
1162  }
1163 #endif
1164 
1165  if (probe != nullptr && probe_this_role &&
1166  probe->seed_finite_stale_value) {
1167  const auto probe_cell = probe->fine_cell;
1168  const int probe_component = probe->global_component;
1169  const Real sentinel = probe->stale_value;
1170  for (amrex::MFIter mfi(destination, false); mfi.isValid(); ++mfi) {
1171  const auto target = destination.array(mfi);
1172  const auto missing = missing_fine_ghosts.const_array(mfi);
1174  mfi.fabbox(), [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1175  if (missing(i, j, k, 0) == Real(1.0) &&
1176  i == probe_cell[0] && j == probe_cell[1] &&
1177  k == probe_cell[2]) {
1178  target(i, j, k, probe_component) = sentinel;
1179  }
1180  });
1181  }
1182  }
1183 
1184  // Poison only the cells classified as coarse-only ghosts in this role.
1185  // This makes a missed destination store observable even when that FAB
1186  // held a finite value from an earlier role or stage. The destination is
1187  // the only N-component storage touched; no all-component staging copy is
1188  // created.
1189  const Real poison = std::numeric_limits<Real>::quiet_NaN();
1190  for (amrex::MFIter mfi(destination, false); mfi.isValid(); ++mfi) {
1191  const amrex::Box fab_box = mfi.fabbox();
1192  const auto missing = missing_fine_ghosts.const_array(mfi);
1193  const auto target = destination.array(mfi);
1194  const int ncomp = destination.nComp();
1196  fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1197  if (missing(i, j, k, 0) != Real(1.0)) return;
1198  for (int n = 0; n < ncomp; ++n) {
1199  target(i, j, k, n) = poison;
1200  }
1201  });
1202  }
1203 
1204  std::vector<int> flattened_components;
1205  std::vector<int> chunk_offsets;
1206  flattened_components.reserve(static_cast<std::size_t>(destination.nComp()));
1207  chunk_offsets.reserve(chunks.size());
1208  for (const auto& chunk : chunks) {
1209  chunk_offsets.push_back(static_cast<int>(flattened_components.size()));
1210  flattened_components.insert(flattened_components.end(),
1211  chunk.components.begin(),
1212  chunk.components.end());
1213  }
1214  if (flattened_components.size() !=
1215  static_cast<std::size_t>(destination.nComp())) {
1216  amrex::Abort("SBM coarse/fine stage chunks do not cover every "
1217  "spectrum component exactly once");
1218  }
1219  amrex::Gpu::DeviceVector<int> device_components(flattened_components.size());
1220  amrex::Gpu::copy(amrex::Gpu::hostToDevice, flattened_components.begin(),
1221  flattened_components.end(), device_components.begin());
1222 
1223  const auto coarse_old_periodic = coarse_periodicity;
1224  for (std::size_t chunk_index = 0; chunk_index < chunks.size();
1225  ++chunk_index) {
1226  const auto& chunk = chunks[chunk_index];
1227  if (chunk.components.empty() ||
1228  static_cast<int>(chunk.components.size()) >
1229  max_chunk_components) {
1230  amrex::Abort("SBM coarse/fine stage chunk exceeds bounded scratch");
1231  }
1232  const int component_count =
1233  static_cast<int>(chunk.components.size());
1234  if (componentwise_parent_fill) {
1235  for (std::size_t local = 0; local < chunk.components.size(); ++local) {
1236  const int global = chunk.components[local];
1237  timed_parallel_copy([&] {
1238  coarse_stage.ParallelCopy(
1239  coarse_old_spectrum, global, static_cast<int>(local), 1,
1240  amrex::IntVect(0), coarse_ghosts, coarse_old_periodic);
1241  });
1242  timed_parallel_copy([&] {
1243  coarse_stage.ParallelCopy(
1244  coarse_new_spectrum, global,
1245  max_chunk_components + static_cast<int>(local), 1,
1246  amrex::IntVect(0), coarse_ghosts, coarse_old_periodic);
1247  });
1248  }
1249  timed_parallel_copy([&] {
1250  coarse_stage.ParallelCopy(
1251  *parent.conserved_old, Rho_comp, rho_old_local, 1,
1252  amrex::IntVect(0), coarse_ghosts, coarse_old_periodic);
1253  });
1254  timed_parallel_copy([&] {
1255  coarse_stage.ParallelCopy(
1256  *parent.conserved_new, Rho_comp, rho_new_local, 1,
1257  amrex::IntVect(0), coarse_ghosts, coarse_old_periodic);
1258  });
1259  } else {
1260  const int component_offset = chunk_offsets[chunk_index];
1261  const int* component_map_local =
1262  device_components.data() + component_offset;
1263  for (amrex::MFIter mfi(coarse_pack, false); mfi.isValid(); ++mfi) {
1264  const amrex::Box bx = mfi.validbox();
1265  const auto old_values = coarse_old_spectrum.const_array(mfi);
1266  const auto new_values = coarse_new_spectrum.const_array(mfi);
1267  const auto rho_old = parent.conserved_old->const_array(mfi);
1268  const auto rho_new = parent.conserved_new->const_array(mfi);
1269  const auto pack = coarse_pack.array(mfi);
1271  bx, 2 * component_count + 2,
1272  [=] AMREX_GPU_DEVICE(int i, int j, int k,
1273  int local) noexcept {
1274  if (local < component_count) {
1275  const int global = component_map_local[local];
1276  pack(i, j, k, local) =
1277  old_values(i, j, k, global);
1278  } else if (local < 2 * component_count) {
1279  const int local_component =
1280  local - component_count;
1281  const int global =
1282  component_map_local[local_component];
1283  pack(i, j, k,
1284  max_chunk_components + local_component) =
1285  new_values(i, j, k, global);
1286  } else if (local == 2 * component_count) {
1287  pack(i, j, k, rho_old_local) =
1288  rho_old(i, j, k, Rho_comp);
1289  } else {
1290  pack(i, j, k, rho_new_local) =
1291  rho_new(i, j, k, Rho_comp);
1292  }
1293  });
1294  }
1295  timed_parallel_copy([&] {
1296  coarse_stage.ParallelCopy(
1297  coarse_pack, 0, 0, 2 * max_chunk_components + 2,
1298  amrex::IntVect(0), coarse_ghosts, coarse_old_periodic);
1299  });
1300  }
1301 
1302  if (!coarse_stage_endpoints_valid(coarse_stage, component_count,
1303  max_chunk_components,
1304  rho_old_local, coarse_region)) {
1305  std::ostringstream message;
1306  message.precision(17);
1307  message << "SBM coarse/fine endpoint data are not finite with "
1308  << "positive density (level=" << level << ", stage="
1309  << stage << ", role=" << role << ", requested_time="
1310  << requested_time << ", coarse_old=" << parent.old_time
1311  << ", coarse_new=" << parent.new_time << ", rank="
1312  << amrex::ParallelDescriptor::MyProc() << ')';
1313  amrex::Abort(message.str());
1314  }
1315 
1316  const int component_offset = chunk_offsets[chunk_index];
1317  const Real theta_real = static_cast<Real>(theta);
1318  const auto component_map = device_components.data();
1319  const amrex::IntVect refinement_ratio = parent.refinement_ratio;
1320  const amrex::IntVect probe_cell =
1321  probe == nullptr ? amrex::IntVect(-1) : probe->fine_cell;
1322  const int skipped_component =
1323  probe == nullptr ? -1 : probe->skipped_global_component;
1324  const bool skip_tally_only =
1325  probe != nullptr && probe->skip_write_tally_only;
1326  const int probe_stage = probe == nullptr ? -1 : probe->requested_stage;
1327  const bool probe_role_matches = probe_this_role;
1328  for (amrex::MFIter mfi(destination, false); mfi.isValid(); ++mfi) {
1329  const amrex::Box fab_box = mfi.fabbox();
1330  const auto coarse = coarse_stage.const_array(mfi);
1331  const auto missing = missing_fine_ghosts.array(mfi);
1332  const auto target = destination.array(mfi);
1333  const auto component_map_local = component_map + component_offset;
1335  fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1336  if (missing(i, j, k, 0) != Real(1.0)) return;
1337  amrex::IntVect parent_cell(i, j, k);
1338  parent_cell.coarsen(refinement_ratio);
1339  const Real rho0 = coarse(parent_cell[0], parent_cell[1],
1340  parent_cell[2], rho_old_local);
1341  const Real rho1 = coarse(parent_cell[0], parent_cell[1],
1342  parent_cell[2], rho_new_local);
1343  const Real rho_t = (Real(1.0) - theta_real) * rho0 +
1344  theta_real * rho1;
1345  int wrote_components = 0;
1346  for (int local = 0; local < component_count; ++local) {
1347  const int global = component_map_local[local];
1348  const bool probe_fault_cell =
1349  global == skipped_component &&
1350  probe_role_matches &&
1351  (probe_stage < 0 || probe_stage == stage) &&
1352  i == probe_cell[0] && j == probe_cell[1] &&
1353  k == probe_cell[2];
1354  const bool skip_assignment =
1355  probe_fault_cell && !skip_tally_only;
1356  const bool skip_rank_local_assignment =
1357  inject_rank_local_store_fault && global == 0 &&
1358  i == fault_cell[0] && j == fault_cell[1] &&
1359  k == fault_cell[2];
1360  const Real u0 = coarse(parent_cell[0], parent_cell[1],
1361  parent_cell[2], local);
1362  const Real u1 = coarse(
1363  parent_cell[0], parent_cell[1], parent_cell[2],
1364  max_chunk_components + local);
1365  const Real u_t = (Real(1.0) - theta_real) * u0 +
1366  theta_real * u1;
1367  const Real intensive = u_t / rho_t;
1368  const bool positive_support_expected =
1369  ((theta_real < Real(1.0)) && u0 > Real(0.0)) ||
1370  ((theta_real > Real(0.0)) && u1 > Real(0.0));
1371  const bool quotient_ok =
1372  amrex::Math::isfinite(rho_t) && rho_t > Real(0.0) &&
1373  amrex::Math::isfinite(u_t) && u_t >= Real(0.0) &&
1374  amrex::Math::isfinite(intensive) &&
1375  intensive >= Real(0.0) &&
1376  (!(positive_support_expected) ||
1377  (u_t > Real(0.0) && intensive > Real(0.0)));
1378  if (!skip_assignment && !skip_rank_local_assignment) {
1379  if (quotient_ok) {
1380  target(i, j, k, global) = intensive;
1381  } else {
1382  // Keep a generated quotient failure distinct
1383  // from a missing destination store.
1384  target(i, j, k, global) =
1385  std::numeric_limits<Real>::infinity();
1386  missing(i, j, k, 2) = Real(1.0);
1387  }
1388  }
1389  if (!(probe_fault_cell && skip_tally_only)) {
1390  ++wrote_components;
1391  }
1392  }
1393  missing(i, j, k, 1) += static_cast<Real>(wrote_components);
1394  });
1395  }
1396  }
1397 
1398  // Independently inspect actual destination values at all marked coarse-
1399  // only ghosts before any stencil can consume them. The per-cell loop
1400  // avoids races when multiple components fail at one location; the mask
1401  // carries one scalar failure code for the collective reduction.
1402  for (amrex::MFIter mfi(destination, false); mfi.isValid(); ++mfi) {
1403  const amrex::Box fab_box = mfi.fabbox();
1404  const auto mask = missing_fine_ghosts.array(mfi);
1405  const int ncomp = destination.nComp();
1406  const auto target = destination.const_array(mfi);
1407  const int sample_component = probe == nullptr
1408  ? -1 : probe->global_component;
1409  const amrex::IntVect sample_cell = probe == nullptr
1410  ? amrex::IntVect(-1) : probe->fine_cell;
1411  const bool sample_role_matches = probe_this_role;
1412  const int sample_stage = probe == nullptr
1413  ? -1 : probe->requested_stage;
1414  auto* sampled_value = probe == nullptr
1415  ? nullptr : probe->sampled_intensive_device;
1416  auto* sampled_hit = probe == nullptr ? nullptr : probe->hit_device;
1418  fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1419  if (mask(i, j, k, 0) != Real(1.0)) return;
1420  int destination_invalid = 0;
1421  const bool quotient_failed =
1422  mask(i, j, k, 2) == Real(1.0);
1423  for (int component = 0; component < ncomp; ++component) {
1424  const Real value = target(i, j, k, component);
1425  if (!amrex::Math::isfinite(value) || value < Real(0.0)) {
1426  // The quotient path writes +infinity deliberately as
1427  // its invalid marker. Keep that distinct from the
1428  // NaN poison that proves a destination store was
1429  // skipped; any other bad component remains visible.
1430  if (quotient_failed &&
1431  value == std::numeric_limits<Real>::infinity()) {
1432  continue;
1433  }
1434  destination_invalid = 1;
1435  break;
1436  }
1437  }
1438  if (destination_invalid != 0) {
1439  // Encode both independent failure classes if necessary:
1440  // 1 = quotient, 2 = invalid destination, 3 = both.
1441  mask(i, j, k, 2) = quotient_failed
1442  ? Real(3.0) : Real(2.0);
1443  }
1444  if (sampled_value != nullptr && sampled_hit != nullptr &&
1445  sample_role_matches &&
1446  (sample_stage < 0 || sample_stage == stage) &&
1447  i == sample_cell[0] && j == sample_cell[1] &&
1448  k == sample_cell[2]) {
1449  *sampled_value = target(i, j, k, sample_component);
1450  *sampled_hit = 1;
1451  }
1452  });
1453  }
1454  const Real destination_failure = missing_fine_ghosts.max(2, 2);
1455  if (destination_failure == Real(2.0) ||
1456  destination_failure == Real(3.0)) {
1457  std::ostringstream message;
1458  message.precision(17);
1459  message << "SBM coarse/fine stage left a coarse-only parent ghost "
1460  << "component unwritten or invalid in the destination"
1461  << (destination_failure == Real(3.0)
1462  ? " (also found an invalid quotient)" : "")
1463  << " (level=" << level << ", stage=" << stage << ", role="
1464  << role << ", requested_time=" << requested_time
1465  << ", coarse_old=" << parent.old_time << ", coarse_new="
1466  << parent.new_time << ", rank="
1467  << amrex::ParallelDescriptor::MyProc()
1468  << (inject_rank_local_store_fault
1469  ? ", assignment_only_fault=rank-local" : "")
1470  << ')';
1471  amrex::Abort(message.str());
1472  }
1473  if (destination_failure == Real(1.0)) {
1474  std::ostringstream message;
1475  message.precision(17);
1476  message << "SBM coarse/fine stage produced an unrepresentable "
1477  << "U(t)/rho_d(t) quotient (level=" << level << ", stage="
1478  << stage << ", role=" << role << ", requested_time="
1479  << requested_time << ", coarse_old=" << parent.old_time
1480  << ", coarse_new=" << parent.new_time << ", rank="
1481  << amrex::ParallelDescriptor::MyProc() << ')';
1482  amrex::Abort(message.str());
1483  }
1484 
1485  // Retain the independent progress token as a second check. It cannot
1486  // stand in for the actual-destination scan above.
1487  for (amrex::MFIter mfi(destination, false); mfi.isValid(); ++mfi) {
1488  const amrex::Box fab_box = mfi.fabbox();
1489  const auto mask = missing_fine_ghosts.array(mfi);
1490  const int ncomp = destination.nComp();
1492  fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1493  if (mask(i, j, k, 0) == Real(1.0)) {
1494  mask(i, j, k, 0) =
1495  (mask(i, j, k, 1) == static_cast<Real>(ncomp))
1496  ? Real(0.0) : Real(1.0);
1497  }
1498  });
1499  }
1500  if (missing_fine_ghosts.max(0, 2) != Real(0.0)) {
1501  std::ostringstream message;
1502  message.precision(17);
1503  message << "SBM coarse/fine stage omitted a required parent ghost "
1504  << "component write (level=" << level << ", stage=" << stage
1505  << ", role=" << role << ", requested_time=" << requested_time
1506  << ", coarse_old=" << parent.old_time << ", coarse_new="
1507  << parent.new_time << ", rank="
1508  << amrex::ParallelDescriptor::MyProc() << ')';
1509  amrex::Abort(message.str());
1510  }
1511 #ifdef ERF_SBM_AMR_QUALIFICATION
1512  if (split_values_checked != nullptr &&
1513  parent.validate_split_ghost_values && current_role == 0) {
1514  // Once at the coarse start, and once strictly inside the coarse
1515  // interval, where both accepted endpoints contribute.
1516  const bool at_start = stage == 0 &&
1517  semantic_time_matches(requested_time, parent.old_time, dt_min);
1518  const bool interior = theta > 0.0 && theta < 1.0;
1519  const std::size_t slot = at_start ? 0U : 1U;
1520  if ((at_start || interior) && !(*split_values_checked)[slot]) {
1521  amrex::Gpu::streamSynchronize();
1523  destination, fine_source_state, fine_source_conserved,
1524  coarse_old_spectrum, coarse_new_spectrum, parent, fine_geometry,
1525  theta, stage, requested_time);
1526  (*split_values_checked)[slot] = true;
1527  }
1528  }
1529 #else
1530  amrex::ignore_unused(fine_source_state, fine_source_conserved,
1531  split_values_checked);
1532 #endif
1533  // Device component maps and parent chunks remain alive through the queued
1534  // ghost kernels. Synchronize before their storage is released.
1535  amrex::Gpu::streamSynchronize();
1536  if (profile_parent_fill) {
1537  std::uint64_t local_coarse_stage_bytes = 0;
1538  std::uint64_t local_coarse_pack_bytes = 0;
1539  for (amrex::MFIter mfi(coarse_stage, false); mfi.isValid(); ++mfi) {
1540  local_coarse_stage_bytes += static_cast<std::uint64_t>(
1541  coarse_stage[mfi].nBytesOwned());
1542  }
1543  if (coarse_pack.isDefined()) {
1544  for (amrex::MFIter mfi(coarse_pack, false);
1545  mfi.isValid(); ++mfi) {
1546  local_coarse_pack_bytes += static_cast<std::uint64_t>(
1547  coarse_pack[mfi].nBytesOwned());
1548  }
1549  }
1550  std::cout << std::setprecision(9)
1551  << "SBM_AMR_PROFILE_PARENT rank="
1552  << amrex::ParallelDescriptor::MyProc()
1553  << " level=" << level << " stage=" << stage
1554  << " role=" << role
1555  << " ncomp=" << destination.nComp()
1556  << " max_chunk_components=" << max_chunk_components
1557  << " chunks=" << chunks.size()
1558  << " parent_fill_mode="
1559  << (componentwise_parent_fill ? "componentwise" : "packed")
1560  << " parallel_copy_calls=" << parallel_copy_calls
1561  << " parallel_copy_wall_s=" << parallel_copy_seconds
1562  << " parent_fill_wall_s="
1563  << std::chrono::duration<double>(ProfileClock::now() -
1564  fill_start).count()
1565  << " coarse_stage_fab_bytes_local="
1566  << local_coarse_stage_bytes
1567  << " coarse_source_pack_fab_bytes_local="
1568  << local_coarse_pack_bytes
1569  << " rank_live_fab_bytes="
1570  << amrex::TotalBytesAllocatedInFabs()
1571  << std::endl;
1572  }
1573 }
@ U
Definition: ERF_IndexDefines.H:178
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real sample_component(int dir, Array4< Real const > const &f, Real x, Real y, Real z, const GpuArray< Real, AMREX_SPACEDIM > &plo, const GpuArray< Real, AMREX_SPACEDIM > &dxi, int klo, int khi, Array4< Real const > const &znd, bool has_znd, Real dz)
Definition: ERF_ActuatorSampling.cpp:61
constexpr Real missing
Definition: ERF_TopographicShading.cpp:10
bool coarse_stage_theta(const double requested_time, const double coarse_old_time, const double coarse_new_time, const double dt_min, double &theta, std::string &diagnostic)
Definition: ERF_SBMTransport.cpp:948
bool coarse_stage_endpoints_valid(const MultiFab &coarse_stage, const int component_count, const int new_offset, const int rho_old_local, const amrex::Box &coarse_region)
Definition: ERF_SBMTransport.cpp:990
void clear_outside_physical_domain(MultiFab &mask, const int component, const amrex::Geometry &geometry)
Definition: ERF_SBMTransport.cpp:200
void verify_split_ghost_values(const MultiFab &destination, const MultiFab &fine_source_state, const MultiFab &fine_source_conserved, const MultiFab &coarse_old_spectrum, const MultiFab &coarse_new_spectrum, const SBMAMRStageParent &parent, const Geometry &fine_geometry, const double theta, const int stage, const double requested_time)
Definition: ERF_SBMAMRQualification.cpp:410
IntVect first_coarse_only_ghost(const MultiFab &mask)
Definition: ERF_SBMAMRQualification.cpp:555

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ fill_physical_ghosts()

void erf_sbm::erf_detail_SBMTransport::fill_physical_ghosts ( MultiFab &  field,
const amrex::Geometry &  geometry,
const SBMPhysicalBoundaryConfig &  boundaries,
const Real *  inflow_device 
)
159 {
160  const amrex::Box& domain = geometry.Domain();
161  const int ncomp = field.nComp();
162  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
163  if (geometry.isPeriodic(dir)) continue;
164  for (const auto side : {amrex::Orientation::low, amrex::Orientation::high}) {
165  const int face = amrex::Orientation(dir, side);
166  const bool low = side == amrex::Orientation::low;
167  const Real* face_inflow =
168  inflow_device != nullptr &&
169  boundaries.kind[static_cast<std::size_t>(face)] ==
170  AdvectionFaceKind::PrescribedInflow
171  ? inflow_device + face * ncomp : nullptr;
172  const int edge = low ? domain.smallEnd(dir) : domain.bigEnd(dir);
173  for (amrex::MFIter mfi(field, false); mfi.isValid(); ++mfi) {
174  amrex::Box ghost = mfi.fabbox();
175  if (low) {
176  ghost.setBig(dir, edge - 1);
177  } else {
178  ghost.setSmall(dir, edge + 1);
179  }
180  if (!ghost.ok()) continue;
181  const auto values = field.array(mfi);
183  ghost, ncomp,
184  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
185  if (face_inflow != nullptr) {
186  values(i, j, k, n) = face_inflow[n];
187  return;
188  }
189  amrex::IntVect source(AMREX_D_DECL(i, j, k));
190  source[dir] = edge;
191  values(i, j, k, n) = values(source, n);
192  });
193  }
194  }
195  }
196 }

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ fill_side_open_mask()

void erf_sbm::erf_detail_SBMTransport::fill_side_open_mask ( MultiFab &  mask,
const int  dir,
const erf_auxiliary::MappedDiffusionBoundary &  boundary,
const amrex::Geometry &  geometry 
)
495 {
496  const amrex::Box& domain = geometry.Domain();
497  const int lo = domain.smallEnd(dir);
498  const int hi = domain.bigEnd(dir);
499  const auto kind_lo = boundary.kind[static_cast<std::size_t>(dir)];
500  const auto kind_hi = boundary.kind[static_cast<std::size_t>(dir + AMREX_SPACEDIM)];
501  const MultiFab* carrier_field = boundary.carrier[static_cast<std::size_t>(dir)];
502  mask.setVal(Real(0.0), 0, 1, mask.nGrowVect());
503  for (amrex::MFIter mfi(mask, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
504  const auto out = mask.array(mfi);
505  const auto carrier = carrier_field != nullptr ? carrier_field->const_array(mfi)
506  : Array4<const Real>{};
507  amrex::ParallelFor(mfi.tilebox(), [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
508  const int index = dir == 0 ? i : j;
509  if (index != lo && index != hi + 1) {
510  return;
511  }
513  index == lo, kind_lo, kind_hi, carrier, i, j, k)
514  ? Real(1.0) : Real(0.0);
515  });
516  }
517  mask.FillBoundary(geometry.periodicity());
518 }

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ include_neighbourhood()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_sbm::erf_detail_SBMTransport::include_neighbourhood ( const Array4< const Real > &  field,
const int  i,
const int  j,
const int  k,
const LocalPropertySupport &  support,
Real &  lower,
Real &  upper,
int &  found 
)
noexcept
1765 {
1766  consider_donor_ratio(field, i, j, k, support, lower, upper, found);
1767  consider_donor_ratio(field, i - 1, j, k, support, lower, upper, found);
1768  consider_donor_ratio(field, i + 1, j, k, support, lower, upper, found);
1769  consider_donor_ratio(field, i, j - 1, k, support, lower, upper, found);
1770  consider_donor_ratio(field, i, j + 1, k, support, lower, upper, found);
1771  consider_donor_ratio(field, i, j, k - 1, support, lower, upper, found);
1772  consider_donor_ratio(field, i, j, k + 1, support, lower, upper, found);
1773 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void consider_donor_ratio(const Array4< const Real > &field, const int i, const int j, const int k, const LocalPropertySupport &support, Real &lower, Real &upper, int &found) noexcept
Definition: ERF_SBMTransport.cpp:1729

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ is_matched_coordinate()

bool erf_sbm::erf_detail_SBMTransport::is_matched_coordinate ( const ConstraintGroup &  group,
const SBMLayout &  layout,
const int  constraint_index 
)
94 {
95  const auto& id =
96  group.constraints.at(static_cast<std::size_t>(constraint_index)).semantic_id;
97  if (id == "mass_nonnegative" || id == "endpoint_low" || id == "endpoint_high") {
98  return true;
99  }
100  for (const int property : group.attached_property_indices) {
101  if (id == layout.attached_properties().at(static_cast<std::size_t>(property))
102  .semantic_id + ".nonnegative") {
103  return true;
104  }
105  }
106  return false;
107 }

Referenced by erf_sbm::SBMTransport::SBMTransport().

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

◆ open_face_ratio_ghosts()

void erf_sbm::erf_detail_SBMTransport::open_face_ratio_ghosts ( MultiFab &  ratios,
const amrex::Geometry &  geometry,
const SBMPhysicalBoundaryConfig &  boundaries 
)
792 {
793  const amrex::Box& domain = geometry.Domain();
794  const int ncomp = ratios.nComp();
795  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
796  if (geometry.isPeriodic(dir)) continue;
797  for (const auto side : {amrex::Orientation::low, amrex::Orientation::high}) {
798  const int face = amrex::Orientation(dir, side);
799  if (boundaries.diffusion[static_cast<std::size_t>(face)] ==
801  continue;
802  }
803  const bool low = side == amrex::Orientation::low;
804  for (amrex::MFIter mfi(ratios, false); mfi.isValid(); ++mfi) {
805  amrex::Box ghost = mfi.fabbox();
806  if (low) {
807  ghost.setBig(dir, domain.smallEnd(dir) - 1);
808  } else {
809  ghost.setSmall(dir, domain.bigEnd(dir) + 1);
810  }
811  if (!ghost.ok()) continue;
812  const auto values = ratios.array(mfi);
813  amrex::ParallelFor(ghost, ncomp,
814  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
815  values(i, j, k, n) = Real(1.0);
816  });
817  }
818  }
819  }
820 }

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ pair_face_gross()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::pair_face_gross ( const int  first,
const int  second,
const Real  first_coefficient,
const Real  second_coefficient,
const FaceArraySet &  low,
const FaceArraySet &  high,
const int  i,
const int  j,
const int  k,
const int  dir,
const int  side,
const Real  tau,
const GpuArray< Real, AMREX_SPACEDIM > &  dx_inv 
)
noexcept
1648 {
1649  const int fi = i + (dir == 0 && side > 0 ? 1 : 0);
1650  const int fj = j + (dir == 1 && side > 0 ? 1 : 0);
1651  const int fk = k + (dir == 2 && side > 0 ? 1 : 0);
1652  const Real l1 = low[dir](fi, fj, fk, first);
1653  const Real l2 = low[dir](fi, fj, fk, second);
1654  const Real h1 = high[dir](fi, fj, fk, first);
1655  const Real h2 = high[dir](fi, fj, fk, second);
1656  const Real gross =
1657  amrex::Math::abs(first_coefficient) * (amrex::Math::abs(l1) + amrex::Math::abs(h1 - l1)) +
1658  amrex::Math::abs(second_coefficient) * (amrex::Math::abs(l2) + amrex::Math::abs(h2 - l2));
1659  return tau * dx_inv[dir] * gross;
1660 }

Referenced by erf_sbm::SBMTransport::advance_stage().

Here is the caller graph for this function:

◆ physical_face_slab()

amrex::Box erf_sbm::erf_detail_SBMTransport::physical_face_slab ( const amrex::Box &  face_valid,
const amrex::Box &  domain,
const int  dir,
const bool  low 
)
261 {
262  amrex::Box slab = face_valid;
263  const int face_index = low ? domain.smallEnd(dir) : domain.bigEnd(dir) + 1;
264  slab.setSmall(dir, std::max(slab.smallEnd(dir), face_index));
265  slab.setBig(dir, std::min(slab.bigEnd(dir), face_index));
266  return slab;
267 }

Referenced by accumulate_boundary_rates(), and check_physical_face_carriers().

Here is the caller graph for this function:

◆ property_face_correction()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_sbm::erf_detail_SBMTransport::property_face_correction ( const LocalPropertySupport &  support,
const FaceArraySet &  low,
const FaceArraySet &  high,
const int  i,
const int  j,
const int  k,
const int  dir,
const int  side,
const Real  tau,
const GpuArray< Real, AMREX_SPACEDIM > &  dx_inv,
const Real  slope,
const bool  upper 
)
noexcept
1714 {
1715  const int fi = i + (dir == 0 && side > 0 ? 1 : 0);
1716  const int fj = j + (dir == 1 && side > 0 ? 1 : 0);
1717  const int fk = k + (dir == 2 && side > 0 ? 1 : 0);
1718  const Real dproperty = high[dir](fi, fj, fk, support.property_local) -
1719  low[dir](fi, fj, fk, support.property_local);
1720  const Real dcarrier = high[dir](fi, fj, fk, support.carrier_local) -
1721  low[dir](fi, fj, fk, support.carrier_local);
1722  const Real g_flux =
1723  upper ? slope * dcarrier - dproperty : dproperty - slope * dcarrier;
1724  const Real outward_sign = side > 0 ? Real(1.0) : Real(-1.0);
1725  return -outward_sign * tau * dx_inv[dir] * g_flux;
1726 }

Referenced by erf_sbm::SBMTransport::advance_stage().

Here is the caller graph for this function:

◆ sample_probe_endpoint_value()

void erf_sbm::erf_detail_SBMTransport::sample_probe_endpoint_value ( const SBMAMRStageGhostProbe *  probe,
const int  stage,
const MultiFab &  endpoint_input 
)
1781 {
1782  if (probe == nullptr || probe->sampled_endpoint_device == nullptr ||
1783  probe->endpoint_hit_device == nullptr ||
1784  (probe->requested_stage >= 0 && probe->requested_stage != stage)) {
1785  return;
1786  }
1787  const amrex::IntVect cell = probe->fine_cell;
1788  const int component = probe->global_component;
1789  auto* value = probe->sampled_endpoint_device;
1790  auto* hit = probe->endpoint_hit_device;
1791  for (amrex::MFIter mfi(endpoint_input, false); mfi.isValid(); ++mfi) {
1792  if (!mfi.fabbox().contains(cell)) continue;
1793  const auto endpoint = endpoint_input.const_array(mfi);
1794  amrex::ParallelFor(amrex::Box(cell, cell),
1795  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1796  *value = endpoint(i, j, k, component);
1797  *hit = 1;
1798  });
1799  }
1800 }

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ sample_probe_face_rates()

void erf_sbm::erf_detail_SBMTransport::sample_probe_face_rates ( const SBMAMRStageGhostProbe *  probe,
const int  stage,
const std::vector< int > &  members,
const std::vector< int > &  global_to_local,
const erf_auxiliary::MappedFaceFluxRate &  accepted_rate,
const erf_auxiliary::MappedFaceFluxRate &  high_rate,
const erf_auxiliary::MappedFaceFluxRate &  low_rate,
const erf_auxiliary::MappedFaceFluxRate &  face_lambda 
)
1851 {
1852  if (probe == nullptr || probe->sampled_face_direction < 0 ||
1853  (probe->sampled_stage >= 0 && probe->sampled_stage != stage) ||
1854  probe->sampled_mass_rate_device == nullptr ||
1855  probe->sampled_number_rate_device == nullptr ||
1856  probe->sampled_property_rate_device == nullptr ||
1857  probe->sampled_high_mass_rate_device == nullptr ||
1858  probe->sampled_high_number_rate_device == nullptr ||
1859  probe->sampled_high_property_rate_device == nullptr ||
1860  probe->sampled_low_mass_rate_device == nullptr ||
1861  probe->sampled_low_number_rate_device == nullptr ||
1862  probe->sampled_low_property_rate_device == nullptr ||
1863  probe->sampled_lambda_device == nullptr ||
1864  probe->sampled_rate_hit_device == nullptr) {
1865  return;
1866  }
1867  const auto local_member = [&] (const int component) {
1868  const bool member = std::find(members.begin(), members.end(),
1869  component) != members.end();
1870  return member
1871  ? global_to_local[static_cast<std::size_t>(component)] : -1;
1872  };
1873  const int m = local_member(probe->sampled_mass_component);
1874  const int n = local_member(probe->sampled_number_component);
1875  const int p = local_member(probe->sampled_property_component);
1876  if (m < 0 || n < 0 || p < 0) return;
1877 
1878  const int dir = probe->sampled_face_direction;
1879  const amrex::IntVect face = probe->sampled_face;
1880  const amrex::Box face_box(face, face,
1881  amrex::IntVect::TheDimensionVector(dir));
1882  const auto& accepted = accepted_rate.dir(dir);
1883  const auto& high = high_rate.dir(dir);
1884  const auto& low = low_rate.dir(dir);
1885  const auto& lambda_field = face_lambda.dir(dir);
1886  auto* am = probe->sampled_mass_rate_device;
1887  auto* an = probe->sampled_number_rate_device;
1888  auto* ap = probe->sampled_property_rate_device;
1889  auto* hm = probe->sampled_high_mass_rate_device;
1890  auto* hn = probe->sampled_high_number_rate_device;
1891  auto* hp = probe->sampled_high_property_rate_device;
1892  auto* lm = probe->sampled_low_mass_rate_device;
1893  auto* ln = probe->sampled_low_number_rate_device;
1894  auto* lp = probe->sampled_low_property_rate_device;
1895  auto* out_lambda = probe->sampled_lambda_device;
1896  auto* out_hit = probe->sampled_rate_hit_device;
1897  for (amrex::MFIter mfi(accepted, amrex::TilingIfNotGPU()); mfi.isValid();
1898  ++mfi) {
1899  if (!mfi.tilebox().contains(face)) continue;
1900  const auto accepted_values = accepted.const_array(mfi);
1901  const auto high_values = high.const_array(mfi);
1902  const auto low_values = low.const_array(mfi);
1903  const auto limiter = lambda_field.const_array(mfi);
1904  amrex::ParallelFor(face_box,
1905  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1906  am[0] = accepted_values(i, j, k, m);
1907  an[0] = accepted_values(i, j, k, n);
1908  ap[0] = accepted_values(i, j, k, p);
1909  hm[0] = high_values(i, j, k, m);
1910  hn[0] = high_values(i, j, k, n);
1911  hp[0] = high_values(i, j, k, p);
1912  lm[0] = low_values(i, j, k, m);
1913  ln[0] = low_values(i, j, k, n);
1914  lp[0] = low_values(i, j, k, p);
1915  out_lambda[0] = limiter(i, j, k, 0);
1916  out_hit[0] = 1;
1917  });
1918  }
1919 }
@ p
Definition: ERF_WSM6.H:303

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ sample_probe_stencil()

void erf_sbm::erf_detail_SBMTransport::sample_probe_stencil ( const SBMAMRStageGhostProbe *  probe,
const int  stage,
const MultiFab &  physical_input,
const MultiFab &  endpoint_input 
)
1807 {
1808  if (probe == nullptr || probe->sampled_face_direction != 0 ||
1809  probe->sampled_physical_stencil_device == nullptr ||
1810  probe->sampled_endpoint_stencil_device == nullptr ||
1811  (probe->sampled_stage >= 0 && probe->sampled_stage != stage)) {
1812  return;
1813  }
1814  // Positive-x WENO-Z3 stencil of face i: cells i-2, i-1, i.
1815  amrex::IntVect lo = probe->sampled_face;
1816  lo[0] -= 2;
1817  const amrex::Box stencil(lo, probe->sampled_face);
1818  const int first = lo[0];
1819  const int mass = probe->sampled_mass_component;
1820  const int number = probe->sampled_number_component;
1821  const int property = probe->sampled_property_component;
1822  auto* physical_out = probe->sampled_physical_stencil_device;
1823  auto* endpoint_out = probe->sampled_endpoint_stencil_device;
1824  for (amrex::MFIter mfi(endpoint_input, false); mfi.isValid(); ++mfi) {
1825  const amrex::Box bx = mfi.fabbox() & stencil;
1826  if (!bx.ok()) continue;
1827  const auto physical = physical_input.const_array(mfi);
1828  const auto endpoint = endpoint_input.const_array(mfi);
1829  amrex::ParallelFor(bx,
1830  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1831  const int offset = 3 * (i - first);
1832  physical_out[offset] = physical(i, j, k, mass);
1833  physical_out[offset + 1] = physical(i, j, k, number);
1834  physical_out[offset + 2] = physical(i, j, k, property);
1835  endpoint_out[offset] = endpoint(i, j, k, mass);
1836  endpoint_out[offset + 1] = endpoint(i, j, k, number);
1837  endpoint_out[offset + 2] = endpoint(i, j, k, property);
1838  });
1839  }
1840 }
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:36

Referenced by erf_sbm::SBMTransport::advance_stage().

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

◆ shared_copy_mismatch()

Real erf_sbm::erf_detail_SBMTransport::shared_copy_mismatch ( const MultiFab &  field,
const amrex::Periodicity &  period 
)
642 {
643  MultiFab synced(field.boxArray(), field.DistributionMap(), field.nComp(), 0);
644  MultiFab::Copy(synced, field, 0, 0, field.nComp(), 0);
645  synced.OverrideSync(period);
646  MultiFab::Subtract(synced, field, 0, 0, field.nComp(), 0);
647  return synced.norm0(0, field.nComp(), amrex::IntVect(0));
648 }
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131

Referenced by shared_metric_mismatch().

Here is the caller graph for this function:

◆ shared_metric_mismatch()

std::string erf_sbm::erf_detail_SBMTransport::shared_metric_mismatch ( const erf_auxiliary::MappedDiffusionMetrics &  metrics,
const amrex::Geometry &  geometry 
)
658 {
659  const amrex::Box& domain = geometry.Domain();
660  const amrex::Periodicity lateral(amrex::IntVect(
661  AMREX_D_DECL(geometry.isPeriodic(0) ? domain.length(0) : 0,
662  geometry.isPeriodic(1) ? domain.length(1) : 0, 0)));
663  const auto dx_inv = geometry.InvCellSizeArray();
664  std::array<MultiFab, 2> slope;
665  for (int dir = 0; dir < 2; ++dir) {
666  const MultiFab& area = dir == 0 ? *metrics.ax : *metrics.ay;
667  slope[static_cast<std::size_t>(dir)].define(area.boxArray(), area.DistributionMap(), 2, 0);
668  for (amrex::MFIter mfi(area); mfi.isValid(); ++mfi) {
669  const auto out = slope[static_cast<std::size_t>(dir)].array(mfi);
670  const auto z_nd = metrics.z_nd->const_array(mfi);
671  amrex::ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
672  out(i, j, k, 0) = dir == 0 ? Compute_h_xi_AtIface(i, j, k, dx_inv, z_nd)
673  : Compute_h_xi_AtJface(i, j, k, dx_inv, z_nd);
674  out(i, j, k, 1) = dir == 0 ? Compute_h_eta_AtIface(i, j, k, dx_inv, z_nd)
675  : Compute_h_eta_AtJface(i, j, k, dx_inv, z_nd);
676  });
677  }
678  }
679  const std::array<std::pair<const char*, const MultiFab*>, 8> fields{{
680  {"ax", metrics.ax}, {"ay", metrics.ay},
681  {"the x-face terrain slopes", &slope[0]}, {"the y-face terrain slopes", &slope[1]},
682  {"the u_x map factor", metrics.mf_ux}, {"the u_y map factor", metrics.mf_uy},
683  {"the v_x map factor", metrics.mf_vx}, {"the v_y map factor", metrics.mf_vy}}};
684  for (const auto& [name, field] : fields) {
685  const Real mismatch = shared_copy_mismatch(*field, lateral);
686  if (mismatch != Real(0.0)) {
687  std::ostringstream message;
688  message.precision(6);
689  message << name << " differ by " << mismatch;
690  return message.str();
691  }
692  }
693  return {};
694 }
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtJface(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:397
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtJface(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:374
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtIface(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:328
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtIface(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:304
Real shared_copy_mismatch(const MultiFab &field, const amrex::Periodicity &period)
Definition: ERF_SBMTransport.cpp:641
const amrex::MultiFab * mf_uy
Definition: ERF_AuxiliaryDiffusion.H:45
const amrex::MultiFab * ax
Definition: ERF_AuxiliaryDiffusion.H:50
const amrex::MultiFab * mf_ux
Definition: ERF_AuxiliaryDiffusion.H:44
const amrex::MultiFab * mf_vx
Definition: ERF_AuxiliaryDiffusion.H:46
const amrex::MultiFab * ay
Definition: ERF_AuxiliaryDiffusion.H:51
const amrex::MultiFab * z_nd
Definition: ERF_AuxiliaryDiffusion.H:53
const amrex::MultiFab * mf_vy
Definition: ERF_AuxiliaryDiffusion.H:47

Referenced by erf_sbm::SBMTransport::advance_stage().

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