21 auto domain =
m_geom.Domain();
22 int k_lo = domain.smallEnd(2);
23 int k_hi = domain.bigEnd(2);
27 auto ba =
tabs->boxArray();
28 auto dm =
tabs->DistributionMap();
29 fz.define(convert(ba, IntVect(0,0,1)), dm, 1, 0);
36 Real coef = dtn *
m_geom.InvCellSize(2);
38 for ( MFIter mfi(*
tabs,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
48 auto tbx = mfi.tilebox();
52 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
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));
58 Real qsat_local, dtqsat_local;
59 Real pressure = pres_array(i,j,k);
61 erf_qsatw(tabs_array(i,j,k), pressure, qsat_local);
62 erf_dtqsatw(tabs_array(i,j,k), pressure, dtqsat_local);
64 if (qsat_local <= Real(0)) {
65 amrex::Warning(
"qsat computed as non-positive; setting to Real(0)!");
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);
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
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));
92 qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
96 for ( MFIter mfi(fz, TilingIfNotGPU()); mfi.isValid(); ++mfi ){
100 auto fz_array = fz.array(mfi);
101 const Box& tbz = mfi.tilebox();
103 ParallelFor(tbz, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
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);
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>{},
141 [=] AMREX_GPU_DEVICE (
int box_no,
int i,
int j,
int k) noexcept
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);
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;
160 Real max_courant = get<0>(max_courant_tuple);
170 ParallelDescriptor::ReduceRealMax(max_courant);
177 if (!std::isfinite(max_courant) ||
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 "
185 <<
" The rain or density handed to the sedimentation is not usable.";
191 "Kessler: Number of precipitation substeps must be greater than 0!");
192 coef /= Real(n_substep);
193 dtn /= Real(n_substep);
195 for (
int nsub(0); nsub<n_substep; ++nsub)
203 for ( MFIter mfi(*
tabs,
TileNoZ()); mfi.isValid(); ++mfi ){
207 auto fz_array = fz.array(mfi);
210 : Array4<const Real>{};
212 const Real inv_dt = Real(1) /
dt;
214 const auto dJ_array = (
m_detJ_cc) ?
m_detJ_cc->const_array(mfi) : Array4<const Real>{};
216 const Box& tbx = mfi.tilebox();
217 const Box& tbz = mfi.tilebox(IntVect(0,0,1),IntVect(0));
219 ParallelFor(tbz, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
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);
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);
241 donor_rho, donor_qp, donor_detJ, coef);
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;
251 sed_array(i,j,k,0) += fz_array(i,j,k) * dtn;
257 rain_accum_array(i,j,k) = rain_accum_array(i,j,k)
262 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
264 Real dJinv = (dJ_array) ? Real(1)/dJ_array(i,j,k) : Real(1);
269 Real f_hi = fz_array(i,j,k+1);
270 Real f_lo = fz_array(i,j,k );
279 f_hi, f_lo, rho_array(i,j,k), dJinv, coef);
284 qp_array(i,j,k) += dq_sed;
285 qp_array(i,j,k) = std::max(Real(0), qp_array(i,j,k));
291 if (solverChoice.
moisture_type == MoistureType::Kessler_NoRain) {
292 if (!do_cond) {
return; }
293 for ( MFIter mfi(*
tabs,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
301 auto tbx = mfi.tilebox();
305 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
307 qc_array(i,j,k) = std::max(Real(0), qc_array(i,j,k));
311 Real pressure = pres_array(i,j,k);
313 erf_qsatw(tabs_array(i,j,k), pressure, qsat);
318 do_cond, d_fac_cond);
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
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));
332 qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
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