ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
SurfaceLayer Class Reference

#include <ERF_SurfaceLayer.H>

Collaboration diagram for SurfaceLayer:

Classes

struct  PBLHColumns
 

Public Types

enum class  FluxCalcType {
  MOENG = 0 , CUSTOM , BULK_COEFF , ROTATE ,
  RICO
}
 
enum class  ThetaCalcType { ADIABATIC = 0 , HEAT_FLUX , SURFACE_TEMPERATURE }
 
enum class  MoistCalcType { ADIABATIC = 0 , MOISTURE_FLUX , SURFACE_MOISTURE }
 
enum class  RoughCalcType {
  CONSTANT = 0 , CHARNOCK , MODIFIED_CHARNOCK , DONELAN ,
  WAVE_COUPLED
}
 
enum class  PBLHeightCalcType { None , MYNN25 , YSU , MRF }
 

Public Member Functions

 SurfaceLayer (amrex::Orientation face, const amrex::Vector< amrex::Geometry > &geom, bool &use_rot_surface_flux, std::string a_pp_prefix, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qv_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &z_phys_nd, const amrex::Vector< amrex::Vector< amrex::Real >> &zlevels_stag, const MeshType &a_mesh_type, const TerrainType &a_terrain_type, const TurbChoice &a_turb_choice, amrex::Real a_rdOcp, double start_low_time, double final_low_time, double low_time_interval=0.0, const amrex::Vector< const eb_ * > &eb_vec={}, SurfaceModel *surf_model=nullptr, bool a_has_immersed_buildings=false)
 
void check_similarity_funs_use () const
 
void make_SurfaceLayer_at_level (const int &lev, int nlevs, const amrex::Vector< amrex::MultiFab * > &mfv, std::unique_ptr< amrex::MultiFab > &Theta_prim, std::unique_ptr< amrex::MultiFab > &Qv_prim, std::unique_ptr< amrex::MultiFab > &Qr_prim, std::unique_ptr< amrex::MultiFab > &z_phys_nd, amrex::MultiFab *Hwave, amrex::MultiFab *Lwave, amrex::MultiFab *eddyDiffs, amrex::Vector< amrex::MultiFab * > lsm_data, amrex::Vector< std::string > lsm_data_name, amrex::Vector< amrex::MultiFab * > lsm_flux, amrex::Vector< std::string > lsm_flux_name, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &sst_lev, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &tsk_lev, amrex::Vector< std::unique_ptr< amrex::iMultiFab >> &lmask_lev, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> *mapfac=nullptr)
 
void set_immersed_surface_params (const int &lev)
 
void update_fluxes (const int &lev, const double &elapsed_time, const double &elapsed_time_since_start_low, amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, const std::unique_ptr< amrex::MultiFab > &walldist, int max_iters=100)
 
template<typename FluxIter >
void compute_fluxes (const int &lev, const int &max_iters, amrex::MultiFab &cons_in, const FluxIter &most_flux, bool is_land)
 
void init_tke_from_ustar (const int &lev, amrex::MultiFab &cons, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, const amrex::Real tkefac=one, const amrex::Real zscale=amrex::Real(700.0))
 
void fill_planar_boundary (const int &lev, amrex::MultiFab &mf)
 
amrex::Real surface_sum (const int &lev, const amrex::MultiFab &mf, int comp=0) const
 
void impose_SurfaceLayer_bcs (const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const amrex::MultiFab *z_phys, amrex::MultiFab *mf_surface_fluxes=nullptr)
 
void impose_SurfaceLayer_bcs_EB (const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux)
 
template<typename FluxCalc >
void compute_SurfaceLayer_bcs (const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const amrex::MultiFab *z_phys, const FluxCalc &flux_comp, amrex::MultiFab *mf_surface_fluxes=nullptr)
 
template<typename FluxCalc >
void compute_SurfaceLayer_bcs_EB (const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const FluxCalc &flux_comp)
 
void compute_sfc_params_from_lsm_fluxes (const int &lev, amrex::MultiFab &cons_in)
 
SurfaceFluxView get_lsm_flux_view (const int &lev, const amrex::MFIter &mfi) const
 
void set_sfc_params_from_file_fluxes (const int &lev, const amrex::MultiFab &cons_in, const amrex::Real &tflux_in, const amrex::Real &qflux_in, const amrex::Real &sfc_tau)
 
void fill_tsurf_with_sst_and_tsk (const int &lev, const double &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void fill_tsurf_with_sfc_sst (const int &lev, const double &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void fill_tsurf_with_coupled_sst (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void fill_tsurf_with_abs_surf_temp (const int &lev, const double &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void fill_tsurf_with_skin_temperature (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void fill_qsurf_with_skin_moisture (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd)
 
void fill_qsurf_with_skin_moisture (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void fill_qsurf_with_qsat (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd)
 
void fill_qsurf_with_qsat (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void set_pblh (const int &lev, const amrex::MultiFab &pblh_in)
 
void update_sfc_time_index (const amrex::Real &time)
 
amrex::Real interpolate_sfc_column (const amrex::Real &time, int col) const
 
void get_lsm_tsurf (const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
 
void update_pblh (const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars, amrex::MultiFab *z_phys_cc, const MoistureComponentIndices &moisture_indices)
 
void fill_pblh_from_coarser (const int &lev)
 
void inject_pblh_from_coarser (const int &lev, amrex::MultiFab &fine) const
 
template<typename PBLHeightEstimator >
void compute_pblh (const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars, amrex::MultiFab *z_phys_cc, const PBLHeightEstimator &est, const MoistureComponentIndices &moisture_indice)
 
void read_custom_roughness (const int &lev, const std::string &fname)
 
void update_surf_temp (const double &time)
 
void update_mac_ptrs (const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_old, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Theta_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qv_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qr_prim)
 
void define_surface_current (const int &lev, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel)
 
void fill_surface_current (const int &lev)
 
void define_relative_velocities (const int &lev, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, int k_top)
 
void build_relative_velocities (const int &lev, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel)
 
bool use_surface_current () const
 
const amrex::MultiFab * get_surface_current (const int &lev, int comp) const
 
amrex::MultiFab * get_u_star (const int &lev)
 
amrex::MultiFab * get_w_star (const int &lev)
 
bool computes_w_star () const
 
bool computes_pblh () const
 
amrex::MultiFab * get_t_star (const int &lev)
 
amrex::MultiFab * get_q_star (const int &lev)
 
amrex::MultiFab * get_olen (const int &lev)
 
const similarity_funs & similarity_functions () const
 
amrex::MultiFab * get_pblh (const int &lev)
 
const amrex::MultiFab * get_mac_avg (const int &lev, int comp)
 
bool mac_avg_is_time_averaged () const
 
int get_num_mac_avg () const
 
bool mac_avg_is_initialized (const int &lev) const
 
void set_mac_avg_initialized (const int &lev)
 
amrex::MultiFab * get_mac_avg_ptr (const int &lev, int comp)
 
amrex::Vector< amrex::Real > get_mac_plane_avg (const int &lev) const
 
bool set_mac_plane_avg (const int &lev, const amrex::Vector< amrex::Real > &pavg)
 
amrex::MultiFab * get_t_surf (const int &lev)
 
void set_skin_temperature (const int &lev, const amrex::MultiFab *t_skin)
 
std::string skin_temperature_conflict () const
 
void set_skin_moisture (const int &lev, const amrex::MultiFab *moisture, bool use_resistances=false, amrex::Real hs=amrex::Real(0))
 
std::string skin_moisture_conflict () const
 
bool set_default_roughness (amrex::Real z0)
 
amrex::Real roughness () const
 
bool use_sfc_fluxes () const
 
bool rotates_surface_fluxes () const
 
void set_t_surf (const int &lev, const amrex::Real tsurf)
 
amrex::MultiFab * get_q_surf (const int &lev)
 
void set_q_surf (const int &lev, const amrex::Real qsurf)
 
amrex::MultiFab * get_surface_diagnostic_source (const int &lev)
 
amrex::MultiFab * get_zref (const int &lev)
 
amrex::Real get_zref_min (const int &lev)
 
amrex::MultiFab * get_z0 (const int &lev)
 
const amrex::MultiFab * get_z0 (const int &lev) const
 
bool have_variable_sea_roughness () const
 
amrex::iMultiFab * get_lmask (const int &lev)
 
int lmask_min_reduce (amrex::iMultiFab &lmask, const int &nghost)
 
void update_sst_ptr (const int lev, const int itime, amrex::MultiFab *sst_ptr)
 
void update_tsk_ptr (const int lev, const int itime, amrex::MultiFab *tsk_ptr)
 
void update_coupled_sst_ptr (const int lev, amrex::MultiFab *sst_ptr, amrex::iMultiFab *valid_ptr)
 
void set_coupled_sst_active (const bool active)
 
void set_coupled_current_active (const bool active)
 
void update_coupled_surface_current (const int &lev, const amrex::MultiFab &east, const amrex::MultiFab &north, const amrex::iMultiFab *covered, const amrex::MultiFab *cos_alpha, const amrex::MultiFab *sin_alpha)
 
void set_surface_layer_faces (const amrex::GpuArray< int, AMREX_SPACEDIM *2 > &active_faces)
 
void fill_lateral_surface_parameter_ghosts (const int &lev, amrex::MultiFab *selected_field=nullptr)
 
template<typename FluxIter >
void compute_fluxes (const int &lev, const int &max_iters, MultiFab &, const FluxIter &most_flux, bool is_land)
 
template<typename FluxCalc >
void compute_SurfaceLayer_bcs (const int &lev, Vector< const MultiFab * > mfs, Vector< std::unique_ptr< MultiFab >> &Tau_lev, MultiFab *xheat_flux, MultiFab *yheat_flux, MultiFab *zheat_flux, MultiFab *xqv_flux, MultiFab *yqv_flux, MultiFab *zqv_flux, const MultiFab *z_phys, const FluxCalc &flux_comp, MultiFab *mf_surface_fluxes)
 
template<typename FluxCalc >
void compute_SurfaceLayer_bcs_EB (const int &lev, Vector< const MultiFab * > mfs, Vector< Vector< std::unique_ptr< MultiFab >>> &Tau_EB, [[maybe_unused]] MultiFab *xheat_flux, [[maybe_unused]] MultiFab *yheat_flux, MultiFab *Hfx3_EB, [[maybe_unused]] MultiFab *xqv_flux, [[maybe_unused]] MultiFab *yqv_flux, [[maybe_unused]] MultiFab *zqv_flux, const FluxCalc &flux_comp)
 
template<typename PBLHeightEstimator >
void compute_pblh (const int &lev, Vector< Vector< MultiFab >> &vars, MultiFab *z_phys_cc, const PBLHeightEstimator &est, const MoistureComponentIndices &moisture_indices)
 

Static Public Member Functions

static amrex::Vector< amrex::Vector< amrex::Real > > read_cols (const std::string &fname, const int skip_nlines=1)
 

Public Attributes

FluxCalcType flux_type {FluxCalcType::MOENG}
 
ThetaCalcType theta_type {ThetaCalcType::ADIABATIC}
 
MoistCalcType moist_type {MoistCalcType::ADIABATIC}
 
RoughCalcType rough_type_land {RoughCalcType::CONSTANT}
 
RoughCalcType rough_type_sea {RoughCalcType::CHARNOCK}
 
PBLHeightCalcType pblh_type {PBLHeightCalcType::None}
 
similarity_funs m_sfuns
 stable-side similarity functions (most.stable_functions) More...
 

Private Member Functions

void define_pblh_columns (const int &lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
 

Private Attributes

amrex::Orientation m_face
 
std::string m_pp_prefix
 
amrex::Vector< amrex::Geometry > m_geom
 
amrex::Gpu::DeviceScalar< erf_surface_temperature::ConversionFailure > m_surface_conversion_failure {erf_surface_temperature::ConversionFailure{}}
 
bool m_rotate = false
 
amrex::GpuArray< int, AMREX_SPACEDIM *2 > m_surface_layer_faces {}
 
double m_start_low_time
 
double m_final_low_time
 
double m_low_time_interval
 
bool m_include_wstar = false
 
amrex::Real z0_const {amrex::Real(0.1)}
 
bool m_z0_given {false}
 
amrex::Real default_land_surf_temp {amrex::Real(300.)}
 
amrex::Real surf_temp {amrex::Real(-1.)}
 
bool surf_temp_is_absolute {false}
 
amrex::Real surf_heating_rate {0}
 
amrex::Real surf_temp_flux {0}
 
amrex::Real default_land_surf_moist {zero}
 
amrex::Real surf_moist {amrex::Real(-1.)}
 
amrex::Real surf_moist_flux {0}
 
amrex::Real custom_ustar {0}
 
amrex::Real custom_tstar {0}
 
amrex::Real custom_qstar {0}
 
amrex::Real custom_rhosurf {0}
 
bool specified_rho_surf {false}
 
amrex::Real cnk_a {amrex::Real(0.0185)}
 
bool smooth_flow_visc {true}
 
amrex::Real depth {amrex::Real(30.0)}
 
amrex::Vector< amrex::MultiFab > z_0
 
bool m_var_z0 {false}
 
amrex::Real rico_theta_z0 {amrex::Real(298.0)}
 
amrex::Real rico_qsat_z0 {amrex::Real(0.001)}
 
bool use_moisture
 
bool m_has_lsm_fluxes = false
 
bool m_has_lsm_tsurf = false
 
int m_lsm_tsurf_indx = -1
 
bool m_lsm_tsurf_is_theta = false
 
bool m_use_lsm_skin_temperature = false
 
bool m_use_sfc_fluxes = false
 
bool m_use_sfc_sst = false
 
int sfc_time_ind = 0
 
amrex::Vector< amrex::Vector< amrex::Real > > sfc
 
amrex::Real sfc_qflux = zero
 
amrex::Real sfc_tflux = zero
 
amrex::Real sfc_ustar = zero
 
bool m_use_coupled_sst = false
 
amrex::Real m_Cd = zero
 
amrex::Real m_Ch = zero
 
amrex::Real m_Cq = zero
 
bool m_bulk_use_fixed_tflux = false
 
amrex::Real m_bulk_fixed_tflux = zero
 
bool m_ignore_sst = false
 
amrex::Vector< const eb_ * > m_eb_vec
 
TerrainType m_terrain_type
 
bool m_has_immersed_buildings = false
 
amrex::Real m_rdOcp = RdoCp
 
MOSTAverage m_ma
 
SurfaceModel * m_surf_model = nullptr
 
bool use_surface_model = false
 
bool surf_model_fluxes = false
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > w_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > olen
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > pblh
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_surf
 
amrex::Vector< PlanarBoundary > m_planar_bndry
 
amrex::Vector< amrex::iMultiFab > m_lsm_held_columns
 
amrex::Vector< PBLHColumns > m_pblh_columns
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > surface_diagnostic_source
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_sst_lev
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_tsk_lev
 
amrex::Vector< amrex::Vector< amrex::iMultiFab * > > m_lmask_lev
 
amrex::Vector< amrex::MultiFab * > m_coupled_sst_lev
 
amrex::Vector< amrex::iMultiFab * > m_coupled_sst_valid_lev
 
bool m_use_surface_current = false
 
bool m_coupled_current_active = false
 
amrex::Real m_surface_current_const [2] = {zero, zero}
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_surface_current_x
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_surface_current_y
 
amrex::Vector< const amrex::MultiFab * > m_coupled_current_east_lev
 
amrex::Vector< const amrex::MultiFab * > m_coupled_current_north_lev
 
amrex::Vector< const amrex::iMultiFab * > m_coupled_current_covered_lev
 
amrex::Vector< const amrex::MultiFab * > m_coupled_current_cos_lev
 
amrex::Vector< const amrex::MultiFab * > m_coupled_current_sin_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_coupled_rotation_lev
 
amrex::Vector< const amrex::MultiFab * > m_coupled_rotation_src_lev
 
amrex::Vector< amrex::BoxArray > m_coupled_rotation_src_ba_lev
 
amrex::Vector< amrex::DistributionMapping > m_coupled_rotation_src_dm_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rel_xvel
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rel_yvel
 
amrex::Vector< int > m_rel_k_top
 
amrex::Vector< amrex::BoxArray > m_rel_src_ba
 
amrex::Vector< const amrex::MultiFab * > m_skin_tsurf_lev
 
amrex::Vector< const amrex::MultiFab * > m_skin_moisture_lev
 
amrex::Vector< int > m_skin_moisture_resistances_lev
 
amrex::Vector< amrex::Real > m_skin_moisture_hs_lev
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_data_lev
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_flux_lev
 
amrex::Vector< std::string > m_lsm_data_name
 
amrex::Vector< std::string > m_lsm_flux_name
 
amrex::Vector< amrex::MultiFab * > m_Hwave_lev
 
amrex::Vector< amrex::MultiFab * > m_Lwave_lev
 
amrex::Vector< amrex::MultiFab * > m_eddyDiffs_lev
 
bool m_update_k_rans = false
 
bool m_k_moist_buoyancy = false
 
amrex::Real inv_Cmu2 = zero
 
amrex::Real theta_ref = zero
 

Detailed Description

Abstraction layer for different surface layer schemes (e.g. MOST, Cd)

van der Laan, P., Kelly, M. C., & Sørensen, N. N. (2017). A new k-epsilon model consistent with Monin-Obukhov similarity theory. Wind Energy, 20(3), 479–amrex::Real(489.) https://doi.org/amrex::Real(10.1002)/we.2017

Consistent with Dyer (1974) formulation from page 57, Chapter 2, Modeling the vertical ABL structure in Modeling of Atmospheric Flow Fields, Demetri P Lalas and Corrado F Ratto, January 1996, https://doi.org/amrex::Real(10.1142)/amrex::Real(2975.)

Member Enumeration Documentation

◆ FluxCalcType

Enumerator
MOENG 

Moeng functional form.

CUSTOM 

Custom constant flux functional form.

BULK_COEFF 

Bulk transfer coefficient functional form.

ROTATE 

Terrain rotation flux functional form.

RICO 
2105  {
2106  MOENG = 0, ///< Moeng functional form
2107  CUSTOM, ///< Custom constant flux functional form
2108  BULK_COEFF, ///< Bulk transfer coefficient functional form
2109  ROTATE, ///< Terrain rotation flux functional form
2110  RICO
2111  };

◆ MoistCalcType

Enumerator
ADIABATIC 
MOISTURE_FLUX 

Qv-flux specified.

SURFACE_MOISTURE 

Surface Qv specified.

2119  {
2120  ADIABATIC = 0,
2121  MOISTURE_FLUX, ///< Qv-flux specified
2122  SURFACE_MOISTURE ///< Surface Qv specified
2123  };

◆ PBLHeightCalcType

Enumerator
None 
MYNN25 
YSU 
MRF 
2133 { None, MYNN25, YSU, MRF };
@ None
Definition: ERF_LSM_Types.H:6

◆ RoughCalcType

Enumerator
CONSTANT 

Constant z0.

CHARNOCK 
MODIFIED_CHARNOCK 
DONELAN 
WAVE_COUPLED 
2125  {
2126  CONSTANT = 0, ///< Constant z0
2127  CHARNOCK,
2128  MODIFIED_CHARNOCK,
2129  DONELAN,
2130  WAVE_COUPLED
2131  };

◆ ThetaCalcType

Enumerator
ADIABATIC 
HEAT_FLUX 

Heat-flux specified.

SURFACE_TEMPERATURE 

Surface temperature specified.

2113  {
2114  ADIABATIC = 0,
2115  HEAT_FLUX, ///< Heat-flux specified
2116  SURFACE_TEMPERATURE ///< Surface temperature specified
2117  };

Constructor & Destructor Documentation

◆ SurfaceLayer()

SurfaceLayer::SurfaceLayer ( amrex::Orientation  face,
const amrex::Vector< amrex::Geometry > &  geom,
bool &  use_rot_surface_flux,
std::string  a_pp_prefix,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  Qv_prim,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  z_phys_nd,
const amrex::Vector< amrex::Vector< amrex::Real >> &  zlevels_stag,
const MeshType &  a_mesh_type,
const TerrainType &  a_terrain_type,
const TurbChoice &  a_turb_choice,
amrex::Real  a_rdOcp,
double  start_low_time,
double  final_low_time,
double  low_time_interval = 0.0,
const amrex::Vector< const eb_ * > &  eb_vec = {},
SurfaceModel *  surf_model = nullptr,
bool  a_has_immersed_buildings = false 
)
inlineexplicit

Construct the surface-layer interface.

Parameters
[in]faceorientation of face (for wall geometries)
[in]geomgeometry for all AMR levels
[in,out]use_rot_surface_fluxwhether to use rotated surface fluxes
[in]a_pp_prefixParmParse prefix used by MOST averages
[in]Qv_primprimitive water-vapor fields by level
[in]z_phys_ndnodal physical-height fields by level
[in]zlevels_stagnominal staggered z levels by level
[in]a_mesh_typemesh type
[in]a_terrain_typeterrain representation
[in]a_turb_choiceturbulence-model options
[in]a_rdOcpconfigured Rd/cp exponent for T-theta conversions
[in]start_low_timefirst available low-boundary-data time
[in]final_low_timefinal available low-boundary-data time
[in]low_time_intervallow-boundary-data time interval
[in]eb_vecoptional embedded-boundary geometry data
[in]surf_modeloptional weighted surface-model interface
[in]a_has_immersed_buildingswhether building immersed forcing is configured
102  {},
103  SurfaceModel* surf_model = nullptr,
104  bool a_has_immersed_buildings = false)
105  : m_face(face),
106  m_pp_prefix(a_pp_prefix),
107  m_geom(geom),
108  m_rotate(use_rot_surface_flux),
109  m_start_low_time(start_low_time),
110  m_final_low_time(final_low_time),
111  m_low_time_interval(low_time_interval),
112  m_eb_vec(eb_vec),
113  m_terrain_type(a_terrain_type),
114  m_has_immersed_buildings(a_has_immersed_buildings),
115  m_rdOcp(a_rdOcp),
116  m_ma(face, geom, (z_phys_nd[0] != nullptr), a_pp_prefix, a_mesh_type, a_terrain_type,
117  zlevels_stag, eb_vec),
118  m_surf_model(surf_model)
119  {
120  // We have a moisture model if Qv_prim is a valid pointer
121  use_moisture = (Qv_prim[0].get());
122 
123  // Keep standalone SurfaceLayer instances compatible with the historical
124  // single-face behavior. ERF replaces this with the complete active-face
125  // set after constructing all SurfaceLayer objects.
126  m_surface_layer_faces[static_cast<int>(face)] = 1;
127 
128  // Get roughness
129  amrex::ParmParse pp(a_pp_prefix);
130  m_z0_given = pp.contains("most.z0");
131  pp.queryAdd("most.z0", z0_const);
132 
133  // Specify how to compute the flux
134  if (use_rot_surface_flux) {
136  } else {
137  std::string flux_string_in;
138  std::string flux_string{"moeng"};
139  auto read_flux = pp.queryAdd("surface_layer.flux_type", flux_string_in);
140  if (read_flux) {
141  flux_string = amrex::toLower(flux_string_in);
142  }
143  if (flux_string == "moeng") {
145  } else if (flux_string == "rico") {
147  } else if (flux_string == "bulk_coeff") {
149  } else if (flux_string == "custom") {
151  } else {
152  amrex::Abort("Undefined MOST flux type!");
153  }
154  }
155 
160  m_face.coordDir() == 2 && m_face.isLow(),
161  "BULK_COEFF, CUSTOM, and RICO surface-layer fluxes are supported only on the z-low face.");
162  }
163 
164  // Include w* to handle free convection (Beljaars 1995, QJRMS)
165  pp.queryAdd("most.include_wstar", m_include_wstar);
166 
167  std::string pblh_string_in;
168  std::string pblh_string{"none"};
169  auto read_pblh = pp.queryAdd("most.pblh_calc", pblh_string_in);
170  if (read_pblh) {
171  pblh_string = amrex::toLower(pblh_string_in);
172  }
173  if (pblh_string == "none") {
175  } else if (pblh_string == "mynn25") {
177  } else if (pblh_string == "mynnedmf") {
179  } else if (pblh_string == "ysu") {
181  } else if (pblh_string == "mrf") {
183  } else if (pblh_string == "ysunew") {
184  // The former YSUNew is now the only YSU; the name is still accepted
185  static bool warned_ysunew = false;
186  if (!warned_ysunew && amrex::ParallelDescriptor::IOProcessor()) {
187  amrex::Warning(m_pp_prefix + ".most.pblh_calc = YSUNew is deprecated; it is now YSU");
188  }
189  warned_ysunew = true;
191  } else {
192  amrex::Abort("Undefined PBLH calc type!");
193  }
194 
197  m_face.coordDir() == 2 && m_face.isLow(),
198  "MOST PBL-height calculation and wstar correction are supported only on the z-low face.");
199  }
200 
201  // The w* correction is computed from the PBL height, so it needs a scheme that
202  // actually diagnoses one. With pblh_calc = "none" the pblh MultiFab keeps the
203  // bogus_large_value it was initialized with and calc_wstar turns that into a
204  // convective velocity scale of ~1e50, which destroys the surface fluxes.
206  amrex::Abort("erf.most.include_wstar requires a PBL height: set "
207  "erf.most.pblh_calc to MYNN25 (or MYNNEDMF), or to YSU or MRF "
208  "with the same erf.pbl_type");
209  }
210 
211  if (m_surf_model) {
212  use_surface_model = true;
213  amrex::Print() << " Using fluxes from surface model!" << std::endl;
215  }
216 
217  // Get surface temperature, as a potential temperature (most.pot_surf_temp) or an
218  // absolute temperature (most.abs_surf_temp); most.surf_temp is the deprecated
219  // spelling of most.pot_surf_temp. These are read with query, not queryAdd, so
220  // that whether a key was given is the query return value: queryAdd would add a
221  // key that is absent, and these keys are also read by ERF_InputSoundingData.H and
222  // by the SurfaceLayer of every face, so the first reader would make the key look
223  // given to the rest. A key that is given must be positive; it is never ignored.
224  {
225  amrex::Real pot_st = amrex::Real(-1.);
226  amrex::Real abs_st = amrex::Real(-1.);
227  amrex::Real old_st = amrex::Real(-1.);
228  const bool has_pot = pp.query("most.pot_surf_temp", pot_st);
229  const bool has_abs = pp.query("most.abs_surf_temp", abs_st);
230  const bool has_old = pp.query("most.surf_temp", old_st);
231  if (int(has_pot) + int(has_abs) + int(has_old) > 1) {
232  amrex::Abort("Specify only one of most.pot_surf_temp, most.abs_surf_temp "
233  "and the deprecated most.surf_temp");
234  }
235  if ((has_pot && !(pot_st > amrex::Real(0))) ||
236  (has_abs && !(abs_st > amrex::Real(0))) ||
237  (has_old && !(old_st > amrex::Real(0)))) {
238  amrex::Abort("most.pot_surf_temp, most.abs_surf_temp and most.surf_temp "
239  "must be positive temperatures [K]");
240  }
241  if (has_old) {
242  amrex::Print() << "WARNING: most.surf_temp is deprecated and is read as a surface "
243  << "potential temperature; use most.pot_surf_temp (potential) or "
244  << "most.abs_surf_temp (absolute) instead" << std::endl;
245  pot_st = old_st;
246  }
247  if (has_abs) {
248  surf_temp = abs_st;
249  surf_temp_is_absolute = true;
250  } else {
251  surf_temp = pot_st;
252  }
253  }
254  const bool erf_st = (surf_temp > amrex::Real(0));
255  // With an absolute temperature this is only the placeholder until update_fluxes
256  // converts it with the surface pressure.
257  if (erf_st) { default_land_surf_temp = surf_temp; }
258 
259  if (surf_temp_is_absolute) {
261  m_face.coordDir() == 2 && m_face.isLow() && m_terrain_type != TerrainType::EB,
262  "most.abs_surf_temp is supported only on the z-low face without EB terrain");
265  "most.abs_surf_temp is not supported with custom or rico fluxes; "
266  "use most.pot_surf_temp");
267  }
268 
269  // Get surface moisture
270  bool erf_sq = false;
271  if (use_moisture) {
272  pp.queryAdd("most.surf_moist", surf_moist);
273  erf_sq = (surf_moist >= amrex::Real(0));
274  }
275  if (erf_sq) { default_land_surf_moist = surf_moist; }
276 
277  // Custom type user must specify the fluxes
282  pp.get("most.ustar", custom_ustar);
283  pp.get("most.tstar", custom_tstar);
284  pp.get("most.qstar", custom_qstar);
285  pp.queryAdd("most.rhosurf", custom_rhosurf);
286  if (custom_qstar != 0) {
288  "Specified custom MOST qv flux without moisture model!");
289  }
290  amrex::Print() << "Using specified ustar, tstar, qstar for MOST = "
291  << custom_ustar << " " << custom_tstar << " "
292  << custom_qstar << std::endl;
293 
294  // Bulk transfer coefficient (must specify coeffs and surface values)
295  } else if (flux_type == FluxCalcType::BULK_COEFF) {
296  // Optional imposed kinematic heat flux <theta'w'> [K m/s], positive upward (the
297  // sign of most.surf_temp_flux for the other flux types). It replaces Ch * |U| *
298  // (theta_surf - theta): a constant drag with a fixed heat flux, as WRF's
299  // isfflx = 0 with tke_drag_coefficient and tke_heat_flux.
300  m_bulk_use_fixed_tflux = (pp.query("most.surf_temp_flux", m_bulk_fixed_tflux) != 0);
301  pp.get("most.Cd", m_Cd);
303  if (!std::isfinite(m_bulk_fixed_tflux)) {
304  amrex::Abort("erf.most.surf_temp_flux must be a finite number");
305  }
306  // the bulk_coeff branch never reads a surface heating rate: stop rather than
307  // run with it silently unused (the doc row of surf_temp_flux forbids the pair)
308  if (pp.contains("most.surf_heating_rate")) {
309  amrex::Abort("erf.most.surf_temp_flux with surface_layer.flux_type = bulk_coeff "
310  "imposes the surface heat flux; it may not be combined with "
311  "erf.most.surf_heating_rate");
312  }
313  // Ch is optional here: the heat flux does not use it
314  if (pp.query("most.Ch", m_Ch)) {
315  amrex::Print() << "WARNING: erf.most.Ch is not used: erf.most.surf_temp_flux "
316  << "imposes the bulk_coeff heat flux" << std::endl;
317  }
318  } else {
319  pp.get("most.Ch", m_Ch);
320  }
321  pp.get("most.Cq", m_Cq);
323  "bulk_coeff fluxes need most.pot_surf_temp or most.abs_surf_temp");
325  pp.get("most.surf_moist", default_land_surf_moist);
327  amrex::Print() << "Using specified Cd, Cq for MOST = " << m_Cd << " " << m_Cq
328  << " with an imposed surface heat flux most.surf_temp_flux = "
329  << m_bulk_fixed_tflux << " K m/s" << std::endl;
330  } else {
331  amrex::Print() << "Using specified Cd, Ch, Cq for MOST = "
332  << m_Cd << " " << m_Ch << " "
333  << m_Cq << std::endl;
334  }
335 
336  // Specify surface temperature/moisture or surface flux
337  } else {
338  if (erf_st) {
340  pp.queryAdd("most.surf_heating_rate", surf_heating_rate); // [K/h]
341 
342  // Modify rate to be in units of K / s rather than K / hr
343  surf_heating_rate /= amrex::Real(3600.0); // [K/s]
344 
345  if (pp.query("most.surf_temp_flux", surf_temp_flux)) {
346  amrex::Abort("Can only specify one of surf_temp_flux or surf_heating_rate");
347  }
348  } else {
349  pp.queryAdd("most.surf_temp_flux", surf_temp_flux);
350 
351  if (pp.query("most.surf_heating_rate", surf_heating_rate)) {
352  amrex::Abort("Can only specify one of surf_temp_flux or surf_heating_rate");
353  }
354  if (std::abs(surf_temp_flux) >
357  } else {
359  }
360  }
361 
362  if (erf_sq) {
364  } else {
365  pp.queryAdd("most.surf_moist_flux", surf_moist_flux);
366  if (std::abs(surf_moist_flux) >
369  } else {
371  }
372  }
373  }
374 
379  m_face.coordDir() == 2 && m_face.isLow(),
380  "HEAT_FLUX and ADIABATIC surface-layer fluxes are supported only on the z-low face.");
381  }
382 
384  {
385  pp.queryAdd("most.rico.theta_z0", rico_theta_z0);
386  pp.queryAdd("most.rico.qsat_z0", rico_qsat_z0);
387  }
388 
389  // Make sure the inputs file doesn't try to use most.roughness_type
390  std::string bogus_input;
391  if (pp.queryAdd("most.roughness_type", bogus_input) > 0) {
392  amrex::Abort("most.roughness_type is deprecated; use "
393  "most.roughness_type_land and/or most.roughness_type_sea");
394  }
395 
396  // Specify how to compute the surface flux over land (if there is any)
397  std::string rough_land_string_in;
398  std::string rough_land_string{"constant"};
399  auto read_rough_land =
400  pp.queryAdd("most.roughness_type_land", rough_land_string_in);
401  if (read_rough_land) {
402  rough_land_string = amrex::toLower(rough_land_string_in);
403  }
404  if (rough_land_string == "constant") {
406  } else {
407  amrex::Abort("Undefined MOST roughness type for land!");
408  }
409 
410  // Allow for smooth-flow limit?
411  pp.queryAdd("most.smooth_flow_viscosity", smooth_flow_visc);
412  amrex::Print() << "The smooth-flow limit will be included for variable roughness models over sea: " << smooth_flow_visc << "\n";
413 
414  // Specify how to compute the surface flux over sea (if there is any)
415  std::string rough_sea_string_in;
416  std::string rough_sea_string{"charnock"};
417  auto read_rough_sea = pp.queryAdd("most.roughness_type_sea", rough_sea_string_in);
418  if (read_rough_sea) {
419  rough_sea_string = amrex::toLower(rough_sea_string_in);
420  }
421  if (rough_sea_string == "charnock") {
423  pp.queryAdd("most.charnock_constant", cnk_a);
424  if (cnk_a > 0) {
425  amrex::Print() << "If there is water, Charnock relation with C_a="
426  << cnk_a << " will be used" << std::endl;
427  } else {
428  amrex::Print() << "If there is water, Charnock relation with variable "
429  "Charnock parameter (COARE3.0) will be used" << std::endl;
430  }
431  } else if (rough_sea_string == "coare3.0") {
433  amrex::Print() << "If there is water, Charnock relation with variable "
434  "Charnock parameter (COARE3.0) will be used" << std::endl;
435  cnk_a = -1;
436  } else if (rough_sea_string == "donelan") {
438  } else if (rough_sea_string == "modified_charnock") {
440  pp.queryAdd("most.modified_charnock_depth", depth);
441  if (depth < amrex::Real(10.0) || depth > amrex::Real(100.0) ) {
442  amrex::Print() << "Specified depth of " << depth
443  << " is outside the valid range of [10 100], resetting to bounds now."
444  << std::endl;
445  }
446  // Limiter based upon the fit range in Jiménez & Dudhia
447  depth = amrex::min(amrex::max(depth,amrex::Real(10.0)),amrex::Real(100.0));
448  } else if (rough_sea_string == "wave_coupled") {
450  } else if (rough_sea_string == "constant") {
452  } else {
453  amrex::Abort("Undefined MOST roughness type for sea!");
454  }
455 
456  // use skin temperature instead of sea-surface temperature
457  // (wrfinput data may have lower resolution SST data)
458  pp.queryAdd("most.ignore_sst", m_ignore_sst);
459 
460  // A uniform current of the water surface [m/s, along grid x and y]. The surface
461  // layer then takes the wind relative to the surface, as over an ocean current.
462  if (m_face.coordDir() == 2 && m_face.isLow()) {
463  amrex::Vector<amrex::Real> current;
464  if (pp.queryarr("most.surface_current", current)) {
465  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(current.size() == 2,
466  "most.surface_current takes two components, along x and y.");
468  "most.surface_current is not supported with EB terrain.");
469  m_use_surface_current = true;
470  m_surface_current_const[0] = current[0];
471  m_surface_current_const[1] = current[1];
472  }
473  }
474 
475  // If we're using the RANS k model, then we need to update the dirichlet
476  // wall value of k (written into the first cell above the wall and held
477  // there through the step) based on the instantaneous u* and θ*; the turbulence modeling
478  // choices can vary per level but for now, assume that if specified then
479  // all levels are using the same RANS model.
480  m_update_k_rans = (a_turb_choice.rans_type == RANSType::kEqn &&
481  a_turb_choice.dirichlet_k == true);
482  if (m_update_k_rans) {
484  m_face.coordDir() == 2 && m_face.isLow(),
485  "RANS surface-layer k updates are supported only on the z-low face.");
486  }
487  if (m_update_k_rans) {
488  inv_Cmu2 = one / (a_turb_choice.Cmu0 * a_turb_choice.Cmu0);
489  theta_ref = a_turb_choice.theta_ref;
490  // with the moist TKE buoyancy (erf.rans_moist_buoyancy) the wall value's buoyancy flux
491  // is the virtual one, -u* theta_v* with theta_v* = theta* (1 + epsv qv) + epsv theta q*
493  }
494 
495  // Stable-side similarity functions (most.stable_functions): Businger-Dyer, or QNSE for
496  // the prescribed-flux kernels and their companions; see check_similarity_funs_use
499 
500  } // constructor
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
ParmParse pp("prob")
similarity_funs read_most_similarity_funs(amrex::ParmParse &pp, const std::string &who="Surface layer")
Definition: ERF_MOSTUtils.H:379
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
AMREX_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
bool m_has_immersed_buildings
Definition: ERF_SurfaceLayer.H:2223
ThetaCalcType theta_type
Definition: ERF_SurfaceLayer.H:2136
bool m_include_wstar
Definition: ERF_SurfaceLayer.H:2158
bool m_rotate
Definition: ERF_SurfaceLayer.H:2152
PBLHeightCalcType pblh_type
Definition: ERF_SurfaceLayer.H:2140
double m_final_low_time
Definition: ERF_SurfaceLayer.H:2155
bool use_moisture
Definition: ERF_SurfaceLayer.H:2192
amrex::Real m_Cq
Definition: ERF_SurfaceLayer.H:2215
amrex::Vector< const eb_ * > m_eb_vec
Definition: ERF_SurfaceLayer.H:2221
RoughCalcType rough_type_land
Definition: ERF_SurfaceLayer.H:2138
SurfaceModel * m_surf_model
Definition: ERF_SurfaceLayer.H:2226
amrex::Real z0_const
Definition: ERF_SurfaceLayer.H:2159
amrex::Real cnk_a
Definition: ERF_SurfaceLayer.H:2183
amrex::Real m_Ch
Definition: ERF_SurfaceLayer.H:2214
amrex::Real surf_temp
Definition: ERF_SurfaceLayer.H:2169
double m_start_low_time
Definition: ERF_SurfaceLayer.H:2154
amrex::Real m_surface_current_const[2]
Definition: ERF_SurfaceLayer.H:2295
amrex::Real rico_qsat_z0
Definition: ERF_SurfaceLayer.H:2190
bool surf_temp_is_absolute
Definition: ERF_SurfaceLayer.H:2172
bool m_update_k_rans
Definition: ERF_SurfaceLayer.H:2332
void check_similarity_funs_use() const
Definition: ERF_SurfaceLayer.H:512
amrex::Real surf_moist_flux
Definition: ERF_SurfaceLayer.H:2177
bool smooth_flow_visc
Definition: ERF_SurfaceLayer.H:2184
bool m_bulk_use_fixed_tflux
Definition: ERF_SurfaceLayer.H:2217
RoughCalcType rough_type_sea
Definition: ERF_SurfaceLayer.H:2139
std::string m_pp_prefix
Definition: ERF_SurfaceLayer.H:2146
amrex::Real surf_moist
Definition: ERF_SurfaceLayer.H:2176
similarity_funs m_sfuns
stable-side similarity functions (most.stable_functions)
Definition: ERF_SurfaceLayer.H:2141
bool m_ignore_sst
Definition: ERF_SurfaceLayer.H:2219
double m_low_time_interval
Definition: ERF_SurfaceLayer.H:2156
amrex::GpuArray< int, AMREX_SPACEDIM *2 > m_surface_layer_faces
Definition: ERF_SurfaceLayer.H:2153
amrex::Real custom_qstar
Definition: ERF_SurfaceLayer.H:2180
bool surf_model_fluxes
Definition: ERF_SurfaceLayer.H:2228
amrex::Real custom_rhosurf
Definition: ERF_SurfaceLayer.H:2181
bool m_use_surface_current
Definition: ERF_SurfaceLayer.H:2292
@ MOENG
Moeng functional form.
@ BULK_COEFF
Bulk transfer coefficient functional form.
@ CUSTOM
Custom constant flux functional form.
@ ROTATE
Terrain rotation flux functional form.
amrex::Real m_rdOcp
Definition: ERF_SurfaceLayer.H:2224
@ SURFACE_MOISTURE
Surface Qv specified.
@ MOISTURE_FLUX
Qv-flux specified.
amrex::Real depth
Definition: ERF_SurfaceLayer.H:2185
amrex::Real default_land_surf_moist
Definition: ERF_SurfaceLayer.H:2175
bool m_z0_given
Definition: ERF_SurfaceLayer.H:2161
bool use_surface_model
Definition: ERF_SurfaceLayer.H:2227
amrex::Real rico_theta_z0
Definition: ERF_SurfaceLayer.H:2189
amrex::Real surf_temp_flux
Definition: ERF_SurfaceLayer.H:2174
amrex::Vector< amrex::Geometry > m_geom
Definition: ERF_SurfaceLayer.H:2147
amrex::Real theta_ref
Definition: ERF_SurfaceLayer.H:2335
amrex::Real custom_tstar
Definition: ERF_SurfaceLayer.H:2179
amrex::Real surf_heating_rate
Definition: ERF_SurfaceLayer.H:2173
FluxCalcType flux_type
Definition: ERF_SurfaceLayer.H:2135
MoistCalcType moist_type
Definition: ERF_SurfaceLayer.H:2137
amrex::Real m_bulk_fixed_tflux
Definition: ERF_SurfaceLayer.H:2218
amrex::Real inv_Cmu2
Definition: ERF_SurfaceLayer.H:2334
amrex::Real custom_ustar
Definition: ERF_SurfaceLayer.H:2178
amrex::Orientation m_face
Definition: ERF_SurfaceLayer.H:2145
amrex::Real m_Cd
Definition: ERF_SurfaceLayer.H:2213
amrex::Real default_land_surf_temp
Definition: ERF_SurfaceLayer.H:2162
bool m_k_moist_buoyancy
Definition: ERF_SurfaceLayer.H:2333
@ SURFACE_TEMPERATURE
Surface temperature specified.
@ HEAT_FLUX
Heat-flux specified.
TerrainType m_terrain_type
Definition: ERF_SurfaceLayer.H:2222
MOSTAverage m_ma
Definition: ERF_SurfaceLayer.H:2225
Interface between ERF and land-surface and urban models.
Definition: ERF_SurfaceModel.H:60
bool are_fluxes()
Returns whether the interface exports fluxes rather than MOST variables.
Definition: ERF_SurfaceModel.H:391
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
RANSType rans_type
Selected RANS closure.
Definition: ERF_TurbStruct.H:960
amrex::Real theta_ref
Reference potential temperature for stable stratification.
Definition: ERF_TurbStruct.H:947
bool rans_moist_buoyancy
Definition: ERF_TurbStruct.H:1000
bool dirichlet_k
Whether TKE uses Dirichlet boundary treatment.
Definition: ERF_TurbStruct.H:962
amrex::Real Cmu0
One-equation RANS Cmu0 coefficient.
Definition: ERF_TurbStruct.H:936

Member Function Documentation

◆ build_relative_velocities()

void SurfaceLayer::build_relative_velocities ( const int &  lev,
const amrex::MultiFab &  xvel,
const amrex::MultiFab &  yvel 
)

Fill the velocities relative to the surface current.

Parameters
[in]levlevel index
[in]xvelx-velocity on the level
[in]yvely-velocity on the level
436 {
438  m_rel_xvel[lev] && m_rel_src_ba[lev] == xvel.boxArray() &&
439  m_rel_xvel[lev]->DistributionMap() == xvel.DistributionMap(),
440  "The surface current was defined for another layout of this level's velocities.");
441 
442  // On a moving mesh the planes the averages read can rise
443  if (m_ma.max_k_read_can_change()) {
444  const int k_top = m_ma.max_k_read(lev);
445  if (k_top > m_rel_k_top[lev]) { define_relative_velocities(lev, xvel, yvel, k_top); }
446  }
447 
448  const int klo = m_geom[lev].Domain().smallEnd(2);
449 
450  // Each component less the current of the plane k = klo, over the planes held,
451  // ghost cells included
452  for (int dir = 0; dir < 2; ++dir) {
453  const MultiFab& vel = (dir == 0) ? xvel : yvel;
454  const MultiFab& current = (dir == 0) ? *m_surface_current_x[lev] : *m_surface_current_y[lev];
455  MultiFab& rel = (dir == 0) ? *m_rel_xvel[lev] : *m_rel_yvel[lev];
456 #ifdef _OPENMP
457 #pragma omp parallel if (Gpu::notInLaunchRegion())
458 #endif
459  for (MFIter mfi(rel, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
460  const auto v = vel.const_array(mfi);
461  const auto c = current.const_array(mfi);
462  const auto r = rel.array(mfi);
463  ParallelFor(mfi.growntilebox(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
464  {
465  r(i,j,k) = v(i,j,k) - c(i,j,klo);
466  });
467  }
468  }
469 }
const int klo
Definition: ERF_InitCustomPert_KE.H:9
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);})
bool max_k_read_can_change() const
Definition: ERF_MOSTAverage.H:670
int max_k_read(const int &lev) const
Definition: ERF_MOSTAverage.cpp:581
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_surface_current_x
Definition: ERF_SurfaceLayer.H:2296
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_surface_current_y
Definition: ERF_SurfaceLayer.H:2297
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rel_yvel
Definition: ERF_SurfaceLayer.H:2313
amrex::Vector< amrex::BoxArray > m_rel_src_ba
Definition: ERF_SurfaceLayer.H:2315
void define_relative_velocities(const int &lev, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, int k_top)
Definition: ERF_SurfaceLayer.cpp:415
amrex::Vector< int > m_rel_k_top
Definition: ERF_SurfaceLayer.H:2314
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rel_xvel
Definition: ERF_SurfaceLayer.H:2312
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233

Referenced by update_mac_ptrs().

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

◆ check_similarity_funs_use()

void SurfaceLayer::check_similarity_funs_use ( ) const
inline

Stop when most.stable_functions = qnse would be read by nothing on this face.

The choice selects the stable arm of the Businger-Dyer pair, which the prescribed-flux (moeng) kernels use, with their companions: the PBL surface gradients, the 2 m and 10 m diagnostics and the MYNN surface TKE production. The prescribed-temperature kernels use the Jimenez (2012) pair on both sides, the adiabatic kernels no stability function, and the custom, rico and bulk_coeff fluxes none at all. Called at construction and again where a surface file, SST/TSK data or a land model switch the flux or temperature mode.

513  {
514  if (!m_sfuns.uses_qnse()) { return; }
515  const std::string key = m_pp_prefix + ".most.stable_functions = qnse";
517  amrex::Abort(key + " needs the moeng flux type: the custom, rico and bulk_coeff fluxes "
518  "use no similarity functions");
519  }
521  amrex::Abort(key + " needs a prescribed heat flux (most.surf_temp_flux): the "
522  "prescribed-temperature kernels use the Jimenez (2012) functions on both "
523  "sides and the adiabatic kernels no stability function");
524  }
525  }
AMREX_GPU_HOST_DEVICE bool uses_qnse() const
Definition: ERF_MOSTUtils.H:334

Referenced by make_SurfaceLayer_at_level().

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

◆ compute_fluxes() [1/2]

template<typename FluxIter >
void SurfaceLayer::compute_fluxes ( const int &  lev,
const int &  max_iters,
amrex::MultiFab &  cons_in,
const FluxIter &  most_flux,
bool  is_land 
)

Compute MOST fluxes with a selected flux-iteration functor.

Parameters
[in]levlevel index
[in]max_itersmaximum MOST iteration count
[in,out]cons_inconserved state used by the flux computation
[in]most_fluxflux-iteration functor
[in]is_landwhether the land-surface branch is active

◆ compute_fluxes() [2/2]

template<typename FluxIter >
void SurfaceLayer::compute_fluxes ( const int &  lev,
const int &  max_iters,
MultiFab &  ,
const FluxIter &  most_flux,
bool  is_land 
)

Function to compute the fluxes (u^star and t^star) for Monin Obukhov similarity theory

Parameters
[in]levCurrent level
[in]max_itersMaximum iterations to use
[in]cons_inConserved state whose grids define the surface iteration
[in]most_fluxFlux-iteration functor used to compute ustar, tstar, qstar, and related fields
[in]is_landSelects whether land or sea cells are updated
1093 {
1094  // The kernel with this surface layer's similarity functions (most.stable_functions)
1095  FluxIter flux_iter = most_flux;
1096  flux_iter.set_similarity_funs(m_sfuns);
1097 
1098  // Pointers to the computed averages
1099  const auto *const tm_ptr = m_ma.get_average(lev,3); // potential temperature
1100  const auto *const qvm_ptr = m_ma.get_average(lev,4); // water vapor mixing ratio
1101  const auto *const tvm_ptr = m_ma.get_average(lev,5); // virtual potential temperature
1102  const auto *const umm_ptr = m_ma.get_average(lev,6); // horizontal velocity magnitude
1103  const auto *const uw_mag_mean = m_ma.get_average(lev,7); // x/z velocity magnitude
1104  const auto *const vw_mag_mean = m_ma.get_average(lev,8); // y/z velocity magnitude
1105  const auto *const zref_ptr = m_ma.get_zref(lev); // reference height
1106  const bool l_use_eb = (m_terrain_type == TerrainType::EB);
1107 
1108  const int dir = m_face.coordDir();
1109  // The source fields and Taus use the same BoxArray ordering and
1110  // DistributionMapping. Full-state fields follow cons_in, while the
1111  // collapsed SurfaceLayer/MOSTAverage fields follow u_star.
1112  int sm_index = 0;
1113  if (m_face.isLow()) {
1114  sm_index = m_geom[lev].Domain().smallEnd(dir);
1115  } else {
1116  sm_index = m_geom[lev].Domain().bigEnd(dir);
1117  }
1118 
1119  // Use the 2-D surface mask as the iterator so ranks participate only when
1120  // their grids coincide with the selected face.
1121  for (MFIter mfi(*m_lmask_lev[lev][0]); mfi.isValid(); ++mfi)
1122  {
1123  // Face ownership is a property of the full grid, not an individual
1124  // tile. Keep the tile box for the kernel below, but test the valid
1125  // box so all tiles of a face-owning grid are processed.
1126  Box vbx = mfi.validbox();
1127  const Box tbx = mfi.tilebox();
1128  Box gtbx = mfi.growntilebox();
1129 
1130  // Since lmask is used in the MFIter, its z extent is collapsed. The
1131  // lateral kernels need the full z column; z-face ownership is instead
1132  // determined from the original 3-D surface-copy mapping.
1133  if (dir != 2 || l_use_eb) {
1134  gtbx.setSmall(2, m_geom[lev].Domain().smallEnd(2));
1135  gtbx.setBig(2, m_geom[lev].Domain().bigEnd(2));
1136  }
1137 
1138  const bool owns_surface = l_use_eb || dir != 2 ||
1139  m_planar_bndry[lev].is_surface_copy(mfi.index());
1140  if (!owns_surface) {
1141  continue;
1142  }
1143 
1144  if (dir != 2) {
1145  if (m_face.isLow()) {
1146  if (vbx.smallEnd(dir) != sm_index ||
1147  tbx.smallEnd(dir) != sm_index) {
1148  continue;
1149  }
1150  } else {
1151  if (vbx.bigEnd(dir) != sm_index ||
1152  tbx.bigEnd(dir) != sm_index) {
1153  continue;
1154  }
1155  }
1156  }
1157 
1158  if (m_face.isLow()) {
1159  gtbx.setSmall(dir, sm_index);
1160  gtbx.setBig(dir, sm_index);
1161  } else {
1162  gtbx.setSmall(dir, sm_index);
1163  gtbx.setBig(dir, sm_index);
1164  }
1165 
1166  // X/Y faces still need the full valid z column
1167  if (!l_use_eb && dir == 2) {
1168  gtbx.makeSlab(2, sm_index);
1169  } else {
1170  gtbx.setBig(2, m_geom[lev].Domain().bigEnd(2));
1171  }
1172 
1173  // The mask iterator can have more lateral ghost cells than the
1174  // surface-layer fields, and an EB FAB may be decomposed in z. Keep
1175  // the face selection above, but never launch outside the target FAB.
1176  gtbx &= u_star[lev]->fabbox(mfi.index());
1177  if (gtbx.isEmpty()) { continue; }
1178 
1179  // Land columns with a valid LSM flux are skipped here and filled instead by
1180  // compute_sfc_params_from_lsm_fluxes. The decision for a ghost column is made from
1181  // the nearest valid column, as that routine makes it; fill_planar_boundary then
1182  // replaces the interior and periodic ghosts with the owning grid's values. (The
1183  // face stresses in compute_SurfaceLayer_bcs read one lateral ghost of the fluxes
1184  // where a grid of the level holds it, and the nearest column elsewhere.)
1185  // Both take the fluxes from get_lsm_flux_view and test them with
1186  // SurfaceFluxView::valid, so a column with lmask == 1 gets exactly one of the two.
1187  // (compute_sfc_params_from_lsm_fluxes also treats a missing lmask as land.)
1188  // Every field written here on the grown box must be refilled at the end of update_fluxes.
1189  const NearestColumn col(vbx);
1190 
1191  auto u_star_arr = u_star[lev]->array(mfi);
1192  auto t_star_arr = t_star[lev]->array(mfi);
1193  auto q_star_arr = q_star[lev]->array(mfi);
1194  auto t_surf_arr = t_surf[lev]->array(mfi);
1195  auto q_surf_arr = q_surf[lev]->array(mfi);
1196  auto olen_arr = olen[lev]->array(mfi);
1197 
1198  const auto tm_arr = tm_ptr->array(mfi);
1199  const auto tvm_arr = tvm_ptr->array(mfi);
1200  const auto qvm_arr = qvm_ptr->array(mfi);
1201  const auto umm_arr = umm_ptr->array(mfi);
1202  const auto vwmm_arr = (dir == 0) ? vw_mag_mean->array(mfi) : Array4<Real>{};
1203  const auto uwmm_arr = (dir == 1) ? uw_mag_mean->array(mfi) : Array4<Real>{};
1204  const auto zref_arr = zref_ptr->array(mfi);
1205 
1206  // umm depending on face direction (YZ, XZ, XY)
1207  const auto dir_umm_arr = ((dir == 0) ? vwmm_arr : ((dir == 1) ? uwmm_arr : umm_arr));
1208  const auto z0_arr = z_0[lev].array(mfi);
1209 
1210  // PBL height if we need to calculate wstar for the Beljaars correction
1211  // TODO: can/should we apply this in LES mode?
1212  const auto w_star_arr = (m_include_wstar) ? w_star[lev].get()->array(mfi) : Array4<Real> {};
1213  const auto pblh_arr = (m_include_wstar) ? pblh[lev].get()->array(mfi) : Array4<Real> {};
1214 
1215  // Wave properties if they exist
1216  const auto Hwave_arr = (m_Hwave_lev[lev]) ? m_Hwave_lev[lev]->array(mfi) : Array4<Real> {};
1217  const auto Lwave_arr = (m_Lwave_lev[lev]) ? m_Lwave_lev[lev]->array(mfi) : Array4<Real> {};
1218  const auto eta_arr = (m_eddyDiffs_lev[lev]) ? m_eddyDiffs_lev[lev]->array(mfi) : Array4<Real> {};
1219 
1220  // Land mask array if it exists
1221  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
1222  Array4<int> {};
1223 
1224  // Get EB flags if needed
1225  const auto flag_arr = (l_use_eb) ? m_eb_vec[lev]->get_const_factory()->getMultiEBCellFlagFab()[mfi].const_array() : Array4<const EBCellFlag>{};
1226 
1227  // Get LSM flux arrays (z-low face only; the other faces never use them)
1228  const bool use_lsm_fluxes = is_land && m_has_lsm_fluxes &&
1229  dir == 2 && m_face.isLow();
1230  const SurfaceFluxView lsm_flux = (use_lsm_fluxes) ? get_lsm_flux_view(lev, mfi)
1231  : SurfaceFluxView{};
1232 
1233  if (!l_use_eb) {
1234  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1235  {
1236  // always check for land mask at k=0 even if on other faces
1237  const bool iterate_land = ( is_land && lmask_arr(i,j,0) == 1 &&
1238  !(use_lsm_fluxes && lsm_flux.valid(col.i(i), col.j(j))) );
1239  const bool iterate_sea = (!is_land && lmask_arr(i,j,0) == 0 );
1240  if (iterate_land || iterate_sea)
1241  {
1242  // NOTE: All 2D MFs so k index is always 0 from ba2d definition
1243  flux_iter.iterate_flux(i, j, k, max_iters,
1244  zref_arr, // set in most average
1245  z0_arr, // updated if(!is_land)
1246  dir_umm_arr, tm_arr, tvm_arr, qvm_arr,
1247  u_star_arr, // updated
1248  w_star_arr, // updated if(m_include_wstar)
1249  t_star_arr, q_star_arr, // updated
1250  t_surf_arr, q_surf_arr, olen_arr, // updated
1251  pblh_arr, // updated if(m_include_wstar)
1252  Hwave_arr, Lwave_arr, eta_arr);
1253  }
1254  });
1255  // EB
1256  } else {
1257  if (std::is_same<FluxIter, adiabatic_eb>::value ||
1258  std::is_same<FluxIter, surface_temp_eb>::value ||
1259  std::is_same<FluxIter, surface_flux_eb>::value) {
1260  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1261  {
1262  const bool iterate_land = ( is_land && lmask_arr(i,j,0) == 1 &&
1263  !(use_lsm_fluxes && lsm_flux.valid(col.i(i), col.j(j))) );
1264  const bool iterate_sea = (!is_land && lmask_arr(i,j,0) == 0 );
1265  if (iterate_land || iterate_sea)
1266  {
1267  if (flag_arr(i,j,k).isSingleValued()) {
1268  flux_iter.iterate_flux(i, j, k, max_iters,
1269  zref_arr, // set in most average
1270  z0_arr, // updated if(!is_land)
1271  umm_arr, tm_arr, tvm_arr, qvm_arr,
1272  u_star_arr, // updated
1273  w_star_arr, // updated if(m_include_wstar)
1274  t_star_arr, q_star_arr, // updated
1275  t_surf_arr, q_surf_arr, olen_arr, // updated
1276  pblh_arr, // updated if(m_include_wstar)
1277  Hwave_arr, Lwave_arr, eta_arr);
1278  }
1279  }
1280  });
1281  } else {
1282  amrex::Abort("FluxIter type not supported for EB");
1283  }
1284  }
1285  }
1286 }
pp_for_pert_vels get("prob_type", prob_type)
amrex::MultiFab * get_zref(const int &lev) const
Definition: ERF_MOSTAverage.H:350
const amrex::MultiFab * get_average(const int &lev, const int &comp) const
Definition: ERF_MOSTAverage.H:272
amrex::Vector< amrex::Vector< amrex::iMultiFab * > > m_lmask_lev
Definition: ERF_SurfaceLayer.H:2275
amrex::Vector< PlanarBoundary > m_planar_bndry
Definition: ERF_SurfaceLayer.H:2241
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
Definition: ERF_SurfaceLayer.H:2235
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_star
Definition: ERF_SurfaceLayer.H:2232
bool m_has_lsm_fluxes
Definition: ERF_SurfaceLayer.H:2193
amrex::Vector< amrex::MultiFab * > m_Lwave_lev
Definition: ERF_SurfaceLayer.H:2329
amrex::Vector< amrex::MultiFab > z_0
Definition: ERF_SurfaceLayer.H:2186
amrex::Vector< std::unique_ptr< amrex::MultiFab > > w_star
Definition: ERF_SurfaceLayer.H:2230
SurfaceFluxView get_lsm_flux_view(const int &lev, const amrex::MFIter &mfi) const
Definition: ERF_SurfaceLayer.cpp:2368
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
Definition: ERF_SurfaceLayer.H:2229
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_surf
Definition: ERF_SurfaceLayer.H:2236
amrex::Vector< amrex::MultiFab * > m_Hwave_lev
Definition: ERF_SurfaceLayer.H:2328
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
Definition: ERF_SurfaceLayer.H:2231
amrex::Vector< amrex::MultiFab * > m_eddyDiffs_lev
Definition: ERF_SurfaceLayer.H:2330
amrex::Vector< std::unique_ptr< amrex::MultiFab > > olen
Definition: ERF_SurfaceLayer.H:2233
amrex::Vector< std::unique_ptr< amrex::MultiFab > > pblh
Definition: ERF_SurfaceLayer.H:2234
Non-owning views of surface fluxes for one tile.
Definition: ERF_SurfaceModel.H:24
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid(int i, int j) const noexcept
Definition: ERF_SurfaceModel.H:32
Definition: ERF_SurfaceLayer.cpp:32
Here is the call graph for this function:

◆ compute_pblh() [1/2]

template<typename PBLHeightEstimator >
void SurfaceLayer::compute_pblh ( const int &  lev,
amrex::Vector< amrex::Vector< amrex::MultiFab >> &  vars,
amrex::MultiFab *  z_phys_cc,
const PBLHeightEstimator &  est,
const MoistureComponentIndices &  moisture_indice 
)

Compute planetary-boundary-layer height with the selected estimator.

Parameters
[in]levlevel index
[in,out]varsstate variables used by the PBL-height calculation
[in]z_phys_cccell-centered physical-height field
[in]estPBL-height estimator functor
[in]moisture_indiceindices for moisture components

◆ compute_pblh() [2/2]

template<typename PBLHeightEstimator >
void SurfaceLayer::compute_pblh ( const int &  lev,
Vector< Vector< MultiFab >> &  vars,
MultiFab *  z_phys_cc,
const PBLHeightEstimator &  est,
const MoistureComponentIndices &  moisture_indices 
)

Compute PBL height with the supplied estimator.

Parameters
[in]levCurrent level
[in]varsLevel-indexed state MultiFabs passed to the estimator
[in]z_phys_ccCell-centered physical height used by the estimator
[in]estPBL height estimator functor
[in]moisture_indicesMoisture component indices used by the estimator
3722 {
3723  const MultiFab& cons = vars[lev][Vars::cons];
3724  const iMultiFab* lmask = m_lmask_lev[lev][0];
3725 
3726  // The estimator scans each box from its lowest cell to its highest and writes the planar
3727  // pblh of that box, so every box it is given must start at the ground. Grids that hold
3728  // such boxes only -- full height or not -- go straight to it. Any other grids (boxes
3729  // stacked in z, or boxes aloft) go through columns: the runs of cells that start at the
3730  // ground, each as one box (see define_pblh_columns).
3731  if (static_cast<int>(m_pblh_columns.size()) <= lev) { m_pblh_columns.resize(lev+1); }
3732  if (m_pblh_columns[lev].ba != cons.boxArray() ||
3733  m_pblh_columns[lev].dm != cons.DistributionMap()) {
3734  define_pblh_columns(lev, cons.boxArray(), cons.DistributionMap());
3735  }
3736  const PBLHColumns& cols = m_pblh_columns[lev];
3737 
3738  // A refined level whose grids do not run from the ground to the top of the domain in every
3739  // column cannot diagnose the boundary layer there: a level that ends below the top would
3740  // return a height capped by its grids, and a level that does not reach the ground has no
3741  // column to scan (it was left at zero). Such a level takes the PBL height of the next
3742  // coarser level at each of its columns. Levels are updated coarse to fine, so that height
3743  // is the one set at the start of the enclosing coarse step: with subcycling, the later fine
3744  // substeps read a coarse height up to one coarse step old. A refined level that spans the
3745  // full height diagnoses its own.
3746  if (lev > 0 && !cols.full_height && m_face.coordDir() == 2 && m_face.isLow() &&
3747  m_terrain_type != TerrainType::EB) {
3749  return;
3750  }
3751 
3752  if (!cols.needed) {
3753  est.compute_pblh(m_geom[lev], z_phys_cc, pblh[lev].get(), cons, lmask, moisture_indices);
3754  return;
3755  }
3756 
3757  // Zero is the estimator's own value for a height it did not find. It stays on the planar
3758  // boxes over which no box of this level reaches the ground: all of them on a level that
3759  // lies entirely aloft.
3760  pblh[lev]->setVal(zero);
3761  if (cols.ba_col.empty()) { return; }
3762 
3763  const Periodicity period = m_geom[lev].periodicity();
3764 
3765  // The estimator reads the density, the potential temperature, the TKE and the moisture
3766  // species that enter theta_v. Those live in [0, RhoKE_comp] and in the moist window, so
3767  // the columns carry the state up to the highest of them and no further: the species above
3768  // it (the number concentrations of a two-moment scheme, the non-water species) are the
3769  // bulk of a moist state and are never read here. The span is contiguous rather than the
3770  // two pieces it is made of, so that every component of cons_col is filled by the copies
3771  // below -- a component the estimator reads must never be one this routine left unset --
3772  // and the components keep their place, since the estimator indexes the state by
3773  // component number.
3774  int q_hi = -1;
3775  for (const int q : {moisture_indices.qv, moisture_indices.qc, moisture_indices.qi,
3776  moisture_indices.qr, moisture_indices.qs, moisture_indices.qg}) {
3777  AMREX_ALWAYS_ASSERT((q < 0) || ((q > RhoKE_comp) && (q < cons.nComp())));
3778  q_hi = std::max(q_hi, q);
3779  }
3780  const int ncomp_col = std::max(RhoKE_comp+1, q_hi+1);
3781 
3782  // The halo the columns need: in x and y the ghost cells of pblh, which the estimator
3783  // writes and so reads the state over, and in z the one cell above the top of each column
3784  // that the scan's k+1 reads end in. The state must hold that halo for the copies below
3785  // to have anything to take it from.
3786  const IntVect ng_pblh = pblh[lev]->nGrowVect();
3787  const IntVect ng_col = elemwiseMax(ng_pblh, IntVect(AMREX_D_DECL(0,0,1)));
3788  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(cons.nGrowVect().allGE(ng_col),
3789  "erf.most.pblh_calc = MYNN25 on grids that do not all start at the ground needs the "
3790  "state to carry at least the ghost cells of the surface-layer fields, and one in z.");
3791 
3792  // Every valid cell of a column is a valid cell of this level, and every ghost cell of a
3793  // column is a valid or a ghost cell of the box that holds the cell next to it, so the two
3794  // passes below leave no cell of the columns unset. Ghost cells go first (they hold the
3795  // physical boundary values and, next to a coarser level, the values interpolated from
3796  // it), then the valid cells, so that every cell this level owns comes from the box that
3797  // owns it and not from a neighbor's ghost cell.
3798  MultiFab cons_col(cols.ba_col, cols.dm_col, ncomp_col, ng_col);
3799  for (const IntVect& ng_src : {ng_col, IntVect(0)}) {
3800  cons_col.ParallelCopy(cons, 0, 0, ncomp_col, ng_src, ng_col, period);
3801  }
3802 
3803  std::unique_ptr<MultiFab> zcc_col;
3804  if (z_phys_cc) {
3805  const IntVect ng_z = z_phys_cc->nGrowVect();
3806  zcc_col = std::make_unique<MultiFab>(cols.ba_col, cols.dm_col, 1, ng_z);
3807  zcc_col->ParallelCopy(*z_phys_cc, 0, 0, 1, ng_z, ng_z, period);
3808  zcc_col->ParallelCopy(*z_phys_cc, 0, 0, 1, IntVect(0), ng_z, period);
3809  }
3810 
3811  std::unique_ptr<iMultiFab> lmask_col;
3812  if (lmask) {
3813  lmask_col = std::make_unique<iMultiFab>(cols.ba_col2d, cols.dm_col, 1, ng_pblh);
3814  lmask_col->setVal(1);
3815  lmask_col->ParallelCopy(*lmask, 0, 0, 1, elemwiseMin(lmask->nGrowVect(), ng_pblh), ng_pblh, period);
3816  lmask_col->ParallelCopy(*lmask, 0, 0, 1, IntVect(0), ng_pblh, period);
3817  }
3818 
3819  MultiFab pblh_col(cols.ba_col2d, cols.dm_col, 1, ng_pblh);
3820  est.compute_pblh(m_geom[lev], zcc_col.get(), &pblh_col, cons_col, lmask_col.get(), moisture_indices);
3821 
3822  // Onto every planar box. The ghost cells of the columns go first, for the ghost cells of
3823  // pblh outside the domain. They also reach valid cells of pblh over which no box of this
3824  // level starts at the ground (the estimator fills the ghost cells of a column next to such
3825  // a gap from ghost data), so those are set back to zero before the valid cells of the
3826  // columns are copied. Every planar copy of a cell then holds the same value, which makes
3827  // the FillBoundary that ends this well defined despite the duplicate boxes.
3828  pblh[lev]->ParallelCopy(pblh_col, 0, 0, 1, ng_pblh, ng_pblh, period);
3829  pblh[lev]->setVal(zero, 0, 1, 0);
3830  pblh[lev]->ParallelCopy(pblh_col, 0, 0, 1, IntVect(0), IntVect(0), period);
3831  pblh[lev]->FillBoundary(period);
3832 }
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
amrex::Vector< PBLHColumns > m_pblh_columns
Definition: ERF_SurfaceLayer.H:2263
void fill_pblh_from_coarser(const int &lev)
Definition: ERF_SurfaceLayer.cpp:3912
void define_pblh_columns(const int &lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
Definition: ERF_SurfaceLayer.cpp:3843
@ cons
Definition: ERF_IndexDefines.H:231
@ q
Definition: ERF_WSM6.H:296
int qs
snow
Definition: ERF_DataStruct.H:294
int qr
rain
Definition: ERF_DataStruct.H:293
int qi
cloud ice
Definition: ERF_DataStruct.H:292
int qv
water vapor
Definition: ERF_DataStruct.H:290
int qc
cloud liquid water
Definition: ERF_DataStruct.H:291
int qg
graupel
Definition: ERF_DataStruct.H:295
Here is the call graph for this function:

◆ compute_sfc_params_from_lsm_fluxes()

void SurfaceLayer::compute_sfc_params_from_lsm_fluxes ( const int &  lev,
amrex::MultiFab &  cons_in 
)

Derive MOST surface parameters from LSM fluxes.

Parameters
[in]levlevel index
[in,out]cons_inconserved state used by the surface-parameter computation

Compute surface-layer parameters from land-surface-model fluxes.

Parameters
[in]levCurrent level
[in]cons_inConserved state used to derive density, theta, and moisture at the surface
2448 {
2450  static_cast<int>(m_face) == Orientation::zlo(),
2451  "LSM surface-layer parameters are supported only on the z-low face.");
2452 
2454  bool has_moisture = use_moisture;
2455  const int klo = m_geom[lev].Domain().smallEnd(2);
2456  const auto *const umm_ptr = m_ma.get_average(lev,6); // horizontal velocity magnitude
2457  const auto *const zref_ptr = m_ma.get_zref(lev); // reference height
2458  for (MFIter mfi(cons_in); mfi.isValid(); ++mfi) {
2459 
2460  Box vbx = mfi.validbox();
2461  if (vbx.smallEnd(2) != klo) { continue; }
2462  vbx.makeSlab(2,0);
2463 
2464  // The ghost columns are set too, so that they hold the same kind of value as the
2465  // valid columns: compute_fluxes writes MOST values over the grown box, and
2466  // fill_planar_boundary below refills only the interior and periodic ghosts, so a
2467  // coarse/fine or domain-edge ghost would otherwise keep a MOST value next to
2468  // LSM values. The LSM fluxes do not carry lateral ghost cells, so a ghost column
2469  // takes the fluxes of the nearest valid column, as in get_lsm_tsurf, with its own
2470  // atmospheric state.
2471  const NearestColumn col(vbx);
2472  const int idx = mfi.index();
2473  Box gbx = amrex::grow(vbx, IntVect(AMREX_D_DECL(u_star[lev]->nGrow(0),
2474  u_star[lev]->nGrow(1), 0)));
2475  Box cons_slab = cons_in.fabbox(idx);
2476  cons_slab.setRange(2, 0);
2477  gbx &= u_star[lev]->fabbox(idx);
2478  gbx &= z_0[lev].fabbox(idx);
2479  gbx &= umm_ptr->fabbox(idx);
2480  gbx &= zref_ptr->fabbox(idx);
2481  gbx &= cons_slab;
2482  if (m_lmask_lev[lev][0]) { gbx &= m_lmask_lev[lev][0]->fabbox(idx); }
2483 
2484  // Get CC state
2485  const Array4<const Real> cons_arr = cons_in.const_array(mfi);
2486 
2487  // Get SL params
2488  const auto u_star_arr = u_star[lev]->array(mfi);
2489  const auto t_star_arr = t_star[lev]->array(mfi);
2490  const auto q_star_arr = q_star[lev]->array(mfi);
2491  const auto olen_arr = olen[lev]->array(mfi);
2492 
2493  const auto umm_arr = umm_ptr->array(mfi);
2494  const auto zref_arr = zref_ptr->array(mfi);
2495  const auto z0_arr = z_0[lev].array(mfi);
2496 
2497  // compute_fluxes does not iterate the columns set here, so w* is set here too
2498  const auto w_star_arr = (m_include_wstar) ? w_star[lev]->array(mfi) : Array4<Real> {};
2499  const auto pblh_arr = (m_include_wstar) ? pblh[lev]->const_array(mfi) : Array4<const Real> {};
2500 
2501  // Get LSM fluxes
2502  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
2503  Array4<int> {};
2504  // compute_sfc_params_from_lsm_fluxes consumes signed kinematic stress
2505  // components; their vector magnitude determines u_star^2.
2506  const SurfaceFluxView lsm_flux = get_lsm_flux_view(lev, mfi);
2507  const auto lsm_t_flux_arr = lsm_flux.t_flux;
2508  const auto lsm_q_flux_arr = lsm_flux.q_flux;
2509  const auto lsm_tau13_arr = lsm_flux.tau13;
2510  const auto lsm_tau23_arr = lsm_flux.tau23;
2511 
2512  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int /*k*/) noexcept
2513  {
2514  int is_land = (lmask_arr) ? lmask_arr(i,j,0) : 1;
2515  const int li = col.i(i);
2516  const int lj = col.j(j);
2517  // Only ordinary land (mask 1) uses LSM fluxes. Immersed buildings and
2518  // terrain (mask 2) retain their existing surface-layer parameters.
2519  // Skip cells where the LSM does not have a valid value (finite and below
2520  // lsm_undefined) for every one of the four fluxes; these keep the MOST values.
2521  if (is_land == 1 && lsm_flux.valid(li,lj)) {
2522  const Real t_flux = lsm_t_flux_arr(li,lj,0);
2523  const Real q_flux = lsm_q_flux_arr(li,lj,0);
2524  Real rho = cons_arr(i,j,klo,Rho_comp);
2525  Real Thd = cons_arr(i,j,klo,RhoTheta_comp) / rho;
2526  Real qv = (has_moisture) ? cons_arr(i,j,klo,RhoQ1_comp) / rho : zero;
2527  Real Thv = Thd * (one + epsv*qv);
2528  Real tau = std::sqrt( lsm_tau13_arr(li,lj,0)*lsm_tau13_arr(li,lj,0)
2529  + lsm_tau23_arr(li,lj,0)*lsm_tau23_arr(li,lj,0) );
2530  u_star_arr(i,j,0) = amrex::max(std::sqrt(tau),eps);
2531  if (t_flux>=zero) {
2532  t_star_arr(i,j,0) = amrex::min(-t_flux / u_star_arr(i,j,0),-eps);
2533  } else {
2534  t_star_arr(i,j,0) = amrex::max(-t_flux / u_star_arr(i,j,0),eps);
2535  }
2536  if (q_flux>=zero) {
2537  q_star_arr(i,j,0) = amrex::min(-q_flux / u_star_arr(i,j,0),-eps);
2538  } else {
2539  q_star_arr(i,j,0) = amrex::max(-q_flux / u_star_arr(i,j,0),eps);
2540  }
2541  Real tstv = t_star_arr(i,j,0)*(one + epsv*qv) + epsv*Thd*q_star_arr(i,j,0);
2542  tstv = (tstv >= zero) ? amrex::max(tstv, eps) : amrex::min(tstv, -eps);
2543  olen_arr(i,j,0) = ( u_star_arr(i,j,0) * u_star_arr(i,j,0) * Thv ) /
2544  ( KAPPA * CONST_GRAV * tstv );
2545  z0_arr(i,j,0) = Compute_roughness(zref_arr(i,j,0), olen_arr(i,j,0),
2546  umm_arr(i,j,0), u_star_arr(i,j,0));
2547  if (w_star_arr) {
2548  w_star_arr(i,j,0) = calc_wstar(u_star_arr(i,j,0), t_star_arr(i,j,0),
2549  q_star_arr(i,j,0), pblh_arr(i,j,0),
2550  Thd, Thv, qv);
2551  }
2552  }
2553  });
2554  } // mfi
2555 }
constexpr amrex::Real epsv
Definition: ERF_Constants.H:56
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_roughness(amrex::Real zref, amrex::Real Olen, amrex::Real umm, amrex::Real ustar)
Definition: ERF_MOSTUtils.H:934
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_wstar(const amrex::Real &ust, const amrex::Real &tst, const amrex::Real &qst, const amrex::Real &pblh, const amrex::Real &th, const amrex::Real &thv, const amrex::Real &qv=amrex::Real(0))
Definition: ERF_Wstar.H:27
@ t_flux
Definition: ERF_NOAHMP_Fields.H:125
@ q_flux
Definition: ERF_NOAHMP_Fields.H:126
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real eps()
Definition: ERF_ShocMoments.cpp:19
amrex::Array4< const amrex::Real > q_flux
Definition: ERF_SurfaceModel.H:28
amrex::Array4< const amrex::Real > tau23
Definition: ERF_SurfaceModel.H:26
amrex::Array4< const amrex::Real > tau13
Definition: ERF_SurfaceModel.H:25
amrex::Array4< const amrex::Real > t_flux
Definition: ERF_SurfaceModel.H:27
Here is the call graph for this function:

◆ compute_SurfaceLayer_bcs() [1/2]

template<typename FluxCalc >
void SurfaceLayer::compute_SurfaceLayer_bcs ( const int &  lev,
amrex::Vector< const amrex::MultiFab * >  mfs,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  Tau_lev,
amrex::MultiFab *  xheat_flux,
amrex::MultiFab *  yheat_flux,
amrex::MultiFab *  zheat_flux,
amrex::MultiFab *  xqv_flux,
amrex::MultiFab *  yqv_flux,
amrex::MultiFab *  zqv_flux,
const amrex::MultiFab *  z_phys,
const FluxCalc &  flux_comp,
amrex::MultiFab *  mf_surface_fluxes = nullptr 
)

Compute planar-terrain surface-layer flux boundary conditions.

Parameters
[in]levlevel index
[in]mfsstate and velocity fields used by the BC computation
[in,out]Tau_levstress fields to fill
[in,out]xheat_fluxx-face heat flux field
[in,out]yheat_fluxy-face heat flux field
[in,out]zheat_fluxz-face heat flux field
[in,out]xqv_fluxx-face moisture flux field
[in,out]yqv_fluxy-face moisture flux field
[in,out]zqv_fluxz-face moisture flux field
[in]z_physphysical-height field
[in]flux_compflux-computation functor

◆ compute_SurfaceLayer_bcs() [2/2]

template<typename FluxCalc >
void SurfaceLayer::compute_SurfaceLayer_bcs ( const int &  lev,
Vector< const MultiFab * >  mfs,
Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
MultiFab *  xheat_flux,
MultiFab *  yheat_flux,
MultiFab *  zheat_flux,
MultiFab *  xqv_flux,
MultiFab *  yqv_flux,
MultiFab *  zqv_flux,
const MultiFab *  z_phys,
const FluxCalc &  flux_comp,
MultiFab *  mf_surface_fluxes 
)

Function to calculate MOST fluxes for populating ghost cells.

Parameters
[in]levCurrent level
[in]mfsState MultiFabs used to compute the boundary fluxes
[in,out]Tau_levDiffusive stress MultiFabs populated with surface stresses
[in,out]xheat_fluxx-face heat-flux MultiFab, used when rotated fluxes are enabled
[in,out]yheat_fluxy-face heat-flux MultiFab, used when rotated fluxes are enabled
[in,out]zheat_fluxz-face heat-flux MultiFab populated with vertical surface heat flux
[in,out]xqv_fluxx-face moisture-flux MultiFab, used when rotated fluxes and moisture are enabled
[in,out]yqv_fluxy-face moisture-flux MultiFab, used when rotated fluxes and moisture are enabled
[in,out]zqv_fluxz-face moisture-flux MultiFab populated when moisture is enabled
[in]z_physNodal physical height used to rotate terrain-following fluxes
[in]flux_compFlux-calculation functor used to compute scalar and momentum fluxes
1522 {
1523  bool rotate = m_rotate;
1524 
1525  const int dir = m_face.coordDir();
1527  !mfs.empty() && mfs[0] != nullptr,
1528  "Surface-layer stress computation requires a conserved-state MultiFab.");
1530  Tau_lev[TauType::tau13] != nullptr && Tau_lev[TauType::tau23] != nullptr,
1531  "tau13 and tau23 are required by surface-layer stress computation.");
1532  int sm_index = 0;
1533  if (m_face.isLow()) {
1534  sm_index = m_geom[lev].Domain().smallEnd(dir);
1535  } else {
1536  sm_index = m_geom[lev].Domain().bigEnd(dir);
1537  }
1538 
1539  // These requirements are invariant over the loop below. Check them once
1540  // before acquiring per-tile array views.
1541  if (dir == 0) {
1543  Tau_lev[TauType::tau31] != nullptr,
1544  "tau31 is required when imposing an x-face surface layer.");
1546  Tau_lev[TauType::tau21] != nullptr,
1547  "tau21 is required when imposing an x-face surface layer.");
1548  } else if (dir == 1) {
1550  Tau_lev[TauType::tau32] != nullptr,
1551  "tau32 is required when imposing a y-face surface layer.");
1553  Tau_lev[TauType::tau12] != nullptr,
1554  "tau12 is required when imposing a y-face surface layer.");
1555  }
1556 
1557  const int klo = sm_index;
1558  const auto& dxInv = m_geom[lev].InvCellSizeArray();
1559  const Box domain = m_geom[lev].Domain();
1560  const int xlo_node = domain.smallEnd(0);
1561  const int xhi_node = domain.bigEnd(0) + 1;
1562  const int ylo_node = domain.smallEnd(1);
1563  const int yhi_node = domain.bigEnd(1) + 1;
1564  const int zlo_node = domain.smallEnd(2);
1565  const int zhi_node = domain.bigEnd(2) + 1;
1566  const bool xlo_surface = m_surface_layer_faces[Orientation::xlo()];
1567  const bool xhi_surface = m_surface_layer_faces[Orientation::xhi()];
1568  const bool ylo_surface = m_surface_layer_faces[Orientation::ylo()];
1569  const bool yhi_surface = m_surface_layer_faces[Orientation::yhi()];
1570  const bool zlo_surface = m_surface_layer_faces[Orientation::zlo()];
1571  const bool zhi_surface = m_surface_layer_faces[Orientation::zhi()];
1572 
1573  // The face stresses read the LSM fluxes of the cells on both sides of a face, one cell
1574  // beyond the grid. Beside another grid or a periodic image that cell holds the
1575  // neighbor's own fluxes, so both grids compute the face from the same values. Outside
1576  // a non-periodic domain it holds no LSM value, and the column there was set by
1577  // compute_fluxes and compute_sfc_params_from_lsm_fluxes from the nearest column of the
1578  // grid, so it reads that column, as set_pblh does. The face-normal direction of a
1579  // lateral face is not clamped: its outer cells lie outside the domain by construction.
1580  Box lsm_flux_columns = domain;
1581  for (int d = 0; d < 2; ++d) {
1582  if (m_geom[lev].isPeriodic(d) || d == dir) { lsm_flux_columns.grow(d, 1); }
1583  }
1584  const NearestColumn in_domain(lsm_flux_columns);
1585 
1586  // On a refined level a ghost column at a coarse/fine boundary also holds no current LSM
1587  // flux: the LSMs refill only the ghost cells that a grid of the level holds (SLM calls
1588  // just FillBoundary), so it keeps what the last regrid left there. The columns a grid
1589  // touching the surface holds are marked in m_lsm_held_columns, so such a column reads
1590  // the grid's nearest column too (LsmFluxColumn). Level 0 has no coarse/fine boundary,
1591  // and in_domain alone suffices.
1592  const bool has_lsm_flux_source = m_has_lsm_fluxes || (use_surface_model && surf_model_fluxes);
1593  const iMultiFab* held_columns =
1594  (has_lsm_flux_source && lev < m_lsm_held_columns.size() && !m_lsm_held_columns[lev].empty())
1595  ? &m_lsm_held_columns[lev] : nullptr;
1596 
1597  // Over a moving surface the stresses and fluxes take the wind relative to it. They read
1598  // the velocities only in the plane k = klo, so only that plane is made relative.
1599  const bool use_current = m_use_surface_current && dir == 2 && m_face.isLow();
1600  const MultiFab* current_x = use_current ? get_surface_current(lev, 0) : nullptr;
1601  const MultiFab* current_y = use_current ? get_surface_current(lev, 1) : nullptr;
1602  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!use_current || (current_x && current_y),
1603  "The surface current has not been defined on this level.");
1604 
1605  for (MFIter mfi(*mfs[0]); mfi.isValid(); ++mfi)
1606  {
1607  // Skip boxes that do not own the selected face before acquiring any
1608  // arrays from collapsed or staggered layouts. Interior boxes may
1609  // share the same collapsed coordinates but do not contain surface
1610  // data for this boundary.
1611  Box bx = mfi.tilebox();
1612  const Box valid_bx = mfi.validbox();
1613  if (m_face.isLow()) {
1614  if (valid_bx.smallEnd(dir) != klo ||
1615  bx.smallEnd(dir) != klo) {
1616  continue;
1617  }
1618  bx.setBig(dir, bx.smallEnd(dir));
1619  } else {
1620  if (valid_bx.bigEnd(dir) != klo ||
1621  bx.bigEnd(dir) != klo) {
1622  continue;
1623  }
1624  bx.setSmall(dir, bx.bigEnd(dir));
1625  }
1626 
1627  // Get field arrays
1628  const auto cons_arr = mfs[Vars::cons]->array(mfi);
1629  auto velx_arr = mfs[Vars::xvel]->const_array(mfi);
1630  auto vely_arr = mfs[Vars::yvel]->const_array(mfi);
1631  const auto velz_arr = mfs[Vars::zvel]->array(mfi);
1632  FArrayBox rel_xvel, rel_yvel;
1633  if (use_current) {
1634  // The plane k = klo less the current, ghost cells included: all the kernels read
1635  for (int vdir = 0; vdir < 2; ++vdir) {
1636  const MultiFab& vel = *mfs[(vdir == 0) ? Vars::xvel : Vars::yvel];
1637  FArrayBox& rel = (vdir == 0) ? rel_xvel : rel_yvel;
1638  const Box plane = makeSlab(vel.fabbox(mfi.index()), 2, klo);
1639  rel.resize(plane, 1, The_Async_Arena());
1640  const auto v = vel.const_array(mfi);
1641  const auto c = ((vdir == 0) ? current_x : current_y)->const_array(mfi);
1642  const auto r = rel.array();
1643  ParallelFor(plane, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1644  {
1645  r(i,j,k) = v(i,j,k) - c(i,j,k);
1646  });
1647  }
1648  velx_arr = rel_xvel.const_array();
1649  vely_arr = rel_yvel.const_array();
1650  }
1651 
1652  // Output stresses:
1653  // T Q U V
1654  // X-faces: hfx1 qfx1 t21 t31
1655  // Y-faces: hfx2 qfx2 t12 t32
1656  // Z-faces: hfx3 qfx3 t13 t23
1657 
1658  // Output stresses nodal locations:
1659  // T Q
1660  // X-faces: hfx1 qfx1(1,0,0) t21(V)(1,1,0) t31(W)(1,0,1)
1661  // Y-faces: hfx2 qfx2(0,1,0) t12(U)(1,1,0) t32(W)(0,1,1)
1662  // Z-faces: hfx3 qfx3(0,0,1) t13(U)(1,0,1) t23(V)(0,1,1)
1663 
1664  // Diffusive stress vars
1665  auto t13_arr = Tau_lev[TauType::tau13]->array(mfi);
1666  auto t31_arr = Tau_lev[TauType::tau31]
1667  ? Tau_lev[TauType::tau31]->array(mfi) : Array4<Real>{};
1668 
1669  auto t23_arr = Tau_lev[TauType::tau23]->array(mfi);
1670  auto t32_arr = Tau_lev[TauType::tau32]
1671  ? Tau_lev[TauType::tau32]->array(mfi) : Array4<Real>{};
1672 
1673 
1674  auto hfx3_arr = zheat_flux->array(mfi);
1675  auto qfx3_arr = (zqv_flux) ? zqv_flux->array(mfi) : Array4<Real>{};
1676 
1677  auto olen_arr = olen[lev]->array(mfi);
1678 
1679  // Rotated stress vars
1680  auto t11_arr = (m_rotate) ? Tau_lev[TauType::tau11]->array(mfi) : Array4<Real>{};
1681  auto t22_arr = (m_rotate) ? Tau_lev[TauType::tau22]->array(mfi) : Array4<Real>{};
1682  auto t33_arr = (m_rotate) ? Tau_lev[TauType::tau33]->array(mfi) : Array4<Real>{};
1683  auto t12_arr = Tau_lev[TauType::tau12]
1684  ? Tau_lev[TauType::tau12]->array(mfi) : Array4<Real>{};
1685  auto t21_arr = Tau_lev[TauType::tau21]
1686  ? Tau_lev[TauType::tau21]->array(mfi) : Array4<Real>{};
1687 
1688  auto hfx1_arr = (m_rotate || dir == 0) ? xheat_flux->array(mfi) : Array4<Real>{};
1689  auto hfx2_arr = (m_rotate || dir == 1) ? yheat_flux->array(mfi) : Array4<Real>{};
1690  auto qfx1_arr = (xqv_flux && (m_rotate || dir == 0)) ? xqv_flux->array(mfi) : Array4<Real>{};
1691  auto qfx2_arr = (yqv_flux && (m_rotate || dir == 1)) ? yqv_flux->array(mfi) : Array4<Real>{};
1692 
1693  // Terrain
1694  const auto zphys_arr = (z_phys) ? z_phys->const_array(mfi) : Array4<const Real>{};
1695 
1696  // Get average arrays
1697  const auto *const u_mean = m_ma.get_average(lev,0);
1698  const auto *const v_mean = m_ma.get_average(lev,1);
1699  const auto *const w_mean = m_ma.get_average(lev,2);
1700  const auto *const t_mean = m_ma.get_average(lev,3);
1701  const auto *const q_mean = m_ma.get_average(lev,4);
1702  const auto *const u_mag_mean = m_ma.get_average(lev,6);
1703  const auto *const uw_mag_mean = m_ma.get_average(lev,7);
1704  const auto *const vw_mag_mean = m_ma.get_average(lev,8);
1705  const auto *const zref_ptr = m_ma.get_zref(lev);
1706 
1707  const auto um_arr = u_mean->array(mfi);
1708  const auto vm_arr = v_mean->array(mfi);
1709  const auto wm_arr = w_mean->array(mfi);
1710  const auto tm_arr = t_mean->array(mfi);
1711  const auto qm_arr = q_mean->array(mfi);
1712  const auto umm_arr = u_mag_mean->array(mfi);
1713  const auto vwmm_arr = (dir == 0) ? vw_mag_mean->array(mfi) : Array4<Real>{};
1714  const auto uwmm_arr = (dir == 1) ? uw_mag_mean->array(mfi) : Array4<Real>{};
1715 
1716  // umm depending on face direction (YZ, XZ, XY)
1717  const auto dir_umm_arr = ((dir == 0) ? vwmm_arr : ((dir == 1) ? uwmm_arr : umm_arr));
1718 
1719  const auto zref_arr = zref_ptr->array(mfi);
1720  const auto z0_arr = z_0[lev].array(mfi);
1721 
1722  // Get derived arrays
1723  const auto u_star_arr = u_star[lev]->array(mfi);
1724  const auto t_star_arr = t_star[lev]->array(mfi);
1725  const auto q_star_arr = q_star[lev]->array(mfi);
1726  const auto t_surf_arr = t_surf[lev]->array(mfi);
1727  const auto q_surf_arr = q_surf[lev]->array(mfi);
1728  auto surface_source_arr = surface_diagnostic_source[lev]->array(mfi);
1729 
1730  // Get LSM fluxes
1731  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
1732  Array4<int> {};
1733  auto soil_t_flux_arr = Array4<Real> {};
1734  for (int n(0); n<m_lsm_flux_lev[lev].size(); ++n) {
1735  if (m_lsm_flux_lev[lev][n] && toLower(m_lsm_flux_name[n]) == "soil_t_flux") {
1736  soil_t_flux_arr = m_lsm_flux_lev[lev][n]->array(mfi);
1737  }
1738  }
1739 
1740  // Provider, weight-averaged LSM+Urban or registered LSM fluxes. A column uses the
1741  // LSM fluxes only where SurfaceFluxView::valid holds for all four, the same test
1742  // compute_fluxes and compute_sfc_params_from_lsm_fluxes make, so the applied fluxes
1743  // come from the same source as that column's u*/t*/q*.
1744  // LSM tau fields are cell-centered kinematic stresses [m2 s-2].
1745  // Tau_lev tau13/tau23 are face-centered conservative stresses [N m-2].
1746  const SurfaceFluxView lsm_flux = get_lsm_flux_view(lev, mfi);
1747  const auto t_flux_arr = lsm_flux.t_flux;
1748  const auto q_flux_arr = lsm_flux.q_flux;
1749  const auto surface_tau13_arr = lsm_flux.tau13;
1750  const auto surface_tau23_arr = lsm_flux.tau23;
1751  const bool has_lsm_t_flux = static_cast<bool>(t_flux_arr);
1752  const LsmFluxColumn flux_col{in_domain, NearestColumn(valid_bx),
1753  held_columns ? held_columns->const_array(mfi)
1754  : Array4<const int>{}};
1755  {
1756  Box flux_columns = amrex::grow(valid_bx, IntVect(AMREX_D_DECL(1, 1, 0)));
1757  flux_columns &= lsm_flux_columns;
1759  covers_columns(t_flux_arr, flux_columns) &&
1760  covers_columns(q_flux_arr, flux_columns) &&
1761  covers_columns(surface_tau13_arr, flux_columns) &&
1762  covers_columns(surface_tau23_arr, flux_columns),
1763  "SurfaceLayer: the LSM fluxes must carry one filled lateral ghost cell "
1764  "for the surface stresses");
1765  }
1766  const bool is_custom = (flux_type == FluxCalcType::CUSTOM);
1767  const bool is_rico = (flux_type == FluxCalcType::RICO);
1768 
1769 
1770  // Rho*Theta flux
1771  //============================================================================
1772  const bool is_low_face = m_face.isLow();
1773 
1774  amrex::Array4<amrex::Real> surface_flux_arr;
1775  if (mf_surface_fluxes != nullptr) {
1776  surface_flux_arr = mf_surface_fluxes->array(mfi);
1777  }
1778 
1779  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1780  {
1781  // Valid theta flux from LSM and over land. The LSM writes the
1782  // lsm_undefined sentinel for cells it did not process (sea-ice /
1783  // open water); fall back to MOST there instead of applying garbage.
1784  Real Tflux;
1785  int is_land = (lmask_arr) ? lmask_arr(i,j,0) : 1;
1786  const bool lsm_flux_is_valid = lsm_flux.valid(i,j);
1787  const bool has_land_and_flux = (is_land == 1 && lsm_flux_is_valid);
1788  if (has_land_and_flux) {
1789  // LSM flux MultiFabs store kinematic fluxes for MOST parameter
1790  // updates. The applied hfx array stores the conservative RHS flux.
1791  Tflux = cons_arr(i,j,k,Rho_comp) * t_flux_arr(i,j,0);
1792  if(surface_flux_arr) {
1793  surface_flux_arr(i,j,0,0) = Tflux;
1794  }
1795  } else if (is_land == 2) { // no temperature flux within buildings
1796  Tflux = zero;
1797  if(surface_flux_arr) {
1798  surface_flux_arr(i,j,0,0) = Tflux;
1799  }
1800  } else {
1801  Tflux = flux_comp.compute_t_flux(i, j, k, dir,
1802  cons_arr, velx_arr, vely_arr, velz_arr,
1803  dir_umm_arr, tm_arr, u_star_arr,
1804  t_star_arr, t_surf_arr);
1805  // NOTE: do NOT write the MOST-fallback flux back into lsm_t_flux_arr.
1806  // Doing so flips a sentinel (water/unprocessed) cell to "valid LSM"
1807  // on the next step, so a MOST-derived value is re-read as an LSM flux
1808  // Only Noah-MP should populate the LSM cache.
1809  if (surface_flux_arr) {
1810  surface_flux_arr(i,j,0,0) = Tflux;
1811  }
1812  }
1813 
1814  if (soil_t_flux_arr && is_land == 1) {
1815  soil_t_flux_arr(i,j,k) = Tflux / cons_arr(i,j,k,Rho_comp);
1816  }
1817 
1818  surface_source_arr(i,j,k) = surface_diagnostics::to_plot_value(
1820  is_custom, is_rico, is_land, has_lsm_t_flux, lsm_flux_is_valid));
1821 
1822  // Do scalar flux rotations?
1823  if (rotate) {
1824  rotate_scalar_flux(i, j, k, dir, Tflux, dxInv, zphys_arr,
1825  hfx1_arr, hfx2_arr, hfx3_arr);
1826  } else {
1827  // swap sign for upward faces
1828  if (!is_low_face && dir != 2) {
1829  Tflux = -Tflux;
1830  }
1831 
1832  // write out to corresponding face
1833  if (dir == 0) {
1834  if (!is_low_face) {
1835  hfx1_arr(i+1,j,k) = Tflux;
1836  } else {
1837  hfx1_arr(i,j,k) = Tflux;
1838  }
1839  } else if (dir == 1) {
1840  if (!is_low_face) {
1841  hfx2_arr(i,j+1,k) = Tflux;
1842  } else {
1843  hfx2_arr(i,j,k) = Tflux;
1844  }
1845  } else {
1846  if (!is_low_face) {
1847  hfx3_arr(i,j,k+1) = Tflux;
1848  } else {
1849  hfx3_arr(i,j,k) = Tflux;
1850  }
1851  }
1852  }
1853  });
1854 
1855  // Rho*Qv flux
1856  //============================================================================
1857  if (use_moisture) {
1858  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1859  {
1860  // Valid qv flux from LSM and over land (sentinel -> fall back to MOST)
1861  Real Qflux;
1862  int is_land = (lmask_arr) ? lmask_arr(i,j,0) : 1;
1863  const bool lsm_flux_is_valid = lsm_flux.valid(i,j);
1864  const bool has_land_and_flux = (is_land == 1 && lsm_flux_is_valid);
1865  if (has_land_and_flux) {
1866  // LSM flux MultiFabs store kinematic fluxes for MOST parameter
1867  // updates. The applied qfx array stores the conservative RHS flux.
1868  Qflux = cons_arr(i,j,k,Rho_comp) * q_flux_arr(i,j,0);
1869  if(surface_flux_arr) {
1870  surface_flux_arr(i,j,0,1) = Qflux;
1871  }
1872  } else if (is_land == 2) { // no moisture flux within buildings
1873  Qflux = zero;
1874  if(surface_flux_arr) {
1875  surface_flux_arr(i,j,0,1) = Qflux;
1876  }
1877  } else {
1878  Qflux = flux_comp.compute_q_flux(i, j, k, dir,
1879  cons_arr, velx_arr, vely_arr, velz_arr,
1880  dir_umm_arr, qm_arr, u_star_arr,
1881  q_star_arr, q_surf_arr);
1882  // NOTE: no writeback into lsm_q_flux_arr -- see the matching
1883  // t_flux note above.
1884  if (surface_flux_arr) {
1885  surface_flux_arr(i,j,0,1) = Qflux;
1886  }
1887  }
1888 
1889  // Do scalar flux rotations?
1890  if (rotate) {
1891  rotate_scalar_flux(i, j, k, dir, Qflux, dxInv, zphys_arr,
1892  qfx1_arr, qfx2_arr, qfx3_arr);
1893  } else {
1894  // swap sign for upward faces
1895  if (!is_low_face && dir != 2) {
1896  Qflux = -Qflux;
1897  }
1898 
1899  // write out to corresponding face
1900  if (dir == 0) {
1901  if (!is_low_face) {
1902  qfx1_arr(i+1,j,k) = Qflux;
1903  } else {
1904  qfx1_arr(i,j,k) = Qflux;
1905  }
1906  } else if (dir == 1) {
1907  if (!is_low_face) {
1908  qfx2_arr(i,j+1,k) = Qflux;
1909  } else {
1910  qfx2_arr(i,j,k) = Qflux;
1911  }
1912  } else {
1913  if (!is_low_face) {
1914  qfx3_arr(i,j,k+1) = Qflux;
1915  } else {
1916  qfx3_arr(i,j,k) = Qflux;
1917  }
1918  }
1919  }
1920  });
1921  } // custom
1922 
1923  if (!rotate) {
1924  // Rho*u flux
1925  //============================================================================
1926  const IntVect stressx_nodal = (dir == 2) ? IntVect(1,0,1) : IntVect(1,1,0);
1927  Box bxx = convert(bx, stressx_nodal);
1928  const int stressx_face_index = is_low_face
1929  ? m_geom[lev].Domain().smallEnd(dir)
1930  : m_geom[lev].Domain().bigEnd(dir) + 1;
1931  bxx.setRange(dir, stressx_face_index);
1932  ParallelFor(bxx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1933  {
1934  // Valid tau13 from LSM and over land. A side that is land but
1935  // whose LSM flux is the sentinel (sea-ice / open water) is treated
1936  // as non-LSM so that side uses the MOST stress instead.
1937  Real stressx;
1938  int is_land_hi = (lmask_arr) ? lmask_arr(i ,j,0) : 1;
1939  int is_land_lo = (lmask_arr) ? lmask_arr(i-1,j,0) : 1;
1940  const int ihi = flux_col.i(i ,j), jhi = flux_col.j(i ,j);
1941  const int ilo = flux_col.i(i-1,j), jlo = flux_col.j(i-1,j);
1942  const bool has_land_and_flux_hi = (is_land_hi == 1 && lsm_flux.valid(ihi,jhi));
1943  const bool has_land_and_flux_lo = (is_land_lo == 1 && lsm_flux.valid(ilo,jlo));
1944  if (has_land_and_flux_hi || has_land_and_flux_lo) {
1945  const Real rho_hi = cons_arr(i ,j,k,Rho_comp);
1946  const Real rho_lo = cons_arr(i-1,j,k,Rho_comp);
1947  const Real most_stress = (!has_land_and_flux_hi || !has_land_and_flux_lo) ?
1948  flux_comp.compute_u_flux(i, j, k, dir,
1949  cons_arr, velx_arr, vely_arr, velz_arr,
1950  dir_umm_arr, um_arr, vm_arr, wm_arr, u_star_arr) : zero;
1952  rho_lo, rho_hi, surface_tau13_arr(ilo,jlo,0), surface_tau13_arr(ihi,jhi,0),
1953  has_land_and_flux_lo, has_land_and_flux_hi, most_stress);
1954  stressx = result.face_stress;
1955  // NOTE: do NOT write the MOST-fallback stress back into the
1956  // cell-centered lsm_tau13_arr. This face-indexed ParallelFor
1957  // touches cells (i) and (i-1), so each cell is written by two
1958  // adjacent face threads in the same launch -> nondeterministic
1959  // write-write race on GPU (ERF #3446). It also spuriously flips
1960  // a sentinel (water/unprocessed) cell to "valid LSM" for the
1961  // next step. The face stress is fully determined here; the LSM
1962  // cache is (re)filled only by Noah-MP. Matches baseline 3ab899d3.
1963  } else if (is_land_hi == 2 || is_land_lo == 2) { // no stress within buildings
1964  stressx = zero;
1965  } else {
1966  stressx = flux_comp.compute_u_flux(i, j, k, dir,
1967  cons_arr, velx_arr, vely_arr, velz_arr,
1968  dir_umm_arr, um_arr, vm_arr, wm_arr, u_star_arr);
1969  }
1970 
1971  // write out to corresponding face
1972  if (dir == 0) {
1973  t21_arr(i,j,k) = stressx;
1974  if (t12_arr &&
1975  (!ylo_surface || j != ylo_node) &&
1976  (!yhi_surface || j != yhi_node)) {
1977  t12_arr(i,j,k) = stressx;
1978  }
1979  } else if (dir == 1) {
1980  t12_arr(i,j,k) = stressx;
1981  if (t21_arr &&
1982  (!xlo_surface || i != xlo_node) &&
1983  (!xhi_surface || i != xhi_node)) {
1984  t21_arr(i,j,k) = stressx;
1985  }
1986  } else {
1987  t13_arr(i,j,k) = stressx;
1988  if (t31_arr &&
1989  (!xlo_surface || i != xlo_node) &&
1990  (!xhi_surface || i != xhi_node)) {
1991  t31_arr(i,j,k) = stressx;
1992  }
1993  }
1994  });
1995 
1996  // Rho*v flux
1997  //============================================================================
1998  const IntVect stressy_nodal = (dir == 0) ? IntVect(1,0,1) : IntVect(0,1,1);
1999  Box bxy = convert(bx, stressy_nodal);
2000  const int stressy_face_index = is_low_face
2001  ? m_geom[lev].Domain().smallEnd(dir)
2002  : m_geom[lev].Domain().bigEnd(dir) + 1;
2003  bxy.setRange(dir, stressy_face_index);
2004  ParallelFor(bxy, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2005  {
2006  // Valid tau23 from LSM and over land (sentinel side -> MOST stress)
2007  Real stressy;
2008  int is_land_hi = (lmask_arr) ? lmask_arr(i,j ,0) : 1;
2009  int is_land_lo = (lmask_arr) ? lmask_arr(i,j-1,0) : 1;
2010  const int ihi = flux_col.i(i,j ), jhi = flux_col.j(i,j );
2011  const int ilo = flux_col.i(i,j-1), jlo = flux_col.j(i,j-1);
2012  const bool has_land_and_flux_hi = (is_land_hi == 1 && lsm_flux.valid(ihi,jhi));
2013  const bool has_land_and_flux_lo = (is_land_lo == 1 && lsm_flux.valid(ilo,jlo));
2014  if (has_land_and_flux_hi || has_land_and_flux_lo) {
2015  const Real rho_hi = cons_arr(i,j ,k,Rho_comp);
2016  const Real rho_lo = cons_arr(i,j-1,k,Rho_comp);
2017  const Real most_stress = (!has_land_and_flux_hi || !has_land_and_flux_lo) ?
2018  flux_comp.compute_v_flux(i, j, k, dir,
2019  cons_arr, velx_arr, vely_arr, velz_arr,
2020  dir_umm_arr, um_arr, vm_arr, wm_arr, u_star_arr) : zero;
2022  rho_lo, rho_hi, surface_tau23_arr(ilo,jlo,0), surface_tau23_arr(ihi,jhi,0),
2023  has_land_and_flux_lo, has_land_and_flux_hi, most_stress);
2024  stressy = result.face_stress;
2025  // NOTE: no writeback into cell-centered lsm_tau23_arr -- see the
2026  // matching tau13 note above (ERF #3446 write-write race + stale
2027  // sentinel-becomes-valid). Face stress is complete here.
2028  } else if (is_land_hi == 2 || is_land_lo == 2) { // no stress within buildings
2029  stressy = zero;
2030  } else {
2031  stressy = flux_comp.compute_v_flux(i, j, k, dir,
2032  cons_arr, velx_arr, vely_arr, velz_arr,
2033  dir_umm_arr, um_arr, vm_arr, wm_arr, u_star_arr);
2034  }
2035 
2036  // write out to corresponding face
2037  if (dir == 0) {
2038  t31_arr(i,j,k) = stressy;
2039  if (t13_arr &&
2040  (!zlo_surface || k != zlo_node) &&
2041  (!zhi_surface || k != zhi_node)) {
2042  t13_arr(i,j,k) = stressy;
2043  }
2044  } else if (dir == 1) {
2045  t32_arr(i,j,k) = stressy;
2046  if (t23_arr &&
2047  (!zlo_surface || k != zlo_node) &&
2048  (!zhi_surface || k != zhi_node)) {
2049  t23_arr(i,j,k) = stressy;
2050  }
2051  } else {
2052  t23_arr(i,j,k) = stressy;
2053  if (t32_arr &&
2054  (!ylo_surface || j != ylo_node) &&
2055  (!yhi_surface || j != yhi_node)) {
2056  t32_arr(i,j,k) = stressy;
2057  }
2058  }
2059  });
2060  } else {
2061  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(dir == 2 && m_face.isLow(), "Stress rotation only supported for zlo face");
2062  // All fluxes with rotation
2063  //============================================================================
2064  Box bxxy = convert(bx, IntVect(1,1,0));
2065  ParallelFor(bxxy, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2066  {
2067  Real stresst = flux_comp.compute_u_flux(i, j, k, dir,
2068  cons_arr, velx_arr, vely_arr, velz_arr,
2069  dir_umm_arr, um_arr, vm_arr, wm_arr, u_star_arr);
2070  rotate_stress_tensor(i, j, k, dir, stresst, dxInv, zphys_arr,
2071  velx_arr, vely_arr, velz_arr,
2072  t11_arr, t22_arr, t33_arr,
2073  t12_arr, t21_arr,
2074  t13_arr, t31_arr,
2075  t23_arr, t32_arr);
2076  });
2077  }
2078 
2079  // For models that do not do iterations to yield u*/T*/q*,
2080  // fill these values from the fluxes that were computed.
2081 
2082  // NOTE: For LSM, this has been handled in "compute_sfc_params_from_lsm_fluxes"
2083  // NOTE: Fluxes here are for conserved quantities, we divide by rho
2085  constexpr Real eps = std::numeric_limits<Real>::epsilon();
2086  bool l_use_moisture = use_moisture;
2087  // With an imposed heat flux (most.surf_temp_flux) the flux stays on in calm
2088  // air, where u* -> 0: t*, q* and the Obukhov length then use u* floored at
2089  // 0.001 m/s, the floor of the MOST imposed-flux path (ERF_MOSTStress.H
2090  // USTARMIN), so they stay finite (t* = -F / 0.001 rather than -F / 2e-16).
2091  // The Ch form's flux vanishes with the wind and keeps the plain u*.
2092  const Real ustar_min = m_bulk_use_fixed_tflux ? Real(0.001) : eps;
2093  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int /*k*/)
2094  {
2095  Real rho = cons_arr(i,j,klo,Rho_comp);
2096  Real Thd = cons_arr(i,j,klo,RhoTheta_comp) / rho;
2097  Real qv = (l_use_moisture) ? cons_arr(i,j,klo,RhoQ1_comp) / rho : zero;
2098  Real Thv = Thd * (one + epsv*qv);
2099 
2100  Real tau = std::sqrt( t13_arr(i,j,klo)/rho * t13_arr(i,j,klo)/rho
2101  + t23_arr(i,j,klo)/rho * t23_arr(i,j,klo)/rho );
2102  u_star_arr(i,j,0) = amrex::max(std::sqrt(tau),eps);
2103  const Real ustar_d = amrex::max(u_star_arr(i,j,0), ustar_min);
2104 
2105  if (hfx3_arr(i,j,klo)>=zero) {
2106  t_star_arr(i,j,0) = amrex::min(-hfx3_arr(i,j,klo) / (rho * ustar_d),-eps);
2107  } else {
2108  t_star_arr(i,j,0) = amrex::max(-hfx3_arr(i,j,klo) / (rho * ustar_d),eps);
2109  }
2110  if (!l_use_moisture) {
2111  q_star_arr(i,j,0) = zero;
2112  } else if (qfx3_arr(i,j,klo)>=zero) {
2113  q_star_arr(i,j,0) = amrex::min(-qfx3_arr(i,j,klo) / (rho * ustar_d),-eps);
2114  } else {
2115  q_star_arr(i,j,0) = amrex::max(-qfx3_arr(i,j,klo) / ( rho * ustar_d),eps);
2116  }
2117  Real tstv = t_star_arr(i,j,0)*(one + epsv*qv) + epsv*Thd*q_star_arr(i,j,0);
2118  tstv = (tstv >= zero) ? amrex::max(tstv, eps) : amrex::min(tstv, -eps);
2119  olen_arr(i,j,0) = ( ustar_d * ustar_d * Thv ) /
2120  ( KAPPA * CONST_GRAV * tstv );
2121  z0_arr(i,j,0) = Compute_roughness(zref_arr(i,j,0), olen_arr(i,j,0),
2122  umm_arr(i,j,0), u_star_arr(i,j,0));
2123  });
2124  }
2125 
2126  } // mfiter
2127 
2129 }
@ tau12
Definition: ERF_DataStruct.H:51
@ tau23
Definition: ERF_DataStruct.H:51
@ tau33
Definition: ERF_DataStruct.H:51
@ tau22
Definition: ERF_DataStruct.H:51
@ tau11
Definition: ERF_DataStruct.H:51
@ tau32
Definition: ERF_DataStruct.H:51
@ tau31
Definition: ERF_DataStruct.H:51
@ tau21
Definition: ERF_DataStruct.H:51
@ tau13
Definition: ERF_DataStruct.H:51
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void rotate_scalar_flux(const int &i, const int &j, const int &klo, const int &, const amrex::Real &flux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &zphys_arr, const amrex::Array4< amrex::Real > &phi1_arr, const amrex::Array4< amrex::Real > &phi2_arr, const amrex::Array4< amrex::Real > &phi3_arr)
Definition: ERF_TerrainMetrics.H:1057
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void rotate_stress_tensor(const int &i, const int &j, const int &klo, const int &, const amrex::Real &flux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &zphys_arr, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &w_arr, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &tau13_arr, const amrex::Array4< amrex::Real > &tau31_arr, const amrex::Array4< amrex::Real > &tau23_arr, const amrex::Array4< amrex::Real > &tau32_arr)
Definition: ERF_TerrainMetrics.H:1101
const amrex::MultiFab * get_surface_current(const int &lev, int comp) const
Definition: ERF_SurfaceLayer.H:1605
amrex::Vector< std::unique_ptr< amrex::MultiFab > > surface_diagnostic_source
Definition: ERF_SurfaceLayer.H:2270
amrex::Vector< amrex::iMultiFab > m_lsm_held_columns
Definition: ERF_SurfaceLayer.H:2244
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_flux_lev
Definition: ERF_SurfaceLayer.H:2325
void fill_planar_boundary(const int &lev, amrex::MultiFab &mf)
Definition: ERF_SurfaceLayer.cpp:1000
amrex::Vector< std::string > m_lsm_flux_name
Definition: ERF_SurfaceLayer.H:2327
@ zvel
Definition: ERF_IndexDefines.H:234
bool covers_columns(const Array4< const Real > &a, const Box &b)
Definition: ERF_SurfaceLayer.cpp:185
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real to_plot_value(SurfaceDiagnosticSource source) noexcept
Definition: ERF_SurfaceDiagnosticSource.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SurfaceDiagnosticSource classify_scalar_source(bool is_custom, bool is_rico, bool is_land, bool has_lsm_flux, bool lsm_flux_is_valid) noexcept
Definition: ERF_SurfaceDiagnosticSource.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE FaceStressResult combine_lsm_and_most_stress(amrex::Real rho_low, amrex::Real rho_high, amrex::Real kinematic_low, amrex::Real kinematic_high, bool low_valid, bool high_valid, amrex::Real most_face_stress)
Definition: ERF_SurfaceLayerStress.H:47
Definition: ERF_SurfaceLayer.cpp:165
Here is the call graph for this function:

◆ compute_SurfaceLayer_bcs_EB() [1/2]

template<typename FluxCalc >
void SurfaceLayer::compute_SurfaceLayer_bcs_EB ( const int &  lev,
amrex::Vector< const amrex::MultiFab * >  mfs,
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &  Tau_lev,
amrex::MultiFab *  xheat_flux,
amrex::MultiFab *  yheat_flux,
amrex::MultiFab *  zheat_flux,
amrex::MultiFab *  xqv_flux,
amrex::MultiFab *  yqv_flux,
amrex::MultiFab *  zqv_flux,
const FluxCalc &  flux_comp 
)

Compute embedded-boundary surface-layer flux boundary conditions.

Parameters
[in]levlevel index
[in]mfsstate and velocity fields used by the BC computation
[in,out]Tau_levEB stress fields to fill
[in,out]xheat_fluxx-face heat flux field
[in,out]yheat_fluxy-face heat flux field
[in,out]zheat_fluxz-face heat flux field
[in,out]xqv_fluxx-face moisture flux field
[in,out]yqv_fluxy-face moisture flux field
[in,out]zqv_fluxz-face moisture flux field
[in]flux_compflux-computation functor

◆ compute_SurfaceLayer_bcs_EB() [2/2]

template<typename FluxCalc >
void SurfaceLayer::compute_SurfaceLayer_bcs_EB ( const int &  lev,
Vector< const MultiFab * >  mfs,
Vector< Vector< std::unique_ptr< MultiFab >>> &  Tau_EB,
[[maybe_unused] ] MultiFab *  xheat_flux,
[[maybe_unused] ] MultiFab *  yheat_flux,
MultiFab *  Hfx3_EB,
[[maybe_unused] ] MultiFab *  xqv_flux,
[[maybe_unused] ] MultiFab *  yqv_flux,
[[maybe_unused] ] MultiFab *  zqv_flux,
const FluxCalc &  flux_comp 
)

Function to calculate MOST fluxes for EB.

Parameters
[in]levCurrent level
[in]mfsState MultiFabs used to compute the EB boundary fluxes
[in,out]Tau_EBEB diffusive stress MultiFabs populated with surface stresses
[in,out]xheat_fluxx-face EB heat-flux MultiFab, currently unused
[in,out]yheat_fluxy-face EB heat-flux MultiFab, currently unused
[in,out]Hfx3_EBEB heat-flux MultiFab populated with scalar surface flux
[in,out]xqv_fluxx-face EB moisture-flux MultiFab, currently unused
[in,out]yqv_fluxy-face EB moisture-flux MultiFab, currently unused
[in,out]zqv_fluxz-face EB moisture-flux MultiFab, currently unused
[in]flux_compEB flux-calculation functor used to compute scalar and momentum fluxes
2157 {
2158  const int dir = m_face.coordDir();
2159  // Get EB flags for all centerings
2160  const auto& cc_factory = m_eb_vec[lev]->get_const_factory();
2161  const auto& cc_flags = cc_factory->getMultiEBCellFlagFab();
2162  const auto& cc_vfrac = cc_factory->getVolFrac();
2163 
2164  const auto& u_factory = m_eb_vec[lev]->get_u_const_factory();
2165  const auto& u_flags = u_factory->getMultiEBCellFlagFab();
2166  const auto& u_vfrac = u_factory->getVolFrac();
2167 
2168  const auto& v_factory = m_eb_vec[lev]->get_v_const_factory();
2169  const auto& v_flags = v_factory->getMultiEBCellFlagFab();
2170  const auto& v_vfrac = v_factory->getVolFrac();
2171 
2172  const auto& w_factory = m_eb_vec[lev]->get_w_const_factory();
2173  const auto& w_flags = w_factory->getMultiEBCellFlagFab();
2174  const auto& w_vfrac = w_factory->getVolFrac();
2175 
2176  // EB does not currently have a cell-centered scalar-source classification.
2177  // Keep the provenance mask missing rather than inventing face-aware
2178  // semantics for the staggered stress path.
2179  surface_diagnostic_source[lev]->setVal(
2181 
2182  for (MFIter mfi(*mfs[0]); mfi.isValid(); ++mfi)
2183  {
2184  // Get flags for this box (all centerings)
2185  const auto& cc_flag = cc_flags[mfi];
2186  const auto& u_flag = u_flags[mfi];
2187  const auto& v_flag = v_flags[mfi];
2188  const auto& w_flag = w_flags[mfi];
2189 
2190  // Skip boxes that have no cut cells at any centering
2191  if (cc_flag.getType() != FabType::singlevalued &&
2192  u_flag.getType() != FabType::singlevalued &&
2193  v_flag.getType() != FabType::singlevalued &&
2194  w_flag.getType() != FabType::singlevalued
2195  ) continue;
2196 
2197  // Get EB flag and volfrac arrays
2198  auto const cc_flag_arr = cc_flag.const_array();
2199  auto const u_flag_arr = u_flag.const_array();
2200  auto const v_flag_arr = v_flag.const_array();
2201  auto const w_flag_arr = w_flag.const_array();
2202 
2203  auto const cc_vfrac_arr = cc_vfrac.const_array(mfi);
2204  auto const u_vfrac_arr = u_vfrac.const_array(mfi);
2205  auto const v_vfrac_arr = v_vfrac.const_array(mfi);
2206  auto const w_vfrac_arr = w_vfrac.const_array(mfi);
2207 
2208  // Get boundary normals only if cut cells exist
2209  auto const bnorm_arr = (cc_flag.getType() == FabType::singlevalued) ?
2210  cc_factory->getBndryNormal().const_array(mfi) : Array4<const Real>{};
2211  auto const u_bnorm_arr = (u_flag.getType() == FabType::singlevalued) ?
2212  u_factory->getBndryNormal().const_array(mfi) : Array4<const Real>{};
2213  auto const v_bnorm_arr = (v_flag.getType() == FabType::singlevalued) ?
2214  v_factory->getBndryNormal().const_array(mfi) : Array4<const Real>{};
2215  auto const w_bnorm_arr = (w_flag.getType() == FabType::singlevalued) ?
2216  w_factory->getBndryNormal().const_array(mfi) : Array4<const Real>{};
2217 
2218  // Get field arrays
2219  const auto cons_arr = mfs[Vars::cons]->array(mfi);
2220  const auto velx_arr = mfs[Vars::xvel]->array(mfi);
2221  const auto vely_arr = mfs[Vars::yvel]->array(mfi);
2222  const auto velz_arr = mfs[Vars::zvel]->array(mfi);
2223 
2224  // Diffusive stress vars - t13 and t23 components for all grid types
2225  auto u_t13_arr = Tau_EB[EBTauType::tau_eb13][EBGridType::xface]->array(mfi);
2226  auto v_t13_arr = Tau_EB[EBTauType::tau_eb13][EBGridType::yface]->array(mfi);
2227  auto w_t13_arr = Tau_EB[EBTauType::tau_eb13][EBGridType::zface]->array(mfi);
2228 
2229  auto u_t23_arr = Tau_EB[EBTauType::tau_eb23][EBGridType::xface]->array(mfi);
2230  auto v_t23_arr = Tau_EB[EBTauType::tau_eb23][EBGridType::yface]->array(mfi);
2231  auto w_t23_arr = Tau_EB[EBTauType::tau_eb23][EBGridType::zface]->array(mfi);
2232 
2233  auto hfx3_arr = Hfx3_EB->array(mfi);
2234 
2235  // Get average arrays
2236  const auto *const u_mean = m_ma.get_average(lev,0);
2237  const auto *const v_mean = m_ma.get_average(lev,1);
2238  // const auto *const w_mean = m_ma.get_average(lev,2);
2239 
2240  const auto *const t_mean = m_ma.get_average(lev,3);
2241  // const auto *const q_mean = m_ma.get_average(lev,4);
2242  const auto *const u_mag_mean = m_ma.get_average(lev,6);
2243  const auto *const uw_mag_mean = m_ma.get_average(lev,7);
2244  const auto *const vw_mag_mean = m_ma.get_average(lev,8);
2245 
2246  const auto um_arr = u_mean->array(mfi);
2247  const auto vm_arr = v_mean->array(mfi);
2248  // const auto wm_arr = w_mean->array(mfi);
2249  const auto tm_arr = t_mean->array(mfi);
2250  // const auto qm_arr = q_mean->array(mfi);
2251  const auto umm_arr = u_mag_mean->array(mfi);
2252  const auto vwmm_arr = (dir == 0) ? vw_mag_mean->array(mfi) : Array4<Real>{};
2253  const auto uwmm_arr = (dir == 1) ? uw_mag_mean->array(mfi) : Array4<Real>{};
2254 
2255  // umm depending on face direction (YZ, XZ, XY)
2256  const auto dir_umm_arr = ((dir == 0) ? vwmm_arr : ((dir == 1) ? uwmm_arr : umm_arr));
2257 
2258  // Get derived arrays
2259  const auto u_star_arr = u_star[lev]->array(mfi);
2260  const auto t_star_arr = t_star[lev]->array(mfi);
2261  const auto t_surf_arr = t_surf[lev]->array(mfi);
2262 
2263  // Rho*Theta flux
2264  //============================================================================
2265  Box bx = mfi.tilebox();
2266  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2267  {
2268  if (cc_flag_arr(i,j,k).isSingleValued()) {
2269  Real Tflux = flux_comp.compute_t_flux(i, j, k,
2270  cons_arr, velx_arr, vely_arr, velz_arr,
2271  dir_umm_arr, tm_arr, u_star_arr,
2272  t_star_arr, t_surf_arr,
2273  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2274  bnorm_arr);
2275  hfx3_arr(i,j,k) = Tflux;
2276  }
2277  });
2278 
2279  // Rho*u flux
2280  //============================================================================
2281  Box bxx = surroundingNodes(bx,0);
2282  Box bxy = surroundingNodes(bx,1);
2283  Box bxz = surroundingNodes(bx,2);
2284  ParallelFor(bxx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2285  {
2286  if (u_flag_arr(i,j,k).isSingleValued()) {
2287  Real stressx = flux_comp.compute_u_flux(i, j, k,
2288  cons_arr, velx_arr, vely_arr, velz_arr,
2289  dir_umm_arr, um_arr, u_star_arr,
2290  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2291  cc_vfrac_arr, cc_flag_arr,
2292  u_bnorm_arr, 0);
2293  u_t13_arr(i,j,k) = stressx;
2294  }
2295  });
2296  ParallelFor(bxy, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2297  {
2298  if (v_flag_arr(i,j,k).isSingleValued()) {
2299  Real stressx = flux_comp.compute_u_flux(i, j, k,
2300  cons_arr, velx_arr, vely_arr, velz_arr,
2301  dir_umm_arr, um_arr, u_star_arr,
2302  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2303  cc_vfrac_arr, cc_flag_arr,
2304  v_bnorm_arr, 1);
2305  v_t13_arr(i,j,k) = stressx;
2306  }
2307  });
2308  ParallelFor(bxz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2309  {
2310  if (w_flag_arr(i,j,k).isSingleValued()) {
2311  Real stressx = flux_comp.compute_u_flux(i, j, k,
2312  cons_arr, velx_arr, vely_arr, velz_arr,
2313  dir_umm_arr, um_arr, u_star_arr,
2314  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2315  cc_vfrac_arr, cc_flag_arr,
2316  w_bnorm_arr, 2);
2317  w_t13_arr(i,j,k) = stressx;
2318  }
2319  });
2320 
2321  // Rho*v flux
2322  //============================================================================
2323  ParallelFor(bxx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2324  {
2325  if (u_flag_arr(i,j,k).isSingleValued()) {
2326  Real stressy = flux_comp.compute_v_flux(i, j, k,
2327  cons_arr, velx_arr, vely_arr, velz_arr,
2328  dir_umm_arr, vm_arr, u_star_arr,
2329  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2330  cc_vfrac_arr, cc_flag_arr, u_bnorm_arr, 0);
2331  u_t23_arr(i,j,k) = stressy;
2332  }
2333  });
2334  ParallelFor(bxy, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2335  {
2336  if (v_flag_arr(i,j,k).isSingleValued()) {
2337  Real stressy = flux_comp.compute_v_flux(i, j, k,
2338  cons_arr, velx_arr, vely_arr, velz_arr,
2339  dir_umm_arr, vm_arr, u_star_arr,
2340  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2341  cc_vfrac_arr, cc_flag_arr, v_bnorm_arr, 1);
2342  v_t23_arr(i,j,k) = stressy;
2343  }
2344  });
2345  ParallelFor(bxz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
2346  {
2347  if (w_flag_arr(i,j,k).isSingleValued()) {
2348  Real stressy = flux_comp.compute_v_flux(i, j, k,
2349  cons_arr, velx_arr, vely_arr, velz_arr,
2350  dir_umm_arr, vm_arr, u_star_arr,
2351  u_vfrac_arr, v_vfrac_arr, w_vfrac_arr,
2352  cc_vfrac_arr, cc_flag_arr, w_bnorm_arr, 2);
2353  w_t23_arr(i,j,k) = stressy;
2354  }
2355  });
2356  } // mfiter
2357 
2358 }
@ tau_eb23
Definition: ERF_EBStruct.H:22
@ tau_eb13
Definition: ERF_EBStruct.H:22
@ yface
Definition: ERF_EBStruct.H:29
@ zface
Definition: ERF_EBStruct.H:29
@ xface
Definition: ERF_EBStruct.H:29
Here is the call graph for this function:

◆ computes_pblh()

bool SurfaceLayer::computes_pblh ( ) const
inline

Do we actually compute the PBL height? If not then the field returned by get_pblh holds only the value it was initialized with, and must not be reported as a diagnostic.

1636 { return (pblh_type != PBLHeightCalcType::None); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ computes_w_star()

bool SurfaceLayer::computes_w_star ( ) const
inline

Do we actually compute w*? If not then the field returned by get_w_star holds only the value it was initialized with, and must not be reported as a diagnostic.

1630 { return m_include_wstar; }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ define_pblh_columns()

void SurfaceLayer::define_pblh_columns ( const int &  lev,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm 
)
private

Build the columns on which compute_pblh runs the PBL-height estimator when the grids of a level do not all start at the ground (see PBLHColumns). Called when the grids change.

Parameters
[in]levCurrent level
[in]baBoxArray of the state at this level
[in]dmDistributionMapping of the state at this level
3846 {
3847  PBLHColumns& cols = m_pblh_columns[lev];
3848  cols = PBLHColumns{};
3849  cols.ba = ba;
3850  cols.dm = dm;
3851 
3852  const int k_ground = m_geom[lev].Domain().smallEnd(2);
3853  const int k_top = m_geom[lev].Domain().bigEnd(2);
3854  for (int ib = 0; ib < ba.size(); ++ib) {
3855  if (ba[ib].smallEnd(2) != k_ground) { cols.needed = true; }
3856  }
3857 
3858  // The runs of cells in z, each as one box
3859  const BoxArray ba_joined = join_boxes_stacked_in_z(ba);
3860  for (int ib = 0; ib < ba_joined.size(); ++ib) {
3861  if (ba_joined[ib].smallEnd(2) != k_ground || ba_joined[ib].bigEnd(2) != k_top) { cols.full_height = false; }
3862  }
3863  if (!cols.needed) { return; }
3864 
3865  // With EB the surface-layer fields live on the 3D grids and the estimator writes their
3866  // k = 0 plane, which a box that does not start at the ground does not hold
3867  if (m_terrain_type == TerrainType::EB) {
3868  Abort("erf.most.pblh_calc = MYNN25 with EB needs every grid at level " + std::to_string(lev) +
3869  " to start at the bottom of the domain: the PBL height is written into the lowest "
3870  "plane of each grid. Choose grids that are not decomposed in z "
3871  "(amr.max_grid_size_z) and refined regions that reach the ground.");
3872  }
3873 
3874  // Those of the runs of cells in z that start at the ground are the columns. A column goes
3875  // to the rank that owns its lowest corner cell, which keeps most of the copies to and from
3876  // the columns on the rank.
3877  BoxList bl_col(IndexType::TheCellType());
3878  BoxList bl_col2d(IndexType::TheCellType());
3879  Vector<int> pmap;
3880  for (int ib = 0; ib < ba_joined.size(); ++ib) {
3881  const Box& b = ba_joined[ib];
3882  if (b.smallEnd(2) != k_ground) { continue; }
3883  const auto& owners = ba.intersections(Box(b.smallEnd(), b.smallEnd()));
3884  AMREX_ALWAYS_ASSERT(!owners.empty());
3885  Box b2d(b);
3886  b2d.setRange(2, k_ground);
3887  bl_col.push_back(b);
3888  bl_col2d.push_back(b2d);
3889  pmap.push_back(dm[owners[0].first]);
3890  }
3891  if (bl_col.isEmpty()) { return; }
3892 
3893  cols.ba_col = BoxArray(std::move(bl_col));
3894  cols.ba_col2d = BoxArray(std::move(bl_col2d));
3895  cols.dm_col = DistributionMapping(std::move(pmap));
3896 
3897  // These hold no data. AMReX drops the communication metadata of a BoxArray and
3898  // DistributionMapping pair with the last FabArray built on it, and the MultiFabs that
3899  // compute_pblh builds on the columns are temporaries.
3900  cols.hold_col.define(cols.ba_col, cols.dm_col, 1, 0, MFInfo().SetAlloc(false));
3901  cols.hold_col2d.define(cols.ba_col2d, cols.dm_col, 1, 0, MFInfo().SetAlloc(false));
3902 }
BoxArray join_boxes_stacked_in_z(const BoxArray &ba)
Definition: ERF_TerrainMetrics.cpp:154
Here is the call graph for this function:

◆ define_relative_velocities()

void SurfaceLayer::define_relative_velocities ( const int &  lev,
const amrex::MultiFab &  xvel,
const amrex::MultiFab &  yvel,
int  k_top 
)

Allocate the velocities relative to the surface current, over the planes the averages read: each box of the velocities from its lower end to k_top.

Parameters
[in]levlevel index
[in]xvelx-velocity on the level
[in]yvely-velocity on the level
[in]k_tophighest k the averages read (MOSTAverage::max_k_read)
417 {
418  // The averages read the velocities only up to k_top (MOSTAverage::max_k_read), so
419  // each box of the velocities is held from its lower end to k_top, with its ghost
420  // cells; a box wholly above k_top keeps a single plane, which is never read
421  m_rel_k_top[lev] = k_top;
422  for (int dir = 0; dir < 2; ++dir) {
423  const MultiFab& vel = (dir == 0) ? xvel : yvel;
424  auto& rel = (dir == 0) ? m_rel_xvel[lev] : m_rel_yvel[lev];
425  BoxList bl = vel.boxArray().boxList();
426  for (auto& b : bl) { b.setBig(2, amrex::max(b.smallEnd(2), amrex::min(b.bigEnd(2), k_top))); }
427  rel = std::make_unique<MultiFab>(BoxArray(std::move(bl)), vel.DistributionMap(), 1,
428  vel.nGrowVect());
429  }
430  m_rel_src_ba[lev] = xvel.boxArray();
431 }

◆ define_surface_current()

void SurfaceLayer::define_surface_current ( const int &  lev,
const amrex::MultiFab &  xvel,
const amrex::MultiFab &  yvel 
)

Allocate the surface current for this level's velocities and set it over the water, and allocate the velocities relative to it over the planes the averages read.

The current is held on the x- and y-faces of the plane k = klo, one 2D box for each box of the velocities, with their lateral ghost cells. Only water moves: a face takes the current where the cells on both sides of it are water (land mask 0), and is at rest elsewhere.

Parameters
[in]levlevel index
[in]xvelx-velocity on the level
[in]yvely-velocity on the level
326 {
327  const int klo = m_geom[lev].Domain().smallEnd(2);
328 
329  for (int dir = 0; dir < 2; ++dir) {
330  const MultiFab& vel = (dir == 0) ? xvel : yvel;
331  auto& current = (dir == 0) ? m_surface_current_x[lev] : m_surface_current_y[lev];
332 
333  // One 2D box at k = klo for each box of the velocity, on its faces and with its
334  // lateral ghost cells
335  BoxList bl = vel.boxArray().boxList();
336  for (auto& b : bl) { b.setRange(2, klo); }
337  const IntVect ng(vel.nGrowVect()[0], vel.nGrowVect()[1], 0);
338  current = std::make_unique<MultiFab>(BoxArray(std::move(bl)), vel.DistributionMap(), 1, ng);
339  }
340  // From the coupler's last current, if it has sent one, so a remade level does not lose it
342 
344 }
void fill_surface_current(const int &lev)
Definition: ERF_SurfaceLayer.cpp:347
@ ng
Definition: ERF_Morrison.H:51

Referenced by make_SurfaceLayer_at_level().

Here is the caller graph for this function:

◆ fill_lateral_surface_parameter_ghosts()

void SurfaceLayer::fill_lateral_surface_parameter_ghosts ( const int &  lev,
amrex::MultiFab *  selected_field = nullptr 
)

Fills surface layer data for lateral faces. A normal FillBoundary on lateral faces would bring in data from other ranks or interior grids that do not own data on the lateral face.

Parameters
[in]levlevel index
[in,out]selected_fieldif non-null, fill only this field; otherwise fill all lateral surface fields
1291 {
1292  const int dir = m_face.coordDir();
1293  AMREX_ALWAYS_ASSERT(dir < 2);
1294 
1295  const iMultiFab& surface_mask = *m_lmask_lev[lev][0];
1296  const int face_index = m_face.isLow()
1297  ? m_geom[lev].Domain().smallEnd(dir)
1298  : m_geom[lev].Domain().bigEnd(dir);
1299  const auto& mask_ba = surface_mask.boxArray();
1300 
1301  IntVect period = m_geom[lev].periodicity().intVect();
1302  period[dir] = 0; // The selected wall is not a periodic source plane.
1303  const Periodicity tangential_periodicity(period);
1304 
1305  Vector<MultiFab*> fields;
1306  if (selected_field) {
1307  fields.push_back(selected_field);
1308  } else {
1309  const Vector<MultiFab*> all_fields{
1310  u_star[lev].get(), t_star[lev].get(), q_star[lev].get(), olen[lev].get(),
1311  t_surf[lev].get(), q_surf[lev].get(), pblh[lev].get(),
1312  surface_diagnostic_source[lev].get()};
1313  for (MultiFab* field : all_fields) {
1314  if (field) { fields.push_back(field); }
1315  }
1316  if (m_include_wstar && w_star[lev]) { fields.push_back(w_star[lev].get()); }
1317  }
1318 
1319  for (MultiFab* field : fields) {
1320  // Each parameter field owns its own index type and BoxArray. Build
1321  // the compact layout from that field rather than reusing u_star's
1322  // layout for all parameters.
1323  BoxList face_boxes;
1324  Vector<int> face_pmap;
1325  Vector<int> source_indices;
1326  const auto& source_ba = field->boxArray();
1327  const auto& source_pmap = field->DistributionMap().ProcessorMap();
1328  for (int ibox = 0; ibox < mask_ba.size(); ++ibox) {
1329  const Box& mask_box = mask_ba[ibox];
1330  const bool owns_face = m_face.isLow()
1331  ? mask_box.smallEnd(dir) == face_index
1332  : mask_box.bigEnd(dir) == face_index;
1333  if (!owns_face) { continue; }
1334 
1335  face_boxes.push_back(source_ba[ibox]);
1336  face_pmap.push_back(source_pmap[ibox]);
1337  source_indices.push_back(ibox);
1338  }
1339  if (face_boxes.isEmpty()) { continue; }
1340 
1341  BoxArray face_ba(std::move(face_boxes));
1342  DistributionMapping face_dm(std::move(face_pmap));
1343  MultiFab face_values(face_ba, face_dm, 1, field->nGrowVect());
1344 
1345  // Selectively gather only face-owned FABs. A direct FillBoundary on
1346  // field would also treat interior-grid FABs as valid sources because
1347  // all lateral FABs collapse onto the same wall plane.
1348  for (MFIter fmfi(face_values, false); fmfi.isValid(); ++fmfi) {
1349  const int compact_index = fmfi.index();
1350  const int source_index = source_indices[compact_index];
1351  const auto src = field->const_array(source_index);
1352  const auto dst = face_values.array(fmfi);
1353  // Preserve the source FAB's existing ghosts. A nonperiodic
1354  // physical ghost has no FillBoundary source, so leaving the
1355  // temporary FAB uninitialized would replace a valid local value
1356  // with garbage at mixed-face corners.
1357  Box source_fab = field->boxArray()[source_index];
1358  source_fab.grow(field->nGrowVect());
1359  const Box copy_box = fmfi.fabbox() & source_fab;
1361  !copy_box.isEmpty(),
1362  "Temporary surface-layer source copy has no valid overlap.");
1363  ParallelFor(copy_box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1364  {
1365  dst(i,j,k) = src(i,j,k);
1366  });
1367  }
1368  Gpu::streamSynchronize();
1369 
1370  face_values.FillBoundary(tangential_periodicity);
1371 
1372  for (MFIter fmfi(face_values, false); fmfi.isValid(); ++fmfi) {
1373  const int compact_index = fmfi.index();
1374  const int source_index = source_indices[compact_index];
1375  const auto src = face_values.const_array(fmfi);
1376  const auto dst = field->array(source_index);
1377  Box source_fab = field->boxArray()[source_index];
1378  source_fab.grow(field->nGrowVect());
1379  const Box copy_box = fmfi.fabbox() & source_fab;
1381  !copy_box.isEmpty(),
1382  "Mapped surface-layer ghost copy has no valid overlap with its source FAB.");
1383  ParallelFor(copy_box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1384  {
1385  dst(i,j,k) = src(i,j,k);
1386  });
1387  }
1388  }
1389  Gpu::streamSynchronize();
1390 }
Here is the call graph for this function:

◆ fill_pblh_from_coarser()

void SurfaceLayer::fill_pblh_from_coarser ( const int &  lev)

Set the PBL height of a refined level whose grids do not run from the ground to the top of the domain in every column from the next coarser level, column by column (see compute_pblh). Public because it launches a device lambda.

Parameters
[in]levCurrent level (> 0)

Set the PBL height of a refined level from the next coarser level: each column of this level takes the height of the coarse column that holds it. Used for a level whose grids do not run from the ground to the top of the domain in every column (see compute_pblh).

Parameters
[in]levCurrent level (> 0)
3913 {
3914  AMREX_ALWAYS_ASSERT(lev > 0 && pblh[lev]);
3915  inject_pblh_from_coarser(lev, *pblh[lev]);
3916  fill_planar_boundary(lev, *pblh[lev]);
3917 }
void inject_pblh_from_coarser(const int &lev, amrex::MultiFab &fine) const
Definition: ERF_SurfaceLayer.cpp:3927
Here is the call graph for this function:

◆ fill_planar_boundary()

void SurfaceLayer::fill_planar_boundary ( const int &  lev,
amrex::MultiFab &  mf 
)

Fill the ghost cells of a planar surface-layer MultiFab, and the valid region of its uncomputed copies when the 3D BoxArray is split in z (see PlanarBoundary).

Parameters
[in]levlevel index
[in,out]mfplanar MultiFab to fill

Fill the ghost cells of a planar surface-layer MultiFab.

The planar MultiFabs hold one box per 3D box, so a 3D BoxArray split in z gives duplicate planar boxes of which only the surface copy is computed; a FillBoundary could then fill a ghost cell from an uncomputed copy (see PlanarBoundary). With the split, the valid region of the uncomputed copies is filled as well. With EB terrain the fields are 3D and FillBoundary is well defined.

On a z face, the ghost cells beyond a non-periodic lateral edge are then given one value per cell, that of the grid holding the column they face (reconcile_outside_domain): next to a box seam two grids hold such a cell, and each producer fills its own copy from its own grid. So these fields do not depend on the decomposition there, and a checkpoint, which keeps one copy, restarts from the same values.

Parameters
[in]levCurrent level
[in,out]mfPlanar MultiFab to fill
1001 {
1002  // PlanarBoundary handles both z-low and z-high z-collapsed arrays split
1003  // in z. EB fields use ordinary FillBoundary because their 3-D layout has
1004  // no duplicate collapsed surface boxes. Lateral planar fields need a
1005  // selective exchange so an interior grid cannot provide wall data.
1006  if (m_terrain_type == TerrainType::EB) {
1007  mf.FillBoundary(m_geom[lev].periodicity());
1008  } else if (m_face.coordDir() != 2) {
1010  } else {
1011  m_planar_bndry[lev].fill(mf, m_geom[lev].periodicity());
1012  m_planar_bndry[lev].reconcile_outside_domain(mf, m_geom[lev]);
1013  }
1014 }
void fill_lateral_surface_parameter_ghosts(const int &lev, amrex::MultiFab *selected_field=nullptr)
Definition: ERF_SurfaceLayer.cpp:1289

◆ fill_qsurf_with_qsat() [1/2]

void SurfaceLayer::fill_qsurf_with_qsat ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd 
)

Fill surface moisture from saturation specific humidity.

Parameters
[in]levlevel index
[in]cons_inconserved state used to evaluate surface pressure
[in]z_phys_ndnodal physical-height field

◆ fill_qsurf_with_qsat() [2/2]

void SurfaceLayer::fill_qsurf_with_qsat ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

◆ fill_qsurf_with_skin_moisture() [1/2]

void SurfaceLayer::fill_qsurf_with_skin_moisture ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd 
)

Overwrite the land surface mixing ratio from the external skin temperature and the moisture field of set_skin_moisture, with q_air the reference-height mixing ratio the flux uses. Without resistances: beta * q_sat(T_skin, p_s) + (1 - beta) * q_air (erf_surface_moisture::surface_mixing_ratio) with beta the soil-water factor, so the moisture flux is beta times the potential one. With resistances: erf_surface_moisture::two_source_surface_mixing_ratio of the aerodynamic resistance (from the last u* and Obukhov length; neutral before the first flux), the canopy resistance with its vapor-deficit factor, the soil resistance and the soil pore air's relative humidity. Needs set_skin_temperature and the averages of this step.

Parameters
[in]levlevel index
[in]cons_inconserved state (surface pressure and q_air from the lowest cell)
[in]z_phys_ndnodal heights, or nullptr on a flat mesh

◆ fill_qsurf_with_skin_moisture() [2/2]

void SurfaceLayer::fill_qsurf_with_skin_moisture ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

◆ fill_surface_current()

void SurfaceLayer::fill_surface_current ( const int &  lev)

Set the surface current on this level's faces: the uniform most.surface_current, or the coupler's last current (update_coupled_surface_current), with water on both sides of a face and, with a coupler, the ocean covering both cells; at rest elsewhere.

Parameters
[in]levlevel index
348 {
349  MultiFab& current_x = *m_surface_current_x[lev];
350  MultiFab& current_y = *m_surface_current_y[lev];
351 
352  // The land mask, on one 2D box for each box of the current, carries one more lateral
353  // ghost cell than the current, so both cells beside every face are in it
354  const iMultiFab* lmask = (lev < static_cast<int>(m_lmask_lev.size()) &&
355  !m_lmask_lev[lev].empty()) ? m_lmask_lev[lev][0] : nullptr;
356  const IntVect ng = current_x.nGrowVect() + IntVect(1, 1, 0);
357  const NearestColumn in_domain = surface_columns(m_geom[lev], ng);
358 
359  // The coupler's current at the cells of the surface, laid out like the land mask; ghost
360  // cells inside the domain or its periodic images take the coupler's values
361  const bool coupled = lev < static_cast<int>(m_coupled_current_east_lev.size()) &&
363  MultiFab east_north;
364  iMultiFab cover;
365  CoupledCurrentCells cells{&east_north, nullptr, &cover};
366  if (coupled) {
367  BoxList bl = convert(current_x.boxArray(), IntVect(0)).boxList();
368  for (auto& b : bl) { b.setRange(2, 0); }
369  const BoxArray ba(std::move(bl));
370  const DistributionMapping& dm = current_x.DistributionMap();
371  const Periodicity period = m_geom[lev].periodicity();
372 
373  east_north.define(ba, dm, 2, ng);
374  east_north.setVal(zero);
375  east_north.ParallelCopy(*m_coupled_current_east_lev[lev], 0, 0, 1, IntVect(0), ng, period);
376  east_north.ParallelCopy(*m_coupled_current_north_lev[lev], 0, 1, 1, IntVect(0), ng, period);
377  // The orientation does not change between calls, so its copy is kept
378  auto& rotation = m_coupled_rotation_lev[lev];
379  const MultiFab* cos_src = (m_coupled_current_cos_lev[lev] && m_coupled_current_sin_lev[lev])
380  ? m_coupled_current_cos_lev[lev] : nullptr;
381  // Remade when the orientation is another array, or the same one remade on another
382  // layout, or the surface's own layout has changed
383  if (!rotation || rotation->boxArray() != ba || rotation->DistributionMap() != dm ||
384  m_coupled_rotation_src_lev[lev] != cos_src ||
385  (cos_src && (cos_src->boxArray() != m_coupled_rotation_src_ba_lev[lev] ||
386  cos_src->DistributionMap() != m_coupled_rotation_src_dm_lev[lev]))) {
387  rotation = std::make_unique<MultiFab>(ba, dm, 2, ng);
388  rotation->setVal(one, 0, 1, ng);
389  rotation->setVal(zero, 1, 1, ng);
390  if (cos_src) {
391  rotation->ParallelCopy(*m_coupled_current_cos_lev[lev], 0, 0, 1, IntVect(0), ng, period);
392  rotation->ParallelCopy(*m_coupled_current_sin_lev[lev], 0, 1, 1, IntVect(0), ng, period);
393  }
394  m_coupled_rotation_src_lev[lev] = cos_src;
395  if (cos_src) {
396  m_coupled_rotation_src_ba_lev[lev] = cos_src->boxArray();
397  m_coupled_rotation_src_dm_lev[lev] = cos_src->DistributionMap();
398  }
399  }
400  cells.rotation = rotation.get();
401  cover.define(ba, dm, 1, ng);
402  cover.setVal(0);
404  cover.ParallelCopy(*m_coupled_current_covered_lev[lev], 0, 0, 1, IntVect(0), ng, period);
405  }
406  }
407 
408  fill_face_current(current_x, 0, lmask, in_domain, m_surface_current_const[0],
409  coupled ? &cells : nullptr);
410  fill_face_current(current_y, 1, lmask, in_domain, m_surface_current_const[1],
411  coupled ? &cells : nullptr);
412 }
amrex::Vector< const amrex::MultiFab * > m_coupled_current_east_lev
Definition: ERF_SurfaceLayer.H:2300
amrex::Vector< const amrex::MultiFab * > m_coupled_current_north_lev
Definition: ERF_SurfaceLayer.H:2301
amrex::Vector< const amrex::iMultiFab * > m_coupled_current_covered_lev
Definition: ERF_SurfaceLayer.H:2302
amrex::Vector< const amrex::MultiFab * > m_coupled_current_sin_lev
Definition: ERF_SurfaceLayer.H:2304
amrex::Vector< const amrex::MultiFab * > m_coupled_rotation_src_lev
Definition: ERF_SurfaceLayer.H:2309
amrex::Vector< amrex::DistributionMapping > m_coupled_rotation_src_dm_lev
Definition: ERF_SurfaceLayer.H:2311
amrex::Vector< amrex::BoxArray > m_coupled_rotation_src_ba_lev
Definition: ERF_SurfaceLayer.H:2310
amrex::Vector< const amrex::MultiFab * > m_coupled_current_cos_lev
Definition: ERF_SurfaceLayer.H:2303
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_coupled_rotation_lev
Definition: ERF_SurfaceLayer.H:2308
NearestColumn surface_columns(const Geometry &geom, const IntVect &ng)
Definition: ERF_SurfaceLayer.cpp:207
void fill_face_current(MultiFab &current, int dir, const iMultiFab *lmask, const NearestColumn &in_domain, Real speed, const CoupledCurrentCells *coupled)
Definition: ERF_SurfaceLayer.cpp:244
Definition: ERF_SurfaceLayer.cpp:223
Here is the call graph for this function:

◆ fill_tsurf_with_abs_surf_temp()

void SurfaceLayer::fill_tsurf_with_abs_surf_temp ( const int &  lev,
const double &  time,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

Set t_surf from the prescribed absolute surface temperature (most.abs_surf_temp, plus most.surf_heating_rate times the time), converted to the potential temperature the surface layer works in with the pressure at the surface diagnosed from the lowest cell, as for coupled SST. Like update_surf_temp, which it replaces in that case, it writes every cell of the surface.

Parameters
[in]levlevel index
[in]timeelapsed simulation time
[in]cons_inconserved state used to evaluate surface pressure
[in]z_phys_ndnodal physical-height field

Set t_surf from the prescribed absolute surface temperature, converted to potential temperature at the surface pressure.

Parameters
[in]levCurrent level
[in]timeElapsed time, for the heating rate
[in]cons_inConserved state (surface pressure from the lowest cell)
[in]z_phys_ndNodal heights, or nullptr on a flat mesh
3272 {
3273  const Real t_abs = surf_temp + surf_heating_rate * static_cast<Real>(time);
3274  if (surf_heating_rate != 0) {
3275  amrex::Print() << "Surface temp (absolute) at t=" << time << ": " << t_abs << std::endl;
3276  }
3277 
3278  const int klo = m_geom[lev].Domain().smallEnd(2);
3279  const Real dz = m_geom[lev].CellSize(2);
3280  const bool moist = use_moisture;
3281  const Real rdOcp = m_rdOcp;
3282  // As in fill_tsurf_with_coupled_sst: a moist run whose state lacks the vapor
3283  // component aborts below rather than reading past the components.
3284  const bool have_rho_qv = cons_in.nComp() > RhoQ1_comp;
3285 
3286  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
3287  {
3288  Box gtbx = mfi.growntilebox();
3289  if (gtbx.smallEnd(2) != klo ||
3290  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
3291  continue;
3292  }
3293  gtbx &= t_surf[lev]->fabbox(mfi.index());
3294  if (gtbx.isEmpty()) { continue; }
3295 
3296  // The halo takes the pressure of the nearest valid column; fill_planar_boundary
3297  // in update_fluxes then fills the interior and periodic ghosts.
3298  const Box vbx = mfi.validbox();
3299  const int i_lo = vbx.smallEnd(0); const int i_hi = vbx.bigEnd(0);
3300  const int j_lo = vbx.smallEnd(1); const int j_hi = vbx.bigEnd(1);
3301 
3302  auto t_surf_arr = t_surf[lev]->array(mfi);
3303  const auto cons_arr = cons_in.const_array(mfi);
3304  const auto z_arr = (z_phys_nd) ? z_phys_nd->const_array(mfi) :
3305  Array4<const Real> {};
3306 
3307  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
3308  {
3309  const int li = amrex::min(amrex::max(i, i_lo), i_hi);
3310  const int lj = amrex::min(amrex::max(j, j_lo), j_hi);
3311 
3312  // The state is checked before it is divided by, as in fill_tsurf_with_coupled_sst,
3313  // so that a bad state reaches the diagnostic rather than a floating-point trap.
3314  const Real rho = cons_arr(li,lj,klo,Rho_comp);
3315  const Real rho_theta = cons_arr(li,lj,klo,RhoTheta_comp);
3316  const Real rho_qv = (moist && have_rho_qv)
3317  ? cons_arr(li,lj,klo,RhoQ1_comp) : Real(0.0);
3318  const Real delta_z = z_arr
3319  ? Compute_Z_AtCellCenter(li,lj,klo,z_arr) -
3320  Compute_Z_AtWFace(li,lj,klo,z_arr)
3321  : myhalf*dz;
3323  fail, true, li, lj, klo, rho, rho_theta, rho_qv,
3324  moist, have_rho_qv, delta_z, t_abs);
3326  return;
3327  }
3328  Real theta = t_surf_arr(i,j,k);
3330  t_abs, pressure.pressure, rdOcp, theta)) {
3331  t_surf_arr(i,j,k) = theta;
3332  } else {
3334  li, lj, klo, rho, rho_theta, rho_qv, t_abs,
3335  pressure.pressure, delta_z);
3336  }
3337  });
3338  }
3339 }
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtCellCenter(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:717
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtWFace(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:741
@ theta
Definition: ERF_Kessler.H:26
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool temperature_to_theta(const amrex::Real temperature, const amrex::Real pressure, const amrex::Real rdOcp, amrex::Real &theta)
Definition: ERF_SurfaceTemperature.H:155
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void record_conversion_failure(ConversionFailure *fail, const bool fatal, const ConversionError code, const int i, const int j, const int k, const amrex::Real rho=amrex::Real(0.0), const amrex::Real rho_theta=amrex::Real(0.0), const amrex::Real rho_qv=amrex::Real(0.0), const amrex::Real t_surf=amrex::Real(0.0), const amrex::Real pressure=amrex::Real(0.0), const amrex::Real delta_z=amrex::Real(0.0), const amrex::Real q_air=amrex::Real(0.0))
Definition: ERF_SurfaceTemperature.H:298
AMREX_GPU_DEVICE AMREX_FORCE_INLINE SurfacePressureResult diagnose_and_record_surface_pressure(ConversionFailure *fail, const bool fatal, const int i, const int j, const int k, const amrex::Real rho, const amrex::Real rho_theta, const amrex::Real rho_qv, const bool moist, const bool have_rho_qv, const amrex::Real delta_z, const amrex::Real surface_temperature=amrex::Real(0.0))
Definition: ERF_SurfaceTemperature.H:336
Here is the call graph for this function:

◆ fill_tsurf_with_coupled_sst()

void SurfaceLayer::fill_tsurf_with_coupled_sst ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

Overwrite surface temperature with coupled ocean SST where the coupler covers the cell.

Runs after fill_tsurf_with_sst_and_tsk so that the lower-boundary data is the base layer: land cells, and water cells with no ocean donor, keep the value written there.

Parameters
[in]levlevel index

Overwrite surface temperature with coupled ocean SST where covered.

Parameters
[in]levCurrent level
3143 {
3144  // No coupler has handed us anything yet. Whatever fill_tsurf_with_sst_and_tsk
3145  // wrote stands, which is the correct answer for one-way and uncoupled runs.
3146  if (m_coupled_sst_lev.empty() || !m_coupled_sst_lev[lev]) { return; }
3147 
3148  // The loop below iterates t_surf and indexes the coupled arrays with the
3149  // same MFIter, so the layouts must agree. They do for planar terrain, where
3150  // t_surf is grids[lev] flattened with setRange(2,0) -- the same construction
3151  // GetOceanToAtmosSurfaceLayout reports. Under EB terrain t_surf keeps the
3152  // full 3D BoxArray and they would not, so fail loudly rather than read the
3153  // wrong fab.
3155  m_coupled_sst_lev[lev]->boxArray() == t_surf[lev]->boxArray() &&
3156  m_coupled_sst_lev[lev]->DistributionMap() == t_surf[lev]->DistributionMap(),
3157  "Coupled SST layout does not match the surface-layer layout.");
3158 
3159  const int klo = m_geom[lev].Domain().smallEnd(2);
3160  const Real dz = m_geom[lev].CellSize(2);
3161  const bool moist = use_moisture;
3162  const bool have_rho_qv = cons_in.nComp() > RhoQ1_comp;
3163  const Real rdOcp = m_rdOcp;
3164  const NearestColumn column = surface_columns(m_geom[lev], t_surf[lev]->nGrowVect());
3165 
3166  // Absent coverage information we must assume nothing is covered: silently
3167  // treating the whole field as valid is how an uncovered cell ends up holding
3168  // the remap's zero fill. Every cell then keeps what the earlier producers wrote.
3169  if (m_coupled_sst_valid_lev[lev] == nullptr) { return; }
3170 
3171  // The coupled lane does not carry lateral ghost cells. Give the SST and its coverage
3172  // the halo of t_surf, filled from the valid cells that own it (interior and periodic
3173  // images), so that the halo, like the valid region, reads the column that
3174  // surface_columns picks and not one that depends on the box. Ghost cells
3175  // outside a non-periodic domain edge are left unfilled: that column is clamped into
3176  // the domain and never reads them.
3177  const IntVect ng_halo = t_surf[lev]->nGrowVect();
3178  MultiFab sst_halo(t_surf[lev]->boxArray(), t_surf[lev]->DistributionMap(), 1, ng_halo);
3179  iMultiFab valid_halo(t_surf[lev]->boxArray(), t_surf[lev]->DistributionMap(), 1, ng_halo);
3180  sst_halo.setVal(zero);
3181  valid_halo.setVal(0);
3182  sst_halo.ParallelCopy(*m_coupled_sst_lev[lev], 0, 0, 1, IntVect(0), ng_halo,
3183  m_geom[lev].periodicity());
3184  valid_halo.ParallelCopy(*m_coupled_sst_valid_lev[lev], 0, 0, 1, IntVect(0), ng_halo,
3185  m_geom[lev].periodicity());
3186 
3187  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
3188  {
3189  Box gtbx = mfi.growntilebox();
3190 
3191  if (gtbx.smallEnd(2) != klo ||
3192  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
3193  continue;
3194  }
3195 
3196  const int donor_k = t_surf[lev]->boxArray()[mfi.index()].smallEnd(2);
3197  gtbx &= t_surf[lev]->fabbox(mfi.index());
3198  if (gtbx.isEmpty()) { continue; }
3199 
3200  auto t_surf_arr = t_surf[lev]->array(mfi);
3201  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
3202  Array4<int> {};
3203  const auto coupled_sst_arr = sst_halo.const_array(mfi);
3204  const auto valid_arr = valid_halo.const_array(mfi);
3205  const auto cons_arr = cons_in.const_array(mfi);
3206  const auto z_arr = (z_phys_nd) ? z_phys_nd->const_array(mfi) :
3207  Array4<const Real> {};
3208 
3209  // Only a cell of this box decides whether a conversion failure aborts; a halo
3210  // cell, which reads the state of a column another box owns, is only reported.
3211  // Nothing is lost where that column is valid on this level: its own box reads the
3212  // same column and aborts. A halo cell whose column lies in a coarse/fine ghost
3213  // region has no such box, and on a failure keeps whatever an earlier producer
3214  // wrote there (as in fill_tsurf_with_sst_and_tsk).
3215  const Box vbx = mfi.validbox();
3216  const int i_lo = vbx.smallEnd(0); const int i_hi = vbx.bigEnd(0);
3217  const int j_lo = vbx.smallEnd(1); const int j_hi = vbx.bigEnd(1);
3218 
3219  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
3220  {
3221  const bool authoritative = (i >= i_lo) && (i <= i_hi) && (j >= j_lo) && (j <= j_hi);
3222  const int li = column.i(i);
3223  const int lj = column.j(j);
3224  int is_land = (lmask_arr) ? lmask_arr(li,lj,0) : 1;
3225  if (is_land) { return; }
3226 
3227  if (valid_arr(li,lj,donor_k) == 0) { return; }
3228 
3229  const Real rho = cons_arr(li,lj,klo,Rho_comp);
3230  const Real rho_theta = cons_arr(li,lj,klo,RhoTheta_comp);
3231  const Real rho_qv = (moist && have_rho_qv)
3232  ? cons_arr(li,lj,klo,RhoQ1_comp) : Real(0.0);
3233  const Real delta_z = z_arr
3234  ? Compute_Z_AtCellCenter(li,lj,klo,z_arr) -
3235  Compute_Z_AtWFace(li,lj,klo,z_arr)
3236  : myhalf*dz;
3237  const Real t_abs = coupled_sst_arr(li,lj,donor_k);
3239  fail, authoritative, li, lj, klo, rho, rho_theta, rho_qv,
3240  moist, have_rho_qv, delta_z, t_abs);
3242  return;
3243  }
3244  Real theta = t_surf_arr(i,j,k);
3246  t_abs, pressure.pressure, rdOcp, theta)) {
3247  t_surf_arr(i,j,k) = theta;
3248  } else {
3250  li, lj, klo, rho, rho_theta, rho_qv, t_abs,
3251  pressure.pressure, delta_z);
3252  }
3253  });
3254  }
3255 }
amrex::Vector< amrex::MultiFab * > m_coupled_sst_lev
Definition: ERF_SurfaceLayer.H:2283
amrex::Vector< amrex::iMultiFab * > m_coupled_sst_valid_lev
Definition: ERF_SurfaceLayer.H:2284
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int j(int jj) const noexcept
Definition: ERF_SurfaceLayer.cpp:42
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int i(int ii) const noexcept
Definition: ERF_SurfaceLayer.cpp:39
Here is the call graph for this function:

◆ fill_tsurf_with_sfc_sst()

void SurfaceLayer::fill_tsurf_with_sfc_sst ( const int &  lev,
const double &  time,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

Fill surface temperature interpolated from time varying SST file

Parameters
[in]levlevel index
[in]timeinterpolation time
2730 {
2731  update_sfc_time_index(elapsed_time);
2732  const Real sfc_sst = interpolate_sfc_column(elapsed_time, 1);
2733  const int klo = m_geom[lev].Domain().smallEnd(2);
2734  const Real dz = m_geom[lev].CellSize(2);
2735  const bool moist = use_moisture;
2736  const bool have_rho_qv = cons_in.nComp() > RhoQ1_comp;
2737  const Real rdOcp = m_rdOcp;
2738  const NearestColumn column = surface_columns(m_geom[lev], t_surf[lev]->nGrowVect());
2739 
2740  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
2741  {
2742  Box gtbx = mfi.growntilebox();
2743 
2744  // A z-split planar field has one copy for every stacked 3-D box. Only
2745  // the copy whose source box touches the physical z-low face owns the
2746  // text-SST conversion and may read the 3-D state or terrain.
2747  if (gtbx.smallEnd(2) != klo ||
2748  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
2749  continue;
2750  }
2751 
2752  gtbx &= t_surf[lev]->fabbox(mfi.index());
2753  gtbx &= cons_in.fabbox(mfi.index());
2754  if (z_phys_nd) {
2755  gtbx &= amrex::convert(z_phys_nd->fabbox(mfi.index()), IntVect::TheCellVector());
2756  }
2757  if (m_lmask_lev[lev][0]) {
2758  gtbx &= m_lmask_lev[lev][0]->fabbox(mfi.index());
2759  }
2760  if (gtbx.isEmpty()) { continue; }
2761 
2762  auto t_surf_arr = t_surf[lev]->array(mfi);
2763  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
2764  Array4<int> {};
2765  const auto cons_arr = cons_in.const_array(mfi);
2766  const auto z_arr = (z_phys_nd) ? z_phys_nd->const_array(mfi) :
2767  Array4<const Real> {};
2768 
2769  // Only a cell of this box decides whether a conversion failure aborts; a halo
2770  // cell, which reads the state of a column another box owns, is only reported.
2771  // Nothing is lost where that column is valid on this level: its own box reads the
2772  // same column and aborts. A halo cell whose column lies in a coarse/fine ghost
2773  // region has no such box, and on a failure keeps whatever an earlier producer
2774  // wrote there (as in fill_tsurf_with_sst_and_tsk).
2775  const Box vbx = mfi.validbox();
2776  const int i_lo = vbx.smallEnd(0); const int i_hi = vbx.bigEnd(0);
2777  const int j_lo = vbx.smallEnd(1); const int j_hi = vbx.bigEnd(1);
2778 
2779  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
2780  {
2781  const bool authoritative = (i >= i_lo) && (i <= i_hi) && (j >= j_lo) && (j <= j_hi);
2782  const int li = column.i(i);
2783  const int lj = column.j(j);
2784  int is_land = (lmask_arr) ? lmask_arr(li,lj,0) : 0;
2785  if (!is_land) {
2786  const Real rho = cons_arr(li,lj,klo,Rho_comp);
2787  const Real rho_theta = cons_arr(li,lj,klo,RhoTheta_comp);
2788  const Real rho_qv = (moist && have_rho_qv)
2789  ? cons_arr(li,lj,klo,RhoQ1_comp) : Real(0.0);
2790  const Real delta_z = z_arr
2791  ? Compute_Z_AtCellCenter(li,lj,klo,z_arr) -
2792  Compute_Z_AtWFace(li,lj,klo,z_arr)
2793  : myhalf*dz;
2795  fail, authoritative, li, lj, klo, rho, rho_theta, rho_qv,
2796  moist, have_rho_qv, delta_z, sfc_sst);
2798  return;
2799  }
2800  Real theta = t_surf_arr(i,j,k);
2802  sfc_sst, pressure.pressure, rdOcp, theta)) {
2803  t_surf_arr(i,j,k) = theta;
2804  } else {
2806  li, lj, klo, rho, rho_theta, rho_qv, sfc_sst,
2807  pressure.pressure, delta_z);
2808  }
2809  }
2810  });
2811  }
2812 
2813  fill_planar_boundary(lev, *t_surf[lev]);
2814 }
amrex::Real interpolate_sfc_column(const amrex::Real &time, int col) const
Definition: ERF_SurfaceLayer.cpp:1054
void update_sfc_time_index(const amrex::Real &time)
Definition: ERF_SurfaceLayer.cpp:1037
Here is the call graph for this function:

◆ fill_tsurf_with_skin_temperature()

void SurfaceLayer::fill_tsurf_with_skin_temperature ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

Overwrite the land surface temperature with an external skin temperature.

The skin is an absolute temperature [K]; it is converted to the potential temperature the surface layer works in with the pressure at the surface diagnosed from the lowest cell, as for coupled SST. Runs last among the surface-temperature writers, so on land it replaces what they wrote.

Parameters
[in]levlevel index
[in]cons_inconserved state used to evaluate surface pressure
[in]z_phys_ndnodal physical-height field

Overwrite the land surface temperature with an external absolute skin temperature, converted to potential temperature at the surface pressure.

Parameters
[in]levCurrent level
[in]cons_inConserved state (surface pressure from the lowest cell)
[in]z_phys_ndNodal heights, or nullptr on a flat mesh
3354 {
3355  const MultiFab& skin = *m_skin_tsurf_lev[lev];
3356  // Indexed with the MFIter of t_surf, so the layouts must agree: both are the
3357  // level's grids flattened to the surface for planar terrain.
3359  skin.boxArray() == t_surf[lev]->boxArray() &&
3360  skin.DistributionMap() == t_surf[lev]->DistributionMap(),
3361  "Skin temperature layout does not match the surface-layer layout.");
3362 
3363  const int klo = m_geom[lev].Domain().smallEnd(2);
3364  const Real dz = m_geom[lev].CellSize(2);
3365  const bool moist = use_moisture;
3366  const Real rdOcp = m_rdOcp;
3367  // As in fill_tsurf_with_coupled_sst: a moist run whose state lacks the vapor
3368  // component aborts below rather than reading past the components.
3369  const bool have_rho_qv = cons_in.nComp() > RhoQ1_comp;
3370 
3371  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
3372  {
3373  Box gtbx = mfi.growntilebox();
3374  if (gtbx.smallEnd(2) != klo ||
3375  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
3376  continue;
3377  }
3378  gtbx &= t_surf[lev]->fabbox(mfi.index());
3379  if (gtbx.isEmpty()) { continue; }
3380 
3381  // The skin is written on valid cells only, so the halo takes the nearest
3382  // valid column; fill_planar_boundary in update_fluxes then fills the
3383  // interior and periodic ghosts.
3384  const Box vbx = mfi.validbox();
3385  const int i_lo = vbx.smallEnd(0); const int i_hi = vbx.bigEnd(0);
3386  const int j_lo = vbx.smallEnd(1); const int j_hi = vbx.bigEnd(1);
3387 
3388  auto t_surf_arr = t_surf[lev]->array(mfi);
3389  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
3390  Array4<int> {};
3391  const auto skin_arr = skin.const_array(mfi);
3392  const auto cons_arr = cons_in.const_array(mfi);
3393  const auto z_arr = (z_phys_nd) ? z_phys_nd->const_array(mfi) :
3394  Array4<const Real> {};
3395 
3396  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
3397  {
3398  const int li = amrex::min(amrex::max(i, i_lo), i_hi);
3399  const int lj = amrex::min(amrex::max(j, j_lo), j_hi);
3400  const int is_land = (lmask_arr) ? lmask_arr(li,lj,0) : 1;
3401  if (!is_land) { return; }
3402 
3403  const Real rho = cons_arr(li,lj,klo,Rho_comp);
3404  const Real rho_theta = cons_arr(li,lj,klo,RhoTheta_comp);
3405  const Real rho_qv = (moist && have_rho_qv)
3406  ? cons_arr(li,lj,klo,RhoQ1_comp) : Real(0.0);
3407  const Real delta_z = z_arr
3408  ? Compute_Z_AtCellCenter(li,lj,klo,z_arr) -
3409  Compute_Z_AtWFace(li,lj,klo,z_arr)
3410  : myhalf*dz;
3411  const Real t_skin = skin_arr(li,lj,k);
3413  fail, true, li, lj, klo, rho, rho_theta, rho_qv,
3414  moist, have_rho_qv, delta_z, t_skin);
3416  return;
3417  }
3418  Real theta = t_surf_arr(i,j,k);
3420  t_skin, pressure.pressure, rdOcp, theta)) {
3421  t_surf_arr(i,j,k) = theta;
3422  } else {
3424  li, lj, klo, rho, rho_theta, rho_qv, t_skin,
3425  pressure.pressure, delta_z);
3426  }
3427  });
3428  }
3429 }
amrex::Vector< const amrex::MultiFab * > m_skin_tsurf_lev
Definition: ERF_SurfaceLayer.H:2318
Here is the call graph for this function:

◆ fill_tsurf_with_sst_and_tsk()

void SurfaceLayer::fill_tsurf_with_sst_and_tsk ( const int &  lev,
const double &  time,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

Fill surface temperature from available SST and TSK data.

The SST and TSK slices hold absolute temperature [K]. They are interpolated in time and converted to potential temperature with the surface pressure diagnosed from the lowest cell of the current state, so the effective surface temperature does not drift as the surface pressure evolves. Land cells without TSK take the prescribed land surface potential temperature unchanged.

Parameters
[in]levlevel index
[in]timeinterpolation time
[in]cons_inconserved state (surface pressure from the lowest cell)
[in]z_phys_ndnodal heights, or nullptr on a flat mesh

Fill surface temperature from SST/TSK lower-boundary data.

The SST and TSK slices hold absolute temperature [K]. They are interpolated in time and then converted to the potential temperature t_surf holds at the surface pressure of the current state, the pressure the consumers of t_surf (q_sat, the radiation) convert it back with. A land cell without TSK takes the prescribed land temperature, which is a potential temperature already.

Parameters
[in]levCurrent level
[in]elapsed_time_since_start_lowTime since the start of the lower-boundary data
[in]cons_inConserved state (surface pressure from the lowest cell)
[in]z_phys_ndNodal heights, or nullptr on a flat mesh
2577 {
2578  int n_times_in_sst = static_cast<int>(m_sst_lev[lev].size());
2579 
2580  double dT = m_low_time_interval;
2581 
2582  int n_time_lo, n_time_hi;
2583  Real alpha;
2584 
2585  if (n_times_in_sst > 1) {
2586  n_time_lo = static_cast<int>( elapsed_time_since_start_low / dT);
2587  alpha = static_cast<Real>((elapsed_time_since_start_low - n_time_lo * dT) / dT);
2588 
2589  AMREX_ALWAYS_ASSERT( alpha >= zero && alpha <= one);
2590 
2591  n_time_hi = n_time_lo + 1;
2592 
2593  // Do not over run the last sst file
2594  if (elapsed_time_since_start_low >= m_final_low_time - m_start_low_time) {
2595  n_time_lo = static_cast<int>(m_sst_lev[lev].size())-1;
2596  n_time_hi = n_time_lo;
2597  alpha = zero;
2598  }
2599 
2600  AMREX_ALWAYS_ASSERT( (n_time_lo >= 0) && (n_time_hi < m_sst_lev[lev].size()));
2601  } else {
2602  n_time_lo = 0;
2603  n_time_hi = 0;
2604  alpha = one;
2605  }
2606  AMREX_ALWAYS_ASSERT( alpha >= zero && alpha <= one);
2607 
2608  Real oma = one - alpha;
2609 
2610  // Define a default land surface temperature if we don't read in tsk. It is the
2611  // prescribed potential temperature (most.pot_surf_temp), so it is not converted.
2612  Real lst = default_land_surf_temp;
2613 
2614  bool use_tsk = (!m_tsk_lev[lev].empty() && m_tsk_lev[lev][0]);
2615  bool ignore_sst = m_ignore_sst;
2616 
2617  const int klo = m_geom[lev].Domain().smallEnd(2);
2618  const Real dz = m_geom[lev].CellSize(2);
2619  const bool moist = use_moisture;
2620  // As in fill_tsurf_with_coupled_sst: a moist run whose state lacks the vapor
2621  // component aborts below rather than reading past the components.
2622  const bool have_rho_qv = cons_in.nComp() > RhoQ1_comp;
2623  const Real rdOcp = m_rdOcp;
2624  const NearestColumn column = surface_columns(m_geom[lev], t_surf[lev]->nGrowVect());
2625 
2626  // Populate t_surf
2627  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
2628  {
2629  Box gtbx = mfi.growntilebox();
2630 
2631  // Only the surface copy of a z-split planar field may read the lowest cell of
2632  // the state; fill_planar_boundary below copies its values to the other copies.
2633  if (gtbx.smallEnd(2) != klo ||
2634  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
2635  continue;
2636  }
2637 
2638  // The halo takes the surface pressure of the column surface_columns picks,
2639  // which does not depend on the box. Its SST and TSK are its own: they are filled
2640  // on the grown box, as the valid cells are.
2641  const Box source_box = cons_in.boxArray()[mfi.index()];
2642  const int i_lo = source_box.smallEnd(0); const int i_hi = source_box.bigEnd(0);
2643  const int j_lo = source_box.smallEnd(1); const int j_hi = source_box.bigEnd(1);
2644  gtbx &= t_surf[lev]->fabbox(mfi.index());
2645  if (gtbx.isEmpty()) { continue; }
2646 
2647  auto t_surf_arr = t_surf[lev]->array(mfi);
2648 
2649  const auto sst_lo_arr = m_sst_lev[lev][n_time_lo]->const_array(mfi);
2650  const auto sst_hi_arr = m_sst_lev[lev][n_time_hi]->const_array(mfi);
2651 
2652  // TSK carries the SST from the low file over water (update_sst_tsk), so it is
2653  // interpolated in time between the same two slices as the SST.
2654  const auto tsk_lo_arr = (use_tsk) ? m_tsk_lev[lev][n_time_lo]->const_array(mfi) :
2655  Array4<const Real> {};
2656  const auto tsk_hi_arr = (use_tsk && m_tsk_lev[lev][n_time_hi]) ?
2657  m_tsk_lev[lev][n_time_hi]->const_array(mfi) : tsk_lo_arr;
2658 
2659  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
2660  Array4<int> {};
2661  const auto cons_arr = cons_in.const_array(mfi);
2662  const auto z_arr = (z_phys_nd) ? z_phys_nd->const_array(mfi) :
2663  Array4<const Real> {};
2664 
2665  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
2666  {
2667  const bool is_land = (lmask_arr) ? (lmask_arr(i,j,k) != 0) : true;
2669  is_land, use_tsk, ignore_sst);
2670 
2671  // The absolute surface temperature now. TSK is written as
2672  // lo + alpha * (hi - lo) so that a cell whose TSK is the same in both
2673  // slices, as it is over land, keeps exactly that value.
2674  Real t_abs;
2676  t_abs = tsk_lo_arr(i,j,k) + alpha * (tsk_hi_arr(i,j,k) - tsk_lo_arr(i,j,k));
2678  t_abs = oma * sst_lo_arr(i,j,k) + alpha * sst_hi_arr(i,j,k);
2679  } else {
2680  t_surf_arr(i,j,k) = lst;
2681  return;
2682  }
2683 
2684  const int li = column.i(i);
2685  const int lj = column.j(j);
2686  // A halo cell reads the state of a column some box owns, so only its own SST or
2687  // TSK can fail where the valid cells do not: report it, but do not abort for it.
2688  const bool authoritative = (i >= i_lo) && (i <= i_hi) && (j >= j_lo) && (j <= j_hi);
2689 
2690  // The state is checked before it is divided by, so that a bad state reaches
2691  // the diagnostic rather than a floating-point trap.
2692  const Real rho = cons_arr(li,lj,klo,Rho_comp);
2693  const Real rho_theta = cons_arr(li,lj,klo,RhoTheta_comp);
2694  const Real rho_qv = (moist && have_rho_qv)
2695  ? cons_arr(li,lj,klo,RhoQ1_comp) : Real(0.0);
2696  const Real delta_z = z_arr
2697  ? Compute_Z_AtCellCenter(li,lj,klo,z_arr) -
2698  Compute_Z_AtWFace(li,lj,klo,z_arr)
2699  : myhalf*dz;
2701  rho, rho_theta, rho_qv, moist, have_rho_qv, delta_z);
2704  fail, authoritative,
2706  li, lj, klo, rho, rho_theta, rho_qv, t_abs,
2707  pressure.pressure, delta_z);
2708  return;
2709  }
2710  Real theta = t_surf_arr(i,j,k);
2712  t_abs, pressure.pressure, rdOcp, theta)) {
2713  t_surf_arr(i,j,k) = theta;
2714  } else {
2716  li, lj, klo, rho, rho_theta, rho_qv, t_abs,
2717  pressure.pressure, delta_z);
2718  }
2719  });
2720  }
2721  fill_planar_boundary(lev, *t_surf[lev]);
2722 }
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_sst_lev
Definition: ERF_SurfaceLayer.H:2273
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_tsk_lev
Definition: ERF_SurfaceLayer.H:2274
@ alpha
Definition: ERF_SLM.H:153
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ConversionError conversion_error(const SurfacePressureError error)
Definition: ERF_SurfaceTemperature.H:243
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SurfacePressureResult diagnose_surface_pressure(const amrex::Real rho, const amrex::Real rho_theta, const amrex::Real rho_qv, const bool moist, const bool have_rho_qv, const amrex::Real delta_z)
Definition: ERF_SurfaceTemperature.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SurfaceTemperatureSource surface_temperature_source(const bool is_land, const bool have_tsk, const bool ignore_sst)
Definition: ERF_SurfaceTemperature.H:205
@ sst
the sea-surface temperature, SST
Here is the call graph for this function:

◆ get_lmask()

amrex::iMultiFab* SurfaceLayer::get_lmask ( const int &  lev)
inline

Return the land-mask field.

Parameters
[in]levlevel index
1937 { return m_lmask_lev[lev][0]; }

◆ get_lsm_flux_view()

SurfaceFluxView SurfaceLayer::get_lsm_flux_view ( const int &  lev,
const amrex::MFIter &  mfi 
) const

The four LSM fluxes on one grid: from the surface model when it supplies fluxes, otherwise from the registered LSM fluxes. A flux that is not available is left null, and SurfaceFluxView::valid then rejects every cell. compute_fluxes, compute_sfc_params_from_lsm_fluxes and get_lsm_tsurf all take their fluxes from here, so they agree on which land columns use the LSM flux. Each decides a ghost column outside a non-periodic domain from the nearest column inside it; compute_SurfaceLayer_bcs also reads the fluxes one ghost cell beyond the grid, so they must carry one filled lateral ghost cell.

Parameters
[in]levlevel index
[in]mfiiterator over a MultiFab with the cons BoxArray and DistributionMapping

The four LSM fluxes on one grid, from the surface model when it supplies fluxes and from the registered LSM fluxes otherwise.

Parameters
[in]levCurrent level
[in]mfiIterator over a MultiFab with the cons BoxArray and DistributionMapping
2370 {
2372  return m_surf_model->get_surface_flux_view(lev, mfi);
2373  }
2374  SurfaceFluxView flux;
2375  for (int n(0); n<m_lsm_flux_lev[lev].size(); ++n) {
2376  if (!m_lsm_flux_lev[lev][n]) { continue; }
2377  if (toLower(m_lsm_flux_name[n]) == "t_flux") { flux.t_flux = m_lsm_flux_lev[lev][n]->const_array(mfi); }
2378  if (toLower(m_lsm_flux_name[n]) == "q_flux") { flux.q_flux = m_lsm_flux_lev[lev][n]->const_array(mfi); }
2379  if (toLower(m_lsm_flux_name[n]) == "tau13") { flux.tau13 = m_lsm_flux_lev[lev][n]->const_array(mfi); }
2380  if (toLower(m_lsm_flux_name[n]) == "tau23") { flux.tau23 = m_lsm_flux_lev[lev][n]->const_array(mfi); }
2381  }
2382  return flux;
2383 }
SurfaceFluxView get_surface_flux_view(const int lev, const amrex::MFIter &mfi) const
Returns provider or blended surface-flux views for one tile.
Definition: ERF_SurfaceModel.H:473

◆ get_lsm_tsurf()

void SurfaceLayer::get_lsm_tsurf ( const int &  lev,
const amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
erf_surface_temperature::ConversionFailure *  fail 
)

Fill surface temperature from the LSM surface-temperature field, converted to potential temperature at the surface pressure when the field is an absolute temperature.

Parameters
[in]levlevel index
[in]cons_inconserved state (surface pressure from the lowest cell)
[in]z_phys_ndnodal heights, or nullptr on a flat mesh

Fill surface temperature from land-surface-model data.

By default the LSM field is copied into t_surf unchanged. With most.use_lsm_skin_temperature, t_surf is a potential temperature: an LSM skin temperature that is an absolute temperature (m_lsm_tsurf_is_theta false) is converted at the surface pressure, as fill_tsurf_with_skin_temperature does. When the LSM also supplies the surface fluxes, t_surf follows the skin only where all four fluxes are valid: those are the cells whose fluxes and u*, t*, q*, L come from the LSM, so the MOST fluxes of the remaining cells keep the surface temperature they had.

Parameters
[in]levCurrent level
[in]cons_inConserved state (surface pressure from the lowest cell)
[in]z_phys_ndNodal heights, or nullptr on a flat mesh
2999 {
3000  const int klo = m_geom[lev].Domain().smallEnd(2);
3001 
3003  // Default: the LSM field is copied into t_surf as it is.
3004  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
3005  {
3006  Box gtbx = mfi.growntilebox();
3007 
3008  if (gtbx.smallEnd(2) != klo) { continue; }
3009 
3010  // NOTE: LSM does not carry lateral ghost cells.
3011  // This copies the valid box into the ghost cells.
3012  // Fillboundary is called after this to pick up the
3013  // interior ghost and periodic directions.
3014  const NearestColumn col(mfi.validbox());
3015 
3016  auto t_surf_arr = t_surf[lev]->array(mfi);
3017  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
3018  Array4<int> {};
3019  const auto& lsm_tsurf = *m_lsm_data_lev[lev][m_lsm_tsurf_indx];
3020  // get the top-most index of the LSM to use as the surface temperature
3021  const auto& lsm_box = lsm_tsurf.box(mfi.index());
3022  const int lsm_khi = lsm_box.bigEnd(2);
3023  const auto lsm_arr = lsm_tsurf.const_array(mfi);
3024 
3025  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
3026  {
3027  int is_land = (lmask_arr) ? lmask_arr(i,j,k) : 1;
3028  if (is_land) {
3029  const Real lsm_value = lsm_arr(col.i(i),col.j(j),lsm_khi);
3030  if (amrex::Math::isfinite(lsm_value) && lsm_value > Real(0.0) &&
3031  lsm_value < lsm_undefined) {
3032  t_surf_arr(i,j,k) = lsm_value;
3033  }
3034  }
3035  });
3036  }
3037  return;
3038  }
3039 
3040  const Real dz = m_geom[lev].CellSize(2);
3041  const bool moist = use_moisture;
3042  const bool have_rho_qv = cons_in.nComp() > RhoQ1_comp;
3043  const Real rdOcp = m_rdOcp;
3044  const bool convert = !m_lsm_tsurf_is_theta;
3045  const bool gate_on_fluxes = m_has_lsm_fluxes;
3046 
3047  for (MFIter mfi(*t_surf[lev]); mfi.isValid(); ++mfi)
3048  {
3049  Box gtbx = mfi.growntilebox();
3050 
3051  // Only the copy whose source box touches the z-low face may read the
3052  // state there; fill_planar_boundary in update_fluxes fills the others.
3053  if (gtbx.smallEnd(2) != klo ||
3054  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
3055  continue;
3056  }
3057  gtbx &= t_surf[lev]->fabbox(mfi.index());
3058  if (gtbx.isEmpty()) { continue; }
3059 
3060  // NOTE: LSM does not carry lateral ghost cells.
3061  // This copies the valid box into the ghost cells.
3062  // Fillboundary is called after this to pick up the
3063  // interior ghost and periodic directions.
3064  const NearestColumn col(mfi.validbox());
3065 
3066  auto t_surf_arr = t_surf[lev]->array(mfi);
3067  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
3068  Array4<int> {};
3069  const auto& lsm_tsurf = *m_lsm_data_lev[lev][m_lsm_tsurf_indx];
3070  // get the top-most index of the LSM to use as the surface temperature
3071  // this is -1 for SLM, but could be different for other models?
3072  const auto& lsm_box = lsm_tsurf.box(mfi.index());
3073  const int lsm_khi = lsm_box.bigEnd(2);
3074  const auto lsm_arr = lsm_tsurf.const_array(mfi);
3075  const auto cons_arr = cons_in.const_array(mfi);
3076  const auto z_arr = (z_phys_nd) ? z_phys_nd->const_array(mfi) :
3077  Array4<const Real> {};
3078 
3079  // The same four fluxes, and the same validity test, as
3080  // compute_sfc_params_from_lsm_fluxes
3081  const SurfaceFluxView lsm_flux = (gate_on_fluxes) ? get_lsm_flux_view(lev, mfi)
3082  : SurfaceFluxView{};
3083 
3084  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
3085  {
3086  const int li = col.i(i);
3087  const int lj = col.j(j);
3088  int is_land = (lmask_arr) ? lmask_arr(i,j,k) : 1;
3089  if (!is_land) { return; }
3090 
3091  const Real lsm_value = lsm_arr(li,lj,lsm_khi);
3092  if (!amrex::Math::isfinite(lsm_value) || lsm_value <= Real(0.0) ||
3093  lsm_value >= lsm_undefined) {
3094  return;
3095  }
3096 
3097  if (gate_on_fluxes && !lsm_flux.valid(li,lj)) {
3098  return;
3099  }
3100 
3101  if (!convert) {
3102  t_surf_arr(i,j,k) = lsm_value;
3103  return;
3104  }
3105 
3106  const Real rho = cons_arr(li,lj,klo,Rho_comp);
3107  const Real rho_theta = cons_arr(li,lj,klo,RhoTheta_comp);
3108  const Real rho_qv = (moist && have_rho_qv)
3109  ? cons_arr(li,lj,klo,RhoQ1_comp) : Real(0.0);
3110  const Real delta_z = z_arr
3111  ? Compute_Z_AtCellCenter(li,lj,klo,z_arr) -
3112  Compute_Z_AtWFace(li,lj,klo,z_arr)
3113  : myhalf*dz;
3115  fail, true, li, lj, klo, rho, rho_theta, rho_qv,
3116  moist, have_rho_qv, delta_z, lsm_value);
3118  return;
3119  }
3120  Real theta = t_surf_arr(i,j,k);
3122  lsm_value, pressure.pressure, rdOcp, theta)) {
3123  t_surf_arr(i,j,k) = theta;
3124  } else {
3126  li, lj, klo, rho, rho_theta, rho_qv, lsm_value,
3127  pressure.pressure, delta_z);
3128  }
3129  });
3130  }
3131 }
constexpr amrex::Real lsm_undefined
Definition: ERF_Constants.H:28
bool m_lsm_tsurf_is_theta
Definition: ERF_SurfaceLayer.H:2196
int m_lsm_tsurf_indx
Definition: ERF_SurfaceLayer.H:2195
bool m_use_lsm_skin_temperature
Definition: ERF_SurfaceLayer.H:2197
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_data_lev
Definition: ERF_SurfaceLayer.H:2324
Here is the call graph for this function:

◆ get_mac_avg()

const amrex::MultiFab* SurfaceLayer::get_mac_avg ( const int &  lev,
int  comp 
)
inline

Return a MOST-average field.

Parameters
[in]levlevel index
[in]compcomponent index
1676  {
1677  return m_ma.get_average(lev, comp);
1678  }
Here is the call graph for this function:

◆ get_mac_avg_ptr()

amrex::MultiFab* SurfaceLayer::get_mac_avg_ptr ( const int &  lev,
int  comp 
)
inline

Return a MOST-average field for modification (restart).

Parameters
[in]levlevel index
[in]compcomponent index
1710 { return m_ma.get_average(lev, comp); }
Here is the call graph for this function:

◆ get_mac_plane_avg()

amrex::Vector<amrex::Real> SurfaceLayer::get_mac_plane_avg ( const int &  lev) const
inline

Return the filtered plane averages, which hold the filter state for the plane and EB averaging policies.

Parameters
[in]levlevel index
1718 { return m_ma.get_plane_average(lev); }
amrex::Vector< amrex::Real > get_plane_average(const int &lev) const
Definition: ERF_MOSTAverage.H:322
Here is the call graph for this function:

◆ get_num_mac_avg()

int SurfaceLayer::get_num_mac_avg ( ) const
inline

Return the number of MOST-average components.

1688 { return m_ma.get_navg(); }
int get_navg() const
Definition: ERF_MOSTAverage.H:291
Here is the call graph for this function:

◆ get_olen()

amrex::MultiFab* SurfaceLayer::get_olen ( const int &  lev)
inline

Return the Obukhov length field.

Parameters
[in]levlevel index
1657 { return olen[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_pblh()

amrex::MultiFab* SurfaceLayer::get_pblh ( const int &  lev)
inline

Return the planetary-boundary-layer-height field.

Parameters
[in]levlevel index
1667 { return pblh[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_q_star()

amrex::MultiFab* SurfaceLayer::get_q_star ( const int &  lev)
inline

Return the moisture scale field.

Parameters
[in]levlevel index
1650 { return q_star[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_q_surf()

amrex::MultiFab* SurfaceLayer::get_q_surf ( const int &  lev)
inline

Return the surface-moisture field.

Parameters
[in]levlevel index
1881 { return q_surf[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_surface_current()

const amrex::MultiFab* SurfaceLayer::get_surface_current ( const int &  lev,
int  comp 
) const
inline

Return a component of the surface current on its faces of the plane k = klo, or null when there is none on this level.

Parameters
[in]levlevel index
[in]comp0 for the x-component on x-faces, 1 for the y-component on y-faces
1606  {
1607  const auto& current = (comp == 0) ? m_surface_current_x : m_surface_current_y;
1608  return (m_use_surface_current && lev < static_cast<int>(current.size()))
1609  ? current[lev].get() : nullptr;
1610  }

Referenced by ERF::FillPlot2DVars().

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

◆ get_surface_diagnostic_source()

amrex::MultiFab* SurfaceLayer::get_surface_diagnostic_source ( const int &  lev)
inline

Return the surface-diagnostic provenance field.

Parameters
[in]levlevel index
1896 { return surface_diagnostic_source[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_t_star()

amrex::MultiFab* SurfaceLayer::get_t_star ( const int &  lev)
inline

Return the temperature scale field.

Parameters
[in]levlevel index
1643 { return t_star[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_t_surf()

amrex::MultiFab* SurfaceLayer::get_t_surf ( const int &  lev)
inline

Return the surface-temperature field.

Parameters
[in]levlevel index
1734 { return t_surf[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_u_star()

amrex::MultiFab* SurfaceLayer::get_u_star ( const int &  lev)
inline

Return the friction-velocity field.

Parameters
[in]levlevel index
1617 { return u_star[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_w_star()

amrex::MultiFab* SurfaceLayer::get_w_star ( const int &  lev)
inline

Return the convective velocity scale field.

Parameters
[in]levlevel index
1624 { return w_star[lev].get(); }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_z0() [1/2]

amrex::MultiFab* SurfaceLayer::get_z0 ( const int &  lev)
inline

Return the roughness-height field.

Parameters
[in]levlevel index
1917 { return &z_0[lev]; }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ get_z0() [2/2]

const amrex::MultiFab* SurfaceLayer::get_z0 ( const int &  lev) const
inline

Return the roughness-height field, read-only (for a caller that holds a const SurfaceLayer, such as a fire engine).

Parameters
[in]levlevel index
1925 { return &z_0[lev]; }

◆ get_zref()

amrex::MultiFab* SurfaceLayer::get_zref ( const int &  lev)
inline

Return the 2D MF of zref heights.

Parameters
[in]levlevel index
1903 { return m_ma.get_zref(lev); }
Here is the call graph for this function:

◆ get_zref_min()

amrex::Real SurfaceLayer::get_zref_min ( const int &  lev)
inline

Return the minimum reference height for one level.

Parameters
[in]levlevel index
1910 { return (m_ma.get_zref(lev))->min(0); }
Here is the call graph for this function:

◆ have_variable_sea_roughness()

bool SurfaceLayer::have_variable_sea_roughness ( ) const
inline

Return whether variable sea roughness is active.

1930 { return m_var_z0; }
bool m_var_z0
Definition: ERF_SurfaceLayer.H:2187

◆ impose_SurfaceLayer_bcs()

void SurfaceLayer::impose_SurfaceLayer_bcs ( const int &  lev,
amrex::Vector< const amrex::MultiFab * >  mfs,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  Tau_lev,
amrex::MultiFab *  xheat_flux,
amrex::MultiFab *  yheat_flux,
amrex::MultiFab *  zheat_flux,
amrex::MultiFab *  xqv_flux,
amrex::MultiFab *  yqv_flux,
amrex::MultiFab *  zqv_flux,
const amrex::MultiFab *  z_phys,
amrex::MultiFab *  mf_surface_fluxes = nullptr 
)

Impose surface-layer boundary conditions for planar terrain.

Parameters
[in]levlevel index
[in]mfsstate and velocity fields used by the BC computation
[in,out]Tau_levstress fields to fill
[in,out]xheat_fluxx-face heat flux field
[in,out]yheat_fluxy-face heat flux field
[in,out]zheat_fluxz-face heat flux field
[in,out]xqv_fluxx-face moisture flux field
[in,out]yqv_fluxy-face moisture flux field
[in,out]zqv_fluxz-face moisture flux field
[in]z_physphysical-height field

Wrapper to impose Monin Obukhov similarity theory fluxes by populating ghost cells.

Parameters
[in]levCurrent level
[in]mfsState MultiFabs used to compute the boundary fluxes
[in,out]Tau_levDiffusive stress MultiFabs populated with surface stresses
[in,out]xheat_fluxx-face heat-flux MultiFab, used when rotated fluxes are enabled
[in,out]yheat_fluxy-face heat-flux MultiFab, used when rotated fluxes are enabled
[in,out]zheat_fluxz-face heat-flux MultiFab populated with vertical surface heat flux
[in,out]xqv_fluxx-face moisture-flux MultiFab, used when rotated fluxes and moisture are enabled
[in,out]yqv_fluxy-face moisture-flux MultiFab, used when rotated fluxes and moisture are enabled
[in,out]zqv_fluxz-face moisture-flux MultiFab populated when moisture is enabled
[in]z_physNodal physical height used to rotate terrain-following fluxes
1419 {
1420  if (flux_type == FluxCalcType::MOENG) {
1421  amrex::Real wsmin = most_min_wind_speed; // TODO: change for different faces
1422  const Box& domain = m_geom[lev].Domain();
1423  moeng_flux flux_comp(wsmin, m_face.isLow(),
1424  domain.smallEnd(2), domain.bigEnd(2));
1425  compute_SurfaceLayer_bcs(lev, mfs, Tau_lev,
1426  xheat_flux, yheat_flux, zheat_flux,
1427  xqv_flux, yqv_flux, zqv_flux,
1428  z_phys, flux_comp, mf_surface_fluxes);
1429  } else if (flux_type == FluxCalcType::ROTATE) {
1430  rotate_flux flux_comp;
1431  compute_SurfaceLayer_bcs(lev, mfs, Tau_lev,
1432  xheat_flux, yheat_flux, zheat_flux,
1433  xqv_flux, yqv_flux, zqv_flux,
1434  z_phys, flux_comp, mf_surface_fluxes);
1435  } else if (flux_type == FluxCalcType::RICO) {
1436  rico_flux flux_comp(rico_theta_z0, rico_qsat_z0);
1437  compute_SurfaceLayer_bcs(lev, mfs, Tau_lev,
1438  xheat_flux, yheat_flux, zheat_flux,
1439  xqv_flux, yqv_flux, zqv_flux,
1440  z_phys, flux_comp, mf_surface_fluxes);
1441  } else if (flux_type == FluxCalcType::BULK_COEFF) {
1443  compute_SurfaceLayer_bcs(lev, mfs, Tau_lev,
1444  xheat_flux, yheat_flux, zheat_flux,
1445  xqv_flux, yqv_flux, zqv_flux,
1446  z_phys, flux_comp, mf_surface_fluxes);
1447  } else if (flux_type == FluxCalcType::CUSTOM) {
1448  custom_flux flux_comp(specified_rho_surf);
1449  compute_SurfaceLayer_bcs(lev, mfs, Tau_lev,
1450  xheat_flux, yheat_flux, zheat_flux,
1451  xqv_flux, yqv_flux, zqv_flux,
1452  z_phys, flux_comp, mf_surface_fluxes);
1453  } else {
1454  amrex::Abort("Unknown surface layer flux calculation type");
1455  }
1456 }
constexpr amrex::Real most_min_wind_speed
Definition: ERF_MOSTStress.H:14
bool specified_rho_surf
Definition: ERF_SurfaceLayer.H:2182
void compute_SurfaceLayer_bcs(const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const amrex::MultiFab *z_phys, const FluxCalc &flux_comp, amrex::MultiFab *mf_surface_fluxes=nullptr)
Definition: ERF_MOSTStress.H:2709
Definition: ERF_MOSTStress.H:2543
Definition: ERF_MOSTStress.H:2219
Definition: ERF_MOSTStress.H:2894
Definition: ERF_MOSTStress.H:3072

◆ impose_SurfaceLayer_bcs_EB()

void SurfaceLayer::impose_SurfaceLayer_bcs_EB ( const int &  lev,
amrex::Vector< const amrex::MultiFab * >  mfs,
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &  Tau_lev,
amrex::MultiFab *  xheat_flux,
amrex::MultiFab *  yheat_flux,
amrex::MultiFab *  zheat_flux,
amrex::MultiFab *  xqv_flux,
amrex::MultiFab *  yqv_flux,
amrex::MultiFab *  zqv_flux 
)

Impose surface-layer boundary conditions for embedded-boundary terrain.

Parameters
[in]levlevel index
[in]mfsstate and velocity fields used by the BC computation
[in,out]Tau_levEB stress fields to fill
[in,out]xheat_fluxx-face heat flux field
[in,out]yheat_fluxy-face heat flux field
[in,out]zheat_fluxz-face heat flux field
[in,out]xqv_fluxx-face moisture flux field
[in,out]yqv_fluxy-face moisture flux field
[in,out]zqv_fluxz-face moisture flux field

Wrapper to impose Monin Obukhov similarity theory fluxes by populating ghost cells.

Parameters
[in]levCurrent level
[in]mfsState MultiFabs used to compute the EB boundary fluxes
[in,out]Tau_EBEB diffusive stress MultiFabs populated with surface stresses
[in,out]xheat_fluxx-face EB heat-flux MultiFab, currently unused
[in,out]yheat_fluxy-face EB heat-flux MultiFab, currently unused
[in,out]Hfx3_EBEB heat-flux MultiFab populated with scalar surface flux
[in,out]xqv_fluxx-face EB moisture-flux MultiFab, currently unused
[in,out]yqv_fluxy-face EB moisture-flux MultiFab, currently unused
[in,out]zqv_fluxz-face EB moisture-flux MultiFab, currently unused
1481 {
1482  if (flux_type == FluxCalcType::MOENG) {
1483  moeng_flux_eb flux_comp;
1484  compute_SurfaceLayer_bcs_EB(lev, mfs, Tau_EB,
1485  xheat_flux, yheat_flux, Hfx3_EB,
1486  xqv_flux, yqv_flux, zqv_flux,
1487  flux_comp);
1488  } else {
1489  amrex::Abort("Not implemented surface layer flux calculation type for EB");
1490  }
1491 }
void compute_SurfaceLayer_bcs_EB(const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const FluxCalc &flux_comp)
EB implementation of the Moeng surface-flux formulation.
Definition: ERF_EBMOSTStress.H:349

◆ init_tke_from_ustar()

void SurfaceLayer::init_tke_from_ustar ( const int &  lev,
amrex::MultiFab &  cons,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
const amrex::Real  tkefac = one,
const amrex::Real  zscale = amrex::Real(700.0) 
)

Initialize TKE from the current surface friction velocity.

Parameters
[in]levlevel index
[in,out]consconserved state whose TKE component is initialized
[in]z_phys_ndnodal physical-height field
[in]tkefacscale factor applied to the initialized TKE
[in]zscalevertical decay scale

Initialize TKE from surface-layer friction velocity.

Parameters
[in]levCurrent level
[in,out]consConserved state whose RhoKE component is initialized
[in]z_phys_ndNodal physical height used to compute height above ground
[in]tkefacFactor multiplying ustar squared for the surface TKE value
[in]zscaleScale factor used to taper TKE with height
3991 {
3993  static_cast<int>(m_face) == Orientation::zlo(),
3994  "TKE initialization from surface-layer ustar is supported only on the z-low face.");
3995 
3996  Print() << "Initializing TKE from surface layer ustar on level " << lev << std::endl;
3997 
3998  // Handle vertical decomposition by selectively copying into
3999  // a FArrayBox section on each rank. Then doing a reduce real sum
4000  // and broadcasting to each rank. No mask since all CC data
4001  //
4002  // Pinned so the reduction below can read them on the host; the device
4003  // still reaches pinned memory, so the loops here are unaffected.
4004  const int klo = m_geom[lev].Domain().smallEnd(2);
4005  Box bx_lo = u_star[lev]->boxArray().minimalBox();
4006  FArrayBox u_star_lo(bx_lo, 1, The_Pinned_Arena()); u_star_lo.setVal<RunOn::Host>(0);
4007  FArrayBox z_surf_lo(bx_lo, 1, The_Pinned_Arena()); z_surf_lo.setVal<RunOn::Host>(0);
4008  Real* ustar_ptr = u_star_lo.dataPtr();
4009  Real* zsurf_ptr = z_surf_lo.dataPtr();
4010  for (MFIter mfi(cons); mfi.isValid(); ++mfi)
4011  {
4012  Box vbx = mfi.validbox();
4013  if (vbx.smallEnd(2) != klo) { continue; }
4014  vbx.makeSlab(2,0);
4015 
4016  auto const& u_star_arr = u_star[lev]->const_array(mfi);
4017  auto u_star_all = u_star_lo.array();
4018 
4019  auto const& z_phys_arr = z_phys_nd->const_array(mfi);
4020  auto z_surf_all = z_surf_lo.array();
4021 
4022  ParallelFor(vbx, [=] AMREX_GPU_DEVICE(int i, int j, int ) noexcept
4023  {
4024  u_star_all(i,j,0) = u_star_arr(i,j,0);
4025  z_surf_all(i,j,0) = fourth * ( z_phys_arr(i ,j ,klo) + z_phys_arr(i+1,j ,klo)
4026  + z_phys_arr(i ,j+1,klo) + z_phys_arr(i+1,j+1,klo) );
4027  });
4028  }
4029  Gpu::streamSynchronize(); // the fills above are async, the reduction is not
4030  ParallelDescriptor::ReduceRealSum(ustar_ptr, static_cast<int>(bx_lo.numPts()));
4031  ParallelDescriptor::ReduceRealSum(zsurf_ptr, static_cast<int>(bx_lo.numPts()));
4032 
4033  // Now work on all boxes (ustar has been filled above)
4034  constexpr Real small = Real(0.01);
4035  for (MFIter mfi(cons); mfi.isValid(); ++mfi)
4036  {
4037  Box vbx = mfi.validbox();
4038 
4039  auto const& u_star_arr = u_star_lo.const_array();
4040  auto const& z_surf_arr = z_surf_lo.const_array();
4041  auto const& z_phys_arr = z_phys_nd->const_array(mfi);
4042 
4043  auto const& cons_arr = cons.array(mfi);
4044 
4045  ParallelFor(vbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
4046  {
4047  Real rho = cons_arr(i, j, k, Rho_comp);
4048  Real ust = u_star_arr(i, j, 0);
4049  Real tke0 = tkefac * ust * ust; // surface value
4050  Real zagl = Compute_Z_AtCellCenter(i, j, k, z_phys_arr) - z_surf_arr(i,j,0);
4051 
4052  // linearly tapering profile -- following WRF, approximate top of
4053  // PBL as ustar * zscale
4054  cons_arr(i, j, k, RhoKE_comp) = rho * tke0 * std::max(
4055  (ust * zscale - zagl) / (std::max(ust, small) * zscale),
4056  small);
4057  });
4058  }
4059 }
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
Here is the call graph for this function:

◆ inject_pblh_from_coarser()

void SurfaceLayer::inject_pblh_from_coarser ( const int &  lev,
amrex::MultiFab &  fine 
) const

The PBL height of the next coarser level, injected onto the grids of this level over all of their cells, ghost cells included. Public because it launches a device lambda.

Parameters
[in]levCurrent level (> 0)
[out]fineMultiFab on the grids of pblh[lev]

Write into fine, a MultiFab on the grids of pblh[lev], the PBL height of the next coarser level over all of its cells, ghost cells included (see fill_pblh_from_coarser).

Parameters
[in]levCurrent level (> 0)
[out]finePBL height of level lev-1, injected onto the grids of level lev
3928 {
3929  AMREX_ALWAYS_ASSERT(lev > 0 && pblh[lev-1]);
3930  const Geometry& geom_f = m_geom[lev];
3931  const Geometry& geom_c = m_geom[lev-1];
3932  const IntVect rr(AMREX_D_DECL(static_cast<int>(std::lround(geom_c.CellSize(0) / geom_f.CellSize(0))),
3933  static_cast<int>(std::lround(geom_c.CellSize(1) / geom_f.CellSize(1))),
3934  1));
3935 
3936  const MultiFab& crse = *pblh[lev-1];
3937 
3938  // Each fine column takes the height of the coarse column that holds it (injection, no
3939  // interpolation): the fine height is then exactly the coarse diagnostic, and independent of
3940  // the decomposition, at the price of being constant over each block of rr x rr fine columns.
3941  // The coarse level's own height varies at that resolution too. Interpolating would reach
3942  // further into the coarse halo than these planar fields hold: a bilinear stencil for a fine
3943  // ghost cell at a non-periodic domain boundary wants a second coarse cell outside the
3944  // domain, and pblh carries one ghost cell. A smooth cap would need a wider halo there, or
3945  // a one-sided stencil.
3946  //
3947  // The coarse heights over the boxes of this level, with enough ghost cells to cover theirs.
3948  // Ghost cells go first, then the valid cells, so every cell the coarse level owns comes
3949  // from the box that owns it. The estimator writes pblh over its grown box (it clips only
3950  // in z), so the coarse ghost cells the first copy reads hold a diagnosed height, outside a
3951  // non-periodic domain too.
3952  const IntVect ng_f = fine.nGrowVect();
3953  const IntVect ng_c(AMREX_D_DECL((ng_f[0] + rr[0] - 1) / rr[0], (ng_f[1] + rr[1] - 1) / rr[1], ng_f[2]));
3954  MultiFab crse_on_fine(amrex::coarsen(fine.boxArray(), rr), fine.DistributionMap(), 1, ng_c);
3955  crse_on_fine.setVal(zero);
3956  for (const IntVect& ng_src : {crse.nGrowVect(), IntVect(0)}) {
3957  crse_on_fine.ParallelCopy(crse, 0, 0, 1, elemwiseMin(ng_src, ng_c), ng_c, geom_c.periodicity());
3958  }
3959 
3960 #ifdef _OPENMP
3961 #pragma omp parallel if (Gpu::notInLaunchRegion())
3962 #endif
3963  for (MFIter mfi(fine, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
3964  const Box bx = mfi.growntilebox();
3965  const Array4<Real> f = fine.array(mfi);
3966  const Array4<Real const> c = crse_on_fine.const_array(mfi);
3967  const int rx = rr[0];
3968  const int ry = rr[1];
3969  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
3970  {
3971  f(i,j,k) = c(amrex::coarsen(i,rx), amrex::coarsen(j,ry), k);
3972  });
3973  }
3974 }
real(c_double), private rr
Definition: ERF_module_mp_morr_two_moment.F90:224
Here is the call graph for this function:

◆ interpolate_sfc_column()

Real SurfaceLayer::interpolate_sfc_column ( const amrex::Real &  time,
int  col 
) const

Interpolates the SFC/SST data at the given column and time

Parameters
[in]timeelapsed time
[in]colcolumn index of file data
1056 {
1057  if (sfc.empty() || sfc[0].empty()) { return zero; }
1058  if (sfc[0].size() == 1) { return sfc[col][0]; }
1059 
1060  const Real t0 = sfc[0][sfc_time_ind];
1061  const Real t1 = sfc[0][sfc_time_ind+1];
1062  const Real x0 = sfc[col][sfc_time_ind];
1063  const Real x1 = sfc[col][sfc_time_ind+1];
1064 
1065  if (elapsed_time < t0) {
1066  return x0;
1067  }
1068 
1069  if (t0 == t1 || elapsed_time > t1) {
1070  return x1;
1071  }
1072 
1073  const Real dt = (elapsed_time - t0) / (t1 - t0);
1074  return x0 + (x1 - x0) * dt;
1075 }
amrex::Vector< amrex::Vector< amrex::Real > > sfc
Definition: ERF_SurfaceLayer.H:2203
int sfc_time_ind
Definition: ERF_SurfaceLayer.H:2202
real(c_double), parameter t0
Definition: ERF_module_model_constants.F90:39

◆ lmask_min_reduce()

int SurfaceLayer::lmask_min_reduce ( amrex::iMultiFab &  lmask,
const int &  nghost 
)
inline

Compute the minimum land-mask value over valid and optional ghost cells.

Parameters
[in]lmaskland-mask field
[in]nghostnumber of ghost cells included in the reduction
1947  {
1948  int lmask_min = amrex::ReduceMin(lmask, nghost, [=] AMREX_GPU_HOST_DEVICE(
1949  amrex::Box const& bx, amrex::Array4<int const> const& lm_arr) -> int
1950  {
1951  int locmin = std::numeric_limits<int>::max();
1952  const auto lo = lbound(bx);
1953  const auto hi = ubound(bx);
1954  for (int j = lo.y; j <= hi.y; ++j) {
1955  for (int i = lo.x; i <= hi.x; ++i) {
1956  locmin = std::min(locmin, lm_arr(i, j, 0));
1957  }
1958  }
1959  return locmin;
1960  });
1961 
1962  return lmask_min;
1963  }

Referenced by make_SurfaceLayer_at_level().

Here is the caller graph for this function:

◆ mac_avg_is_initialized()

bool SurfaceLayer::mac_avg_is_initialized ( const int &  lev) const
inline

Return whether the time filter at this level holds meaningful history.

Parameters
[in]levlevel index
1695 { return m_ma.time_avg_is_initialized(lev); }
bool time_avg_is_initialized(const int &lev) const
Definition: ERF_MOSTAverage.H:299
Here is the call graph for this function:

◆ mac_avg_is_time_averaged()

bool SurfaceLayer::mac_avg_is_time_averaged ( ) const
inline

Return whether the MOST averages are filtered in time.

1683 { return m_ma.do_time_averaging(); }
bool do_time_averaging() const
Definition: ERF_MOSTAverage.H:286
Here is the call graph for this function:

◆ make_SurfaceLayer_at_level()

void SurfaceLayer::make_SurfaceLayer_at_level ( const int &  lev,
int  nlevs,
const amrex::Vector< amrex::MultiFab * > &  mfv,
std::unique_ptr< amrex::MultiFab > &  Theta_prim,
std::unique_ptr< amrex::MultiFab > &  Qv_prim,
std::unique_ptr< amrex::MultiFab > &  Qr_prim,
std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
amrex::MultiFab *  Hwave,
amrex::MultiFab *  Lwave,
amrex::MultiFab *  eddyDiffs,
amrex::Vector< amrex::MultiFab * >  lsm_data,
amrex::Vector< std::string >  lsm_data_name,
amrex::Vector< amrex::MultiFab * >  lsm_flux,
amrex::Vector< std::string >  lsm_flux_name,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  sst_lev,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  tsk_lev,
amrex::Vector< std::unique_ptr< amrex::iMultiFab >> &  lmask_lev,
const amrex::Vector< std::unique_ptr< amrex::MultiFab >> *  mapfac = nullptr 
)
inline

Allocate and initialize surface-layer data for one AMR level.

Parameters
[in]levlevel index
[in]nlevsnumber of AMR levels
[in]mfvconserved and velocity MultiFabs for this level
[in]Theta_primprimitive potential-temperature field
[in]Qv_primprimitive water-vapor field
[in]Qr_primprimitive rain-water field
[in]z_phys_ndnodal physical-height field
[in]Hwavewave-height field
[in]Lwavewavelength field
[in]eddyDiffseddy-diffusivity field
[in]lsm_dataland-surface-model data fields
[in]lsm_data_namenames for lsm_data entries
[in]lsm_fluxland-surface-model flux fields
[in]lsm_flux_namenames for lsm_flux entries
[in]sst_levsea-surface-temperature data by time
[in]tsk_levskin-temperature data by time
[in]lmask_levland-mask data by time
[in]mapfacmap-factor fields at the level (MapFacType); none means m = 1
567  {
568  // Update MOST Average
570  Theta_prim, Qv_prim, Qr_prim,
571  z_phys_nd, mapfac);
572 
573  // Get CC vars
574  amrex::MultiFab& mf = *(mfv[0]);
575 
576  amrex::ParmParse pp(m_pp_prefix);
577 
578  // Do we have a time-varying surface roughness that needs to be saved?
579  if (lev == 0) {
580  const int nghost = 0; // ghost cells not included
581  int lmask_min = lmask_min_reduce(*lmask_lev[0].get(), nghost);
582  amrex::ParallelDescriptor::ReduceIntMin(lmask_min);
583 
584  m_var_z0 = (lmask_min < 1) & (rough_type_sea != RoughCalcType::CONSTANT);
585  if (m_var_z0) {
587  m_face.coordDir() == 2 && m_face.isLow(),
588  "Variable sea roughness surface-layer fluxes are supported only on the z-low face.");
589 
590  std::string rough_sea_string{"charnock"};
591  pp.queryAdd("most.roughness_type_sea", rough_sea_string);
592  amrex::Print() << "Variable sea roughness (type " << rough_sea_string
593  << ")" << std::endl;
594  }
595 
596  // The surface current moves only the water, so without water it would do nothing
598  "The surface current (most.surface_current or erf.use_coupled_currents) moves "
599  "only water, and the surface has none: set erf.is_land = 0 or supply a land "
600  "mask with water.");
601  }
602 
603  if (m_eddyDiffs_lev.size() < lev+1) {
604  m_Hwave_lev.resize(nlevs);
605  m_Lwave_lev.resize(nlevs);
606  m_eddyDiffs_lev.resize(nlevs);
607 
608  m_lsm_data_lev.resize(nlevs);
609  m_lsm_flux_lev.resize(nlevs);
610 
611  m_sst_lev.resize(nlevs);
612  m_tsk_lev.resize(nlevs);
613  m_lmask_lev.resize(nlevs);
614 
615  m_coupled_sst_lev.resize(nlevs, nullptr);
616  m_coupled_sst_valid_lev.resize(nlevs, nullptr);
617 
618  m_surface_current_x.resize(nlevs);
619  m_surface_current_y.resize(nlevs);
620  m_rel_xvel.resize(nlevs);
621  m_rel_yvel.resize(nlevs);
622  m_coupled_current_east_lev.resize(nlevs, nullptr);
623  m_coupled_current_north_lev.resize(nlevs, nullptr);
624  m_coupled_current_covered_lev.resize(nlevs, nullptr);
625  m_coupled_current_cos_lev.resize(nlevs, nullptr);
626  m_coupled_current_sin_lev.resize(nlevs, nullptr);
627  m_coupled_rotation_lev.resize(nlevs);
628  m_coupled_rotation_src_lev.resize(nlevs, nullptr);
629  m_coupled_rotation_src_ba_lev.resize(nlevs);
630  m_coupled_rotation_src_dm_lev.resize(nlevs);
631  m_rel_k_top.resize(nlevs, 0);
632  m_rel_src_ba.resize(nlevs);
633 
634  // Size the MOST params for all levels
635  z_0.resize(nlevs);
636  u_star.resize(nlevs);
637  w_star.resize(nlevs);
638  t_star.resize(nlevs);
639  q_star.resize(nlevs);
640  t_surf.resize(nlevs);
641  q_surf.resize(nlevs);
642  surface_diagnostic_source.resize(nlevs);
643  olen.resize(nlevs);
644  pblh.resize(nlevs);
645  m_planar_bndry.resize(nlevs);
646  m_lsm_held_columns.resize(nlevs);
647  }
648 
649  // Get pointers to SST,TSK and LANDMASK data
650  int nt_tot_sst = sst_lev.size();
651  m_sst_lev[lev].resize(nt_tot_sst);
652  for (int nt(0); nt < nt_tot_sst; ++nt) {
653  m_sst_lev[lev][nt] = sst_lev[nt].get();
654  }
655  int nt_tot_tsk = static_cast<int>(tsk_lev.size());
656  m_tsk_lev[lev].resize(nt_tot_tsk);
657  for (int nt(0); nt < nt_tot_tsk; ++nt) {
658  m_tsk_lev[lev][nt] = tsk_lev[nt].get();
659  }
660  int nt_tot_lmask = static_cast<int>(lmask_lev.size());
661  m_lmask_lev[lev].resize(nt_tot_lmask);
662  for (int nt(0); nt < nt_tot_lmask; ++nt) {
663  m_lmask_lev[lev][nt] = lmask_lev[nt].get();
664  }
665 
666  // The surface current over this level's water, and room for the velocities relative to it
667  if (m_use_surface_current) {
668  define_surface_current(lev, *mfv[Vars::xvel], *mfv[Vars::yvel]);
669  }
670 
671  // Get pointers to wave data
672  m_Hwave_lev[lev] = Hwave;
673  m_Lwave_lev[lev] = Lwave;
674  m_eddyDiffs_lev[lev] = eddyDiffs;
675 
676  // Text-file driven surface forcing modes. The file always contains at
677  // least time(day) and absolute sst(K); the value is normalized to the
678  // canonical SurfaceLayer theta field at the z-low surface.
679  pp.queryAdd("most.use_sfc_fluxes", m_use_sfc_fluxes);
680  pp.queryAdd("most.use_sfc_sst", m_use_sfc_sst);
682  amrex::Abort("Only one of most.use_sfc_fluxes and most.use_sfc_sst may be enabled");
683  }
685  amrex::Abort("erf.most.surf_temp_flux with surface_layer.flux_type = bulk_coeff "
686  "imposes the surface heat flux; it cannot be combined with "
687  "most.use_sfc_fluxes or most.use_sfc_sst");
688  }
690  if (m_use_sfc_fluxes) {
691  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!use_surface_model, "Cannot use surface flux forcing with LSM/Urban model!");
692  // The file's H and LE already carry the density, and the stress
693  // takes the local density, so a surface density would count it
694  // twice in H and LE (see set_sfc_params_from_file_fluxes).
695  // The value is tested, not the key: flux_type = custom has already
696  // queryAdd-ed most.rhosurf with its default of 0 (use the first cell).
697  amrex::Real rhosurf_in = zero;
698  pp.query("most.rhosurf", rhosurf_in);
700  "most.rhosurf cannot be combined with most.use_sfc_fluxes");
701  }
702  if (m_terrain_type == TerrainType::EB) {
703  amrex::Abort("Text-file surface forcing is not supported with EB terrain");
704  }
706  m_face.coordDir() == 2 && m_face.isLow(),
707  "most.use_sfc_fluxes and most.use_sfc_sst are supported only on the z-low face.");
708 
709  // load sensible and latent heat fluxes from sfc to prescribe
710  std::string sfc_file = "";
711  pp.queryAdd("most.sfc_file", sfc_file);
712  if (sfc_file.empty()) {
713  amrex::Abort("most.sfc_file must be set when using text-file surface forcing");
714  }
715 
716  // sfc contains: time(day) sst(K) H(W/m2) LE(W/m2) TAU(m2/s2)
717  sfc = read_cols(sfc_file, 1);
718 
719  const int min_cols = m_use_sfc_fluxes ? 5 : 2;
720  if (static_cast<int>(sfc.size()) < min_cols) {
721  amrex::Abort("Surface forcing file does not contain the required number of columns");
722  }
723 
724  // shift time column in days to be relative to current elapsed time
725  const amrex::Real start_day = sfc[0][0];
726  for (int i = 0; i < static_cast<int>(sfc[0].size()); ++i) {
727  sfc[0][i] = 86400.0 * (sfc[0][i] - start_day);
728  }
729 
730  if (m_use_sfc_sst) {
732  amrex::Abort("most.use_sfc_sst cannot be combined with prescribed heat flux or surf_heating_rate");
733  }
735  amrex::Abort("most.use_sfc_sst cannot be combined with prescribed moisture flux");
736  }
738  amrex::Print() << "Using MOST with prescribed SST from most.sfc_file '" << sfc_file << "' over sea" << std::endl;
739  }
740 
741  if (m_use_sfc_fluxes) {
743  amrex::Print() << "Using MOST with prescribed time-varying surface fluxes from '" << sfc_file << "'" << std::endl;
744  }
745  }
747 
748  // The constructor's check of most.abs_surf_temp sees only most.flux_type; the
749  // modes known here replace the prescribed temperature too. The surface-flux file
750  // makes the fluxes custom, and the SST/TSK and sfc-file SST fills use the
751  // prescribed value as their land temperature, which is a potential temperature there.
752  if (surf_temp_is_absolute) {
754  "most.abs_surf_temp cannot be combined with most.use_sfc_fluxes");
756  (m_sst_lev[lev].empty() || !m_sst_lev[lev][0]) && !m_use_sfc_sst,
757  "most.abs_surf_temp cannot be combined with SST/TSK or sfc-file SST input");
758  }
759 
760  // By default an LSM field named "tsurf", "theta" or "t_surf" is copied into
761  // t_surf unchanged. With this option the LSM skin temperature ("tsurf" from
762  // SLM, "t_sfc" from Noah-MP) is taken as an absolute temperature and
763  // converted to potential temperature at the surface pressure.
764  pp.queryAdd("most.use_lsm_skin_temperature", m_use_lsm_skin_temperature);
765 
766  // Get pointers to LSM data and Fluxes
767  int ndata = static_cast<int>(lsm_data.size());
768  int nflux = static_cast<int>(lsm_flux.size());
769  m_lsm_data_name.resize(ndata);
770  m_lsm_data_lev[lev].resize(ndata);
771  m_lsm_flux_name.resize(nflux);
772  m_lsm_flux_lev[lev].resize(nflux);
773  for (int n(0); n < ndata; ++n) {
774  m_lsm_data_name[n] = lsm_data_name[n];
775  m_lsm_data_lev[lev][n] = lsm_data[n];
776  const std::string lc_name = amrex::toLower(lsm_data_name[n]);
777  // With most.use_lsm_skin_temperature, "tsurf" (SLM) and "t_sfc" (Noah-MP)
778  // are absolute skin temperatures and are converted to potential
779  // temperature in get_lsm_tsurf; "theta" and "t_surf" are taken to be
780  // potential temperature already.
781  if (lc_name == "tsurf" || (m_use_lsm_skin_temperature && lc_name == "t_sfc") ||
782  lc_name == "theta" || lc_name == "t_surf") {
783  m_has_lsm_tsurf = true;
784  m_lsm_tsurf_indx = n;
785  m_lsm_tsurf_is_theta = (lc_name == "theta" || lc_name == "t_surf");
786  }
787  }
789  amrex::Abort("most.use_sfc_sst cannot be combined with an ocean LSM t_surf input");
790  }
791  int n_valid_lsm_flux = 0;
792  bool has_soil_t_flux = false;
793  for (int n(0); n < nflux; ++n) {
794  m_lsm_flux_name[n] = lsm_flux_name[n];
795  m_lsm_flux_lev[lev][n] = lsm_flux[n];
796  if (m_lsm_flux_lev[lev][n]) { ++n_valid_lsm_flux; }
797  if (amrex::toLower(m_lsm_flux_name[n]) == "soil_t_flux") {
798  has_soil_t_flux = true;
799  }
800  }
801  AMREX_ALWAYS_ASSERT((n_valid_lsm_flux==0 || n_valid_lsm_flux>=4 ||
802  (n_valid_lsm_flux==1 && has_soil_t_flux)));
803  if (n_valid_lsm_flux>=4) { m_has_lsm_fluxes = true; }
804 
805  const bool use_sst = (!m_sst_lev[lev].empty() && m_sst_lev[lev][0]);
806  const bool use_tsk = (!m_tsk_lev[lev].empty() && m_tsk_lev[lev][0]);
807 
808  // An imposed bulk_coeff heat flux and a surface temperature or flux supplied from
809  // elsewhere contradict each other: one of the two would be dropped without a word.
811  (use_sst || use_tsk || m_has_lsm_tsurf || m_has_lsm_fluxes ||
813  amrex::Abort("erf.most.surf_temp_flux with surface_layer.flux_type = bulk_coeff "
814  "imposes the surface heat flux; it cannot be combined with SST/TSK data, "
815  "a land-surface or surface model, or a coupled ocean");
816  }
817 
818  // Check if there is a user-specified roughness file to be read
819  std::string fname;
820  bool read_z0 = false;
821  if ( (flux_type == FluxCalcType::MOENG) ||
823  int count = pp.countval("most.roughness_file_name");
824  if (count > 1) {
825  AMREX_ALWAYS_ASSERT(count >= lev+1);
826  pp.query("most.roughness_file_name", fname, lev);
827  read_z0 = true;
828  } else if (count == 1) {
829  if (lev == 0) {
830  pp.queryAdd("most.roughness_file_name", fname);
831  } else {
832  // we will interpolate from the coarsest level
833  fname = "";
834  }
835  read_z0 = true;
836  }
837  // else use z0_const
838  }
839  if (read_z0) {
841  m_face.coordDir() == 2 && m_face.isLow(),
842  "Custom MOST roughness is supported only on the z-low face.");
843  }
844 
845  // LSM flux arrays are planar and compute_sfc_params_from_lsm_fluxes only
846  // writes the k=0 slab, while EB MOST consumes surface parameters at
847  // arbitrary cut-cell k; no valid planar-to-cut-cell mapping exists yet.
848  // Custom roughness is a horizontal material property, handled separately.
850  m_terrain_type, use_sst, use_tsk, m_use_coupled_sst,
852  amrex::Abort(
853  "EB SurfaceLayer does not support planar SST/TSK, coupled SST, LSM surface "
854  "temperature or fluxes; no mapping exists "
855  "from those planar inputs to arbitrary EB cut cells.");
856  }
857 
858  // Attributes for MFs and FABs
859  //--------------------------------------------------------
860  // Create a 2D ba for planar terrain, 3D for EB terrain
861  const int dir = m_face.coordDir();
862  int sm_index;
863  if (m_face.isLow()) {
864  sm_index = m_geom[lev].Domain().smallEnd(dir);
865  } else {
866  sm_index = m_geom[lev].Domain().bigEnd(dir);
867  }
868 
869  amrex::BoxArray ba = mf.boxArray();
870  amrex::BoxArray ba_flux;
871  amrex::IntVect ng{1,1,0};
872 
873  // The lateral-wall implementation uses the two-dimensional land-mask
874  // layout to identify grids on the requested face. Lateral walls are
875  // intentionally restricted to grids spanning the complete z domain;
876  // z-decomposed and partial-height grids are not supported.
877  if (dir != 2) {
878  const int dom_lo_z = m_geom[lev].Domain().smallEnd(2);
879  const int dom_hi_z = m_geom[lev].Domain().bigEnd(2);
880  for (int ibox = 0; ibox < ba.size(); ++ibox) {
882  ba[ibox].smallEnd(2) == dom_lo_z && ba[ibox].bigEnd(2) == dom_hi_z,
883  "Surface layer boundaries on x/y faces require Cartesian grids that "
884  "span the full level z domain; partial-height refined grids and grids "
885  "decomposed in z are not supported. Set amr.max_grid_size_z accordingly.");
886  }
887  }
888 
889  if (m_terrain_type == TerrainType::EB) {
890  // Use full 3D BoxArray for EB terrain
891  ba_flux = ba;
892  ng = amrex::IntVect{1,1,1}; // Include z ghost cells
893  } else {
894  // Collapse to 2D for planar terrain
895  amrex::BoxList bl2d = ba.boxList();
896  for (auto& b : bl2d) {
897  b.setRange(dir,sm_index);
898  }
899  ba_flux = amrex::BoxArray(std::move(bl2d));
900  // Lateral faces need state-width ghosts in the tangential z
901  // direction. A z face only needs the original one-cell x/y halo;
902  // kernels using the wider state/mask boxes clip to the FAB bounds.
903  if (dir == 2) {
904  ng = amrex::IntVect{1,1,0};
905  } else {
906  ng = mf.nGrowVect();
907  ng[dir] = 0;
908  }
909  }
910 
911  const amrex::DistributionMapping& dm = mf.DistributionMap();
912  const int ncomp = 1;
913 
914  // Surface copies of the planar boxes (see fill_planar_boundary)
915  // PlanarBoundary handles duplicate boxes created by a z-split. The x/y
916  // layouts use selective lateral exchange instead.
917  if (m_terrain_type != TerrainType::EB && dir == 2) {
918  const int ksurface = m_face.isLow()
919  ? m_geom[lev].Domain().smallEnd(2)
920  : m_geom[lev].Domain().bigEnd(2);
921  m_planar_bndry[lev].define(ba, ba_flux, dm, ksurface, m_face.isLow());
922  }
923 
924  // Z0 heights FAB
925  //--------------------------------------------------------
926  z_0[lev].define(ba_flux, dm, ncomp, ng);
927  z_0[lev].setVal(z0_const);
928  if (read_z0) {
929  read_custom_roughness(lev, fname);
930  }
931 
932  // The surface layer normalizes with ln(zref / z0), so the reference height
933  // must lie above the roughness length in every column. With the default
934  // (the first cell center) a fine mesh over a rough surface can fail this.
935  {
936  const amrex::MultiFab* zref = m_ma.get_zref(lev);
937  if (zref && zref->boxArray() == z_0[lev].boxArray()) {
938  amrex::MultiFab margin(ba_flux, dm, ncomp, 0);
939  amrex::MultiFab::Copy(margin, *zref, 0, 0, ncomp, 0);
940  amrex::MultiFab::Subtract(margin, z_0[lev], 0, 0, ncomp, 0);
941  if (margin.min(0) <= zero) {
942  amrex::Abort(m_pp_prefix + ".most.zref (or the first cell center), "
943  + std::to_string(zref->min(0)) + " m at its lowest, must exceed "
944  + m_pp_prefix + ".most.z0, " + std::to_string(z_0[lev].max(0))
945  + " m at its largest, in every column");
946  }
947  }
948  }
949 
950  // 2D MFs for U*, T*, T_surf
951  //--------------------------------------------------------
952  u_star[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
953  u_star[lev]->setVal(bogus_large_value);
954 
955  w_star[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
956  w_star[lev]->setVal(bogus_large_value);
957 
958  t_star[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
959  t_star[lev]->setVal(zero); // default to neutral
960 
961  q_star[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
962  q_star[lev]->setVal(zero); // default to dry
963 
964  olen[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
965  olen[lev]->setVal(bogus_large_value);
966 
967  pblh[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
968  pblh[lev]->setVal(bogus_large_value);
969 
970  t_surf[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
971  t_surf[lev]->setVal(default_land_surf_temp);
972 
973  q_surf[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
974  q_surf[lev]->setVal(default_land_surf_moist);
975 
976  // Columns of a refined level that a grid touching the surface holds, one cell beyond
977  // each grid (see LsmFluxColumn). A grid that starts above the ground collapses onto
978  // the same columns but holds no surface fluxes there, so it does not count. Level 0
979  // has no coarse/fine boundary and needs no mask.
980  m_lsm_held_columns[lev].clear();
981  if (lev > 0 && dir == 2 && m_face.isLow() && m_terrain_type != TerrainType::EB) {
982  amrex::iMultiFab& held = m_lsm_held_columns[lev];
983  held.define(ba_flux, dm, 1, amrex::IntVect(1,1,0));
984  held.setVal(0);
985  for (amrex::MFIter mfi(held); mfi.isValid(); ++mfi) {
986  if (m_planar_bndry[lev].is_surface_copy(mfi.index())) {
987  held[mfi].setVal<amrex::RunOn::Device>(1, mfi.validbox());
988  }
989  }
990  held.FillBoundary(m_geom[lev].periodicity());
991  }
992 
993  const amrex::iMultiFab& surface_mask = *m_lmask_lev[lev][0];
995  surface_mask.boxArray().size() == mf.boxArray().size(),
996  "Surface-layer mask and state must have the same number of boxes.");
998  surface_mask.DistributionMap() == mf.DistributionMap(),
999  "Surface-layer mask and state must have identical ownership.");
1001  surface_mask.boxArray().size() == u_star[lev]->boxArray().size(),
1002  "Surface-layer mask and parameters must have the same number of boxes.");
1004  surface_mask.DistributionMap() == u_star[lev]->DistributionMap(),
1005  "Surface-layer mask and parameters must have identical ownership.");
1006 
1008 
1009  surface_diagnostic_source[lev] = std::make_unique<amrex::MultiFab>(ba_flux, dm, ncomp, ng);
1010  surface_diagnostic_source[lev]->setVal(
1012 
1013  // TODO: Do we want an enum struct for indexing?
1014 
1015  if (use_sst || use_tsk || m_has_lsm_tsurf || m_use_coupled_sst || use_surface_model) {
1016  // Valid SST, TSK, LSM or coupled-ocean data; t_surf set before computing
1017  // fluxes (avoids extended lambda capture) Note that land temp will be set
1018  // from m_tsk_lev while sea temp will be set from m_sst_lev
1021 
1022  // Pathways in fill_tsurf_with_sst_and_tsk
1023  amrex::Print() << "Using MOST with specified surface temperature ";
1024  if (m_has_lsm_tsurf && !use_sst && !use_tsk) {
1025  amrex::Print() << "(LSM: " << m_lsm_data_name[m_lsm_tsurf_indx] << ")";
1026  } else if (!use_sst && !use_tsk) {
1027  amrex::Print() << "(land: T0, sea: none)";
1028  } else {
1029  // NOTE: SST from the LOW file populates TSK in update_sst_tsk.
1030  // So if we have TSK, it contains everything and has been
1031  // sanity checked for valid SST values.
1033  if (use_tsk) {
1034  amrex::Print() << "(land: TSK, ";
1035  } else {
1036  amrex::Print() << "(land: T0, ";
1037  }
1038  if (use_tsk && !use_sst) {
1039  amrex::Print() << "sea: TSK)";
1040  } else {
1041  amrex::Print() << "sea: SST)";
1042  AMREX_ALWAYS_ASSERT(m_sst_lev[lev][0]);
1043  }
1044  }
1045  // The coupler is layered on top of whatever the above selected: it
1046  // overwrites only the water cells it actually covers, so the pathway
1047  // named above remains the value for land and for uncovered water.
1048  if (m_use_coupled_sst) {
1049  amrex::Print() << " + coupled ocean SST where covered";
1050  }
1051  amrex::Print() << std::endl;
1052  }
1053  }
int count
Definition: ERF_ActuatorSpreading.cpp:264
constexpr amrex::Real bogus_large_value
Definition: ERF_Constants.H:19
void make_MOSTAverage_at_level(const int &lev, const amrex::Vector< amrex::MultiFab * > &vars_old, std::unique_ptr< amrex::MultiFab > &Theta_prim, std::unique_ptr< amrex::MultiFab > &Qv_prim, std::unique_ptr< amrex::MultiFab > &Qr_prim, std::unique_ptr< amrex::MultiFab > &z_phys_nd, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> *mapfac=nullptr)
Definition: ERF_MOSTAverage.cpp:174
int lmask_min_reduce(amrex::iMultiFab &lmask, const int &nghost)
Definition: ERF_SurfaceLayer.H:1945
amrex::Vector< std::string > m_lsm_data_name
Definition: ERF_SurfaceLayer.H:2326
bool m_has_lsm_tsurf
Definition: ERF_SurfaceLayer.H:2194
bool m_use_sfc_fluxes
Definition: ERF_SurfaceLayer.H:2200
void set_immersed_surface_params(const int &lev)
Definition: ERF_SurfaceLayer.cpp:288
static amrex::Vector< amrex::Vector< amrex::Real > > read_cols(const std::string &fname, const int skip_nlines=1)
Definition: ERF_SurfaceLayer.cpp:4255
bool m_use_sfc_sst
Definition: ERF_SurfaceLayer.H:2201
void define_surface_current(const int &lev, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel)
Definition: ERF_SurfaceLayer.cpp:325
bool m_use_coupled_sst
Definition: ERF_SurfaceLayer.H:2211
void read_custom_roughness(const int &lev, const std::string &fname)
Definition: ERF_SurfaceLayer.cpp:4071
bool planar_sources_supported_for_terrain(TerrainType terrain_type, bool use_sst, bool use_tsk, bool use_coupled_sst, bool has_lsm_tsurf, bool has_lsm_fluxes)
Definition: ERF_SurfaceLayer.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sst_ignored(const bool ignore_sst_requested, const bool have_tsk)
Definition: ERF_SurfaceTemperature.H:189
Here is the call graph for this function:

◆ read_cols()

amrex::Vector< amrex::Vector< amrex::Real > > SurfaceLayer::read_cols ( const std::string &  fname,
const int  skip_nlines = 1 
)
static

Reads columns of data from a text file, returning each column in a vector.

Parameters
[in]fnamepath to text file
[in]skip_nlinesnumber of lines to skip before reading data (e.g, header lines)
Returns
Vector containing each column in the file as a vector
4256 {
4257  std::ifstream ifs(fname);
4258  if (!ifs.is_open())
4259  {
4260  amrex::Error("Error opening input file " + fname);
4261  }
4262 
4263  amrex::Vector<amrex::Vector<amrex::Real>> col_data;
4264  std::string line;
4265  int nlines = 0;
4266  int ncols = -1;
4267 
4268  const auto print_err = [](const std::string &err_fname, int lineno, int cols, int expected_cols) {
4269  amrex::Error("Error reading file '" + err_fname + "': expected line " +
4270  std::to_string(lineno) + " to have " + std::to_string(expected_cols) +
4271  " columns, but got " + std::to_string(cols));
4272  };
4273 
4274  while (std::getline(ifs, line))
4275  {
4276  nlines++;
4277  if (nlines <= skip_nlines) continue;
4278  if (line.empty()) continue;
4279 
4280  std::istringstream iss(line);
4281 
4282  amrex::Real tmp;
4283  // Get the number of columns in the file
4284  if (ncols == -1) {
4285  int j = 0;
4286  while (iss >> tmp) {
4287  col_data.push_back(amrex::Vector<amrex::Real>());
4288  j+= 1;
4289  }
4290 
4291  ncols = j;
4292  iss = std::istringstream(line);
4293  }
4294 
4295  int j = 0;
4296  while (iss >> tmp) {
4297  // verify each line has the same number of columns
4298  if (j >= ncols) {
4299  print_err(fname, nlines, j+1, ncols);
4300  }
4301  col_data[j].push_back(tmp);
4302  j+= 1;
4303  }
4304 
4305  // throw error if there are fewer columns in the line than expected
4306  if (j != ncols) {
4307  print_err(fname, nlines, j, ncols);
4308  }
4309  }
4310 
4311  ifs.close();
4312 
4313  return col_data;
4314 }
@ tmp
Definition: ERF_AdvanceWSM6.cpp:116

Referenced by make_SurfaceLayer_at_level().

Here is the caller graph for this function:

◆ read_custom_roughness()

void SurfaceLayer::read_custom_roughness ( const int &  lev,
const std::string &  fname 
)

Read custom roughness data for one level.

Parameters
[in]levlevel index
[in]fnameroughness-data file name

Read or interpolate custom roughness length data. EB maps the horizontal values through every vertical cell and ghost cell; non-EB terrain retains its surface slab.

Parameters
[in]levCurrent level
[in]fnameRoughness file name; an empty name interpolates from level 0
4073 {
4074  const bool is_eb = m_terrain_type == TerrainType::EB;
4075  // Read the file if we have it
4076  if (!fname.empty()) {
4077  // Only the ioproc reads the file
4078  Gpu::HostVector<Real> m_x,m_y,m_z0;
4079  if (ParallelDescriptor::IOProcessor()) {
4080  Print()<<"Reading MOST roughness file at level " << lev << " : " << fname << std::endl;
4081  std::ifstream file(fname);
4082  if (!file.is_open()) {
4083  Abort("Could not open the MOST roughness file \"" + fname + "\" given as "
4084  "erf.most.roughness_file_name -- please check the file name in the inputs file");
4085  }
4086  if (is_eb) {
4087  m_z0 = read_eb_roughness(file, fname, m_geom[lev], lev);
4088  } else {
4089  Real value1,value2,value3;
4090  while(file>>value1>>value2>>value3){
4091  m_x.push_back(value1);
4092  m_y.push_back(value2);
4093  m_z0.push_back(value3);
4094  }
4095 
4096  AMREX_ALWAYS_ASSERT(m_x.size() == m_y.size());
4097  AMREX_ALWAYS_ASSERT(m_x.size() == m_z0.size());
4098 
4099  if (m_x.empty()) {
4100  Abort("The MOST roughness file \"" + fname + "\" holds no (x, y, z0) triples");
4101  }
4102  }
4103  file.close();
4104  }
4105 
4106  // Broadcast the whole domain to every rank
4107  int ioproc = ParallelDescriptor::IOProcessorNumber();
4108  int nnode = static_cast<int>(m_z0.size());
4109  ParallelDescriptor::Bcast(&nnode, 1, ioproc);
4110 
4111  if (!ParallelDescriptor::IOProcessor()) {
4112  if (!is_eb) {
4113  m_x.resize(nnode);
4114  m_y.resize(nnode);
4115  }
4116  m_z0.resize(nnode);
4117  }
4118  if (!is_eb) {
4119  ParallelDescriptor::Bcast(m_x.data() , nnode, ioproc);
4120  ParallelDescriptor::Bcast(m_y.data() , nnode, ioproc);
4121  }
4122  ParallelDescriptor::Bcast(m_z0.data(), nnode, ioproc);
4123 
4124  // The loop below indexes the file's values as nodes of this level's grid, so a file
4125  // holding fewer values than the grid has nodes would be read past its end
4126  if (!is_eb) {
4127  const Box& dom = m_geom[lev].Domain();
4128  const int nnode_needed = dom.bigEnd(0) + dom.bigEnd(1) * (dom.length(0)+1) + 1;
4129  if (nnode < nnode_needed) {
4130  Abort("The MOST roughness file \"" + fname + "\" holds " + std::to_string(nnode) +
4131  " values but the grid at level " + std::to_string(lev) + " needs at least " +
4132  std::to_string(nnode_needed) + " -- is this file written for this grid?");
4133  }
4134  }
4135 
4136  // Copy data to the GPU
4137  Gpu::DeviceVector<Real> d_x(is_eb ? 0 : nnode),d_y(is_eb ? 0 : nnode),d_z0(nnode);
4138  if (!is_eb) {
4139  Gpu::copy(Gpu::hostToDevice, m_x.begin(), m_x.end(), d_x.begin());
4140  Gpu::copy(Gpu::hostToDevice, m_y.begin(), m_y.end(), d_y.begin());
4141  }
4142  Gpu::copy(Gpu::hostToDevice, m_z0.begin(), m_z0.end(), d_z0.begin());
4143  Real* xp = d_x.data();
4144  Real* yp = d_y.data();
4145  Real* z0p = d_z0.data();
4146 
4147  // Each rank populates its z_0[lev] MultiFab.
4148  const int klo = m_geom[lev].Domain().smallEnd(2);
4149  for (MFIter mfi(z_0[lev]); mfi.isValid(); ++mfi)
4150  {
4151  // EB roughness extends through the entire FAB, including vertical ghosts.
4152  // The shared domain lookup gives overlapping FAB ghosts identical values.
4153  Box gtbx = is_eb ? mfi.fabbox() : mfi.growntilebox();
4154 
4155  if (!is_eb && gtbx.smallEnd(2) != klo) { continue; }
4156 
4157  // Match the horizontal roughness map at the legacy node-like coordinates.
4158  Real tol = Real(1.0e-4);
4159  auto dx = m_geom[lev].CellSizeArray();
4160  auto ProbLoArr = m_geom[lev].ProbLoArray();
4161  int ilo = m_geom[lev].Domain().smallEnd(0);
4162  int jlo = m_geom[lev].Domain().smallEnd(1);
4163  int ihi = m_geom[lev].Domain().bigEnd(0);
4164  int jhi = m_geom[lev].Domain().bigEnd(1);
4165  const int file_i_offset = is_eb ? ilo : 0;
4166  const int file_j_offset = is_eb ? jlo : 0;
4167  const int file_stride = is_eb ? ihi-ilo+1 : ihi-ilo+2;
4168 
4169  Array4<Real> const& z0_arr = z_0[lev].array(mfi);
4170  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
4171  {
4172  // Clip indices for ghost-cells
4173  int ii = amrex::Clamp(i,ilo,ihi) - file_i_offset;
4174  int jj = amrex::Clamp(j,jlo,jhi) - file_j_offset;
4175  const int roughness_k = is_eb ? k : klo;
4176  const int inode = ii + jj * file_stride;
4177  if (is_eb) {
4178  // Coverage and values were validated and ordered on the I/O rank.
4179  z0_arr(i,j,k) = z0p[inode];
4180  return;
4181  }
4182 
4183  // Location of nodes
4184  Real x = ProbLoArr[0] + ii * dx[0];
4185  Real y = ProbLoArr[1] + jj * dx[1];
4186  if (std::sqrt(amrex::Math::powi<2>(x-xp[inode])+amrex::Math::powi<2>(y-yp[inode])) < tol) {
4187  z0_arr(i,j,roughness_k) = z0p[inode];
4188  } else {
4189  // Unexpected list order, do brute force search
4190  Real z0loc = zero;
4191  bool found = false;
4192  for (int n=0; n<nnode; ++n) {
4193  Real delta=std::sqrt(amrex::Math::powi<2>(x-xp[n])+amrex::Math::powi<2>(y-yp[n]));
4194  if (delta < tol) {
4195  found = true;
4196  z0loc = z0p[n];
4197  break;
4198  }
4199  }
4200  AMREX_ASSERT_WITH_MESSAGE(found, "Location read from terrain file does not match the grid!");
4201  amrex::ignore_unused(found);
4202  z0_arr(i,j,roughness_k) = z0loc;
4203  }
4204  });
4205  } // mfi
4206  } else {
4207  AMREX_ALWAYS_ASSERT(lev > 0);
4208 
4209  Print()<<"Interpolating MOST roughness at level " << lev << std::endl;
4210 
4211  // Create a BC mapper that uses FOEXTRAP at domain bndry
4212  Vector<int> bc_lo(3,ERFBCType::foextrap);
4213  Vector<int> bc_hi(3,ERFBCType::foextrap);
4214  Vector<BCRec> bcr; bcr.push_back(BCRec(bc_lo.data(),bc_hi.data()));
4215 
4216  // Create ref ratio
4217  IntVect ratio;
4218  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
4219  ratio[idim] = m_geom[lev].Domain().length(idim) / m_geom[0].Domain().length(idim);
4220  }
4221  // Non-EB roughness is a single surface slab at klo on both levels, so map it
4222  // horizontally only; a z ratio would pull unfilled cells above the slab into the
4223  // coarse patch and its z slopes.
4224  if (!is_eb) { ratio[2] = 1; }
4225 
4226  // Interpolate from the coarsest grid. InterpFromCoarseLevel copies z_0[0] onto
4227  // coarse patches laid out like the fine boxes and fills the physical ghosts; a raw
4228  // MFInterpolater::interp call would need z_0[0] to share z_0[lev]'s box ownership,
4229  // which it does not.
4230  MFInterpolater* interp = &mf_cell_cons_interp;
4231  GpuBndryFuncFab<FabFillNoOp> bndry_func(FabFillNoOp{});
4232  PhysBCFunct<GpuBndryFuncFab<FabFillNoOp>>
4233  cbc(m_geom[0], bcr, bndry_func), fbc(m_geom[lev], bcr, bndry_func);
4234  InterpFromCoarseLevel(z_0[lev], z_0[lev].nGrowVect(), Real(0.0),
4235  z_0[0], 0, 0, 1, m_geom[0], m_geom[lev],
4236  cbc, 0, fbc, 0, ratio, interp, bcr, 0);
4237  }
4238 
4239  // The file is written only to the boxes that touch the surface; the copies of the boxes
4240  // above it (a grid split in z) are read too (ComputeTurbulentViscosity), and update_fluxes
4241  // does not fill a roughness that is never rewritten, so fill them here once
4242  if (m_terrain_type == TerrainType::EB || m_face.coordDir() == 2) {
4243  fill_planar_boundary(lev, z_0[lev]);
4244  }
4245 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
@ m_y
Definition: ERF_DataStruct.H:41
@ m_x
Definition: ERF_DataStruct.H:40
@ foextrap
Definition: ERF_IndexDefines.H:316
Gpu::HostVector< Real > read_eb_roughness(std::istream &file, const std::string &fname, const Geometry &geom, int lev)
Definition: ERF_SurfaceLayer.cpp:48

Referenced by make_SurfaceLayer_at_level().

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

◆ rotates_surface_fluxes()

bool SurfaceLayer::rotates_surface_fluxes ( ) const
inline

Return whether the surface fluxes are rotated with the terrain slope (erf.use_rotate_surface_flux), splitting them over the x, y and z faces.

1866 { return m_rotate; }

◆ roughness()

amrex::Real SurfaceLayer::roughness ( ) const
inline

The constant roughness length [m] the levels take.

1855 { return z0_const; }

◆ set_coupled_current_active()

void SurfaceLayer::set_coupled_current_active ( const bool  active)
inline

Declare that an ocean coupler will supply the surface current for this run.

Must be called before make_SurfaceLayer_at_level, which allocates the current. The surface is at rest until update_coupled_surface_current first sets it.

Parameters
[in]activewhether a coupled surface current is configured
2027  {
2028  // Idempotent: the set-up that calls it may run again on the same layer
2029  if (!active || m_coupled_current_active) { return; }
2031  "most.surface_current cannot be combined with a coupled surface current "
2032  "(erf.use_coupled_currents).");
2033  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_face.coordDir() == 2 && m_face.isLow(),
2034  "A coupled surface current is supported only on the z-low face.");
2036  "A coupled surface current is not supported with EB terrain.");
2037  m_coupled_current_active = true;
2038  m_use_surface_current = true;
2039  }
bool m_coupled_current_active
Definition: ERF_SurfaceLayer.H:2294
Here is the call graph for this function:

◆ set_coupled_sst_active()

void SurfaceLayer::set_coupled_sst_active ( const bool  active)
inline

Declare that an ocean coupler will supply SST for this run.

Must be called before make_SurfaceLayer_at_level, which uses it to select ThetaCalcType::SURFACE_TEMPERATURE.

Parameters
[in]activewhether coupled SST is configured
2016 { m_use_coupled_sst = active; }

◆ set_default_roughness()

bool SurfaceLayer::set_default_roughness ( amrex::Real  z0)
inline

The land roughness length [m] to use when erf.most.z0 is not given (the two-stream balance's, from Noah-MP's tables). Call before the levels are made, which set z0 from it.

Taking it also replaces the erf.most.z0 entry that the constructor's queryAdd put in the ParmParse table. job_info (ParmParse::dumpTable) then records the roughness the run used.

Returns
whether the roughness was taken: an erf.most.z0 given in the inputs stands.
1845  {
1846  if (m_z0_given) { return false; }
1847  z0_const = z0;
1848  amrex::ParmParse pp(m_pp_prefix);
1849  pp.remove("most.z0");
1850  pp.add("most.z0", z0_const);
1851  return true;
1852  }
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
Here is the call graph for this function:

◆ set_immersed_surface_params()

void SurfaceLayer::set_immersed_surface_params ( const int &  lev)

Set benign surface scales in immersed columns (land mask 2), including ghosts. Called after allocation, checkpoint restoration, and surface-scale updates. Preserve PBL height, roughness, surface temperature, and surface moisture.

Parameters
[in]levlevel index
289 {
290  // The land mask describes ground columns, not the full height of a lateral wall.
291  if (m_face.coordDir() != 2 ||
292  (m_terrain_type != TerrainType::ImmersedForcing && !m_has_immersed_buildings)) {
293  return;
294  }
295  const auto& surface_mask = *m_lmask_lev[lev][0];
296  for (MFIter mfi(*u_star[lev]); mfi.isValid(); ++mfi) {
297  Box bx = mfi.fabbox();
298  // Limit the halo to the mask's available ghost cells.
299  Box mask_columns = surface_mask.fabbox(mfi.index());
300  mask_columns.setRange(2, bx.smallEnd(2), bx.length(2));
301  bx &= mask_columns;
302 
303  const auto mask_arr = surface_mask.const_array(mfi);
304  const auto u_star_arr = u_star[lev]->array(mfi);
305  const auto w_star_arr = w_star[lev]->array(mfi);
306  const auto t_star_arr = t_star[lev]->array(mfi);
307  const auto q_star_arr = q_star[lev]->array(mfi);
308  const auto olen_arr = olen[lev]->array(mfi);
309  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
310  if (mask_arr(i,j,0) == 2) {
311  // MOST and LSM updates skip immersed columns. Finite, inactive
312  // scales keep their initialization sentinels out of stress/TKE
313  // calculations; immersed forcing handles roof and wall physics.
314  u_star_arr(i,j,k) = zero;
315  w_star_arr(i,j,k) = zero;
316  t_star_arr(i,j,k) = zero;
317  q_star_arr(i,j,k) = zero;
318  olen_arr(i,j,k) = immersed_neutral_obukhov_length;
319  }
320  });
321  }
322 }
constexpr amrex::Real immersed_neutral_obukhov_length
Definition: ERF_Constants.H:31

Referenced by make_SurfaceLayer_at_level().

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

◆ set_mac_avg_initialized()

void SurfaceLayer::set_mac_avg_initialized ( const int &  lev)
inline

Declare the time filter at this level to hold meaningful history (restart).

Parameters
[in]levlevel index
void set_time_avg_initialized(const int &lev)
Definition: ERF_MOSTAverage.H:310
Here is the call graph for this function:

◆ set_mac_plane_avg()

bool SurfaceLayer::set_mac_plane_avg ( const int &  lev,
const amrex::Vector< amrex::Real > &  pavg 
)
inline

Restore the filtered plane averages from a checkpoint; returns false if the checkpoint does not hold what this run expects.

Parameters
[in]levlevel index
[in]pavgfiltered plane averages, one per average component
1727 { return m_ma.set_plane_average(lev, pavg); }
bool set_plane_average(const int &lev, const amrex::Vector< amrex::Real > &pavg)
Definition: ERF_MOSTAverage.H:336
Here is the call graph for this function:

◆ set_pblh()

void SurfaceLayer::set_pblh ( const int &  lev,
const amrex::MultiFab &  pblh_in 
)

Store the PBL height a PBL scheme (MRF, YSU) has diagnosed.

pblh_in has no ghost cells, so the ghost cells of pblh are filled here: those that another grid of this level or a periodic image holds by fill_planar_boundary; those at a coarse/fine boundary from the next coarser level (the same injection as fill_pblh_from_coarser), so that they agree with the coarse state the other surface fields there are computed from; those outside a non-periodic domain from the nearest column of the domain (by fill_planar_boundary, or with EB after it, so that a corner beside another grid takes that grid's height); and the rest – where the coarser level has no height yet – from the nearest column of their own grid.

Parameters
[in]levCurrent level
[in]pblh_inPBL height, on the grids of the eddy diffusivities (3D, no ghost cells)
3623 {
3624  // NOTE: pblh[lev] is a 2D MF (except with EB)
3625  // pblh_in is a 3D MF built off the eddydiffs BA
3626  AMREX_ALWAYS_ASSERT(pblh[lev]);
3627  MultiFab& dst = *pblh[lev];
3628 
3629  // The boxes of the two are paired by index below
3631  pblh_in.size() == dst.size() && pblh_in.DistributionMap() == dst.DistributionMap(),
3632  "SurfaceLayer::set_pblh: the PBL height must be on the grids of the surface layer");
3633 
3634  std::unique_ptr<MultiFab> crse;
3635  if (lev > 0 && pblh[lev-1]) {
3636  crse = std::make_unique<MultiFab>(dst.boxArray(), dst.DistributionMap(), 1, dst.nGrowVect());
3637  inject_pblh_from_coarser(lev, *crse);
3638  }
3639  // Only the columns inside the domain (or a periodic image of it) take the coarse height
3640  const Geometry& geom = m_geom[lev];
3641  const NearestColumn in_domain(geom.Domain());
3642  const bool per_x = geom.isPeriodic(0);
3643  const bool per_y = geom.isPeriodic(1);
3644 
3645 #ifdef _OPENMP
3646 #pragma omp parallel if (Gpu::notInLaunchRegion())
3647 #endif
3648  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi)
3649  {
3650  const Box gtbx = mfi.growntilebox();
3651  const Box& vbx = mfi.validbox();
3652  const Box& sbx = pblh_in.box(mfi.index());
3654  sbx.smallEnd(0) == vbx.smallEnd(0) && sbx.bigEnd(0) == vbx.bigEnd(0) &&
3655  sbx.smallEnd(1) == vbx.smallEnd(1) && sbx.bigEnd(1) == vbx.bigEnd(1),
3656  "SurfaceLayer::set_pblh: the PBL height must be on the grids of the surface layer");
3657 
3658  // Clamp to the source box, which is the one we read
3659  const NearestColumn col(sbx);
3660  const int klo = sbx.smallEnd(2);
3661  const int khi = sbx.bigEnd(2);
3662 
3663  const Array4< Real> pblh_dst = dst.array(mfi);
3664  const Array4<const Real> pblh_src = pblh_in.const_array(mfi);
3665  const Array4<const Real> pblh_crse = (crse) ? crse->const_array(mfi) : Array4<const Real>{};
3666  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
3667  {
3668  const int li = col.i(i);
3669  const int lj = col.j(j);
3670  const int lk = amrex::min(amrex::max(k, klo), khi);
3671  Real h = pblh_src(li,lj,lk);
3672  const bool inside = (per_x || in_domain.i(i) == i) && (per_y || in_domain.j(j) == j);
3673  if (pblh_crse && inside && (li != i || lj != j) && pblh_is_diagnosed(pblh_crse(i,j,k))) {
3674  h = pblh_crse(i,j,k);
3675  }
3676  pblh_dst(i,j,k) = h;
3677  });
3678  }
3679  fill_planar_boundary(lev, dst);
3680 
3681  // With EB, a ghost cell outside a non-periodic domain but beside another grid of this level
3682  // (a corner) was left above with the nearest column of its own grid, which the FillBoundary
3683  // in fill_planar_boundary does not overwrite; give it the nearest column of the domain,
3684  // which is inside this fab and now holds the height of the grid that owns it. On a planar
3685  // layout fill_planar_boundary has already given such a cell that value.
3686  if (m_terrain_type == TerrainType::EB && (!per_x || !per_y)) {
3687 #ifdef _OPENMP
3688 #pragma omp parallel if (Gpu::notInLaunchRegion())
3689 #endif
3690  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi)
3691  {
3692  const Box gtbx = mfi.growntilebox();
3693  const Array4<Real> pblh_dst = dst.array(mfi);
3694  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
3695  {
3696  const int ci = (per_x) ? i : in_domain.i(i);
3697  const int cj = (per_y) ? j : in_domain.j(j);
3698  if (ci != i || cj != j) {
3699  pblh_dst(i,j,k) = pblh_dst(ci,cj,k);
3700  }
3701  });
3702  }
3703  }
3704 }
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool pblh_is_diagnosed(const amrex::Real &pblh)
Definition: ERF_Wstar.H:15
real(c_double), private ci
Definition: ERF_module_mp_morr_two_moment.F90:203
Here is the call graph for this function:

◆ set_q_surf()

void SurfaceLayer::set_q_surf ( const int &  lev,
const amrex::Real  qsurf 
)
inline

Set the surface-moisture field to a constant value.

Parameters
[in]levlevel index
[in]qsurfsurface moisture
1889 { q_surf[lev]->setVal(qsurf); }

◆ set_sfc_params_from_file_fluxes()

void SurfaceLayer::set_sfc_params_from_file_fluxes ( const int &  lev,
const amrex::MultiFab &  cons_in,
const amrex::Real &  tflux_in,
const amrex::Real &  qflux_in,
const amrex::Real &  sfc_tau 
)

Set kinematic u*, t*, and q* from the fluxes interpolated from most.sfc_file.

Parameters
[in]levlevel index
[in]cons_inconserved state supplying the first-cell density
[in]tflux_insensible heat flux H [W/m2]
[in]qflux_inlatent heat flux LE [W/m2]
[in]sfc_taukinematic surface stress TAU [m2/s2]

Set u*, t*, and q* from the fluxes interpolated from most.sfc_file.

The file's H and LE [W/m2] are dynamic fluxes, but its TAU [m2/s2] is kinematic. All three are stored kinematic, as most.ustar/tstar/qstar are without most.rhosurf, and custom_flux multiplies each by the local density: H/Cp_d and LE/L_v are divided here by the first-cell density that custom_flux multiplies back, so they are applied unchanged, and the applied stress is rho*TAU.

Parameters
[in]levCurrent level
[in]cons_inConserved state supplying the first-cell density
[in]tflux_inSensible heat flux H [W/m2]
[in]qflux_inLatent heat flux LE [W/m2]
[in]sfc_tauKinematic surface stress TAU [m2/s2]
2406 {
2407  u_star[lev]->setVal(std::sqrt(sfc_tau));
2408 
2409  const int klo = m_geom[lev].Domain().smallEnd(2);
2410  const Real rho_tflux = tflux_in / Cp_d;
2411  const Real rho_qflux = qflux_in / L_v;
2412 
2413  for (MFIter mfi(*t_star[lev]); mfi.isValid(); ++mfi)
2414  {
2415  Box gtbx = mfi.growntilebox();
2416 
2417  // Only the copy of a z-split planar field on the z-low face reads the 3-D
2418  // state; fill_planar_boundary at the end of update_fluxes fills the others.
2419  if (gtbx.smallEnd(2) != klo ||
2420  !m_planar_bndry[lev].is_surface_copy(mfi.index())) {
2421  continue;
2422  }
2423  gtbx &= cons_in.fabbox(mfi.index());
2424  if (gtbx.isEmpty()) { continue; }
2425 
2426  const auto cons_arr = cons_in.const_array(mfi);
2427  const auto t_star_arr = t_star[lev]->array(mfi);
2428  const auto q_star_arr = q_star[lev]->array(mfi);
2429 
2430  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
2431  {
2432  const Real rho = cons_arr(i,j,klo,Rho_comp);
2433  t_star_arr(i,j,k) = rho_tflux / rho;
2434  q_star_arr(i,j,k) = rho_qflux / rho;
2435  });
2436  }
2437 }
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:51
constexpr amrex::Real L_v
Definition: ERF_Constants.H:67
Here is the call graph for this function:

◆ set_skin_moisture()

void SurfaceLayer::set_skin_moisture ( const int &  lev,
const amrex::MultiFab *  moisture,
bool  use_resistances = false,
amrex::Real  hs = amrex::Real(0) 
)
inline

Take the land surface mixing ratio of level lev from the skin set by set_skin_temperature (fill_qsurf_with_skin_moisture), or stop doing so (nullptr). The owner keeps the field alive and resets the pointer whenever it reallocates it.

Parameters
[in]levlevel index
[in]moistureper-column field in the components of erf_surface_moisture::Component, on the surface-layer layout
[in]use_resistancesform q_surf from the soil resistance and pore humidity and, where the field's VegetationFraction is positive, the canopy's (two_source_surface_mixing_ratio), not from the soil-water factor alone: the two-stream balance passes true whenever it has a soil type
[in]hsthe canopy's vapor-deficit parameter [1/(kg/kg)]; 0 without vegetation
1802  {
1803  if (lev >= static_cast<int>(m_skin_moisture_lev.size())) {
1804  m_skin_moisture_lev.resize(lev + 1, nullptr);
1805  m_skin_moisture_resistances_lev.resize(lev + 1, 0);
1806  m_skin_moisture_hs_lev.resize(lev + 1, amrex::Real(0));
1807  }
1808  m_skin_moisture_lev[lev] = moisture;
1809  m_skin_moisture_resistances_lev[lev] = use_resistances ? 1 : 0;
1810  m_skin_moisture_hs_lev[lev] = hs;
1811  }
amrex::Vector< int > m_skin_moisture_resistances_lev
Definition: ERF_SurfaceLayer.H:2322
amrex::Vector< const amrex::MultiFab * > m_skin_moisture_lev
Definition: ERF_SurfaceLayer.H:2321
amrex::Vector< amrex::Real > m_skin_moisture_hs_lev
Definition: ERF_SurfaceLayer.H:2323

◆ set_skin_temperature()

void SurfaceLayer::set_skin_temperature ( const int &  lev,
const amrex::MultiFab *  t_skin 
)
inline

Take the land surface temperature of level lev from an external absolute skin temperature [K] on the surface-layer layout, or stop doing so (nullptr). update_fluxes reads it; the owner keeps it alive and resets the pointer whenever it reallocates the field.

Parameters
[in]levlevel index
[in]t_skinabsolute skin temperature, or nullptr
1746  {
1747  if (lev >= static_cast<int>(m_skin_tsurf_lev.size())) {
1748  m_skin_tsurf_lev.resize(lev + 1, nullptr);
1749  }
1750  m_skin_tsurf_lev[lev] = t_skin;
1751  }

◆ set_surface_layer_faces()

void SurfaceLayer::set_surface_layer_faces ( const amrex::GpuArray< int, AMREX_SPACEDIM *2 > &  active_faces)
inline

Set the domain faces that use the surface-layer boundary condition.

The face set is used to suppress transpose stress writes at shared edges; the face-normal component remains owned by its corresponding face path.

Parameters
[in]active_faceswhether a specific x/y/z lo/hi face is enabled
2079  {
2080  m_surface_layer_faces = active_faces;
2081  }

◆ set_t_surf()

void SurfaceLayer::set_t_surf ( const int &  lev,
const amrex::Real  tsurf 
)
inline

Set the surface-temperature field to a constant value.

Parameters
[in]levlevel index
[in]tsurfsurface temperature
1874 { t_surf[lev]->setVal(tsurf); }
@ tsurf
Definition: ERF_SLM.H:29

◆ similarity_functions()

const similarity_funs& SurfaceLayer::similarity_functions ( ) const
inline

Similarity functions of this surface layer (most.stable_functions).

1660 { return m_sfuns; }

Referenced by ERF::FillPlot2DVars().

Here is the caller graph for this function:

◆ skin_moisture_conflict()

std::string SurfaceLayer::skin_moisture_conflict ( ) const
inline

Why this surface layer cannot take its surface mixing ratio from the skin (set_skin_moisture), or an empty string when it can: everything skin_temperature_conflict asks, plus a moisture model and a moisture flux computed from a surface mixing ratio (erf.most.surf_moist given).

1820  {
1821  const std::string temperature = skin_temperature_conflict();
1822  if (!temperature.empty()) { return temperature; }
1823  if (!use_moisture) {
1824  return "the run has no moisture model";
1825  }
1827  return "the surface layer does not compute its moisture flux from a surface "
1828  "mixing ratio (set erf.most.surf_moist, not a flux)";
1829  }
1830  return "";
1831  }
std::string skin_temperature_conflict() const
Definition: ERF_SurfaceLayer.H:1760
Here is the call graph for this function:

◆ skin_temperature_conflict()

std::string SurfaceLayer::skin_temperature_conflict ( ) const
inline

Why this surface layer cannot take its surface temperature from an external skin temperature, or an empty string when it can: the skin sets t_surf, so the surface layer must compute its heat flux from t_surf (a surface temperature given, no heating rate) on a non-EB lower surface without rotated surface fluxes, and no land model may own t_surf.

1761  {
1762  if (m_terrain_type == TerrainType::EB) {
1763  return "the surface layer is on EB terrain";
1764  }
1765  // Rotated, the flux is split over hfx1/hfx2/hfx3 and the balance, which removes
1766  // the vertical-face flux hfx3 only, would lose cos(slope) of what the air gains.
1767  if (m_rotate) {
1768  return "erf.use_rotate_surface_flux is set";
1769  }
1771  return "the surface layer does not compute its heat flux from a surface "
1772  "temperature (set erf.most.pot_surf_temp or erf.most.abs_surf_temp, not a "
1773  "flux or custom/bulk fluxes)";
1774  }
1775  if (surf_heating_rate != amrex::Real(0)) {
1776  return "erf.most.surf_heating_rate is set";
1777  }
1779  return "a land-surface or surface model supplies the surface temperature";
1780  }
1781  return "";
1782  }

Referenced by skin_moisture_conflict().

Here is the caller graph for this function:

◆ surface_sum()

Real SurfaceLayer::surface_sum ( const int &  lev,
const amrex::MultiFab &  mf,
int  comp = 0 
) const

Sum a planar field over the valid cells of the surface, counting each surface cell once.

On a level whose grids are split in the surface-normal direction the planar BoxArray holds one duplicate box per stacked 3D box (see PlanarBoundary), so a plain sum over the planar MultiFab counts every surface cell once per stacked box. Only the computed surface copies are read here, so the duplicates need not have been filled by fill_planar_boundary, and the gather needs no communication. On EB terrain the fields are 3D without duplicates, and the lowest plane of the domain is summed. Only for a surface layer on a z face.

Parameters
[in]levlevel index
[in]mfcell-centered planar MultiFab on this surface's planar BoxArray
[in]compcomponent to sum
1018 {
1019  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_face.coordDir() == 2,
1020  "SurfaceLayer::surface_sum is only defined for a surface layer on a z face");
1021  if (m_terrain_type == TerrainType::EB) {
1022  // EB fields live on the full 3D BoxArray without duplicates: sum the lowest plane
1023  return sumToLine(mf, comp, 1, m_geom[lev].Domain(), 2)[0];
1024  }
1025  // A face-centered planar field (the MOST velocity averages) shares the planar BoxArray
1026  // but not its index type, and neighboring surface boxes would then share a face, which
1027  // this sum would count twice
1028  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(mf.boxArray().ixType().cellCentered(),
1029  "SurfaceLayer::surface_sum is only defined for a cell-centered planar MultiFab");
1030  const PlanarBoundary& pb = m_planar_bndry[lev];
1031  MultiFab surface_copy(pb.surface_boxes(), pb.surface_dm(), 1, 0);
1032  pb.gather_surface(mf, surface_copy, comp, 0, 1);
1033  return surface_copy.sum(0);
1034 }
Definition: ERF_PlanarBoundary.H:44
const amrex::DistributionMapping & surface_dm() const
Ranks owning the surface copies: each is on the rank of the planar box it is a copy of.
Definition: ERF_PlanarBoundary.H:127
void gather_surface(const amrex::MultiFab &mf, amrex::MultiFab &dst, int scomp, int dcomp, int ncomp) const
Definition: ERF_PlanarBoundary.cpp:288
const amrex::BoxArray & surface_boxes() const
Cell-centered surface copies of the planar boxes, without duplicates.
Definition: ERF_PlanarBoundary.H:124
Here is the call graph for this function:

◆ update_coupled_sst_ptr()

void SurfaceLayer::update_coupled_sst_ptr ( const int  lev,
amrex::MultiFab *  sst_ptr,
amrex::iMultiFab *  valid_ptr 
)
inline

Hand over the coupled sea-surface temperature and its per-cell coverage flag.

Both pointers stay owned by the caller and must remain valid, and on the same layout, until replaced. Passing a null sst_ptr retracts the coupled lane, so the lower-boundary SST/TSK value stands everywhere again.

Parameters
[in]levlevel index
[in]sst_ptrcoupled sea-surface temperature [K]
[in]valid_ptrper-cell coverage flag; nonzero where the coupler supplied a value. Null means no cell is covered.
2003  {
2004  m_coupled_sst_lev[lev] = sst_ptr;
2005  m_coupled_sst_valid_lev[lev] = valid_ptr;
2006  }

◆ update_coupled_surface_current()

void SurfaceLayer::update_coupled_surface_current ( const int &  lev,
const amrex::MultiFab &  east,
const amrex::MultiFab &  north,
const amrex::iMultiFab *  covered,
const amrex::MultiFab *  cos_alpha,
const amrex::MultiFab *  sin_alpha 
)

Set the surface current on this level from an ocean coupler's current at the cell centers of the surface.

The current is rotated from east and north to the grid axes and averaged to the faces. A face takes it where the cells on both sides of it are water (land mask 0) and covered by the ocean, and is at rest elsewhere. Outside a non-periodic domain, the cells beside a face are those of the nearest column inside it.

The fields are borrowed, like the coupled SST's: the surface layer keeps them and sets the current from them again whenever the level is remade, so they must outlive it or be replaced by a later call.

Parameters
[in]levlevel index
[in]easteastward current [m/s], cell-centered on the 2D surface layout
[in]northnorthward current [m/s], on the layout of east
[in]coverednonzero where the ocean covers the cell, on the layout of east; null when it covers none, as for the coupled SST
[in]cos_alphacosine of the angle of the grid x axis from east, cell-centered on the 2D surface layout; null when the grid is aligned with east
[in]sin_alphasine of that angle, on the layout of cos_alpha
478 {
480  m_use_surface_current && lev < static_cast<int>(m_surface_current_x.size()) &&
481  m_surface_current_x[lev],
482  "The coupled surface current was set on a level made before set_coupled_current_active.");
483 
484  // Kept, so a remade level takes the current again (define_surface_current)
485  m_coupled_current_east_lev[lev] = &east;
486  m_coupled_current_north_lev[lev] = &north;
487  m_coupled_current_covered_lev[lev] = covered;
488  m_coupled_current_cos_lev[lev] = cos_alpha;
489  m_coupled_current_sin_lev[lev] = sin_alpha;
491 }
Here is the call graph for this function:

◆ update_fluxes()

void SurfaceLayer::update_fluxes ( const int &  lev,
const double &  elapsed_time,
const double &  elapsed_time_since_start_low,
amrex::MultiFab &  cons_in,
const std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
const std::unique_ptr< amrex::MultiFab > &  walldist,
int  max_iters = 100 
)

Update surface fluxes and related surface-layer state.

Parameters
[in]levlevel index
[in]elapsed_timecurrent elapsed simulation time
[in]elapsed_time_since_start_lowelapsed time relative to low-data start
[in,out]cons_inconserved state used by the flux update
[in]z_phys_ndnodal physical-height field
[in]walldistwall-distance field
[in]max_itersmaximum MOST iteration count

Wrapper to update ustar and tstar for Monin Obukhov similarity theory.

Parameters
[in]levCurrent level
[in]elapsed_timeCurrent simulation time
[in]elapsed_time_since_start_lowTime since the start of the lower-boundary data
[in,out]cons_inConserved state, updated when RANS TKE is initialized from surface-layer data
[in]z_phys_ndNodal physical height used by terrain-aware surface calculations
[in]walldistWall distance used when updating boundary TKE
[in]max_itersMaximum iterations to use in the MOST flux solve
512 {
513  auto reset_failure = [this] () {
514  auto* failure = m_surface_conversion_failure.dataPtr();
515  ParallelFor(1, [=] AMREX_GPU_DEVICE (int) noexcept
516  {
518  });
519  };
520  auto* conversion_fail = m_surface_conversion_failure.dataPtr();
521 
522  const bool zlo = (int) m_face == Orientation::zlo();
523  const bool has_sst_tsk = zlo && !m_sst_lev[lev].empty() && m_sst_lev[lev][0];
524  const bool has_sfc_sst = zlo && m_use_sfc_sst;
525  // Keep this predicate aligned with the absolute-temperature producer below: the
526  // bulk-coefficient path consumes t_surf without selecting SURFACE_TEMPERATURE.
527  const bool has_absolute_temperature = surf_temp_is_absolute &&
530  const bool has_coupled_sst = zlo && lev < static_cast<int>(m_coupled_sst_lev.size()) &&
531  m_coupled_sst_lev[lev];
532  const bool has_lsm_temperature_conversion =
534  const bool has_skin_temperature = zlo && lev < static_cast<int>(m_skin_tsurf_lev.size()) &&
535  m_skin_tsurf_lev[lev];
536  const bool check_surface_temperature = has_sst_tsk || has_sfc_sst ||
537  has_absolute_temperature || has_coupled_sst || has_lsm_temperature_conversion ||
538  has_skin_temperature;
539  const bool check_surface_humidity = use_moisture;
540  if (check_surface_temperature || check_surface_humidity) {
541  reset_failure();
542  }
543  // Update with SST/TSK data if we have a valid pointer.
544  //
545  // This runs even when an ocean coupler is active: it is the only writer of
546  // t_surf over land, and it is the fallback for the water cells the coupler
547  // does not cover. Coupled SST is applied below and only where the coupler
548  // actually supplied a value, so the lower-boundary data is the base layer
549  // rather than an alternative to it.
550  //
551  // Without an SST at the level, neither the SST nor the TSK is taken; the restart of
552  // an older checkpoint judges its fields by the same condition
553  // (erf_checkpoint_surface_temperature::restart_surface_temperature_use).
554  if (has_sst_tsk) {
555  fill_tsurf_with_sst_and_tsk(lev, elapsed_time_since_start_low, cons_in, z_phys_nd,
556  conversion_fail);
557  }
558  if (has_sfc_sst) {
559  // Set tsurf to time varying SST from sfc file
560  fill_tsurf_with_sfc_sst(lev, elapsed_time, cons_in, z_phys_nd, conversion_fail);
561  }
562 
563  // Apply heating rate if needed. The rate is applied from the start of the
564  // simulation, so it is given the elapsed simulation time, not the time since the
565  // start of the lower-boundary data: that includes start_time, which with
566  // erf.start_datetime and no wrflowinp file is the epoch time of the start.
568  update_surf_temp(elapsed_time);
569  }
570  if (has_absolute_temperature) {
571  // bulk_coeff reads t_surf without selecting the surface-temperature formulation;
572  // its absolute temperature is converted with the current surface pressure too.
573  // Heating-rate updates remain exclusive to SURFACE_TEMPERATURE above.
574  fill_tsurf_with_abs_surf_temp(lev, elapsed_time, cons_in, z_phys_nd,
575  conversion_fail);
576  }
577 
578  // Overwrite the covered water cells with coupled ocean SST. This must come
579  // after update_surf_temp, which is a whole-domain setVal, and before
580  // fill_qsurf_with_qsat, which derives sea-surface humidity from t_surf.
581  if (zlo) {
582  fill_tsurf_with_coupled_sst(lev, cons_in, z_phys_nd, conversion_fail);
583  }
584 
585  // Update land surface temp if we have a valid pointer
586  if (zlo && m_has_lsm_tsurf) {
587  get_lsm_tsurf(lev, cons_in, z_phys_nd, conversion_fail);
588  }
589 
590  // An external skin temperature (the two-stream surface energy balance's) owns
591  // the land surface temperature; last, so it replaces what was written above.
592  if (has_skin_temperature) {
593  fill_tsurf_with_skin_temperature(lev, cons_in, z_phys_nd, conversion_fail);
594  }
595 
596  // Dry updates have no later humidity check, so validate their temperature conversions
597  // here before a flux kernel can consume them. Moist updates keep the record for qsat and
598  // validate once at the end, after the humidity producers have finished.
599  if (!check_surface_humidity && check_surface_temperature) {
601  "SurfaceLayer temperature update", lev, m_surface_conversion_failure.dataValue());
602  }
603 
604  // Update qsurf with qsat over sea
605  if (check_surface_humidity) {
606  fill_qsurf_with_qsat(lev, cons_in, z_phys_nd, conversion_fail);
607  }
608 
609  // Fill interior ghost cells
610  fill_planar_boundary(lev, *t_surf[lev]);
611 
612  // Over a moving surface the averages must read the velocities relative to it, which
613  // update_mac_ptrs points them at; anything that points them back at the level's own
614  // velocities in between would silently average the absolute wind
616  (m_ma.get_field_ptr(lev, 0) == m_rel_xvel[lev].get() &&
617  m_ma.get_field_ptr(lev, 1) == m_rel_yvel[lev].get()),
618  "The surface-layer averages do not read the wind relative to the surface current: "
619  "call update_mac_ptrs before update_fluxes.");
620 
621  // Compute plane averages for all vars (regardless of flux type)
622  m_ma.compute_averages(lev);
623 
624  // The skin's surface mixing ratio over land (the two-stream balance's), relative to the
625  // reference-height mixing ratio just averaged, which the moisture flux then uses.
626  if (zlo && use_moisture &&
627  lev < static_cast<int>(m_skin_tsurf_lev.size()) && m_skin_tsurf_lev[lev] &&
628  lev < static_cast<int>(m_skin_moisture_lev.size()) && m_skin_moisture_lev[lev]) {
629  fill_qsurf_with_skin_moisture(lev, cons_in, z_phys_nd, conversion_fail);
630  fill_planar_boundary(lev, *q_surf[lev]);
631  }
632 
633  // The averaging work between qsat and the optional skin-moisture fill reads atmospheric
634  // fields, not q_surf. Check their shared failure record before any surface-flux kernel.
635  if (check_surface_humidity) {
637  "SurfaceLayer surface humidity update", lev, m_surface_conversion_failure.dataValue());
638  }
639 
640  // NOTE: Over land, iterate only where the LSM flux is invalid; the LSM-valid
641  // columns are filled by compute_sfc_params_from_lsm_fluxes below.
642  // ***************************************************************
643  // Iterate the fluxes if moeng type
644  // First iterate over land -- the only model for surface roughness
645  // over land is RoughCalcType::CONSTANT
646  // ***************************************************************
649  bool is_land = true;
650  // Do we have a constant flux for moisture over land?
651  bool cons_qflux = ( (moist_type == MoistCalcType::MOISTURE_FLUX) ||
653  if (m_terrain_type != TerrainType::EB) {
656  surface_flux most_flux(surf_temp_flux, surf_moist_flux, cons_qflux);
657  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
658  } else {
659  amrex::Abort("Unknown value for rough_type_land");
660  }
663  surface_temp most_flux(surf_temp_flux, surf_moist_flux, cons_qflux,
664  m_face.coordDir(), m_face.isLow());
665  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
666  } else {
667  amrex::Abort("Unknown value for rough_type_land");
668  }
669  } else if ((theta_type == ThetaCalcType::ADIABATIC) &&
673  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
674  } else {
675  amrex::Abort("Unknown value for rough_type_land");
676  }
677  } else {
678  amrex::Abort("Unknown value for theta_type");
679  }
680  // EB
681  } else {
684  surface_flux_eb most_flux(surf_temp_flux, surf_moist_flux, cons_qflux);
685  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
686  } else {
687  amrex::Abort("Unknown value for rough_type_land");
688  }
691  surface_temp_eb most_flux(surf_temp_flux, surf_moist_flux, cons_qflux);
692  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
693  } else {
694  amrex::Abort("Unknown value for rough_type_land");
695  }
696  } else if ((theta_type == ThetaCalcType::ADIABATIC) &&
700  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
701  } else {
702  amrex::Abort("Unknown value for rough_type_land");
703  }
704  } else {
705  amrex::Abort("Unknown value for theta_type");
706  }
707  } // EB
708  } // MOENG -- LAND
709 
710  // Update u*/T*/q*/L over land (iterations or from LSM fluxes)
711  if (m_has_lsm_fluxes) {
713  }
714 
715  // ***************************************************************
716  // Iterate the fluxes if moeng type
717  // Next iterate over sea -- the models for surface roughness
718  // over sea are CHARNOCK, DONELAN, MODIFIED_CHARNOCK or WAVE_COUPLED
719  // NOTE: Sea surface fluxes are not supported for EB terrain
720  // ***************************************************************
721  if ((flux_type == FluxCalcType::MOENG ||
723  m_terrain_type != TerrainType::EB) {
724  bool is_land = false;
725  // NOTE: Do not allow default to adiabatic over sea (we have Qvs at surface)
726  // Do we have a constant flux for moisture over sea?
727  bool cons_qflux = (moist_type == MoistCalcType::MOISTURE_FLUX);
731  cnk_a, smooth_flow_visc, cons_qflux);
732  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
735  depth, smooth_flow_visc, cons_qflux);
736  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
737  } else if (rough_type_sea == RoughCalcType::DONELAN) {
739  smooth_flow_visc, cons_qflux);
740  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
743  smooth_flow_visc, cons_qflux);
744  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
745  } else {
746  amrex::Abort("Unknown value for rough_type_sea");
747  }
748 
752  cnk_a, smooth_flow_visc, cons_qflux);
753  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
756  depth, smooth_flow_visc, cons_qflux);
757  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
758  } else if (rough_type_sea == RoughCalcType::DONELAN) {
760  smooth_flow_visc, cons_qflux);
761  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
764  smooth_flow_visc, cons_qflux);
765  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
766  } else {
767  amrex::Abort("Unknown value for rough_type_sea");
768  }
769 
770  } else if ((theta_type == ThetaCalcType::ADIABATIC) &&
775  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
779  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
780  } else if (rough_type_sea == RoughCalcType::DONELAN) {
782  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
785  compute_fluxes(lev, max_iters, cons_in, most_flux, is_land);
786  } else {
787  amrex::Abort("Unknown value for rough_type_sea");
788  }
789  } else {
790  amrex::Abort("Unknown value for theta_type");
791  }
792  } // MOENG -- SEA
793 
795  if (m_use_sfc_fluxes) {
796  // update custom surface fluxes interpolated from file
797  update_sfc_time_index(elapsed_time);
798  sfc_tflux = interpolate_sfc_column(elapsed_time, 2);
799  sfc_qflux = interpolate_sfc_column(elapsed_time, 3);
800  sfc_ustar = interpolate_sfc_column(elapsed_time, 4);
801 
802  amrex::Print() << " ABLMOST: Interpolating SHF and LHF at time "
803  << elapsed_time
804  << ": SHF = " << sfc_tflux
805  << " (W/m^2) LHF = " << sfc_qflux
806  << " (W/m^2) TAU = " << sfc_ustar
807  << " (m^2/s^2)" << std::endl;
808 
810  } else if (custom_rhosurf > 0) {
811  specified_rho_surf = true;
812  u_star[lev]->setVal(std::sqrt(custom_rhosurf) * custom_ustar);
813  t_star[lev]->setVal(custom_rhosurf * custom_tstar);
814  q_star[lev]->setVal(custom_rhosurf * custom_qstar);
815  } else {
816  u_star[lev]->setVal(custom_ustar);
817  t_star[lev]->setVal(custom_tstar);
818  q_star[lev]->setVal(custom_qstar);
819  }
820  }
821 
822  // Custom fluxes can write whole fields; reset immersed columns before
823  // the RANS boundary TKE calculation or any subsequent stress calculation.
825 
826  if (m_update_k_rans) {
827  // Clamped divisor: the select is if-converted, so 1/theta_ref runs even
828  // when theta_ref = 0 and would trip fpe_trap_zero (see ERF_SetupDiff.H)
829  const bool use_ref_theta = (theta_ref > 0);
830  const Real inv_theta_ref = one / amrex::max(theta_ref, std::numeric_limits<Real>::min());
831  const Real l_inv_theta0 = (use_ref_theta) ? inv_theta_ref : one;
832  const Real l_inv_Cmu2 = inv_Cmu2;
833  const bool l_moist_buoy = m_k_moist_buoyancy;
834  const int klo = m_geom[lev].Domain().smallEnd(2);
835  IntVect ng = u_star[lev]->nGrowVect(); ng[2] = 0;
836 
837  for (MFIter mfi(cons_in); mfi.isValid(); ++mfi)
838  {
839  Box gpbx = mfi.tilebox(IntVect(0),ng);
840 
841  if (gpbx.smallEnd(2) != klo) { continue; }
842 
843  gpbx.makeSlab(2,klo);
844  gpbx &= cons_in.fabbox(mfi.index());
845  gpbx &= walldist->fabbox(mfi.index());
846  if (gpbx.isEmpty()) { continue; }
847 
848  auto cons_arr = cons_in.array(mfi);
849  const auto& u_star_arr = u_star[lev]->const_array(mfi);
850  const auto& t_star_arr = t_star[lev]->const_array(mfi);
851  const auto& q_star_arr = q_star[lev]->const_array(mfi);
852  const auto& dist_arr = walldist->const_array(mfi);
853 
854  ParallelFor(gpbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
855  {
856  Real rho = cons_arr(i,j,k,Rho_comp);
857  // the buoyancy scale: theta*, or with erf.rans_moist_buoyancy the virtual
858  // theta_v* = theta* (1 + epsv qv) + epsv theta q* over theta_v (the scale the
859  // TKE buoyancy source and the immersed wall law use)
860  Real bstar = t_star_arr(i,j,0);
861  Real btheta = cons_arr(i,j,k,RhoTheta_comp) / rho;
862  if (l_moist_buoy) {
863  const Real qv = cons_arr(i,j,k,RhoQ1_comp) / rho;
864  bstar = t_star_arr(i,j,0) * (one + epsv * qv) + epsv * btheta * q_star_arr(i,j,0);
865  btheta = btheta * (one + epsv * qv);
866  }
867  if (bstar < -1e-8) {
868  // Only destabilizing buoyancy flux affects the boundary k
869  // tstar < 0 ==> B > 0
870  Real B = -CONST_GRAV * l_inv_theta0 * u_star_arr(i,j,0) * bstar;
871  if (!use_ref_theta) {
872  // the dry form keeps its arithmetic (bit for bit)
873  if (l_moist_buoy) { B /= btheta; }
874  else { B *= cons_arr(i,j,k,Rho_comp) / cons_arr(i,j,k,RhoTheta_comp); }
875  }
876 
877  // Axell & Liungman 2001, Eqn. 16
878  cons_arr(i,j,k,RhoKE_comp) = rho * l_inv_Cmu2 *
879  std::pow(
880  u_star_arr(i,j,0) * u_star_arr(i,j,0) * u_star_arr(i,j,0)
881  + KAPPA * B * dist_arr(i,j,k),
882  two/three);
883  } else {
884  cons_arr(i,j,k,RhoKE_comp) = rho * l_inv_Cmu2 * u_star_arr(i,j,0) * u_star_arr(i,j,0);
885  }
886  });
887  }
888  }
889 
890  // If using Land and/or Urban models, then overwrite u_star and t_star with values calculated from the surface models
891  //
892  // Gate on whether the surface models have actually advanced, not on the lower-boundary-data
893  // clock: elapsed_time_since_start_low is offset by (start_time - start_low_time), so it is
894  // already positive at step 0 when the wrflowinp series starts before erf.start_time (which
895  // would let the still-uninitialized u*/t*/q* overwrite the MOST values), and it never becomes
896  // positive at all when the series starts after it.
898  for (MFIter mfi(*u_star[lev]); mfi.isValid(); ++mfi)
899  {
900  Box gtbx = mfi.growntilebox();
901  // The surface-model fields need not carry lateral ghost cells, so a ghost
902  // column takes the nearest valid column's values, as in
903  // compute_sfc_params_from_lsm_fluxes; fill_planar_boundary below then fills
904  // the interior and periodic ghosts.
905  const NearestColumn col(mfi.validbox());
906 
907  auto u_star_arr = u_star[lev]->array(mfi);
908  auto t_star_arr = t_star[lev]->array(mfi);
909  auto q_star_arr = q_star[lev]->array(mfi);
910  auto olen_arr = olen[lev]->array(mfi);
911 
912  // Land mask array if it exists
913  auto lmask_arr = (m_lmask_lev[lev][0]) ? m_lmask_lev[lev][0]->array(mfi) :
914  Array4<int> {};
915 
916  auto lsm_tstar_arr = Array4<Real> {};
917  auto lsm_qstar_arr = Array4<Real> {};
918  auto lsm_ustar_arr = Array4<Real> {};
919  auto lsm_olen_arr = Array4<Real> {};
920  if (use_surface_model) {
921  auto mf = m_surf_model->get_field("tstar", lev);
922  lsm_tstar_arr = (mf) ? mf->array(mfi) : Array4<Real> {};
923  mf = m_surf_model->get_field("qstar", lev);
924  lsm_qstar_arr = (mf) ? mf->array(mfi) : Array4<Real> {};
925  mf = m_surf_model->get_field("ustar", lev);
926  lsm_ustar_arr = (mf) ? mf->array(mfi) : Array4<Real> {};
927  mf = m_surf_model->get_field("olen", lev);
928  lsm_olen_arr = (mf) ? mf->array(mfi) : Array4<Real> {};
929  }
930 
931  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
932  {
933  // Overwrite ustar, tstar, qstar, and olen computed above with LSM values
934  if (lmask_arr(i,j,0) == 1) {
935  const int li = col.i(i);
936  const int lj = col.j(j);
937  if (lsm_tstar_arr) t_star_arr(i,j,k) = lsm_tstar_arr(li,lj,0);
938  if (lsm_qstar_arr) q_star_arr(i,j,k) = lsm_qstar_arr(li,lj,0);
939  if (lsm_ustar_arr) u_star_arr(i,j,k) = lsm_ustar_arr(li,lj,0);
940  if (lsm_olen_arr) olen_arr(i,j,k) = lsm_olen_arr(li,lj,0);
941  }
942  });
943  }
944 
945  }
946 
947  if (m_terrain_type == TerrainType::EB || m_face.coordDir() == 2) {
948  fill_planar_boundary(lev, *u_star[lev]);
949  if (m_include_wstar) { fill_planar_boundary(lev, *w_star[lev]); }
950  fill_planar_boundary(lev, *t_star[lev]);
951  fill_planar_boundary(lev, *q_star[lev]);
952  fill_planar_boundary(lev, *olen[lev]);
953  // The flux iterations also write the surface values on the grown box: t_surf with a
954  // heat flux and q_surf with a moisture flux (most_flux_outputs, and the spec_qflux
955  // branches of the kernels). A ghost column decides from its own grid's nearest
956  // column whether it takes the LSM flux, so at a seam it can be iterated while the
957  // grid owning it is not; without a refill its ghost kept that value (issue #5257).
958  fill_planar_boundary(lev, *t_surf[lev]);
959  fill_planar_boundary(lev, *q_surf[lev]);
960  // A Charnock, Donelan or wave-coupled roughness is iterated on the grown box, from
961  // the z0 stored there; without this its ghost cells kept each box's own value, which
962  // a restart (that refills them from the valid cells) does not reproduce. The LSM
963  // and bulk-coefficient paths also recover z0 on the grown box (Compute_roughness).
964  // A constant or file roughness is not rewritten, and needs no fill here
965  // (read_custom_roughness fills a file roughness once).
967  fill_planar_boundary(lev, z_0[lev]);
968  }
969  } else {
970  // The ordinary FillBoundary is unsafe for lateral walls: the
971  // collapsed layout contains FABs from interior grids whose surface
972  // parameters were never computed. Exchange only after all flux
973  // iterations have written the selected face FABs, and copy the
974  // communicated values back only to those FABs. z0 is not among them:
975  // a variable sea roughness is allowed on the z-low face only (see
976  // make_SurfaceLayer_at_level), so z0 is never iterated on a lateral face.
978  }
979 }
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
void compute_averages(const int &lev)
Definition: ERF_MOSTAverage.cpp:1695
const amrex::MultiFab * get_field_ptr(const int &lev, const int &comp) const
Definition: ERF_MOSTAverage.H:358
amrex::Real sfc_tflux
Definition: ERF_SurfaceLayer.H:2205
void fill_tsurf_with_coupled_sst(const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
Definition: ERF_SurfaceLayer.cpp:3139
amrex::Gpu::DeviceScalar< erf_surface_temperature::ConversionFailure > m_surface_conversion_failure
Definition: ERF_SurfaceLayer.H:2151
amrex::Real sfc_qflux
Definition: ERF_SurfaceLayer.H:2204
void fill_tsurf_with_skin_temperature(const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
Definition: ERF_SurfaceLayer.cpp:3350
void set_sfc_params_from_file_fluxes(const int &lev, const amrex::MultiFab &cons_in, const amrex::Real &tflux_in, const amrex::Real &qflux_in, const amrex::Real &sfc_tau)
Definition: ERF_SurfaceLayer.cpp:2401
void fill_qsurf_with_qsat(const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd)
void get_lsm_tsurf(const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
Definition: ERF_SurfaceLayer.cpp:2995
void compute_fluxes(const int &lev, const int &max_iters, amrex::MultiFab &cons_in, const FluxIter &most_flux, bool is_land)
void fill_tsurf_with_sst_and_tsk(const int &lev, const double &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
Definition: ERF_SurfaceLayer.cpp:2572
void fill_tsurf_with_sfc_sst(const int &lev, const double &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
Definition: ERF_SurfaceLayer.cpp:2725
amrex::Real sfc_ustar
Definition: ERF_SurfaceLayer.H:2206
void update_surf_temp(const double &time)
Definition: ERF_SurfaceLayer.H:1499
void compute_sfc_params_from_lsm_fluxes(const int &lev, amrex::MultiFab &cons_in)
Definition: ERF_SurfaceLayer.cpp:2446
void fill_qsurf_with_skin_moisture(const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd)
void fill_tsurf_with_abs_surf_temp(const int &lev, const double &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, erf_surface_temperature::ConversionFailure *fail)
Definition: ERF_SurfaceLayer.cpp:3267
bool fields_are_valid() const
Returns whether the surface models have advanced at least once.
Definition: ERF_SurfaceModel.H:429
amrex::MultiFab * get_field(const std::string &name, int lev=0)
Retrieves a registered field by its common name.
Definition: ERF_SurfaceModel.H:642
void abort_on_conversion_failure(const char *who, const int lev, ConversionFailure const &fail)
Definition: ERF_SurfaceTemperature.H:403
Definition: ERF_MOSTStress.H:93
Definition: ERF_MOSTStress.H:320
EB surface-layer model for adiabatic constant-roughness fluxes.
Definition: ERF_EBMOSTStress.H:14
Definition: ERF_MOSTStress.H:211
Definition: ERF_MOSTStress.H:426
Definition: ERF_MOSTStress.H:20
Definition: ERF_SurfaceTemperature.H:268
Definition: ERF_MOSTStress.H:674
Definition: ERF_MOSTStress.H:968
EB surface-layer model with prescribed surface fluxes and constant roughness.
Definition: ERF_EBMOSTStress.H:229
Definition: ERF_MOSTStress.H:825
Definition: ERF_MOSTStress.H:1108
Definition: ERF_MOSTStress.H:538
Definition: ERF_MOSTStress.H:1450
Definition: ERF_MOSTStress.H:1840
EB surface-layer model with prescribed surface temperature and constant roughness.
Definition: ERF_EBMOSTStress.H:75
Definition: ERF_MOSTStress.H:1649
Definition: ERF_MOSTStress.H:2028
Definition: ERF_MOSTStress.H:1254
Here is the call graph for this function:

◆ update_mac_ptrs()

void SurfaceLayer::update_mac_ptrs ( const int &  lev,
amrex::Vector< amrex::Vector< amrex::MultiFab >> &  vars_old,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  Theta_prim,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  Qv_prim,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  Qr_prim 
)
inline

Update MOST-average field pointers.

Parameters
[in]levlevel index
[in]vars_oldold-time state variables
[in]Theta_primprimitive potential-temperature fields by level
[in]Qv_primprimitive water-vapor fields by level
[in]Qr_primprimitive rain-water fields by level
1535  {
1536  m_ma.update_field_ptrs(lev, vars_old, Theta_prim, Qv_prim, Qr_prim);
1537  if (m_use_surface_current) {
1538  // Average the wind relative to the surface. The averages read a copy of the
1539  // velocities taken here, not the velocities themselves, so they must be computed
1540  // before the velocities change, as update_fluxes does right after this.
1541  build_relative_velocities(lev, vars_old[lev][Vars::xvel], vars_old[lev][Vars::yvel]);
1543  }
1544  }
void update_field_ptrs(const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_old, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Theta_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qv_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qr_prim)
Definition: ERF_MOSTAverage.cpp:474
void set_velocity_field_ptrs(const int &lev, amrex::MultiFab *xvel, amrex::MultiFab *yvel)
Definition: ERF_MOSTAverage.H:120
void build_relative_velocities(const int &lev, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel)
Definition: ERF_SurfaceLayer.cpp:434
Here is the call graph for this function:

◆ update_pblh()

void SurfaceLayer::update_pblh ( const int &  lev,
amrex::Vector< amrex::Vector< amrex::MultiFab >> &  vars,
amrex::MultiFab *  z_phys_cc,
const MoistureComponentIndices &  moisture_indices 
)

Wrapper around compute_pblh.

Parameters
[in]levlevel index
[in,out]varsstate variables used by the PBL-height calculation
[in]z_phys_cccell-centered physical-height field
[in]moisture_indicesindices for moisture components

Update PBL height using the configured estimator.

Parameters
[in]levCurrent level
[in]varsLevel-indexed state MultiFabs passed to the PBL height estimator
[in]z_phys_ccCell-centered physical height used by the PBL height estimator
[in]moisture_indicesMoisture component indices used by the PBL height estimator
3594 {
3596  MYNNPBLH estimator;
3597  compute_pblh(lev, vars, z_phys_cc, estimator, moisture_indices);
3599  {
3600  //amrex::Error("YSU/MRF PBLH calc not implemented yet");
3601  // PBLH for MRF/YSU is computed inside ComputeDiffusivityMRF
3602  // and written back via set_pblh(). Nothing to do here.
3603  }
3604 }
void compute_pblh(const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars, amrex::MultiFab *z_phys_cc, const PBLHeightEstimator &est, const MoistureComponentIndices &moisture_indice)
Diagnostic utility for the planetary boundary layer height.
Definition: ERF_PBLHeight.H:12

◆ update_sfc_time_index()

void SurfaceLayer::update_sfc_time_index ( const amrex::Real &  time)

Updates current time index for interpolating data from SFC/SST file.

Parameters
[in]timeelapsed time
1038 {
1039  if (sfc.empty() || sfc[0].size() < 2) { return; }
1040 
1041  Real t1 = sfc[0][sfc_time_ind+1];
1042  while (elapsed_time >= t1)
1043  {
1044  int prev_index = sfc_time_ind;
1045  sfc_time_ind = std::min(sfc_time_ind + 1, int(sfc[0].size() - 2));
1046  t1 = sfc[0][sfc_time_ind+1];
1047  if (prev_index == sfc_time_ind) {
1048  break;
1049  }
1050  }
1051 }

◆ update_sst_ptr()

void SurfaceLayer::update_sst_ptr ( const int  lev,
const int  itime,
amrex::MultiFab *  sst_ptr 
)
inline

Update one stored sea-surface-temperature pointer.

Parameters
[in]levlevel index
[in]itimetime-slice index
[in]sst_ptrsea-surface-temperature field pointer
1972  {
1973  AMREX_ALWAYS_ASSERT(itime >= 0 && itime < static_cast<int>(m_sst_lev[lev].size()));
1974  m_sst_lev[lev][itime] = sst_ptr;
1975  }
Here is the call graph for this function:

◆ update_surf_temp()

void SurfaceLayer::update_surf_temp ( const double &  time)
inline

Update prescribed surface temperature from the configured heating rate.

Parameters
[in]timeelapsed simulation time
1500  {
1501  // NOTE: this is a whole-domain setVal, so it overwrites the SST/TSK fill
1502  // done earlier in update_fluxes. Coupled SST is applied after this
1503  // call and therefore still wins on the water cells it covers.
1504  // An absolute surface temperature is written, converted, by fill_tsurf_with_abs_surf_temp
1505  if (surf_temp_is_absolute) { return; }
1506  if (surf_heating_rate != 0) {
1507  // Use the actual size of t_surf, not m_geom.size(), which is always
1508  // max_level+1 and so runs past the levels that exist. t_surf is sized for
1509  // all levels up front but filled one level at a time, so we also have to
1510  // skip the entries that have not been allocated yet.
1511  int nlevs = static_cast<int>(t_surf.size());
1512  for (int lev = 0; lev < nlevs; lev++) {
1513  if (!t_surf[lev]) { continue; }
1514  t_surf[lev]->setVal(surf_temp + surf_heating_rate * static_cast<amrex::Real>(time));
1515  amrex::Print() << "Surface temp at t=" << time << ": "
1516  << surf_temp + surf_heating_rate * time << std::endl;
1517  }
1518  }
1519  }

◆ update_tsk_ptr()

void SurfaceLayer::update_tsk_ptr ( const int  lev,
const int  itime,
amrex::MultiFab *  tsk_ptr 
)
inline

Update one stored skin-temperature pointer.

Parameters
[in]levlevel index
[in]itimetime-slice index
[in]tsk_ptrskin-temperature field pointer
1984  {
1985  AMREX_ALWAYS_ASSERT(itime >= 0 && itime < static_cast<int>(m_tsk_lev[lev].size()));
1986  m_tsk_lev[lev][itime] = tsk_ptr;
1987  }
Here is the call graph for this function:

◆ use_sfc_fluxes()

bool SurfaceLayer::use_sfc_fluxes ( ) const
inline

Return whether prescribed surface fluxes are active.

1860 { return m_use_sfc_fluxes; }

◆ use_surface_current()

bool SurfaceLayer::use_surface_current ( ) const
inline

Return whether the surface layer takes the wind relative to a current of the surface.

1596 { return m_use_surface_current; }

Member Data Documentation

◆ cnk_a

amrex::Real SurfaceLayer::cnk_a {amrex::Real(0.0185)}
private

◆ custom_qstar

amrex::Real SurfaceLayer::custom_qstar {0}
private

◆ custom_rhosurf

amrex::Real SurfaceLayer::custom_rhosurf {0}
private

◆ custom_tstar

amrex::Real SurfaceLayer::custom_tstar {0}
private

◆ custom_ustar

amrex::Real SurfaceLayer::custom_ustar {0}
private

◆ default_land_surf_moist

amrex::Real SurfaceLayer::default_land_surf_moist {zero}
private

◆ default_land_surf_temp

amrex::Real SurfaceLayer::default_land_surf_temp {amrex::Real(300.)}
private

◆ depth

amrex::Real SurfaceLayer::depth {amrex::Real(30.0)}
private

◆ flux_type

◆ inv_Cmu2

amrex::Real SurfaceLayer::inv_Cmu2 = zero
private

◆ m_bulk_fixed_tflux

amrex::Real SurfaceLayer::m_bulk_fixed_tflux = zero
private

◆ m_bulk_use_fixed_tflux

bool SurfaceLayer::m_bulk_use_fixed_tflux = false
private

◆ m_Cd

amrex::Real SurfaceLayer::m_Cd = zero
private

◆ m_Ch

amrex::Real SurfaceLayer::m_Ch = zero
private

◆ m_coupled_current_active

bool SurfaceLayer::m_coupled_current_active = false
private

◆ m_coupled_current_cos_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_coupled_current_cos_lev
private

◆ m_coupled_current_covered_lev

amrex::Vector<const amrex::iMultiFab*> SurfaceLayer::m_coupled_current_covered_lev
private

◆ m_coupled_current_east_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_coupled_current_east_lev
private

◆ m_coupled_current_north_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_coupled_current_north_lev
private

◆ m_coupled_current_sin_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_coupled_current_sin_lev
private

◆ m_coupled_rotation_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::m_coupled_rotation_lev
private

◆ m_coupled_rotation_src_ba_lev

amrex::Vector<amrex::BoxArray> SurfaceLayer::m_coupled_rotation_src_ba_lev
private

◆ m_coupled_rotation_src_dm_lev

amrex::Vector<amrex::DistributionMapping> SurfaceLayer::m_coupled_rotation_src_dm_lev
private

◆ m_coupled_rotation_src_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_coupled_rotation_src_lev
private

◆ m_coupled_sst_lev

amrex::Vector<amrex::MultiFab*> SurfaceLayer::m_coupled_sst_lev
private

◆ m_coupled_sst_valid_lev

amrex::Vector<amrex::iMultiFab*> SurfaceLayer::m_coupled_sst_valid_lev
private

◆ m_Cq

amrex::Real SurfaceLayer::m_Cq = zero
private

◆ m_eb_vec

amrex::Vector<const eb_*> SurfaceLayer::m_eb_vec
private

◆ m_eddyDiffs_lev

amrex::Vector<amrex::MultiFab*> SurfaceLayer::m_eddyDiffs_lev
private

◆ m_face

amrex::Orientation SurfaceLayer::m_face
private

◆ m_final_low_time

double SurfaceLayer::m_final_low_time
private

◆ m_geom

amrex::Vector<amrex::Geometry> SurfaceLayer::m_geom
private

◆ m_has_immersed_buildings

bool SurfaceLayer::m_has_immersed_buildings = false
private

◆ m_has_lsm_fluxes

bool SurfaceLayer::m_has_lsm_fluxes = false
private

◆ m_has_lsm_tsurf

bool SurfaceLayer::m_has_lsm_tsurf = false
private

◆ m_Hwave_lev

amrex::Vector<amrex::MultiFab*> SurfaceLayer::m_Hwave_lev
private

◆ m_ignore_sst

bool SurfaceLayer::m_ignore_sst = false
private

◆ m_include_wstar

bool SurfaceLayer::m_include_wstar = false
private

Referenced by computes_w_star().

◆ m_k_moist_buoyancy

bool SurfaceLayer::m_k_moist_buoyancy = false
private

◆ m_lmask_lev

amrex::Vector<amrex::Vector<amrex::iMultiFab*> > SurfaceLayer::m_lmask_lev
private

◆ m_low_time_interval

double SurfaceLayer::m_low_time_interval
private

◆ m_lsm_data_lev

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceLayer::m_lsm_data_lev
private

◆ m_lsm_data_name

amrex::Vector<std::string> SurfaceLayer::m_lsm_data_name
private

◆ m_lsm_flux_lev

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceLayer::m_lsm_flux_lev
private

◆ m_lsm_flux_name

amrex::Vector<std::string> SurfaceLayer::m_lsm_flux_name
private

◆ m_lsm_held_columns

amrex::Vector<amrex::iMultiFab> SurfaceLayer::m_lsm_held_columns
private

◆ m_lsm_tsurf_indx

int SurfaceLayer::m_lsm_tsurf_indx = -1
private

◆ m_lsm_tsurf_is_theta

bool SurfaceLayer::m_lsm_tsurf_is_theta = false
private

◆ m_Lwave_lev

amrex::Vector<amrex::MultiFab*> SurfaceLayer::m_Lwave_lev
private

◆ m_ma

◆ m_pblh_columns

amrex::Vector<PBLHColumns> SurfaceLayer::m_pblh_columns
private

◆ m_planar_bndry

amrex::Vector<PlanarBoundary> SurfaceLayer::m_planar_bndry
private

◆ m_pp_prefix

std::string SurfaceLayer::m_pp_prefix
private

◆ m_rdOcp

amrex::Real SurfaceLayer::m_rdOcp = RdoCp
private

◆ m_rel_k_top

amrex::Vector<int> SurfaceLayer::m_rel_k_top
private

◆ m_rel_src_ba

amrex::Vector<amrex::BoxArray> SurfaceLayer::m_rel_src_ba
private

◆ m_rel_xvel

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::m_rel_xvel
private

◆ m_rel_yvel

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::m_rel_yvel
private

◆ m_rotate

bool SurfaceLayer::m_rotate = false
private

◆ m_sfuns

similarity_funs SurfaceLayer::m_sfuns

stable-side similarity functions (most.stable_functions)

Referenced by check_similarity_funs_use(), and similarity_functions().

◆ m_skin_moisture_hs_lev

amrex::Vector<amrex::Real> SurfaceLayer::m_skin_moisture_hs_lev
private

Referenced by set_skin_moisture().

◆ m_skin_moisture_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_skin_moisture_lev
private

Referenced by set_skin_moisture().

◆ m_skin_moisture_resistances_lev

amrex::Vector<int> SurfaceLayer::m_skin_moisture_resistances_lev
private

Referenced by set_skin_moisture().

◆ m_skin_tsurf_lev

amrex::Vector<const amrex::MultiFab*> SurfaceLayer::m_skin_tsurf_lev
private

Referenced by set_skin_temperature().

◆ m_sst_lev

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceLayer::m_sst_lev
private

◆ m_start_low_time

double SurfaceLayer::m_start_low_time
private

◆ m_surf_model

SurfaceModel* SurfaceLayer::m_surf_model = nullptr
private

◆ m_surface_conversion_failure

amrex::Gpu::DeviceScalar<erf_surface_temperature::ConversionFailure> SurfaceLayer::m_surface_conversion_failure {erf_surface_temperature::ConversionFailure{}}
private

◆ m_surface_current_const

amrex::Real SurfaceLayer::m_surface_current_const[2] = {zero, zero}
private

◆ m_surface_current_x

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::m_surface_current_x
private

◆ m_surface_current_y

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::m_surface_current_y
private

◆ m_surface_layer_faces

amrex::GpuArray<int, AMREX_SPACEDIM*2> SurfaceLayer::m_surface_layer_faces {}
private

Referenced by set_surface_layer_faces().

◆ m_terrain_type

TerrainType SurfaceLayer::m_terrain_type
private

◆ m_tsk_lev

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceLayer::m_tsk_lev
private

◆ m_update_k_rans

bool SurfaceLayer::m_update_k_rans = false
private

◆ m_use_coupled_sst

bool SurfaceLayer::m_use_coupled_sst = false
private

◆ m_use_lsm_skin_temperature

bool SurfaceLayer::m_use_lsm_skin_temperature = false
private

◆ m_use_sfc_fluxes

bool SurfaceLayer::m_use_sfc_fluxes = false
private

◆ m_use_sfc_sst

bool SurfaceLayer::m_use_sfc_sst = false
private

◆ m_use_surface_current

bool SurfaceLayer::m_use_surface_current = false
private

◆ m_var_z0

bool SurfaceLayer::m_var_z0 {false}
private

◆ m_z0_given

bool SurfaceLayer::m_z0_given {false}
private

Referenced by set_default_roughness().

◆ moist_type

◆ olen

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::olen
private

◆ pblh

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::pblh
private

◆ pblh_type

PBLHeightCalcType SurfaceLayer::pblh_type {PBLHeightCalcType::None}

Referenced by computes_pblh().

◆ q_star

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::q_star
private

◆ q_surf

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::q_surf
private

◆ rico_qsat_z0

amrex::Real SurfaceLayer::rico_qsat_z0 {amrex::Real(0.001)}
private

◆ rico_theta_z0

amrex::Real SurfaceLayer::rico_theta_z0 {amrex::Real(298.0)}
private

◆ rough_type_land

RoughCalcType SurfaceLayer::rough_type_land {RoughCalcType::CONSTANT}

◆ rough_type_sea

RoughCalcType SurfaceLayer::rough_type_sea {RoughCalcType::CHARNOCK}

◆ sfc

amrex::Vector<amrex::Vector<amrex::Real> > SurfaceLayer::sfc
private

◆ sfc_qflux

amrex::Real SurfaceLayer::sfc_qflux = zero
private

◆ sfc_tflux

amrex::Real SurfaceLayer::sfc_tflux = zero
private

◆ sfc_time_ind

int SurfaceLayer::sfc_time_ind = 0
private

◆ sfc_ustar

amrex::Real SurfaceLayer::sfc_ustar = zero
private

◆ smooth_flow_visc

bool SurfaceLayer::smooth_flow_visc {true}
private

◆ specified_rho_surf

bool SurfaceLayer::specified_rho_surf {false}
private

◆ surf_heating_rate

amrex::Real SurfaceLayer::surf_heating_rate {0}
private

◆ surf_model_fluxes

bool SurfaceLayer::surf_model_fluxes = false
private

◆ surf_moist

amrex::Real SurfaceLayer::surf_moist {amrex::Real(-1.)}
private

◆ surf_moist_flux

amrex::Real SurfaceLayer::surf_moist_flux {0}
private

◆ surf_temp

amrex::Real SurfaceLayer::surf_temp {amrex::Real(-1.)}
private

Referenced by update_surf_temp().

◆ surf_temp_flux

amrex::Real SurfaceLayer::surf_temp_flux {0}
private

◆ surf_temp_is_absolute

bool SurfaceLayer::surf_temp_is_absolute {false}
private

◆ surface_diagnostic_source

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::surface_diagnostic_source
private

◆ t_star

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::t_star
private

◆ t_surf

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::t_surf
private

◆ theta_ref

amrex::Real SurfaceLayer::theta_ref = zero
private

◆ theta_type

◆ u_star

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::u_star
private

◆ use_moisture

bool SurfaceLayer::use_moisture
private

Referenced by skin_moisture_conflict().

◆ use_surface_model

bool SurfaceLayer::use_surface_model = false
private

◆ w_star

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceLayer::w_star
private

◆ z0_const

amrex::Real SurfaceLayer::z0_const {amrex::Real(0.1)}
private

◆ z_0

amrex::Vector<amrex::MultiFab> SurfaceLayer::z_0
private

The documentation for this class was generated from the following files: