ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SedimentationFlux.H
Go to the documentation of this file.
1 /*! @file ERF_SedimentationFlux.H
2  * \brief The sedimentation face fluxes a precipitating microphysics scheme records
3  */
4 
5 #ifndef ERF_SEDIMENTATIONFLUX_H
6 #define ERF_SEDIMENTATIONFLUX_H
7 
8 #include <memory>
9 
10 #include <AMReX_MultiFab.H>
11 #include <AMReX_Vector.H>
12 
13 /**
14  * The hydrometeors a microphysics scheme moved across each z-face by sedimentation during
15  * its most recent Advance on a level.
16  *
17  * down(i,j,k,n) is the amount of the conserved state component cons_comp[n] (rho*q, so
18  * kg m^-3 for a mixing ratio and m^-3 for a number concentration) that crossed z-face
19  * (i,j,k) downward during that Advance, per unit horizontal area: kg m^-2 or m^-2. Face k
20  * is the bottom face of cell k, so the face at the domain bottom holds what reached the
21  * ground. down is defined on the level's grids, z-nodal, and is zeroed at the start of
22  * every Advance.
23  *
24  * A scheme records the fluxes its cell updates actually used, so that (up to the clipping
25  * of negative values) the change of rho*q*dz in a cell is down on its top face minus down on
26  * its bottom face. Schemes whose sedimentation has no face fluxes of its own (the
27  * semi-Lagrangian WSM6/WDM6 solvers) reconstruct them with sedimentation_add_column_sums below.
28  */
29 /**
30  * The inflow a fine patch receives through its top face, handed to a scheme for one Advance
31  * (NullMoist::Set_Sed_Inflow). It is z-nodal on the level's grids, with the components of
32  * the level's SedimentationFlux plus a flag, comp inflow_flag_comp(): where the flag is 1,
33  * face (i,j,k) is the top of a fine column that stops short of the domain top, and
34  * component n holds the amount of cons_comp[n] entering through it during the Advance, per
35  * unit horizontal area (as SedimentationFlux::down). Elsewhere everything is zero.
36  */
38 {
39  std::shared_ptr<amrex::MultiFab> down;
40  amrex::Vector<int> cons_comp;
41  amrex::Real dt = 0.0;
42 
43  void define (const amrex::BoxArray& cc_ba, const amrex::DistributionMapping& dm,
44  const amrex::Vector<int>& a_cons_comp)
45  {
46  cons_comp = a_cons_comp;
47  down = std::make_shared<amrex::MultiFab>(amrex::convert(cc_ba, amrex::IntVect(0,0,1)), dm,
48  static_cast<int>(cons_comp.size()), 0);
49  down->setVal(0.0);
50  dt = 0.0;
51  }
52 
53  //! The component of a sedimentation inflow (see above) that flags the faces it applies at
54  [[nodiscard]] int inflow_flag_comp () const { return static_cast<int>(cons_comp.size()); }
55 
56  //! Zero the fluxes at the start of an Advance of length a_dt
57  void reset (amrex::Real a_dt)
58  {
59  if (down) { down->setVal(0.0); }
60  dt = a_dt;
61  }
62 };
63 
64 /**
65  * Add sign * (sum over m = k..khi of w(m)) to sed(i,j,k,n) for every k in [klo, khi].
66  *
67  * Called with sign = +1 and w(m) = rho*q*dz before a sedimentation step and with sign = -1
68  * and the same w after it, this adds to each face k the mass that crossed it downward: what
69  * the cells above it lost. The face above khi gets nothing (no inflow).
70  */
71 template <typename F>
72 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
73 void
74 sedimentation_add_column_sums (const amrex::Array4<amrex::Real>& sed, int n,
75  int i, int j, int klo, int khi, amrex::Real sign, F&& w) noexcept
76 {
77  amrex::Real sum = 0.0;
78  for (int k = khi; k >= klo; --k) {
79  sum += w(k);
80  sed(i,j,k,n) += sign * sum;
81  }
82 }
83 
84 #endif
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
Real w
Definition: ERF_Plotfile2DInterpolator.cpp:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void sedimentation_add_column_sums(const amrex::Array4< amrex::Real > &sed, int n, int i, int j, int klo, int khi, amrex::Real sign, F &&w) noexcept
Definition: ERF_SedimentationFlux.H:74
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_SedimentationFlux.H:38
amrex::Real dt
Definition: ERF_SedimentationFlux.H:41
int inflow_flag_comp() const
The component of a sedimentation inflow (see above) that flags the faces it applies at.
Definition: ERF_SedimentationFlux.H:54
std::shared_ptr< amrex::MultiFab > down
Definition: ERF_SedimentationFlux.H:39
amrex::Vector< int > cons_comp
Definition: ERF_SedimentationFlux.H:40
void define(const amrex::BoxArray &cc_ba, const amrex::DistributionMapping &dm, const amrex::Vector< int > &a_cons_comp)
Definition: ERF_SedimentationFlux.H:43
void reset(amrex::Real a_dt)
Zero the fluxes at the start of an Advance of length a_dt.
Definition: ERF_SedimentationFlux.H:57