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);
46 const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
49 const Box &domain = geom.Domain();
51 MultiFab coeff_A_mf(fast_coeffs, amrex::make_alias, 0, 1);
52 MultiFab coeff_B_mf(fast_coeffs, amrex::make_alias, 1, 1);
53 MultiFab coeff_C_mf(fast_coeffs, amrex::make_alias, 2, 1);
54 MultiFab coeff_P_mf(fast_coeffs, amrex::make_alias, 3, 1);
55 MultiFab coeff_Q_mf(fast_coeffs, amrex::make_alias, 4, 1);
60 const Array<Real,AMREX_SPACEDIM> grav{0.0, 0.0, -gravity};
61 const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
67 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
73 Box bx = mfi.tilebox();
74 Box tbz = surroundingNodes(bx,2);
76 const Array4<const Real> & stage_cons = S_stage_data[
IntVars::cons].const_array(mfi);
77 const Array4<const Real> & prim = S_stage_prim.const_array(mfi);
79 const Array4<const Real>& detJ = (mesh_type != MeshType::ConstantDz) ? detJ_cc->const_array(mfi) : Array4<const Real>{};
81 const Array4<const Real>& r0_ca = r0->const_array(mfi);
82 const Array4<const Real>& pi0_ca = pi0->const_array(mfi);
83 const Array4<const Real>& pi_stage_ca = pi_stage.const_array(mfi);
85 FArrayBox gam_fab; gam_fab.resize(surroundingNodes(bx,2),1,The_Async_Arena());
87 auto const& coeffA_a = coeff_A_mf.array(mfi);
88 auto const& coeffB_a = coeff_B_mf.array(mfi);
89 auto const& coeffC_a = coeff_C_mf.array(mfi);
90 auto const& coeffP_a = coeff_P_mf.array(mfi);
91 auto const& coeffQ_a = coeff_Q_mf.array(mfi);
92 auto const& gam_a = gam_fab.array();
98 Box bx_shrunk_in_k = bx;
99 int klo = tbz.smallEnd(2);
100 int khi = tbz.bigEnd(2);
101 bx_shrunk_in_k.setSmall(2,klo+1);
102 bx_shrunk_in_k.setBig(2,khi-1);
107 Real halfg = std::abs(0.5 * grav_gpu[2]);
110 if (mesh_type != MeshType::ConstantDz)
112 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
114 Real rhobar_lo, rhobar_hi, pibar_lo, pibar_hi;
115 rhobar_lo = r0_ca(i,j,k-1);
116 rhobar_hi = r0_ca(i,j,k );
117 pibar_lo = pi0_ca(i,j,k-1);
118 pibar_hi = pi0_ca(i,j,k );
120 Real pi_c = 0.5 * (pi_stage_ca(i,j,k-1) + pi_stage_ca(i,j,k));
122 Real detJ_on_kface = 0.5 * (detJ(i,j,k) + detJ(i,j,k-1));
123 Real inv_detJ_on_kface = 1. / detJ_on_kface;
125 Real coeff_P = -
Gamma *
R_d * dzi * inv_detJ_on_kface
126 + halfg *
R_d * rhobar_hi /
130 Real coeff_Q =
Gamma *
R_d * dzi * inv_detJ_on_kface
131 + halfg *
R_d * rhobar_lo /
135 coeffP_a(i,j,k) = coeff_P;
136 coeffQ_a(i,j,k) = coeff_Q;
138 if (l_use_moisture) {
141 coeff_P /= (1.0 + q);
142 coeff_Q /= (1.0 + q);
150 Real D = dtau * dtau * beta_2 * beta_2 * dzi;
151 coeffA_a(i,j,k) = D * ( halfg - coeff_Q * theta_t_lo );
152 coeffC_a(i,j,k) = D * (-halfg + coeff_P * theta_t_hi );
154 coeffB_a(i,j,k) = detJ_on_kface + D * (coeff_Q - coeff_P) * theta_t_mid;
159 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
161 Real rhobar_lo, rhobar_hi, pibar_lo, pibar_hi;
162 rhobar_lo = r0_ca(i,j,k-1);
163 rhobar_hi = r0_ca(i,j,k );
164 pibar_lo = pi0_ca(i,j,k-1);
165 pibar_hi = pi0_ca(i,j,k );
167 Real pi_c = 0.5 * (pi_stage_ca(i,j,k-1) + pi_stage_ca(i,j,k));
170 + halfg *
R_d * rhobar_hi /
175 + halfg *
R_d * rhobar_lo /
179 coeffP_a(i,j,k) = coeff_P;
180 coeffQ_a(i,j,k) = coeff_Q;
182 if (l_use_moisture) {
185 coeff_P /= (1.0 + q);
186 coeff_Q /= (1.0 + q);
194 Real D = dtau * dtau * beta_2 * beta_2 * dzi;
195 coeffA_a(i,j,k) = D * ( halfg - coeff_Q * theta_t_lo );
196 coeffC_a(i,j,k) = D * (-halfg + coeff_P * theta_t_hi );
198 coeffB_a(i,j,k) = 1.0 + D * (coeff_Q - coeff_P) * theta_t_mid;
202 amrex::Box b2d = tbz;
205 auto const lo = amrex::lbound(bx);
206 auto const hi = amrex::ubound(bx);
208 auto const domhi = amrex::ubound(domain);
211 BL_PROFILE(
"make_coeffs_b2d_loop");
213 ParallelFor(b2d, [=] AMREX_GPU_DEVICE (
int i,
int j,
int) {
216 coeffA_a(i,j,lo.z) = 0.0;
217 coeffB_a(i,j,lo.z) = 1.0;
218 coeffC_a(i,j,lo.z) = 0.0;
221 coeffA_a(i,j,hi.z+1) = 0.0;
222 coeffB_a(i,j,hi.z+1) = 1.0;
223 coeffC_a(i,j,hi.z+1) = 0.0;
227 if ( (hi.z == domhi.z) &&
230 coeffA_a(i,j,hi.z+1) = -1.0;
234 Real bet = coeffB_a(i,j,lo.z);
236 for (
int k = lo.z+1; k <= hi.z+1; k++) {
237 gam_a(i,j,k) = coeffC_a(i,j,k-1) / bet;
238 bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam_a(i,j,k);
239 coeffB_a(i,j,k) = bet;
244 for (
int j = lo.y; j <= hi.y; ++j) {
246 for (
int i = lo.x; i <= hi.x; ++i) {
247 coeffA_a(i,j,lo.z) = 0.0;
248 coeffB_a(i,j,lo.z) = 1.0;
249 coeffC_a(i,j,lo.z) = 0.0;
252 for (
int j = lo.y; j <= hi.y; ++j) {
254 for (
int i = lo.x; i <= hi.x; ++i) {
257 coeffA_a(i,j,hi.z+1) = 0.0;
258 coeffB_a(i,j,hi.z+1) = 1.0;
259 coeffC_a(i,j,hi.z+1) = 0.0;
263 if ( (hi.z == domhi.z) &&
266 coeffA_a(i,j,hi.z+1) = -1.0;
270 for (
int k = lo.z+1; k <= hi.z+1; ++k) {
271 for (
int j = lo.y; j <= hi.y; ++j) {
273 for (
int i = lo.x; i <= hi.x; ++i) {
274 gam_a(i,j,k) = coeffC_a(i,j,k-1) / coeffB_a(i,j,k-1);
275 Real bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam_a(i,j,k);
276 coeffB_a(i,j,k) = bet;
285 BL_PROFILE(
"make_coeffs_invert");
286 ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
288 coeffB_a(i,j,k) = 1.0 / coeffB_a(i,j,k);
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_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ cons
Definition: ERF_IndexDefines.H:139