7 Vector<MultiFab>& S_slow_rhs,
8 const Vector<MultiFab>& S_old,
9 Vector<MultiFab>& S_stage,
10 Vector<MultiFab>& S_data,
14 const Real old_substep_time,
15 const Real new_substep_time)
17 BL_PROFILE(
"acoustic_substepping_fun");
18 if (verbose) amrex::Print() <<
"Fast time integration at level " << level
19 << std::setprecision(timeprecision)
20 <<
" from " << old_substep_time <<
" to " << new_substep_time
21 <<
" with dt = " << dtau << std::endl;
29 if (solverChoice.substepping_type[level] == SubsteppingType::Implicit) {
30 beta_s = solverChoice.beta_s;
35 const GpuArray<Real, AMREX_SPACEDIM> dxInv = fine_geom.InvCellSizeArray();
38 MultiFab* forest_drag = (solverChoice.do_forest_drag) ?
39 m_forest_drag[level]->get_drag_field() :
nullptr;
42 MultiFab* terrain_blank = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
43 solverChoice.buildings_type == BuildingsType::ImmersedForcing ) ?
44 terrain_blanking[level].get() :
nullptr;
46 Vector<MultiFab> Svec_to_use;
50 Svec_to_use.push_back(MultiFab(S_old[
IntVars::xmom],make_alias,0,1));
51 Svec_to_use.push_back(MultiFab(S_old[
IntVars::ymom],make_alias,0,1));
52 Svec_to_use.push_back(MultiFab(S_old[
IntVars::zmom],make_alias,0,1));
56 Svec_to_use.push_back(MultiFab(S_data[
IntVars::xmom],make_alias,0,1));
57 Svec_to_use.push_back(MultiFab(S_data[
IntVars::ymom],make_alias,0,1));
58 Svec_to_use.push_back(MultiFab(S_data[
IntVars::zmom],make_alias,0,1));
62 Svec_to_use, S_prim, cc_src, base_state[level], z_phys_cc[level].get(),
64 qheating_rates[level].get(),
65 terrain_blank, fine_geom, solverChoice,
67 dptr_rhotheta_src, dptr_rhoqt_src,
68 dptr_wbar_sub, d_rayleigh_ptrs_at_lev,
70 input_sounding_data, turbPert,
false);
75 const bool l_reflux = ( (solverChoice.coupling_type == CouplingType::TwoWay) && (nrk == 2) && (finest_level > 0) );
77 YAFluxRegister* fr_as_crse =
nullptr;
78 YAFluxRegister* fr_as_fine =
nullptr;
80 if (level < finest_level) {
81 fr_as_crse = getAdvFluxReg(level+1);
84 fr_as_fine = getAdvFluxReg(level);
89 if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh ) {
96 z_phys_nd[level].get(), z_phys_cc[level].get(), stretched_dz_h[level],
97 xvel_new, yvel_new, zvel_new,
98 xmom_src, ymom_src, zmom_src,
99 base_to_use, forest_drag, terrain_blank,
100 cosPhi_m[level].get(), sinPhi_m[level].get(), fine_geom, solverChoice,
102 (solverChoice.have_geo_wind_profile) ? d_u_geos[level].data() :
nullptr,
103 (solverChoice.have_geo_wind_profile) ? d_v_geos[level].data() :
nullptr,
104 dptr_wbar_sub, d_rayleigh_ptrs_at_lev,
105 d_sinesq_at_lev, d_sinesq_stag_at_lev, d_sponge_ptrs_at_lev,
106 (solverChoice.hindcast_lateral_forcing? &forecast_state_interp[level] :
nullptr),
107 input_sounding_data,
false);
110 std::unique_ptr<MultiFab> z_t_pert;
111 if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh )
117 bool l_use_moisture = ( solverChoice.moisture_type != MoistureType::None );
119 if ( (fast_step == 0) || (solverChoice.terrain_type == TerrainType::MovingFittedMesh) )
123 detJ_cc[level], r0, pi0, dtau, beta_s, phys_bc_type);
127 Real l_damp_coef = solverChoice.dampingChoice.rayleigh_dampcoef;
129 if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh )
132 S_slow_rhs, Svec_to_use, S_stage, S_prim,
qt, pi_stage, fast_coeffs,
133 S_data, lagged_delta_rt[level], avg_xmom[level], avg_ymom[level], avg_zmom[level],
134 cc_src, xmom_src, ymom_src, zmom_src,
136 solverChoice.gravity, solverChoice.use_lagged_delta_rt,
137 z_t_rk[level], z_t_pert.get(),
138 z_phys_nd[level], z_phys_nd_new[level], z_phys_nd_src[level],
139 detJ_cc[level], detJ_cc_new[level], detJ_cc_src[level],
140 dtau, beta_s, inv_fac, mapfac[level],
141 fr_as_crse, fr_as_fine, l_use_moisture, l_reflux);
143 }
else if (solverChoice.mesh_type == MeshType::VariableDz) {
146 S_slow_rhs, Svec_to_use, S_stage, S_prim,
qt, pi_stage, fast_coeffs,
147 S_data, lagged_delta_rt[level], avg_xmom[level], avg_ymom[level], avg_zmom[level],
148 cc_src, xmom_src, ymom_src, zmom_src,
149 fine_geom, solverChoice.gravity,
150 z_phys_nd[level], detJ_cc[level], dtau, beta_s, inv_fac,
152 fr_as_crse, fr_as_fine, l_use_moisture, l_reflux,
153 (l_rayleigh_implicit) ? d_sinesq_ptrs[level].data() :
nullptr, l_damp_coef);
158 S_slow_rhs, Svec_to_use, S_stage, S_prim,
qt, pi_stage, fast_coeffs,
159 S_data, lagged_delta_rt[level], avg_xmom[level], avg_ymom[level], avg_zmom[level],
160 cc_src, xmom_src, ymom_src, zmom_src,
161 fine_geom, solverChoice.gravity, stretched_dz_d[level],
162 dtau, beta_s, inv_fac, mapfac[level],
163 fr_as_crse, fr_as_fine, l_use_moisture, l_reflux,
164 (l_rayleigh_implicit) ? d_sinesq_ptrs[level].data() :
nullptr, l_damp_coef);
170 if ( (solverChoice.vert_implicit_fac[nrk] > 0.) && !solverChoice.implicit_before_substep &&
171 (fast_step == n_sub-1) )
174 MultiFab scratch_xmom(S_data[
IntVars::xmom], make_alias, 0, 1);
175 MultiFab scratch_ymom(S_data[
IntVars::ymom], make_alias, 0, 1);
176 #ifdef ERF_IMPLICIT_W
177 MultiFab scratch_zmom(S_data[
IntVars::zmom], make_alias, 0, 1);
183 if ( (solverChoice.dampingChoice.w_damping) &&
185 (fast_step == n_sub-1))
187 amrex::Real w_damping_const = solverChoice.dampingChoice.w_damping_const;
188 amrex::Real w_damping_coeff = solverChoice.dampingChoice.w_damping_coeff;
189 amrex::Real cflw_lim = solverChoice.dampingChoice.w_damping_cfl;
191 for ( MFIter mfi(S_data[
IntVars::cons]); mfi.isValid(); ++mfi)
193 Box tbz = mfi.nodaltilebox(2);
195 const Array4<const Real>& z_nd_arr = z_phys_nd[level]->const_array(mfi);
197 const Array4<const Real>& cell_data = S_data[
IntVars::cons].const_array(mfi);
198 const Array4< Real>& rho_w = S_data[
IntVars::zmom].array(mfi);
200 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
205 if (k == domain.smallEnd(2)) {
207 z_nd_arr(i ,j ,k+1) - z_nd_arr(i ,j ,k)
208 + z_nd_arr(i+1,j ,k+1) - z_nd_arr(i+1,j ,k)
209 + z_nd_arr(i ,j+1,k+1) - z_nd_arr(i ,j+1,k)
210 + z_nd_arr(i+1,j+1,k+1) - z_nd_arr(i+1,j+1,k) );
211 }
else if (k == domain.bigEnd(2)+1) {
213 z_nd_arr(i ,j ,k) - z_nd_arr(i ,j ,k-1)
214 + z_nd_arr(i+1,j ,k) - z_nd_arr(i+1,j ,k-1)
215 + z_nd_arr(i ,j+1,k) - z_nd_arr(i ,j+1,k-1)
216 + z_nd_arr(i+1,j+1,k) - z_nd_arr(i+1,j+1,k-1) );
221 z_nd_arr(i ,j ,k+1) - z_nd_arr(i ,j ,k-1)
222 + z_nd_arr(i+1,j ,k+1) - z_nd_arr(i+1,j ,k-1)
223 + z_nd_arr(i ,j+1,k+1) - z_nd_arr(i ,j+1,k-1)
224 + z_nd_arr(i+1,j+1,k+1) - z_nd_arr(i+1,j+1,k-1) );
230 Real dampcoef = (w_damping_const > 0)
232 : w_damping_coeff / (dzInv * dt_advance * dt_advance);
235 Real wmag = std::abs(rho_w(i,j,k) / rho_on_w_face);
238 Real cflw = wmag * dt_advance * dzInv;
240 if (cflw > cflw_lim) {
241 Real sgn_w = (rho_w(i,j,k) > 0) ? 1.0 : -1.0;
242 rho_w(i, j, k) -= rho_on_w_face * sgn_w * dampcoef * (cflw - cflw_lim) * dt_advance;
245 AMREX_DEVICE_PRINTF(
"t=%f w-damping applied at (%d,%d,%d) for w-CFL = %f > %f : %f --> %f\n",
246 old_time+dt_advance, i,j,k, cflw, cflw_lim, sgn_w*wmag, rho_w(i,j,k)/rho_on_w_face);
248 printf(
"t=%f w-damping applied at (%d,%d,%d) for w-CFL = %f > %f : %f --> %f\n",
249 old_time+dt_advance, i,j,k, cflw, cflw_lim, sgn_w*wmag, rho_w(i,j,k)/rho_on_w_face);
262 if (!solverChoice.use_num_diff) {
266 apply_bcs(S_data, new_substep_time, ng_cons, ng_vel, fast_only=
true, vel_and_mom_synced=
false);
if(l_use_mynn &&start_comp<=RhoKE_comp &&end_comp >=RhoKE_comp)
Definition: ERF_AddQKESources.H:2
#define Rho_comp
Definition: ERF_IndexDefines.H:36
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
void make_mom_sources(Real time, Real, const Vector< MultiFab > &S_data, const MultiFab *z_phys_nd, const MultiFab *z_phys_cc, Vector< Real > &stretched_dz_h, const MultiFab &xvel, const MultiFab &yvel, const MultiFab &wvel, MultiFab &xmom_src, MultiFab &ymom_src, MultiFab &zmom_src, const MultiFab &base_state, MultiFab *forest_drag, MultiFab *terrain_blank, MultiFab *cosPhi_mf, MultiFab *sinPhi_mf, const Geometry geom, const SolverChoice &solverChoice, Vector< std::unique_ptr< MultiFab >> &, const Real *dptr_u_geos, const Real *dptr_v_geos, const Real *dptr_wbar_sub, const Vector< Real * > d_rayleigh_ptrs_at_lev, const amrex::Real *d_sinesq_at_lev, const amrex::Real *d_sinesq_stag_at_lev, const Vector< Real * > d_sponge_ptrs_at_lev, const Vector< MultiFab > *forecast_state_at_lev, InputSoundingData &input_sounding_data, bool is_slow_step)
Definition: ERF_MakeMomSources.cpp:37
void make_sources(int level, int, Real dt, Real time, const Vector< MultiFab > &S_data, const MultiFab &S_prim, MultiFab &source, const MultiFab &base_state, const MultiFab *z_phys_cc, const MultiFab &xvel, const MultiFab &yvel, const MultiFab *qheating_rates, MultiFab *terrain_blank, const Geometry geom, const SolverChoice &solverChoice, Vector< std::unique_ptr< MultiFab >> &mapfac, const Real *dptr_rhotheta_src, const Real *dptr_rhoqt_src, const Real *dptr_wbar_sub, const Vector< Real * > d_rayleigh_ptrs_at_lev, const Real *d_sinesq_at_lev, InputSoundingData &input_sounding_data, TurbulentPerturbation &turbPert, bool is_slow_step)
Definition: ERF_MakeSources.cpp:33
amrex::Real Real
Definition: ERF_ShocInterface.H:19
void erf_substep_MT(int step, int, int level, int finest_level, Vector< MultiFab > &S_slow_rhs, const Vector< MultiFab > &S_prev, Vector< MultiFab > &S_stg_data, const MultiFab &S_stg_prim, const MultiFab &qt, const MultiFab &pi_stage, const MultiFab &fast_coeffs, Vector< MultiFab > &S_data, MultiFab &lagged_delta_rt, MultiFab &avg_xmom, MultiFab &avg_ymom, MultiFab &avg_zmom, const MultiFab &cc_src, const MultiFab &xmom_src, const MultiFab &ymom_src, const MultiFab &zmom_src, const Geometry geom, const Real gravity, const bool use_lagged_delta_rt, std::unique_ptr< MultiFab > &z_t_rk, const MultiFab *z_t_pert, std::unique_ptr< MultiFab > &z_phys_nd_old, std::unique_ptr< MultiFab > &z_phys_nd_new, std::unique_ptr< MultiFab > &z_phys_nd_stg, std::unique_ptr< MultiFab > &detJ_cc_old, std::unique_ptr< MultiFab > &detJ_cc_new, std::unique_ptr< MultiFab > &detJ_cc_stg, const Real dtau, const Real beta_s, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux)
Definition: ERF_Substep_MT.cpp:49
void erf_substep_NS(int step, int nrk, int level, int finest_level, Vector< MultiFab > &S_slow_rhs, const Vector< MultiFab > &S_prev, Vector< MultiFab > &S_stage_data, const MultiFab &S_stage_prim, const MultiFab &qt, const MultiFab &pi_stage, const MultiFab &fast_coeffs, Vector< MultiFab > &S_data, MultiFab &lagged_delta_rt, MultiFab &avg_xmom, MultiFab &avg_ymom, MultiFab &avg_zmom, const MultiFab &cc_src, const MultiFab &xmom_src, const MultiFab &ymom_src, const MultiFab &zmom_src, const Geometry geom, const Real gravity, amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const Real dtau, const Real beta_s, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux, const amrex::Real *sinesq_stag_d, const Real l_damp_coef)
Definition: ERF_Substep_NS.cpp:42
void erf_substep_T(int step, int, int level, int finest_level, Vector< MultiFab > &S_slow_rhs, const Vector< MultiFab > &S_prev, Vector< MultiFab > &S_stage_data, const MultiFab &S_stage_prim, const MultiFab &qt, const MultiFab &pi_stage, const MultiFab &fast_coeffs, Vector< MultiFab > &S_data, MultiFab &lagged_delta_rt, MultiFab &avg_xmom, MultiFab &avg_ymom, MultiFab &avg_zmom, const MultiFab &cc_src, const MultiFab &xmom_src, const MultiFab &ymom_src, const MultiFab &zmom_src, const Geometry geom, const Real gravity, std::unique_ptr< MultiFab > &z_phys_nd, std::unique_ptr< MultiFab > &detJ_cc, const Real dtau, const Real beta_s, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux, const Real *sinesq_stag_d, const Real l_damp_coef)
Definition: ERF_Substep_T.cpp:43
auto acoustic_substepping_fun
Definition: ERF_TI_substep_fun.H:6
auto apply_bcs
Definition: ERF_TI_utils.H:73
auto update_terrain_substep
Definition: ERF_TI_utils.H:238
@ num_comps
Definition: ERF_IndexDefines.H:68
@ ymom
Definition: ERF_IndexDefines.H:160
@ cons
Definition: ERF_IndexDefines.H:158
@ zmom
Definition: ERF_IndexDefines.H:161
@ xmom
Definition: ERF_IndexDefines.H:159
@ qt
Definition: ERF_Kessler.H:27
static MeshType mesh_type
Definition: ERF_DataStruct.H:983