54 #ifndef ERF_RICHARDSON_NUMBER_H_
55 #define ERF_RICHARDSON_NUMBER_H_
57 #include <AMReX_GpuQualifiers.H>
58 #include <AMReX_REAL.H>
83 const amrex::Array4<const amrex::Real>& cell_data,
133 const amrex::Array4<const amrex::Real>& cell_data,
138 const int qv_index = moisture_indices.
qv;
139 const int qc_index = moisture_indices.
qc;
143 bool saturated =
IsSaturated(i, j, k, cell_data, qc_index);
148 if (saturated && qc_index >= 0) {
153 inv_theta =
one / theta_l;
154 dtheta_dz =
myhalf * (theta_l_kp1 - theta_l_km1) * dzInv;
156 }
else if (qv_index >= 0) {
161 inv_theta =
one / theta_v;
162 dtheta_dz =
myhalf * (theta_v_kp1 - theta_v_km1) * dzInv;
166 amrex::Real theta_kp1 = cell_data(i, j, k+1, rhoTheta_comp) / cell_data(i, j, k+1, rho_comp);
167 amrex::Real theta_km1 = cell_data(i, j, k-1, rhoTheta_comp) / cell_data(i, j, k-1, rho_comp);
170 dtheta_dz =
myhalf * (theta_kp1 - theta_km1) * dzInv;
173 return const_grav * inv_theta * dtheta_dz;
193 const amrex::Array4<const amrex::EBCellFlag>& c_cflag,
196 const amrex::Array4<const amrex::Real>& cell_data,
201 const int qv_index = moisture_indices.
qv;
202 const int qc_index = moisture_indices.
qc;
206 bool saturated =
IsSaturated(i, j, k, cell_data, qc_index);
211 bool is_covered_kp1 = c_cflag(i,j,k+1).isCovered();
212 bool is_covered_km1 = c_cflag(i,j,k-1).isCovered();
214 if (saturated && qc_index >= 0) {
219 inv_theta =
one / theta_l;
221 if (is_covered_kp1) {
223 dtheta_dz = (
three*theta_l -
four*theta_l_km1 + theta_l_km2) *
myhalf * dzInv;
224 }
else if (is_covered_km1) {
226 dtheta_dz = (-theta_l_kp2 +
four*theta_l_kp1 -
three*theta_l) *
myhalf * dzInv;
228 dtheta_dz =
myhalf * (theta_l_kp1 - theta_l_km1) * dzInv;
231 }
else if (qv_index >= 0) {
236 inv_theta =
one / theta_v;
238 if (is_covered_kp1) {
240 dtheta_dz = (
three*theta_v -
four*theta_v_km1 + theta_v_km2) *
myhalf * dzInv;
241 }
else if (is_covered_km1) {
243 dtheta_dz = (-theta_v_kp2 +
four*theta_v_kp1 -
three*theta_v) *
myhalf * dzInv;
245 dtheta_dz =
myhalf * (theta_v_kp1 - theta_v_km1) * dzInv;
250 amrex::Real theta_kp1 = cell_data(i, j, k+1, rhoTheta_comp) / cell_data(i, j, k+1, rho_comp);
251 amrex::Real theta_km1 = cell_data(i, j, k-1, rhoTheta_comp) / cell_data(i, j, k-1, rho_comp);
255 if (is_covered_kp1) {
256 amrex::Real theta_km2 = cell_data(i, j, k-2, rhoTheta_comp) / cell_data(i, j, k-2, rho_comp);
258 }
else if (is_covered_km1) {
259 amrex::Real theta_kp2 = cell_data(i, j, k+2, rhoTheta_comp) / cell_data(i, j, k+2, rho_comp);
262 dtheta_dz =
myhalf * (theta_kp1 - theta_km1) * dzInv;
266 return const_grav * inv_theta * dtheta_dz;
302 const amrex::Array4<const amrex::Real>& u,
303 const amrex::Array4<const amrex::Real>& v)
314 amrex::Real S2_vert = du_dz * du_dz + dv_dz * dv_dz;
337 const amrex::Array4<const amrex::EBCellFlag>& c_cflag,
338 const amrex::Array4<const amrex::Real>& u_vfrac,
339 const amrex::Array4<const amrex::Real>& v_vfrac,
341 const amrex::Array4<const amrex::Real>& u,
342 const amrex::Array4<const amrex::Real>& v)
347 amrex::Real u_c = ( u_vfrac(i,j,k) * u(i, j, k) + u_vfrac(i+1,j,k) * u(i+1, j, k) )
348 / ( u_vfrac(i,j,k) + u_vfrac(i+1,j,k) );
349 amrex::Real v_c = ( v_vfrac(i,j,k) * v(i, j, k) + v_vfrac(i,j+1,k) * v(i, j+1, k) )
350 / ( v_vfrac(i,j,k) + v_vfrac(i,j+1,k) );
352 if (c_cflag(i,j,k+1).isCovered()) {
353 amrex::Real u_c_km1 = ( u_vfrac(i,j,k-1) * u(i, j, k-1) + u_vfrac(i+1,j,k-1) * u(i+1, j, k-1) )
354 / ( u_vfrac(i,j,k-1) + u_vfrac(i+1,j,k-1) );
355 amrex::Real u_c_km2 = ( u_vfrac(i,j,k-2) * u(i, j, k-2) + u_vfrac(i+1,j,k-2) * u(i+1, j, k-2) )
356 / ( u_vfrac(i,j,k-2) + u_vfrac(i+1,j,k-2) );
357 amrex::Real v_c_km1 = ( v_vfrac(i,j,k-1) * v(i, j, k-1) + v_vfrac(i,j+1,k-1) * v(i, j+1, k-1) )
358 / ( v_vfrac(i,j,k-1) + v_vfrac(i,j+1,k-1) );
359 amrex::Real v_c_km2 = ( v_vfrac(i,j,k-2) * v(i, j, k-2) + v_vfrac(i,j+1,k-2) * v(i, j+1, k-2) )
360 / ( v_vfrac(i,j,k-2) + v_vfrac(i,j+1,k-2) );
364 }
else if (c_cflag(i,j,k-1).isCovered()) {
365 amrex::Real u_c_kp1 = ( u_vfrac(i,j,k+1) * u(i, j, k+1) + u_vfrac(i+1,j,k+1) * u(i+1, j, k+1) )
366 / ( u_vfrac(i,j,k+1) + u_vfrac(i+1,j,k+1) );
367 amrex::Real u_c_kp2 = ( u_vfrac(i,j,k+2) * u(i, j, k+2) + u_vfrac(i+1,j,k+2) * u(i+1, j, k+2) )
368 / ( u_vfrac(i,j,k+2) + u_vfrac(i+1,j,k+2) );
369 amrex::Real v_c_kp1 = ( v_vfrac(i,j,k+1) * v(i, j, k+1) + v_vfrac(i,j+1,k+1) * v(i, j+1, k+1) )
370 / ( v_vfrac(i,j,k+1) + v_vfrac(i,j+1,k+1) );
371 amrex::Real v_c_kp2 = ( v_vfrac(i,j,k+2) * v(i, j, k+2) + v_vfrac(i,j+1,k+2) * v(i, j+1, k+2) )
372 / ( v_vfrac(i,j,k+2) + v_vfrac(i,j+1,k+2) );
376 amrex::Real u_c_km1 = ( u_vfrac(i,j,k-1) * u(i, j, k-1) + u_vfrac(i+1,j,k-1) * u(i+1, j, k-1) )
377 / ( u_vfrac(i,j,k-1) + u_vfrac(i+1,j,k-1) );
378 amrex::Real u_c_kp1 = ( u_vfrac(i,j,k+1) * u(i, j, k+1) + u_vfrac(i+1,j,k+1) * u(i+1, j, k+1) )
379 / ( u_vfrac(i,j,k+1) + u_vfrac(i+1,j,k+1) );
380 amrex::Real v_c_km1 = ( v_vfrac(i,j,k-1) * v(i, j, k-1) + v_vfrac(i,j+1,k-1) * v(i, j+1, k-1) )
381 / ( v_vfrac(i,j,k-1) + v_vfrac(i,j+1,k-1) );
382 amrex::Real v_c_kp1 = ( v_vfrac(i,j,k+1) * v(i, j, k+1) + v_vfrac(i,j+1,k+1) * v(i, j+1, k+1) )
383 / ( v_vfrac(i,j,k+1) + v_vfrac(i,j+1,k+1) );
384 du_dz =
myhalf * (u_c_kp1 - u_c_km1) * dzInv;
385 dv_dz =
myhalf * (v_c_kp1 - v_c_km1) * dzInv;
388 amrex::Real S2_vert = du_dz * du_dz + dv_dz * dv_dz;
406 return N2_moist / S2_safe;
429 return stability_factor;
constexpr amrex::Real three
Definition: ERF_Constants.H:11
constexpr amrex::Real four
Definition: ERF_Constants.H:12
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
rho
Definition: ERF_InitCustomPert_Bubble.H:107
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetav(const int &i, const int &j, const int &k, const amrex::Array4< amrex::Real const > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_MoistUtils.H:72
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetal(const int &i, const int &j, const int &k, const amrex::Array4< amrex::Real const > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_MoistUtils.H:128
AMREX_GPU_DEVICE AMREX_FORCE_INLINE bool IsSaturated(int i, int j, int k, const amrex::Array4< const amrex::Real > &cell_data, int qc_index)
Definition: ERF_RichardsonNumber.H:82
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real StabilityFunction(amrex::Real Ri, amrex::Real Ri_crit)
Definition: ERF_RichardsonNumber.H:419
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeVerticalShear2(int i, int j, int k, amrex::Real dzInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v)
Definition: ERF_RichardsonNumber.H:300
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeVerticalShear2_EB(int i, int j, int k, const amrex::Array4< const amrex::EBCellFlag > &c_cflag, const amrex::Array4< const amrex::Real > &u_vfrac, const amrex::Array4< const amrex::Real > &v_vfrac, amrex::Real dzInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v)
Definition: ERF_RichardsonNumber.H:336
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeRichardson(amrex::Real N2_moist, amrex::Real S2_vert)
Definition: ERF_RichardsonNumber.H:403
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeN2(int i, int j, int k, amrex::Real dzInv, amrex::Real const_grav, const amrex::Array4< const amrex::Real > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_RichardsonNumber.H:130
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeN2_EB(int i, int j, int k, const amrex::Array4< const amrex::EBCellFlag > &c_cflag, amrex::Real dzInv, amrex::Real const_grav, const amrex::Array4< const amrex::Real > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_RichardsonNumber.H:192
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ theta
Definition: ERF_SLM.H:20
@ qc
Definition: ERF_SatAdj.H:40
Component indices for moisture species in the conserved state.
Definition: ERF_DataStruct.H:166
int qv
Water vapor component index.
Definition: ERF_DataStruct.H:167
int qc
Cloud liquid water component index.
Definition: ERF_DataStruct.H:168