Function for computing the coefficients for the tridiagonal solver used in the fast integrator (the acoustic substepping).
64 const GpuArray<Real, AMREX_SPACEDIM>
dxInv = geom.InvCellSizeArray();
67 const Box &domain = geom.Domain();
69 MultiFab coeff_A_mf(fast_coeffs, amrex::make_alias, 0, 1);
70 MultiFab coeff_B_mf(fast_coeffs, amrex::make_alias, 1, 1);
71 MultiFab coeff_C_mf(fast_coeffs, amrex::make_alias, 2, 1);
72 MultiFab coeff_P_mf(fast_coeffs, amrex::make_alias, 3, 1);
73 MultiFab coeff_Q_mf(fast_coeffs, amrex::make_alias, 4, 1);
74 MultiFab beta_s_mf(fast_coeffs, amrex::make_alias, 5, 1);
76 const bool has_z_nd = (z_phys_nd !=
nullptr);
77 const bool l_zcc_kface = use_zcc_kface_metric && (z_phys_cc !=
nullptr);
82 const Array<Real,AMREX_SPACEDIM> grav{
zero,
zero, -gravity};
83 const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
89 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
95 Box bx = mfi.tilebox();
96 Box tbz = surroundingNodes(bx,2);
98 const Array4<const Real> & stage_cons = S_stage_data[
IntVars::cons].const_array(mfi);
99 const Array4<const Real> & prim = S_stage_prim.const_array(mfi);
101 const Array4<const Real>& detJ = (mesh_type != MeshType::ConstantDz) ?
102 detJ_cc->const_array(mfi) : Array4<const Real>{};
103 const Array4<const Real>& pi_stage_ca = pi_stage.const_array(mfi);
105 FArrayBox gam_fab; gam_fab.resize(surroundingNodes(bx,2),1,The_Async_Arena());
107 auto const& coeffA_a = coeff_A_mf.array(mfi);
108 auto const& coeffB_a = coeff_B_mf.array(mfi);
109 auto const& coeffC_a = coeff_C_mf.array(mfi);
110 auto const& coeffP_a = coeff_P_mf.array(mfi);
111 auto const& coeffQ_a = coeff_Q_mf.array(mfi);
112 auto const& gam_a = gam_fab.array();
113 auto const& beta_s_a = beta_s_mf.array(mfi);
115 const Array4<const Real>& z_nd = (has_z_nd) ? z_phys_nd->const_array(mfi)
116 : Array4<const Real>{};
117 const Array4<const Real>& z_cc = (has_z_nd) ? z_phys_cc->const_array(mfi)
118 : Array4<const Real>{};
124 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
126 if (use_variable_beta_s) {
135 const Real sigma2 = amrex::max(h_xi*h_xi + h_eta*h_eta, Real(0.021));
140 const Real b_tmp = sigma2 / (
two + sigma2);
141 const Real zcrit =
two * std::sqrt(
one + sigma2)
146 + stage_cons(i, j, k-1,
Rho_comp ) );
149 const Real qv_kf = (l_use_moisture) ?
myhalf * ( stage_cons(i, j, k ,
RhoQ1_comp)
153 const Real
cs = std::sqrt(
Gamma *
p / r_kf);
154 const Real dz_kf = z_cc(i,j,k) - z_cc(i,j,k-1);
155 const Real zval =
two *
cs *
static_cast<Real
>(dtau) / dz_kf;
158 const Real beta_lo = b_tmp;
159 const Real beta_hi = amrex::min(sigma2, Real(1.0));
161 const Real s = amrex::Clamp((zval -
alpha*zcrit) / ((
one -
alpha)*zcrit), Real(0.0), Real(1.0));
163 beta_s_a(i,j,k) = beta_lo + w*(beta_hi - beta_lo);
165 beta_s_a(i,j,k) = beta_s;
173 Box bx_shrunk_in_k = bx;
174 int klo = tbz.smallEnd(2);
175 int khi = tbz.bigEnd(2);
176 bx_shrunk_in_k.setSmall(2,
klo+1);
177 bx_shrunk_in_k.setBig(2,
khi-1);
182 Real halfg = std::abs(
myhalf * grav_gpu[2]);
185 if (mesh_type != MeshType::ConstantDz)
187 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
189 Real pi_c =
myhalf * (pi_stage_ca(i,j,k-1) + pi_stage_ca(i,j,k));
196 Real detJ_on_kface = (l_zcc_kface) ? (z_cc(i,j,k) - z_cc(i,j,k-1)) * dzi
197 :
myhalf * (detJ(i,j,k) + detJ(i,j,k-1));
198 Real inv_detJ_on_kface =
one / detJ_on_kface;
205 Real Thm_grad = dzi * inv_detJ_on_kface * ( Thm_hi - Thm_lo );
207 Real coeff_P = -
Gamma *
R_d * dzi * inv_detJ_on_kface * pi_c * (
one +
RvoRd*qv_p)
211 Real coeff_Q =
Gamma *
R_d * dzi * inv_detJ_on_kface * pi_c * (
one +
RvoRd*qv_q)
215 if (l_use_moisture) {
218 coeff_P /= (
one +
q);
219 coeff_Q /= (
one +
q);
225 coeffP_a(i,j,k) = coeff_P;
226 coeffQ_a(i,j,k) = coeff_Q;
236 Real beta_2_km1 =
myhalf * (
one + beta_s_a(i,j,k-1));
237 Real beta_2_k =
myhalf * (
one + beta_s_a(i,j,k ));
238 Real beta_2_kp1 =
myhalf * (
one + beta_s_a(i,j,k+1));
239 Real D_A = beta_2_km1 * beta_2_k * dzi *
static_cast<Real
>(dtau * dtau);
240 Real D_B = beta_2_k * beta_2_k * dzi *
static_cast<Real
>(dtau * dtau);
241 Real D_C = beta_2_k * beta_2_kp1 * dzi *
static_cast<Real
>(dtau * dtau);
242 coeffA_a(i,j,k) = D_A * (
one/detJ(i,j,k-1)) * ( halfg - coeff_Q * theta_t_lo );
243 coeffC_a(i,j,k) = D_C * (
one/detJ(i,j,k )) * (-halfg + coeff_P * theta_t_hi );
247 coeffB_a(i,j,k) =
one + D_B * ( (coeff_Q/detJ(i,j,k-1) - coeff_P/detJ(i,j,k)) * theta_t_mid
248 + halfg * (
one/detJ(i,j,k) -
one/detJ(i,j,k-1)) );
253 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
255 Real pi_c =
myhalf * (pi_stage_ca(i,j,k-1) + pi_stage_ca(i,j,k));
260 Real inv_h_kface = (l_zcc_kface) ?
one / ((z_cc(i,j,k) - z_cc(i,j,k-1)) * dzi) :
one;
267 Real Thm_grad = dzi * inv_h_kface * ( Thm_hi - Thm_lo );
277 if (l_use_moisture) {
280 coeff_P /= (
one +
q);
281 coeff_Q /= (
one +
q);
287 coeffP_a(i,j,k) = coeff_P;
288 coeffQ_a(i,j,k) = coeff_Q;
298 Real beta_2_km1 =
myhalf * (
one + beta_s_a(i,j,k-1));
299 Real beta_2_k =
myhalf * (
one + beta_s_a(i,j,k ));
300 Real beta_2_kp1 =
myhalf * (
one + beta_s_a(i,j,k+1));
301 Real D_A = beta_2_km1 * beta_2_k * dzi *
static_cast<Real
>(dtau * dtau);
302 Real D_B = beta_2_k * beta_2_k * dzi *
static_cast<Real
>(dtau * dtau);
303 Real D_C = beta_2_k * beta_2_kp1 * dzi *
static_cast<Real
>(dtau * dtau);
304 coeffA_a(i,j,k) = D_A * ( halfg - coeff_Q * theta_t_lo );
305 coeffC_a(i,j,k) = D_C * (-halfg + coeff_P * theta_t_hi );
307 coeffB_a(i,j,k) =
one + D_B * (coeff_Q - coeff_P) * theta_t_mid;
311 amrex::Box b2d = tbz;
314 auto const lo = amrex::lbound(bx);
315 auto const hi = amrex::ubound(bx);
317 auto const domhi = amrex::ubound(domain);
320 BL_PROFILE(
"make_coeffs_b2d_loop");
322 ParallelFor(b2d, [=] AMREX_GPU_DEVICE (
int i,
int j,
int) {
325 coeffA_a(i,j,
lo.z) =
zero;
326 coeffB_a(i,j,
lo.z) =
one;
327 coeffC_a(i,j,
lo.z) =
zero;
330 coeffA_a(i,j,
hi.z+1) =
zero;
331 coeffB_a(i,j,
hi.z+1) =
one;
332 coeffC_a(i,j,
hi.z+1) =
zero;
336 if ( (
hi.z == domhi.z) &&
339 coeffA_a(i,j,
hi.z+1) = -
one;
343 gam_a(i,j,
lo.z) = coeffC_a(i,j,
lo.z) / coeffB_a(i,j,
lo.z);
344 for (
int k =
lo.z+1; k <=
hi.z+1; k++) {
345 coeffB_a(i,j,k) =
one / ( coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam_a(i,j,k-1) );
346 gam_a(i,j,k) = coeffC_a(i,j,k) * coeffB_a(i,j,k);
351 for (
int j =
lo.y; j <=
hi.y; ++j) {
353 for (
int i =
lo.x; i <=
hi.x; ++i) {
354 coeffA_a(i,j,
lo.z) =
zero;
355 coeffB_a(i,j,
lo.z) =
one;
356 coeffC_a(i,j,
lo.z) =
zero;
357 gam_a(i,j,
lo.z) = coeffC_a(i,j,
lo.z) / coeffB_a(i,j,
lo.z);
360 for (
int j =
lo.y; j <=
hi.y; ++j) {
362 for (
int i =
lo.x; i <=
hi.x; ++i) {
365 coeffA_a(i,j,
hi.z+1) =
zero;
366 coeffB_a(i,j,
hi.z+1) =
one;
367 coeffC_a(i,j,
hi.z+1) =
zero;
371 if ( (
hi.z == domhi.z) &&
374 coeffA_a(i,j,
hi.z+1) = -
one;
378 for (
int k =
lo.z+1; k <=
hi.z+1; ++k) {
379 for (
int j =
lo.y; j <=
hi.y; ++j) {
381 for (
int i =
lo.x; i <=
hi.x; ++i) {
382 coeffB_a(i,j,k) =
one / ( coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam_a(i,j,k-1) );
383 gam_a(i,j,k) = coeffC_a(i,j,k) * coeffB_a(i,j,k);
constexpr amrex::Real RvoRd
Definition: ERF_Constants.H:59
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:70
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
#define PrimQ1_comp
Definition: ERF_IndexDefines.H:94
#define PrimQ2_comp
Definition: ERF_IndexDefines.H:95
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define PrimTheta_comp
Definition: ERF_IndexDefines.H:91
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
void make_fast_coeffs(int, MultiFab &fast_coeffs, Vector< MultiFab > &S_stage_data, const MultiFab &S_stage_prim, const MultiFab &pi_stage, const amrex::Geometry geom, bool l_use_moisture, MeshType mesh_type, Real gravity, Real c_p, std::unique_ptr< MultiFab > &detJ_cc, const double dtau, Real beta_s, const MultiFab *z_phys_cc, const MultiFab *z_phys_nd, bool use_zcc_kface_metric, bool use_variable_beta_s, amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &phys_bc_type)
Definition: ERF_MakeFastCoeffs.cpp:42
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);})
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtKface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:445
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtKface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:468
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ cons
Definition: ERF_IndexDefines.H:249
@ alpha
Definition: ERF_SLM.H:153
@ q
Definition: ERF_WSM6.H:296
@ p
Definition: ERF_WSM6.H:303
real(c_double), private cs
Definition: ERF_module_mp_morr_two_moment.F90:203