Function for computing the slow RHS for the evolution equations for the density, potential temperature and momentum.
53 BL_PROFILE_REGION(
"erf_make_sources()");
61 const bool use_terrain = solverChoice.
terrain_type != TerrainType::None;
64 const bool l_use_KE = ( (tc.
les_type == LESType::Deardorff) ||
68 const Box& domain = geom.Domain();
70 const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
77 Table1D<Real> dptr_r_plane, dptr_t_plane, dptr_qv_plane, dptr_qc_plane;
78 TableData<Real, 1> r_plane_tab, t_plane_tab, qv_plane_tab, qc_plane_tab;
83 r_ave.compute_averages(
ZDir(), r_ave.field());
85 int ncell = r_ave.ncell_line();
86 Gpu::HostVector< Real> r_plane_h(ncell);
87 Gpu::DeviceVector< Real> r_plane_d(ncell);
89 r_ave.line_average(
Rho_comp, r_plane_h);
91 Gpu::copyAsync(Gpu::hostToDevice, r_plane_h.begin(), r_plane_h.end(), r_plane_d.begin());
93 Real* dptr_r = r_plane_d.data();
96 Box tdomain = domain; tdomain.grow(2,ng_c[2]);
97 r_plane_tab.resize({tdomain.smallEnd(2)}, {tdomain.bigEnd(2)});
100 dptr_r_plane = r_plane_tab.table();
101 ParallelFor(ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
103 dptr_r_plane(k-
offset) = dptr_r[k];
108 t_ave.compute_averages(
ZDir(), t_ave.field());
110 Gpu::HostVector< Real> t_plane_h(ncell);
111 Gpu::DeviceVector< Real> t_plane_d(ncell);
115 Gpu::copyAsync(Gpu::hostToDevice, t_plane_h.begin(), t_plane_h.end(), t_plane_d.begin());
117 Real* dptr_t = t_plane_d.data();
119 t_plane_tab.resize({tdomain.smallEnd(2)}, {tdomain.bigEnd(2)});
121 dptr_t_plane = t_plane_tab.table();
122 ParallelFor(ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
124 dptr_t_plane(k-
offset) = dptr_t[k];
129 Gpu::HostVector< Real> qv_plane_h(ncell), qc_plane_h(ncell);
130 Gpu::DeviceVector<Real> qv_plane_d(ncell), qc_plane_d(ncell);
134 qv_ave.compute_averages(
ZDir(), qv_ave.field());
136 Gpu::copyAsync(Gpu::hostToDevice, qv_plane_h.begin(), qv_plane_h.end(), qv_plane_d.begin());
140 qc_ave.compute_averages(
ZDir(), qc_ave.field());
142 Gpu::copyAsync(Gpu::hostToDevice, qc_plane_h.begin(), qc_plane_h.end(), qc_plane_d.begin());
144 Real* dptr_qv = qv_plane_d.data();
145 Real* dptr_qc = qc_plane_d.data();
147 qv_plane_tab.resize({tdomain.smallEnd(2)}, {tdomain.bigEnd(2)});
148 qc_plane_tab.resize({tdomain.smallEnd(2)}, {tdomain.bigEnd(2)});
150 dptr_qv_plane = qv_plane_tab.table();
151 dptr_qc_plane = qc_plane_tab.table();
152 ParallelFor(ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
154 dptr_qv_plane(k-
offset) = dptr_qv[k];
155 dptr_qc_plane(k-
offset) = dptr_qc[k];
177 #pragma omp parallel if (Gpu::notInLaunchRegion())
182 Box bx = mfi.tilebox();
184 const Array4<const Real> & cell_data = S_data[
IntVars::cons].array(mfi);
185 const Array4<const Real> & cell_prim = S_prim.array(mfi);
186 const Array4<Real> & cell_src = source.array(mfi);
188 const Array4<const Real>& z_cc_arr = (use_terrain) ? z_phys_cc->const_array(mfi) : Array4<Real>{};
190 #ifdef ERF_USE_RRTMGP
195 auto const& qheating_arr = qheating_rates->const_array(mfi);
196 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
199 cell_src(i,j,k,
RhoTheta_comp) += qheating_arr(i,j,k,0) + qheating_arr(i,j,k,1);
208 Real zlo = geom.ProbLo(2);
209 Real dz = geom.CellSize(2);
218 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
220 Real zcc = (z_cc_arr) ? z_cc_arr(i,j,k) : zlo + (k+0.5)*dz;
221 Real zfrac = 1 - (ztop - zcc) / zdamp;
223 Real
theta = cell_prim(i,j,k,np);
224 Real sinefac = std::sin(
PIoTwo*zfrac);
225 cell_src(i, j, k, n) -= dampcoef*sinefac*sinefac * (
theta -
thetabar[k]) * cell_data(i,j,k,nr);
237 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
239 cell_src(i, j, k, n) += cell_data(i,j,k,nr) * dptr_rhotheta_src[k];
242 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
244 cell_src(i, j, k, n) += dptr_rhotheta_src[k];
256 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
258 cell_src(i, j, k, n) += cell_data(i,j,k,nr) * dptr_rhoqt_src[k];
261 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
263 cell_src(i, j, k, n) += dptr_rhoqt_src[k];
275 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
277 Real dzInv = (z_cc_arr) ? 1.0/ (z_cc_arr(i,j,k+1) - z_cc_arr(i,j,k-1)) : 0.5*dxInv[2];
278 Real T_hi = dptr_t_plane(k+1) / dptr_r_plane(k+1);
279 Real T_lo = dptr_t_plane(k-1) / dptr_r_plane(k-1);
280 Real wbar_cc = 0.5 * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
281 cell_src(i, j, k, n) -= cell_data(i,j,k,nr) * wbar_cc * (T_hi - T_lo) * dzInv;
284 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
286 Real dzInv = (z_cc_arr) ? 1.0/ (z_cc_arr(i,j,k+1) - z_cc_arr(i,j,k-1)) : 0.5*dxInv[2];
287 Real T_hi = dptr_t_plane(k+1) / dptr_r_plane(k+1);
288 Real T_lo = dptr_t_plane(k-1) / dptr_r_plane(k-1);
289 Real wbar_cc = 0.5 * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
290 cell_src(i, j, k, n) -= wbar_cc * (T_hi - T_lo) * dzInv;
302 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
304 Real dzInv = (z_cc_arr) ? 1.0/ (z_cc_arr(i,j,k+1) - z_cc_arr(i,j,k-1)) : 0.5*dxInv[2];
305 Real Qv_hi = dptr_qv_plane(k+1) / dptr_r_plane(k+1);
306 Real Qv_lo = dptr_qv_plane(k-1) / dptr_r_plane(k-1);
307 Real Qc_hi = dptr_qc_plane(k+1) / dptr_r_plane(k+1);
308 Real Qc_lo = dptr_qc_plane(k-1) / dptr_r_plane(k-1);
309 Real wbar_cc = 0.5 * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
310 cell_src(i, j, k, nv ) -= cell_data(i,j,k,nr) * wbar_cc * (Qv_hi - Qv_lo) * dzInv;
311 cell_src(i, j, k, nv+1) -= cell_data(i,j,k,nr) * wbar_cc * (Qc_hi - Qc_lo) * dzInv;
314 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
316 Real dzInv = (z_cc_arr) ? 1.0/ (z_cc_arr(i,j,k+1) - z_cc_arr(i,j,k-1)) : 0.5*dxInv[2];
317 Real Qv_hi = dptr_qv_plane(k+1) / dptr_r_plane(k+1);
318 Real Qv_lo = dptr_qv_plane(k-1) / dptr_r_plane(k-1);
319 Real Qc_hi = dptr_qc_plane(k+1) / dptr_r_plane(k+1);
320 Real Qc_lo = dptr_qc_plane(k-1) / dptr_r_plane(k-1);
321 Real wbar_cc = 0.5 * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
322 cell_src(i, j, k, nv ) -= wbar_cc * (Qv_hi - Qv_lo) * dzInv;
323 cell_src(i, j, k, nv+1) -= wbar_cc * (Qc_hi - Qc_lo) * dzInv;
335 const Array4<const Real>& mf_m = mapfac_m->const_array(mfi);
339 cell_data, cell_data, cell_src, mf_m);
343 cell_prim, cell_data, cell_src, mf_m);
346 if (l_use_KE && l_diff_KE) {
348 cell_prim, cell_data, cell_src, mf_m);
352 cell_prim, cell_data, cell_src, mf_m);
365 if (solverChoice.
pert_type == PerturbationType::Source) {
367 const amrex::Array4<const amrex::Real>& pert_cell = turbPert.
pb_cell.const_array(mfi);
378 Real coeff_n = Real(1.0);
379 Real coeff_np1 = Real(0.0);
381 Real tau_inv = Real(1.0) / input_sounding_data.
tau_nudging;
385 for (
int nt = 1; nt < n_sounding_times; nt++) {
388 if (itime_n == n_sounding_times-1) {
391 itime_np1 = itime_n+1;
394 coeff_n = Real(1.0) - coeff_np1;
397 const Real* theta_inp_sound_n = input_sounding_data.
theta_inp_sound_d[itime_n].dataPtr();
398 const Real* theta_inp_sound_np1 = input_sounding_data.
theta_inp_sound_d[itime_np1].dataPtr();
403 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
405 Real nudge = (coeff_n*theta_inp_sound_n[k] + coeff_np1*theta_inp_sound_np1[k]) - (dptr_t_plane(k)/dptr_r_plane(k));
407 cell_src(i, j, k, n) += cell_data(i, j, k, nr) * nudge;
void ApplySpongeZoneBCsForCC(const SpongeChoice &spongeChoice, const Geometry geom, const Box &bx, const Array4< Real > &cell_rhs, const Array4< const Real > &cell_data)
Definition: ERF_ApplySpongeZoneBCs.cpp:7
constexpr amrex::Real PIoTwo
Definition: ERF_Constants.H:7
@ thetabar
Definition: ERF_DataStruct.H:70
DirectionSelector< 2 > ZDir
Definition: ERF_DirectionSelector.H:38
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:43
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define PrimTheta_comp
Definition: ERF_IndexDefines.H:50
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38
void NumericalDiffusion_Scal(const Box &bx, const int start_comp, const int num_comp, const Real dt, const Real num_diff_coeff, const Array4< const Real > &prim_data, const Array4< const Real > &cell_data, const Array4< Real > &rhs, const Array4< const Real > &mf_arr)
Definition: ERF_NumericalDiffusion.cpp:18
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:28
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
Definition: ERF_PlaneAverage.H:14
@ cons
Definition: ERF_IndexDefines.H:139
@ theta
Definition: ERF_MM5.H:20
bool rayleigh_damp_T
Definition: ERF_DataStruct.H:608
amrex::Real rayleigh_zdamp
Definition: ERF_DataStruct.H:610
bool custom_rhotheta_forcing
Definition: ERF_DataStruct.H:634
bool custom_w_subsidence
Definition: ERF_DataStruct.H:636
bool nudging_from_input_sounding
Definition: ERF_DataStruct.H:642
amrex::Real rayleigh_ztop
Definition: ERF_DataStruct.H:611
bool use_num_diff
Definition: ERF_DataStruct.H:657
bool custom_moisture_forcing
Definition: ERF_DataStruct.H:635
amrex::Real num_diff_coeff
Definition: ERF_DataStruct.H:658
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:581
MoistureType moisture_type
Definition: ERF_DataStruct.H:664
bool custom_forcing_prim_vars
Definition: ERF_DataStruct.H:638
static TerrainType terrain_type
Definition: ERF_DataStruct.H:567
PerturbationType pert_type
Definition: ERF_DataStruct.H:654
SpongeChoice spongeChoice
Definition: ERF_DataStruct.H:580
amrex::Real rayleigh_dampcoef
Definition: ERF_DataStruct.H:609
int ave_plane
Definition: ERF_DataStruct.H:675
std::string sponge_type
Definition: ERF_SpongeStruct.H:61
Definition: ERF_TurbStruct.H:31
PBLType pbl_type
Definition: ERF_TurbStruct.H:201
bool diffuse_KE_3D
Definition: ERF_TurbStruct.H:216
LESType les_type
Definition: ERF_TurbStruct.H:175
amrex::MultiFab pb_cell
Definition: ERF_TurbPertStruct.H:536
void apply_tpi(const int &lev, const amrex::Box &vbx, const int &comp, const amrex::IndexType &m_ixtype, const amrex::Array4< amrex::Real > &src_arr, const amrex::Array4< amrex::Real const > &pert_cell)
Definition: ERF_TurbPertStruct.H:245