ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
Kessler Class Reference

#include <ERF_Kessler.H>

Inheritance diagram for Kessler:
Collaboration diagram for Kessler:

Public Member Functions

 Kessler ()
 
virtual ~Kessler ()=default
 
void AdvanceKessler (const SolverChoice &solverChoice)
 
void Define (SolverChoice &sc) override
 
void Init (const amrex::MultiFab &cons_in, const amrex::BoxArray &grids, const amrex::Geometry &geom, const amrex::Real &dt_advance, std::unique_ptr< amrex::MultiFab > &z_phys_nd, std::unique_ptr< amrex::MultiFab > &detJ_cc) override
 
void Copy_State_to_Micro (const amrex::MultiFab &cons_in) override
 
void Copy_State_to_Micro (const amrex::MultiFab &cons_in, const amrex::MultiFab *base_state)
 
void Update_Micro_Vars (amrex::MultiFab &cons_in, const amrex::MultiFab *base_state) override
 
void Copy_Micro_to_State (amrex::MultiFab &cons_in) override
 
void Update_Micro_Vars (amrex::MultiFab &cons_in) override
 
void Update_State_Vars (amrex::MultiFab &cons_in, const amrex::MultiFab &) override
 
void Advance (const amrex::Real &dt_advance, const SolverChoice &solverChoice) override
 
const SedimentationFlux * Sed_Flux () const override
 The sedimentation face fluxes of the most recent Advance, or null for a scheme that does not sediment (see ERF_SedimentationFlux.H) More...
 
amrex::MultiFab * Qmoist_Ptr (const int &varIdx) override
 
int Qmoist_Size () override
 
int Qstate_Moist_Size () override
 
int Qstate_Moist_NumConc_Size () override
 
void Qmoist_Restart_Vars (const SolverChoice &, std::vector< int > &a_idx, std::vector< std::string > &a_names) const override
 
SurfacePrecipAccumulationSources Get_Surface_Precip_Accumulation_Ptrs (const int &) const override
 
- Public Member Functions inherited from NullMoist
 NullMoist ()
 
virtual ~NullMoist ()=default
 
virtual int Qstate_NonMoist_Size ()
 
virtual void GetPlotVarNames (amrex::Vector< std::string > &a_vec) const
 
virtual void GetPlotVar (const std::string &, amrex::MultiFab &) const
 
virtual void GetPlotVar (const std::string &a_name, amrex::MultiFab &a_mf, const int) const
 
virtual void SetCurrentLevel (const int &lev)
 
virtual void InitLevel (const int, const amrex::MultiFab &)
 
virtual int getDiagnosticsInterval () const
 
virtual void Set_dzmin (const amrex::Real)
 
virtual void Set_Lmask (amrex::iMultiFab *)
 Import ERF's land/water mask. Only schemes whose physics branches on land vs water need to override this. More...
 
virtual void Set_Sed_Inflow (const amrex::MultiFab *inflow)
 The inflow through the top of a fine patch for the next Advance, or null (see ERF_SedimentationFlux.H); the caller keeps it alive for that Advance. More...
 
virtual void Set_RealWidth (const int)
 

Private Types

using FabPtr = std::shared_ptr< amrex::MultiFab >
 

Private Attributes

int m_qmoist_size = 1
 
int n_qstate_moist_size = 3
 
int n_qstate_moist_numconc_size = 0
 
amrex::Vector< int > MicVarMap
 
amrex::Geometry m_geom
 
amrex::Real dt
 
int nlev
 
int zlo
 
int zhi
 
amrex::Real m_fac_cond
 
amrex::Real m_rdOcp {RdoCp}
 
bool m_do_cond
 
MoistureType m_moisture_type = MoistureType::None
 
amrex::MultiFab * m_z_phys_nd
 
amrex::MultiFab * m_detJ_cc
 
amrex::Array< FabPtr, MicVar_Kess::NumVars > mic_fab_vars
 
SedimentationFlux m_sed
 

Static Private Attributes

static constexpr amrex::Real CFL_MAX = kessler_sedimentation_cfl_max
 

Additional Inherited Members

- Protected Member Functions inherited from NullMoist
void set_anelastic_reference_pressure_mode (const SolverChoice &sc)
 
void assert_base_state_available (const amrex::MultiFab *base_state) const
 
- Protected Attributes inherited from NullMoist
const amrex::MultiFab * m_sed_inflow = nullptr
 
int m_level {0}
 
bool m_use_anelastic_reference_pressure {false}
 

Member Typedef Documentation

◆ FabPtr

using Kessler::FabPtr = std::shared_ptr<amrex::MultiFab>
private

Constructor & Destructor Documentation

◆ Kessler()

Kessler::Kessler ( )
inline
84 {}

◆ ~Kessler()

virtual Kessler::~Kessler ( )
virtualdefault

Member Function Documentation

◆ Advance()

void Kessler::Advance ( const amrex::Real &  dt_advance,
const SolverChoice &  solverChoice 
)
inlineoverridevirtual

Reimplemented from NullMoist.

149  {
150  dt = dt_advance;
151  m_sed.reset(dt_advance);
152 
153  this->AdvanceKessler(solverChoice);
154  }
amrex::Real dt
Definition: ERF_Kessler.H:218
SedimentationFlux m_sed
Definition: ERF_Kessler.H:237
void AdvanceKessler(const SolverChoice &solverChoice)
Definition: ERF_Kessler.cpp:17
void reset(amrex::Real a_dt)
Zero the fluxes at the start of an Advance of length a_dt.
Definition: ERF_SedimentationFlux.H:57
Here is the call graph for this function:

◆ AdvanceKessler()

void Kessler::AdvanceKessler ( const SolverChoice &  solverChoice)

Compute Precipitation-related Microphysics quantities.

18 {
19  bool do_cond = m_do_cond;
21  auto domain = m_geom.Domain();
22  int k_lo = domain.smallEnd(2);
23  int k_hi = domain.bigEnd(2);
24  if (solverChoice.moisture_type == MoistureType::Kessler)
25  {
26  MultiFab fz;
27  auto ba = tabs->boxArray();
28  auto dm = tabs->DistributionMap();
29  fz.define(convert(ba, IntVect(0,0,1)), dm, 1, 0); // No ghost cells
30 
31  Real dtn = dt;
32  // NOTE: coef carries only the reference vertical spacing. The physical
33  // spacing is supplied by the inverse Jacobian in the tendency below,
34  // since detJ = dz_phys/CellSize(2). Dividing by dz_phys here as well
35  // would apply the vertical metric twice.
36  Real coef = dtn * m_geom.InvCellSize(2);
37 
38  for ( MFIter mfi(*tabs,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
39  auto qv_array = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
40  auto qc_array = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
41  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
42  auto qt_array = mic_fab_vars[MicVar_Kess::qt]->array(mfi);
43  auto tabs_array = mic_fab_vars[MicVar_Kess::tabs]->array(mfi);
44  auto pres_array = mic_fab_vars[MicVar_Kess::pres]->array(mfi);
45  auto theta_array = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
46  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
47 
48  auto tbx = mfi.tilebox();
49 
50  Real d_fac_cond = m_fac_cond;
51 
52  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
53  {
54  qv_array(i,j,k) = std::max(Real(0), qv_array(i,j,k));
55  qc_array(i,j,k) = std::max(Real(0), qc_array(i,j,k));
56  qp_array(i,j,k) = std::max(Real(0), qp_array(i,j,k));
57 
58  Real qsat_local, dtqsat_local;
59  Real pressure = pres_array(i,j,k);
60  // Kessler stores pressure in mbar / hPa for the qsat helpers.
61  erf_qsatw(tabs_array(i,j,k), pressure, qsat_local);
62  erf_dtqsatw(tabs_array(i,j,k), pressure, dtqsat_local);
63 
64  if (qsat_local <= Real(0)) {
65  amrex::Warning("qsat computed as non-positive; setting to Real(0)!");
66  qsat_local = Real(0);
67  }
68 
69  const KesslerSourceTerms source_terms = kessler_warm_rain_sources(
70  qv_array(i,j,k), qc_array(i,j,k), qp_array(i,j,k), rho_array(i,j,k),
71  pressure, qsat_local, dtqsat_local, dtn, do_cond, d_fac_cond);
72 
73  qv_array(i,j,k) += -source_terms.dq_vapor_to_cloud
74  + source_terms.dq_cloud_to_vapor
75  + source_terms.dq_rain_to_vapor;
76  qc_array(i,j,k) += source_terms.dq_vapor_to_cloud
77  - source_terms.dq_cloud_to_vapor
78  - source_terms.dq_cloud_to_rain;
79  qp_array(i,j,k) += source_terms.dq_cloud_to_rain
80  - source_terms.dq_rain_to_vapor;
81 
82  Real theta_over_T = theta_array(i,j,k)/tabs_array(i,j,k);
83  theta_array(i,j,k) += theta_over_T * d_fac_cond
84  * (source_terms.dq_vapor_to_cloud
85  - source_terms.dq_cloud_to_vapor
86  - source_terms.dq_rain_to_vapor);
87 
88  qv_array(i,j,k) = std::max(Real(0), qv_array(i,j,k));
89  qc_array(i,j,k) = std::max(Real(0), qc_array(i,j,k));
90  qp_array(i,j,k) = std::max(Real(0), qp_array(i,j,k));
91 
92  qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
93  });
94  }
95 
96  for ( MFIter mfi(fz, TilingIfNotGPU()); mfi.isValid(); ++mfi ){
97  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
98  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
99 
100  auto fz_array = fz.array(mfi);
101  const Box& tbz = mfi.tilebox();
102 
103  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
104  {
105  const Real rho_km1 = (k == k_lo) ? rho_array(i,j,k) : rho_array(i,j,k-1);
106  const Real rho_k = (k == k_hi+1) ? rho_array(i,j,k-1) : rho_array(i,j,k);
107  const Real qp_km1 = (k == k_lo) ? qp_array(i,j,k) : qp_array(i,j,k-1);
108  const Real qp_k = (k == k_hi+1) ? qp_array(i,j,k-1) : qp_array(i,j,k);
109  const KesslerFaceState face_state =
110  kessler_face_state(k, k_hi, rho_km1, rho_k, qp_km1, qp_k);
111 
112  const Real terminal_velocity = kessler_terminal_velocity(face_state.rho, face_state.qp);
113  fz_array(i,j,k) = kessler_precip_flux(face_state.rho, terminal_velocity, face_state.qp);
114  });
115  }
116 
117  auto const& ma_rho_arr = mic_fab_vars[MicVar_Kess::rho]->const_arrays();
118  auto const& ma_qp_arr = mic_fab_vars[MicVar_Kess::qp]->const_arrays();
119  // The sedimentation CFL uses fall speed, not precipitating mass flux.
120  // fz stores rho * Vt * qp for the flux divergence below, so the reduction
121  // recomputes Vt from the same face state used for the flux. Each face is checked
122  // against the physical height of the cell it drains, as the limiter below is, so
123  // fast rain aloft in tall cells is not sized by the thinnest cell near the ground.
124  // A face inside the domain is also checked against the cell below it, the one its
125  // rain falls into (kessler_sizing_detJ): the count is fixed here, at the start of
126  // the step, while the cells below the rain front are still dry, and this covers the
127  // first cell the front enters. Beyond that the donor cap in the substep loop
128  // (kessler_limit_precip_flux) is the backstop and keeps qp non-negative. At the
129  // bottom of a box that does not touch the ground the cell below is a ghost cell;
130  // detJ_cc has one, filled by make_J.
131  // On an EB mesh detJ is the volume fraction, not a cell height, so the sizing uses
132  // the reference dz there (J = 1). The limiter and the tendency below still use the
133  // volume fraction, so small cut cells can be donor-capped.
134  const auto ma_dJ = (m_detJ_cc && solverChoice.terrain_type != TerrainType::EB)
135  ? m_detJ_cc->const_arrays() : MultiArray4<const Real>{};
136  const Real dz_ref = m_geom.CellSize(2);
137  const Real dt_full = dt;
138  GpuTuple<Real> max_courant_tuple = ParReduce(TypeList<ReduceOpMax>{},
139  TypeList<Real>{},
140  fz, IntVect(0),
141  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
142  -> GpuTuple<Real>
143  {
144  const auto& rho_arr = ma_rho_arr[box_no];
145  const auto& qp_arr = ma_qp_arr[box_no];
146  const Real rho_km1 = (k == k_lo) ? rho_arr(i,j,k) : rho_arr(i,j,k-1);
147  const Real rho_k = (k == k_hi+1) ? rho_arr(i,j,k-1) : rho_arr(i,j,k);
148  const Real qp_km1 = (k == k_lo) ? qp_arr(i,j,k) : qp_arr(i,j,k-1);
149  const Real qp_k = (k == k_hi+1) ? qp_arr(i,j,k-1) : qp_arr(i,j,k);
150  const KesslerFaceState face_state =
151  kessler_face_state(k, k_hi, rho_km1, rho_k, qp_km1, qp_k);
152  const int donor_k = kessler_face_donor_k(k, k_hi);
153  const Real detJ_donor = (ma_dJ) ? ma_dJ[box_no](i,j,donor_k) : Real(1);
154  const Real detJ_below = (ma_dJ && k > k_lo) ? ma_dJ[box_no](i,j,k-1) : detJ_donor;
155  return { kessler_fall_courant(
156  kessler_terminal_velocity(face_state.rho, face_state.qp),
157  dt_full, dz_ref,
158  kessler_sizing_detJ(k, k_lo, k_hi, detJ_donor, detJ_below)) };
159  });
160  Real max_courant = get<0>(max_courant_tuple);
161  //
162  // ParReduce over a MultiFab gives the local rank maximum here. Every rank must
163  // arrive at the SAME substep count: otherwise different parts of the domain
164  // advance with different effective timesteps, the answer depends on the number
165  // of ranks, and the ranks make different numbers of the collective FillBoundary
166  // calls in the substep loop below. A rank owning no boxes would also see
167  // ReduceOpMax's lowest() initial value here. (SAM's PrecipFall does this same
168  // reduction for the same reasons.)
169  //
170  ParallelDescriptor::ReduceRealMax(max_courant);
171 
172  //
173  // A NaN or infinite Courant number, or one that asks for more substeps than any
174  // healthy state does, means the rain or density handed in is not usable; name
175  // the cause here rather than casting it to an int.
176  //
177  if (!std::isfinite(max_courant) ||
179  std::ostringstream message;
180  message.precision(17);
181  message << "Kessler: cannot size the rain sedimentation substeps: the largest fall"
182  << " Courant number is " << max_courant << " (dt=" << dt
183  << ", dz=" << dz_ref << "), which would need more than "
184  << kessler_max_sedimentation_substeps << " substeps."
185  << " The rain or density handed to the sedimentation is not usable.";
186  Abort(message.str());
187  }
188 
189  int n_substep = kessler_num_sedimentation_substeps(max_courant);
190  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(n_substep >= 1,
191  "Kessler: Number of precipitation substeps must be greater than 0!");
192  coef /= Real(n_substep);
193  dtn /= Real(n_substep);
194 
195  for (int nsub(0); nsub<n_substep; ++nsub)
196  {
197  // The face state and the donor-cap limiter read rho/qp at k-1, which is a ghost
198  // cell whenever a box boundary is interior in z. The previous substep updated qp
199  // in valid cells only, so refresh ghosts here; otherwise the two sides of a
200  // shared z face see different donor values and the column budget does not close.
201  mic_fab_vars[MicVar_Kess::qp]->FillBoundary(m_geom.periodicity());
202 
203  for ( MFIter mfi(*tabs, TileNoZ()); mfi.isValid(); ++mfi ){
204  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
205  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
206  auto rain_accum_array = mic_fab_vars[MicVar_Kess::rain_accum]->array(mfi);
207  auto fz_array = fz.array(mfi);
208  auto sed_array = m_sed.down->array(mfi);
209  const auto inflow_array = (m_sed_inflow) ? m_sed_inflow->const_array(mfi)
210  : Array4<const Real>{};
211  const int inflow_flag = m_sed.inflow_flag_comp();
212  const Real inv_dt = Real(1) / dt;
213 
214  const auto dJ_array = (m_detJ_cc) ? m_detJ_cc->const_array(mfi) : Array4<const Real>{};
215 
216  const Box& tbx = mfi.tilebox();
217  const Box& tbz = mfi.tilebox(IntVect(0,0,1),IntVect(0));
218 
219  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
220  {
221  const Real rho_km1 = (k == k_lo) ? rho_array(i,j,k) : rho_array(i,j,k-1);
222  const Real rho_k = (k == k_hi+1) ? rho_array(i,j,k-1) : rho_array(i,j,k);
223  const Real qp_km1 = (k == k_lo) ? qp_array(i,j,k) : qp_array(i,j,k-1);
224  const Real qp_k = (k == k_hi+1) ? qp_array(i,j,k-1) : qp_array(i,j,k);
225  const int donor_k = kessler_face_donor_k(k, k_hi);
226  const KesslerFaceState face_state =
227  kessler_face_state(k, k_hi, rho_km1, rho_k, qp_km1, qp_k);
228 
229  const Real terminal_velocity = kessler_terminal_velocity(face_state.rho, face_state.qp);
230  const Real donor_rho = rho_array(i,j,donor_k);
231  const Real donor_qp = std::max(Real(0), qp_array(i,j,donor_k));
232  const Real donor_detJ = (dJ_array) ? dJ_array(i,j,donor_k) : Real(1);
233  // The face flux uses face rho and donor qp. The limiter uses donor rho,
234  // donor qp, and donor detJ because it caps how much rain can leave the donor
235  // cell in this substep.
236  // Cap outgoing flux by the donor cell's detJ-weighted available rain water:
237  // F * dt / dz <= rho_donor * qp_donor * detJ_donor.
238  // This keeps compressed cells from losing more rain than they contain.
239  fz_array(i,j,k) = kessler_limit_precip_flux(
240  kessler_precip_flux(face_state.rho, terminal_velocity, face_state.qp),
241  donor_rho, donor_qp, donor_detJ, coef);
242 
243  // At the top of a fine patch the rain coming in is the coarse level's
244  // flux through that face, not one built from interpolated ghost cells
245  if (inflow_array && inflow_array(i,j,k,inflow_flag) > Real(0.5)) {
246  fz_array(i,j,k) = inflow_array(i,j,k,0) * inv_dt;
247  }
248 
249  // Record the flux the cell update below uses, after its small-value cutoff
250  if (!kessler_is_small_sedimentation_value(fz_array(i,j,k))) {
251  sed_array(i,j,k,0) += fz_array(i,j,k) * dtn;
252  }
253 
254  if(k==k_lo){
255  // Surface accumulation stores the bottom-face precipitation mass per area
256  // increment converted to liquid-water depth.
257  rain_accum_array(i,j,k) = rain_accum_array(i,j,k)
258  + kessler_rain_accumulation_increment(fz_array(i,j,k) * dtn);
259  }
260  });
261 
262  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
263  {
264  Real dJinv = (dJ_array) ? Real(1)/dJ_array(i,j,k) : Real(1);
265 
266  // Threshold local face-flux copies only. Neighboring cells share fz
267  // faces, so the cell update must not mutate fz while applying the
268  // small-value cutoff.
269  Real f_hi = fz_array(i,j,k+1);
270  Real f_lo = fz_array(i,j,k );
271 
273  f_hi = Real(0);
274  }
276  f_lo = Real(0);
277  }
278  Real dq_sed = kessler_sedimentation_tendency(
279  f_hi, f_lo, rho_array(i,j,k), dJinv, coef);
281  dq_sed = Real(0);
282  }
283 
284  qp_array(i,j,k) += dq_sed;
285  qp_array(i,j,k) = std::max(Real(0), qp_array(i,j,k));
286  });
287  }
288  }
289  }
290 
291  if (solverChoice.moisture_type == MoistureType::Kessler_NoRain) {
292  if (!do_cond) { return; }
293  for ( MFIter mfi(*tabs,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
294  auto qv_array = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
295  auto qc_array = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
296  auto qt_array = mic_fab_vars[MicVar_Kess::qt]->array(mfi);
297  auto tabs_array = mic_fab_vars[MicVar_Kess::tabs]->array(mfi);
298  auto theta_array = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
299  auto pres_array = mic_fab_vars[MicVar_Kess::pres]->array(mfi);
300 
301  auto tbx = mfi.tilebox();
302 
303  Real d_fac_cond = m_fac_cond;
304 
305  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
306  {
307  qc_array(i,j,k) = std::max(Real(0), qc_array(i,j,k));
308 
309  Real qsat, dtqsat;
310 
311  Real pressure = pres_array(i,j,k);
312  // Kessler stores pressure in mbar / hPa for the qsat helpers.
313  erf_qsatw(tabs_array(i,j,k), pressure, qsat);
314  erf_dtqsatw(tabs_array(i,j,k), pressure, dtqsat);
315 
316  const KesslerSaturationAdjustment saturation_adjustment =
317  kessler_saturation_adjustment(qv_array(i,j,k), qc_array(i,j,k), qsat, dtqsat,
318  do_cond, d_fac_cond);
319 
320  qv_array(i,j,k) += -saturation_adjustment.dq_vapor_to_cloud
321  + saturation_adjustment.dq_cloud_to_vapor;
322  qc_array(i,j,k) += saturation_adjustment.dq_vapor_to_cloud
323  - saturation_adjustment.dq_cloud_to_vapor;
324 
325  Real theta_over_T = theta_array(i,j,k)/tabs_array(i,j,k);
326  theta_array(i,j,k) += theta_over_T * d_fac_cond
327  * (saturation_adjustment.dq_vapor_to_cloud - saturation_adjustment.dq_cloud_to_vapor);
328 
329  qv_array(i,j,k) = std::max(Real(0), qv_array(i,j,k));
330  qc_array(i,j,k) = std::max(Real(0), qc_array(i,j,k));
331 
332  qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
333  });
334  }
335  }
336 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
std::string message
Definition: ERF_InputPreflight.cpp:25
static constexpr int kessler_max_sedimentation_substeps
Definition: ERF_KesslerUtils.H:34
static constexpr amrex::Real kessler_sedimentation_cfl_max
Definition: ERF_KesslerUtils.H:32
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE KesslerSaturationAdjustment kessler_saturation_adjustment(const amrex::Real qv, const amrex::Real qc, const amrex::Real qsat, const amrex::Real dtqsat, const bool do_cond, const amrex::Real latent_over_cp) noexcept
Definition: ERF_KesslerUtils.H:142
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_sizing_detJ(const int k, const int k_lo, const int k_hi, const amrex::Real detJ_donor, const amrex::Real detJ_below) noexcept
Definition: ERF_KesslerUtils.H:109
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE KesslerSourceTerms kessler_warm_rain_sources(const amrex::Real qv, const amrex::Real qc, const amrex::Real qp, const amrex::Real rho, const amrex::Real pressure_current_units, const amrex::Real qsat, const amrex::Real dtqsat, const amrex::Real dt, const bool do_cond, const amrex::Real latent_over_cp) noexcept
Definition: ERF_KesslerUtils.H:210
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_fall_courant(const amrex::Real terminal_velocity, const amrex::Real dt, const amrex::Real dz, const amrex::Real detJ_donor) noexcept
Definition: ERF_KesslerUtils.H:98
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_limit_precip_flux(const amrex::Real flux, const amrex::Real donor_rho, const amrex::Real donor_qp, const amrex::Real donor_detJ, const amrex::Real coef) noexcept
Definition: ERF_KesslerUtils.H:71
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_sedimentation_tendency(const amrex::Real fz_hi, const amrex::Real fz_lo, const amrex::Real rho, const amrex::Real dJinv, const amrex::Real coef) noexcept
Definition: ERF_KesslerUtils.H:199
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_terminal_velocity(const amrex::Real rho, const amrex::Real qp) noexcept
Definition: ERF_KesslerUtils.H:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_rain_accumulation_increment(const amrex::Real precip_mass_per_area) noexcept
Definition: ERF_KesslerUtils.H:125
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE KesslerFaceState kessler_face_state(const int k, const int k_hi, const amrex::Real rho_km1, const amrex::Real rho_k, const amrex::Real, const amrex::Real qp_k) noexcept
Definition: ERF_KesslerUtils.H:167
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_precip_flux(const amrex::Real rho, const amrex::Real terminal_velocity, const amrex::Real qp) noexcept
Definition: ERF_KesslerUtils.H:63
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int kessler_num_sedimentation_substeps(const amrex::Real max_courant) noexcept
Definition: ERF_KesslerUtils.H:83
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool kessler_is_small_sedimentation_value(const amrex::Real value) noexcept
Definition: ERF_KesslerUtils.H:135
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int kessler_face_donor_k(const int k, const int k_hi) noexcept
Definition: ERF_KesslerUtils.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsatw(amrex::Real t, amrex::Real p, amrex::Real &dtqsatw)
Definition: ERF_MicrophysicsUtils.H:281
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:265
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_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
auto rho_arr
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:3
amrex::Geometry m_geom
Definition: ERF_Kessler.H:215
amrex::MultiFab * m_detJ_cc
Definition: ERF_Kessler.H:231
amrex::Real m_fac_cond
Definition: ERF_Kessler.H:224
bool m_do_cond
Definition: ERF_Kessler.H:226
amrex::Array< FabPtr, MicVar_Kess::NumVars > mic_fab_vars
Definition: ERF_Kessler.H:234
const amrex::MultiFab * m_sed_inflow
Definition: ERF_NullMoist.H:168
@ qp
Definition: ERF_Kessler.H:34
@ qcl
Definition: ERF_Kessler.H:32
@ tabs
Definition: ERF_Kessler.H:27
@ pres
Definition: ERF_Kessler.H:28
@ rho
Definition: ERF_Kessler.H:25
@ theta
Definition: ERF_Kessler.H:26
@ qt
Definition: ERF_Kessler.H:30
@ rain_accum
Definition: ERF_Kessler.H:36
@ qv
Definition: ERF_Kessler.H:31
Definition: ERF_KesslerUtils.H:27
amrex::Real rho
Definition: ERF_KesslerUtils.H:28
amrex::Real qp
Definition: ERF_KesslerUtils.H:29
Definition: ERF_KesslerUtils.H:22
amrex::Real dq_cloud_to_vapor
Definition: ERF_KesslerUtils.H:24
amrex::Real dq_vapor_to_cloud
Definition: ERF_KesslerUtils.H:23
Definition: ERF_KesslerUtils.H:15
amrex::Real dq_rain_to_vapor
Definition: ERF_KesslerUtils.H:19
amrex::Real dq_cloud_to_vapor
Definition: ERF_KesslerUtils.H:17
amrex::Real dq_cloud_to_rain
Definition: ERF_KesslerUtils.H:18
amrex::Real dq_vapor_to_cloud
Definition: ERF_KesslerUtils.H:16
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
MoistureType moisture_type
Moisture or microphysics model.
Definition: ERF_DataStruct.H:3433
static TerrainType terrain_type
Terrain or immersed-boundary representation.
Definition: ERF_DataStruct.H:2989

Referenced by Advance().

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

◆ Copy_Micro_to_State()

void Kessler::Copy_Micro_to_State ( amrex::MultiFab &  cons_in)
overridevirtual

Updates conserved and microphysics variables in the provided MultiFabs from the internal MultiFabs that store Microphysics module data.

Parameters
[out]consConserved variables
[out]qmoistqv, qc, qi, qr, qs, qg

Reimplemented from NullMoist.

15 {
16  // Get the temperature, density, theta, qt and qp from input
17  for ( MFIter mfi(cons,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
18  const auto& box3d = mfi.tilebox();
19 
20  auto states_arr = cons.array(mfi);
21 
22  auto rho_arr = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
23  auto theta_arr = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
24  auto qv_arr = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
25  auto qc_arr = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
26  auto qp_arr = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
27 
28  // get potential total density, temperature, qt, qp
29  ParallelFor( box3d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
30  {
31  states_arr(i,j,k,RhoTheta_comp) = rho_arr(i,j,k)*theta_arr(i,j,k);
32  states_arr(i,j,k,RhoQ1_comp) = rho_arr(i,j,k)*qv_arr(i,j,k);
33  states_arr(i,j,k,RhoQ2_comp) = rho_arr(i,j,k)*qc_arr(i,j,k);
34  states_arr(i,j,k,RhoQ3_comp) = rho_arr(i,j,k)*qp_arr(i,j,k);
35  });
36  }
37 
38  // Fill interior ghost cells and periodic boundaries
39  cons.FillBoundary(m_geom.periodicity());
40 }
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:79
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:80
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
auto qv_arr
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:222
@ cons
Definition: ERF_IndexDefines.H:231

Referenced by Update_State_Vars().

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

◆ Copy_State_to_Micro() [1/2]

void Kessler::Copy_State_to_Micro ( const amrex::MultiFab &  cons_in)
overridevirtual

Reimplemented from NullMoist.

Referenced by Update_Micro_Vars().

Here is the caller graph for this function:

◆ Copy_State_to_Micro() [2/2]

void Kessler::Copy_State_to_Micro ( const amrex::MultiFab &  cons_in,
const amrex::MultiFab *  base_state 
)

◆ Define()

void Kessler::Define ( SolverChoice &  sc)
inlineoverridevirtual

Reimplemented from NullMoist.

95  {
97  // Use one latent-over-cp factor for both the saturation solve and theta
98  // update. L_v comes from ERF_Constants.H; c_p comes from SolverChoice.
99  m_fac_cond = L_v / sc.c_p;
100  m_rdOcp = sc.rdOcp;
101  m_do_cond = (!sc.uses_shoc_family());
103  }
constexpr amrex::Real L_v
Definition: ERF_Constants.H:67
MoistureType m_moisture_type
Definition: ERF_Kessler.H:227
amrex::Real m_rdOcp
Definition: ERF_Kessler.H:225
void set_anelastic_reference_pressure_mode(const SolverChoice &sc)
Definition: ERF_NullMoist.H:171
amrex::Real rdOcp
Ratio of dry-air gas constant to c_p.
Definition: ERF_DataStruct.H:3150
bool uses_shoc_family() const noexcept
Query whether any SHOC-family PBL scheme is active.
Definition: ERF_DataStruct.H:3357
amrex::Real c_p
Specific heat at constant pressure for dry air [J/(kg-K)].
Definition: ERF_DataStruct.H:3149
Here is the call graph for this function:

◆ Get_Surface_Precip_Accumulation_Ptrs()

SurfacePrecipAccumulationSources Kessler::Get_Surface_Precip_Accumulation_Ptrs ( const int &  ) const
inlineoverridevirtual

Reimplemented from NullMoist.

188  {
189  if (m_moisture_type == MoistureType::Kessler_NoRain) {
190  return {};
191  }
192 
194  sources.rain = {mic_fab_vars[MicVar_Kess::rain_accum].get(), rhor / amrex::Real(1000.0)};
195  return sources;
196  }
constexpr amrex::Real rhor
Definition: ERF_MicrophysicsConstants.H:39
Definition: ERF_SurfacePrecipitation.H:40
SurfacePrecipAccumulationSource rain
Definition: ERF_SurfacePrecipitation.H:42

◆ Init()

void Kessler::Init ( const amrex::MultiFab &  cons_in,
const amrex::BoxArray &  grids,
const amrex::Geometry &  geom,
const amrex::Real &  dt_advance,
std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
std::unique_ptr< amrex::MultiFab > &  detJ_cc 
)
overridevirtual

Initializes the Microphysics module.

Parameters
[in]cons_inConserved variables input
[in]qc_inCloud variables input
[in,out]qv_inVapor variables input
[in]qi_inIce variables input
[in]gridsThe boxes on which we will evolve the solution
[in]geomGeometry associated with these MultiFabs and grids
[in]dt_advanceTimestep for the advance

Reimplemented from NullMoist.

27 {
28  dt = dt_advance;
29  m_geom = geom;
30 
31  m_z_phys_nd = z_phys_nd.get();
32  m_detJ_cc = detJ_cc.get();
33 
34  MicVarMap.resize(m_qmoist_size);
36 
37  // initialize microphysics variables
38  for (auto ivar = 0; ivar < MicVar_Kess::NumVars; ++ivar) {
39  mic_fab_vars[ivar] = std::make_shared<MultiFab>(cons_in.boxArray(), cons_in.DistributionMap(),
40  1, cons_in.nGrowVect());
41  mic_fab_vars[ivar]->setVal(0.);
42  }
43 
44  m_sed.define(cons_in.boxArray(), cons_in.DistributionMap(), {RhoQ3_comp});
45 
46  // Set class data members
47  for ( MFIter mfi(cons_in, TileNoZ()); mfi.isValid(); ++mfi) {
48  const auto& box3d = mfi.tilebox();
49 
50  const auto& lo = lbound(box3d);
51  const auto& hi = ubound(box3d);
52 
53  nlev = box3d.length(2);
54  zlo = lo.z;
55  zhi = hi.z;
56  }
57 }
int zlo
Definition: ERF_Kessler.H:221
amrex::Vector< int > MicVarMap
Definition: ERF_Kessler.H:212
int zhi
Definition: ERF_Kessler.H:221
int nlev
Definition: ERF_Kessler.H:221
amrex::MultiFab * m_z_phys_nd
Definition: ERF_Kessler.H:230
int m_qmoist_size
Definition: ERF_Kessler.H:200
@ NumVars
Definition: ERF_Kessler.H:37
void define(const amrex::BoxArray &cc_ba, const amrex::DistributionMapping &dm, const amrex::Vector< int > &a_cons_comp)
Definition: ERF_SedimentationFlux.H:43
Here is the call graph for this function:

◆ Qmoist_Ptr()

amrex::MultiFab* Kessler::Qmoist_Ptr ( const int &  varIdx)
inlineoverridevirtual

Reimplemented from NullMoist.

160  {
162  return mic_fab_vars[MicVarMap[varIdx]].get();
163  }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
Here is the call graph for this function:

◆ Qmoist_Restart_Vars()

void Kessler::Qmoist_Restart_Vars ( const SolverChoice &  ,
std::vector< int > &  a_idx,
std::vector< std::string > &  a_names 
) const
inlineoverridevirtual

Reimplemented from NullMoist.

178  {
179  a_idx.clear();
180  a_names.clear();
181 
182  // NOTE: These are the indices to access into qmoist (not mic_fab_vars)
183  a_idx.push_back(0); a_names.push_back("RainAccum");
184  }

◆ Qmoist_Size()

int Kessler::Qmoist_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

166 { return Kessler::m_qmoist_size; }

◆ Qstate_Moist_NumConc_Size()

int Kessler::Qstate_Moist_NumConc_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

int n_qstate_moist_numconc_size
Definition: ERF_Kessler.H:206

◆ Qstate_Moist_Size()

int Kessler::Qstate_Moist_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

int n_qstate_moist_size
Definition: ERF_Kessler.H:203

◆ Sed_Flux()

const SedimentationFlux* Kessler::Sed_Flux ( ) const
inlineoverridevirtual

The sedimentation face fluxes of the most recent Advance, or null for a scheme that does not sediment (see ERF_SedimentationFlux.H)

Reimplemented from NullMoist.

156 { return &m_sed; }

◆ Update_Micro_Vars() [1/2]

void Kessler::Update_Micro_Vars ( amrex::MultiFab &  cons_in)
inlineoverridevirtual

Reimplemented from NullMoist.

133  {
134  this->Copy_State_to_Micro(cons_in);
135  }
void Copy_State_to_Micro(const amrex::MultiFab &cons_in) override
Here is the call graph for this function:

◆ Update_Micro_Vars() [2/2]

void Kessler::Update_Micro_Vars ( amrex::MultiFab &  cons_in,
const amrex::MultiFab *  base_state 
)
overridevirtual

Reimplemented from NullMoist.

◆ Update_State_Vars()

void Kessler::Update_State_Vars ( amrex::MultiFab &  cons_in,
const amrex::MultiFab &   
)
inlineoverridevirtual

Reimplemented from NullMoist.

141  {
142  this->Copy_Micro_to_State(cons_in);
143  }
void Copy_Micro_to_State(amrex::MultiFab &cons_in) override
Definition: ERF_UpdateKessler.cpp:14
Here is the call graph for this function:

Member Data Documentation

◆ CFL_MAX

constexpr amrex::Real Kessler::CFL_MAX = kessler_sedimentation_cfl_max
staticconstexprprivate

◆ dt

amrex::Real Kessler::dt
private

Referenced by Advance().

◆ m_detJ_cc

amrex::MultiFab* Kessler::m_detJ_cc
private

◆ m_do_cond

bool Kessler::m_do_cond
private

Referenced by Define().

◆ m_fac_cond

amrex::Real Kessler::m_fac_cond
private

Referenced by Define().

◆ m_geom

amrex::Geometry Kessler::m_geom
private

◆ m_moisture_type

MoistureType Kessler::m_moisture_type = MoistureType::None
private

◆ m_qmoist_size

int Kessler::m_qmoist_size = 1
private

Referenced by Qmoist_Ptr(), and Qmoist_Size().

◆ m_rdOcp

amrex::Real Kessler::m_rdOcp {RdoCp}
private

Referenced by Define().

◆ m_sed

SedimentationFlux Kessler::m_sed
private

Referenced by Advance(), and Sed_Flux().

◆ m_z_phys_nd

amrex::MultiFab* Kessler::m_z_phys_nd
private

◆ mic_fab_vars

amrex::Array<FabPtr, MicVar_Kess::NumVars> Kessler::mic_fab_vars
private

◆ MicVarMap

amrex::Vector<int> Kessler::MicVarMap
private

Referenced by Qmoist_Ptr().

◆ n_qstate_moist_numconc_size

int Kessler::n_qstate_moist_numconc_size = 0
private

◆ n_qstate_moist_size

int Kessler::n_qstate_moist_size = 3
private

Referenced by Qstate_Moist_Size().

◆ nlev

int Kessler::nlev
private

◆ zhi

int Kessler::zhi
private

◆ zlo

int Kessler::zlo
private

The documentation for this class was generated from the following files: