ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ImplicitPre.H
Go to the documentation of this file.
1  // *****************************************************************************
2  // Do semi-implicit solve for diffusion: theta, u, and v
3  // *****************************************************************************
4  {
5  const Real l_vert_implicit_fac = solverChoice.vert_implicit_fac[level][nrk];
6 
8 
9  const bool l_do_implicit_theta = solverChoice.implicit_thermal_diffusion;
10  const bool l_do_implicit_mom = solverChoice.implicit_momentum_diffusion;
11 
12  // If we're doing an implicit solve for momenta (u and v only),
13  // then we use the explicit solution at this point to derive
14  // the surface velocity gradient -- to be consistent with the
15  // hoextrap used with the surface layer BC. We then subtract
16  // out the contribution from the gradient of tau_corr times
17  // (1 - implicit_fac) and add in the implicit solution scaled
18  // by implicit_fac.
19  MultiFab* Tau13corr = (l_do_implicit_mom) ? Tau_corr[level][0].get() : nullptr;
20  MultiFab* Tau23corr = (l_do_implicit_mom) ? Tau_corr[level][1].get() : nullptr;
21 #ifdef ERF_IMPLICIT_W
22  MultiFab* Tau33corr = (l_do_implicit_mom) ? Tau_corr[level][2].get() : nullptr;
23 #endif
24 
25  // BCs
26  const BCRec* bc_ptr_h = domain_bcs_type.data();
27  GpuArray<Real, AMREX_SPACEDIM*2> l_bc_neumann_vals_d;
28  for (int ori = 0; ori < 2*AMREX_SPACEDIM; ori++) {
29  l_bc_neumann_vals_d[ori] = m_bc_neumann_vals[RhoTheta_comp][ori];
30  }
31  const bool l_use_SurfLayer = (m_SurfaceLayer[Orientation(Direction::z, Orientation::low)] != nullptr);
32 
33  const bool l_use_turb = solverChoice.turbChoice[level].use_kturb;
34 
35  const bool l_use_stretched_dz = (solverChoice.mesh_type == MeshType::StretchedDz);
36 
37  for ( MFIter mfi(S_old[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
38  {
39  Box bx = mfi.tilebox();
40  Box tbx = mfi.nodaltilebox(0);
41  Box tby = mfi.nodaltilebox(1);
42 
43  const Array4< Real>& cell_data = scratch.array(mfi);
44 
45  const Array4< Real>& rho_u = (l_do_implicit_mom) ? scratch_xmom.array(mfi) : Array4<Real>{};
46  const Array4< Real>& rho_v = (l_do_implicit_mom) ? scratch_ymom.array(mfi) : Array4<Real>{};
47  const Array4<const Real>& tau13_corr = (l_do_implicit_mom) ? Tau13corr->array(mfi) : Array4<Real>{};
48  const Array4<const Real>& tau23_corr = (l_do_implicit_mom) ? Tau23corr->array(mfi) : Array4<Real>{};
49 
50 #ifdef ERF_IMPLICIT_W
51  Box tbz = mfi.nodaltilebox(2);
52  const Array4< Real>& rho_w = (l_do_implicit_mom) ? scratch_zmom.array(mfi) : Array4<Real>{};
53  const Array4<const Real>& tau33_corr = (l_do_implicit_mom) ? Tau33corr->array(mfi) : Array4<Real>{};
54 #endif
55 
56  const Array4<const Real>& z_nd_arr = z_phys_nd[level]->const_array(mfi);
57  const Array4<const Real>& detJ_arr = detJ_cc[level]->const_array(mfi);
58 
59  const Array4<const Real>& mu_turb = l_use_turb ? eddyDiffs->const_array(mfi) : Array4<const Real>{};
60 
61  // Vertical extent of the grid column over each (i,j), with a one-cell halo
62  // so a box can also see the column on the other side of each of its faces
63  const Array4<const int>& col_kext = column_kextent[level]->const_array(mfi);
64 
65  const Array4<const Real> tau13 = Tau[level][TauType::tau13]->array(mfi);
66  const Array4<const Real> tau23 = Tau[level][TauType::tau23]->array(mfi);
67  [[maybe_unused]] const Array4<const Real> tau33 = Tau[level][TauType::tau33]->array(mfi);
68  const Array4<const Real>& hfx_z = Hfx3->const_array(mfi);
69  const bool l_use_mrf_cg = solverChoice.turbChoice[level].enable_mrf_countergradient
70  && (solverChoice.turbChoice[level].pbl_type == PBLType::MRF);
71  // NOTE: Only ComputeDiffusivityYSUNew fills EddyDiff::HGAMU_v/HGAMV_v;
72  // the legacy PBLType::YSU never writes them. Gating on YSU
73  // therefore both disabled the term where it is produced and read
74  // an unwritten component where it was not.
75  const bool l_use_ysu_mom_cg = solverChoice.turbChoice[level].enable_ysu_countergradient
76  && (solverChoice.turbChoice[level].pbl_type == PBLType::YSUNew);
77  if (l_use_stretched_dz) {
78  if (l_do_implicit_theta) {
79 
80  ImplicitDiffForStateLU_S(bx, fine_geom.Domain(), level, RhoTheta_comp,
81  stage_dt, l_bc_neumann_vals_d, cell_data,
82  stretched_dz_d[level], hfx_z,
83  mu_turb, solverChoice,
84  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
85  l_use_mrf_cg);
86  }
87  if (l_do_implicit_mom) {
88  ImplicitDiffForMomLU_S<0>(tbx, fine_geom.Domain(), level, stage_dt,
89  col_kext,
90  cell_data, rho_u, tau13, tau13_corr,
91  stretched_dz_d[level],
92  mu_turb, solverChoice,
93  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
94  l_use_ysu_mom_cg);
95 
96  ImplicitDiffForMomLU_S<1>(tby, fine_geom.Domain(), level, stage_dt,
97  col_kext,
98  cell_data, rho_v, tau23, tau23_corr,
99  stretched_dz_d[level],
100  mu_turb, solverChoice,
101  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
102  l_use_ysu_mom_cg);
103 #ifdef ERF_IMPLICIT_W
104  ImplicitDiffForMomLU_S<2>(tbz, fine_geom.Domain(), level, stage_dt,
105  col_kext,
106  cell_data, rho_w, tau33, tau33_corr,
107  stretched_dz_d[level],
108  mu_turb, solverChoice,
109  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
110  l_use_ysu_mom_cg);
111 #endif
112  }
113  } else if (l_use_terrain_fitted_coords) {
114  if (l_do_implicit_theta) {
115  ImplicitDiffForStateLU_T(bx, fine_geom.Domain(), level, RhoTheta_comp,
116  stage_dt, l_bc_neumann_vals_d, cell_data,
117  z_nd_arr, detJ_arr, dxInv, hfx_z,
118  mu_turb, solverChoice,
119  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
120  l_use_mrf_cg);
121  }
122  if (l_do_implicit_mom) {
123  ImplicitDiffForMomLU_T<0>(tbx, fine_geom.Domain(), level, stage_dt,
124  col_kext,
125  cell_data, rho_u, tau13, tau13_corr,
126  z_nd_arr, detJ_arr, dxInv,
127  mu_turb, solverChoice,
128  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
129  l_use_ysu_mom_cg);
130 
131  ImplicitDiffForMomLU_T<1>(tby, fine_geom.Domain(), level, stage_dt,
132  col_kext,
133  cell_data, rho_v, tau23, tau23_corr,
134  z_nd_arr, detJ_arr, dxInv,
135  mu_turb, solverChoice,
136  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
137  l_use_ysu_mom_cg);
138 #ifdef ERF_IMPLICIT_W
139  ImplicitDiffForMomLU_T<2>(tbz, fine_geom.Domain(), level, stage_dt,
140  col_kext,
141  cell_data, rho_w, tau33, tau33_corr,
142  z_nd_arr, detJ_arr, dxInv,
143  mu_turb, solverChoice,
144  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
145  l_use_ysu_mom_cg);
146 #endif
147  }
148  } else { // no terrain
149  if (l_do_implicit_theta) {
150  ImplicitDiffForStateLU_N(bx, fine_geom.Domain(), level, RhoTheta_comp,
151  stage_dt, l_bc_neumann_vals_d, cell_data,
152  dxInv, hfx_z, mu_turb, solverChoice,
153  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
154  l_use_mrf_cg);
155  }
156  if (l_do_implicit_mom) {
157  ImplicitDiffForMomLU_N<0>(tbx, fine_geom.Domain(), level, stage_dt,
158  col_kext,
159  cell_data, rho_u, tau13, tau13_corr,
160  dxInv,
161  mu_turb, solverChoice,
162  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
163  l_use_ysu_mom_cg);
164 
165  ImplicitDiffForMomLU_N<1>(tby, fine_geom.Domain(), level, stage_dt,
166  col_kext,
167  cell_data, rho_v, tau23, tau23_corr,
168  dxInv,
169  mu_turb, solverChoice,
170  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
171  l_use_ysu_mom_cg);
172 #ifdef ERF_IMPLICIT_W
173  ImplicitDiffForMomLU_N<2>(tbz, fine_geom.Domain(), level, stage_dt,
174  col_kext,
175  cell_data, rho_w, tau33, tau33_corr,
176  dxInv,
177  mu_turb, solverChoice,
178  bc_ptr_h, l_use_SurfLayer, l_vert_implicit_fac,
179  l_use_ysu_mom_cg);
180 #endif
181  }
182  }
183  } // mfi
184 
185  } // if do implicit solve for diffusive contribution to (rho theta) update
186  } // wrapper
@ tau23
Definition: ERF_DataStruct.H:40
@ tau33
Definition: ERF_DataStruct.H:40
@ tau13
Definition: ERF_DataStruct.H:40
void ImplicitDiffForStateLU_N(const amrex::Box &bx, const amrex::Box &domain, const int level, const int n, const double dt, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM *2 > &bc_neumann_vals, const amrex::Array4< amrex::Real > &cell_data, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &hfx_z, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const amrex::BCRec *bc_ptr, const bool use_SurfLayer, const amrex::Real implicit_fac, const bool use_mrf_countergradient=false)
Apply implicit vertical state diffusion on a uniform grid without terrain.
void ImplicitDiffForStateLU_T(const amrex::Box &bx, const amrex::Box &domain, const int level, const int n, const double dt, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM *2 > &bc_neumann_vals, const amrex::Array4< amrex::Real > &cell_data, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &hfx_z, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const amrex::BCRec *bc_ptr, const bool use_SurfLayer, const amrex::Real implicit_fac, const bool use_mrf_countergradient=false)
Apply implicit vertical state diffusion on terrain-following coordinates.
void ImplicitDiffForStateLU_S(const amrex::Box &bx, const amrex::Box &domain, const int level, const int n, const double dt, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM *2 > &bc_neumann_vals, const amrex::Array4< amrex::Real > &cell_data, const amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::Array4< const amrex::Real > &hfx_z, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const amrex::BCRec *bc_ptr, const bool use_SurfLayer, const amrex::Real implicit_fac, const bool use_mrf_countergradient=false)
Apply implicit vertical state diffusion on a vertically stretched grid.
const Real l_vert_implicit_fac
Definition: ERF_ImplicitPost.H:6
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
pp get("wavelength", wavelength)
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:29
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ cons
Definition: ERF_IndexDefines.H:232