Function for computing the coefficients for the tridiagonal solver used in the fast integrator (the acoustic substepping).
42 Real beta_2 = 0.5 * (1.0 + beta_s);
47 const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
50 const Box &domain = geom.Domain();
52 MultiFab coeff_A_mf(fast_coeffs, amrex::make_alias, 0, 1);
53 MultiFab coeff_B_mf(fast_coeffs, amrex::make_alias, 1, 1);
54 MultiFab coeff_C_mf(fast_coeffs, amrex::make_alias, 2, 1);
55 MultiFab coeff_P_mf(fast_coeffs, amrex::make_alias, 3, 1);
56 MultiFab coeff_Q_mf(fast_coeffs, amrex::make_alias, 4, 1);
61 const Array<Real,AMREX_SPACEDIM> grav{0.0, 0.0, -gravity};
62 const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
68 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
74 Box bx = mfi.tilebox();
75 Box tbz = surroundingNodes(bx,2);
77 const Array4<const Real> & stage_cons = S_stage_data[
IntVars::cons].const_array(mfi);
78 const Array4<const Real> & prim = S_stage_prim.const_array(mfi);
80 const Array4<const Real>& detJ = (mesh_type != MeshType::ConstantDz) ? detJ_cc->const_array(mfi) : Array4<const Real>{};
82 const Array4<const Real>& r0_ca = r0->const_array(mfi);
83 const Array4<const Real>& pi0_ca = pi0->const_array(mfi);
84 const Array4<const Real>& pi_stage_ca = pi_stage.const_array(mfi);
86 FArrayBox gam_fab; gam_fab.resize(surroundingNodes(bx,2),1,The_Async_Arena());
88 auto const& coeffA_a = coeff_A_mf.array(mfi);
89 auto const& coeffB_a = coeff_B_mf.array(mfi);
90 auto const& coeffC_a = coeff_C_mf.array(mfi);
91 auto const& coeffP_a = coeff_P_mf.array(mfi);
92 auto const& coeffQ_a = coeff_Q_mf.array(mfi);
93 auto const& gam_a = gam_fab.array();
99 Box bx_shrunk_in_k = bx;
100 int klo = tbz.smallEnd(2);
101 int khi = tbz.bigEnd(2);
102 bx_shrunk_in_k.setSmall(2,klo+1);
103 bx_shrunk_in_k.setBig(2,khi-1);
108 Real halfg = std::abs(0.5 * grav_gpu[2]);
111 if (mesh_type != MeshType::ConstantDz)
113 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
115 Real rhobar_lo, rhobar_hi, pibar_lo, pibar_hi;
116 rhobar_lo = r0_ca(i,j,k-1);
117 rhobar_hi = r0_ca(i,j,k );
118 pibar_lo = pi0_ca(i,j,k-1);
119 pibar_hi = pi0_ca(i,j,k );
121 Real pi_c = 0.5 * (pi_stage_ca(i,j,k-1) + pi_stage_ca(i,j,k));
123 Real detJ_on_kface = 0.5 * (detJ(i,j,k) + detJ(i,j,k-1));
124 Real inv_detJ_on_kface = 1. / detJ_on_kface;
129 Real coeff_P = -
Gamma *
R_d * dzi * inv_detJ_on_kface * (1.0 + RvOverRd*qv_p)
130 + halfg *
R_d * rhobar_hi /
134 Real coeff_Q =
Gamma *
R_d * dzi * inv_detJ_on_kface * (1.0 + RvOverRd*qv_q)
135 + halfg *
R_d * rhobar_lo /
139 coeffP_a(i,j,k) = coeff_P;
140 coeffQ_a(i,j,k) = coeff_Q;
142 if (l_use_moisture) {
145 coeff_P /= (1.0 + q);
146 coeff_Q /= (1.0 + q);
154 Real D = dtau * dtau * beta_2 * beta_2 * dzi;
155 coeffA_a(i,j,k) = D * ( halfg - coeff_Q * theta_t_lo );
156 coeffC_a(i,j,k) = D * (-halfg + coeff_P * theta_t_hi );
158 coeffB_a(i,j,k) = detJ_on_kface + D * (coeff_Q - coeff_P) * theta_t_mid;
163 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
165 Real rhobar_lo, rhobar_hi, pibar_lo, pibar_hi;
166 rhobar_lo = r0_ca(i,j,k-1);
167 rhobar_hi = r0_ca(i,j,k );
168 pibar_lo = pi0_ca(i,j,k-1);
169 pibar_hi = pi0_ca(i,j,k );
171 Real pi_c = 0.5 * (pi_stage_ca(i,j,k-1) + pi_stage_ca(i,j,k));
176 Real coeff_P = -
Gamma *
R_d * dzi * (1.0 + RvOverRd*qv_p)
177 + halfg *
R_d * rhobar_hi /
181 Real coeff_Q =
Gamma *
R_d * dzi * (1.0 + RvOverRd*qv_q)
182 + halfg *
R_d * rhobar_lo /
186 coeffP_a(i,j,k) = coeff_P;
187 coeffQ_a(i,j,k) = coeff_Q;
189 if (l_use_moisture) {
192 coeff_P /= (1.0 + q);
193 coeff_Q /= (1.0 + q);
201 Real D = dtau * dtau * beta_2 * beta_2 * dzi;
202 coeffA_a(i,j,k) = D * ( halfg - coeff_Q * theta_t_lo );
203 coeffC_a(i,j,k) = D * (-halfg + coeff_P * theta_t_hi );
205 coeffB_a(i,j,k) = 1.0 + D * (coeff_Q - coeff_P) * theta_t_mid;
209 amrex::Box b2d = tbz;
212 auto const lo = amrex::lbound(bx);
213 auto const hi = amrex::ubound(bx);
215 auto const domhi = amrex::ubound(domain);
218 BL_PROFILE(
"make_coeffs_b2d_loop");
220 ParallelFor(b2d, [=] AMREX_GPU_DEVICE (
int i,
int j,
int) {
223 coeffA_a(i,j,lo.z) = 0.0;
224 coeffB_a(i,j,lo.z) = 1.0;
225 coeffC_a(i,j,lo.z) = 0.0;
228 coeffA_a(i,j,hi.z+1) = 0.0;
229 coeffB_a(i,j,hi.z+1) = 1.0;
230 coeffC_a(i,j,hi.z+1) = 0.0;
234 if ( (hi.z == domhi.z) &&
237 coeffA_a(i,j,hi.z+1) = -1.0;
241 Real bet = coeffB_a(i,j,lo.z);
243 for (
int k = lo.z+1; k <= hi.z+1; k++) {
244 gam_a(i,j,k) = coeffC_a(i,j,k-1) / bet;
245 bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam_a(i,j,k);
246 coeffB_a(i,j,k) = bet;
251 for (
int j = lo.y; j <= hi.y; ++j) {
253 for (
int i = lo.x; i <= hi.x; ++i) {
254 coeffA_a(i,j,lo.z) = 0.0;
255 coeffB_a(i,j,lo.z) = 1.0;
256 coeffC_a(i,j,lo.z) = 0.0;
259 for (
int j = lo.y; j <= hi.y; ++j) {
261 for (
int i = lo.x; i <= hi.x; ++i) {
264 coeffA_a(i,j,hi.z+1) = 0.0;
265 coeffB_a(i,j,hi.z+1) = 1.0;
266 coeffC_a(i,j,hi.z+1) = 0.0;
270 if ( (hi.z == domhi.z) &&
273 coeffA_a(i,j,hi.z+1) = -1.0;
277 for (
int k = lo.z+1; k <= hi.z+1; ++k) {
278 for (
int j = lo.y; j <= hi.y; ++j) {
280 for (
int i = lo.x; i <= hi.x; ++i) {
281 gam_a(i,j,k) = coeffC_a(i,j,k-1) / coeffB_a(i,j,k-1);
282 Real bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam_a(i,j,k);
283 coeffB_a(i,j,k) = bet;
292 BL_PROFILE(
"make_coeffs_invert");
293 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
295 coeffB_a(i,j,k) = 1.0 / coeffB_a(i,j,k);
constexpr amrex::Real R_v
Definition: ERF_Constants.H:11
constexpr amrex::Real R_d
Definition: ERF_Constants.H:10
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:19
#define PrimQ1_comp
Definition: ERF_IndexDefines.H:53
#define PrimQ2_comp
Definition: ERF_IndexDefines.H:54
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define PrimTheta_comp
Definition: ERF_IndexDefines.H:50
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 MultiFab *r0, const MultiFab *pi0, Real dtau, Real beta_s, amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &phys_bc_type)
Definition: ERF_MakeFastCoeffs.cpp:26
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ cons
Definition: ERF_IndexDefines.H:158