ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ImmersedForcing.cpp File Reference
Include dependency graph for ERF_ImmersedForcing.cpp:

Functions

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real compute_if_most_target_vel (const amrex::Real u1_2r, const amrex::Real u2_2r, const amrex::Real delta, const amrex::Real z0, const amrex::Real t_blank, const amrex::Real theta_face, const amrex::Real theta_surf, const amrex::Real tflux_in, const amrex::Real Olen_in, const bool stability_correction, const amrex::Real wind_floor, const amrex::Real psi_cap_factor, const similarity_funs &sfuns)
 
void ImmersedForcingTerrain_Xmom (const Box &tbx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_xface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &xmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const bool l_drag_in_projection)
 
void ImmersedForcingTerrain_Ymom (const Box &tby, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_yface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &ymom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const bool l_drag_in_projection)
 
static ib_wall::WallCond make_wall_cond (const SolverChoice &sc, const Real time)
 
template<int dir>
void ImmersedForcingTerrain_HorizMom_FractionStress (const Box &tb, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_face_arr, const Array4< Real > &mom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real dt, const Real time, const bool l_drag_in_projection)
 
void ImmersedForcingTerrain_Xmom_FractionStress (const Box &tbx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_xface_arr, const Array4< Real > &xmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const Real time, const bool l_drag_in_projection)
 
void ImmersedForcingTerrain_Ymom_FractionStress (const Box &tby, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_yface_arr, const Array4< Real > &ymom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const Real time, const bool l_drag_in_projection)
 
void ImmersedForcingTerrain_Scalar_FractionStress (const Box &bx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< Real > &cell_src, const Array4< Real > &wall_hfx, const Array4< Real > &wall_ktarget, const Geometry &geom, const SolverChoice &solverChoice, const Table1D< Real > &r_avg, const Table1D< Real > &t_avg, const Real dt, const Real time, const bool wall_tke, const Real Cmu0, const Array4< Real > &wall_qfx, const bool wall_tke_moist)
 
void ImmersedForcingTerrain_Zmom (const Box &tbz, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_zface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &zmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const bool l_drag_in_projection)
 
void ImmersedForcingBuildings_Xmom (const Box &tbx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_xface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &xmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, bool is_slow_step, const bool l_drag_in_projection)
 
void ImmersedForcingBuildings_Ymom (const Box &tby, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_yface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &ymom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, bool is_slow_step, const bool l_drag_in_projection)
 
void ImmersedForcingBuildings_Zmom (const Box &tbz, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_zface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &zmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, bool is_slow_step, const bool l_drag_in_projection)
 
void ImmersedForcingTerrain_Scalar (const Box &bx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &cell_src, const Geometry &geom, const SolverChoice &solverChoice, const Table1D< Real > &r_avg, const Table1D< Real > &t_avg, const Real time)
 
void ImmersedForcingBuildings_Scalar (const Box &bx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &cell_src, const Geometry &geom, const SolverChoice &solverChoice, const Table1D< Real > &r_avg, const Table1D< Real > &t_avg, const Real time)
 

Function Documentation

◆ compute_if_most_target_vel()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real compute_if_most_target_vel ( const amrex::Real  u1_2r,
const amrex::Real  u2_2r,
const amrex::Real  delta,
const amrex::Real  z0,
const amrex::Real  t_blank,
const amrex::Real  theta_face,
const amrex::Real  theta_surf,
const amrex::Real  tflux_in,
const amrex::Real  Olen_in,
const bool  stability_correction,
const amrex::Real  wind_floor,
const amrex::Real  psi_cap_factor,
const similarity_funs &  sfuns 
)

Compute the target velocity using Monin-Obukhov Similarity Theory for immersed forcing.

Parameters
[in]u1_2rFirst tangential velocity component.
[in]u2_2rSecond tangential velocity component.
[in]deltaDistance from the surface.
[in]z0Roughness length.
[in]t_blankVolume fraction.
[in]theta_facePotential temperature at the face.
[in]theta_surfPotential temperature at the surface.
[in]tflux_inSurface heat flux.
[in]Olen_inObukhov length.
[in]stability_correctionWhether to apply stability corrections.
[in]wind_floorWind-speed floor [m/s] behind the friction velocity of the stability estimate (erf.if_stability_wind_floor).
[in]psi_cap_factorCap on psi_m as a fraction of ln(z/z0) (erf.if_psi_cap_factor).
[in]sfunsSimilarity functions of the wall law (erf.most.stable_functions).
Returns
Target velocity component.
48 {
50  Real psi_m = zero;
51  Real psi_h = zero;
52  Real tang_windspeed2r = std::sqrt(u1_2r * u1_2r + u2_2r * u2_2r);
53 
54  // The stability estimate uses the wind floored at wind_floor, a derived Obukhov length bounded
55  // so that |zeta| <= ib_stability::zeta_max() as on flat ground, and a prescribed one as given
56  // with its zeta held there; the target below uses the actual wind
57  Real ustar = ib_stability::floored_wind(tang_windspeed2r, wind_floor) * KAPPA / (std::log(1.5 * delta / z0) - psi_m);
58  Real tflux = (tflux_in != Real(1.e-8)) ? tflux_in : -(theta_face - theta_surf) * ustar * KAPPA / (std::log(1.5 * delta / z0) - psi_h);
59  Real Olen = (Olen_in != Real(1.e-8)) ? Olen_in
60  : ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta_face / (KAPPA * CONST_GRAV * tflux + tiny), Real(1.5) * delta);
61  Real zeta = ib_stability::bounded_zeta(Real(1.5) * delta, Olen);
62 
63  // similarity functions (sfuns: erf.most.stable_functions)
64  if (stability_correction){
65  psi_m = sfuns.calc_psi_m(zeta);
66  psi_h = sfuns.calc_psi_h(zeta);
67  }
68  ustar = tang_windspeed2r * KAPPA / (std::log(1.5 * delta / z0) - ib_stability::psi_m_for_ustar(psi_m, Real(1.5) * delta, z0, psi_cap_factor));
69 
70  // prevent some unphysical math
72  psi_m = ib_stability::capped_psi(psi_m, myhalf * delta, z0, psi_cap_factor);
73 
74  Real uTarget = (1 - t_blank) * ustar / KAPPA * (std::log(myhalf * delta / z0) - psi_m);
75  Real u1Target = uTarget * u1_2r / (tiny + tang_windspeed2r);
76 
77  return u1Target;
78 }
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
@ ustar
Definition: ERF_SLM.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real bounded_zeta(amrex::Real z, amrex::Real Olen) noexcept
Definition: ERF_ImmersedWallStability.H:62
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real floored_wind(amrex::Real speed, amrex::Real wind_floor) noexcept
Definition: ERF_ImmersedWallStability.H:38
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real capped_psi(amrex::Real psi, amrex::Real z, amrex::Real z0, amrex::Real factor) noexcept
Definition: ERF_ImmersedWallStability.H:85
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real bounded_obukhov_length(amrex::Real Olen, amrex::Real z_ref) noexcept
Definition: ERF_ImmersedWallStability.H:51
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real psi_m_for_ustar(amrex::Real psi_m, amrex::Real z, amrex::Real z0, amrex::Real factor) noexcept
Definition: ERF_ImmersedWallStability.H:98
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real clamped_ustar(amrex::Real ustar) noexcept
Definition: ERF_ImmersedWallStability.H:109
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_m(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:149
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_h(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:168

Referenced by ImmersedForcingBuildings_Xmom(), ImmersedForcingBuildings_Ymom(), and ImmersedForcingBuildings_Zmom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingBuildings_Scalar()

void ImmersedForcingBuildings_Scalar ( const Box &  bx,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  cell_src,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Table1D< Real > &  r_avg,
const Table1D< Real > &  t_avg,
const Real  time 
)

Apply buildings immersed forcing to scalars (Rho, RhoTheta)

1486 {
1487  // geometric properties
1488  const auto dx_arr = geom.CellSizeArray();
1489  const Real dx_x = dx_arr[0];
1490  const Real dx_y = dx_arr[1];
1491  // The drag rates take dx in place of a dy over one cell, and the reverse
1492  const auto len_arr = LengthScaleCellSize(geom);
1493  const Real len_x = len_arr[0];
1494  const Real len_y = len_arr[1];
1495 
1496  const Real alpha_h = solverChoice.if_Cd_scalar;
1497  // erf.if_snap_partial_cells: read the cell blanking snapped to solid (1)
1498  // or fluid (0) at half, so a height-map building becomes the same
1499  // staircase of whole cells an exact box is: the thermal conditions sit
1500  // on the boundary solid cells, roofs included, found from the neighbor
1501  // blanking. Off (the default), the raw fractions are used and nothing
1502  // below changes. See SolverChoice::if_snap_partial_cells.
1503  const bool l_snap = solverChoice.if_snap_partial_cells;
1504  auto snapb = [=] AMREX_GPU_DEVICE (amrex::Real b) noexcept -> amrex::Real {
1505  return l_snap ? ((b >= myhalf) ? one : zero) : b;
1506  };
1507  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
1508  const Real U_s = one; // unit velocity scale
1509 
1510  // MOST parameters (the similarity functions from erf.most.stable_functions)
1511  const similarity_funs sfuns = solverChoice.most_sfuns;
1512  const Real ggg = CONST_GRAV;
1513  const Real kappa = KAPPA;
1514  const Real z0 = solverChoice.if_z0;
1515  const Real tflux = solverChoice.if_surf_temp_flux;
1516  const Real init_surf_temp = solverChoice.if_init_surf_temp;
1517  const Real surf_heating_rate = solverChoice.if_surf_heating_rate;
1518  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
1519  // erf.if_stability_correction (off by default): the similarity functions of the temperature
1520  // kernels, as of the momentum kernels; off, the log law (erf-model/ERF#4931)
1521  const bool l_stability_correction = solverChoice.if_stability_correction;
1522 
1523  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1524  {
1525  const Real t_blank = snapb(t_blank_arr(i, j, k));
1526  const Real t_blank_below = snapb(t_blank_arr(i, j, k-1));
1527  const Real t_blank_above = snapb(t_blank_arr(i, j, k+1));
1528  const Real t_blank_north = snapb(t_blank_arr(i , j+1, k));
1529  const Real t_blank_south = snapb(t_blank_arr(i , j-1, k));
1530  const Real t_blank_east = snapb(t_blank_arr(i+1, j , k));
1531  const Real t_blank_west = snapb(t_blank_arr(i-1, j , k));
1532 
1533  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
1534  Real drag_coefficient = alpha_h / std::pow(len_x*len_y*dx_z, one/three);
1535 
1536  // Wall cells of the building, named by the face they carry: a
1537  // partially blanked cell with a more solid neighbor behind it and a
1538  // fluid one in front, or, with the snap (every solid cell at 1), a
1539  // solid cell with a solid neighbor behind and a fluid one in front.
1540  const bool south_face = l_snap ? (t_blank == one && t_blank_north == one && t_blank_south == zero)
1541  : (t_blank > zero && t_blank < t_blank_north && t_blank_south == zero);
1542  const bool north_face = l_snap ? (t_blank == one && t_blank_south == one && t_blank_north == zero)
1543  : (t_blank > zero && t_blank < t_blank_south && t_blank_north == zero);
1544  const bool west_face = l_snap ? (t_blank == one && t_blank_east == one && t_blank_west == zero)
1545  : (t_blank > zero && t_blank < t_blank_east && t_blank_west == zero);
1546  const bool east_face = l_snap ? (t_blank == one && t_blank_west == one && t_blank_east == zero)
1547  : (t_blank > zero && t_blank < t_blank_west && t_blank_east == zero);
1548 
1549  // SURFACE TEMP AND HEATING/COOLING RATE
1550  if (init_surf_temp > zero) {
1551  const Real surf_temp = init_surf_temp + surf_heating_rate*time;
1552  if (t_blank > 0 && (t_blank_above == zero) && (t_blank_below == one)) { // building roof
1553  const Real bc_forcing_rt_srf = -(cell_data(i,j,k,Rho_comp) * surf_temp - cell_data(i,j,k,RhoTheta_comp));
1554  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt_srf;
1555 
1556  } else if (east_face || west_face || south_face || north_face) {
1557  // this should enter for just building walls
1558  // walls are currently separated to allow for flexibility in the future to heat walls differently
1559 
1560  // south face
1561  if (l_snap ? south_face : ((t_blank < t_blank_north) && (t_blank_north == one))) {
1562  const Real bc_forcing_rt_srf = -(cell_data(i,j,k,Rho_comp) * surf_temp - cell_data(i,j,k,RhoTheta_comp));
1563  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt_srf;
1564  }
1565 
1566  // north face
1567  if (l_snap ? north_face : ((t_blank < t_blank_south) && (t_blank_south == one))) {
1568  const Real bc_forcing_rt_srf = -(cell_data(i,j,k,Rho_comp) * surf_temp - cell_data(i,j,k,RhoTheta_comp));
1569  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt_srf;
1570  }
1571 
1572  // west face
1573  if (l_snap ? west_face : ((t_blank < t_blank_east) && (t_blank_east == one))) {
1574  const Real bc_forcing_rt_srf = -(cell_data(i,j,k,Rho_comp) * surf_temp - cell_data(i,j,k,RhoTheta_comp));
1575  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt_srf;
1576  }
1577 
1578  // east face
1579  if (l_snap ? east_face : ((t_blank < t_blank_west) && (t_blank_west == one))) {
1580  const Real bc_forcing_rt_srf = -(cell_data(i,j,k,Rho_comp) * surf_temp - cell_data(i,j,k,RhoTheta_comp));
1581  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt_srf;
1582  }
1583 
1584  }
1585  }
1586 
1587  // SURFACE HEAT FLUX
1588  if (tflux != Real(1.e-8)){
1589  const Real ux_cc_2r = myhalf * (u(i ,j ,k+1) + u(i+1,j ,k+1));
1590  const Real uy_cc_2r = myhalf * (v(i ,j ,k+1) + v(i ,j+1,k+1));
1591  // The heat transfer uses the wind floored at erf.if_stability_wind_floor and an Obukhov
1592  // length bounded so that |zeta| <= ib_stability::zeta_max(), as on flat ground
1593  const Real h_windspeed2r = ib_stability::floored_wind(std::sqrt(ux_cc_2r * ux_cc_2r + uy_cc_2r * uy_cc_2r), stab_wind_floor);
1594 
1595  const Real theta = cell_data(i,j,k ,RhoTheta_comp) / cell_data(i,j,k ,Rho_comp);
1596  Real theta_neighbor = cell_data(i,j,k+1,RhoTheta_comp) / cell_data(i,j,k+1,Rho_comp);
1597 
1598  if (t_blank > zero && (t_blank_above == zero)) { // building roof
1599  Real psi_m = zero;
1600  Real psi_h = zero;
1601  Real psi_h_neighbor = zero;
1602  Real ustar = h_windspeed2r * kappa / (std::log((1.5) * dx_z / z0) - psi_m);
1603  // (start-up refuses erf.if_Olen with a surface flux, so L always comes from the flux here)
1604  Real Olen = ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta / (kappa * ggg * tflux + tiny), Real(1.5) * dx_z);
1605 
1606  for (int iter = 0; iter < 2; ++iter) {
1607  if (iter > 0) { Olen = ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta / (kappa * ggg * tflux + tiny), Real(1.5) * dx_z); }
1608  Real zeta = ib_stability::bounded_zeta(myhalf * dx_z, Olen);
1609  Real zeta_neighbor = ib_stability::bounded_zeta(Real(1.5) * dx_z, Olen);
1610 
1611  // similarity functions (off by default: the plain log law, as in the momentum kernels)
1612  if (l_stability_correction) {
1613  psi_m = sfuns.calc_psi_m(zeta);
1614  psi_h = sfuns.calc_psi_h(zeta);
1615  psi_h_neighbor = sfuns.calc_psi_h(zeta_neighbor);
1616  }
1617  ustar = h_windspeed2r * kappa / (std::log((1.5) * dx_z / z0) - psi_m);
1618  }
1619 
1620  // prevent some unphysical math
1622  // caps of ln(z / z0): erf.if_psi_cap_factor stays off the temperature forcing, whose
1623  // theta* comes from an L not made consistent with u* (the legacy law, kept as it is;
1624  // the fraction-stress law of erf-model/ERF#4134 forms them consistently)
1625  // (with the flag off psi_h is zero and stays so; a cap of ln(z / z0) <= 0, for z0 >= z, is not applied)
1626  if (l_stability_correction) {
1627  psi_h_neighbor = ib_stability::capped_psi(psi_h_neighbor, Real(1.5) * dx_z, z0, one);
1628  psi_h = ib_stability::capped_psi(psi_h, myhalf * dx_z, z0, one);
1629  }
1630 
1631  // We do not know the actual temperature so use cell above
1632  const Real thetastar = theta * ustar * ustar / (kappa * ggg * Olen);
1633  const Real surf_temp = theta_neighbor - thetastar / kappa * (std::log((1.5) * dx_z / z0) - psi_h_neighbor);
1634  const Real tTarget = surf_temp + thetastar / kappa * (std::log((myhalf) * dx_z / z0) - psi_h);
1635 
1636  const Real bc_forcing_rt = -(cell_data(i,j,k,Rho_comp) * tTarget - cell_data(i,j,k,RhoTheta_comp));
1637  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt;
1638 
1639  } else if (east_face || west_face || south_face || north_face) { // this should enter for just building walls
1640 
1641  Real ux_cellaway = zero;
1642  Real uy_cellaway = zero;
1643  Real uz_cellaway = zero;
1644  Real u1 = zero;
1645  Real u2 = zero;
1646  Real delta = zero;
1647 
1648  // south face
1649  if (south_face) {
1650  ux_cellaway = myhalf * (u(i ,j-1,k) + u(i+1,j-1,k ));
1651  uz_cellaway = myhalf * (w(i ,j-1,k) + w(i ,j-1,k+1));
1652  u1 = ux_cellaway;
1653  u2 = uz_cellaway;
1654  delta = dx_y;
1655 
1656  // MOST
1657  theta_neighbor = cell_data(i,j-1,k,RhoTheta_comp) / cell_data(i,j-1,k,Rho_comp);
1658  }
1659 
1660  // north face
1661  if (north_face) {
1662  ux_cellaway = myhalf * (u(i ,j+1,k) + u(i+1,j+1,k ));
1663  uz_cellaway = myhalf * (w(i ,j+1,k) + w(i ,j+1,k+1));
1664  u1 = ux_cellaway;
1665  u2 = uz_cellaway;
1666  delta = dx_y;
1667 
1668  // MOST
1669  theta_neighbor = cell_data(i,j+1,k,RhoTheta_comp) / cell_data(i,j+1,k,Rho_comp);
1670  }
1671 
1672  // west face
1673  if (west_face) {
1674  uy_cellaway = myhalf * (v(i-1,j ,k) + v(i-1,j+1,k ));
1675  uz_cellaway = myhalf * (w(i-1,j ,k) + w(i-1,j ,k+1));
1676  u1 = uy_cellaway;
1677  u2 = uz_cellaway;
1678  delta = dx_x;
1679 
1680  // MOST
1681  theta_neighbor = cell_data(i-1,j,k,RhoTheta_comp) / cell_data(i-1,j,k,Rho_comp);
1682  }
1683 
1684  // east face
1685  if (east_face) {
1686  uy_cellaway = myhalf * (v(i+1,j ,k) + v(i+1,j+1,k ));
1687  uz_cellaway = myhalf * (w(i+1,j ,k) + w(i+1,j ,k+1));
1688  u1 = uy_cellaway;
1689  u2 = uz_cellaway;
1690  delta = dx_x;
1691 
1692  // MOST
1693  theta_neighbor = cell_data(i+1,j,k,RhoTheta_comp) / cell_data(i+1,j,k,Rho_comp);
1694  }
1695 
1696  Real tan_wspd = ib_stability::floored_wind(std::sqrt(u1 * u1 + u2 * u2), stab_wind_floor);
1697 
1698  Real psi_m = zero;
1699  Real psi_h = zero;
1700  Real psi_h_neighbor = zero;
1701  Real ustar = tan_wspd * kappa / (std::log(1.5 * delta / z0) - psi_m);
1702  Real Olen = ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta / (kappa * ggg * tflux + tiny), Real(1.5) * delta);
1703 
1704  for (int iter = 0; iter < 2; ++iter) {
1705  if (iter > 0) { Olen = ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta / (kappa * ggg * tflux + tiny), Real(1.5) * delta); }
1706  Real zeta = ib_stability::bounded_zeta(myhalf * delta, Olen);
1707  Real zeta_neighbor = ib_stability::bounded_zeta(Real(1.5) * delta, Olen);
1708 
1709  // similarity functions (off by default: the plain log law, as in the momentum kernels)
1710  if (l_stability_correction) {
1711  psi_m = sfuns.calc_psi_m(zeta);
1712  psi_h = sfuns.calc_psi_h(zeta);
1713  psi_h_neighbor = sfuns.calc_psi_h(zeta_neighbor);
1714  }
1715  ustar = tan_wspd * kappa / (std::log((1.5) * delta / z0) - psi_m);
1716  }
1717 
1718  // prevent some unphysical math
1720  // caps of ln(z / z0), as above (erf-model/ERF#4134)
1721  // (with the flag off psi_h is zero and stays so; a cap of ln(z / z0) <= 0, for z0 >= z, is not applied)
1722  if (l_stability_correction) {
1723  psi_h_neighbor = ib_stability::capped_psi(psi_h_neighbor, Real(1.5) * delta, z0, one);
1724  psi_h = ib_stability::capped_psi(psi_h, myhalf * delta, z0, one);
1725  }
1726 
1727  // We do not know the actual temperature so use cell above
1728  const Real thetastar = theta * ustar * ustar / (kappa * ggg * Olen);
1729  const Real surf_temp = theta_neighbor - thetastar / kappa * (std::log((1.5) * delta / z0) - psi_h_neighbor);
1730  const Real tTarget = surf_temp + thetastar / kappa * (std::log((myhalf) * delta / z0) - psi_h);
1731 
1732  const Real bc_forcing_rt = -(cell_data(i,j,k,Rho_comp) * tTarget - cell_data(i,j,k,RhoTheta_comp));
1733  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt;
1734  }
1735  }
1736 
1737  // Force fully immersed cells to planar average rho and theta
1738  if (t_blank == 1.0 && r_avg && t_avg) {
1739  const Real rho_avg = r_avg(k);
1740  const Real theta_avg = t_avg(k) / rho_avg; // Convert from RhoTheta to Theta
1741  const Real rho_cell = cell_data(i,j,k,Rho_comp);
1742  const Real bc_forcing_r = -(rho_avg - rho_cell);
1743  const Real bc_forcing_rt = -(rho_avg * theta_avg - cell_data(i,j,k,RhoTheta_comp));
1744 
1745  cell_src(i, j, k, Rho_comp) -= drag_coefficient * U_s * bc_forcing_r;
1746  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt;
1747  }
1748  });
1749 }
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:28
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 three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
@ theta
Definition: ERF_Kessler.H:26
amrex::Real if_z0
Immersed-forcing roughness length [m].
Definition: ERF_DataStruct.H:3113
similarity_funs most_sfuns
Definition: ERF_DataStruct.H:3125
bool if_snap_partial_cells
Definition: ERF_DataStruct.H:3123
amrex::Real if_Cd_scalar
Immersed-forcing drag coefficient for scalars.
Definition: ERF_DataStruct.H:3107
amrex::Real if_init_surf_temp
Initial immersed-forcing surface temperature [K].
Definition: ERF_DataStruct.H:3115
amrex::Real if_surf_temp_flux
Immersed-forcing surface temperature flux [K m/s].
Definition: ERF_DataStruct.H:3114
amrex::Real if_surf_heating_rate
Immersed-forcing surface heating rate [K/hr].
Definition: ERF_DataStruct.H:3116
bool if_stability_correction
Whether the immersed-forcing wall law applies the MOST similarity functions, in the momentum and the ...
Definition: ERF_DataStruct.H:3124
amrex::Real if_stability_wind_floor
Wind-speed floor [m/s] behind the friction velocity of the wall law's stability estimate (0: none).
Definition: ERF_DataStruct.H:3133
Definition: ERF_MOSTUtils.H:84

Referenced by make_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingBuildings_Xmom()

void ImmersedForcingBuildings_Xmom ( const Box &  tbx,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_xface_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  xmom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
bool  is_slow_step,
const bool  l_drag_in_projection 
)

Apply buildings immersed forcing to X-momentum

is_slow_step: whether the forcing is being applied on the slow step (the drag is then limited) rather than in the acoustic substeps

715 {
716  // geometric properties
717  const auto dx_arr = geom.CellSizeArray();
718  const Real dx_y = dx_arr[1];
719  // The drag rates take dx in place of a dy over one cell, and the reverse
720  const auto len_arr = LengthScaleCellSize(geom);
721  const Real len_x = len_arr[0];
722  const Real len_y = len_arr[1];
723  const Real dt = fac;
724 
725  const Real alpha_m = solverChoice.if_Cd_momentum;
726  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
727  const Real U_s = one; // unit velocity scale
728 
729  // MOST parameters
730  const Real z0 = solverChoice.if_z0;
731  const Real tflux_in = solverChoice.if_surf_temp_flux;
732  const Real Olen_in = solverChoice.if_Olen_in;
733  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
734  const Real psi_cap_factor = solverChoice.if_psi_cap_factor;
735  const bool l_use_most = solverChoice.if_use_most;
736  const bool l_stability_correction = solverChoice.if_stability_correction;
737  const similarity_funs sfuns = solverChoice.most_sfuns; // erf.most.stable_functions
738 
739  // To limit stiffness of drag when it is applied in the slow step (the anelastic and
740  // pseudo-incompressible default)
741  const Real ws_floor = solverChoice.if_ws_floor;
742  const Real damp_alpha = solverChoice.if_damp_alpha;
743  // Point-implicit alternative to the clamp above; stabilizes both compressible and
744  // anelastic or pseudo-incompressible runs
745  const bool l_implicit_drag = solverChoice.if_implicit_drag;
746  // erf.if_implicit_projection: the linear drag of the solid is applied inside the projection of
747  // an anelastic or pseudo-incompressible level (ERF::make_if_projection_sigma), not here
748  const bool l_ip = l_drag_in_projection;
749 
750  const Real small_volfrac = solverChoice.if_small_volfrac;
751  // erf.if_snap_partial_cells: read the cell blanking snapped to solid (1)
752  // or fluid (0) at half, so a height-map building becomes the same
753  // staircase of whole cells an exact box is. A face is solid when either
754  // cell it joins is; a face between a solid and a fluid cell is
755  // wall-normal and gets the interior drag toward zero (no penetration); a
756  // face between two solid cells carries the roof or wall law of its row
757  // (the full log-law target, not the partial-cell weighted one) or the
758  // interior drag, never both; the partial-cell branches (wall_mask,
759  // east_west_mask and the like, faces with 0 < t_blank < 1) do not arise
760  // under the snap. Off (the default), the raw fractions
761  // are used and nothing below changes: a boundary face of an exact box
762  // carries the wall law and the interior drag together as before. See
763  // SolverChoice::if_snap_partial_cells.
764  const bool l_snap = solverChoice.if_snap_partial_cells;
765  // The face blanking and its neighbors are read through ERF_ImmersedBuildingMasks.H, as the
766  // implicit projection reads them
767  const int dom_klo = geom.Domain().smallEnd(2);
768 
769 
770  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
771  {
772  const Real ux = u(i, j, k );
773  const Real uy = fourth * ( v(i, j , k ) + v(i-1, j , k )
774  + v(i, j+1, k ) + v(i-1, j+1, k ) );
775  const Real uz = fourth * ( w(i, j , k ) + w(i-1, j , k )
776  + w(i, j , k+1) + w(i-1, j , k+1) );
777  const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
778 
779  const Real rho_xface = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i-1,j,k,Rho_comp) );
780  const Real theta_xface = (myhalf * (cell_data(i,j,k,RhoTheta_comp) + cell_data(i-1,j,k, RhoTheta_comp))) / rho_xface;
781 
782  // the face, its neighbors and the raw blanking the explicit path zeroes on (ERF_ImmersedBuildingMasks.H)
783  const if_bld::HorizFace fc = if_bld::horiz_face<0>(t_blank_arr, t_blank_xface_arr, i, j, k, dom_klo, l_snap, small_volfrac);
784  const Real t_blank = fc.t;
785  // With the snap the boundary solid face stands for the wall layer and
786  // takes the full log-law target; the partial-cell weight (1 - t_blank)
787  // of compute_if_most_target_vel() would make it zero (a no-slip
788  // staircase), so the snap path passes a zero blanking to it.
789  const Real t_blank_law = l_snap ? zero : t_blank;
790  const Real t_blank_below = fc.below;
791  const Real t_blank_above = fc.above;
792  const Real t_blank_south = fc.lo;
793  const Real t_blank_north = fc.hi;
794 
795  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
796  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dx_z, one/three);
797  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
798  // With the snap a face joining a solid and a fluid cell is wall-normal:
799  // it gets the interior drag (no penetration), not a wall law, whatever
800  // row it lies in.
801  const bool normal_face = fc.normal;
802 
803  // With the snap every solid face has t_blank = 1: a roof face lies in
804  // the top solid row (t_blank <= t_blank_below, the face above fluid),
805  // and a face carrying a wall law is not also an interior face.
806  // roof, south/north wall law, partial-wall and interior drag (ERF_ImmersedBuildingMasks.H)
807  if_bld::HorizMasks mk = if_bld::horiz_masks(t_blank, t_blank_below, t_blank_above, t_blank_south, t_blank_north,
808  normal_face, l_use_most, l_snap);
809  // erf.if_implicit_projection: the linear drag is in the projection, and a face the explicit
810  // path would zero after the projection (solid on both sides) is held there, with no wall law
811  if (l_ip) {
812  mk.wall = zero; mk.side = zero; mk.interior = zero;
813  if (fc.raw == one) { mk.roof = zero; mk.lo = zero; mk.hi = zero; }
814  }
815  const Real roof_mask = mk.roof;
816  const Real south_mask = mk.lo;
817  const Real north_mask = mk.hi;
818  const Real wall_mask = mk.wall;
819  const Real east_west_mask = mk.side;
820  const Real interior_mask = mk.interior;
821 
822  Real drag = zero;
823  Real u1_cellaway = zero;
824  Real u2_cellaway = zero;
825  Real rho_xface_inside = rho_xface;
826  Real theta_surf = theta_xface;
827  Real bc_forcing_x = zero;
828  Real u_target = zero;
829 
830  // roof forcing
831  if (roof_mask == one) {
832  u1_cellaway = u(i, j, k+1) ;
833  u2_cellaway = fourth * ( v(i, j , k+1) + v(i-1, j , k+1)
834  + v(i, j+1, k+1) + v(i-1, j+1, k+1) ) ;
835  rho_xface_inside = myhalf * (cell_data(i,j,k-1,Rho_comp) + cell_data(i-1,j,k-1,Rho_comp));
836  theta_surf = (myhalf * (cell_data(i,j,k-1,RhoTheta_comp) + cell_data(i-1,j,k-1, RhoTheta_comp))) / rho_xface_inside;
837  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_z, z0, t_blank_law, theta_xface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
838  bc_forcing_x = -(u_target - ux); // BC forcing pushes nonrelative velocity toward target velocity
839  drag += bc_forcing_x * roof_mask * rho_xface * CdM * U_s;
840  }
841 
842  // south wall forcing
843  if (south_mask == one) {
844  u1_cellaway = u(i, j-1, k );
845  u2_cellaway = fourth * ( w(i, j-1, k ) + w(i-1, j-1, k )
846  + w(i, j-1, k+1) + w(i-1, j-1, k+1) ) ;
847  rho_xface_inside = myhalf * ( cell_data(i,j+1,k,Rho_comp) + cell_data(i-1,j+1,k,Rho_comp) );
848  theta_surf = (myhalf * (cell_data(i,j+1,k,RhoTheta_comp) + cell_data(i-1,j+1,k, RhoTheta_comp))) / rho_xface_inside;
849  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_y, z0, t_blank_law, theta_xface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
850  bc_forcing_x = -(u_target - ux); // BC forcing pushes nonrelative velocity toward target velocity
851  drag += bc_forcing_x * south_mask * rho_xface * CdM * U_s;
852  }
853 
854  // north wall forcing
855  if (north_mask == one) {
856  u1_cellaway = u(i, j+1, k ) ;
857  u2_cellaway = fourth * ( w(i, j+1, k ) + w(i-1, j+1, k )
858  + w(i, j+1, k+1) + w(i-1, j+1, k+1) ) ;
859  rho_xface_inside = myhalf * ( cell_data(i,j-1,k,Rho_comp) + cell_data(i-1,j-1,k,Rho_comp) );
860  theta_surf = (myhalf * (cell_data(i,j-1,k,RhoTheta_comp) + cell_data(i-1,j-1,k, RhoTheta_comp))) / rho_xface_inside;
861  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_y, z0, t_blank_law, theta_xface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
862  bc_forcing_x = -(u_target - ux); // BC forcing pushes nonrelative velocity toward target velocity
863  drag += bc_forcing_x * north_mask * rho_xface * CdM * U_s;
864  }
865 
866  // wall forcing (if not using most) or east/west walls when using MOST
867  if (wall_mask == one || east_west_mask == one) {
868  drag += (wall_mask + east_west_mask) * t_blank * rho_xface * CdM * ux * windspeed;
869  }
870 
871  // interior cell forcing
872  if (interior_mask == one) {
873  drag += interior_mask * rho_xface * CdM * ux * windspeed;
874  }
875 
876  if (l_implicit_drag) {
877  // point-implicit rescale of the aggregated drag
878  const Real lambda = CdM * ( (roof_mask + south_mask + north_mask) * U_s
879  + (wall_mask + east_west_mask) * t_blank * windspeed
880  + interior_mask * windspeed );
881  xmom_src_arr(i,j,k) -= drag / (one + lambda*dt);
882  } else if (is_slow_step) {
883  // limit drag term in the slow step (the anelastic and pseudo-incompressible default)
884  // for numerical stability
885  Real d_drag = dt * -drag; // time step * acceleration like tendency
886  Real wsmax_change = damp_alpha * amrex::max(amrex::Math::abs(ux), ws_floor); // aims to prevent oscillations around 0.
887  if (amrex::Math::abs(ux) < 0.1){ // no damping for smaller velocities
888  wsmax_change =one * amrex::max(amrex::Math::abs(ux), ws_floor);
889  }
890  d_drag = amrex::min(amrex::max(d_drag, -wsmax_change), wsmax_change);
891  xmom_src_arr(i,j,k) += d_drag / dt; // put back as limited tendency
892  } else {
893  xmom_src_arr(i, j, k) -= drag;
894  }
895  });
896 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real compute_if_most_target_vel(const amrex::Real u1_2r, const amrex::Real u2_2r, const amrex::Real delta, const amrex::Real z0, const amrex::Real t_blank, const amrex::Real theta_face, const amrex::Real theta_surf, const amrex::Real tflux_in, const amrex::Real Olen_in, const bool stability_correction, const amrex::Real wind_floor, const amrex::Real psi_cap_factor, const similarity_funs &sfuns)
Definition: ERF_ImmersedForcing.cpp:33
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
@ fc
Definition: ERF_AdvanceMorrison.cpp:141
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE HorizMasks horiz_masks(amrex::Real t, amrex::Real below, amrex::Real above, amrex::Real lo, amrex::Real hi, bool normal_face, bool use_most, bool snap) noexcept
Definition: ERF_ImmersedBuildingMasks.H:140
amrex::Real if_psi_cap_factor
Cap on psi_m in the immersed momentum wall law as a fraction of ln(z/z0) (1: none).
Definition: ERF_DataStruct.H:3134
amrex::Real if_Cd_momentum
Immersed-forcing drag coefficient for momentum.
Definition: ERF_DataStruct.H:3106
amrex::Real if_Olen_in
Input Obukhov length for immersed-forcing MOST [m].
Definition: ERF_DataStruct.H:3117
amrex::Real if_small_volfrac
Immersed-forcing solid fraction below which a cell or face counts as fluid; read from eb2....
Definition: ERF_DataStruct.H:3135
amrex::Real if_damp_alpha
Immersed-forcing damping coefficient.
Definition: ERF_DataStruct.H:3132
amrex::Real if_ws_floor
Wind-speed floor [m/s] in the per-step change limit of the building wall-law forcing.
Definition: ERF_DataStruct.H:3131
bool if_use_most
Whether immersed-forcing MOST is enabled.
Definition: ERF_DataStruct.H:3122
bool if_implicit_drag
Definition: ERF_DataStruct.H:3110
Definition: ERF_ImmersedBuildingMasks.H:60
Definition: ERF_ImmersedBuildingMasks.H:119
amrex::Real lo
Definition: ERF_ImmersedBuildingMasks.H:120
amrex::Real hi
Definition: ERF_ImmersedBuildingMasks.H:120
amrex::Real roof
Definition: ERF_ImmersedBuildingMasks.H:120
amrex::Real wall
Definition: ERF_ImmersedBuildingMasks.H:120
amrex::Real side
Definition: ERF_ImmersedBuildingMasks.H:120
amrex::Real interior
Definition: ERF_ImmersedBuildingMasks.H:120

Referenced by make_mom_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingBuildings_Ymom()

void ImmersedForcingBuildings_Ymom ( const Box &  tby,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_yface_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  ymom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
bool  is_slow_step,
const bool  l_drag_in_projection 
)

Apply buildings immersed forcing to Y-momentum

is_slow_step: whether the forcing is being applied on the slow step (the drag is then limited) rather than in the acoustic substeps

918 {
919  // geometric properties
920  const auto dx_arr = geom.CellSizeArray();
921  const Real dx_x = dx_arr[0];
922  // The drag rates take dx in place of a dy over one cell, and the reverse
923  const auto len_arr = LengthScaleCellSize(geom);
924  const Real len_x = len_arr[0];
925  const Real len_y = len_arr[1];
926  const Real dt = fac;
927 
928  const Real alpha_m = solverChoice.if_Cd_momentum;
929  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
930  const Real U_s = one; // unit velocity scale
931 
932  // MOST parameters
933  const Real z0 = solverChoice.if_z0;
934  const Real tflux_in = solverChoice.if_surf_temp_flux;
935  const Real Olen_in = solverChoice.if_Olen_in;
936  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
937  const Real psi_cap_factor = solverChoice.if_psi_cap_factor;
938  const bool l_use_most = solverChoice.if_use_most;
939  const bool l_stability_correction = solverChoice.if_stability_correction;
940  const similarity_funs sfuns = solverChoice.most_sfuns; // erf.most.stable_functions
941 
942  // To limit stiffness of drag when it is applied in the slow step (the anelastic and
943  // pseudo-incompressible default)
944  const Real ws_floor = solverChoice.if_ws_floor;
945  const Real damp_alpha = solverChoice.if_damp_alpha;
946  // Point-implicit alternative to the clamp above; stabilizes both compressible and
947  // anelastic or pseudo-incompressible runs
948  const bool l_implicit_drag = solverChoice.if_implicit_drag;
949  // erf.if_implicit_projection: the linear drag of the solid is applied inside the projection of
950  // an anelastic or pseudo-incompressible level (ERF::make_if_projection_sigma), not here
951  const bool l_ip = l_drag_in_projection;
952 
953  const Real small_volfrac = solverChoice.if_small_volfrac;
954  // erf.if_snap_partial_cells: read the cell blanking snapped to solid (1)
955  // or fluid (0) at half, so a height-map building becomes the same
956  // staircase of whole cells an exact box is. A face is solid when either
957  // cell it joins is; a face between a solid and a fluid cell is
958  // wall-normal and gets the interior drag toward zero (no penetration); a
959  // face between two solid cells carries the roof or wall law of its row
960  // (the full log-law target, not the partial-cell weighted one) or the
961  // interior drag, never both; the partial-cell branches (wall_mask,
962  // east_west_mask and the like, faces with 0 < t_blank < 1) do not arise
963  // under the snap. Off (the default), the raw fractions
964  // are used and nothing below changes: a boundary face of an exact box
965  // carries the wall law and the interior drag together as before. See
966  // SolverChoice::if_snap_partial_cells.
967  const bool l_snap = solverChoice.if_snap_partial_cells;
968  // The face blanking and its neighbors are read through ERF_ImmersedBuildingMasks.H, as the
969  // implicit projection reads them
970  const int dom_klo = geom.Domain().smallEnd(2);
971 
972 
973  ParallelFor(tby, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
974  {
975  const Real ux = fourth * ( u(i , j , k ) + u(i , j-1, k )
976  + u(i+1, j , k ) + u(i+1, j-1, k ) );
977  const Real uy = v(i, j, k);
978  const Real uz = fourth * ( w(i , j , k ) + w(i , j-1, k )
979  + w(i , j , k+1) + w(i , j-1, k+1) );
980  const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
981 
982  const Real rho_yface = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j-1,k,Rho_comp) );
983  const Real theta_yface = (myhalf * (cell_data(i,j,k ,RhoTheta_comp) + cell_data(i,j-1,k,RhoTheta_comp))) / rho_yface;
984 
985  // the face, its neighbors and the raw blanking the explicit path zeroes on (ERF_ImmersedBuildingMasks.H)
986  const if_bld::HorizFace fc = if_bld::horiz_face<1>(t_blank_arr, t_blank_yface_arr, i, j, k, dom_klo, l_snap, small_volfrac);
987  const Real t_blank = fc.t;
988  // With the snap the boundary solid face stands for the wall layer and
989  // takes the full log-law target; the partial-cell weight (1 - t_blank)
990  // of compute_if_most_target_vel() would make it zero (a no-slip
991  // staircase), so the snap path passes a zero blanking to it.
992  const Real t_blank_law = l_snap ? zero : t_blank;
993  const Real t_blank_below = fc.below;
994  const Real t_blank_above = fc.above;
995  const Real t_blank_west = fc.lo;
996  const Real t_blank_east = fc.hi;
997 
998  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
999  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dx_z, one/three);
1000  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
1001  // With the snap a face joining a solid and a fluid cell is wall-normal:
1002  // it gets the interior drag (no penetration), not a wall law, whatever
1003  // row it lies in.
1004  const bool normal_face = fc.normal;
1005 
1006  // As in the x-momentum: with the snap a roof face lies in the top
1007  // solid row and a wall-law face is not also an interior face.
1008  // roof, west/east wall law, partial-wall and interior drag (ERF_ImmersedBuildingMasks.H)
1009  if_bld::HorizMasks mk = if_bld::horiz_masks(t_blank, t_blank_below, t_blank_above, t_blank_west, t_blank_east,
1010  normal_face, l_use_most, l_snap);
1011  // erf.if_implicit_projection: as in the x-momentum
1012  if (l_ip) {
1013  mk.wall = zero; mk.side = zero; mk.interior = zero;
1014  if (fc.raw == one) { mk.roof = zero; mk.lo = zero; mk.hi = zero; }
1015  }
1016  const Real roof_mask = mk.roof;
1017  const Real west_mask = mk.lo;
1018  const Real east_mask = mk.hi;
1019  const Real wall_mask = mk.wall;
1020  const Real north_south_mask = mk.side;
1021  const Real interior_mask = mk.interior;
1022 
1023  Real drag = zero;
1024  Real u1_cellaway = zero;
1025  Real u2_cellaway = zero;
1026  Real rho_yface_inside = rho_yface;
1027  Real theta_surf = theta_yface;
1028  Real bc_forcing_y = zero;
1029  Real u_target = zero;
1030 
1031  // roof forcing
1032  if (roof_mask == one) {
1033  u1_cellaway = fourth * ( u(i , j , k+1) + u(i , j-1, k+1)
1034  + u(i+1, j , k+1) + u(i+1, j-1, k+1) );
1035  u2_cellaway = v(i, j, k+1);
1036  rho_yface_inside = myhalf * ( cell_data(i,j,k-1,Rho_comp) + cell_data(i,j-1,k-1,Rho_comp) );
1037  theta_surf = (myhalf * (cell_data(i,j,k-1,RhoTheta_comp) + cell_data(i,j-1,k-1,RhoTheta_comp))) / rho_yface_inside;
1038  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_z, z0, t_blank_law, theta_yface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1039  bc_forcing_y = -(u_target - uy); // BC forcing pushes nonrelative velocity toward target velocity
1040  drag += bc_forcing_y * roof_mask * rho_yface * CdM * U_s;
1041  }
1042 
1043  // west wall forcing
1044  if (west_mask == one) {
1045  u1_cellaway = v(i-1, j , k );
1046  u2_cellaway = fourth * ( w(i-1, j , k ) + w(i-1, j-1, k )
1047  + w(i-1, j , k+1) + w(i-1, j-1, k+1) );
1048  rho_yface_inside = myhalf * ( cell_data(i+1,j,k,Rho_comp) + cell_data(i+1,j-1,k,Rho_comp) );
1049  theta_surf = (myhalf * (cell_data(i+1,j,k,RhoTheta_comp) + cell_data(i+1,j-1,k,RhoTheta_comp))) / rho_yface_inside;
1050  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_x, z0, t_blank_law, theta_yface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1051  bc_forcing_y = -(u_target - uy); // BC forcing pushes nonrelative velocity toward target velocity
1052  drag += bc_forcing_y * west_mask * rho_yface * CdM * U_s;
1053  }
1054 
1055  // east wall forcing
1056  if (east_mask == one) {
1057  u1_cellaway = v(i+1, j , k );
1058  u2_cellaway = fourth * ( w(i+1, j , k ) + w(i+1, j-1, k )
1059  + w(i+1, j , k+1) + w(i+1, j-1, k+1) );
1060  rho_yface_inside = myhalf * ( cell_data(i-1,j,k,Rho_comp) + cell_data(i-1,j-1,k,Rho_comp) );
1061  theta_surf = (myhalf * (cell_data(i-1,j,k,RhoTheta_comp) + cell_data(i-1,j-1,k,RhoTheta_comp))) / rho_yface_inside;
1062  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_x, z0, t_blank_law, theta_yface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1063  bc_forcing_y = -(u_target - uy); // BC forcing pushes nonrelative velocity toward target velocity
1064  drag += bc_forcing_y * east_mask * rho_yface * CdM * U_s;
1065  }
1066 
1067  // wall forcing (if not using most) or north/south walls when using MOST
1068  if (wall_mask == one || north_south_mask == one) {
1069  drag += (wall_mask + north_south_mask) * t_blank * rho_yface * CdM * uy * windspeed;
1070  }
1071 
1072  // interior cell forcing
1073  if (interior_mask == one) {
1074  drag += interior_mask * rho_yface * CdM * uy * windspeed;
1075  }
1076 
1077  if (l_implicit_drag) {
1078  // point-implicit rescale of the aggregated drag
1079  const Real lambda = CdM * ( (roof_mask + west_mask + east_mask) * U_s
1080  + (wall_mask + north_south_mask) * t_blank * windspeed
1081  + interior_mask * windspeed );
1082  ymom_src_arr(i,j,k) -= drag / (one + lambda*dt);
1083  } else if (is_slow_step) {
1084  // limit drag term in the slow step (the anelastic and pseudo-incompressible default)
1085  // for numerical stability
1086  Real d_drag = dt * -drag; // time step * acceleration like tendency
1087  Real wsmax_change = damp_alpha * amrex::max(amrex::Math::abs(uy), ws_floor); // aims to prevent oscillations around 0.
1088  if (amrex::Math::abs(uy) < 0.1){ // no damping for smaller velocities
1089  wsmax_change =one * amrex::max(amrex::Math::abs(uy), ws_floor);
1090  }
1091  d_drag = amrex::min(amrex::max(d_drag, -wsmax_change), wsmax_change);
1092  ymom_src_arr(i,j,k) += d_drag / dt; // put back as limited tendency
1093  } else {
1094  ymom_src_arr(i, j, k) -= drag;
1095  }
1096  });
1097 }

Referenced by make_mom_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingBuildings_Zmom()

void ImmersedForcingBuildings_Zmom ( const Box &  tbz,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_zface_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  zmom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
bool  is_slow_step,
const bool  l_drag_in_projection 
)

Apply buildings immersed forcing to Z-momentum

is_slow_step: whether the forcing is being applied on the slow step (the drag is then limited) rather than in the acoustic substeps

1119 {
1120  // geometric properties
1121  const auto dx_arr = geom.CellSizeArray();
1122  const Real dx_x = dx_arr[0];
1123  const Real dx_y = dx_arr[1];
1124  // The drag rates take dx in place of a dy over one cell, and the reverse
1125  const auto len_arr = LengthScaleCellSize(geom);
1126  const Real len_x = len_arr[0];
1127  const Real len_y = len_arr[1];
1128  const Real dt = fac;
1129 
1130  const Real alpha_m = solverChoice.if_Cd_momentum;
1131  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
1132  const Real U_s = one; // unit velocity scale
1133 
1134  // MOST parameters
1135  const Real z0 = solverChoice.if_z0;
1136  const Real tflux_in = solverChoice.if_surf_temp_flux;
1137  const Real Olen_in = solverChoice.if_Olen_in;
1138  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
1139  const Real psi_cap_factor = solverChoice.if_psi_cap_factor;
1140  const bool l_use_most = solverChoice.if_use_most;
1141  const bool l_stability_correction = solverChoice.if_stability_correction;
1142  const similarity_funs sfuns = solverChoice.most_sfuns; // erf.most.stable_functions
1143 
1144  // To limit stiffness of drag when it is applied in the slow step (the anelastic and
1145  // pseudo-incompressible default)
1146  const Real ws_floor = solverChoice.if_ws_floor;
1147  const Real damp_alpha = solverChoice.if_damp_alpha;
1148  // Point-implicit alternative to the clamp above; stabilizes both compressible and
1149  // anelastic or pseudo-incompressible runs
1150  const bool l_implicit_drag = solverChoice.if_implicit_drag;
1151  // erf.if_implicit_projection: the linear drag of the solid is applied inside the projection of
1152  // an anelastic or pseudo-incompressible level (ERF::make_if_projection_sigma), not here
1153  const bool l_ip = l_drag_in_projection;
1154 
1155  const Real small_volfrac = solverChoice.if_small_volfrac;
1156  // erf.if_snap_partial_cells: read the cell blanking snapped to solid (1)
1157  // or fluid (0) at half, so a height-map building becomes the same
1158  // staircase of whole cells an exact box is. A face is solid when either
1159  // cell it joins is; a face between a solid and a fluid cell is
1160  // wall-normal and gets the interior drag toward zero (no penetration); a
1161  // face between two solid cells carries the roof or wall law of its row
1162  // (the full log-law target, not the partial-cell weighted one) or the
1163  // interior drag, never both; the partial-cell branches (wall_mask,
1164  // east_west_mask and the like, faces with 0 < t_blank < 1) do not arise
1165  // under the snap. Off (the default), the raw fractions
1166  // are used and nothing below changes: a boundary face of an exact box
1167  // carries the wall law and the interior drag together as before. See
1168  // SolverChoice::if_snap_partial_cells.
1169  const bool l_snap = solverChoice.if_snap_partial_cells;
1170  // The face blanking and its neighbors are read through ERF_ImmersedBuildingMasks.H, as the
1171  // implicit projection reads them
1172 
1173 
1174  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1175  {
1176  const Real ux = fourth * ( u(i , j , k ) + u(i+1, j , k )
1177  + u(i , j , k-1) + u(i+1, j , k-1) );
1178  const Real uy = fourth * ( v(i, j , k ) + v(i, j+1, k )
1179  + v(i, j , k-1) + v(i, j+1, k-1) );
1180  const Real uz = w(i, j, k);
1181  const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
1182 
1183  const Real rho_zface = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k-1,Rho_comp) );
1184  const Real theta_zface = (myhalf * (cell_data(i,j,k,RhoTheta_comp) + cell_data(i,j,k-1,RhoTheta_comp))) / rho_zface;
1185 
1186  // the face, its neighbors and the raw blanking the explicit path zeroes on (ERF_ImmersedBuildingMasks.H)
1187  const if_bld::VertFace fc = if_bld::vert_face(t_blank_arr, t_blank_zface_arr, i, j, k, l_snap, small_volfrac);
1188  const Real t_blank = fc.t;
1189  // With the snap the boundary solid face stands for the wall layer and
1190  // takes the full log-law target; the partial-cell weight (1 - t_blank)
1191  // of compute_if_most_target_vel() would make it zero (a no-slip
1192  // staircase), so the snap path passes a zero blanking to it.
1193  const Real t_blank_law = l_snap ? zero : t_blank;
1194  const Real t_blank_above = fc.above;
1195  const Real t_blank_south = fc.south;
1196  const Real t_blank_north = fc.north;
1197  const Real t_blank_west = fc.west;
1198  const Real t_blank_east = fc.east;
1199 
1200  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
1201  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dx_z, one/three);
1202  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
1203  // With the snap a face joining a solid and a fluid cell is wall-normal:
1204  // it gets the interior drag (no penetration), not a wall law, whatever
1205  // row it lies in.
1206  const bool normal_face = fc.normal;
1207 
1208  // wall law on the four sides, partial-wall, roof and interior drag (ERF_ImmersedBuildingMasks.H);
1209  // with the snap a face carrying a wall law or the roof drag is not also an interior face
1210  if_bld::VertMasks mk = if_bld::vert_masks(t_blank, t_blank_above, t_blank_south, t_blank_north,
1211  t_blank_west, t_blank_east, k >= 1, normal_face, l_use_most, l_snap);
1212  // erf.if_implicit_projection: as in the x-momentum
1213  if (l_ip) {
1214  mk.wall = zero; mk.roof = zero; mk.interior = zero;
1215  if (fc.raw == one) { mk.south = zero; mk.north = zero; mk.west = zero; mk.east = zero; }
1216  }
1217  const Real south_mask = mk.south;
1218  const Real north_mask = mk.north;
1219  const Real west_mask = mk.west;
1220  const Real east_mask = mk.east;
1221  const Real wall_mask = mk.wall;
1222  const Real roof_mask = mk.roof;
1223  const Real interior_mask = mk.interior;
1224 
1225  Real drag = zero;
1226  Real u1_cellaway = zero;
1227  Real u2_cellaway = zero;
1228  Real rho_zface_inside = rho_zface;
1229  Real theta_surf = theta_zface;
1230  Real bc_forcing_z = zero;
1231  Real u_target = zero;
1232 
1233  // south wall forcing
1234  if (south_mask == one) {
1235  u1_cellaway = fourth * ( u(i , j-1, k ) + u(i+1, j-1, k )
1236  + u(i , j-1, k-1) + u(i+1, j-1, k-1) );
1237  u2_cellaway = w(i, j-1, k);
1238  rho_zface_inside = myhalf * ( cell_data(i,j+1,k,Rho_comp) + cell_data(i,j+1,k-1,Rho_comp) );
1239  theta_surf = (myhalf * (cell_data(i,j+1,k,RhoTheta_comp) + cell_data(i,j+1,k-1,RhoTheta_comp))) / rho_zface_inside;
1240  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_y, z0, t_blank_law, theta_zface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1241  bc_forcing_z = -(u_target - uz); // BC forcing pushes nonrelative velocity toward target velocity
1242  drag += bc_forcing_z * south_mask * rho_zface * CdM * U_s;
1243  }
1244 
1245  // north wall forcing
1246  if (north_mask == one) {
1247  u1_cellaway = fourth * ( u(i , j+1, k ) + u(i+1, j+1, k )
1248  + u(i , j+1, k-1) + u(i+1, j+1, k-1) );
1249  u2_cellaway = w(i, j+1, k);
1250  rho_zface_inside = myhalf * ( cell_data(i,j-1,k,Rho_comp) + cell_data(i,j-1,k-1,Rho_comp) );
1251  theta_surf = (myhalf * (cell_data(i,j-1,k,RhoTheta_comp) + cell_data(i,j-1,k-1,RhoTheta_comp))) / rho_zface_inside;
1252  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_y, z0, t_blank_law, theta_zface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1253  bc_forcing_z = -(u_target - uz); // BC forcing pushes nonrelative velocity toward target velocity
1254  drag += bc_forcing_z * north_mask * rho_zface * CdM * U_s;
1255  }
1256 
1257  // west wall forcing
1258  if (west_mask == one) {
1259  u1_cellaway = fourth * ( v(i-1, j , k ) + v(i-1, j+1, k )
1260  + v(i-1, j , k-1) + v(i-1, j+1, k-1) );
1261  u2_cellaway = w(i-1, j, k);
1262  rho_zface_inside = myhalf * ( cell_data(i+1,j,k,Rho_comp) + cell_data(i+1,j,k-1,Rho_comp) );
1263  theta_surf = (myhalf * (cell_data(i+1,j,k,RhoTheta_comp) + cell_data(i+1,j,k-1,RhoTheta_comp))) / rho_zface_inside;
1264  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_x, z0, t_blank_law, theta_zface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1265  bc_forcing_z = -(u_target - uz); // BC forcing pushes nonrelative velocity toward target velocity
1266  drag += bc_forcing_z * west_mask * rho_zface * CdM * U_s;
1267  }
1268 
1269  // east wall forcing
1270  if (east_mask == one) {
1271  u1_cellaway = fourth * ( v(i+1, j , k ) + v(i+1, j+1, k )
1272  + v(i+1, j , k-1) + v(i+1, j+1, k-1) );
1273  u2_cellaway = w(i+1, j, k);
1274  rho_zface_inside = myhalf * ( cell_data(i-1,j,k,Rho_comp) + cell_data(i-1,j,k-1,Rho_comp) );
1275  theta_surf = (myhalf * (cell_data(i-1,j,k,RhoTheta_comp) + cell_data(i-1,j,k-1,RhoTheta_comp))) / rho_zface_inside;
1276  u_target = compute_if_most_target_vel(u1_cellaway, u2_cellaway, dx_x, z0, t_blank_law, theta_zface, theta_surf, tflux_in, Olen_in, l_stability_correction, stab_wind_floor, psi_cap_factor, sfuns);
1277  bc_forcing_z = -(u_target - uz); // BC forcing pushes nonrelative velocity toward target velocity
1278  drag += bc_forcing_z * east_mask * rho_zface * CdM * U_s;
1279  }
1280 
1281  // wall forcing (if not using most) or roof when using MOST
1282  if (wall_mask == one || roof_mask == one) {
1283  drag += (wall_mask + roof_mask) * t_blank * rho_zface * CdM * uz * windspeed;
1284  }
1285 
1286  // interior cell forcing
1287  if (interior_mask == one) {
1288  drag += interior_mask * rho_zface * CdM * uz * windspeed;
1289  }
1290 
1291  if (l_implicit_drag) {
1292  // point-implicit rescale of the aggregated drag
1293  const Real lambda = CdM * ( (south_mask + north_mask + west_mask + east_mask) * U_s
1294  + (wall_mask + roof_mask) * t_blank * windspeed
1295  + interior_mask * windspeed );
1296  zmom_src_arr(i,j,k) -= drag / (one + lambda*dt);
1297  } else if (is_slow_step) {
1298  // limit drag term in the slow step (the anelastic and pseudo-incompressible default)
1299  // for numerical stability
1300  Real d_drag = dt * -drag; // time step * acceleration like tendency
1301  Real wsmax_change = damp_alpha * amrex::max(amrex::Math::abs(uz), ws_floor); // aims to prevent oscillations around 0.
1302  if (amrex::Math::abs(uz) < 0.1){ // no damping for smaller velocities
1303  wsmax_change = one * amrex::max(amrex::Math::abs(uz), ws_floor);
1304  }
1305  d_drag = amrex::min(amrex::max(d_drag, -wsmax_change), wsmax_change);
1306  zmom_src_arr(i,j,k) += d_drag / dt; // put back as limited tendency
1307  } else {
1308  zmom_src_arr(i, j, k) -= drag;
1309  }
1310  });
1311 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VertMasks vert_masks(amrex::Real t, amrex::Real above, amrex::Real south, amrex::Real north, amrex::Real west, amrex::Real east, bool above_floor, bool normal_face, bool use_most, bool snap) noexcept
Definition: ERF_ImmersedBuildingMasks.H:185
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VertFace vert_face(const amrex::Array4< const amrex::Real > &t, const amrex::Array4< const amrex::Real > &tf, int i, int j, int k, bool snap, amrex::Real small) noexcept
Definition: ERF_ImmersedBuildingMasks.H:100
Definition: ERF_ImmersedBuildingMasks.H:94
Definition: ERF_ImmersedBuildingMasks.H:167
amrex::Real interior
Definition: ERF_ImmersedBuildingMasks.H:168
amrex::Real east
Definition: ERF_ImmersedBuildingMasks.H:168
amrex::Real north
Definition: ERF_ImmersedBuildingMasks.H:168
amrex::Real wall
Definition: ERF_ImmersedBuildingMasks.H:168
amrex::Real roof
Definition: ERF_ImmersedBuildingMasks.H:168
amrex::Real south
Definition: ERF_ImmersedBuildingMasks.H:168
amrex::Real west
Definition: ERF_ImmersedBuildingMasks.H:168

Referenced by make_mom_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingTerrain_HorizMom_FractionStress()

template<int dir>
void ImmersedForcingTerrain_HorizMom_FractionStress ( const Box &  tb,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_face_arr,
const Array4< Real > &  mom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  dt,
const Real  time,
const bool  l_drag_in_projection 
)

Fraction-stress wall law (erf.if_wall_form = fraction_stress) for a horizontal momentum component, see ERF_ImmersedWallCell.H: the wall stress in the wall cell of each face column, the drag of the terrain kernels elsewhere (solid cells, and partial cells under the wall cell). dir = 0 forces x-momentum, dir = 1 y-momentum.

435 {
436  const Real* dx_arr = geom.CellSize();
437  // The drag rates take dx in place of a dy over one cell, and the reverse
438  const auto len_arr = LengthScaleCellSize(geom);
439  const Real len_x = len_arr[0];
440  const Real len_y = len_arr[1];
441  const Real dz = dx_arr[2]; // fraction_stress runs on a constant-dz mesh
442  const Real alpha_m = solverChoice.if_Cd_momentum;
443  const Real z0 = solverChoice.if_z0;
444  const bool l_implicit_drag = solverChoice.if_implicit_drag;
445  // erf.if_implicit_projection: the drag of the solid is applied inside the projection
446  // (anelastic and pseudo-incompressible levels)
447  const bool l_drag = !l_drag_in_projection;
448  const Real tiny = std::numeric_limits<Real>::epsilon();
449  const Real small = solverChoice.if_small_volfrac;
450  const ib_wall::WallCond cond = make_wall_cond(solverChoice, time);
451  // water vapor on the face (zero without a moisture model), for q* and the virtual Obukhov
452  // length of the wall state, as the scalar kernel forms them
453  const int qv_comp = cond.moist ? solverChoice.moisture_indices.qv : -1;
454  constexpr int io = (dir == 0) ? 1 : 0;
455  constexpr int jo = (dir == 1) ? 1 : 0;
456  const int klo = geom.Domain().smallEnd(2);
457  const int khi = geom.Domain().bigEnd(2);
458 
459  ParallelFor(tb, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
460  {
461  // solid fraction on this face column, as the terrain kernels read it, with the column
462  // ends clamped to the domain as make_ib_wall_face_masks does
463  const Real b_km1 = if_face_beta(t_blank_arr, t_blank_face_arr, i, j, k-1, io, jo, klo, khi, small);
464  const Real b_k = if_face_beta(t_blank_arr, t_blank_face_arr, i, j, k, io, jo, klo, khi, small);
465  const Real b_kp1 = if_face_beta(t_blank_arr, t_blank_face_arr, i, j, k+1, io, jo, klo, khi, small);
466  const Real rho_face = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i-io,j-jo,k,Rho_comp) );
467  const Real un = (dir == 0) ? u(i, j, k) : v(i, j, k);
468 
469  if (ib_wall::is_wall_cell(b_km1, b_k, b_kp1, small)) {
470  const Real ut = if_face_speed<dir>(u, v, i, j, k);
471  const Real ut_ref = if_face_speed<dir>(u, v, i, j, k+1);
472  const ib_wall::WallState ws = ib_wall::wall_state(ut, ut_ref,
473  if_face_theta(cell_data, i, j, k, io, jo),
474  if_face_theta(cell_data, i, j, k+1, io, jo),
475  if_face_q(cell_data, qv_comp, i, j, k, io, jo),
476  if_face_q(cell_data, qv_comp, i, j, k+1, io, jo),
477  ib_wall::wall_beta(b_k, small), dz, z0, cond);
478  mom_src_arr(i, j, k) -= ib_wall::stress_rate(ws.ustar, ut, dz, dt) * rho_face * un;
479  } else if (l_drag) {
480  const Real wz = (dir == 0) ? fourth * ( w(i, j, k) + w(i-1, j, k) + w(i, j, k+1) + w(i-1, j, k+1) )
481  : fourth * ( w(i, j, k) + w(i, j-1, k) + w(i, j, k+1) + w(i, j-1, k+1) );
482  const Real uh = if_face_speed<dir>(u, v, i, j, k);
483  const Real windspeed = std::sqrt(uh * uh + wz * wz);
484  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dz, one/three);
485  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
486  const Real lambda = b_k * CdM * windspeed; // linear drag rate [1/s]; zero in fluid cells
487  const Real fac_local = l_implicit_drag ? lambda / (one + lambda*dt) : lambda;
488  mom_src_arr(i, j, k) -= fac_local * rho_face * un;
489  }
490  });
491 }
static ib_wall::WallCond make_wall_cond(const SolverChoice &sc, const Real time)
Definition: ERF_ImmersedForcing.cpp:340
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool is_wall_cell(amrex::Real b_km1, amrex::Real b_k, amrex::Real b_kp1, amrex::Real small) noexcept
Definition: ERF_ImmersedWallCell.H:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real wall_beta(amrex::Real b_k, amrex::Real small) noexcept
Definition: ERF_ImmersedWallCell.H:65
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WallState wall_state(amrex::Real ut, amrex::Real ut_ref, amrex::Real theta, amrex::Real theta_ref, amrex::Real q, amrex::Real q_ref, amrex::Real beta, amrex::Real dz, amrex::Real z0, const WallCond &c) noexcept
Definition: ERF_ImmersedWallCell.H:205
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real stress_rate(amrex::Real ustar, amrex::Real ut, amrex::Real dz, amrex::Real dt) noexcept
Definition: ERF_ImmersedWallCell.H:333
int qv
water vapor
Definition: ERF_DataStruct.H:290
MoistureComponentIndices moisture_indices
Index map of the moisture data carried by the active scheme: conserved-state components for the speci...
Definition: ERF_DataStruct.H:3504
Definition: ERF_ImmersedWallCell.H:121
bool moist
Definition: ERF_ImmersedWallCell.H:141
Definition: ERF_ImmersedWallCell.H:146
amrex::Real ustar
Definition: ERF_ImmersedWallCell.H:147
Here is the call graph for this function:

◆ ImmersedForcingTerrain_Scalar()

void ImmersedForcingTerrain_Scalar ( const Box &  bx,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  cell_src,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Table1D< Real > &  r_avg,
const Table1D< Real > &  t_avg,
const Real  time 
)

Apply terrain immersed forcing to scalars (Rho, RhoTheta)

1328 {
1329  // geometric properties
1330  const auto dx_arr = geom.CellSizeArray();
1331  // The drag rates take dx in place of a dy over one cell, and the reverse
1332  const auto len_arr = LengthScaleCellSize(geom);
1333  const Real len_x = len_arr[0];
1334  const Real len_y = len_arr[1];
1335 
1336  const Real alpha_h = solverChoice.if_Cd_scalar;
1337  // The terrain kernels keep the raw fractions: erf.if_snap_partial_cells
1338  // applies to the buildings kernels only (the wall law below is weighted
1339  // by the fluid fraction of the face, which a snapped face has not).
1340  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
1341  const Real U_s = one; // unit velocity scale
1342 
1343  // MOST parameters (the similarity functions from erf.most.stable_functions)
1344  const similarity_funs sfuns = solverChoice.most_sfuns;
1345  const Real ggg = CONST_GRAV;
1346  const Real kappa = KAPPA;
1347  const Real z0 = solverChoice.if_z0;
1348  const Real tflux = solverChoice.if_surf_temp_flux;
1349  const Real init_surf_temp = solverChoice.if_init_surf_temp;
1350 
1351  // Note this has been converted to K / s when it was read in;
1352  const Real surf_heating_rate = solverChoice.if_surf_heating_rate;
1353 
1354  const Real Olen_in = solverChoice.if_Olen_in;
1355  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
1356  // erf.if_stability_correction (off by default): the similarity functions of the temperature
1357  // kernels, as of the momentum kernels; off, the log law (erf-model/ERF#4931)
1358  const bool l_stability_correction = solverChoice.if_stability_correction;
1359 
1360  ParallelFor(bx, [=]
1361  AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1362  {
1363  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
1364  const Real drag_coefficient = alpha_h / std::pow(len_x*len_y*dx_z, one/three);
1365 
1366  const Real t_blank = t_blank_arr(i, j, k);
1367  const Real t_blank_above = t_blank_arr(i, j, k+1);
1368  const Real ux_cc_2r = myhalf * (u(i ,j ,k+1) + u(i+1,j ,k+1));
1369  const Real uy_cc_2r = myhalf * (v(i ,j ,k+1) + v(i ,j+1,k+1));
1370  // The heat transfer uses the wind floored at erf.if_stability_wind_floor and an Obukhov
1371  // length bounded so that |zeta| <= ib_stability::zeta_max(), as on flat ground
1372  const Real h_windspeed2r = ib_stability::floored_wind(std::sqrt(ux_cc_2r * ux_cc_2r + uy_cc_2r * uy_cc_2r), stab_wind_floor);
1373 
1374  const Real theta = cell_data(i,j,k ,RhoTheta_comp) / cell_data(i,j,k ,Rho_comp);
1375  const Real theta_neighbor = cell_data(i,j,k+1,RhoTheta_comp) / cell_data(i,j,k+1,Rho_comp);
1376 
1377  // SURFACE TEMP AND HEATING/COOLING RATE
1378  if (init_surf_temp > zero) {
1379  if (t_blank > 0 && (t_blank_above == zero)) { // force to MOST value
1380  const Real surf_temp = init_surf_temp + surf_heating_rate*time;
1381  const Real bc_forcing_rt_srf = -(cell_data(i,j,k-1,Rho_comp) * surf_temp - cell_data(i,j,k-1,RhoTheta_comp));
1382  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt_srf;
1383  }
1384  }
1385 
1386  // SURFACE HEAT FLUX
1387  if (tflux != Real(1e-8)){
1388  if (t_blank > 0 && (t_blank_above == zero)) { // force to MOST value
1389  Real psi_m = zero;
1390  Real psi_h = zero;
1391  Real psi_h_neighbor = zero;
1392  Real ustar = h_windspeed2r * kappa / (std::log((Real(1.5)) * dx_z / z0) - psi_m);
1393  const Real Olen = ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta / (kappa * ggg * tflux + tiny),
1394  Real(1.5) * dx_z);
1395  const Real zeta = ib_stability::bounded_zeta(myhalf * dx_z, Olen);
1396  const Real zeta_neighbor = ib_stability::bounded_zeta(Real(1.5) * dx_z, Olen);
1397 
1398  // similarity functions (off by default: the plain log law, as in the momentum kernels)
1399  if (l_stability_correction) {
1400  psi_m = sfuns.calc_psi_m(zeta);
1401  psi_h = sfuns.calc_psi_h(zeta);
1402  psi_h_neighbor = sfuns.calc_psi_h(zeta_neighbor);
1403  }
1404  ustar = h_windspeed2r * kappa / (std::log((Real(1.5)) * dx_z / z0) - psi_m);
1405 
1406  // prevent some unphysical math
1408  // caps of ln(z / z0): erf.if_psi_cap_factor stays off the temperature forcing, whose
1409  // theta* comes from an L not made consistent with u* (the legacy law, kept as it is;
1410  // the fraction-stress law of erf-model/ERF#4134 forms them consistently)
1411  // (with the flag off psi_h is zero and stays so; a cap of ln(z / z0) <= 0, for z0 >= z, is not applied)
1412  if (l_stability_correction) {
1413  psi_h_neighbor = ib_stability::capped_psi(psi_h_neighbor, Real(1.5) * dx_z, z0, one);
1414  psi_h = ib_stability::capped_psi(psi_h, myhalf * dx_z, z0, one);
1415  }
1416 
1417  // We do not know the actual temperature so use cell above
1418  const Real thetastar = theta * ustar * ustar / (kappa * ggg * Olen);
1419  const Real surf_temp = theta_neighbor - thetastar / kappa * (std::log((Real(1.5)) * dx_z / z0) - psi_h_neighbor);
1420  const Real tTarget = surf_temp + thetastar / kappa * (std::log((myhalf) * dx_z / z0) - psi_h);
1421 
1422  const Real bc_forcing_rt = -(cell_data(i,j,k,Rho_comp) * tTarget - cell_data(i,j,k,RhoTheta_comp));
1423  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt;
1424  }
1425  }
1426 
1427  // OBUKHOV LENGTH
1428  if (Olen_in != Real(1e-8)){
1429  if (t_blank > 0 && (t_blank_above == zero)) { // force to MOST value
1430  // the prescribed length as given, with its zeta held within +-zeta_max()
1431  const Real Olen = Olen_in;
1432  const Real zeta = ib_stability::bounded_zeta(myhalf * dx_z, Olen);
1433  const Real zeta_neighbor = ib_stability::bounded_zeta(Real(1.5) * dx_z, Olen);
1434 
1435  // similarity functions (off by default: the log law, theta* from the given L); psi_h
1436  // capped at ln(z / z0) as on the other temperature branches
1437  const Real psi_m = l_stability_correction ? sfuns.calc_psi_m(zeta) : zero;
1438  const Real psi_h = l_stability_correction ? ib_stability::capped_psi(sfuns.calc_psi_h(zeta), myhalf * dx_z, z0, one) : zero;
1439  const Real psi_h_neighbor = l_stability_correction ? ib_stability::capped_psi(sfuns.calc_psi_h(zeta_neighbor), Real(1.5) * dx_z, z0, one) : zero;
1440  // psi_m at 0.5 dz against ln(1.5 dz / z0) can cancel; u* is held in [0, 2] m/s as on the
1441  // other branches. In unstable air psi_h >= psi_m and psi_h grows with |zeta|, so wherever
1442  // psi_m reaches ln(1.5 dz / z0) both psi_h caps above bind, the two log brackets close
1443  // and the target is the cell above whatever u* is: the clamp only guards the arithmetic.
1444  const Real ustar = ib_stability::clamped_ustar(h_windspeed2r * kappa / (std::log((Real(1.5)) * dx_z / z0) - psi_m));
1445 
1446  // We do not know the actual temperature so use cell above
1447  const Real thetastar = theta * ustar * ustar / (kappa * ggg * Olen);
1448  const Real surf_temp = theta_neighbor - thetastar / kappa * (std::log((Real(1.5)) * dx_z / z0) - psi_h_neighbor);
1449  const Real tTarget = surf_temp + thetastar / kappa * (std::log((myhalf) * dx_z / z0) - psi_h);
1450 
1451  const Real bc_forcing_rt = -(cell_data(i,j,k,Rho_comp) * tTarget - cell_data(i,j,k,RhoTheta_comp));
1452  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt;
1453  }
1454  }
1455 
1456  // Force fully immersed cells to planar average rho and theta
1457  if (t_blank == one && r_avg && t_avg) {
1458  const Real rho_avg = r_avg(k);
1459  const Real theta_avg = t_avg(k) / rho_avg; // Convert from RhoTheta to Theta
1460  const Real rho_cell = cell_data(i,j,k,Rho_comp);
1461  const Real bc_forcing_r = -(rho_avg - rho_cell);
1462  const Real bc_forcing_rt = -(rho_avg * theta_avg - cell_data(i,j,k,RhoTheta_comp));
1463 
1464  cell_src(i, j, k, Rho_comp) -= drag_coefficient * U_s * bc_forcing_r;
1465  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * U_s * bc_forcing_rt;
1466  }
1467  });
1468 }

Referenced by make_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingTerrain_Scalar_FractionStress()

void ImmersedForcingTerrain_Scalar_FractionStress ( const Box &  bx,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< Real > &  cell_src,
const Array4< Real > &  wall_hfx,
const Array4< Real > &  wall_ktarget,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Table1D< Real > &  r_avg,
const Table1D< Real > &  t_avg,
const Real  dt,
const Real  time,
const bool  wall_tke,
const Real  Cmu0,
const Array4< Real > &  wall_qfx,
const bool  wall_tke_moist 
)

Fraction-stress wall law for the scalars (erf.if_wall_form = fraction_stress), see ERF_ImmersedWallCell.H: the wall heat flux -u* theta* in the wall cell of each column, with the u* and theta* of the momentum law, and the relaxation of fully immersed cells to the planar average of the legacy kernel. The kinematic wall flux -u* theta* is stored in wall_hfx at the wall cell (zero elsewhere), for the TKE buoyancy on the wall face; with wall_tke the wall value of the TKE is stored in wall_ktarget at the wall cell (-1 elsewhere), and a time factor of 1 leaves the pin to erf_slow_rhs_post and the implicit TKE solve. With a moisture model the wall moisture flux -u* q* of the surface moisture condition (erf.if_surf_moist_flux or erf.if_surf_moist; q* = 0 without one) goes to the water vapor of the wall cell and is stored in wall_qfx (zero elsewhere); with wall_tke_moist (erf.rans_moist_buoyancy) the wall TKE's buoyancy uses theta_v* and theta_v, as flat ground's erf.dirichlet_k does under the same key.

560 {
561  const Real* dx_arr = geom.CellSize();
562  const Real dz = dx_arr[2]; // fraction_stress runs on a constant-dz mesh
563  // The drag rate takes dx in place of a dy over one cell, and the reverse
564  const auto len_arr = LengthScaleCellSize(geom);
565  const Real tke_time_factor = solverChoice.if_wall_tke_time_factor;
566  // a time factor of 1 pins the wall cell at the wall value after every stage (erf_slow_rhs_post
567  // and the implicit TKE solve read wall_ktarget), as erf.dirichlet_k does on flat ground;
568  // larger factors relax toward it here as a source
569  const bool tke_pin = (tke_time_factor <= one);
570  const Real drag_coefficient = solverChoice.if_Cd_scalar / std::pow(len_arr[0]*len_arr[1]*dz, one/three);
571  const Real z0 = solverChoice.if_z0;
572  const Real small = solverChoice.if_small_volfrac;
573  const ib_wall::WallCond cond = make_wall_cond(solverChoice, time);
574  const int klo = geom.Domain().smallEnd(2);
575  const int khi = geom.Domain().bigEnd(2);
576  const bool have_avg = (r_avg && t_avg);
577  // water vapor component of the conserved state (-1 without a moisture model that carries it)
578  const int qv_comp = cond.moist ? solverChoice.moisture_indices.qv : -1;
579  const bool moist_cond = (qv_comp >= 0) && (cond.moist_type != ib_wall::WallCond::moist_none);
580 
581  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
582  {
583  const Real b_k = if_cell_beta(t_blank_arr, i, j, k, klo, khi, small);
584  if (wall_hfx) { wall_hfx(i, j, k) = zero; }
585  if (wall_qfx) { wall_qfx(i, j, k) = zero; }
586  if (wall_ktarget) { wall_ktarget(i, j, k) = -one; } // no wall value: not a wall cell
587 
588  if (ib_wall::is_wall_cell(if_cell_beta(t_blank_arr, i, j, k-1, klo, khi, small), b_k,
589  if_cell_beta(t_blank_arr, i, j, k+1, klo, khi, small), small)) {
590  // horizontal speed at the cell centers of the wall cell and the cell above
591  const Real uc0 = myhalf * (u(i, j, k) + u(i+1, j, k));
592  const Real vc0 = myhalf * (v(i, j, k) + v(i, j+1, k));
593  const Real uc1 = myhalf * (u(i, j, k+1) + u(i+1, j, k+1));
594  const Real vc1 = myhalf * (v(i, j, k+1) + v(i, j+1, k+1));
595  const Real rho = cell_data(i, j, k, Rho_comp);
596  const Real theta = cell_data(i, j, k, RhoTheta_comp) / rho;
597  const Real theta_ref = cell_data(i, j, k+1, RhoTheta_comp) / cell_data(i, j, k+1, Rho_comp);
598  // water vapor of the wall cell and the cell above (zero without a moisture model)
599  const Real q = (qv_comp >= 0) ? cell_data(i, j, k, qv_comp) / rho : zero;
600  const Real q_ref = (qv_comp >= 0) ? cell_data(i, j, k+1, qv_comp) / cell_data(i, j, k+1, Rho_comp) : zero;
601  const ib_wall::WallState ws = ib_wall::wall_state(std::sqrt(uc0*uc0 + vc0*vc0), std::sqrt(uc1*uc1 + vc1*vc1),
602  theta, theta_ref, q, q_ref,
603  ib_wall::wall_beta(b_k, small), dz, z0, cond);
604  cell_src(i, j, k, RhoTheta_comp) += rho * ib_wall::heat_source(ws, theta, cond, dz, dt);
605  if (wall_hfx) { wall_hfx(i, j, k) = -ws.ustar * ws.thetastar; }
606  if (moist_cond) {
607  cell_src(i, j, k, qv_comp) += rho * ib_wall::moist_source(ws, q, cond, dz, dt);
608  }
609  if (wall_qfx) { wall_qfx(i, j, k) = -ws.ustar * ws.qstar; }
610  if (wall_tke) {
611  // under erf.rans_moist_buoyancy the buoyancy of the wall value is the virtual one
612  const Real k_wall = (wall_tke_moist && cond.moist)
613  ? ib_wall::wall_tke(ws, ib_wall::wall_beta(b_k, small), dz, z0, Cmu0,
615  : ib_wall::wall_tke(ws, ib_wall::wall_beta(b_k, small), dz, z0, theta, Cmu0);
616  if (wall_ktarget) { wall_ktarget(i, j, k) = k_wall; }
617  if (!tke_pin) {
618  // relax the wall-cell TKE toward its wall value over tke_time_factor steps
619  const Real k_now = cell_data(i, j, k, RhoKE_comp) / rho;
620  cell_src(i, j, k, RhoKE_comp) += rho * (k_wall - k_now) / (tke_time_factor * dt);
621  }
622  }
623  } else if (b_k == one && have_avg) {
624  // fully immersed cells: relax to the planar average, as the legacy kernel does
625  const Real rho_avg = r_avg(k);
626  const Real theta_avg = t_avg(k) / rho_avg;
627  cell_src(i, j, k, Rho_comp) -= drag_coefficient * (cell_data(i,j,k,Rho_comp) - rho_avg);
628  cell_src(i, j, k, RhoTheta_comp) -= drag_coefficient * (cell_data(i,j,k,RhoTheta_comp) - rho_avg * theta_avg);
629  }
630  });
631 }
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
@ rho
Definition: ERF_Kessler.H:25
@ q
Definition: ERF_WSM6.H:296
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real wall_tke(const WallState &w, amrex::Real beta, amrex::Real dz, amrex::Real z0, amrex::Real Cmu0, amrex::Real bstar, amrex::Real btheta) noexcept
Definition: ERF_ImmersedWallCell.H:352
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real virtual_thetastar(const WallState &w, amrex::Real theta, amrex::Real q) noexcept
Definition: ERF_ImmersedWallCell.H:169
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real virtual_theta(amrex::Real theta, amrex::Real q) noexcept
Definition: ERF_ImmersedWallCell.H:158
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real moist_source(const WallState &w, amrex::Real q, const WallCond &c, amrex::Real dz, amrex::Real dt) noexcept
Definition: ERF_ImmersedWallCell.H:320
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real heat_source(const WallState &w, amrex::Real theta, const WallCond &c, amrex::Real dz, amrex::Real dt) noexcept
Definition: ERF_ImmersedWallCell.H:304
amrex::Real if_wall_tke_time_factor
1 (the default) pins the wall cell after every stage and in the implicit TKE solve; a larger value re...
Definition: ERF_DataStruct.H:3129
int moist_type
Definition: ERF_ImmersedWallCell.H:136
static constexpr int moist_none
no moisture exchange, q* = 0
Definition: ERF_ImmersedWallCell.H:133
amrex::Real thetastar
Definition: ERF_ImmersedWallCell.H:148
amrex::Real qstar
Definition: ERF_ImmersedWallCell.H:149

Referenced by make_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingTerrain_Xmom()

void ImmersedForcingTerrain_Xmom ( const Box &  tbx,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_xface_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  xmom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
const bool  l_drag_in_projection 
)

Apply terrain immersed forcing to X-momentum

96 {
97  // geometric properties
98  const auto dx_arr = geom.CellSizeArray();
99  // The drag rates take dx in place of a dy over one cell, and the reverse
100  const auto len_arr = LengthScaleCellSize(geom);
101  const Real len_x = len_arr[0];
102  const Real len_y = len_arr[1];
103  const Real dt = fac; // fac is actually dt in the calling code
104 
105  const Real alpha_m = solverChoice.if_Cd_momentum;
106  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
107  const Real U_s = one; // unit velocity scale
108  const bool l_implicit_drag = solverChoice.if_implicit_drag;
109  // erf.if_implicit_projection: the drag of the solid is applied inside the projection
110  // (anelastic and pseudo-incompressible levels)
111  const bool l_drag = !l_drag_in_projection;
112 
113  // MOST parameters (the similarity functions from erf.most.stable_functions)
114  const similarity_funs sfuns = solverChoice.most_sfuns;
115  const Real ggg = CONST_GRAV;
116  const Real kappa = KAPPA;
117  const Real z0 = solverChoice.if_z0;
118  const Real tflux_in = solverChoice.if_surf_temp_flux;
119  const Real Olen_in = solverChoice.if_Olen_in;
120  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
121  const Real psi_cap_factor = solverChoice.if_psi_cap_factor;
122  const bool l_use_most = solverChoice.if_use_most;
123  const bool l_stability_correction = solverChoice.if_stability_correction;
124 
125  const Real small_volfrac = solverChoice.if_small_volfrac;
126  // The terrain kernels keep the raw fractions: erf.if_snap_partial_cells
127  // applies to the buildings kernels only (the wall law below is weighted
128  // by the fluid fraction of the face, which a snapped face has not).
129 
130  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
131  {
132  const Real ux = u(i, j, k);
133  const Real uy = fourth * ( v(i, j , k ) + v(i-1, j , k )
134  + v(i, j+1, k ) + v(i-1, j+1, k ) );
135  const Real uz = fourth * ( w(i, j , k ) + w(i-1, j , k )
136  + w(i, j , k+1) + w(i-1, j , k+1) );
137  const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
138  // Use face-centered terrain_blanking if available, otherwise average from cell centers
139  Real t_blank_raw = (t_blank_xface_arr) ? t_blank_xface_arr(i, j, k) :
140  myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i-1, j, k));
141  // Threshold: if averaged value is below small_volfrac, set to zero
142  const Real t_blank = (t_blank_raw < small_volfrac) ? zero : t_blank_raw;
143 
144  Real t_blank_above_raw = (t_blank_xface_arr) ? t_blank_xface_arr(i, j, k+1) :
145  myhalf * (t_blank_arr(i, j, k+1) + t_blank_arr(i-1, j, k+1));
146  const Real t_blank_above = (t_blank_above_raw < small_volfrac) ? zero : t_blank_above_raw;
147 
148  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
149  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dx_z, one/three);
150  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
151 
152  const Real rho_xface = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i-1,j,k,Rho_comp) );
153 
154  // With erf.if_implicit_projection a fully solid face is held by the drag in the projection
155  // (the explicit path zeroes it after the projection instead), so the wall law is not applied there
156  if ((t_blank > 0 && (t_blank_above == zero)) && l_use_most && (l_drag || t_blank < one)) { // force to MOST value
157  // calculate tangential velocity one cell above
158  const Real ux2r = u(i, j, k+1) ;
159  const Real uy2r = fourth * ( v(i, j , k+1) + v(i-1, j , k+1)
160  + v(i, j+1, k+1) + v(i-1, j+1, k+1) ) ;
161  const Real h_windspeed2r = std::sqrt(ux2r * ux2r + uy2r * uy2r);
162 
163  // MOST
164  const Real theta_xface = (myhalf * (cell_data(i,j,k ,RhoTheta_comp) + cell_data(i-1,j,k, RhoTheta_comp))) / rho_xface;
165  const Real rho_xface_below = myhalf * ( cell_data(i,j,k-1,Rho_comp) + cell_data(i-1,j,k-1,Rho_comp) );
166  const Real theta_xface_below = (myhalf * (cell_data(i,j,k-1,RhoTheta_comp) + cell_data(i-1,j,k-1, RhoTheta_comp))) / rho_xface_below;
167  const Real theta_surf = theta_xface_below;
168 
169  Real psi_m = zero;
170  Real psi_h = zero;
171  // The stability estimate uses the wind floored at erf.if_stability_wind_floor, a derived
172  // Obukhov length bounded so that |zeta| <= ib_stability::zeta_max() as on flat ground,
173  // and a prescribed one as given with its zeta held there; the target uses the actual wind
174  Real ustar = ib_stability::floored_wind(h_windspeed2r, stab_wind_floor) * kappa / (std::log(Real(1.5) * dx_z / z0) - psi_m); // calculated from bottom of cell. Maintains flexibility for different Vf values
175  Real tflux = (tflux_in != Real(1e-8)) ? tflux_in : -(theta_xface - theta_surf) * ustar * kappa / (std::log(Real(1.5) * dx_z / z0) - psi_h);
176  Real Olen = (Olen_in != Real(1e-8)) ? Olen_in
177  : ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta_xface / (kappa * ggg * tflux + tiny), Real(1.5) * dx_z);
178  Real zeta = ib_stability::bounded_zeta(Real(1.5) * dx_z, Olen);
179 
180  // similarity functions (off by default: the plain log law)
181  if (l_stability_correction) {
182  psi_m = sfuns.calc_psi_m(zeta);
183  psi_h = sfuns.calc_psi_h(zeta);
184  }
185  ustar = h_windspeed2r * kappa / (std::log(Real(1.5) * dx_z / z0) - ib_stability::psi_m_for_ustar(psi_m, Real(1.5) * dx_z, z0, psi_cap_factor));
186 
187  // prevent some unphysical math
189  psi_m = ib_stability::capped_psi(psi_m, myhalf * dx_z, z0, psi_cap_factor);
190 
191  // determine target velocity
192  const Real uTarget = ustar / kappa * (std::log(myhalf * dx_z / z0) - psi_m);
193  Real uxTarget = uTarget * ux2r / (tiny + h_windspeed2r);
194  const Real bc_forcing_x = -(uxTarget - ux); // BC forcing pushes nonrelative velocity toward target velocity
195  const Real lambda = (1-t_blank) * CdM * U_s; // affine relaxation rate toward MOST target [1/s]
196  const Real fac_local = l_implicit_drag ? lambda / (one + lambda*dt) : lambda; // point-implicit rescale (else explicit)
197  xmom_src_arr(i, j, k) -= fac_local * rho_xface * bc_forcing_x; // if Vf low, force more strongly to MOST. If high, less forcing.
198  } else if (l_drag) {
199  const Real lambda = t_blank * CdM * windspeed; // linear drag rate [1/s]
200  const Real fac_local = l_implicit_drag ? lambda / (one + lambda*dt) : lambda; // point-implicit rescale (else explicit)
201  xmom_src_arr(i, j, k) -= fac_local * rho_xface * ux;
202  }
203  });
204 }

Referenced by make_mom_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingTerrain_Xmom_FractionStress()

void ImmersedForcingTerrain_Xmom_FractionStress ( const Box &  tbx,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_xface_arr,
const Array4< Real > &  xmom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
const Real  time,
const bool  l_drag_in_projection 
)
506 {
507  ImmersedForcingTerrain_HorizMom_FractionStress<0>(tbx, u, v, w, cell_data, t_blank_arr, t_blank_xface_arr,
508  xmom_src_arr, geom, solverChoice, fac, time, l_drag_in_projection);
509 }

Referenced by make_mom_sources().

Here is the caller graph for this function:

◆ ImmersedForcingTerrain_Ymom()

void ImmersedForcingTerrain_Ymom ( const Box &  tby,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_yface_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  ymom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
const bool  l_drag_in_projection 
)

Apply terrain immersed forcing to Y-momentum

222 {
223  // geometric properties
224  const auto dx_arr = geom.CellSizeArray();
225  // The drag rates take dx in place of a dy over one cell, and the reverse
226  const auto len_arr = LengthScaleCellSize(geom);
227  const Real len_x = len_arr[0];
228  const Real len_y = len_arr[1];
229  const Real dt = fac; // fac is actually dt in the calling code
230 
231  const Real alpha_m = solverChoice.if_Cd_momentum;
232  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
233  const Real U_s = one; // unit velocity scale
234  const bool l_implicit_drag = solverChoice.if_implicit_drag;
235  // erf.if_implicit_projection: the drag of the solid is applied inside the projection
236  // (anelastic and pseudo-incompressible levels)
237  const bool l_drag = !l_drag_in_projection;
238 
239  // MOST parameters (the similarity functions from erf.most.stable_functions)
240  const similarity_funs sfuns = solverChoice.most_sfuns;
241  const Real ggg = CONST_GRAV;
242  const Real kappa = KAPPA;
243  const Real z0 = solverChoice.if_z0;
244  const Real tflux_in = solverChoice.if_surf_temp_flux;
245  const Real Olen_in = solverChoice.if_Olen_in;
246  const Real stab_wind_floor = solverChoice.if_stability_wind_floor;
247  const Real psi_cap_factor = solverChoice.if_psi_cap_factor;
248  const bool l_use_most = solverChoice.if_use_most;
249  const bool l_stability_correction = solverChoice.if_stability_correction;
250 
251  const Real small_volfrac = solverChoice.if_small_volfrac;
252  // The terrain kernels keep the raw fractions: erf.if_snap_partial_cells
253  // applies to the buildings kernels only (the wall law below is weighted
254  // by the fluid fraction of the face, which a snapped face has not).
255 
256  ParallelFor(tby, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
257  {
258  const Real ux = fourth * ( u(i , j , k ) + u(i , j-1, k )
259  + u(i+1, j , k ) + u(i+1, j-1, k ) );
260  const Real uy = v(i, j, k);
261  const Real uz = fourth * ( w(i , j , k ) + w(i , j-1, k )
262  + w(i , j , k+1) + w(i , j-1, k+1) );
263  const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
264  // Use face-centered terrain_blanking if available, otherwise average from cell centers
265  Real t_blank_raw = (t_blank_yface_arr) ? t_blank_yface_arr(i, j, k) :
266  myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j-1, k));
267  const Real t_blank = (t_blank_raw < small_volfrac) ? zero : t_blank_raw;
268 
269  Real t_blank_above_raw = (t_blank_yface_arr) ? t_blank_yface_arr(i, j, k+1) :
270  myhalf * (t_blank_arr(i, j, k+1) + t_blank_arr(i, j-1, k+1));
271  const Real t_blank_above = (t_blank_above_raw < small_volfrac) ? zero : t_blank_above_raw;
272 
273  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
274  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dx_z, one/three);
275  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
276 
277  const Real rho_yface = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j-1,k,Rho_comp) );
278 
279  // With erf.if_implicit_projection a fully solid face is held by the drag in the projection
280  // (the explicit path zeroes it after the projection instead), so the wall law is not applied there
281  if ((t_blank > 0 && (t_blank_above == zero)) && l_use_most && (l_drag || t_blank < one)) { // force to MOST value
282  // calculate tangential velocity one cell above
283  const Real ux2r = fourth * ( u(i , j , k+1) + u(i , j-1, k+1)
284  + u(i+1, j , k+1) + u(i+1, j-1, k+1) );
285  const Real uy2r = v(i, j, k+1) ;
286  const Real h_windspeed2r = std::sqrt(ux2r * ux2r + uy2r * uy2r);
287 
288  // MOST
289  const Real theta_yface = (myhalf * (cell_data(i,j,k ,RhoTheta_comp) + cell_data(i,j-1,k, RhoTheta_comp))) / rho_yface;
290  const Real rho_yface_below = myhalf * ( cell_data(i,j,k-1,Rho_comp) + cell_data(i,j-1,k-1,Rho_comp) );
291  const Real theta_yface_below = (myhalf * (cell_data(i,j,k-1,RhoTheta_comp) + cell_data(i,j-1,k-1, RhoTheta_comp))) / rho_yface_below;
292  const Real theta_surf = theta_yface_below;
293 
294  Real psi_m = zero;
295  Real psi_h = zero;
296  // The stability estimate uses the wind floored at erf.if_stability_wind_floor, a derived
297  // Obukhov length bounded so that |zeta| <= ib_stability::zeta_max() as on flat ground,
298  // and a prescribed one as given with its zeta held there; the target uses the actual wind
299  Real ustar = ib_stability::floored_wind(h_windspeed2r, stab_wind_floor) * kappa / (std::log(Real(1.5) * dx_z / z0) - psi_m); // calculated from bottom of cell. Maintains flexibility for different Vf values
300  Real tflux = (tflux_in != Real(1e-8)) ? tflux_in : -(theta_yface - theta_surf) * ustar * kappa / (std::log(Real(1.5) * dx_z / z0) - psi_h);
301  Real Olen = (Olen_in != Real(1e-8)) ? Olen_in
302  : ib_stability::bounded_obukhov_length(-ustar * ustar * ustar * theta_yface / (kappa * ggg * tflux + tiny), Real(1.5) * dx_z);
303  Real zeta = ib_stability::bounded_zeta(Real(1.5) * dx_z, Olen);
304 
305  // similarity functions (off by default: the plain log law)
306  if (l_stability_correction) {
307  psi_m = sfuns.calc_psi_m(zeta);
308  psi_h = sfuns.calc_psi_h(zeta);
309  }
310  ustar = h_windspeed2r * kappa / (std::log(Real(1.5) * dx_z / z0) - ib_stability::psi_m_for_ustar(psi_m, Real(1.5) * dx_z, z0, psi_cap_factor));
311 
312  // prevent some unphysical math
314  psi_m = ib_stability::capped_psi(psi_m, myhalf * dx_z, z0, psi_cap_factor);
315 
316  // determine target velocity
317  const Real uTarget = ustar / kappa * (std::log(myhalf * dx_z / z0) - psi_m);
318  Real uyTarget = uTarget * uy2r / (tiny + h_windspeed2r);
319  const Real bc_forcing_y = -(uyTarget - uy); // BC forcing pushes nonrelative velocity toward target velocity
320  const Real lambda = (1 - t_blank) * CdM * U_s; // affine relaxation rate toward MOST target [1/s]
321  const Real fac_local = l_implicit_drag ? lambda / (one + lambda*dt) : lambda; // point-implicit rescale (else explicit)
322  ymom_src_arr(i, j, k) -= fac_local * rho_yface * bc_forcing_y; // if Vf low, force more strongly to MOST. If high, less forcing.
323  } else if (l_drag) {
324  const Real lambda = t_blank * CdM * windspeed; // linear drag rate [1/s]
325  const Real fac_local = l_implicit_drag ? lambda / (one + lambda*dt) : lambda; // point-implicit rescale (else explicit)
326  ymom_src_arr(i, j, k) -= fac_local * rho_yface * uy;
327  }
328  });
329 }

Referenced by make_mom_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImmersedForcingTerrain_Ymom_FractionStress()

void ImmersedForcingTerrain_Ymom_FractionStress ( const Box &  tby,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_yface_arr,
const Array4< Real > &  ymom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
const Real  time,
const bool  l_drag_in_projection 
)
524 {
525  ImmersedForcingTerrain_HorizMom_FractionStress<1>(tby, u, v, w, cell_data, t_blank_arr, t_blank_yface_arr,
526  ymom_src_arr, geom, solverChoice, fac, time, l_drag_in_projection);
527 }

Referenced by make_mom_sources().

Here is the caller graph for this function:

◆ ImmersedForcingTerrain_Zmom()

void ImmersedForcingTerrain_Zmom ( const Box &  tbz,
const Array4< const Real > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  t_blank_arr,
const Array4< const Real > &  t_blank_zface_arr,
const Array4< const Real > &  z_cc_arr,
const Array4< Real > &  zmom_src_arr,
const Geometry &  geom,
const SolverChoice &  solverChoice,
const Real  fac,
const bool  l_drag_in_projection 
)

Apply terrain immersed forcing to Z-momentum

650 {
651  // geometric properties
652  const auto dx_arr = geom.CellSizeArray();
653  // The drag rates take dx in place of a dy over one cell, and the reverse
654  const auto len_arr = LengthScaleCellSize(geom);
655  const Real len_x = len_arr[0];
656  const Real len_y = len_arr[1];
657  const Real dt = fac; // fac is actually dt in the calling code
658 
659  const Real alpha_m = solverChoice.if_Cd_momentum;
660  const Real tiny = std::numeric_limits<amrex::Real>::epsilon();
661  const bool l_implicit_drag = solverChoice.if_implicit_drag;
662  // erf.if_implicit_projection: the drag of the solid is applied inside the projection
663  // (anelastic and pseudo-incompressible levels)
664  const bool l_drag = !l_drag_in_projection;
665 
666  const Real small_volfrac = solverChoice.if_small_volfrac;
667  // The terrain kernels keep the raw fractions: erf.if_snap_partial_cells
668  // applies to the buildings kernels only (the wall law below is weighted
669  // by the fluid fraction of the face, which a snapped face has not).
670 
671  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
672  {
673  const Real ux = fourth * ( u(i , j , k ) + u(i+1, j , k )
674  + u(i , j , k-1) + u(i+1, j , k-1) );
675  const Real uy = fourth * ( v(i , j , k ) + v(i , j+1, k )
676  + v(i , j , k-1) + v(i , j+1, k-1) );
677  const Real uz = w(i, j, k);
678  const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
679  // Use face-centered terrain_blanking if available, otherwise average from cell centers
680  Real t_blank_raw = (t_blank_zface_arr) ? t_blank_zface_arr(i, j, k) :
681  myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j, k-1));
682  const Real t_blank = (t_blank_raw < small_volfrac) ? zero : t_blank_raw;
683 
684  const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
685  const Real drag_coefficient = alpha_m / std::pow(len_x*len_y*dx_z, one/three);
686  const Real CdM = std::min(drag_coefficient / (windspeed + tiny), drag_coefficient);
687 
688  const Real rho_zface = myhalf * ( cell_data(i,j,k,Rho_comp) + cell_data(i,j,k-1,Rho_comp) );
689  const Real lambda = t_blank * CdM * windspeed; // linear drag rate [1/s]
690  const Real fac_local = l_implicit_drag ? lambda / (one + lambda*dt) : lambda; // point-implicit rescale (else explicit)
691  if (l_drag) { zmom_src_arr(i, j, k) -= fac_local * rho_zface * uz; }
692  });
693 }

Referenced by make_mom_sources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_wall_cond()

static ib_wall::WallCond make_wall_cond ( const SolverChoice &  sc,
const Real  time 
)
static

Surface condition of the fraction-stress wall law from the erf.if_* inputs at this time: a given Obukhov length, a given heat flux, a given surface temperature (erf.if_init_surf_temp, changing at erf.if_surf_heating_rate, which is stored in K/s), or none (neutral); and, with a moisture model that carries water vapor, a given moisture flux (erf.if_surf_moist_flux), a given surface mixing ratio (erf.if_surf_moist) or none, the Obukhov length then formed from theta_v and theta_v*. The inputs guarantee that at most one of each is set.

341 {
343  c.sfuns = sc.most_sfuns; // erf.most.stable_functions
345  if (sc.if_surf_moist_flux != zero) {
347  c.qflux = sc.if_surf_moist_flux;
348  } else if (sc.if_surf_moist >= zero) {
350  c.q_s = sc.if_surf_moist;
351  }
352  if (sc.if_Olen_in != Real(1e-8)) {
354  c.Linv = one / sc.if_Olen_in;
355  } else if (sc.if_surf_temp_flux != Real(1e-8)) {
357  c.q = sc.if_surf_temp_flux;
358  } else if (sc.if_init_surf_temp > zero) {
361  }
362  return c;
363 }
static constexpr int absent
not carried by the active scheme
Definition: ERF_DataStruct.H:282
amrex::Real if_surf_moist
Definition: ERF_DataStruct.H:3121
amrex::Real if_surf_moist_flux
Definition: ERF_DataStruct.H:3120
static constexpr int heat_flux
given kinematic surface heat flux q [K m/s]
Definition: ERF_ImmersedWallCell.H:123
amrex::Real Linv
Definition: ERF_ImmersedWallCell.H:129
static constexpr int obukhov
given Obukhov length (inverse Linv) [1/m]
Definition: ERF_ImmersedWallCell.H:125
static constexpr int surface_moist
given surface mixing ratio q_s [kg/kg]
Definition: ERF_ImmersedWallCell.H:135
int type
Definition: ERF_ImmersedWallCell.H:126
static constexpr int surface_temp
given surface potential temperature theta_s [K]
Definition: ERF_ImmersedWallCell.H:124
amrex::Real q
Definition: ERF_ImmersedWallCell.H:127
amrex::Real qflux
Definition: ERF_ImmersedWallCell.H:137
amrex::Real theta_s
Definition: ERF_ImmersedWallCell.H:128
similarity_funs sfuns
the similarity functions (erf.most.stable_functions)
Definition: ERF_ImmersedWallCell.H:130
amrex::Real q_s
Definition: ERF_ImmersedWallCell.H:138
static constexpr int moist_flux
given kinematic surface moisture flux [kg/kg m/s]
Definition: ERF_ImmersedWallCell.H:134

Referenced by ImmersedForcingTerrain_HorizMom_FractionStress(), and ImmersedForcingTerrain_Scalar_FractionStress().

Here is the caller graph for this function: