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

Functions

bool make_sed_inflow (const BoxArray &ba, const DistributionMapping &dm, const Box &domain, const IntVect &rr, const SedimentationFlux &crse, Real dt_fine, MultiFab &inflow)
 
void register_sed_fluxes (YAFluxRegister &fr, bool as_crse, const SedimentationFlux &sf, const MultiFab &cons, const MultiFab &mfx, const MultiFab &mfy, const Geometry &geom)
 

Function Documentation

◆ make_sed_inflow()

bool erf_detail_AdvanceMicrophysics::make_sed_inflow ( const BoxArray &  ba,
const DistributionMapping &  dm,
const Box &  domain,
const IntVect &  rr,
const SedimentationFlux &  crse,
Real  dt_fine,
MultiFab &  inflow 
)

The inflow through the top of a fine level's patches for one Advance of length dt_fine (see ERF_SedimentationFlux.H), from the sedimentation flux crse its parent recorded over its own, enclosing, step. A patch-top face is a z-face at the top of a fine box with no fine cell above it and below the domain top; it gets the coarse flux through the coarse face it lies in, piecewise constant in x and y, in proportion dt_fine / crse.dt.

Returns false, leaving inflow alone, when every box reaches the domain top.

22 {
23  bool any_short = false;
24  for (int ib = 0; ib < ba.size() && !any_short; ++ib) {
25  any_short = (ba[ib].bigEnd(2) < domain.bigEnd(2));
26  }
27  if (!any_short) { return false; }
28 
29  AMREX_ALWAYS_ASSERT(crse.down && crse.dt > Real(0));
30  const int ncomp = crse.down->nComp();
31 
32  // The coarse faces over the top face of each fine box, on the fine distribution
33  BoxList bl(IndexType(IntVect(0,0,1)));
34  for (int ib = 0; ib < ba.size(); ++ib) {
35  const Box& b = ba[ib];
36  const Box top(IntVect(b.smallEnd(0), b.smallEnd(1), b.bigEnd(2)+1),
37  IntVect(b.bigEnd(0), b.bigEnd(1), b.bigEnd(2)+1),
38  IndexType(IntVect(0,0,1)));
39  bl.push_back(coarsen(top, rr));
40  }
41  MultiFab crse_top(BoxArray(std::move(bl)), dm, ncomp, 0);
42  crse_top.ParallelCopy(*crse.down);
43 
44  inflow.define(convert(ba, IntVect(0,0,1)), dm, ncomp+1, 0);
45  inflow.setVal(0.0);
46 
47  const Real frac = dt_fine / crse.dt;
48  for (MFIter mfi(inflow); mfi.isValid(); ++mfi) {
49  const Box& b = ba[mfi.index()];
50  if (b.bigEnd(2) >= domain.bigEnd(2)) { continue; }
51 
52  Box above(b);
53  above.setRange(2, b.bigEnd(2)+1);
54  const auto ct = crse_top.const_array(mfi);
55  const auto in = inflow.array(mfi);
56  // Cells above this box that no fine box covers: their bottom faces are patch tops
57  for (const Box& ub : ba.complementIn(above)) {
58  ParallelFor(ub, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
59  {
60  const int ic = amrex::coarsen(i, rr[0]);
61  const int jc = amrex::coarsen(j, rr[1]);
62  const int kc = amrex::coarsen(k, rr[2]);
63  for (int n = 0; n < ncomp; ++n) {
64  in(i,j,k,n) = ct(ic,jc,kc,n) * frac;
65  }
66  in(i,j,k,ncomp) = Real(1);
67  });
68  }
69  }
70  return true;
71 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
real(c_double), private rr
Definition: ERF_module_mp_morr_two_moment.F90:224
amrex::Real dt
Definition: ERF_SedimentationFlux.H:41
std::shared_ptr< amrex::MultiFab > down
Definition: ERF_SedimentationFlux.H:39

Referenced by ERF::advance_microphysics().

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

◆ register_sed_fluxes()

void erf_detail_AdvanceMicrophysics::register_sed_fluxes ( YAFluxRegister &  fr,
bool  as_crse,
const SedimentationFlux &  sf,
const MultiFab &  cons,
const MultiFab &  mfx,
const MultiFab &  mfy,
const Geometry &  geom 
)

Add a level's sedimentation fluxes to a flux register, as the coarse level (as_crse) or the fine one, so that Reflux replaces the flux a coarse cell next to a fine patch saw through their shared z-face with the fine level's. Below a patch that stops short of the ground, that hands the patch's outflow to the coarse cell under it; at a patch top the fine flux is the coarse one (make_sed_inflow), so nothing changes there.

The register works with the advective form d(rho q)/dt = -(m^2/detJ) dF_z/dz on the computational grid, so the downward amount D per unit area over sf.dt is registered as F_z = -D / (sf.dt m_x m_y). Sedimentation has no x or y flux.

88 {
89  const int ncomp = sf.down->nComp();
90  const Real inv_dt = Real(1) / sf.dt;
91  for (MFIter mfi(cons); mfi.isValid(); ++mfi) {
92  const Box& bx = mfi.validbox();
93  FArrayBox fx(surroundingNodes(bx,0), ncomp, The_Async_Arena());
94  FArrayBox fy(surroundingNodes(bx,1), ncomp, The_Async_Arena());
95  FArrayBox fz(surroundingNodes(bx,2), ncomp, The_Async_Arena());
96  fx.setVal<RunOn::Device>(0.0);
97  fy.setVal<RunOn::Device>(0.0);
98 
99  const auto down = sf.down->const_array(mfi);
100  const auto mx = mfx.const_array(mfi);
101  const auto my = mfy.const_array(mfi);
102  const auto f = fz.array();
103  ParallelFor(fz.box(), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
104  {
105  f(i,j,k,n) = -down(i,j,k,n) * inv_dt / (mx(i,j,0) * my(i,j,0));
106  });
107 
108  const std::array<FArrayBox const*, AMREX_SPACEDIM> flux{{&fx, &fy, &fz}};
109  for (int n = 0; n < ncomp; ++n) {
110  if (as_crse) {
111  fr.CrseAdd(mfi, flux, geom.CellSize(), sf.dt, n, sf.cons_comp[n], 1, RunOn::Device);
112  } else {
113  fr.FineAdd(mfi, flux, geom.CellSize(), sf.dt, n, sf.cons_comp[n], 1, RunOn::Device);
114  }
115  }
116  // The fluxes live in temporaries: finish with them before the next box
117  Gpu::streamSynchronize();
118  }
119 }
@ fr
Definition: ERF_AdvanceMorrison.cpp:108
@ cons
Definition: ERF_IndexDefines.H:231
amrex::Vector< int > cons_comp
Definition: ERF_SedimentationFlux.H:40

Referenced by ERF::advance_microphysics().

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