1 #ifndef ERF_KESSLER_UTILS_H_
2 #define ERF_KESSLER_UTILS_H_
8 #include <AMReX_GpuQualifiers.H>
9 #include <AMReX_REAL.H>
45 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
47 const int k_hi) noexcept
49 return (k == k_hi + 1) ? k - 1 : k;
52 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
54 const amrex::Real
qp) noexcept
62 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
64 const amrex::Real terminal_velocity,
65 const amrex::Real
qp) noexcept
67 return rho * terminal_velocity *
qp;
70 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
72 const amrex::Real donor_rho,
73 const amrex::Real donor_qp,
74 const amrex::Real donor_detJ,
75 const amrex::Real coef) noexcept
79 return amrex::min(flux, donor_rho * donor_qp * donor_detJ / coef);
82 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
94 return amrex::max(1,
static_cast<int>(std::ceil(ratio)));
97 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
100 const amrex::Real
dz,
101 const amrex::Real detJ_donor) noexcept
105 return terminal_velocity * dt / (
dz * detJ_donor);
108 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
112 const amrex::Real detJ_donor,
113 const amrex::Real detJ_below) noexcept
121 return (k > k_lo && k <= k_hi) ? amrex::min(detJ_donor, detJ_below) : detJ_donor;
124 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
129 return precip_mass_per_area
134 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
138 return std::fabs(value) < 1e-14;
141 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
143 const amrex::Real
qc,
144 const amrex::Real qsat,
145 const amrex::Real dtqsat,
147 const amrex::Real latent_over_cp) noexcept
151 const amrex::Real fac = latent_over_cp * dtqsat;
154 if ((
qv > qsat) && do_cond) {
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));
166 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
169 const amrex::Real rho_km1,
170 const amrex::Real rho_k,
172 const amrex::Real qp_k) noexcept
183 face_state.
rho = rho_km1;
184 face_state.qp = amrex::Real(0);
186 face_state.rho = rho_k;
187 face_state.qp = qp_k;
189 face_state.rho = amrex::Real(0.5) * (rho_km1 + rho_k);
190 face_state.qp = qp_k;
194 face_state.qp = std::max(amrex::Real(0), face_state.qp);
198 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
200 const amrex::Real fz_lo,
201 const amrex::Real
rho,
202 const amrex::Real dJinv,
203 const amrex::Real coef) noexcept
206 return dJinv * (amrex::Real(1) /
rho) * (fz_hi - fz_lo) * coef;
209 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
211 const amrex::Real
qc,
212 const amrex::Real
qp,
213 const amrex::Real
rho,
214 const amrex::Real pressure_current_units,
215 const amrex::Real qsat,
216 const amrex::Real dtqsat,
217 const amrex::Real dt,
219 const amrex::Real latent_over_cp) noexcept
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(
238 const amrex::Real qv_eff =
qv
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))) {
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)
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))
254 source_terms.dq_rain_to_vapor = amrex::min(
qp, amrex::min(raw_rain_to_vapor, remaining_capacity));
257 if (
qc > amrex::Real(0)) {
258 const amrex::Real qcc =
qc;
261 const amrex::Real available_cloud = amrex::max(
263 amrex::Real auto_r = amrex::Real(0);
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);
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
static constexpr amrex::Real kessler_water_depth_m_per_kg_m2
Definition: ERF_KesslerUtils.H:35
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
static constexpr amrex::Real kessler_millimeters_per_meter
Definition: ERF_KesslerUtils.H:36
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
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
static constexpr amrex::Real kessler_vt_coeff
Definition: ERF_KesslerUtils.H:39
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
static constexpr amrex::Real kessler_vt_exponent
Definition: ERF_KesslerUtils.H:41
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
static constexpr amrex::Real kessler_vt_rho0
Definition: ERF_KesslerUtils.H:42
Physical constants and tuning parameters used only by the moisture and cloud-physics code.
constexpr amrex::Real alphaelq
Definition: ERF_MicrophysicsConstants.H:78
constexpr amrex::Real qcw0
Definition: ERF_MicrophysicsConstants.H:76
constexpr amrex::Real rhor
Definition: ERF_MicrophysicsConstants.H:39
Dimensionless numeric literals and pure mathematical constants.
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
@ qp
Definition: ERF_Kessler.H:34
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
@ qc
Definition: ERF_Morrison.H:110
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
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