ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_KesslerUtils.H File Reference
#include <algorithm>
#include <cmath>
#include <limits>
#include <AMReX_GpuQualifiers.H>
#include <AMReX_REAL.H>
#include <ERF_NumericalConstants.H>
#include <ERF_MicrophysicsConstants.H>
#include <ERF_MicrophysicsUtils.H>
Include dependency graph for ERF_KesslerUtils.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  KesslerSourceTerms
 
struct  KesslerSaturationAdjustment
 
struct  KesslerFaceState
 

Functions

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int kessler_face_donor_k (const int k, const int k_hi) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_terminal_velocity (const amrex::Real rho, const amrex::Real qp) noexcept
 
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
 
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
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int kessler_num_sedimentation_substeps (const amrex::Real max_courant) noexcept
 
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
 
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
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_rain_accumulation_increment (const amrex::Real precip_mass_per_area) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool kessler_is_small_sedimentation_value (const amrex::Real value) noexcept
 
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
 
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
 
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
 
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
 

Variables

static constexpr amrex::Real kessler_sedimentation_cfl_max = myhalf
 
static constexpr int kessler_max_sedimentation_substeps = 1000
 
static constexpr amrex::Real kessler_water_depth_m_per_kg_m2 = amrex::Real(1.0) / rhor
 
static constexpr amrex::Real kessler_millimeters_per_meter = amrex::Real(1000.0)
 
static constexpr amrex::Real kessler_vt_coeff = amrex::Real(36.34)
 
static constexpr amrex::Real kessler_vt_rho_to_cgs = amrex::Real(0.001)
 
static constexpr amrex::Real kessler_vt_exponent = amrex::Real(0.1364)
 
static constexpr amrex::Real kessler_vt_rho0 = amrex::Real(1.16)
 
static constexpr amrex::Real kessler_vt_density_exponent = -myhalf
 

Function Documentation

◆ kessler_face_donor_k()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int kessler_face_donor_k ( const int  k,
const int  k_hi 
)
noexcept
48 {
49  return (k == k_hi + 1) ? k - 1 : k;
50 }

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_face_state()

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
173 {
174  KesslerFaceState face_state{amrex::Real(0), amrex::Real(0)};
175 
176  // Sedimentation is one-way downward transport. Use a face-centered density
177  // for the z-face flux, but upwind the transported rain mixing ratio from the
178  // donor cell. A centered qp can create flux from downstream rain when the
179  // donor cell is dry. The top boundary face carries no rain: nothing lies
180  // above the domain, so its donor is empty. It keeps the top cell's rho so
181  // the fall speed stays defined.
182  if (k == k_hi + 1) {
183  face_state.rho = rho_km1;
184  face_state.qp = amrex::Real(0);
185  } else if (k == 0) {
186  face_state.rho = rho_k;
187  face_state.qp = qp_k;
188  } else {
189  face_state.rho = amrex::Real(0.5) * (rho_km1 + rho_k);
190  face_state.qp = qp_k;
191  }
192 
193  // MUST MATCH: current AdvanceKessler nonnegative donor-qp clip before flux formation.
194  face_state.qp = std::max(amrex::Real(0), face_state.qp);
195  return face_state;
196 }
Definition: ERF_KesslerUtils.H:27
amrex::Real rho
Definition: ERF_KesslerUtils.H:28

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_fall_courant()

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
102 {
103  // The fall Courant number at a face: the distance fallen in dt over the physical height
104  // dz*detJ of the donor cell, the one the face drains, as the donor-cap limiter uses.
105  return terminal_velocity * dt / (dz * detJ_donor);
106 }
@ dz
Definition: ERF_AdvanceWDM6.cpp:273

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_is_small_sedimentation_value()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool kessler_is_small_sedimentation_value ( const amrex::Real  value)
noexcept
136 {
137  // MUST MATCH: current AdvanceKessler sedimentation zero threshold literal.
138  return std::fabs(value) < 1e-14;
139 }

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_limit_precip_flux()

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
76 {
77  // The donor cap: a face cannot export more rain in one substep than its donor cell
78  // holds, F * dt / dz <= rho_donor * qp_donor * detJ_donor, with coef = dt / dz.
79  return amrex::min(flux, donor_rho * donor_qp * donor_detJ / coef);
80 }

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_num_sedimentation_substeps()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int kessler_num_sedimentation_substeps ( const amrex::Real  max_courant)
noexcept
84 {
85  // max_courant is the largest fall Courant number over the faces for the full step,
86  // V*dt over the height of the cell the face drains: enough substeps that rain falls
87  // at most CFL_MAX of that cell per substep, and always at least one. A NaN, infinite
88  // or huge max_courant returns kessler_max_sedimentation_substeps + 1 rather than casting
89  // it to an int; AdvanceKessler aborts before it gets here.
90  const amrex::Real ratio = max_courant / kessler_sedimentation_cfl_max;
91  if (!(ratio <= amrex::Real(kessler_max_sedimentation_substeps))) {
93  }
94  return amrex::max(1, static_cast<int>(std::ceil(ratio)));
95 }
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

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_precip_flux()

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
66 {
67  return rho * terminal_velocity * qp;
68 }
@ qp
Definition: ERF_Kessler.H:34
@ rho
Definition: ERF_Kessler.H:25

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_rain_accumulation_increment()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_rain_accumulation_increment ( const amrex::Real  precip_mass_per_area)
noexcept
126 {
127  // Convert precipitation mass per unit area [kg m^-2] to liquid-water depth
128  // [mm]: divide by water density [kg m^-3], then multiply by mm per meter.
129  return precip_mass_per_area
132 }
static constexpr amrex::Real kessler_water_depth_m_per_kg_m2
Definition: ERF_KesslerUtils.H:35
static constexpr amrex::Real kessler_millimeters_per_meter
Definition: ERF_KesslerUtils.H:36

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_saturation_adjustment()

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
148 {
149  KesslerSaturationAdjustment source_terms{amrex::Real(0), amrex::Real(0)};
150 
151  const amrex::Real fac = latent_over_cp * dtqsat;
152 
153  // MUST MATCH: current AdvanceKessler condensation branch behavior.
154  if ((qv > qsat) && do_cond) {
155  source_terms.dq_vapor_to_cloud = std::min(qv, (qv - qsat) / (amrex::Real(1) + fac));
156  }
157 
158  // MUST MATCH: current AdvanceKessler cloud-evaporation branch behavior.
159  if ((qv < qsat) && (qc > amrex::Real(0)) && do_cond) {
160  source_terms.dq_cloud_to_vapor = std::min(qc, (qsat - qv) / (amrex::Real(1) + fac));
161  }
162 
163  return source_terms;
164 }
@ qv
Definition: ERF_Kessler.H:31
@ qc
Definition: ERF_Morrison.H:110
Definition: ERF_KesslerUtils.H:22
amrex::Real dq_vapor_to_cloud
Definition: ERF_KesslerUtils.H:23

Referenced by Kessler::AdvanceKessler(), and kessler_warm_rain_sources().

Here is the caller graph for this function:

◆ kessler_sedimentation_tendency()

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
204 {
205  // MUST MATCH: current AdvanceKessler sedimentation tendency arithmetic order.
206  return dJinv * (amrex::Real(1) / rho) * (fz_hi - fz_lo) * coef;
207 }

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_sizing_detJ()

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
114 {
115  // The detJ that sizes the substeps at face k: the smaller of the donor's (the cell the
116  // face drains) and that of the cell below it (the one its rain falls into), for faces
117  // inside the domain. The substep count is fixed at the start of the step, while the
118  // cells below the rain front are still dry; looking one cell down covers the first cell
119  // the front enters. The surface face drains out of the domain and the top face carries
120  // no rain, so both use the donor alone.
121  return (k > k_lo && k <= k_hi) ? amrex::min(detJ_donor, detJ_below) : detJ_donor;
122 }

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_terminal_velocity()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real kessler_terminal_velocity ( const amrex::Real  rho,
const amrex::Real  qp 
)
noexcept
55 {
56  // This function, with the kessler_vt_* constants, defines the Kessler rain fall speed.
57  return kessler_vt_coeff
60 }
static constexpr amrex::Real kessler_vt_density_exponent
Definition: ERF_KesslerUtils.H:43
static constexpr amrex::Real kessler_vt_rho_to_cgs
Definition: ERF_KesslerUtils.H:40
static constexpr amrex::Real kessler_vt_coeff
Definition: ERF_KesslerUtils.H:39
static constexpr amrex::Real kessler_vt_exponent
Definition: ERF_KesslerUtils.H:41
static constexpr amrex::Real kessler_vt_rho0
Definition: ERF_KesslerUtils.H:42

Referenced by Kessler::AdvanceKessler().

Here is the caller graph for this function:

◆ kessler_warm_rain_sources()

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
220 {
221  // Units must match current AdvanceKessler: q* are mass fractions, rho is in
222  // the production density units currently carried by Kessler, pressure is in
223  // Kessler's mbar / hPa path for qsat helpers, and dt is in seconds.
224  const KesslerSaturationAdjustment saturation_adjustment =
225  kessler_saturation_adjustment(qv, qc, qsat, dtqsat, do_cond, latent_over_cp);
226  KesslerSourceTerms source_terms{
227  saturation_adjustment.dq_vapor_to_cloud,
228  saturation_adjustment.dq_cloud_to_vapor,
229  amrex::Real(0),
230  amrex::Real(0)};
231 
232  const amrex::Real capacity = amrex::max(
233  amrex::Real(0), (qsat - qv) / (amrex::Real(1) + latent_over_cp * dtqsat));
234  const amrex::Real remaining_capacity = amrex::max(
235  amrex::Real(0), capacity - saturation_adjustment.dq_cloud_to_vapor);
236  // Cloud evaporation gets first claim on the linearized subsaturation
237  // capacity. Rain evaporation can use only the remaining capacity.
238  const amrex::Real qv_eff = qv
239  - saturation_adjustment.dq_vapor_to_cloud
240  + saturation_adjustment.dq_cloud_to_vapor;
241 
242  if ((qp > amrex::Real(0)) && (qsat > amrex::Real(0))
243  && (pressure_current_units > amrex::Real(0))
244  && (qv_eff < qsat) && (remaining_capacity > amrex::Real(0))) {
245  // MUST MATCH: current AdvanceKessler rain-evaporation coefficients and exponents.
246  const amrex::Real coeff = amrex::Real(1.6)
247  + amrex::Real(124.9) * std::pow(amrex::Real(0.001) * rho * qp, amrex::Real(0.2046));
248  const amrex::Real raw_rain_to_vapor = amrex::Real(1) / (amrex::Real(0.001) * rho)
249  * (amrex::Real(1) - qv_eff / qsat)
250  * coeff
251  * std::pow(amrex::Real(0.001) * rho * qp, amrex::Real(0.525))
252  / (amrex::Real(5.4e5) + amrex::Real(2.55e6) / (pressure_current_units * qsat))
253  * dt;
254  source_terms.dq_rain_to_vapor = amrex::min(qp, amrex::min(raw_rain_to_vapor, remaining_capacity));
255  }
256 
257  if (qc > amrex::Real(0)) {
258  const amrex::Real qcc = qc;
259  // Cloud-to-rain conversion is capped by cloud water available after
260  // saturation adjustment, not by the original qc.
261  const amrex::Real available_cloud = amrex::max(
262  amrex::Real(0), qc + saturation_adjustment.dq_vapor_to_cloud - saturation_adjustment.dq_cloud_to_vapor);
263  amrex::Real auto_r = amrex::Real(0);
264  if (qcc > qcw0) {
265  // MUST MATCH: current AdvanceKessler autoconversion trigger.
266  auto_r = alphaelq;
267  }
268 
269  // MUST MATCH: current AdvanceKessler accretion coefficient and exponent.
270  amrex::Real accrr = amrex::Real(0);
271  accrr = amrex::Real(2.2) * std::pow(qp, amrex::Real(0.875));
272  source_terms.dq_cloud_to_rain = dt * (accrr * qcc + auto_r * (qcc - qcw0));
273  source_terms.dq_cloud_to_rain = amrex::min(source_terms.dq_cloud_to_rain, available_cloud);
274  }
275 
276  return source_terms;
277 }
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
constexpr amrex::Real alphaelq
Definition: ERF_MicrophysicsConstants.H:78
constexpr amrex::Real qcw0
Definition: ERF_MicrophysicsConstants.H:76
amrex::Real dq_cloud_to_vapor
Definition: ERF_KesslerUtils.H:24
Definition: ERF_KesslerUtils.H:15

Referenced by Kessler::AdvanceKessler().

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

Variable Documentation

◆ kessler_max_sedimentation_substeps

constexpr int kessler_max_sedimentation_substeps = 1000
staticconstexpr

◆ kessler_millimeters_per_meter

constexpr amrex::Real kessler_millimeters_per_meter = amrex::Real(1000.0)
staticconstexpr

◆ kessler_sedimentation_cfl_max

constexpr amrex::Real kessler_sedimentation_cfl_max = myhalf
staticconstexpr

◆ kessler_vt_coeff

constexpr amrex::Real kessler_vt_coeff = amrex::Real(36.34)
staticconstexpr

◆ kessler_vt_density_exponent

constexpr amrex::Real kessler_vt_density_exponent = -myhalf
staticconstexpr

◆ kessler_vt_exponent

constexpr amrex::Real kessler_vt_exponent = amrex::Real(0.1364)
staticconstexpr

◆ kessler_vt_rho0

constexpr amrex::Real kessler_vt_rho0 = amrex::Real(1.16)
staticconstexpr

◆ kessler_vt_rho_to_cgs

constexpr amrex::Real kessler_vt_rho_to_cgs = amrex::Real(0.001)
staticconstexpr

◆ kessler_water_depth_m_per_kg_m2

constexpr amrex::Real kessler_water_depth_m_per_kg_m2 = amrex::Real(1.0) / rhor
staticconstexpr