7 Vector<MultiFab>& S_slow_rhs,
8 const Vector<MultiFab>& S_old,
9 Vector<MultiFab>& S_stage,
10 Vector<MultiFab>& S_data,
14 const double old_substep_time,
15 const double 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;
31 bool l_variable_beta_s;
32 if (solverChoice.substepping_type[level] == SubsteppingType::Implicit) {
33 beta_s = solverChoice.beta_s;
34 l_variable_beta_s = solverChoice.use_variable_beta_s;
37 l_variable_beta_s =
false;
40 const GpuArray<Real, AMREX_SPACEDIM>
dxInv = fine_geom.InvCellSizeArray();
43 MultiFab* forest_drag = (solverChoice.do_forest_drag) ?
44 m_forest_drag[level]->get_drag_field() :
nullptr;
47 MultiFab* terrain_blank = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
48 solverChoice.buildings_type == BuildingsType::ImmersedForcing ) ?
49 terrain_blanking[level].
get() :
nullptr;
50 MultiFab* terrain_blank_xface = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
51 solverChoice.buildings_type == BuildingsType::ImmersedForcing ) ?
52 terrain_blanking_xface[level].
get() :
nullptr;
53 MultiFab* terrain_blank_yface = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
54 solverChoice.buildings_type == BuildingsType::ImmersedForcing ) ?
55 terrain_blanking_yface[level].
get() :
nullptr;
56 MultiFab* terrain_blank_zface = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
57 solverChoice.buildings_type == BuildingsType::ImmersedForcing ) ?
58 terrain_blanking_zface[level].
get() :
nullptr;
60 Vector<MultiFab> Svec_to_use;
64 Svec_to_use.push_back(MultiFab(S_old[
IntVars::xmom],make_alias,0,1));
65 Svec_to_use.push_back(MultiFab(S_old[
IntVars::ymom],make_alias,0,1));
66 Svec_to_use.push_back(MultiFab(S_old[
IntVars::zmom],make_alias,0,1));
70 Svec_to_use.push_back(MultiFab(S_data[
IntVars::xmom],make_alias,0,1));
71 Svec_to_use.push_back(MultiFab(S_data[
IntVars::ymom],make_alias,0,1));
72 Svec_to_use.push_back(MultiFab(S_data[
IntVars::zmom],make_alias,0,1));
76 bool l_use_IF = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
77 solverChoice.buildings_type == BuildingsType::ImmersedForcing);
78 Table1D<Real> r_avg_to_pass = l_use_IF ? r_plane_avg[level].table() : Table1D<Real>();
79 Table1D<Real> t_avg_to_pass = l_use_IF ? t_plane_avg[level].table() : Table1D<Real>();
82 Svec_to_use, S_prim, cc_src, base_state[level], z_phys_cc[level].
get(),
83 xvel_new, yvel_new, zvel_new,
84 qheating_rates[level].
get(),
85 terrain_blank, fine_geom, solverChoice,
87 rhotheta_src[level].
get(), rhoqt_src[level].
get(),
88 dptr_wbar_sub, d_rayleigh_ptrs_at_lev,
91 r_avg_to_pass, t_avg_to_pass,
98 const bool l_reflux =
IsRefluxStage(solverChoice, level, finest_level, nrk);
100 YAFluxRegister* fr_as_crse =
nullptr;
101 YAFluxRegister* fr_as_fine =
nullptr;
103 if (level < finest_level) {
104 fr_as_crse = getAdvFluxReg(level+1);
107 fr_as_fine = getAdvFluxReg(level);
111 MultiFab base_to_use;
112 if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh ) {
119 z_phys_nd[level].
get(), z_phys_cc[level].
get(), stretched_dz_h[level],
120 xvel_new, yvel_new, zvel_new,
121 xmom_src, ymom_src, zmom_src,
122 base_to_use, forest_drag, terrain_blank,
123 terrain_blank_xface, terrain_blank_yface, terrain_blank_zface,
124 cosPhi_m[level].
get(), sinPhi_m[level].
get(), fine_geom, solverChoice,
126 (solverChoice.have_geo_wind_profile) ? d_u_geos[level].data() :
nullptr,
127 (solverChoice.have_geo_wind_profile) ? d_v_geos[level].data() :
nullptr,
128 dptr_wbar_sub, d_rayleigh_ptrs_at_lev,
129 d_sinesq_at_lev, d_sinesq_stag_at_lev, d_sponge_ptrs_at_lev,
130 (solverChoice.hindcast_lateral_forcing? &forecast_state_interp[level] :
nullptr),
131 sounding_at_level(level), lsf_at_level(level), lsf_data[level],
132 get_eb(level),
false);
135 std::unique_ptr<MultiFab> z_t_pert;
136 if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh )
144 if ( (fast_step == 0) || (solverChoice.terrain_type == TerrainType::MovingFittedMesh) )
148 detJ_cc[level], dtau, beta_s, z_phys_nd[level].get(),
149 l_variable_beta_s, solverChoice.beta_s_min, solverChoice.beta_s_max,
154 Real l_damp_coef = solverChoice.dampingChoice.rayleigh_dampcoef;
160 Array<MultiFab, AMREX_SPACEDIM> cf_rec;
161 MultiFab cf_rec_om, cf_rec_om_old;
162 const bool cf_terrain = (solverChoice.mesh_type == MeshType::VariableDz);
166 const bool cf_record = cf_stage && cf_flux_history_active(level);
167 const bool cf_impose = cf_stage && (level > 0) && cf_flux_history_active(level-1);
170 for (
int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
171 cf_rec[dir].define(S_data[mom[dir]].boxArray(), S_data[mom[dir]].DistributionMap(), 1, 0);
172 cf_fluxes.
rec[dir] = &cf_rec[dir];
177 cf_fluxes.
rec_w = &cf_rec_om;
178 if (fast_step == 0) {
185 cf_flux_history_targets(level,
static_cast<Real>(old_substep_time),
186 static_cast<Real>(new_substep_time));
187 CFFluxHistory&
H = cf_flux_history(level);
188 for (
int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
189 cf_fluxes.
tgt[dir] = &
H.tgt[dir];
191 cf_fluxes.
tgt_w = &
H.tgt_w;
194 if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh )
197 S_slow_rhs, Svec_to_use, S_stage, S_prim,
qt, pi_stage, fast_coeffs,
198 S_data, lagged_delta_rt[level], avg_xmom[level], avg_ymom[level], avg_zmom[level],
199 cc_src, xmom_src, ymom_src, zmom_src,
201 solverChoice.gravity, solverChoice.use_lagged_delta_rt,
202 z_t_rk[level], z_t_pert.get(),
203 z_phys_nd[level], z_phys_nd_new[level], z_phys_nd_src[level],
204 detJ_cc[level], detJ_cc_new[level], detJ_cc_src[level],
205 dtau, inv_fac, mapfac[level],
206 fr_as_crse, fr_as_fine, l_use_moisture, l_reflux, solverChoice.use_real_bcs,
207 (l_rayleigh_implicit) ? d_sinesq_stag_ptrs[level].data() :
nullptr, l_damp_coef,
208 solverChoice.beta_d);
210 }
else if (cf_terrain) {
213 S_slow_rhs, Svec_to_use, S_stage, S_prim,
qt, pi_stage, fast_coeffs,
214 S_data, lagged_delta_rt[level], avg_xmom[level], avg_ymom[level], avg_zmom[level],
215 cc_src, xmom_src, ymom_src, zmom_src,
216 fine_geom, solverChoice.gravity,
217 z_phys_nd[level], detJ_cc[level], dtau, inv_fac,
219 fr_as_crse, fr_as_fine, l_use_moisture, l_reflux, solverChoice.use_real_bcs,
220 (l_rayleigh_implicit) ? d_sinesq_stag_ptrs[level].data() :
nullptr, l_damp_coef,
221 solverChoice.beta_d, cf_fluxes);
226 S_slow_rhs, Svec_to_use, S_stage, S_prim,
qt, pi_stage, fast_coeffs,
227 S_data, lagged_delta_rt[level], avg_xmom[level], avg_ymom[level], avg_zmom[level],
228 cc_src, xmom_src, ymom_src, zmom_src,
229 fine_geom, solverChoice.gravity, stretched_dz_d[level],
230 dtau, inv_fac, mapfac[level],
231 fr_as_crse, fr_as_fine, l_use_moisture, l_reflux, solverChoice.use_real_bcs,
232 (l_rayleigh_implicit) ? d_sinesq_stag_ptrs[level].data() :
nullptr, l_damp_coef,
233 solverChoice.beta_d, cf_fluxes);
240 const MultiFab& w_old = (cf_terrain) ? ((fast_step == 0) ? cf_rec_om_old : cf_rec_om)
242 const MultiFab& w_new = (cf_terrain) ? cf_rec_om : S_data[
IntVars::zmom];
243 cf_flux_history_record(level, fast_step, n_sub,
244 static_cast<Real>(old_substep_time),
static_cast<Real>(new_substep_time),
245 cf_rec, w_old, w_new);
257 if (!solverChoice.use_num_diff) {
262 if ( (solverChoice.vert_implicit_fac[level][nrk] > zero_d) &&
263 !solverChoice.implicit_before_substep &&
264 (fast_step == n_sub-1) )
272 apply_bcs(S_data, new_substep_time, ng_cons, ng_vel, fast_only=
true, vel_and_mom_synced=
false);
275 const Real stage_dt =
static_cast<Real>(n_sub * dtau);
277 MultiFab scratch_xmom(S_data[
IntVars::xmom], make_alias, 0, 1);
278 MultiFab scratch_ymom(S_data[
IntVars::ymom], make_alias, 0, 1);
283 if ( (solverChoice.dampingChoice.w_damping) &&
285 (fast_step == n_sub-1))
287 amrex::Real w_damping_const = solverChoice.dampingChoice.w_damping_const;
288 amrex::Real w_damping_coeff = solverChoice.dampingChoice.w_damping_coeff;
289 amrex::Real cflw_lim = solverChoice.dampingChoice.w_damping_cfl;
291 for ( MFIter mfi(S_data[
IntVars::cons]); mfi.isValid(); ++mfi)
293 Box tbz = mfi.nodaltilebox(2);
295 const Array4<const Real>& z_nd_arr = z_phys_nd[level]->const_array(mfi);
297 const Array4<const Real>& cell_data = S_data[
IntVars::cons].const_array(mfi);
298 const Array4< Real>& rho_w = S_data[
IntVars::zmom].array(mfi);
300 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
305 if (k == domain.smallEnd(2)) {
306 dzInv = amrex::Real(4.0) / (
307 z_nd_arr(i ,j ,k+1) - z_nd_arr(i ,j ,k)
308 + z_nd_arr(i+1,j ,k+1) - z_nd_arr(i+1,j ,k)
309 + z_nd_arr(i ,j+1,k+1) - z_nd_arr(i ,j+1,k)
310 + z_nd_arr(i+1,j+1,k+1) - z_nd_arr(i+1,j+1,k) );
311 }
else if (k == domain.bigEnd(2)+1) {
312 dzInv = amrex::Real(4.0) / (
313 z_nd_arr(i ,j ,k) - z_nd_arr(i ,j ,k-1)
314 + z_nd_arr(i+1,j ,k) - z_nd_arr(i+1,j ,k-1)
315 + z_nd_arr(i ,j+1,k) - z_nd_arr(i ,j+1,k-1)
316 + z_nd_arr(i+1,j+1,k) - z_nd_arr(i+1,j+1,k-1) );
320 dzInv = amrex::Real(8.0) / (
321 z_nd_arr(i ,j ,k+1) - z_nd_arr(i ,j ,k-1)
322 + z_nd_arr(i+1,j ,k+1) - z_nd_arr(i+1,j ,k-1)
323 + z_nd_arr(i ,j+1,k+1) - z_nd_arr(i ,j+1,k-1)
324 + z_nd_arr(i+1,j+1,k+1) - z_nd_arr(i+1,j+1,k-1) );
330 Real dt_adv =
static_cast<Real>(dt_advance);
332 Real dampcoef = (w_damping_const > 0) ? w_damping_const
333 : w_damping_coeff / (dzInv * dt_adv * dt_adv);
336 Real wmag = std::abs(rho_w(i,j,k) / rho_on_w_face);
339 Real cflw = wmag * dt_adv * dzInv;
341 if (cflw > cflw_lim) {
343 rho_w(i, j, k) -= rho_on_w_face * sgn_w * dampcoef * (cflw - cflw_lim) * dt_adv;
346 AMREX_DEVICE_PRINTF(
"t=%f w-damping applied at (%d,%d,%d) for w-CFL = %f > %f : %f --> %f\n",
347 old_time+dt_adv, i,j,k, cflw, cflw_lim, sgn_w*wmag, rho_w(i,j,k)/rho_on_w_face);
349 printf(
"t=%f w-damping applied at (%d,%d,%d) for w-CFL = %f > %f : %f --> %f\n",
350 old_time+dt_adv, i,j,k, cflw, cflw_lim, sgn_w*wmag, rho_w(i,j,k)/rho_on_w_face);
357 apply_bcs(S_data, new_substep_time, ng_cons, ng_vel, fast_only=
true, vel_and_mom_synced=
false);
#define Rho_comp
Definition: ERF_IndexDefines.H:53
pp_for_pert_vels get("prob_type", prob_type)
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
if(KE_decay_height > 0 &&state_pert.nComp() > RhoKE_comp)
Definition: ERF_InitCustomPert_ABL.H:74
Real H
Definition: ERF_InitCustomPert_MovingTerrain.H:8
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_nd, bool use_variable_beta_s, Real beta_s_min, Real beta_s_max, amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &phys_bc_type)
Definition: ERF_MakeFastCoeffs.cpp:35
void make_mom_sources(double time_d, double dt, 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 *terrain_blank_xface, MultiFab *terrain_blank_yface, MultiFab *terrain_blank_zface, 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, const InputSoundingData &input_sounding_data, const LargeScaleForcingData &lsf_data, std::unique_ptr< amrex::MultiFab > &lsf_tendencies, const eb_ &ebfact, bool is_slow_step)
Definition: ERF_MakeMomSources.cpp:40
void make_sources(int level, int, double dt, double time_d, 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 &zvel, const MultiFab *qheating_rates, MultiFab *terrain_blank, const Geometry geom, const SolverChoice &solverChoice, Vector< std::unique_ptr< MultiFab >> &mapfac, const MultiFab *rhotheta_src, const MultiFab *rhoqt_src, const Real *dptr_wbar_sub, const Vector< Real * > d_rayleigh_ptrs_at_lev, const Real *d_sinesq_at_lev, TurbulentPerturbation &turbPert, const Table1D< Real > r_plane_avg, const Table1D< Real > t_plane_avg, const MultiFab *forest_drag, const MultiFab *cons_old, bool is_slow_step, MultiFab *ib_wall_hfx, MultiFab *ib_wall_ktarget)
Definition: ERF_MakeSources.cpp:39
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 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::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 double dtau_d, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux, bool, const Real *sinesq_stag_d, const Real l_damp_coef, const Real beta_d)
Definition: ERF_Substep_MT.cpp:52
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 double dtau_d, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux, bool l_real_bc, const amrex::Real *sinesq_stag_d, const Real l_damp_coef, const Real beta_d, const CFFaceFluxes &cf_fluxes)
Definition: ERF_Substep_NS.cpp:45
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 double dtau_d, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux, bool l_real_bc, const Real *sinesq_stag_d, const Real l_damp_coef, const Real beta_d, const CFFaceFluxes &cf_fluxes)
Definition: ERF_Substep_T.cpp:68
auto acoustic_substepping_fun
Definition: ERF_TI_substep_fun.H:6
auto apply_bcs
Definition: ERF_TI_utils.H:34
auto update_terrain_substep
Definition: ERF_TI_utils.H:203
@ num_comps
Definition: ERF_IndexDefines.H:102
@ ymom
Definition: ERF_IndexDefines.H:274
@ cons
Definition: ERF_IndexDefines.H:272
@ zmom
Definition: ERF_IndexDefines.H:275
@ xmom
Definition: ERF_IndexDefines.H:273
@ None
Definition: ERF_LSM_Types.H:6
@ qt
Definition: ERF_Kessler.H:30
Definition: ERF_TI_fast_headers.H:28
std::array< amrex::MultiFab *, AMREX_SPACEDIM > rec
Definition: ERF_TI_fast_headers.H:29
amrex::MultiFab * rec_w
Definition: ERF_TI_fast_headers.H:30
const amrex::MultiFab * tgt_w
Definition: ERF_TI_fast_headers.H:33
std::array< const amrex::MultiFab *, AMREX_SPACEDIM > tgt
Definition: ERF_TI_fast_headers.H:32
amrex::MultiFab * rec_w_old
Definition: ERF_TI_fast_headers.H:31
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:2604