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

The two-stream radiation model (erf.radiation_model = TwoStream). More...

#include <ERF_TwoStreamRadiation.H>

Collaboration diagram for TwoStreamRadiation:

Classes

struct  FluxDiag
 
struct  OrbitalCache
 

Public Types

enum  Roof : int {
  ROOF_SET = 0 , ROOF_ALBEDO = 1 , ROOF_EMISSIVITY = 2 , ROOF_TEMPERATURE = 3 ,
  ROOF_LIT = 4 , ROOF_NCOMP = 5
}
 Components of the field of roofs_for_step(). More...
 

Public Member Functions

 TwoStreamRadiation ()=default
 
void resize (int nlevs_max)
 Size the per-level containers; no allocation happens here. More...
 
bool active () const
 True once a level has been defined with the model selected. More...
 
const amrex::MultiFab * prognostic_surface_temperature_state (int lev) const noexcept
 Read-only view of the per-level prognostic surface-temperature state. More...
 
void define_level (int lev, const RadChoice &rad_choice, amrex::Real rdOcp, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::BoxArray &ba, const amrex::Box &domain, bool supply_land_forcing=false)
 Allocate the 2D surface fields of one level on the given horizontal BoxArray and fill them with the scalar defaults. A no-op unless rad_choice.rad_type == TwoStream. More...
 
void advance (int lev, int nstep, amrex::Real time, amrex::Real dt_step, const std::string &call_site, const amrex::MultiFab &cons_old, const amrex::MultiFab *z_phys_nd, const amrex::Geometry &geom, LandSurface &lsm, const amrex::Vector< const amrex::MultiFab * > &radiation_inputs, bool noahmp_active, amrex::MultiFab *qheating, amrex::MultiFab *rad_fluxes, const amrex::MultiFab *t_surf, const amrex::MultiFab *sfc_sens_flux, const amrex::MultiFab *sfc_laten_flux, const amrex::MultiFab *lat_m, const amrex::MultiFab *lon_m, double epoch_time, bool have_datetime, const amrex::iMultiFab *land_mask=nullptr)
 One radiation call at one level. More...
 
amrex::MultiFab * seb_t_sfc (int lev)
 The prognostic surface state of one level, or nullptr when the SEB is off or the level has not been built. More...
 
amrex::MultiFab * seb_q_sfc (int lev)
 
const amrex::MultiFab * seb_hfx (int lev) const
 The sensible and latent heat fluxes [W/m^2] the surface energy balance of one level last used, or nullptr when the SEB is off or the level has not been built. Read-only: for output. More...
 
const amrex::MultiFab * seb_lh (int lev) const
 
const amrex::MultiFab * seb_surface_moisture (int lev)
 What level lev's surface hands the surface layer for its surface mixing ratio (erf.radiation.seb_surface_layer_uses_moisture), per column, in the components of erf_surface_moisture::Component: the soil-water factor (seb_moisture_availability of the current q_s); with erf.radiation.seb_soil_type, the bare-soil resistance and the relative humidity of its pore air at the skin temperature; and with erf.radiation.seb_vegetation_type as well, the vegetated fraction and the canopy resistance without its vapor-deficit factor (from the net shortwave the balance holds divided by (1 - surface albedo) – the sweep's with seb_use_radiation_fluxes, seb_sw_flux_default otherwise – and the skin temperature). Absent pieces are a fraction of 0 and resistances of 1e6 s/m. nullptr when the option is off or the level has not been built. Recomputed on every call, on the valid cells; the halo is not filled. More...
 
amrex::Vector< amrex::MultiFab * > seb_prognostic_fields (int lev)
 Every field of the force-restore state of lev that evolves and so must survive a regrid, be filled from the coarse level on a new level and be averaged down: t_sfc and q_sfc; with erf.radiation.seb_deep_prognostic_enable, t_deep and q_deep; with erf.radiation.seb_init_t_deep_from_file, t_deep (it does not evolve then, but it differs from column to column); with the hydrology, its running totals (several components); with the snow layer, its water equivalent and totals. Empty when the state is not evolved. Each is a 2D field (k = 0) on the level's horizontal grids. More...
 
void hydrology_begin_step (int lev, const SurfacePrecipAccumulationSources &sources, int klo)
 Store the surface precipitation accumulation of lev at the start of its step (ERF::Advance, before the dycore and microphysics). A no-op without erf.radiation.seb_precipitation_source = microphysics. More...
 
void hydrology_end_step (int lev, const SurfacePrecipAccumulationSources &sources, int klo, amrex::Real dt)
 The rain rate of the step of lev just taken, from the accumulation now and the one hydrology_begin_step stored; called before the post-dycore advance. A no-op without erf.radiation.seb_precipitation_source = microphysics. More...
 
ForceRestoreSoil force_restore_soil (int lev) const
 The force-restore soil of lev, read-only (see ForceRestoreSoil), or an empty view (every pointer nullptr) when the force-restore state is not evolved there. More...
 
bool seb_t_deep_is_state () const
 True when the deep temperature is part of the state: it evolves (erf.radiation.seb_deep_prognostic_enable) or it was set per column from the initial file (erf.radiation.seb_init_t_deep_from_file). It is then not reset to erf.radiation.seb_t_deep_default at a radiation step, it is one of seb_prognostic_fields and it is written to the checkpoint and read back. More...
 
amrex::MultiFab * seb_t_deep_state (int lev)
 The deep temperature [K] of lev for ERF::init_seb_t_deep_from_file to write, or nullptr when it is not part of the state (seb_t_deep_is_state) or the level has not been built. More...
 
bool seb_q_deep_is_state () const
 True when the deep water content is part of the state: it evolves (erf.radiation.seb_deep_prognostic_enable) or it was set per column from the initial file (erf.radiation.seb_init_soil_moisture_from_file). It is then not reset to erf.radiation.seb_q_deep_default at a radiation step, it is one of seb_prognostic_fields and it is written to the checkpoint and read back. More...
 
amrex::MultiFab * seb_q_sfc_state (int lev)
 The surface water content q_s [m^3/m^3] of lev for ERF::init_seb_soil_moisture_from_file to write, or nullptr when the prognostic balance does not run or the level has not been built. More...
 
amrex::MultiFab * seb_q_deep_state (int lev)
 The deep water content [m^3/m^3] of lev for ERF::init_seb_soil_moisture_from_file to write, or nullptr when it is not part of the state (seb_q_deep_is_state) or the level has not been built. More...
 
const amrex::MultiFab * seb_t_deep (int lev) const
 The deep temperature [K] and column water content of lev, or nullptr. Read-only: for output. More...
 
const amrex::MultiFab * seb_q_deep (int lev) const
 
const amrex::MultiFab * hydrology_rain_rate (int lev) const
 The hydrology's rain rate of the last step [kg/m^2/s], in component 0 (nullptr without seb_precipitation_source) and running totals [kg/m^2] (nullptr without the hydrology). Read-only: for output. More...
 
const amrex::MultiFab * hydrology_totals (int lev)
 
const amrex::MultiFab * snow_swe (int lev)
 The snow water equivalent [kg/m^2] and the snow layer's running totals (ForceRestoreSnow::Total components) [kg/m^2]; nullptr without erf.radiation.seb_snow_enable. Read-only: for output. More...
 
const amrex::MultiFab * snow_totals (int lev)
 
bool seb_prognostic_active () const
 True when the force-restore state is being evolved and so needs transferring. More...
 
bool supplies_land_forcing (int lev) const noexcept
 True when define_level allocated the land-model forcing fields on lev. More...
 
const amrex::MultiFab * land_forcing_sw_dn (int lev) const noexcept
 The surface forcing of the last sweep on lev (2D: i,j), or nullptr when the level does not supply it: total downwelling shortwave [W/m^2], downwelling longwave [W/m^2] and the cosine of the solar zenith angle floored at zero [1]. lsm_undefined until a sweep has run on the level, so a copy made before one is caught by the land model's missing-input check instead of reading as zero. More...
 
const amrex::MultiFab * land_forcing_lw_dn (int lev) const noexcept
 
const amrex::MultiFab * land_forcing_cos_zenith (int lev) const noexcept
 
void write_land_forcing (int lev, amrex::MultiFab *sw_flux_dn, amrex::MultiFab *lw_flux_dn, amrex::MultiFab *cos_zenith_angle) const
 Copy the surface forcing of the last sweep on lev into a land-surface model's radiation inputs (SurfaceModel's "sw_flux_dn", "lw_flux_dn" and "cos_zenith_angle" outputs). A null destination is skipped. Each destination must lie on this level's horizontal grids; see copy_surface_plane. Before the level's first sweep this copies the lsm_undefined sentinel, not zero. More...
 
void supply_canopy_forcing (int lev, int m_top, bool ground_albedo=false)
 Have every later sweep on lev write what the building faces need besides the interface fluxes (erf.ibseb.radiation = two_stream; ERF_TwoStreamCanopyForcing.H): the direct beam on a horizontal surface at the interfaces 0 .. m_top of each column, counted from the surface, and the cosine of the zenith. Allocates one field on the level's horizontal grids given those interfaces in z and one 2D field. Call after define_level(); a later define_level() of the level (a regrid) drops the request. More...
 
bool supplies_canopy_forcing (int lev) const noexcept
 True when supply_canopy_forcing() was called for lev since its last define_level(). More...
 
TwoStreamCanopyView canopy_forcing (int lev, int nstep) const noexcept
 The beam and the cosine of the zenith of lev as the sweep of step nstep wrote them (the view's fluxes are left for the caller, who owns rad_fluxes), or an empty view when the level does not supply them or has not swept at that step: the faces must not take a previous step's radiation, nor the zeros of a level whose radiation came from its parent. More...
 
void set_building_cover (int lev, const amrex::MultiFab &blanking, const amrex::Box &domain, bool take_ground_walls=false, bool start_on_roofs=false)
 Have the columns of lev see the buildings of the immersed-boundary balance (erf.ibseb.two_stream_buildings). From now on, on this level: More...
 
bool starts_on_roofs (int lev) const noexcept
 True when the columns of lev under a building start on its roof (erf.ibseb.two_stream_roofs; set_building_cover() with start_on_roofs, on a level that sweeps its own columns): the one condition for the fields and for the sweep. More...
 
const amrex::iMultiFab * roof_cell (int lev) const noexcept
 For each column of lev, the first cell above the building that stands on its ground (the cell on the roof), or the bottom cell on open ground (2D: i,j); nullptr unless starts_on_roofs(). A cell above the level's top means the building fills the column. Solid cells above an air gap (an overhang) are not a roof here: under an overhang above open ground the cell is the bottom cell, and under an overhang above a lower roof it is the cell on that lower roof. More...
 
amrex::MultiFab * roofs_for_step (int lev, int nstep)
 The field the immersed-boundary balance fills, before the sweep of step nstep, with the roof face of each column under a building (2D: i,j; ROOF_SET 1 where a roof face stands on roof_cell(), then its albedo, emissivity, skin temperature and the share of the beam that reaches it), or nullptr unless starts_on_roofs(). Marks the field as that step's: the sweep stops unless the roofs are of its own step. Where ROOF_SET is 0 the column keeps the ground as its lower boundary. More...
 
bool roofs_given (int lev) const noexcept
 True once roofs_for_step() has been called for lev since its building cover was set. More...
 
bool takes_ground_walls (int lev) const noexcept
 True when the ground balance of lev takes what the walls send it (see set_building_cover()): the one condition for the field, what the sweep keeps for it, and the shortwave and longwave terms. More...
 
bool has_building_cover (int lev) const noexcept
 True when set_building_cover() was called for lev since its last define_level(). More...
 
amrex::MultiFab * ground_shadow_for_step (int lev, int nstep)
 The field the immersed-boundary balance fills with the buildings' shadow on the ground of lev for step nstep (1 where the ray from the ground toward the sun meets a building, 0 where the sun reaches it; 2D: i,j), or nullptr when the level's ground balance takes no shadow (no building cover; no balance on the sweep's shortwave, or the shortwave off; or a level whose rates come from its parent). Marks the field as that step's: the update after the dycore stops unless the shadow is of the step its sweep ran in. More...
 
amrex::MultiFab * ground_walls_for_step (int lev, int nstep)
 The field the immersed-boundary balance fills with what the walls send to the ground of lev for step nstep (IBFaceSet::compute_ground_walls(): the walls' share of the ground's view, their reflected shortwave and their longwave arriving on the ground, W/m^2), or nullptr when the level's ground balance takes none (takes_ground_walls()). Marks the field as that step's. At the update after the dycore the open ground then keeps its absorbed diffuse shortwave and the sky's longwave through the part of its view the walls leave open, and takes the walls' through the rest: SW += (1 - alb_dif) SW_walls - v (SW - SW_beam), LW += emis (LW_walls - v LW_down), with v the walls' share (two_stream_ground_wall_terms()). More...
 
const amrex::MultiFab * ground_walls (int lev) const noexcept
 What the walls sent to the ground of lev last (see ground_walls_for_step()), or nullptr before any or when the level takes none. Read-only: for output. More...
 
const amrex::MultiFab * seb_lw_net (int lev) const
 The net longwave [W/m^2] the ground balance of lev used at its last update after the dycore (with the walls' longwave of erf.ibseb.ground_sky_view); nullptr as for seb_sw_net(). Read-only: for output. More...
 
const amrex::MultiFab * ground_shadow (int lev) const noexcept
 The ground's shadow last given for lev (see ground_shadow_for_step()), or nullptr before one is given or when the level takes none. Read-only: for output. More...
 
void mask_building_heating (int lev, amrex::MultiFab &qheating) const
 Set the heating rates of lev to zero in the solid cells of its building cover (a no-op without one): for a level whose rates come from its parent by interpolation, where no sweep of its own masks them. More...
 
const amrex::MultiFab * seb_sw_net (int lev) const
 The net shortwave [W/m^2] the ground balance of lev used at its last update after the dycore, with the building cover's footprints and shadow applied; nullptr when the SEB is off, before the level's first such update after a sweep (the initial plotfile, the one a restart writes), or on a level that does not sweep. Read-only: for output. More...
 
void write_checkpoint (int lev, const std::string &checkpointname) const
 Write the prognostic surface state of one level (SEB on). More...
 
void read_checkpoint (int lev, const std::string &restart_chkfile, const amrex::Periodicity &period)
 Read it back when the checkpoint carries it; else keep defaults. More...
 

Private Attributes

const RadChoice * m_rad = nullptr
 
amrex::Real m_rdOcp = RdoCp
 
OrbitalCache m_orbit
 
amrex::Vector< std::unique_ptr< RadiationDiagnostics > > m_diag
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_alb_sw
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_emiss_lw
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_t_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_sw_flux_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_lw_flux_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_hfx_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_lh_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_grdflx_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_q_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_t_deep
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_q_deep
 
ForceRestorePrecipRate m_precip
 
ForceRestoreHydrology m_hydro
 
ForceRestoreSnow m_snow
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_moisture
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_sw_dn_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_lw_dn_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_cos_zenith
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_canopy
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_canopy_cosz
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_canopy_alb
 
amrex::Vector< int > m_canopy_m
 
amrex::Vector< int > m_canopy_step
 
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_solid
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_footprint
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ground_shadow
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_sw_beam_sfc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ground_walls
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ground_keep
 
amrex::Vector< int > m_walls_step
 
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_roof_k
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_roof
 
amrex::Vector< int > m_roof_step
 
amrex::Vector< int > m_shadow_step
 
amrex::Vector< int > m_sweep_step
 
amrex::Vector< int > m_shaded_step
 
amrex::Vector< int > m_has_cover
 
amrex::Vector< int > m_seb_updated
 
amrex::Vector< int > m_water_message
 
amrex::Vector< FluxDiag > m_flux_diag
 

Detailed Description

The two-stream radiation model (erf.radiation_model = TwoStream).

Owns everything the model keeps between steps: the per-level surface property fields it falls back on when no land-surface model supplies them, the surface-energy-balance (SEB) fields and force-restore state, and the domain-mean flux diagnostics of the last column sweep. ERF holds one instance and calls it only after testing solverChoice.rad_type == RadiationType::TwoStream; every method here checks the same predicate and returns without acting otherwise.

Lifecycle:

  • resize(nlevs) once at construction (before the inputs are read);
  • define_level(lev, radChoice, rdOcp, ba2d, dm, ba, domain, supply_land_forcing) whenever a level is (re)built;
  • advance(...) twice per step: "pre_dycore" runs the column sweep on the old state and writes the heating rates, "post_dycore" reuses that sweep's flux diagnostics and advances the SEB state by dt_step;
  • write_land_forcing(...) after a sweep, when a land-surface model integrates on the radiation this model computes (see supply_land_forcing);
  • supply_canopy_forcing(...) once, when the building faces of the immersed-boundary balance take their radiation from the sweep (erf.ibseb.radiation = two_stream), and canopy_forcing(...) after each sweep;
  • set_building_cover(...) once, when the columns are to see the buildings of the immersed-boundary balance (erf.ibseb.two_stream_buildings), and ground_shadow_for_step(...) every step, for the balance to fill with the buildings' shadow on the ground;
  • write_checkpoint / read_checkpoint for the prognostic surface state;
  • with the force-restore hydrology (RadChoice::seb_hydrology_enabled()), hydrology_begin_step(...) at the start of each step of a level and hydrology_end_step(...) before its post-dycore call, which give the rain of the step.

The heating-rate MultiFab itself stays in ERF, since RRTMGP writes the same 2-component (SW, LW) array and the RhoTheta source term and the plotfile read it without caring which model filled it.

Member Enumeration Documentation

◆ Roof

Components of the field of roofs_for_step().

Enumerator
ROOF_SET 
ROOF_ALBEDO 
ROOF_EMISSIVITY 
ROOF_TEMPERATURE 
ROOF_LIT 
ROOF_NCOMP 
447 : int { ROOF_SET = 0, ROOF_ALBEDO = 1, ROOF_EMISSIVITY = 2, ROOF_TEMPERATURE = 3, ROOF_LIT = 4, ROOF_NCOMP = 5 };
@ ROOF_SET
Definition: ERF_TwoStreamRadiation.H:447
@ ROOF_ALBEDO
Definition: ERF_TwoStreamRadiation.H:447
@ ROOF_TEMPERATURE
Definition: ERF_TwoStreamRadiation.H:447
@ ROOF_EMISSIVITY
Definition: ERF_TwoStreamRadiation.H:447
@ ROOF_LIT
Definition: ERF_TwoStreamRadiation.H:447
@ ROOF_NCOMP
Definition: ERF_TwoStreamRadiation.H:447

Constructor & Destructor Documentation

◆ TwoStreamRadiation()

TwoStreamRadiation::TwoStreamRadiation ( )
default

Member Function Documentation

◆ active()

bool TwoStreamRadiation::active ( ) const
inline

True once a level has been defined with the model selected.

68  {
69  return (m_rad != nullptr) && m_rad->enabled;
70  }
const RadChoice * m_rad
Definition: ERF_TwoStreamRadiation.H:599
bool enabled
True when erf.radiation_model = TwoStream. Set by init_params from the model SolverChoice read; the e...
Definition: ERF_RadStruct.H:148

Referenced by seb_hfx(), seb_lh(), seb_lw_net(), seb_prognostic_active(), seb_q_deep(), seb_q_deep_is_state(), seb_q_sfc(), seb_sw_net(), seb_t_deep(), seb_t_deep_is_state(), and seb_t_sfc().

Here is the caller graph for this function:

◆ advance()

void TwoStreamRadiation::advance ( int  lev,
int  nstep,
amrex::Real  time,
amrex::Real  dt_step,
const std::string &  call_site,
const amrex::MultiFab &  cons_old,
const amrex::MultiFab *  z_phys_nd,
const amrex::Geometry &  geom,
LandSurface &  lsm,
const amrex::Vector< const amrex::MultiFab * > &  radiation_inputs,
bool  noahmp_active,
amrex::MultiFab *  qheating,
amrex::MultiFab *  rad_fluxes,
const amrex::MultiFab *  t_surf,
const amrex::MultiFab *  sfc_sens_flux,
const amrex::MultiFab *  sfc_laten_flux,
const amrex::MultiFab *  lat_m,
const amrex::MultiFab *  lon_m,
double  epoch_time,
bool  have_datetime,
const amrex::iMultiFab *  land_mask = nullptr 
)

One radiation call at one level.

Parameters
levlevel
nstepstep number, used as the diagnostics row index
timetime logged with the diagnostics row [s]
dt_stepstep size, used by the SEB Euler update [s]
call_site"pre_dycore" (column sweep + diagnostics) or "post_dycore" (cached diagnostics + SEB update)
cons_oldold-state conserved variables of this level
z_phys_ndnodal heights (layer interfaces), or nullptr on a uniform grid
geomgeometry of this level
lsmland-surface model (queried for per-column fields)
radiation_inputscanonical surface-property inputs, in fixed order
noahmp_activewhether Noah-MP diagnostics may be queried
qheating2-component (SW, LW) heating-rate MultiFab of this level, written at the pre-dycore call; may be nullptr
rad_fluxes4-component (SW up, SW down, LW up, LW down) interface fluxes of this level in RRTMGP's level layout (index k the lower interface of layer k, the top of the atmosphere in the z-ghost cell above the top layer), written at the pre-dycore call; may be nullptr
t_surfthe surface layer's surface temperature, or nullptr; used as the longwave boundary condition where no land-surface field exists, as RRTMGP does
sfc_sens_fluxthe conservative heat flux (rho w'theta', z faces) the zlo surface layer applies to this level, or nullptr when it applies none; the surface energy balance's H where no land-surface model supplies one (see ERF_SEBTurbulentFlux.H)
sfc_laten_fluxthe moisture flux (rho w'qv', z faces) likewise, for LE; nullptr without a moisture model
lat_mper-column latitude [degrees], or nullptr (then erf.rad_cons_lat); only the WRF/metgrid inits fill it
lon_mper-column longitude [degrees], likewise
epoch_timeseconds since 1970-01-01 00:00 UTC of this call (start_time + time), the RRTMGP time base; double, as RRTMGP keeps it, since a float cannot resolve a time of day at ~1.7e9 s
have_datetimetrue when start_datetime (or a WRF/metgrid start date) fixed the calendar; without it a dynamic sun cannot be placed and the call aborts
land_maskthe level's land mask (ERF::lmask_lev: 0 water, 1 land, 2 a building's column), one 2D box at k = 0 for each box of the state, or nullptr (every column is land). The force-restore balance is a model of soil, so a water column (mask 0) is not its ground: its state is held (the snow layer's water is set to zero), it is left out of the balance's means and of the hydrology, and the sweep takes its surface temperature from t_surf (the surface layer's sea surface temperature) and not from the balance's skin.
913 {
914  BL_PROFILE("TwoStreamRadiation::advance()");
915 
916  // Only proceed if TwoStream radiation is enabled
917  if (!active()) { return; }
918  const RadChoice& rad_choice = *m_rad;
919 
920  // A level on which no box holds a whole column has nothing for the sweep or the surface
921  // state to work on; ERF::advance_radiation interpolates its fields from the parent
922  // instead. Returning here covers the post-dycore call too, which comes from ERF::Advance
923  // and does not test for it. Same test (rad_boxes_span_column) as level_needs_interpolation():
924  // if the two tests disagreed, one of them would try to sweep a level the other had
925  // already interpolated.
926  if (lev > 0 && !rad_boxes_span_column(cons_old.boxArray(), geom.Domain())) { return; }
927 
928  // ---- Contract checks. Each of these would otherwise surface as a wrong
929  // heating rate or an out-of-bounds read several routines away.
930  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(call_site == "pre_dycore" || call_site == "post_dycore",
931  "TwoStreamRadiation::advance: call_site must be pre_dycore or post_dycore");
932  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(lev < m_alb_sw.size() && m_alb_sw[lev] != nullptr,
933  "TwoStreamRadiation::advance called on a level define_level has not built");
934  // The sweep indexes the 2D surface fields with the MFIter of the 3D state,
935  // so both must have the same number of boxes on the same ranks.
937  m_alb_sw[lev]->boxArray().size() == cons_old.boxArray().size() &&
938  m_alb_sw[lev]->DistributionMap() == cons_old.DistributionMap(),
939  "TwoStreamRadiation: the 2D surface fields and the 3D state are laid out differently");
940  if (qheating != nullptr) {
941  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(qheating->nComp() == 2 &&
942  qheating->boxArray() == cons_old.boxArray() &&
943  qheating->DistributionMap() == cons_old.DistributionMap(),
944  "TwoStreamRadiation: qheating must be the 2-component (SW, LW) field on the state's grids");
945  }
946  if (rad_choice.seb_enable) {
948  m_lh_sfc[lev] && m_grdflx_sfc[lev] && m_q_sfc[lev] &&
949  m_t_deep[lev] && m_q_deep[lev],
950  "TwoStreamRadiation: seb_enable is set but the SEB fields were not allocated");
951  }
952  // The land-model forcing is read off the interface fluxes the sweep writes. Reached
953  // only on a level that will sweep: the per-box interpolation return above comes first,
954  // and a level whose radiation comes from its parent has no sweep and no rad_fluxes to
955  // read here. Keep that order -- TwoStreamRadiationDriver.LandForcingIsUndefinedUntilASweep
956  // advances such a level and expects it to return untouched.
957  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!supplies_land_forcing(lev) || rad_fluxes != nullptr ||
958  call_site == "post_dycore",
959  "TwoStreamRadiation: supplying a land-surface model's forcing needs the rad_fluxes array");
960  if (call_site == "post_dycore" && rad_choice.seb_prognostic_enable) {
961  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(dt_step > 0.0 && std::isfinite(dt_step),
962  "TwoStreamRadiation: the force-restore update needs a positive, finite dt_step");
963  }
964 
965  // The surface energy balance runs on every level that sweeps, each evolving its
966  // own force-restore state.
967  //
968  // These fields are per level (see define_level), so two levels covering the same
969  // column are not advancing one shared state twice -- they are forming two
970  // independent estimates of one surface. Left alone those estimates drift apart,
971  // which would give the longwave boundary condition two different values for the
972  // same ground. ERF averages t_sfc and q_sfc down after the finer levels have
973  // advanced, so a coarse cell carries the mean of its fine children and the two
974  // agree where they overlap.
975  //
976  // A level that does not sweep has no fluxes of its own and returns earlier.
977  //
978  // NOTE for anyone resolving a merge here: the development side of this line still
979  // carries `&& (lev == 0)`, the single-level restriction. Taking that side back --
980  // which a "resolve by accepting theirs" does -- silently turns this whole branch
981  // into a no-op: the surface energy balance returns to level 0 only while the tests,
982  // docs and PR all still claim otherwise. Keep this form.
983  const bool seb_active = rad_choice.seb_enable;
984  // The land mask counts only for the balance: a water column (mask 0) is not soil.
985  // The mask is read by the local index of the state's boxes, as the 2D fields are.
986  // How the mask is read is in ERF_SEBLandMask.H; balance_mask is nullptr with no balance.
987  const iMultiFab* const balance_mask = seb_active ? land_mask : nullptr;
988  if (balance_mask != nullptr) {
990  seb_assert_land_mask_layout(balance_mask, *m_alb_sw[lev], "TwoStreamRadiation::advance");
991  // A message only, once per set of grids (one reduction and one collective). The
992  // kernels below read the mask as it is at each sweep, and ERF reads it again for
993  // the average-down and the fill of a new level; none of them uses this flag.
994  if (m_water_message[lev] < 0) {
995  m_water_message[lev] = seb_land_mask_has_water(balance_mask) ? 1 : 0;
996  if (m_water_message[lev] == 1) {
997  // Say so once: the keys of the balance are read, but it does not run there.
998  amrex::Print() << "TwoStreamRadiation: level " << lev
999  << " has water columns in its land mask. The force-restore "
1000  << "balance does not run on them; their longwave boundary is "
1001  << (t_surf != nullptr
1002  ? "the surface layer's surface temperature.\n"
1003  : "erf.rad_t_sfc (there is no surface layer at the lower boundary).\n");
1004  }
1005  }
1006  }
1007  // The force-restore state is only the longwave boundary when no external
1008  // surface-temperature provider owns that boundary on this level. The
1009  // canonical radiation input covers SurfaceModel providers such as SLM;
1010  // Noah-MP can also supply t_sfc directly when no canonical input is set.
1011  // Orthogonal to the level question above: this asks WHO owns the boundary,
1012  // that one asks WHETHER this level sweeps at all.
1013  const bool has_external_surface_temperature =
1014  (radiation_inputs.size() > 0 && radiation_inputs[0] != nullptr) ||
1015  (noahmp_active && lsm_has_field(lsm, lev, "t_sfc"));
1016  // The column kernel would substitute placeholders (rho = 1, rho*theta of
1017  // 288 K) for a non-finite or non-positive density or rho*theta and carry
1018  // on, hiding a corrupt state behind plausible heating rates. Refuse such
1019  // a state here instead.
1020  //
1021  // This runs every step, so it is one pass over the state and one
1022  // collective, not the three that contains_nan() plus two MultiFab::min()
1023  // calls would cost. A non-finite value is mapped to -infinity so that the
1024  // same minimum answers both questions: -infinity means non-finite, and any
1025  // other value <= 0 means non-positive. The reduction is collective, so
1026  // every rank takes the same branch.
1027  if (call_site == "pre_dycore") {
1028  ReduceOps<ReduceOpMin, ReduceOpMin> state_ops;
1029  ReduceData<amrex::Real, amrex::Real> state_data(state_ops);
1030  using StateTuple = typename decltype(state_data)::Type;
1031  for (MFIter mfi(cons_old, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1032  const auto& arr = cons_old.const_array(mfi);
1033  state_ops.eval(mfi.tilebox(), state_data,
1034  [=] AMREX_GPU_DEVICE (int i, int j, int k) -> StateTuple {
1035  constexpr amrex::Real neg_inf = -std::numeric_limits<amrex::Real>::infinity();
1036  const amrex::Real rho = arr(i,j,k,Rho_comp);
1037  const amrex::Real rth = arr(i,j,k,RhoTheta_comp);
1038  return {amrex::Math::isfinite(rho) ? rho : neg_inf,
1039  amrex::Math::isfinite(rth) ? rth : neg_inf};
1040  });
1041  }
1042  auto state_tuple = state_data.value(state_ops);
1043  amrex::Real mins[2] = {amrex::get<0>(state_tuple), amrex::get<1>(state_tuple)};
1044  ParallelDescriptor::ReduceRealMin(mins, 2);
1045  const amrex::Real rho_min = mins[0];
1046  const amrex::Real rth_min = mins[1];
1047  if (!std::isfinite(rho_min) || !std::isfinite(rth_min)) {
1048  amrex::Abort("TwoStreamRadiation: the state handed to the column sweep at level " +
1049  std::to_string(lev) + ", step " + std::to_string(nstep) +
1050  " has a non-finite density or rho*theta");
1051  }
1052  if (!(rho_min > 0.0) || !(rth_min > 0.0)) {
1053  amrex::Abort("TwoStreamRadiation: the state handed to the column sweep at level " +
1054  std::to_string(lev) + ", step " + std::to_string(nstep) +
1055  " has a non-positive density (min " + std::to_string(rho_min) +
1056  ") or rho*theta (min " + std::to_string(rth_min) + ")");
1057  }
1058  }
1059 
1060  // The column sweep runs once per step, at the pre-dycore call. The
1061  // post-dycore call would sweep the same old state (vars_old is not
1062  // swapped until the next step), so it reuses the cached flux diagnostics
1063  // and only advances the surface-energy-balance state.
1064  const bool do_sweep = (call_site != "post_dycore");
1065 
1066  // One diagnostics writer per level for the life of the run, so the
1067  // header-written flag and the (step, call_site, time) duplicate guard carry
1068  // over between calls. Per level rather than one for the run: the levels of a
1069  // hierarchy report the same step, call_site and time, so a single shared
1070  // guard would drop every level but the first. All of them append to the one
1071  // CSV, whose `level` column tells the rows apart.
1072  if (!m_diag[lev]) {
1073  m_diag[lev] = std::make_unique<RadiationDiagnostics>(
1074  rad_choice.verbosity, rad_choice.diag_file, lev,
1075  rad_choice.diag_enable, rad_choice.diag_stdout_enable,
1076  rad_choice.diag_tagged_enable, rad_choice.diag_regtest_line_enable,
1077  rad_choice.diag_csv_enable, rad_choice.diag_callsite_mode,
1078  rad_choice.diag_dedup_tol);
1079  }
1080  RadiationDiagnostics& rad_diag = *m_diag[lev];
1081 
1082  // ========================================
1083  // GPU-Safe ParallelFor Implementation with Cloud Fraction
1084  // Blending, Diffuse (Scattering) SW Flux, and Per-Level Heating Rate
1085  // Output (qheating_rates MultiFab)
1086  // ========================================
1087 
1088  // Initialize global diagnostics
1089  amrex::Real SW_surface = 0.0;
1090  amrex::Real SW_TOA = 0.0;
1091  amrex::Real SW_up_TOA = 0.0;
1092  amrex::Real LW_net_surface = 0.0;
1093  amrex::Real LW_up_TOA = 0.0;
1094  amrex::Real heating_rate_max = 0.0;
1095  amrex::Real seb_residual_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
1096  amrex::Real seb_residual_max = std::numeric_limits<amrex::Real>::quiet_NaN();
1097 
1098  // Prognostic SEB surface temperature and moisture diagnostics
1099  amrex::Real t_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
1100  amrex::Real t_s_max = std::numeric_limits<amrex::Real>::quiet_NaN();
1101  amrex::Real q_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
1102  amrex::Real q_s_max = std::numeric_limits<amrex::Real>::quiet_NaN();
1103 
1104  // Get state at this level (conservative variables: density, RhoTheta, etc.)
1105  const MultiFab& state_cons = cons_old;
1106 
1107  // Only compute radiation if we have valid state data
1108  if (state_cons.nComp() > 0 ) {
1109 
1110  // Trivially copyable parameter set for the device lambdas below
1111  // (RadChoice itself holds std::string members and cannot be captured),
1112  // with the sun of this call from the inputs shared with RRTMGP. The
1113  // incident SW at the top (SW_TOA) is a domain mean formed by the sweep,
1114  // since with a calendar sun it varies across the columns.
1115  TwoStreamParams ts_params = make_two_stream_params(rad_choice, m_rdOcp);
1116  if (do_sweep) { set_solar_state(ts_params, rad_choice, m_orbit, epoch_time, have_datetime, lev, nstep); }
1117 
1118  // Host-side storage for reduction results (will be set by device-side reduction)
1119  amrex::Real max_heating_global = 0.0;
1120  amrex::Real sw_surface_sum = 0.0;
1121  amrex::Real sw_up_toa_sum = 0.0;
1122  amrex::Real lw_net_sum = 0.0;
1123  amrex::Real lw_up_toa_sum = 0.0;
1124  amrex::Real sw_toa_sum = 0.0;
1125  amrex::Long n_columns_total = 0;
1126 
1127  // SEB residual diagnostics
1128  amrex::Real seb_residual_sum = 0.0;
1129  amrex::Long n_seb_columns = 0;
1130 
1131  // cloud fraction used to blend clear-sky and cloudy-column results.
1132  // cloud_fraction == 0.0 (default) means only the clear-sky column is
1133  // ever evaluated, and the blend below reduces to F = F_clear exactly.
1134  amrex::Real cloud_fraction = rad_choice.cloud_fraction;
1135 
1136  // qheating is ERF's 2-component (SW, LW) heating-rate MultiFab of this
1137  // level. If it is not allocated yet, the sweep still runs for the
1138  // diagnostics and skips the per-level heating write.
1139  MultiFab* qheating_mf = qheating;
1140 
1141  // Surface radiative fluxes for the SEB. Precedence: an LSM field when
1142  // the LSM exposes one; otherwise, with seb_use_radiation_fluxes, the
1143  // fluxes the column sweep below computes at the surface (written per
1144  // column by the sweep and left in place for the post-dycore call);
1145  // otherwise the scalar defaults.
1146  const bool sw_flux_from_rad = seb_active &&
1147  rad_choice.seb_use_radiation_fluxes &&
1148  !(noahmp_active && lsm_has_field(lsm, lev, "sav"));
1149  const bool lw_flux_from_rad = seb_active &&
1150  rad_choice.seb_use_radiation_fluxes &&
1151  !(noahmp_active && lsm_has_field(lsm, lev, "fira"));
1152 
1153  if (seb_active) {
1154  fill_or_copy_seb_field(m_alb_sw[lev].get(), lsm, lev, lsm_broadband_albedo_name, rad_choice.surface_albedo_sw);
1155  // With the snow layer, the albedo of each column is the blend of the snow-free
1156  // value just written and the snow albedo (Douville et al. 1995, Eq. 8).
1157  if (rad_choice.seb_snow_enable && m_snow.defined(lev)) {
1158  // The sweep below takes a land-surface model's albedo before this field;
1159  // the snow would then melt under an albedo that does not see it.
1160  if ((noahmp_active && lsm_has_field(lsm, lev, lsm_broadband_albedo_name)) ||
1161  (radiation_inputs.size() > 2 && radiation_inputs[2] != nullptr)) {
1162  amrex::Abort("erf.radiation.seb_snow_enable acts on the two-stream surface "
1163  "albedo, but a land-surface model supplies the albedo here; turn "
1164  "it off with a land-surface model");
1165  }
1166  // No snow lies on a building footprint, or on water.
1167  m_snow.apply_albedo(lev, *m_alb_sw[lev], ForceRestoreSnow::params(rad_choice),
1168  has_building_cover(lev) ? m_footprint[lev].get() : nullptr,
1169  balance_mask);
1170  }
1171  fill_or_copy_seb_field(m_emiss_lw[lev].get(), lsm, lev, "sfc_emis", rad_choice.surface_emissivity_lw);
1172 
1173  // In prognostic mode, do not seed this state from an LSM field.
1174  // The column sweep applies external-provider precedence directly,
1175  // and the post-dycore update advances this state only when
1176  // TwoStream owns the surface-temperature boundary.
1177  if (!rad_choice.seb_prognostic_enable) {
1178  fill_or_copy_seb_field(m_t_sfc[lev].get(), lsm, lev, "t_sfc", rad_choice.rad_t_sfc);
1179  }
1180 
1181  // Net absorbed shortwave: Noah-MP splits it into the canopy (sav)
1182  // and ground (sag) parts. Net longwave: Noah-MP's fira is the
1183  // net flux to the atmosphere (positive up); the SEB wants the
1184  // absorbed flux, so the sign flips.
1185  if (!sw_flux_from_rad) {
1186  fill_or_copy_seb_field(m_sw_flux_sfc[lev].get(), lsm, lev, "sav",
1187  rad_choice.seb_sw_flux_default, 1.0, "sag");
1188  }
1189  if (!lw_flux_from_rad) {
1190  fill_or_copy_seb_field(m_lw_flux_sfc[lev].get(), lsm, lev, "fira",
1191  rad_choice.seb_lw_flux_default, -1.0);
1192  }
1193  // H and LE: a land-surface field of that name, else the flux the
1194  // surface layer applies to the air (so the ground loses what the air
1195  // receives), else the scalar defaults; see ERF_SEBTurbulentFlux.H.
1196  // No land model exposes "hfx" or "lh" today, so without one the
1197  // surface layer is the source. G is Noah-MP's grdflx when present.
1198  //
1199  // At the post-dycore call, the one the force-restore update uses, the
1200  // surface layer's flux is the one it applied during this step. At the
1201  // pre-dycore call it is the previous step's, which only the residual
1202  // diagnostic reads.
1203  const int surface_k = geom.Domain().smallEnd(2);
1205  lsm_field(lsm, lev, "hfx"), sfc_sens_flux, surface_k,
1206  rad_choice.seb_turbulent_flux_source,
1207  rad_choice.seb_hfx_default);
1209  lsm_field(lsm, lev, "lh"), sfc_laten_flux, surface_k,
1210  rad_choice.seb_turbulent_flux_source,
1211  rad_choice.seb_lh_default);
1212  fill_or_copy_seb_field(m_grdflx_sfc[lev].get(), lsm, lev, "grdflx", rad_choice.seb_grdflx_default);
1213 
1214  // Gate q_sfc fill on prognostic mode: same reasoning as t_sfc.
1215  if (!rad_choice.seb_prognostic_enable) {
1216  fill_or_copy_seb_field(m_q_sfc[lev].get(), lsm, lev, "noahmp_water_vapor_mixing_ratio_2m_vegetated", rad_choice.seb_q_sfc_default);
1217  }
1218  // No LSM exposes a deep-soil temperature or moisture in kg/kg by
1219  // name (Noah-MP's smstav / smstot are soil-moisture availability
1220  // and total column water), so the reservoir values are the
1221  // scalar defaults. With erf.radiation.seb_deep_prognostic_enable they evolve
1222  // (ERF_ForceRestoreHydrology.H) and are left alone here. So is the deep
1223  // temperature that erf.radiation.seb_init_t_deep_from_file set per column and
1224  // the deep moisture that erf.radiation.seb_init_soil_moisture_from_file set.
1225  if (!seb_t_deep_is_state()) {
1226  m_t_deep[lev]->setVal(rad_choice.seb_t_deep_default);
1227  }
1228  if (!seb_q_deep_is_state()) {
1229  m_q_deep[lev]->setVal(rad_choice.seb_q_deep_default);
1230  }
1231  }
1232 
1233  // The column sweep integrates the whole atmospheric column in one
1234  // kernel, so it needs every k of a box in a single pass. MFIter tiling
1235  // would hand it partial columns (the default CPU tile size splits z),
1236  // so this loop is deliberately untiled and works on valid boxes; the
1237  // horizontal ParallelFor below still provides the parallelism.
1238  const Box& rad_domain = geom.Domain();
1239  if (do_sweep) {
1240  for (MFIter mfi(state_cons, false); mfi.isValid(); ++mfi)
1241  {
1242  const Box& bx = mfi.validbox();
1243 
1244  // A box that does not span the domain vertically would give this
1245  // column solver a truncated atmosphere: no beam from above, no
1246  // cooling to space. ERF only decomposes in z when max_grid_size_z
1247  // is smaller than the domain, so refuse that configuration rather
1248  // than return heating rates that look plausible and are wrong.
1250  bx.smallEnd(2) == rad_domain.smallEnd(2) &&
1251  bx.bigEnd(2) == rad_domain.bigEnd(2),
1252  "TwoStream radiation requires grids that span the domain in z; "
1253  "set amr.max_grid_size_z to at least amr.n_cell in z");
1254  const auto& state_arr = state_cons.const_array(mfi);
1255  // Geometry::CellSize() is host-only; read it here and hand the
1256  // value to the device sweep.
1257  const amrex::Real dz_uniform_lev = geom.CellSize(2);
1258 
1259  // Nodal heights for the layer thicknesses on a stretched or
1260  // terrain-following grid (nullptr on a uniform grid).
1261  Array4<const amrex::Real> z_phys_nd_arr;
1262  if (z_phys_nd != nullptr) {
1263  z_phys_nd_arr = z_phys_nd->const_array(mfi);
1264  }
1265 
1266  // Per-column scratch of the sweep (interfaces need nlev + 1 entries),
1267  // shared by the clear and cloudy evaluations of the same column.
1268  FArrayBox scratch_fab(two_stream_scratch_box(bx), TwoStreamScratch::NCOMP);
1269  Array4<amrex::Real> scratch_arr = scratch_fab.array();
1270 
1271  // Wire LSM surface property fields or use standalone fallback MultiFabs
1272  // Priority:
1273  // 1. If LSM is active (lsm.Get_DataIdx() returns >=0), use real LSM fields
1274  // 2. Otherwise, use standalone fallback MultiFabs (allocated and constant-filled from RadChoice scalars)
1275  // The resolve_surface_*() helpers implement the full precedence chain with finite guards
1276 
1277  // SW albedo. With Noah-MP, its broadband albedo (see lsm_broadband_albedo_name)
1278  // comes first: the canonical SurfaceModel input radiation_inputs[2] is the
1279  // visible direct-beam band of RRTMGP's four (Noah-MP's sfc_alb_dir_vis), not a
1280  // broadband value. Otherwise that canonical input (SLM), then the standalone
1281  // field. resolve_surface_albedo_sw takes the value per column where it is in
1282  // [0, 1] and otherwise the erf.radiation.surface_albedo_sw default, so the
1283  // lsm_undefined placeholder over water, before the first land step and at
1284  // night (Noah-MP has no albedo without sunlight) falls back to the default.
1285  bool has_hetero_alb_sw = false;
1286  Array4<const amrex::Real> hetero_alb_sw_arr;
1287  {
1288  const MultiFab* lsm_albedo = noahmp_active
1289  ? lsm_field(lsm, lev, lsm_broadband_albedo_name)
1290  : nullptr;
1291  if (lsm_albedo != nullptr) {
1292  hetero_alb_sw_arr = lsm_albedo->const_array(mfi);
1293  has_hetero_alb_sw = true;
1294  } else if (radiation_inputs.size() > 2 && radiation_inputs[2]) {
1295  hetero_alb_sw_arr = radiation_inputs[2]->const_array(mfi);
1296  has_hetero_alb_sw = true;
1297  } else if (m_alb_sw[lev]) {
1298  hetero_alb_sw_arr = m_alb_sw[lev]->const_array(mfi);
1299  has_hetero_alb_sw = true;
1300  }
1301  }
1302 
1303  // LW emissivity: Try LSM field "sfc_emis"
1304  bool has_hetero_emiss_lw = false;
1305  Array4<const amrex::Real> hetero_emiss_lw_arr;
1306  {
1307  std::string varname_emiss = "sfc_emis";
1308  int lsm_idx = noahmp_active ? lsm.Get_DataIdx(lev, varname_emiss) : -1;
1309  if (radiation_inputs.size() > 1 && radiation_inputs[1]) {
1310  hetero_emiss_lw_arr = radiation_inputs[1]->const_array(mfi);
1311  has_hetero_emiss_lw = true;
1312  } else if (lsm_idx >= 0) {
1313  auto lsm_ptr = lsm.Get_Data_Ptr(lev, lsm_idx);
1314  if (lsm_ptr) {
1315  hetero_emiss_lw_arr = lsm_ptr->const_array(mfi);
1316  has_hetero_emiss_lw = true;
1317  }
1318  } else if (m_emiss_lw[lev]) {
1319  hetero_emiss_lw_arr = m_emiss_lw[lev]->const_array(mfi);
1320  has_hetero_emiss_lw = true;
1321  }
1322  }
1323 
1324  // Keep the surface-temperature sources separate until the column
1325  // kernel resolves them per cell. An LSM field can exist globally
1326  // while carrying an undefined sentinel in an individual column;
1327  // that column must still fall through to SurfaceLayer theta.
1328  // The kernel's precedence is valid LSM absolute temperature,
1329  // valid prognostic SEB absolute temperature, SurfaceLayer theta,
1330  // then the scalar absolute-temperature fallback.
1331  bool has_lsm_t_sfc = false;
1332  Array4<const amrex::Real> lsm_t_sfc_arr;
1333  bool has_seb_t_sfc = false;
1334  Array4<const amrex::Real> seb_t_sfc_arr;
1335  bool has_surface_layer = false;
1336  Array4<const amrex::Real> surface_layer_theta_arr;
1337  {
1338  std::string varname_t_sfc = "t_sfc";
1339  int lsm_idx = noahmp_active ? lsm.Get_DataIdx(lev, varname_t_sfc) : -1;
1340  if (radiation_inputs.size() > 0 && radiation_inputs[0]) {
1341  lsm_t_sfc_arr = radiation_inputs[0]->const_array(mfi);
1342  has_lsm_t_sfc = true;
1343  } else if (lsm_idx >= 0) {
1344  auto lsm_ptr = lsm.Get_Data_Ptr(lev, lsm_idx);
1345  if (lsm_ptr) {
1346  lsm_t_sfc_arr = lsm_ptr->const_array(mfi);
1347  has_lsm_t_sfc = true;
1348  }
1349  }
1350  // Prognostic SEB is a level-wide alternative to an authoritative
1351  // external surface-temperature provider. When one owns this
1352  // level's boundary, m_t_sfc is not advanced and is not offered
1353  // as a per-cell fallback.
1354  if (!has_lsm_t_sfc && rad_choice.seb_prognostic_enable &&
1355  seb_active && m_t_sfc[lev]) {
1356  seb_t_sfc_arr = m_t_sfc[lev]->const_array(mfi);
1357  has_seb_t_sfc = true;
1358  }
1359  if (t_surf != nullptr) {
1360  surface_layer_theta_arr = t_surf->const_array(mfi);
1361  has_surface_layer = true;
1362  }
1363  }
1364  // The balance's skin is a soil temperature. Over water (land mask 0) it is
1365  // not offered, so the column falls through to the surface layer's sea surface
1366  // temperature, then to the scalar fallback.
1367  const SEBLandMaskView skin_mask = seb_land_mask_view(has_seb_t_sfc ? balance_mask : nullptr, mfi);
1368 
1369  // Per-column latitude and longitude for the calendar sun (only
1370  // the WRF and metgrid initializations fill them; otherwise the
1371  // erf.rad_cons_lat/lon constants apply).
1372  const bool has_latlon = (lat_m != nullptr) && (lon_m != nullptr);
1373  Array4<const amrex::Real> lat_arr, lon_arr;
1374  if (has_latlon) {
1375  lat_arr = lat_m->const_array(mfi);
1376  lon_arr = lon_m->const_array(mfi);
1377  }
1378 
1379  // Interface fluxes for ERF's rad_fluxes (SW up, SW down, LW up,
1380  // LW down at each layer's lower interface, plus the top of the
1381  // atmosphere in the z-ghost cell above the column), the level
1382  // layout RRTMGP writes. The cloudy evaluation goes to a scratch
1383  // FArrayBox on the same grown box and is blended like the
1384  // heating rates.
1385  const bool write_fluxes = (rad_fluxes != nullptr);
1386  Array4<amrex::Real> rad_flux_clear_arr;
1387  FArrayBox rad_flux_cloudy_fab;
1388  Array4<amrex::Real> rad_flux_cloudy_arr;
1389  if (write_fluxes) {
1390  rad_flux_clear_arr = rad_fluxes->array(mfi);
1391  if (cloud_fraction > 0.0) {
1392  rad_flux_cloudy_fab.resize(two_stream_scratch_box(bx), 4);
1393  rad_flux_cloudy_arr = rad_flux_cloudy_fab.array();
1394  }
1395  }
1396 
1397 
1398  // Surface flux arrays the sweep fills for the SEB when asked to.
1399  Array4<amrex::Real> sw_sfc_out;
1400  Array4<amrex::Real> lw_sfc_out;
1401  if (sw_flux_from_rad) sw_sfc_out = m_sw_flux_sfc[lev]->array(mfi);
1402  if (lw_flux_from_rad) lw_sfc_out = m_lw_flux_sfc[lev]->array(mfi);
1403 
1404  // What a land-surface model integrates on, written by the same kernel: the
1405  // surface-interface values of the (blended) fluxes, and the sun the sweep used.
1406  const bool supply_land = supplies_land_forcing(lev);
1407  Array4<amrex::Real> sw_dn_out, lw_dn_out, coszen_out;
1408  if (supply_land) {
1409  sw_dn_out = m_sw_dn_sfc[lev]->array(mfi);
1410  lw_dn_out = m_lw_dn_sfc[lev]->array(mfi);
1411  coszen_out = m_cos_zenith[lev]->array(mfi);
1412  }
1413 
1414  // What the building faces take (erf.ibseb.radiation = two_stream) besides the
1415  // interface fluxes, written by the same kernel: the direct beam at the canopy's
1416  // interfaces from the scratch of each evaluation, weighted as the blend weights
1417  // them, and the cosine of the zenith the sweep used.
1418  const bool supply_canopy = supplies_canopy_forcing(lev);
1419  const int m_canopy_top = supply_canopy ? m_canopy_m[lev] : 0;
1420  const bool sw_on = rad_choice.sw_enabled;
1421  Array4<amrex::Real> canopy_out, canopy_cosz_out, canopy_alb_out;
1422  const bool supply_canopy_alb = supply_canopy && m_canopy_alb[lev];
1423  if (supply_canopy_alb) { canopy_alb_out = m_canopy_alb[lev]->array(mfi); }
1424  if (supply_canopy) {
1425  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(write_fluxes,
1426  "TwoStreamRadiation: the canopy forcing of the building faces needs the rad_fluxes array");
1427  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_canopy_top <= bx.length(2),
1428  "TwoStreamRadiation: the canopy reaches above the top of the column");
1429  canopy_out = m_canopy[lev]->array(mfi);
1430  canopy_cosz_out = m_canopy_cosz[lev]->array(mfi);
1431  }
1432 
1433  // The buildings, when the columns see them (set_building_cover): no heating in
1434  // their solid cells, and, for a ground balance on the sweep's shortwave, the
1435  // absorbed beam at the ground, which the update after the dycore takes off
1436  // the shaded open ground.
1437  const bool cover = has_building_cover(lev);
1438  const bool keep_beam = cover && sw_flux_from_rad && m_sw_beam_sfc[lev];
1439  Array4<const int> solid_arr;
1440  Array4<amrex::Real> sw_beam_out;
1441  int k_solid_top = bx.smallEnd(2) - 1; // the solid cells are kept up to here
1442  if (cover) {
1443  solid_arr = m_solid[lev]->const_array(mfi);
1444  k_solid_top = amrex::min(bx.bigEnd(2), (*m_solid[lev])[mfi].box().bigEnd(2));
1445  }
1446  if (keep_beam) { sw_beam_out = m_sw_beam_sfc[lev]->array(mfi); }
1447  // For what the walls send to the ground (ground_walls_for_step()): the
1448  // longwave down at the ground and the ground's diffuse absorptance and emissivity.
1449  const bool keep_ground = keep_beam && takes_ground_walls(lev);
1450  Array4<amrex::Real> ground_keep_out;
1451  if (keep_ground) {
1452  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(write_fluxes,
1453  "TwoStreamRadiation: the walls' longwave on the ground (erf.ibseb.ground_sky_view) needs the rad_fluxes array");
1454  ground_keep_out = m_ground_keep[lev]->array(mfi);
1455  }
1456 
1457  // The roofs the columns under buildings start on (erf.ibseb.two_stream_roofs),
1458  // which the immersed-boundary balance gave for this step.
1459  const bool on_roofs = cover && starts_on_roofs(lev);
1460  Array4<const int> roof_k_arr;
1461  Array4<const amrex::Real> roof_arr;
1462  if (on_roofs) {
1464  "TwoStreamRadiation: the roofs of level " + std::to_string(lev) + " are of step " +
1465  std::to_string(m_roof_step[lev]) + ", the sweep of step " + std::to_string(nstep) +
1466  "; the immersed-boundary balance must give them before the sweep (ERF::Advance())");
1467  roof_k_arr = m_roof_k[lev]->const_array(mfi);
1468  roof_arr = m_roof[lev]->const_array(mfi);
1469  }
1470 
1471  // Create a 2D box for (i,j) iteration over the horizontal extent
1472  // One GPU thread per (i,j) column; k-loop is sequential within each thread
1473  const auto& lo = bx.loVect();
1474  const auto& hi = bx.hiVect();
1475  Box xy_box(IntVect(lo[0], lo[1], 0), IntVect(hi[0], hi[1], 0));
1476 
1477  // Count columns in this box for later averaging
1478  amrex::Long n_cols = static_cast<amrex::Long>(bx.length(0)) *
1479  static_cast<amrex::Long>(bx.length(1));
1480  n_columns_total += n_cols;
1481 
1482  // Clear-sky-column heating rates are written directly
1483  // into the real qheating_rates MultiFab when available.
1484  // Fall back to a throwaway local FArrayBox otherwise (keeps the
1485  // kernel call GPU-safe even if qheating_rates isn't allocated).
1486  FArrayBox qheating_fallback_fab;
1487  Array4<amrex::Real> qheating_clear_arr;
1488  if (qheating_mf != nullptr) {
1489  qheating_clear_arr = qheating_mf->array(mfi);
1490  } else {
1491  qheating_fallback_fab.resize(bx, 2);
1492  qheating_clear_arr = qheating_fallback_fab.array();
1493  }
1494 
1495  // Cloudy-column heating rates always go into a scratch
1496  // FArrayBox; only used/blended when cloud_fraction > 0.
1497  FArrayBox qheating_cloudy_fab;
1498  Array4<amrex::Real> qheating_cloudy_arr;
1499  if (cloud_fraction > 0.0) {
1500  qheating_cloudy_fab.resize(bx, 2);
1501  qheating_cloudy_arr = qheating_cloudy_fab.array();
1502  }
1503 
1504  // GPU-safe reduction using ReduceOps (per-column results aggregated on device)
1505  amrex::Real max_heating_box = 0.0;
1506  amrex::Real sw_sum_box = 0.0;
1507  amrex::Real sw_up_sum_box = 0.0;
1508  amrex::Real lw_sum_box = 0.0;
1509  amrex::Real lw_up_sum_box = 0.0;
1510  amrex::Real sw_toa_sum_box = 0.0;
1511 
1512  // Device-side reduction: max heating, sums of the surface and
1513  // top-of-atmosphere fluxes
1514  ReduceOps<ReduceOpMax, ReduceOpSum, ReduceOpSum, ReduceOpSum, ReduceOpSum, ReduceOpSum> reduce_ops;
1515  ReduceData<amrex::Real, amrex::Real, amrex::Real, amrex::Real, amrex::Real, amrex::Real> reduce_data(reduce_ops);
1516 
1517  using ReduceTuple = typename decltype(reduce_data)::Type;
1518 
1519  // Launch parallel kernel over (i,j) columns
1520  reduce_ops.eval(xy_box, reduce_data,
1521  [=] AMREX_GPU_DEVICE (int i, int j, int /*k_unused*/) -> ReduceTuple
1522  {
1523  // Clear-sky column (always evaluated; this is the sole
1524  // contributor when cloud_fraction == 0.0, matching earlier behavior)
1525  amrex::Real max_heating_clear = 0.0;
1526  amrex::Real sw_flux_clear = 0.0;
1527  amrex::Real sw_up_clear = 0.0;
1528  amrex::Real lw_net_clear = 0.0;
1529  amrex::Real lw_up_clear = 0.0;
1530  amrex::Real sw_toa_clear = 0.0;
1531  amrex::Real cos_zenith_col = 0.0;
1532  amrex::Real sw_beam_clear = 0.0;
1533  // A column under a building starts on the roof face given for it; one
1534  // without such a face (none given, or open ground) starts on the ground.
1535  TwoStreamRoof roof_col;
1536  // On a roof: a roof face stands on the column and its cell is above the
1537  // box's bottom layer. The sweep takes the roof under the same condition
1538  // (two_stream_starts_on_roof()), so what the faces read of this column
1539  // below is what the sweep used.
1540  const bool col_on_roof = on_roofs && roof_arr(i, j, 0, ROOF_SET) > amrex::Real(0.5)
1541  && two_stream_starts_on_roof(roof_k_arr(i, j, 0), bx.smallEnd(2));
1542  if (col_on_roof) {
1543  roof_col.k_lower = roof_k_arr(i, j, 0);
1544  roof_col.albedo = roof_arr(i, j, 0, ROOF_ALBEDO);
1545  roof_col.emissivity = roof_arr(i, j, 0, ROOF_EMISSIVITY);
1546  roof_col.temperature = roof_arr(i, j, 0, ROOF_TEMPERATURE);
1547  roof_col.lit = roof_arr(i, j, 0, ROOF_LIT);
1548  }
1549  const TwoStreamRoof* roof_ptr = col_on_roof ? &roof_col : nullptr;
1551  i, j, bx, dz_uniform_lev, state_arr, ts_params, /*cloudy=*/false,
1552  qheating_clear_arr,
1553  max_heating_clear, sw_flux_clear, sw_up_clear, lw_net_clear, lw_up_clear,
1554  sw_toa_clear,
1555  z_phys_nd_arr, scratch_arr,
1556  has_hetero_alb_sw, &hetero_alb_sw_arr,
1557  has_hetero_emiss_lw, &hetero_emiss_lw_arr,
1558  has_lsm_t_sfc, &lsm_t_sfc_arr,
1559  has_seb_t_sfc && !skin_mask.water(i, j), &seb_t_sfc_arr,
1560  has_surface_layer, &surface_layer_theta_arr,
1561  has_latlon, &lat_arr, &lon_arr,
1562  write_fluxes ? &rad_flux_clear_arr : nullptr,
1563  &cos_zenith_col, keep_beam ? &sw_beam_clear : nullptr, roof_ptr);
1564 
1565  // The scratch holds this evaluation's beam until the cloudy one overwrites it.
1566  if (supply_canopy) {
1567  two_stream_canopy_beam(i, j, bx.smallEnd(2), m_canopy_top, scratch_arr,
1568  TwoStreamScratch::F_DIR, sw_on, cos_zenith_col,
1569  cloud_fraction, false, canopy_out);
1570  }
1571 
1572  amrex::Real max_heating_col = max_heating_clear;
1573  amrex::Real sw_flux_col = sw_flux_clear;
1574  amrex::Real sw_up_col = sw_up_clear;
1575  amrex::Real lw_net_col = lw_net_clear;
1576  amrex::Real lw_up_col = lw_up_clear;
1577  amrex::Real sw_beam_col = sw_beam_clear;
1578 
1579  // Cloudy column only needs to be evaluated when there is a
1580  // nonzero cloud fraction; this keeps the cloud_fraction==0
1581  // path numerically and computationally identical.
1582  if (cloud_fraction > 0.0) {
1583  amrex::Real max_heating_cloudy = 0.0;
1584  amrex::Real sw_flux_cloudy = 0.0;
1585  amrex::Real sw_up_cloudy = 0.0;
1586  amrex::Real lw_net_cloudy = 0.0;
1587  amrex::Real lw_up_cloudy = 0.0;
1588  amrex::Real sw_toa_cloudy = 0.0;
1589  amrex::Real sw_beam_cloudy = 0.0;
1591  i, j, bx, dz_uniform_lev, state_arr, ts_params, /*cloudy=*/true,
1592  qheating_cloudy_arr,
1593  max_heating_cloudy, sw_flux_cloudy, sw_up_cloudy, lw_net_cloudy, lw_up_cloudy,
1594  sw_toa_cloudy,
1595  z_phys_nd_arr, scratch_arr,
1596  has_hetero_alb_sw, &hetero_alb_sw_arr,
1597  has_hetero_emiss_lw, &hetero_emiss_lw_arr,
1598  has_lsm_t_sfc, &lsm_t_sfc_arr,
1599  has_seb_t_sfc && !skin_mask.water(i, j), &seb_t_sfc_arr,
1600  has_surface_layer, &surface_layer_theta_arr,
1601  has_latlon, &lat_arr, &lon_arr,
1602  write_fluxes ? &rad_flux_cloudy_arr : nullptr,
1603  nullptr, keep_beam ? &sw_beam_cloudy : nullptr, roof_ptr);
1604 
1605  // Blend clear-sky and cloudy-column results
1606  sw_flux_col = (1.0 - cloud_fraction) * sw_flux_clear +
1607  cloud_fraction * sw_flux_cloudy;
1608  sw_up_col = (1.0 - cloud_fraction) * sw_up_clear +
1609  cloud_fraction * sw_up_cloudy;
1610  lw_net_col = (1.0 - cloud_fraction) * lw_net_clear +
1611  cloud_fraction * lw_net_cloudy;
1612  lw_up_col = (1.0 - cloud_fraction) * lw_up_clear +
1613  cloud_fraction * lw_up_cloudy;
1614  sw_beam_col = (1.0 - cloud_fraction) * sw_beam_clear +
1615  cloud_fraction * sw_beam_cloudy;
1616  max_heating_col = std::max(max_heating_clear, max_heating_cloudy);
1617  if (supply_canopy) {
1618  two_stream_canopy_beam(i, j, bx.smallEnd(2), m_canopy_top, scratch_arr,
1619  TwoStreamScratch::F_DIR, sw_on, cos_zenith_col,
1620  cloud_fraction, true, canopy_out);
1621  }
1622 
1623  // Blend per-level heating rates in place
1624  // into qheating_clear_arr (which is the real output
1625  // MultiFab when qheating_mf != nullptr).
1626  int kmin = bx.smallEnd(2);
1627  int kmax = bx.bigEnd(2);
1628  for (int k = kmin; k <= kmax; ++k) {
1629  for (int comp = 0; comp < 2; ++comp) {
1630  amrex::Real q_clear_val = qheating_clear_arr(i, j, k, comp);
1631  amrex::Real q_cloudy_val = qheating_cloudy_arr(i, j, k, comp);
1632  qheating_clear_arr(i, j, k, comp) =
1633  (1.0 - cloud_fraction) * q_clear_val +
1634  cloud_fraction * q_cloudy_val;
1635  }
1636  }
1637  if (write_fluxes) {
1638  // nlev + 1 levels: the top interface sits at kmax + 1
1639  for (int k = kmin; k <= kmax + 1; ++k) {
1640  for (int comp = 0; comp < 4; ++comp) {
1641  rad_flux_clear_arr(i, j, k, comp) =
1642  (1.0 - cloud_fraction) * rad_flux_clear_arr(i, j, k, comp) +
1643  cloud_fraction * rad_flux_cloudy_arr(i, j, k, comp);
1644  }
1645  }
1646  }
1647  }
1648 
1649  // No heating in the solid cells of a building: what its cells would
1650  // absorb is its faces' (the immersed-boundary balance takes the
1651  // column at each face's own height). In a column that holds one, the
1652  // largest rate is then taken over its air cells, from the blended rates.
1653  if (cover) {
1654  bool has_solid = false;
1655  for (int k = bx.smallEnd(2); k <= k_solid_top; ++k) {
1656  if (solid_arr(i, j, k) != 0) {
1657  qheating_clear_arr(i, j, k, 0) = 0.0;
1658  qheating_clear_arr(i, j, k, 1) = 0.0;
1659  has_solid = true;
1660  }
1661  }
1662  if (has_solid) {
1663  amrex::Real q_max = 0.0;
1664  for (int k = bx.smallEnd(2); k <= bx.bigEnd(2); ++k) {
1665  q_max = amrex::max(q_max, std::abs(qheating_clear_arr(i, j, k, 0)) +
1666  std::abs(qheating_clear_arr(i, j, k, 1)));
1667  }
1668  max_heating_col = q_max;
1669  }
1670  }
1671 
1672  // Surface fluxes for the SEB: absorbed shortwave, and the
1673  // absorbed longwave, which is minus the net (up - down).
1674  if (sw_flux_from_rad) sw_sfc_out(i, j, 0) = sw_flux_col;
1675  if (keep_beam) sw_beam_out(i, j, 0) = sw_beam_col;
1676  if (lw_flux_from_rad) lw_sfc_out(i, j, 0) = -lw_net_col;
1677 
1678  // The land model's forcing, after the clear/cloudy blend above.
1679  if (supply_land) {
1680  two_stream_land_forcing(i, j, bx.smallEnd(2), rad_flux_clear_arr,
1681  cos_zenith_col, sw_dn_out(i, j, 0),
1682  lw_dn_out(i, j, 0), coszen_out(i, j, 0));
1683  }
1684 
1685  // After the clear/cloudy blend: the longwave down at the ground, and the
1686  // diffuse absorptance and the emissivity the sweep gave this column's ground.
1687  if (keep_ground) {
1688  const amrex::Real alb_dir_g = resolve_surface_albedo_sw(i, j, &hetero_alb_sw_arr, ts_params,
1689  has_hetero_alb_sw);
1690  const amrex::Real alb_dif_g = resolve_surface_albedo_sw_diffuse(alb_dir_g, ts_params.surface_albedo_sw_diffuse);
1691  ground_keep_out(i, j, 0, 0) = rad_flux_clear_arr(i, j, bx.smallEnd(2), 3);
1692  ground_keep_out(i, j, 0, 1) = amrex::Real(1.0) - alb_dif_g;
1693  ground_keep_out(i, j, 0, 2) = resolve_surface_emissivity_lw(i, j, &hetero_emiss_lw_arr, ts_params,
1694  has_hetero_emiss_lw);
1695  }
1696 
1697  // The sun the building faces must share (their beam is in canopy_out).
1698  if (supply_canopy) {
1699  canopy_cosz_out(i, j, 0) = (cos_zenith_col > amrex::Real(0.0)) ? cos_zenith_col : amrex::Real(0.0);
1700  }
1701  // The direct-beam albedo the sweep gave this column's ground.
1702  if (supply_canopy_alb) {
1703  // On a roof: the roof's albedo for the beam that reaches it, and
1704  // the interface the roof is at, for the faces that read this column.
1705  if (col_on_roof) {
1706  canopy_alb_out(i, j, 0, 0) = roof_col.albedo * roof_col.lit;
1707  canopy_alb_out(i, j, 0, 1) = static_cast<amrex::Real>(roof_col.k_lower - bx.smallEnd(2));
1708  } else {
1709  canopy_alb_out(i, j, 0, 0) = resolve_surface_albedo_sw(i, j, &hetero_alb_sw_arr, ts_params,
1710  has_hetero_alb_sw);
1711  canopy_alb_out(i, j, 0, 1) = amrex::Real(0.0);
1712  }
1713  }
1714 
1715  // The incident TOA flux is the same for both evaluations.
1716  // Return tuple for reduction
1717  return {max_heating_col, sw_flux_col, sw_up_col, lw_net_col, lw_up_col, sw_toa_clear};
1718  }
1719  );
1720 
1721  // Copy results from device to host
1722  amrex::Gpu::synchronize();
1723  auto reduce_tuple = reduce_data.value(reduce_ops);
1724  max_heating_box = amrex::get<0>(reduce_tuple);
1725  sw_sum_box = amrex::get<1>(reduce_tuple);
1726  sw_up_sum_box = amrex::get<2>(reduce_tuple);
1727  lw_sum_box = amrex::get<3>(reduce_tuple);
1728  lw_up_sum_box = amrex::get<4>(reduce_tuple);
1729  sw_toa_sum_box = amrex::get<5>(reduce_tuple);
1730 
1731  // Accumulate box results into global results
1732  max_heating_global = std::max(max_heating_global, max_heating_box);
1733  sw_surface_sum += sw_sum_box;
1734  sw_up_toa_sum += sw_up_sum_box;
1735  lw_net_sum += lw_sum_box;
1736  lw_up_toa_sum += lw_up_sum_box;
1737  sw_toa_sum += sw_toa_sum_box;
1738 
1739  }
1740  // Every accumulator above is rank-local. Reduce before forming means
1741  // and maxima, so the diagnostics describe the whole domain and do
1742  // not change with the decomposition. These are collective calls; the
1743  // conditions around them are input-driven and identical on all ranks.
1744  if (do_sweep) {
1745  amrex::Real sums[5] = {sw_surface_sum, sw_up_toa_sum, lw_net_sum, lw_up_toa_sum, sw_toa_sum};
1746  ParallelDescriptor::ReduceRealSum(sums, 5);
1747  sw_surface_sum = sums[0]; sw_up_toa_sum = sums[1];
1748  lw_net_sum = sums[2]; lw_up_toa_sum = sums[3];
1749  sw_toa_sum = sums[4];
1750  ParallelDescriptor::ReduceLongSum(n_columns_total);
1751  ParallelDescriptor::ReduceRealMax(max_heating_global);
1752  // The faces may take this sweep's canopy forcing in this step, and only in it.
1753  if (supplies_canopy_forcing(lev)) { m_canopy_step[lev] = nstep; }
1754  // The shadow on the ground must be of this step too (see the update below).
1755  m_sweep_step[lev] = nstep;
1756  }
1757  } // do_sweep
1758 
1759  // The heating rates go straight into the RhoTheta source term, so a
1760  // non-finite value here becomes a non-finite state one step later.
1761  if (do_sweep && qheating_mf != nullptr &&
1762  (qheating_mf->contains_nan(0, 2, 0) || qheating_mf->contains_inf(0, 2, 0))) {
1763  amrex::Abort("TwoStreamRadiation: non-finite heating rate after the column sweep at level " +
1764  std::to_string(lev) + ", step " + std::to_string(nstep));
1765  }
1766 
1767  // Warn if diagnostic is requested but SEB infrastructure isn't enabled
1768  if (rad_choice.seb_diagnostic_enable && !rad_choice.seb_enable && lev == 0) {
1769  static bool warned_seb_misconfig = false;
1770  if (!warned_seb_misconfig && ParallelDescriptor::IOProcessor()) {
1771  Print() << "WARNING: erf.radiation.seb_diagnostic_enable=true but "
1772  "seb_enable=false; SEB residual diagnostics will report NaN. "
1773  "Set erf.radiation.seb_enable=true to enable SEB field "
1774  "population.\n";
1775  warned_seb_misconfig = true;
1776  }
1777  }
1778  // The buildings on the ground balance, at the update after the dycore (see
1779  // set_building_cover): a footprint absorbs no shortwave, and with the shortwave
1780  // from the sweep the open ground the buildings shade loses the beam the sweep
1781  // brought it. The shadow is the immersed-boundary balance's, of the sun of this
1782  // step's sweep: that balance runs between the two calls (ERF::Advance()), and the
1783  // stamps say so. Once per sweep, so a second call cannot take the beam twice. The
1784  // call before the dycore sees the sweep's own values, which only its residual
1785  // diagnostic reads.
1786  const bool cover_seb = seb_active && has_building_cover(lev);
1787  if (cover_seb && call_site == "post_dycore") {
1788  const bool take_beam = sw_flux_from_rad && m_ground_shadow[lev] && m_flux_diag[lev].valid &&
1789  m_shaded_step[lev] != m_sweep_step[lev];
1790  if (take_beam) {
1792  "TwoStreamRadiation: the ground's shadow on level " + std::to_string(lev) + " is of step " +
1793  std::to_string(m_shadow_step[lev]) + ", its sweep of step " + std::to_string(m_sweep_step[lev]) +
1794  "; the immersed-boundary balance must give it between the sweep and the update (ERF::Advance())");
1795  }
1796  // What the walls send to the open ground (erf.ibseb.ground_sky_view), with the
1797  // beam, once per sweep: the ground keeps its absorbed diffuse shortwave (the
1798  // sweep's less the beam) and the sky's longwave through the part of its view
1799  // the walls leave open, and takes the walls' through the rest.
1800  // The shortwave and the longwave together: only when the balance takes both from the sweep.
1801  const bool take_walls = take_beam && takes_ground_walls(lev) && lw_flux_from_rad;
1802  if (take_walls) {
1804  "TwoStreamRadiation: what the walls send to the ground on level " + std::to_string(lev) + " is of step " +
1805  std::to_string(m_walls_step[lev]) + ", its sweep of step " + std::to_string(m_sweep_step[lev]) +
1806  "; the immersed-boundary balance must give it between the sweep and the update (ERF::Advance())");
1807  }
1808  for (MFIter mfi(*m_sw_flux_sfc[lev]); mfi.isValid(); ++mfi) {
1809  const Box xy_box = makeSlab(mfi.validbox(), 2, 0);
1810  const auto sw = m_sw_flux_sfc[lev]->array(mfi);
1811  const auto foot = m_footprint[lev]->const_array(mfi);
1812  const auto shadow = take_beam ? m_ground_shadow[lev]->const_array(mfi) : Array4<const Real>{};
1813  const auto beam = take_beam ? m_sw_beam_sfc[lev]->const_array(mfi) : Array4<const Real>{};
1814  const auto walls = take_walls ? m_ground_walls[lev]->const_array(mfi) : Array4<const Real>{};
1815  const auto keep = take_walls ? m_ground_keep[lev]->const_array(mfi) : Array4<const Real>{};
1816  const auto lw = take_walls ? m_lw_flux_sfc[lev]->array(mfi) : Array4<Real>{};
1817  ParallelFor(xy_box, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept {
1818  if (foot(i, j, 0) > Real(0.5)) {
1819  sw(i, j, 0) = 0.0;
1820  return;
1821  }
1822  if (take_walls) {
1824  sw(i, j, 0), beam(i, j, 0), walls(i, j, 0, 0), walls(i, j, 0, 1), walls(i, j, 0, 2),
1825  keep(i, j, 0, 0), keep(i, j, 0, 1), keep(i, j, 0, 2));
1826  sw(i, j, 0) += t.d_sw;
1827  lw(i, j, 0) += t.d_lw;
1828  }
1829  if (take_beam && shadow(i, j, 0) > Real(0.5)) {
1830  sw(i, j, 0) -= beam(i, j, 0);
1831  }
1832  });
1833  }
1834  if (take_beam) { m_shaded_step[lev] = m_sweep_step[lev]; }
1835  }
1836  // From the level's first update after a sweep on, the net shortwave is the balance's.
1837  if (seb_active && call_site == "post_dycore" && m_flux_diag[lev].valid) { m_seb_updated[lev] = 1; }
1838 
1839  // Compute SEB residual diagnostics if enabled
1840  if (rad_choice.seb_diagnostic_enable && seb_active) {
1841  seb_residual_max = 0.0;
1842  // Second loop over boxes to compute SEB residual from populated SEB
1843  // MultiFabs. Untiled: the work below is per surface column, and a
1844  // tiled iteration would visit each (i,j) once per z tile.
1845  for (MFIter mfi(state_cons, false); mfi.isValid(); ++mfi) {
1846  const Box& bx = mfi.validbox();
1847  const auto& lo = bx.loVect();
1848  const auto& hi = bx.hiVect();
1849  Box xy_box(IntVect(lo[0], lo[1], 0), IntVect(hi[0], hi[1], 0));
1850 
1851  // Get SEB field arrays
1852  Array4<const amrex::Real> sw_flux_arr = m_sw_flux_sfc[lev]->const_array(mfi);
1853  Array4<const amrex::Real> lw_flux_arr = m_lw_flux_sfc[lev]->const_array(mfi);
1854  Array4<const amrex::Real> hfx_arr = m_hfx_sfc[lev]->const_array(mfi);
1855  Array4<const amrex::Real> lh_arr = m_lh_sfc[lev]->const_array(mfi);
1856  Array4<const amrex::Real> grdflx_arr = m_grdflx_sfc[lev]->const_array(mfi);
1857  // A building's footprint is not ground the balance runs on.
1858  const bool skip_footprints = cover_seb;
1859  Array4<const amrex::Real> foot_arr;
1860  if (skip_footprints) { foot_arr = m_footprint[lev]->const_array(mfi); }
1861  // Nor is a water column (land mask 0).
1862  const SEBLandMaskView lmask = seb_land_mask_view(balance_mask, mfi);
1863 
1864  // Count columns and compute residuals
1865  amrex::Long n_cols_box = 0;
1866  amrex::Real residual_sum_box = 0.0;
1867  amrex::Real residual_max_box = 0.0;
1868 
1869  // GPU-safe reduction for SEB residuals
1870  ReduceOps<ReduceOpSum, ReduceOpMax, ReduceOpSum> seb_reduce_ops;
1871  ReduceData<amrex::Real, amrex::Real, amrex::Long> seb_reduce_data(seb_reduce_ops);
1872 
1873  using SEBReduceTuple = typename decltype(seb_reduce_data)::Type;
1874 
1875  seb_reduce_ops.eval(xy_box, seb_reduce_data,
1876  [=] AMREX_GPU_DEVICE (int i, int j, int /*k_unused*/) -> SEBReduceTuple {
1877  if ((skip_footprints && foot_arr(i, j, 0) > amrex::Real(0.5)) ||
1878  lmask.water(i, j)) {
1879  return {amrex::Real(0.0), amrex::Real(0.0), amrex::Long(0)};
1880  }
1881  amrex::Real sw_net = sw_flux_arr(i, j, 0);
1882  amrex::Real lw_net = lw_flux_arr(i, j, 0);
1883  amrex::Real hfx = hfx_arr(i, j, 0);
1884  amrex::Real lh = lh_arr(i, j, 0);
1885  amrex::Real grdflx = grdflx_arr(i, j, 0);
1886 
1887  // Compute residual using helper function
1888  amrex::Real residual = diagnose_seb_residual(sw_net, lw_net, hfx, lh, grdflx);
1889 
1890  // Return sum and abs(max) of residual, and the column count
1891  return {residual, std::abs(residual), amrex::Long(1)};
1892  }
1893  );
1894 
1895  // Copy results from device to host
1896  amrex::Gpu::synchronize();
1897  auto seb_reduce_tuple = seb_reduce_data.value(seb_reduce_ops);
1898  residual_sum_box = amrex::get<0>(seb_reduce_tuple);
1899  residual_max_box = amrex::get<1>(seb_reduce_tuple);
1900  n_cols_box = amrex::get<2>(seb_reduce_tuple);
1901 
1902  // Accumulate into global results
1903  seb_residual_sum += residual_sum_box;
1904  seb_residual_max = std::max(seb_residual_max, residual_max_box);
1905  n_seb_columns += n_cols_box;
1906  }
1907  ParallelDescriptor::ReduceRealSum(seb_residual_sum);
1908  ParallelDescriptor::ReduceRealMax(seb_residual_max);
1909  ParallelDescriptor::ReduceLongSum(n_seb_columns);
1910  }
1911 
1912  // Prognostic SEB surface temperature and moisture evolution
1913  // Only advance the force-restore state when TwoStream owns the
1914  // surface-temperature boundary at this level.
1915  //
1916  // With the surface radiation taken from the sweep, also wait for this level's
1917  // first sweep. Until then m_sw_flux_sfc / m_lw_flux_sfc hold what define_level
1918  // left, and advancing on them would apply the scalar defaults for that step. That
1919  // is the first step of a level built by interp_atmos_from_coarse, whose pre-dycore
1920  // sweep ERF::advance_radiation skips (the level's state is not yet consistent),
1921  // while this post-dycore call still arrives.
1922  const bool seb_radiation_ready = m_flux_diag[lev].valid ||
1923  !(sw_flux_from_rad || lw_flux_from_rad);
1924  if (rad_choice.seb_prognostic_enable && seb_active &&
1925  call_site == "post_dycore" && seb_radiation_ready) {
1926  if (!has_external_surface_temperature) {
1927  // No external provider owns the boundary; advance TwoStream's state.
1928 
1929  // Initialize diagnostics for T_s and q_s
1930  amrex::Real t_s_sum = 0.0;
1931  amrex::Real t_s_max_val = -std::numeric_limits<amrex::Real>::max();
1932  amrex::Real q_s_sum = 0.0;
1933  amrex::Real q_s_max_val = -std::numeric_limits<amrex::Real>::max();
1934  amrex::Long n_prog_columns = 0;
1935 
1936  // Third loop over boxes for prognostic SEB update. Untiled for
1937  // the same reason as above, and here it also matters for
1938  // correctness: the force-restore update is applied in place, so
1939  // visiting a column twice would advance it twice in one step.
1940  for (MFIter mfi(state_cons, false); mfi.isValid(); ++mfi) {
1941  const Box& bx = mfi.validbox();
1942  const auto& lo = bx.loVect();
1943  const auto& hi = bx.hiVect();
1944  Box xy_box(IntVect(lo[0], lo[1], 0), IntVect(hi[0], hi[1], 0));
1945 
1946  // Get SEB field arrays (read-only)
1947  Array4<const amrex::Real> sw_flux_arr = m_sw_flux_sfc[lev]->const_array(mfi);
1948  Array4<const amrex::Real> lw_flux_arr = m_lw_flux_sfc[lev]->const_array(mfi);
1949  Array4<const amrex::Real> hfx_arr = m_hfx_sfc[lev]->const_array(mfi);
1950  Array4<const amrex::Real> lh_arr = m_lh_sfc[lev]->const_array(mfi);
1951  Array4<const amrex::Real> grdflx_arr = m_grdflx_sfc[lev]->const_array(mfi);
1952  Array4<const amrex::Real> t_deep_arr = m_t_deep[lev]->const_array(mfi);
1953  Array4<const amrex::Real> q_deep_arr = m_q_deep[lev]->const_array(mfi);
1954 
1955  // Get SEB state arrays (read-write for prognostic update)
1956  Array4<amrex::Real> t_s_arr = m_t_sfc[lev]->array(mfi);
1957  Array4<amrex::Real> q_s_arr = m_q_sfc[lev]->array(mfi);
1958  // A building's footprint keeps its state (see set_building_cover).
1959  const bool hold_footprints = cover_seb;
1960  Array4<const amrex::Real> foot_arr;
1961  if (hold_footprints) { foot_arr = m_footprint[lev]->const_array(mfi); }
1962  // Under snow the upper bound of T_s waits for the snow step below: the
1963  // heat above it melts snow first (ERF_ForceRestoreSnow.H).
1964  const bool melt_first = rad_choice.seb_snow_enable && m_snow.defined(lev);
1965  Array4<const amrex::Real> swe_arr;
1966  if (melt_first) { swe_arr = m_snow.swe(lev)->const_array(mfi); }
1967  // So does a water column (land mask 0): the update is a soil's.
1968  const SEBLandMaskView lmask = seb_land_mask_view(balance_mask, mfi);
1969  // Count columns and prepare for reductions
1970  amrex::Long n_cols_box = 0;
1971  amrex::Real t_s_sum_box = 0.0;
1972  amrex::Real t_s_max_box = -std::numeric_limits<amrex::Real>::max();
1973  amrex::Real q_s_sum_box = 0.0;
1974  amrex::Real q_s_max_box = -std::numeric_limits<amrex::Real>::max();
1975 
1976  // GPU-safe update for prognostic T_s and q_s with reductions
1977  ReduceOps<ReduceOpSum, ReduceOpMax, ReduceOpSum, ReduceOpMax, ReduceOpSum> prog_reduce_ops;
1978  ReduceData<amrex::Real, amrex::Real, amrex::Real, amrex::Real, amrex::Long> prog_reduce_data(prog_reduce_ops);
1979 
1980  using ProgReduceTuple = typename decltype(prog_reduce_data)::Type;
1981 
1982  prog_reduce_ops.eval(xy_box, prog_reduce_data,
1983  [=, C_s=rad_choice.seb_surface_heat_capacity,
1984  tau=rad_choice.seb_restore_timescale_s,
1985  d_s=rad_choice.seb_moisture_layer_depth_m,
1986  tau_q=rad_choice.seb_moisture_restore_timescale_s,
1987  t_min=rad_choice.seb_prognostic_t_min_k,
1988  t_max=rad_choice.seb_prognostic_t_max_k,
1989  q_min=rad_choice.seb_prognostic_q_min,
1990  q_max=rad_choice.seb_prognostic_q_max]
1991  AMREX_GPU_DEVICE (int i, int j, int /*k_unused*/) -> ProgReduceTuple {
1992  if ((hold_footprints && foot_arr(i, j, 0) > amrex::Real(0.5)) ||
1993  lmask.water(i, j)) {
1994  constexpr amrex::Real lowest = std::numeric_limits<amrex::Real>::lowest();
1995  return {amrex::Real(0.0), lowest, amrex::Real(0.0), lowest, amrex::Long(0)};
1996  }
1997  amrex::Real t_s_old = t_s_arr(i, j, 0);
1998  amrex::Real q_s_old = q_s_arr(i, j, 0);
1999 
2000  // Read forcing data
2001  amrex::Real sw_net = sw_flux_arr(i, j, 0);
2002  amrex::Real lw_net = lw_flux_arr(i, j, 0);
2003  amrex::Real hfx = hfx_arr(i, j, 0);
2004  amrex::Real lh = lh_arr(i, j, 0);
2005  amrex::Real grdflx = grdflx_arr(i, j, 0);
2006  amrex::Real t_deep_val = t_deep_arr(i, j, 0);
2007  amrex::Real q_deep_val = q_deep_arr(i, j, 0);
2008 
2009  // Compute SEB residual
2010  amrex::Real seb_res = diagnose_seb_residual(sw_net, lw_net, hfx, lh, grdflx);
2011 
2012  // Compute tendencies
2013  amrex::Real dT_s_dt = prognostic_dTs_dt(seb_res, t_s_old, t_deep_val,
2014  C_s, tau);
2015  amrex::Real dq_s_dt = prognostic_dqs_dt(lh, q_s_old, q_deep_val,
2016  d_s, tau_q);
2017 
2018  // Explicit Euler update over the step size
2019  amrex::Real t_s_new = t_s_old + dt_step * dT_s_dt;
2020  amrex::Real q_s_new = q_s_old + dt_step * dq_s_dt;
2021 
2022  // Clamp to valid ranges
2023  const bool under_snow = melt_first && swe_arr(i, j, 0) > amrex::Real(0.0);
2024  t_s_new = amrex::max(t_min, under_snow ? t_s_new : amrex::min(t_max, t_s_new));
2025  q_s_new = amrex::max(q_min, amrex::min(q_max, q_s_new));
2026 
2027  // Write back updated values (this modifies the device array)
2028  t_s_arr(i, j, 0) = t_s_new;
2029  q_s_arr(i, j, 0) = q_s_new;
2030 
2031  // Return for reduction: sum T_s, max T_s, sum q_s, max q_s, one column
2032  return {t_s_new, std::abs(t_s_new), q_s_new, std::abs(q_s_new), amrex::Long(1)};
2033  });
2034 
2035  // Copy results from device to host
2036  amrex::Gpu::synchronize();
2037  auto prog_reduce_tuple = prog_reduce_data.value(prog_reduce_ops);
2038  t_s_sum_box = amrex::get<0>(prog_reduce_tuple);
2039  t_s_max_box = amrex::get<1>(prog_reduce_tuple);
2040  q_s_sum_box = amrex::get<2>(prog_reduce_tuple);
2041  q_s_max_box = amrex::get<3>(prog_reduce_tuple);
2042  n_cols_box = amrex::get<4>(prog_reduce_tuple);
2043 
2044  // Accumulate into global results
2045  t_s_sum += t_s_sum_box;
2046  t_s_max_val = std::max(t_s_max_val, t_s_max_box);
2047  q_s_sum += q_s_sum_box;
2048  q_s_max_val = std::max(q_s_max_val, q_s_max_box);
2049  n_prog_columns += n_cols_box;
2050  }
2051 
2052  // The force-restore kernels return a zero tendency on any
2053  // non-finite input, so a NaN here means the state itself was
2054  // corrupted (a bad restart file, or an overwrite elsewhere).
2055  if (m_t_sfc[lev]->contains_nan(0, 1, 0) || m_q_sfc[lev]->contains_nan(0, 1, 0)) {
2056  amrex::Abort("TwoStreamRadiation: non-finite surface temperature or moisture "
2057  "after the force-restore update at level " + std::to_string(lev) +
2058  ", step " + std::to_string(nstep));
2059  }
2060 
2061  // The force-restore hydrology (ERF_ForceRestoreHydrology.H): rain, runoff,
2062  // the deep reservoir, drainage and the deep temperature, after the balance
2063  // and on the same columns. A second pass so that with it off the balance's
2064  // kernel and its answers are unchanged.
2065  // The snow layer (ERF_ForceRestoreSnow.H), between the balance and the
2066  // hydrology: it takes the frozen precipitation, lowers T_s where snow melts
2067  // and leaves the melt water for the hydrology step below.
2068  const bool snow_on = rad_choice.seb_snow_enable && m_snow.defined(lev);
2069  if (snow_on) {
2070  amrex::Real t_s_sum_snow = 0.0;
2071  amrex::Real t_s_max_snow = -std::numeric_limits<amrex::Real>::max();
2073  lev, *m_t_sfc[lev], *m_lh_sfc[lev],
2074  cover_seb ? m_footprint[lev].get() : nullptr, dt_step,
2075  ForceRestoreSnow::params(rad_choice), m_precip.frozen(lev, dt_step),
2076  t_s_sum_snow, t_s_max_snow, balance_mask);
2077  // The melt changed T_s: the step's T_s statistics are those after it.
2078  t_s_sum = t_s_sum_snow;
2079  t_s_max_val = t_s_max_snow;
2080  // Counted in the step's own reduction.
2081  if (ss.bad_columns > 0) {
2082  amrex::Abort("TwoStreamRadiation: non-finite surface temperature, or "
2083  "non-finite or negative snow water equivalent, after the force-restore snow step at level " +
2084  std::to_string(lev) + ", step " + std::to_string(nstep));
2085  }
2086  if (rad_choice.verbosity >= 2 && ss.columns > 0) {
2087  const amrex::Real inv_n = amrex::Real(1.0) / static_cast<amrex::Real>(ss.columns);
2088  amrex::Print() << "Force-restore snow at level " << lev << ", step " << nstep
2089  << " (column means, kg/m^2): snowfall = " << ss.snowfall * inv_n
2090  << ", sublimation = " << ss.sublimation * inv_n
2091  << ", melt = " << ss.melt * inv_n
2092  << ", snow water equivalent = " << ss.swe * inv_n
2093  << "; max column budget residual = " << ss.max_residual
2094  << " kg/m^2\n";
2095  }
2096  }
2097 
2098  if (rad_choice.seb_hydrology_enabled()) {
2100  lev, *m_t_sfc[lev], *m_q_sfc[lev], *m_q_deep[lev], *m_t_deep[lev],
2101  *m_lh_sfc[lev], cover_seb ? m_footprint[lev].get() : nullptr,
2102  dt_step, ForceRestoreHydrology::params(rad_choice),
2103  m_precip.rain(lev, dt_step),
2104  snow_on ? m_snow.soil_water(lev) : nullptr,
2105  balance_mask);
2106  if (m_q_sfc[lev]->contains_nan(0, 1, 0) || m_q_deep[lev]->contains_nan(0, 1, 0) ||
2107  m_t_deep[lev]->contains_nan(0, 1, 0)) {
2108  amrex::Abort("TwoStreamRadiation: non-finite soil water or deep temperature "
2109  "after the force-restore hydrology at level " + std::to_string(lev) +
2110  ", step " + std::to_string(nstep));
2111  }
2112  if (rad_choice.verbosity >= 2 && hs.columns > 0) {
2113  const amrex::Real inv_n = amrex::Real(1.0) / static_cast<amrex::Real>(hs.columns);
2114  amrex::Print() << "Force-restore hydrology at level " << lev << ", step " << nstep
2115  << " (column means, kg/m^2 this step): rain = " << hs.rain * inv_n
2116  << ", evaporation = " << hs.evaporation * inv_n
2117  << ", runoff = " << hs.runoff * inv_n
2118  << ", drainage = " << hs.drainage * inv_n
2119  << ", deficit = " << hs.deficit * inv_n
2120  << "; max column budget residual = " << hs.max_residual
2121  << " kg/m^2\n";
2122  }
2123  }
2124  // The steps above took the precipitation rate of this step: a step that
2125  // follows without a new rate takes none.
2126  m_precip.mark_used(lev);
2127 
2128  {
2129  amrex::Real sums[2] = {t_s_sum, q_s_sum};
2130  ParallelDescriptor::ReduceRealSum(sums, 2);
2131  t_s_sum = sums[0]; q_s_sum = sums[1];
2132  ParallelDescriptor::ReduceRealMax(t_s_max_val);
2133  ParallelDescriptor::ReduceRealMax(q_s_max_val);
2134  ParallelDescriptor::ReduceLongSum(n_prog_columns);
2135  }
2136 
2137  // Compute mean values from sums
2138  if (n_prog_columns > 0) {
2139  t_s_mean = t_s_sum / static_cast<amrex::Real>(n_prog_columns);
2140  t_s_max = t_s_max_val;
2141  q_s_mean = q_s_sum / static_cast<amrex::Real>(n_prog_columns);
2142  q_s_max = q_s_max_val;
2143  } else {
2144  t_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
2145  t_s_max = std::numeric_limits<amrex::Real>::quiet_NaN();
2146  q_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
2147  q_s_max = std::numeric_limits<amrex::Real>::quiet_NaN();
2148  }
2149  } else {
2150  // The hydrology acts on TwoStream's own state, which an external provider
2151  // leaves unused: stop rather than silently drop the rain.
2152  if (rad_choice.seb_hydrology_enabled()) {
2153  amrex::Abort("erf.radiation.seb_precipitation_source and "
2154  "seb_deep_prognostic_enable act on the two-stream force-restore "
2155  "state, but a land-surface model supplies the surface temperature "
2156  "here; turn them off with a land-surface model");
2157  }
2158  // An external provider owns the boundary; leave the unused
2159  // TwoStream state untouched and do not report it as active.
2160  t_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
2161  t_s_max = std::numeric_limits<amrex::Real>::quiet_NaN();
2162  q_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
2163  q_s_max = std::numeric_limits<amrex::Real>::quiet_NaN();
2164  }
2165  }
2166  // equivalent to a single-column value for spatially UNIFORM atmospheres
2167  // (as in the current SW_ClearSky_Analytical / LW_Isothermal RegTests).
2168  // Cloud layer and scattering tests are ALSO spatially uniform (identical
2169  // cloud/tau/scattering parameters applied to every column), so the
2170  // domain-averaged value still equals the true single-column flux there.
2171  // True horizontal heterogeneity (e.g., patchy clouds varying by column)
2172  // remains deferred to future work.
2173  if (do_sweep) {
2174  if (n_columns_total > 0) {
2175  const amrex::Real inv_n = 1.0 / static_cast<amrex::Real>(n_columns_total);
2176  SW_surface = sw_surface_sum * inv_n;
2177  SW_TOA = sw_toa_sum * inv_n;
2178  SW_up_TOA = sw_up_toa_sum * inv_n;
2179  LW_net_surface = lw_net_sum * inv_n;
2180  LW_up_TOA = lw_up_toa_sum * inv_n;
2181  }
2182  heating_rate_max = max_heating_global;
2183  m_flux_diag[lev] = FluxDiag{true, SW_surface, SW_TOA, SW_up_TOA,
2184  LW_net_surface, LW_up_TOA,
2185  heating_rate_max};
2186  } else {
2187  const FluxDiag& cached = m_flux_diag[lev];
2188  if (!cached.valid) {
2189  // No sweep has run on this level yet, so there is nothing to report. This
2190  // happens on the first step of a level built by interp_atmos_from_coarse:
2191  // ERF::advance_radiation interpolates that level's fields and returns
2192  // before the pre-dycore sweep, while this post-dycore call still arrives
2193  // from ERF::Advance. Emitting here would write a row of zeros that reads
2194  // exactly like a real zero-flux result. A nested patch already contributes
2195  // no rows for the same reason; this is the same rule for a level that
2196  // simply has not swept yet.
2197  return;
2198  }
2199  SW_surface = cached.SW_surface;
2200  SW_TOA = cached.SW_TOA;
2201  SW_up_TOA = cached.SW_up_TOA;
2202  LW_net_surface = cached.LW_net_surface;
2203  LW_up_TOA = cached.LW_up_TOA;
2204  heating_rate_max = cached.heating_rate_max;
2205  }
2206 
2207  // Compute SEB residual mean from sum
2208  if (rad_choice.seb_diagnostic_enable && seb_active && n_seb_columns > 0) {
2209  seb_residual_mean = seb_residual_sum / static_cast<amrex::Real>(n_seb_columns);
2210  } else {
2211  // When feature is disabled, use NaN for backward compatibility
2212  seb_residual_mean = std::numeric_limits<amrex::Real>::quiet_NaN();
2213  seb_residual_max = std::numeric_limits<amrex::Real>::quiet_NaN();
2214  }
2215 
2216  }
2217 
2218  // Logging output
2219  if (rad_choice.verbosity >= 1 && ParallelDescriptor::IOProcessor()) {
2220  Print() << "Radiation diagnostics at step " << nstep << ":\n"
2221  << " SW TOA = " << SW_TOA << " W/m^2\n"
2222  << " SW surface = " << SW_surface << " W/m^2\n"
2223  << " SW up (TOA) = " << SW_up_TOA << " W/m^2\n"
2224  << " LW net (surface) = " << LW_net_surface << " W/m^2\n"
2225  << " LW up (TOA) = " << LW_up_TOA << " W/m^2\n"
2226  << " Max heating rate = " << heating_rate_max << " K/s\n";
2227  if (rad_choice.seb_diagnostic_enable && std::isfinite(seb_residual_mean)) {
2228  Print() << " SEB residual (mean) = " << seb_residual_mean << " W/m^2\n"
2229  << " SEB residual (max) = " << seb_residual_max << " W/m^2\n";
2230  }
2231  if (rad_choice.seb_prognostic_enable && std::isfinite(t_s_mean)) {
2232  Print() << " Surface temperature (mean) = " << t_s_mean << " K\n"
2233  << " Surface temperature (max) = " << t_s_max << " K\n"
2234  << " Surface moisture (mean) = " << q_s_mean << " m^3/m^3\n"
2235  << " Surface moisture (max) = " << q_s_max << " m^3/m^3\n";
2236  }
2237  }
2238 
2239  rad_diag.append(nstep, time, call_site, SW_surface, SW_TOA,
2240  SW_up_TOA, LW_net_surface, LW_up_TOA, heating_rate_max,
2241  seb_residual_mean, seb_residual_max,
2242  t_s_mean, t_s_max, q_s_mean, q_s_max);
2243 }
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
pp_for_pert_vels get("prob_type", prob_type)
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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 rad_boxes_span_column(const amrex::BoxArray &ba, const amrex::Box &dom)
Definition: ERF_RadiationInterface.H:18
SEBLandMaskView seb_land_mask_view(const amrex::iMultiFab *mask, const amrex::MFIter &mfi)
The view of mask on the box of mfi; off when mask is nullptr.
Definition: ERF_SEBLandMask.H:54
bool seb_land_mask_has_water(const amrex::iMultiFab *mask)
True when mask holds a water column on any rank; false for nullptr.
Definition: ERF_SEBLandMask.H:70
void seb_assert_land_mask_layout(const amrex::iMultiFab *mask, const amrex::FabArrayBase &field, const char *who)
Stop when mask is given and is not on the grids of field.
Definition: ERF_SEBLandMask.H:43
SEBFluxOrigin fill_seb_turbulent_flux(MultiFab &seb_flux, SEBTurbulentFlux kind, const MultiFab *land_surface_field, const MultiFab *surface_layer_flux, int surface_k, SEBTurbulentFluxSource source, Real fallback)
Definition: ERF_SEBTurbulentFlux.cpp:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real diagnose_seb_residual(amrex::Real sw_net, amrex::Real lw_net, amrex::Real hfx, amrex::Real lh, amrex::Real grdflx)
Diagnose the surface energy balance residual.
Definition: ERF_SimplifiedSEB.H:68
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real prognostic_dqs_dt(amrex::Real le, amrex::Real q_s, amrex::Real q_deep, amrex::Real d_s, amrex::Real tau_q)
Compute prognostic surface moisture tendency using force-restore formulation.
Definition: ERF_SimplifiedSEB.H:169
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real prognostic_dTs_dt(amrex::Real seb_residual, amrex::Real t_s, amrex::Real t_deep, amrex::Real c_s, amrex::Real tau)
Compute prognostic surface temperature tendency using force-restore formulation.
Definition: ERF_SimplifiedSEB.H:114
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void two_stream_canopy_beam(int i, int j, int kmin, int m_top, const amrex::Array4< const amrex::Real > &scratch, int f_dir_comp, bool sw_on, amrex::Real cos_zenith, amrex::Real cloud_fraction, bool blend, const amrex::Array4< amrex::Real > &beam)
Write the direct beam on a horizontal surface at the interfaces 0 .. m_top of column (i,...
Definition: ERF_TwoStreamCanopyForcing.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GroundWallTerms two_stream_ground_wall_terms(amrex::Real sw_net, amrex::Real sw_beam, amrex::Real wall_view, amrex::Real sw_walls, amrex::Real lw_walls, amrex::Real lw_down, amrex::Real absorb_dif, amrex::Real emis) noexcept
The change of the open ground's net radiation beside walls (erf.ibseb.ground_sky_view)....
Definition: ERF_TwoStreamCanopyForcing.H:233
TwoStreamParams make_two_stream_params(const RadChoice &rc, const amrex::Real rdOcp)
Copy the column-kernel parameters out of a RadChoice.
Definition: ERF_TwoStreamColumn.H:127
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real resolve_surface_albedo_sw(int i, int j, const amrex::Array4< const amrex::Real > *hetero_alb_sw, const TwoStreamParams &rad_choice, bool has_hetero_alb)
Resolve per-column shortwave surface albedo from hetero field or fallback.
Definition: ERF_TwoStreamColumn.H:245
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real resolve_surface_albedo_sw_diffuse(amrex::Real alb_dir, amrex::Real surface_albedo_sw_diffuse) noexcept
The ground's albedo for diffuse shortwave: the input surface_albedo_sw_diffuse, or the direct-beam al...
Definition: ERF_TwoStreamColumn.H:308
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void two_stream_land_forcing(int i, int j, int kmin, const amrex::Array4< const amrex::Real > &rad_flux, amrex::Real cos_zenith, amrex::Real &sw_dn, amrex::Real &lw_dn, amrex::Real &coszen)
The radiative forcing a land-surface model integrates on, for column (i,j).
Definition: ERF_TwoStreamColumn.H:908
amrex::Box two_stream_scratch_box(const amrex::Box &bx)
Box of the scratch FArrayBox a sweep over box bx needs.
Definition: ERF_TwoStreamColumn.H:662
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool two_stream_starts_on_roof(int k_lower, int kbot) noexcept
Whether a column starts on a roof: the layer on the roof, k_lower, is above the box's bottom layer kb...
Definition: ERF_TwoStreamColumn.H:284
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real resolve_surface_emissivity_lw(int i, int j, const amrex::Array4< const amrex::Real > *hetero_emiss_lw, const TwoStreamParams &rad_choice, bool has_hetero_emiss)
Resolve per-column longwave surface emissivity from hetero field or fallback.
Definition: ERF_TwoStreamColumn.H:328
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void vertical_two_stream_sweep(int i, int j, const amrex::Box &bx, amrex::Real dz_uniform, const amrex::Array4< const amrex::Real > &state_arr, const TwoStreamParams &rad_choice, bool cloudy, const amrex::Array4< amrex::Real > &qheating_arr, amrex::Real &max_heating_rate, amrex::Real &sw_surface_flux, amrex::Real &sw_up_toa, amrex::Real &lw_net_surface, amrex::Real &lw_up_toa, amrex::Real &sw_down_toa, const amrex::Array4< const amrex::Real > &z_phys_nd, const amrex::Array4< amrex::Real > &scratch, bool has_hetero_alb_sw=false, const amrex::Array4< const amrex::Real > *hetero_alb_sw=nullptr, bool has_hetero_emiss_lw=false, const amrex::Array4< const amrex::Real > *hetero_emiss_lw=nullptr, bool has_lsm_t_sfc=false, const amrex::Array4< const amrex::Real > *lsm_t_sfc=nullptr, bool has_seb_t_sfc=false, const amrex::Array4< const amrex::Real > *seb_t_sfc=nullptr, bool has_surface_layer=false, const amrex::Array4< const amrex::Real > *surface_layer_theta=nullptr, bool has_latlon=false, const amrex::Array4< const amrex::Real > *lat_arr=nullptr, const amrex::Array4< const amrex::Real > *lon_arr=nullptr, const amrex::Array4< amrex::Real > *rad_flux_out=nullptr, amrex::Real *cos_zenith_out=nullptr, amrex::Real *sw_beam_absorbed_out=nullptr, const TwoStreamRoof *roof=nullptr)
GPU-safe per-column vertical integration kernel for two-stream radiation, computing either the clear-...
Definition: ERF_TwoStreamColumn.H:1004
StepSums step(int lev, const amrex::MultiFab &t_s, amrex::MultiFab &q_s, amrex::MultiFab &q_deep, amrex::MultiFab &t_deep, const amrex::MultiFab &lh, const amrex::MultiFab *footprint, amrex::Real dt, const ForceRestoreHydrologyParams &prm, const ForceRestorePrecipInput &rain, const amrex::MultiFab *snow_water=nullptr, const amrex::iMultiFab *land_mask=nullptr)
One hydrology step on every open column of lev, after the balance has updated T_s and q_s....
Definition: ERF_ForceRestoreHydrologyState.cpp:54
static ForceRestoreHydrologyParams params(const RadChoice &rc)
The parameters of one step, from the erf.radiation.seb_* inputs.
Definition: ERF_ForceRestoreHydrologyState.cpp:20
ForceRestorePrecipInput rain(int lev, amrex::Real dt) const noexcept
The rain a step of length dt takes (the total without the snow layer).
Definition: ERF_ForceRestorePrecipRate.H:87
ForceRestorePrecipInput frozen(int lev, amrex::Real dt) const noexcept
The frozen precipitation a step of length dt takes; none unless split().
Definition: ERF_ForceRestorePrecipRate.H:92
void mark_used(int lev) noexcept
The steps of this level took the rate: it is not applied again.
Definition: ERF_ForceRestorePrecipRate.cpp:113
StepSums step(int lev, amrex::MultiFab &t_s, const amrex::MultiFab &lh, const amrex::MultiFab *footprint, amrex::Real dt, const ForceRestoreSnowParams &prm, const ForceRestorePrecipInput &snowfall, amrex::Real &t_s_sum_local, amrex::Real &t_s_max_local, const amrex::iMultiFab *land_mask=nullptr)
One snow step on every open column of lev, after the balance has updated T_s. A footprint cell (footp...
Definition: ERF_ForceRestoreSnowState.cpp:54
void apply_albedo(int lev, amrex::MultiFab &alb_sw, const ForceRestoreSnowParams &prm, const amrex::MultiFab *footprint=nullptr, const amrex::iMultiFab *land_mask=nullptr) const
Write the surface albedo with snow into alb_sw, which holds the snow-free albedo: DRM95 Eq....
Definition: ERF_ForceRestoreSnowState.cpp:147
static ForceRestoreSnowParams params(const RadChoice &rc)
The parameters of one step, from the erf.radiation.seb_* inputs.
Definition: ERF_ForceRestoreSnowState.cpp:22
const amrex::MultiFab * soil_water(int lev) const noexcept
Water the last step() handed the soil [kg/m^2]: melt plus sublimation; or nullptr.
Definition: ERF_ForceRestoreSnowState.H:111
amrex::MultiFab * swe(int lev) noexcept
The snow water equivalent [kg/m^2], or nullptr.
Definition: ERF_ForceRestoreSnowState.H:101
bool defined(int lev) const noexcept
True once define_level allocated lev.
Definition: ERF_ForceRestoreSnowState.H:63
int Get_DataIdx(const int &lev, const std::string &varname)
Definition: ERF_LandSurface.H:186
amrex::MultiFab * Get_Data_Ptr(const int &lev, const int &varIdx)
Definition: ERF_LandSurface.H:142
CSV logger and debug-print manager for radiation module.
Definition: ERF_RadiationDiagnostics.H:75
void append(int step, amrex::Real time, std::string const &call_site, amrex::Real sw_surface, amrex::Real sw_toa, amrex::Real sw_up_toa, amrex::Real lw_net_surface, amrex::Real lw_up_toa, amrex::Real heating_rate_max, amrex::Real seb_residual_mean=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real seb_residual_max=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real t_s_mean=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real t_s_max=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real q_s_mean=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real q_s_max=std::numeric_limits< amrex::Real >::quiet_NaN())
Append a diagnostic row to the CSV file.
Definition: ERF_RadiationDiagnostics.cpp:79
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_footprint
Definition: ERF_TwoStreamRadiation.H:657
bool supplies_canopy_forcing(int lev) const noexcept
True when supply_canopy_forcing() was called for lev since its last define_level().
Definition: ERF_TwoStreamRadiation.H:396
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_canopy_cosz
Definition: ERF_TwoStreamRadiation.H:643
bool supplies_land_forcing(int lev) const noexcept
True when define_level allocated the land-model forcing fields on lev.
Definition: ERF_TwoStreamRadiation.H:343
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_q_sfc
Definition: ERF_TwoStreamRadiation.H:621
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_canopy_alb
Definition: ERF_TwoStreamRadiation.H:644
bool takes_ground_walls(int lev) const noexcept
True when the ground balance of lev takes what the walls send it (see set_building_cover()): the one ...
Definition: ERF_TwoStreamRadiation.H:487
ForceRestorePrecipRate m_precip
Definition: ERF_TwoStreamRadiation.H:626
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_roof
Definition: ERF_TwoStreamRadiation.H:670
bool has_building_cover(int lev) const noexcept
True when set_building_cover() was called for lev since its last define_level().
Definition: ERF_TwoStreamRadiation.H:492
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_roof_k
Definition: ERF_TwoStreamRadiation.H:669
amrex::Vector< int > m_roof_step
Definition: ERF_TwoStreamRadiation.H:671
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_canopy
Definition: ERF_TwoStreamRadiation.H:642
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_grdflx_sfc
Definition: ERF_TwoStreamRadiation.H:620
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ground_walls
Definition: ERF_TwoStreamRadiation.H:664
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_lw_flux_sfc
Definition: ERF_TwoStreamRadiation.H:617
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_q_deep
Definition: ERF_TwoStreamRadiation.H:623
bool seb_q_deep_is_state() const
True when the deep water content is part of the state: it evolves (erf.radiation.seb_deep_prognostic_...
Definition: ERF_TwoStreamRadiation.H:291
amrex::Real m_rdOcp
Definition: ERF_TwoStreamRadiation.H:600
amrex::Vector< FluxDiag > m_flux_diag
Definition: ERF_TwoStreamRadiation.H:684
bool active() const
True once a level has been defined with the model selected.
Definition: ERF_TwoStreamRadiation.H:68
bool seb_t_deep_is_state() const
True when the deep temperature is part of the state: it evolves (erf.radiation.seb_deep_prognostic_en...
Definition: ERF_TwoStreamRadiation.H:268
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ground_keep
Definition: ERF_TwoStreamRadiation.H:665
ForceRestoreHydrology m_hydro
Definition: ERF_TwoStreamRadiation.H:627
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_emiss_lw
Definition: ERF_TwoStreamRadiation.H:612
amrex::Vector< int > m_walls_step
Definition: ERF_TwoStreamRadiation.H:666
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_t_sfc
Definition: ERF_TwoStreamRadiation.H:613
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_lw_dn_sfc
Definition: ERF_TwoStreamRadiation.H:636
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_lh_sfc
Definition: ERF_TwoStreamRadiation.H:619
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_alb_sw
Definition: ERF_TwoStreamRadiation.H:611
bool starts_on_roofs(int lev) const noexcept
True when the columns of lev under a building start on its roof (erf.ibseb.two_stream_roofs; set_buil...
Definition: ERF_TwoStreamRadiation.H:454
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_sw_flux_sfc
Definition: ERF_TwoStreamRadiation.H:616
ForceRestoreSnow m_snow
Definition: ERF_TwoStreamRadiation.H:628
OrbitalCache m_orbit
Definition: ERF_TwoStreamRadiation.H:601
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_t_deep
Definition: ERF_TwoStreamRadiation.H:622
amrex::Vector< std::unique_ptr< RadiationDiagnostics > > m_diag
Definition: ERF_TwoStreamRadiation.H:608
amrex::Vector< int > m_shadow_step
Definition: ERF_TwoStreamRadiation.H:672
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ground_shadow
Definition: ERF_TwoStreamRadiation.H:658
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_sw_dn_sfc
Definition: ERF_TwoStreamRadiation.H:635
amrex::Vector< int > m_seb_updated
Definition: ERF_TwoStreamRadiation.H:677
amrex::Vector< int > m_sweep_step
Definition: ERF_TwoStreamRadiation.H:673
amrex::Vector< int > m_shaded_step
Definition: ERF_TwoStreamRadiation.H:674
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_solid
Definition: ERF_TwoStreamRadiation.H:656
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_sw_beam_sfc
Definition: ERF_TwoStreamRadiation.H:659
amrex::Vector< int > m_canopy_step
Definition: ERF_TwoStreamRadiation.H:646
amrex::Vector< int > m_water_message
Definition: ERF_TwoStreamRadiation.H:682
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_hfx_sfc
Definition: ERF_TwoStreamRadiation.H:618
amrex::Vector< int > m_canopy_m
Definition: ERF_TwoStreamRadiation.H:645
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_cos_zenith
Definition: ERF_TwoStreamRadiation.H:637
@ rho
Definition: ERF_Kessler.H:25
constexpr int F_DIR
Definition: ERF_TwoStreamColumn.H:652
constexpr int NCOMP
Definition: ERF_TwoStreamColumn.H:658
@ t
Definition: ERF_WSM6.H:295
Domain sums of one step on one level (rank-reduced), for the log.
Definition: ERF_ForceRestoreHydrologyState.H:54
amrex::Real deficit
[kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:59
amrex::Long columns
open columns updated
Definition: ERF_ForceRestoreHydrologyState.H:61
amrex::Real runoff
[kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:57
amrex::Real evaporation
sum of E dt [kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:56
amrex::Real rain
sum of P dt [kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:55
amrex::Real max_residual
max |column budget residual| [kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:60
amrex::Real drainage
[kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:58
Domain sums of one step on one level (rank-reduced), for the log.
Definition: ERF_ForceRestoreSnowState.H:39
amrex::Real swe
sum of W_n after the step [kg/m^2]
Definition: ERF_ForceRestoreSnowState.H:43
amrex::Real sublimation
[kg/m^2]
Definition: ERF_ForceRestoreSnowState.H:41
amrex::Real snowfall
[kg/m^2]
Definition: ERF_ForceRestoreSnowState.H:40
amrex::Long columns
Definition: ERF_ForceRestoreSnowState.H:45
amrex::Long bad_columns
open columns left with a non-finite T_s, or a non-finite or negative W_n
Definition: ERF_ForceRestoreSnowState.H:47
amrex::Real melt
[kg/m^2]
Definition: ERF_ForceRestoreSnowState.H:42
amrex::Real max_residual
max |column budget residual| [kg/m^2]
Definition: ERF_ForceRestoreSnowState.H:44
What two_stream_ground_wall_terms() adds to the ground balance's net shortwave and longwave [W/m^2].
Definition: ERF_TwoStreamCanopyForcing.H:206
Container holding radiation-related choices and parameters.
Definition: ERF_RadStruct.H:142
bool seb_snow_enable
One bulk snow layer on the force-restore surface (ERF_ForceRestoreSnow.H): the snow routine of the IS...
Definition: ERF_RadStruct.H:784
bool sw_enabled
Enable shortwave (solar) radiation computation. Only used by the two-stream model.
Definition: ERF_RadStruct.H:154
std::string diag_file
Output file path for radiation diagnostics CSV. Paths are relative to the simulation working director...
Definition: ERF_RadStruct.H:278
amrex::Real surface_albedo_sw
Shortwave surface albedo fallback [0, 1] for per-column heterogeneous-surface-property resolution....
Definition: ERF_RadStruct.H:412
amrex::Real surface_emissivity_lw
Longwave surface emissivity fallback [0, 1] for per-column heterogeneous-surface-property resolution....
Definition: ERF_RadStruct.H:427
amrex::Real seb_grdflx_default
Fallback SEB ground heat flux [W/m^2]. The force-restore restoring term already represents the flux i...
Definition: ERF_RadStruct.H:610
amrex::Real diag_dedup_tol
Tolerance for time equality in duplicate guard [s]. Times within this tolerance are considered equal....
Definition: ERF_RadStruct.H:329
amrex::Real seb_restore_timescale_s
Force-restore timescale for surface temperature [s]. Relaxation time constant toward T_deep in progno...
Definition: ERF_RadStruct.H:670
std::string diag_callsite_mode
Call-site filtering mode: "both" (pre+post rows), "pre_only", or "post_only".
Definition: ERF_RadStruct.H:322
bool diag_regtest_line_enable
Enable RADIATION_DIAG: line emission. Controls regtest-parsing diagnostics line. Default true.
Definition: ERF_RadStruct.H:309
amrex::Real seb_lh_default
Fallback SEB latent heat flux [W/m^2].
Definition: ERF_RadStruct.H:603
amrex::Real seb_moisture_restore_timescale_s
Force-restore timescale for surface moisture [s]. Relaxation time constant toward q_deep in prognosti...
Definition: ERF_RadStruct.H:686
amrex::Real seb_lw_flux_default
Fallback SEB surface net longwave flux [W/m^2].
Definition: ERF_RadStruct.H:453
amrex::Real seb_q_sfc_default
Fallback SEB surface moisture, and the initial value of the prognostic one. With seb_prognostic_enabl...
Definition: ERF_RadStruct.H:618
bool diag_csv_enable
Enable CSV file append behavior. When false, no file writes; other enabled streams may still print....
Definition: ERF_RadStruct.H:316
amrex::Real seb_t_deep_default
SEB deep soil temperature [K] of every column; with seb_init_t_deep_from_file, of the water columns a...
Definition: ERF_RadStruct.H:624
amrex::Real seb_prognostic_t_max_k
Maximum clamping bound for prognostic surface temperature [K]. After each Euler update,...
Definition: ERF_RadStruct.H:703
amrex::Real rad_t_sfc
erf.rad_t_sfc: surface temperature [K] used as the longwave boundary condition wherever no land-surfa...
Definition: ERF_RadStruct.H:207
bool seb_prognostic_enable
Enable prognostic SEB surface temperature and moisture evolution. When true, integrates SEB residual ...
Definition: ERF_RadStruct.H:649
bool seb_use_radiation_fluxes
Take the SEB's net surface shortwave and longwave fluxes from the two-stream sweep itself (per column...
Definition: ERF_RadStruct.H:443
amrex::Real seb_prognostic_t_min_k
Minimum clamping bound for prognostic surface temperature [K]. After each Euler update,...
Definition: ERF_RadStruct.H:695
amrex::Real cloud_fraction
Cloud fraction in [0, 1] used to blend clear-sky and cloudy-column fluxes: F = (1 - cloud_fraction) *...
Definition: ERF_RadStruct.H:364
amrex::Real seb_prognostic_q_max
Maximum clamping bound for prognostic surface moisture [kg/kg]. After each Euler update,...
Definition: ERF_RadStruct.H:719
bool seb_hydrology_enabled() const noexcept
True when any of the force-restore hydrology inputs is on.
Definition: ERF_RadStruct.H:807
amrex::Real seb_moisture_layer_depth_m
Effective surface moisture layer depth [m]. Used in force-restore prognostic q_s equation: dq_s/dt = ...
Definition: ERF_RadStruct.H:678
SEBTurbulentFluxSource seb_turbulent_flux_source
Source of the SEB's sensible and latent heat fluxes when no land-surface model supplies them: "surfac...
Definition: ERF_RadStruct.H:460
amrex::Real seb_hfx_default
Fallback SEB sensible heat flux [W/m^2].
Definition: ERF_RadStruct.H:598
bool diag_tagged_enable
Enable tagged [RAD][...] debug lines. Controls emission of bracketed-tag debug output....
Definition: ERF_RadStruct.H:302
amrex::Real seb_q_deep_default
Deep soil moisture the prognostic q_s restores to, in q_s's units (see seb_q_sfc_default).
Definition: ERF_RadStruct.H:630
amrex::Real seb_sw_flux_default
Fallback SEB surface net shortwave flux [W/m^2].
Definition: ERF_RadStruct.H:448
bool diag_enable
Master switch for radiation diagnostics emission. When false, no diagnostics output (stdout/tagged/re...
Definition: ERF_RadStruct.H:288
amrex::Real seb_prognostic_q_min
Minimum clamping bound for prognostic surface moisture [kg/kg]. After each Euler update,...
Definition: ERF_RadStruct.H:711
bool seb_enable
Master switch for simplified SEB infrastructure. When false (default), no SEB MultiFabs are allocated...
Definition: ERF_RadStruct.H:433
bool diag_stdout_enable
Enable human-readable stdout diagnostics block. Controls tagged [RAD][...] debug line emission (when ...
Definition: ERF_RadStruct.H:295
int verbosity
Debug verbosity level (0=off, 1+=debug output). Gated debug prints only emit when this is >= 1.
Definition: ERF_RadStruct.H:272
amrex::Real seb_surface_heat_capacity
Effective surface heat capacity [J/(m^2*K)]. Used in force-restore prognostic T_s equation: dT_s/dt =...
Definition: ERF_RadStruct.H:660
bool seb_diagnostic_enable
Enable diagnostic SEB residual computation and reporting. When true, computes and reports SEB residua...
Definition: ERF_RadStruct.H:640
The land mask of one box, for a device kernel. Captured by value.
Definition: ERF_SEBLandMask.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool water(int i, int j) const noexcept
True when the balance does not run on column (i, j).
Definition: ERF_SEBLandMask.H:35
Trivially copyable subset of RadChoice used by the column kernels.
Definition: ERF_TwoStreamColumn.H:57
amrex::Real surface_albedo_sw_diffuse
Definition: ERF_TwoStreamColumn.H:74
A roof as the lower boundary of a column (erf.ibseb.two_stream_roofs): the column under a building st...
Definition: ERF_TwoStreamColumn.H:270
amrex::Real emissivity
Longwave emissivity of the roof [1].
Definition: ERF_TwoStreamColumn.H:273
amrex::Real albedo
Shortwave albedo of the roof, for the beam and for diffuse light [1].
Definition: ERF_TwoStreamColumn.H:272
amrex::Real lit
Share of the direct beam that reaches the roof: 0 where a taller building shades it [1].
Definition: ERF_TwoStreamColumn.H:275
int k_lower
First cell of the column above the roof (the roof is its lower interface)
Definition: ERF_TwoStreamColumn.H:271
amrex::Real temperature
Skin temperature of the roof [K].
Definition: ERF_TwoStreamColumn.H:274
Here is the call graph for this function:

◆ canopy_forcing()

TwoStreamCanopyView TwoStreamRadiation::canopy_forcing ( int  lev,
int  nstep 
) const
inlinenoexcept

The beam and the cosine of the zenith of lev as the sweep of step nstep wrote them (the view's fluxes are left for the caller, who owns rad_fluxes), or an empty view when the level does not supply them or has not swept at that step: the faces must not take a previous step's radiation, nor the zeros of a level whose radiation came from its parent.

407  {
409  if (supplies_canopy_forcing(lev) && m_canopy_step[lev] == nstep) {
410  v.beam = m_canopy[lev].get();
411  v.cos_zenith = m_canopy_cosz[lev].get();
412  v.ground_albedo_dir = m_canopy_alb[lev].get();
413  }
414  return v;
415  }
The fields a level's faces read for one step: the beam and the cosine of the zenith the sweep of that...
Definition: ERF_TwoStreamCanopyForcing.H:45
const amrex::MultiFab * beam
Direct beam on a horizontal surface, interfaces 0 .. m_top [W/m^2].
Definition: ERF_TwoStreamCanopyForcing.H:46
const amrex::MultiFab * cos_zenith
Cosine of the zenith of the sweep, floored at zero (2D) [1].
Definition: ERF_TwoStreamCanopyForcing.H:47
const amrex::MultiFab * ground_albedo_dir
Definition: ERF_TwoStreamCanopyForcing.H:53
Here is the call graph for this function:

◆ define_level()

void TwoStreamRadiation::define_level ( int  lev,
const RadChoice &  rad_choice,
amrex::Real  rdOcp,
const amrex::BoxArray &  ba2d,
const amrex::DistributionMapping &  dm,
const amrex::BoxArray &  ba,
const amrex::Box &  domain,
bool  supply_land_forcing = false 
)

Allocate the 2D surface fields of one level on the given horizontal BoxArray and fill them with the scalar defaults. A no-op unless rad_choice.rad_type == TwoStream.

The column sweep needs every box of ba to span domain in z, because it applies the top-of-atmosphere and surface boundary conditions at the ends of a box. A fine level that does not takes its fields from its parent; a level 0 that does not is rejected before this is called (ERF::check_rad_level_grids), and is only asserted here.

Parameters
levlevel
rad_choicethe model's inputs
ba2dhorizontal BoxArray the 2D surface fields live on
dmdistribution mapping shared with the level's state
bathe level's 3D BoxArray (z span asserted on level 0)
domainthe level's domain Box
supply_land_forcingallocate the downwelling SW, downwelling LW and cos(zenith) fields the sweep fills for a land-surface model (SolverChoice::rad_feeds_lsm()); off, the sweep does no extra work and the fields do not exist
289 {
290  if (!rad_choice.enabled) { return; }
291  m_rad = &rad_choice;
292  m_rdOcp = rdOcp;
293 
294  // The sweep integrates a whole column in one pass inside a single box, applying the
295  // top-of-atmosphere boundary condition above the top layer and the surface condition
296  // below the bottom one. So the requirement is per box: every box must span the domain
297  // in z. Levels that do not meet it come in several shapes -- a shallow nest, a level
298  // tagged at different heights in different horizontal regions, grids decomposed in z --
299  // and they all have the same consequence, that no box holds a column to sweep.
300  //
301  // Above level 0 that is not an error: ERF::advance_radiation interpolates the level's
302  // heating rates and fluxes from its parent, the route RRTMGP takes for a nested patch.
303  // On level 0 there is no parent to interpolate from, so it is fatal; ERF rejects such a
304  // level 0 for every radiation model when its grids are built (ERF::check_rad_level_grids,
305  // called just before this), so here it is only asserted.
306  AMREX_ASSERT(lev > 0 || rad_boxes_span_column(ba, domain));
307  amrex::ignore_unused(ba, domain);
308 
309  // 2D surface fields on the horizontal BoxArray, one ghost cell in x and y
310  const IntVect ng_sfc{1,1,0};
311  m_alb_sw[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
312  m_emiss_lw[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
313  m_t_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
314  m_alb_sw[lev]->setVal(rad_choice.surface_albedo_sw);
315  m_emiss_lw[lev]->setVal(rad_choice.surface_emissivity_lw);
316  m_t_sfc[lev]->setVal(rad_choice.rad_t_sfc);
317 
318  if (rad_choice.seb_enable) {
319  m_sw_flux_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
320  m_lw_flux_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
321  m_hfx_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
322  m_lh_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
323  m_grdflx_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
324  m_q_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
325  m_t_deep[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
326  m_q_deep[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, ng_sfc);
327  m_sw_flux_sfc[lev]->setVal(rad_choice.seb_sw_flux_default);
328  m_lw_flux_sfc[lev]->setVal(rad_choice.seb_lw_flux_default);
329  m_hfx_sfc[lev]->setVal(rad_choice.seb_hfx_default);
330  m_lh_sfc[lev]->setVal(rad_choice.seb_lh_default);
331  m_grdflx_sfc[lev]->setVal(rad_choice.seb_grdflx_default);
332  m_q_sfc[lev]->setVal(rad_choice.seb_q_sfc_default);
333  m_t_deep[lev]->setVal(rad_choice.seb_t_deep_default);
334  m_q_deep[lev]->setVal(rad_choice.seb_q_deep_default);
335  if (rad_choice.seb_surface_layer_uses_moisture) {
336  m_moisture[lev] = std::make_unique<MultiFab>(ba2d, dm,
338  m_moisture[lev]->setVal(0.0);
339  } else {
340  m_moisture[lev].reset();
341  }
342  // The precipitation rate of the step, and the hydrology's running totals (each a
343  // no-op when it is off).
344  m_precip.define_level(lev, rad_choice, ba2d, dm);
345  m_hydro.define_level(lev, rad_choice, ba2d, dm, ng_sfc);
346  // The snow water equivalent and its running totals (a no-op when it is off).
347  m_snow.define_level(lev, rad_choice, ba2d, dm, ng_sfc);
348  }
349 
350  // The land-model forcing (see the members). It holds the lsm_undefined sentinel until a
351  // sweep on this level fills it. Zero would be a valid forcing (night, no sky), so a copy
352  // made before any sweep -- a level whose advance() returned early, or a caller that
353  // drifts out of step with the sweep -- would hand the land model a 0 K sky that its
354  // first-land-step check (NOAHMP::Advance_With_State) accepts. The sentinel is what
355  // that check looks for.
356  if (supply_land_forcing) {
357  m_sw_dn_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, 0);
358  m_lw_dn_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, 0);
359  m_cos_zenith[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, 0);
360  m_sw_dn_sfc[lev]->setVal(lsm_undefined);
361  m_lw_dn_sfc[lev]->setVal(lsm_undefined);
362  m_cos_zenith[lev]->setVal(lsm_undefined);
363  } else {
364  m_sw_dn_sfc[lev].reset();
365  m_lw_dn_sfc[lev].reset();
366  m_cos_zenith[lev].reset();
367  }
368  // A rebuilt level has new grids: the canopy forcing, if the faces asked for it,
369  // must be asked for again on them (the faces do not regrid; ERF::init_ibseb()).
370  m_canopy[lev].reset();
371  m_canopy_cosz[lev].reset();
372  m_canopy_alb[lev].reset();
373  m_canopy_m[lev] = -1;
374  m_canopy_step[lev] = -1;
375  // The building cover likewise (ERF::init_ibseb() sets it once; the balance refuses a regrid).
376  m_solid[lev].reset();
377  m_footprint[lev].reset();
378  m_ground_shadow[lev].reset();
379  m_sw_beam_sfc[lev].reset();
380  m_ground_walls[lev].reset();
381  m_ground_keep[lev].reset();
382  m_roof_k[lev].reset();
383  m_roof[lev].reset();
384  m_roof_step[lev] = -1;
385  m_walls_step[lev] = -1;
386  m_shadow_step[lev] = -1;
387  m_sweep_step[lev] = -1;
388  m_shaded_step[lev] = -1;
389  m_has_cover[lev] = 0;
390  m_seb_updated[lev] = 0;
391  // The level may have new grids: look at its land mask again.
392  m_water_message[lev] = -1;
393  m_flux_diag[lev] = FluxDiag{};
394 }
constexpr amrex::Real lsm_undefined
Definition: ERF_Constants.H:28
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
void define_level(int lev, const RadChoice &rc, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::IntVect &ng)
Allocate the level's fields; a no-op unless the hydrology is enabled.
Definition: ERF_ForceRestoreHydrologyState.cpp:45
void define_level(int lev, const RadChoice &rc, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm)
Allocate the level's fields; a no-op without erf.radiation.seb_precipitation_source.
Definition: ERF_ForceRestorePrecipRate.cpp:23
void define_level(int lev, const RadChoice &rc, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::IntVect &ng)
Allocate the level's fields, with the snow water equivalent at erf.radiation.seb_snow_initial_swe_kg_...
Definition: ERF_ForceRestoreSnowState.cpp:41
amrex::Vector< int > m_has_cover
Definition: ERF_TwoStreamRadiation.H:675
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_moisture
Definition: ERF_TwoStreamRadiation.H:629
@ NumComponents
Definition: ERF_SurfaceMoisture.H:37
bool seb_surface_layer_uses_moisture
Two-way coupling of moisture as well: the surface layer takes its land surface mixing ratio from the ...
Definition: ERF_RadStruct.H:528
Here is the call graph for this function:

◆ force_restore_soil()

ForceRestoreSoil TwoStreamRadiation::force_restore_soil ( int  lev) const

The force-restore soil of lev, read-only (see ForceRestoreSoil), or an empty view (every pointer nullptr) when the force-restore state is not evolved there.

870 {
872  if (!seb_prognostic_active() || lev < 0 || lev >= static_cast<int>(m_t_sfc.size()) ||
873  !m_q_sfc[lev]) {
874  return v;
875  }
876  const RadChoice& rc = *m_rad;
877  v.q_sfc = m_q_sfc[lev].get();
878  v.q_deep = m_q_deep[lev].get();
879  v.t_sfc = m_t_sfc[lev].get();
880  v.rain_rate = m_precip.rate(lev);
881  v.d_s = rc.seb_moisture_layer_depth_m;
882  v.deep = rc.seb_deep_prognostic_enable;
883  v.d_2 = v.deep ? rc.seb_deep_layer_depth_m : Real(0.0); // 0 also when the depth only averages the file's SMOIS
884  v.porosity = (rc.seb_soil_porosity > 0.0) ? rc.seb_soil_porosity
885  : (rc.seb_soil_type != 0 ? noahmp_soil_params(rc.seb_soil_type)->smc_max : Real(-1.0));
886  v.fc = rc.seb_soil_moisture_fc;
887  v.wilt = rc.seb_soil_moisture_wilt;
888  return v;
889 }
const NoahMPSoilParams * noahmp_soil_params(int category) noexcept
The parameters of STAS soil category category (1-19), as Noah-MP reads them.
Definition: ERF_NoahMPSoilTable.H:49
const amrex::MultiFab * rate(int lev) const noexcept
The rate of the last end_step [kg/m^2/s] (Comp components), or nullptr. For output.
Definition: ERF_ForceRestorePrecipRate.H:100
bool seb_prognostic_active() const
True when the force-restore state is being evolved and so needs transferring.
Definition: ERF_TwoStreamRadiation.H:338
constexpr std::array< amrex::Real, num_veg_params > rc
Definition: ERF_SLM_DefaultParams.H:22
The force-restore soil of one level, read-only, for a model that reads the ground (the dust coupling'...
Definition: ERF_ForceRestoreHydrologyState.H:24
const amrex::MultiFab * q_sfc
surface-layer water content [m^3/m^3]
Definition: ERF_ForceRestoreHydrologyState.H:25
amrex::Real d_2
column depth [m] (seb_deep_layer_depth_m); 0 without the deep reservoir
Definition: ERF_ForceRestoreHydrologyState.H:30
amrex::Real porosity
[m^3/m^3]; -1 when neither seb_soil_porosity nor seb_soil_type gives one
Definition: ERF_ForceRestoreHydrologyState.H:31
const amrex::MultiFab * t_sfc
surface temperature [K]
Definition: ERF_ForceRestoreHydrologyState.H:27
bool deep
seb_deep_prognostic_enable
Definition: ERF_ForceRestoreHydrologyState.H:34
const amrex::MultiFab * q_deep
column water content [m^3/m^3]; constant in time without the deep reservoir (per column with seb_init...
Definition: ERF_ForceRestoreHydrologyState.H:26
const amrex::MultiFab * rain_rate
rain of the last step [kg/m^2/s], component 0; nullptr without seb_precipitation_source
Definition: ERF_ForceRestoreHydrologyState.H:28
amrex::Real fc
field capacity [m^3/m^3] (seb_soil_moisture_fc)
Definition: ERF_ForceRestoreHydrologyState.H:32
amrex::Real wilt
wilting point [m^3/m^3] (seb_soil_moisture_wilt)
Definition: ERF_ForceRestoreHydrologyState.H:33
amrex::Real d_s
surface layer depth [m] (seb_moisture_layer_depth_m)
Definition: ERF_ForceRestoreHydrologyState.H:29
amrex::Real smc_max
MAXSMC saturated soil moisture (porosity) [m^3/m^3].
Definition: ERF_NoahMPSoilTable.H:23
Here is the call graph for this function:

◆ ground_shadow()

const amrex::MultiFab* TwoStreamRadiation::ground_shadow ( int  lev) const
inlinenoexcept

The ground's shadow last given for lev (see ground_shadow_for_step()), or nullptr before one is given or when the level takes none. Read-only: for output.

538  {
539  return (lev >= 0 && lev < static_cast<int>(m_ground_shadow.size()) && m_shadow_step[lev] >= 0)
540  ? m_ground_shadow[lev].get() : nullptr;
541  }

◆ ground_shadow_for_step()

MultiFab * TwoStreamRadiation::ground_shadow_for_step ( int  lev,
int  nstep 
)

The field the immersed-boundary balance fills with the buildings' shadow on the ground of lev for step nstep (1 where the ray from the ground toward the sun meets a building, 0 where the sun reaches it; 2D: i,j), or nullptr when the level's ground balance takes no shadow (no building cover; no balance on the sweep's shortwave, or the shortwave off; or a level whose rates come from its parent). Marks the field as that step's: the update after the dycore stops unless the shadow is of the step its sweep ran in.

562 {
563  if (!has_building_cover(lev) || !m_ground_shadow[lev]) { return nullptr; }
564  m_shadow_step[lev] = nstep;
565  return m_ground_shadow[lev].get();
566 }

◆ ground_walls()

const amrex::MultiFab* TwoStreamRadiation::ground_walls ( int  lev) const
inlinenoexcept

What the walls sent to the ground of lev last (see ground_walls_for_step()), or nullptr before any or when the level takes none. Read-only: for output.

522  {
523  return (lev >= 0 && lev < static_cast<int>(m_ground_walls.size()) && m_walls_step[lev] >= 0)
524  ? m_ground_walls[lev].get() : nullptr;
525  }

◆ ground_walls_for_step()

MultiFab * TwoStreamRadiation::ground_walls_for_step ( int  lev,
int  nstep 
)

The field the immersed-boundary balance fills with what the walls send to the ground of lev for step nstep (IBFaceSet::compute_ground_walls(): the walls' share of the ground's view, their reflected shortwave and their longwave arriving on the ground, W/m^2), or nullptr when the level's ground balance takes none (takes_ground_walls()). Marks the field as that step's. At the update after the dycore the open ground then keeps its absorbed diffuse shortwave and the sky's longwave through the part of its view the walls leave open, and takes the walls' through the rest: SW += (1 - alb_dif) SW_walls - v (SW - SW_beam), LW += emis (LW_walls - v LW_down), with v the walls' share (two_stream_ground_wall_terms()).

554 {
555  if (!has_building_cover(lev) || !takes_ground_walls(lev)) { return nullptr; }
556  m_walls_step[lev] = nstep;
557  return m_ground_walls[lev].get();
558 }

◆ has_building_cover()

bool TwoStreamRadiation::has_building_cover ( int  lev) const
inlinenoexcept

True when set_building_cover() was called for lev since its last define_level().

492  {
493  return lev >= 0 && lev < static_cast<int>(m_has_cover.size()) && m_has_cover[lev] != 0;
494  }

◆ hydrology_begin_step()

void TwoStreamRadiation::hydrology_begin_step ( int  lev,
const SurfacePrecipAccumulationSources &  sources,
int  klo 
)

Store the surface precipitation accumulation of lev at the start of its step (ERF::Advance, before the dycore and microphysics). A no-op without erf.radiation.seb_precipitation_source = microphysics.

855 {
857  m_precip.begin_step(lev, sources, klo);
858 }
const int klo
Definition: ERF_InitCustomPert_KE.H:9
void begin_step(int lev, const SurfacePrecipAccumulationSources &sources, int klo)
Store the accumulation [kg/m^2] at the start of the level's step. When no step used the rate of the p...
Definition: ERF_ForceRestorePrecipRate.cpp:55
@ None
Definition: ERF_LSM_Types.H:6
SEBPrecipitationSource seb_precipitation_source
Rain into the force-restore surface (ERF_ForceRestoreHydrology.H). Default none: the balance as befor...
Definition: ERF_RadStruct.H:727

◆ hydrology_end_step()

void TwoStreamRadiation::hydrology_end_step ( int  lev,
const SurfacePrecipAccumulationSources &  sources,
int  klo,
amrex::Real  dt 
)

The rain rate of the step of lev just taken, from the accumulation now and the one hydrology_begin_step stored; called before the post-dycore advance. A no-op without erf.radiation.seb_precipitation_source = microphysics.

863 {
865  m_precip.end_step(lev, sources, klo, dt);
866 }
void end_step(int lev, const SurfacePrecipAccumulationSources &sources, int klo, amrex::Real dt)
The rate [kg/m^2/s]: the accumulation now minus the one begin_step stored, over the time since that s...
Definition: ERF_ForceRestorePrecipRate.cpp:72

◆ hydrology_rain_rate()

const amrex::MultiFab* TwoStreamRadiation::hydrology_rain_rate ( int  lev) const
inline

The hydrology's rain rate of the last step [kg/m^2/s], in component 0 (nullptr without seb_precipitation_source) and running totals [kg/m^2] (nullptr without the hydrology). Read-only: for output.

326  {
327  return m_precip.rate(lev);
328  }
Here is the call graph for this function:

◆ hydrology_totals()

const amrex::MultiFab* TwoStreamRadiation::hydrology_totals ( int  lev)
inline
329  {
330  return m_hydro.totals(lev);
331  }
amrex::MultiFab * totals(int lev) noexcept
The running totals (Total components) [kg/m^2], or nullptr.
Definition: ERF_ForceRestoreHydrologyState.H:109
Here is the call graph for this function:

◆ land_forcing_cos_zenith()

const amrex::MultiFab* TwoStreamRadiation::land_forcing_cos_zenith ( int  lev) const
inlinenoexcept
360  {
361  return supplies_land_forcing(lev) ? m_cos_zenith[lev].get() : nullptr;
362  }
Here is the call graph for this function:

◆ land_forcing_lw_dn()

const amrex::MultiFab* TwoStreamRadiation::land_forcing_lw_dn ( int  lev) const
inlinenoexcept
357  {
358  return supplies_land_forcing(lev) ? m_lw_dn_sfc[lev].get() : nullptr;
359  }
Here is the call graph for this function:

◆ land_forcing_sw_dn()

const amrex::MultiFab* TwoStreamRadiation::land_forcing_sw_dn ( int  lev) const
inlinenoexcept

The surface forcing of the last sweep on lev (2D: i,j), or nullptr when the level does not supply it: total downwelling shortwave [W/m^2], downwelling longwave [W/m^2] and the cosine of the solar zenith angle floored at zero [1]. lsm_undefined until a sweep has run on the level, so a copy made before one is caught by the land model's missing-input check instead of reading as zero.

354  {
355  return supplies_land_forcing(lev) ? m_sw_dn_sfc[lev].get() : nullptr;
356  }
Here is the call graph for this function:

◆ mask_building_heating()

void TwoStreamRadiation::mask_building_heating ( int  lev,
amrex::MultiFab &  qheating 
) const

Set the heating rates of lev to zero in the solid cells of its building cover (a no-op without one): for a level whose rates come from its parent by interpolation, where no sweep of its own masks them.

570 {
571  if (!has_building_cover(lev)) { return; }
572  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(qheating.nComp() == 2 && qheating.boxArray().size() == m_solid[lev]->boxArray().size() &&
573  qheating.DistributionMap() == m_solid[lev]->DistributionMap(),
574  "TwoStreamRadiation::mask_building_heating: the heating rates are not on the level's grids");
575  // The kept solid cells: each box of the level up to the tallest building.
576  for (MFIter mfi(qheating); mfi.isValid(); ++mfi) {
577  const Box sbx = (*m_solid[lev])[mfi].box() & mfi.validbox();
578  if (sbx.isEmpty()) { continue; }
579  const auto q = qheating.array(mfi);
580  const auto solid = m_solid[lev]->const_array(mfi);
581  ParallelFor(sbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
582  if (solid(i, j, k) != 0) { q(i, j, k, 0) = 0.0; q(i, j, k, 1) = 0.0; }
583  });
584  }
585 }
@ q
Definition: ERF_WSM6.H:296
Here is the call graph for this function:

◆ prognostic_surface_temperature_state()

const amrex::MultiFab* TwoStreamRadiation::prognostic_surface_temperature_state ( int  lev) const
inlinenoexcept

Read-only view of the per-level prognostic surface-temperature state.

73  {
74  return (lev >= 0 && lev < static_cast<int>(m_t_sfc.size()))
75  ? m_t_sfc[lev].get() : nullptr;
76  }

◆ read_checkpoint()

void TwoStreamRadiation::read_checkpoint ( int  lev,
const std::string &  restart_chkfile,
const amrex::Periodicity &  period 
)

Read it back when the checkpoint carries it; else keep defaults.

733 {
734  // Older checkpoints do not carry the state; then the defaults set by
735  // define_level stand. Every level, matching write_checkpoint. A checkpoint
736  // written before the SEB ran on fine levels simply has no file for them, which
737  // the FileExists test below already handles.
738  //
739  // Each field is read on the grids in the file and redistributed onto the grids the
740  // run uses, which differ when the restart re-made level 0 (issue 4225). The fields
741  // are written with their ghost cells and an ordinary restart has always restored
742  // those, so the halo is offered too.
743  if (!active() || !m_rad->seb_enable) { return; }
744  const std::string tsfc_name =
745  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "TwoStream_TSfc");
746  if (m_t_sfc[lev] && amrex::FileExists(tsfc_name + "_H")) {
747  erf_checkpoint::read_checkpoint_multifab(*m_t_sfc[lev], tsfc_name, 0, 0, 1,
748  m_t_sfc[lev]->nGrowVect(), true, period);
749  }
750  const std::string qsfc_name =
751  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "TwoStream_QSfc");
752  if (m_q_sfc[lev] && amrex::FileExists(qsfc_name + "_H")) {
753  erf_checkpoint::read_checkpoint_multifab(*m_q_sfc[lev], qsfc_name, 0, 0, 1,
754  m_q_sfc[lev]->nGrowVect(), true, period);
755  }
756  // A checkpoint written without the deep reservoir has no deep state: the defaults stand.
757  // With erf.radiation.seb_init_t_deep_from_file and no deep reservoir only the deep
758  // temperature is read. A checkpoint without it was written by a run whose deep
759  // temperature was erf.radiation.seb_t_deep_default in every column, so that value, set
760  // by define_level, continues that run; the initial file is not read on a restart.
761  if (seb_t_deep_is_state()) {
762  const bool reservoir = m_rad->seb_deep_prognostic_enable;
763  const bool from_file = m_rad->seb_init_t_deep_from_file;
764  bool t_deep_read = false;
765  MultiFab* deep[] = {m_t_deep[lev].get(), m_q_deep[lev].get()};
766  const char* deep_names[] = {"TwoStream_TDeep", "TwoStream_QDeep"};
767  for (int n = 0; n < (reservoir ? 2 : 1); ++n) {
768  const std::string name =
769  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", deep_names[n]);
770  if (deep[n] && amrex::FileExists(name + "_H")) {
772  deep[n]->nGrowVect(), true, period);
773  if (n == 0) { t_deep_read = true; }
774  } else if (deep[n] && lev == 0 && n == 0 && from_file) {
775  // Written by a run without the input and without the reservoir
776  amrex::Print() << "NOTE: the checkpoint has no " << deep_names[n]
777  << ": erf.radiation.seb_init_t_deep_from_file is not used on "
778  "this restart and the deep temperature "
779  << (reservoir ? "starts from " : "is ")
780  << "erf.radiation.seb_t_deep_default = "
781  << m_rad->seb_t_deep_default << " K in every column\n";
782  } else if (deep[n] && lev == 0 && n == 1 && t_deep_read) {
783  // Written with seb_init_t_deep_from_file and without the reservoir
784  amrex::Print() << "NOTE: the checkpoint has no " << deep_names[n]
785  << "; the deep temperature is the checkpoint's and "
786  "erf.radiation.seb_q_deep_default starts the deep moisture\n";
787  } else if (deep[n] && lev == 0 && n == 0 && amrex::FileExists(
788  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", deep_names[1]) + "_H")) {
789  // Written with seb_init_soil_moisture_from_file and without the reservoir
790  amrex::Print() << "NOTE: the checkpoint has no " << deep_names[n]
791  << "; erf.radiation.seb_t_deep_default starts the deep "
792  "temperature and the deep moisture is the checkpoint's\n";
793  } else if (deep[n] && lev == 0) {
794  amrex::Print() << "NOTE: the checkpoint has no " << deep_names[n]
795  << "; erf.radiation.seb_t_deep_default and seb_q_deep_default "
796  "start the deep reservoir\n";
797  }
798  }
799  } else if (lev == 0 && amrex::FileExists(
800  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "TwoStream_TDeep") + "_H")) {
801  amrex::Print() << "NOTE: the checkpoint holds TwoStream_TDeep, which is not read: "
802  "neither erf.radiation.seb_deep_prognostic_enable nor "
803  "erf.radiation.seb_init_t_deep_from_file is set, and the deep "
804  "temperature is erf.radiation.seb_t_deep_default in every column\n";
805  }
806  // The deep moisture that erf.radiation.seb_init_soil_moisture_from_file set per column,
807  // without the deep reservoir (with it the loop above read the field). A checkpoint
808  // without it was written by a run whose deep moisture was
809  // erf.radiation.seb_q_deep_default in every column, so that value continues that run.
810  const std::string qdeep_name =
811  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "TwoStream_QDeep");
813  if (m_q_deep[lev] && amrex::FileExists(qdeep_name + "_H")) {
814  erf_checkpoint::read_checkpoint_multifab(*m_q_deep[lev], qdeep_name, 0, 0, 1,
815  m_q_deep[lev]->nGrowVect(), true, period);
816  } else if (m_q_deep[lev] && lev == 0) {
817  amrex::Print() << "NOTE: the checkpoint has no TwoStream_QDeep: "
818  "erf.radiation.seb_init_soil_moisture_from_file is not used on "
819  "this restart and the deep moisture is "
820  "erf.radiation.seb_q_deep_default = "
821  << m_rad->seb_q_deep_default << " in every column\n";
822  }
823  } else if (!seb_q_deep_is_state() && lev == 0 && amrex::FileExists(qdeep_name + "_H")) {
824  amrex::Print() << "NOTE: the checkpoint holds TwoStream_QDeep, which is not read: "
825  "neither erf.radiation.seb_deep_prognostic_enable nor "
826  "erf.radiation.seb_init_soil_moisture_from_file is set, and the "
827  "deep moisture is erf.radiation.seb_q_deep_default in every column\n";
828  }
829  m_hydro.read_checkpoint(lev, restart_chkfile, period);
830  m_snow.read_checkpoint(lev, restart_chkfile, period);
831 }
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
void read_checkpoint(int lev, const std::string &restart_chkfile, const amrex::Periodicity &period)
Definition: ERF_ForceRestoreHydrologyState.cpp:158
void read_checkpoint(int lev, const std::string &restart_chkfile, const amrex::Periodicity &period)
Read W_n and the totals. A checkpoint with neither file was written without the snow layer: the snow ...
Definition: ERF_ForceRestoreSnowState.cpp:185
void read_checkpoint_multifab(amrex::MultiFab &dst, const std::string &mf_name, int scomp, int dcomp, int ncomp, const amrex::IntVect &dst_ghosts, bool src_ghosts, const amrex::Periodicity &period)
Definition: ERF_ReadCheckpointMF.H:92
bool seb_init_t_deep_from_file
At a fresh start, the deep (restoring) temperature T_deep of a land column is the deep soil temperatu...
Definition: ERF_RadStruct.H:494
bool seb_deep_prognostic_enable
Make seb_q_deep and seb_t_deep prognostic (ERF_ForceRestoreHydrology.H): q_deep becomes the mean wate...
Definition: ERF_RadStruct.H:746
Here is the call graph for this function:

◆ resize()

void TwoStreamRadiation::resize ( int  nlevs_max)

Size the per-level containers; no allocation happens here.

236 {
237  m_alb_sw.resize(nlevs_max);
238  m_emiss_lw.resize(nlevs_max);
239  m_t_sfc.resize(nlevs_max);
240  m_sw_flux_sfc.resize(nlevs_max);
241  m_lw_flux_sfc.resize(nlevs_max);
242  m_hfx_sfc.resize(nlevs_max);
243  m_lh_sfc.resize(nlevs_max);
244  m_grdflx_sfc.resize(nlevs_max);
245  m_sw_dn_sfc.resize(nlevs_max);
246  m_lw_dn_sfc.resize(nlevs_max);
247  m_cos_zenith.resize(nlevs_max);
248  m_q_sfc.resize(nlevs_max);
249  m_t_deep.resize(nlevs_max);
250  m_q_deep.resize(nlevs_max);
251  m_moisture.resize(nlevs_max);
252  m_canopy.resize(nlevs_max);
253  m_canopy_cosz.resize(nlevs_max);
254  m_canopy_alb.resize(nlevs_max);
255  m_canopy_m.resize(nlevs_max, -1);
256  m_canopy_step.resize(nlevs_max, -1);
257  m_solid.resize(nlevs_max);
258  m_footprint.resize(nlevs_max);
259  m_ground_shadow.resize(nlevs_max);
260  m_sw_beam_sfc.resize(nlevs_max);
261  m_shadow_step.resize(nlevs_max, -1);
262  m_ground_walls.resize(nlevs_max);
263  m_ground_keep.resize(nlevs_max);
264  m_walls_step.resize(nlevs_max, -1);
265  m_roof_k.resize(nlevs_max);
266  m_roof.resize(nlevs_max);
267  m_roof_step.resize(nlevs_max, -1);
268  m_sweep_step.resize(nlevs_max, -1);
269  m_shaded_step.resize(nlevs_max, -1);
270  m_has_cover.resize(nlevs_max, 0);
271  m_seb_updated.resize(nlevs_max, 0);
272  m_water_message.resize(nlevs_max, -1);
273  m_flux_diag.resize(nlevs_max);
274  m_diag.resize(nlevs_max);
275  m_precip.resize(nlevs_max);
276  m_hydro.resize(nlevs_max);
277  m_snow.resize(nlevs_max);
278 }
void resize(int nlevs_max)
Definition: ERF_ForceRestoreHydrologyState.cpp:39
void resize(int nlevs_max)
Definition: ERF_ForceRestorePrecipRate.cpp:12
void resize(int nlevs_max)
Definition: ERF_ForceRestoreSnowState.cpp:33

Referenced by ERF::ERF_shared().

Here is the caller graph for this function:

◆ roof_cell()

const amrex::iMultiFab* TwoStreamRadiation::roof_cell ( int  lev) const
inlinenoexcept

For each column of lev, the first cell above the building that stands on its ground (the cell on the roof), or the bottom cell on open ground (2D: i,j); nullptr unless starts_on_roofs(). A cell above the level's top means the building fills the column. Solid cells above an air gap (an overhang) are not a roof here: under an overhang above open ground the cell is the bottom cell, and under an overhang above a lower roof it is the cell on that lower roof.

466  {
467  return starts_on_roofs(lev) ? m_roof_k[lev].get() : nullptr;
468  }
Here is the call graph for this function:

◆ roofs_for_step()

MultiFab * TwoStreamRadiation::roofs_for_step ( int  lev,
int  nstep 
)

The field the immersed-boundary balance fills, before the sweep of step nstep, with the roof face of each column under a building (2D: i,j; ROOF_SET 1 where a roof face stands on roof_cell(), then its albedo, emissivity, skin temperature and the share of the beam that reaches it), or nullptr unless starts_on_roofs(). Marks the field as that step's: the sweep stops unless the roofs are of its own step. Where ROOF_SET is 0 the column keeps the ground as its lower boundary.

546 {
547  if (!has_building_cover(lev) || !starts_on_roofs(lev)) { return nullptr; }
548  m_roof_step[lev] = nstep;
549  return m_roof[lev].get();
550 }

◆ roofs_given()

bool TwoStreamRadiation::roofs_given ( int  lev) const
inlinenoexcept

True once roofs_for_step() has been called for lev since its building cover was set.

482  {
483  return starts_on_roofs(lev) && m_roof_step[lev] >= 0;
484  }
Here is the call graph for this function:

◆ seb_hfx()

const amrex::MultiFab* TwoStreamRadiation::seb_hfx ( int  lev) const
inline

The sensible and latent heat fluxes [W/m^2] the surface energy balance of one level last used, or nullptr when the SEB is off or the level has not been built. Read-only: for output.

205  {
206  return (active() && m_rad->seb_enable && lev < m_hfx_sfc.size()) ? m_hfx_sfc[lev].get() : nullptr;
207  }
Here is the call graph for this function:

◆ seb_lh()

const amrex::MultiFab* TwoStreamRadiation::seb_lh ( int  lev) const
inline
208  {
209  return (active() && m_rad->seb_enable && lev < m_lh_sfc.size()) ? m_lh_sfc[lev].get() : nullptr;
210  }
Here is the call graph for this function:

◆ seb_lw_net()

const amrex::MultiFab* TwoStreamRadiation::seb_lw_net ( int  lev) const
inline

The net longwave [W/m^2] the ground balance of lev used at its last update after the dycore (with the walls' longwave of erf.ibseb.ground_sky_view); nullptr as for seb_sw_net(). Read-only: for output.

532  {
533  return (active() && m_rad->seb_enable && lev < static_cast<int>(m_lw_flux_sfc.size()) && m_seb_updated[lev] != 0)
534  ? m_lw_flux_sfc[lev].get() : nullptr;
535  }
Here is the call graph for this function:

◆ seb_prognostic_active()

bool TwoStreamRadiation::seb_prognostic_active ( ) const
inline

True when the force-restore state is being evolved and so needs transferring.

338  {
340  }

Referenced by seb_q_sfc_state().

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

◆ seb_prognostic_fields()

Vector< MultiFab * > TwoStreamRadiation::seb_prognostic_fields ( int  lev)

Every field of the force-restore state of lev that evolves and so must survive a regrid, be filled from the coarse level on a new level and be averaged down: t_sfc and q_sfc; with erf.radiation.seb_deep_prognostic_enable, t_deep and q_deep; with erf.radiation.seb_init_t_deep_from_file, t_deep (it does not evolve then, but it differs from column to column); with the hydrology, its running totals (several components); with the snow layer, its water equivalent and totals. Empty when the state is not evolved. Each is a 2D field (k = 0) on the level's horizontal grids.

835 {
836  Vector<MultiFab*> out;
837  if (!seb_prognostic_active() || lev >= static_cast<int>(m_t_sfc.size())) { return out; }
838  out.push_back(m_t_sfc[lev].get());
839  out.push_back(m_q_sfc[lev].get());
840  // The deep temperature is carried when it evolves and when it was set per column from
841  // the initial file (seb_t_deep_is_state); so is the deep moisture (seb_q_deep_is_state).
842  if (seb_t_deep_is_state()) { out.push_back(m_t_deep[lev].get()); }
843  if (seb_q_deep_is_state()) { out.push_back(m_q_deep[lev].get()); }
844  if (m_hydro.totals(lev)) { out.push_back(m_hydro.totals(lev)); }
845  if (m_snow.defined(lev)) {
846  out.push_back(m_snow.swe(lev));
847  out.push_back(m_snow.totals(lev));
848  }
849  return out;
850 }
amrex::MultiFab * totals(int lev) noexcept
The running totals (Total components) [kg/m^2], or nullptr.
Definition: ERF_ForceRestoreSnowState.H:106
Here is the call graph for this function:

◆ seb_q_deep()

const amrex::MultiFab* TwoStreamRadiation::seb_q_deep ( int  lev) const
inline
321  {
322  return (active() && m_rad->seb_enable && lev < static_cast<int>(m_q_deep.size())) ? m_q_deep[lev].get() : nullptr;
323  }
Here is the call graph for this function:

◆ seb_q_deep_is_state()

bool TwoStreamRadiation::seb_q_deep_is_state ( ) const
inline

True when the deep water content is part of the state: it evolves (erf.radiation.seb_deep_prognostic_enable) or it was set per column from the initial file (erf.radiation.seb_init_soil_moisture_from_file). It is then not reset to erf.radiation.seb_q_deep_default at a radiation step, it is one of seb_prognostic_fields and it is written to the checkpoint and read back.

291  {
292  return active() && m_rad->seb_enable &&
295  }
bool seb_init_soil_moisture_from_file
At a fresh start, the soil water of a land column is the soil moisture profile of the wrfinput file (...
Definition: ERF_RadStruct.H:511

Referenced by seb_q_deep_state().

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

◆ seb_q_deep_state()

amrex::MultiFab* TwoStreamRadiation::seb_q_deep_state ( int  lev)
inline

The deep water content [m^3/m^3] of lev for ERF::init_seb_soil_moisture_from_file to write, or nullptr when it is not part of the state (seb_q_deep_is_state) or the level has not been built.

312  {
313  return (seb_q_deep_is_state() && lev >= 0 && lev < static_cast<int>(m_q_deep.size()))
314  ? m_q_deep[lev].get() : nullptr;
315  }
Here is the call graph for this function:

◆ seb_q_sfc()

amrex::MultiFab* TwoStreamRadiation::seb_q_sfc ( int  lev)
inline
196  {
197  return (active() && m_rad->seb_enable && lev < m_q_sfc.size()) ? m_q_sfc[lev].get() : nullptr;
198  }
Here is the call graph for this function:

◆ seb_q_sfc_state()

amrex::MultiFab* TwoStreamRadiation::seb_q_sfc_state ( int  lev)
inline

The surface water content q_s [m^3/m^3] of lev for ERF::init_seb_soil_moisture_from_file to write, or nullptr when the prognostic balance does not run or the level has not been built.

302  {
303  return (seb_prognostic_active() && lev >= 0 && lev < static_cast<int>(m_q_sfc.size()))
304  ? m_q_sfc[lev].get() : nullptr;
305  }
Here is the call graph for this function:

◆ seb_surface_moisture()

const MultiFab * TwoStreamRadiation::seb_surface_moisture ( int  lev)

What level lev's surface hands the surface layer for its surface mixing ratio (erf.radiation.seb_surface_layer_uses_moisture), per column, in the components of erf_surface_moisture::Component: the soil-water factor (seb_moisture_availability of the current q_s); with erf.radiation.seb_soil_type, the bare-soil resistance and the relative humidity of its pore air at the skin temperature; and with erf.radiation.seb_vegetation_type as well, the vegetated fraction and the canopy resistance without its vapor-deficit factor (from the net shortwave the balance holds divided by (1 - surface albedo) – the sweep's with seb_use_radiation_fluxes, seb_sw_flux_default otherwise – and the skin temperature). Absent pieces are a fraction of 0 and resistances of 1e6 s/m. nullptr when the option is off or the level has not been built. Recomputed on every call, on the valid cells; the halo is not filled.

607 {
609  lev >= static_cast<int>(m_moisture.size()) || !m_moisture[lev] || !m_q_sfc[lev]) {
610  return nullptr;
611  }
612  using namespace erf_surface_moisture;
613  const Real q_wilt = m_rad->seb_soil_moisture_wilt;
614  const Real q_fc = m_rad->seb_soil_moisture_fc;
615 
616  // With a soil type: the soil's parameters for the bare-soil resistance of the top
617  // seb_moisture_layer_depth_m, vegetation or not. With a vegetation type as well (which
618  // needs a soil type): Noah-MP's canopy parameters. RadChoice::init_params checked both
619  // categories.
622  const NoahMPSoilParams* soil = (m_rad->seb_soil_type != 0)
623  ? noahmp_soil_params(m_rad->seb_soil_type) : nullptr;
624  const bool has_soil = (soil != nullptr);
625  const bool vegetated = (veg != nullptr && has_soil);
626  const Real f_veg = vegetated ? m_rad->seb_vegetation_fraction : Real(0.0);
627  const Real lai = m_rad->seb_leaf_area_index;
628  const Real rs_min = vegetated ? veg->rs_min : Real(0.0);
629  const Real rs_max = vegetated ? veg->rs_max : Real(0.0);
630  const Real rgl = vegetated ? veg->rgl : Real(0.0);
631  const Real t_opt = vegetated ? veg->t_opt : Real(0.0);
632  const Real smc_max = has_soil ? soil->smc_max : Real(0.0);
633  const Real bb = has_soil ? soil->bb : Real(0.0);
634  const Real psi_sat = has_soil ? soil->psi_sat : Real(0.0);
635  const Real d1 = m_rad->seb_moisture_layer_depth_m;
636  const Real resistance_exponent = noahmp_soil_resistance_exponent;
637 
638  MultiFab& out = *m_moisture[lev];
639  const MultiFab& q_s = *m_q_sfc[lev];
640  const MultiFab& t_s = *m_t_sfc[lev];
641  // The shortwave down at the surface, from the net the balance holds and the albedo.
642  const MultiFab* sw_net = m_sw_flux_sfc[lev].get();
643  const MultiFab* albedo = m_alb_sw[lev].get();
644 #ifdef _OPENMP
645 #pragma omp parallel if (Gpu::notInLaunchRegion())
646 #endif
647  for (MFIter mfi(out, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
648  const Box& bx = mfi.tilebox();
649  const auto out_arr = out.array(mfi);
650  const auto q_arr = q_s.const_array(mfi);
651  const auto t_arr = t_s.const_array(mfi);
652  const auto sw_arr = (vegetated && sw_net) ? sw_net->const_array(mfi) : Array4<const Real>{};
653  const auto alb_arr = (vegetated && albedo) ? albedo->const_array(mfi) : Array4<const Real>{};
654  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
655  {
656  const Real soil_factor = seb_moisture_availability(q_arr(i, j, k), q_wilt, q_fc);
657  out_arr(i, j, k, SoilFactor) = soil_factor;
658  out_arr(i, j, k, VegetationFraction) = f_veg;
659  Real r_c = no_flux_resistance;
660  Real r_soil = no_flux_resistance;
661  if (vegetated) {
662  const Real a = (alb_arr) ? alb_arr(i, j, k) : Real(0.0);
663  const Real sw_down = (sw_arr && a < Real(1.0)) ? sw_arr(i, j, k) / (Real(1.0) - a) : Real(0.0);
664  r_c = seb_canopy_resistance_without_vpd(rs_min, rs_max, rgl, t_opt, lai, sw_down,
665  t_arr(i, j, k), soil_factor);
666  }
667  Real rh_ground = Real(1.0);
668  if (has_soil) {
669  r_soil = seb_soil_evaporation_resistance(q_arr(i, j, k), smc_max, q_wilt, bb, d1,
670  resistance_exponent);
671  rh_ground = seb_soil_surface_relative_humidity(q_arr(i, j, k), smc_max, psi_sat,
672  bb, t_arr(i, j, k));
673  }
674  out_arr(i, j, k, CanopyResistanceWithoutVPD) = r_c;
675  out_arr(i, j, k, SoilResistance) = r_soil;
676  out_arr(i, j, k, GroundRelativeHumidity) = rh_ground;
677  });
678  }
679  return m_moisture[lev].get();
680 }
Real r_c
Definition: ERF_InitCustomPert_SquallLine.H:53
constexpr amrex::Real noahmp_soil_resistance_exponent
Definition: ERF_NoahMPSoilTable.H:39
const NoahMPVegetationParams * noahmp_vegetation_params(int category) noexcept
The parameters of MODIS land-use category category (1-20), as Noah-MP reads them.
Definition: ERF_NoahMPVegetationTable.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real seb_soil_evaporation_resistance(amrex::Real theta, amrex::Real theta_sat, amrex::Real theta_wilt, amrex::Real b, amrex::Real d1, amrex::Real p)
Resistance of bare soil to evaporation [s/m], Noah-MP's ground-evaporation option 1 (Sakaguchi and Ze...
Definition: ERF_SimplifiedSEB.H:288
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real seb_moisture_availability(amrex::Real q_s, amrex::Real q_wilt, amrex::Real q_fc)
Moisture availability beta of the force-restore surface, from its water content.
Definition: ERF_SimplifiedSEB.H:218
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real seb_soil_surface_relative_humidity(amrex::Real theta, amrex::Real theta_sat, amrex::Real psi_sat, amrex::Real b, amrex::Real t_ground)
Relative humidity of the air in the top soil's pores, Noah-MP's for bare ground (ResistanceGroundEvap...
Definition: ERF_SimplifiedSEB.H:318
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real seb_canopy_resistance_without_vpd(amrex::Real rs_min, amrex::Real rs_max, amrex::Real rgl, amrex::Real t_opt, amrex::Real lai, amrex::Real sw_down, amrex::Real t_canopy, amrex::Real soil_factor)
Canopy resistance to transpiration [s/m] without its vapor-deficit factor.
Definition: ERF_SimplifiedSEB.H:254
@ lai
Definition: ERF_SLM.H:78
Definition: ERF_SurfaceMoisture.H:21
constexpr amrex::Real no_flux_resistance
Definition: ERF_SurfaceMoisture.H:79
@ GroundRelativeHumidity
Definition: ERF_SurfaceMoisture.H:36
@ SoilResistance
Definition: ERF_SurfaceMoisture.H:35
@ VegetationFraction
Definition: ERF_SurfaceMoisture.H:33
@ CanopyResistanceWithoutVPD
Definition: ERF_SurfaceMoisture.H:34
@ SoilFactor
Definition: ERF_SurfaceMoisture.H:32
Definition: ERF_NoahMPSoilTable.H:20
amrex::Real bb
BB Clapp-Hornberger b [1].
Definition: ERF_NoahMPSoilTable.H:21
amrex::Real psi_sat
SATPSI saturated matric potential [m].
Definition: ERF_NoahMPSoilTable.H:25
Definition: ERF_NoahMPVegetationTable.H:23
amrex::Real t_opt
TOPT optimum transpiration air temperature [K].
Definition: ERF_NoahMPVegetationTable.H:27
amrex::Real rs_min
RS minimum stomatal resistance [s/m].
Definition: ERF_NoahMPVegetationTable.H:24
amrex::Real rgl
RGL radiation stress parameter [W/m^2].
Definition: ERF_NoahMPVegetationTable.H:25
amrex::Real rs_max
RSMAX maximum stomatal resistance [s/m].
Definition: ERF_NoahMPVegetationTable.H:28
int seb_vegetation_type
Noah-MP land-use category (modified IGBP MODIS, 1-20 except the unvegetated 15, 16 and 17,...
Definition: ERF_RadStruct.H:569
amrex::Real seb_soil_moisture_wilt
Wilting point [m^3/m^3]: at or below it the soil-water factor is 0, so the vegetation does not transp...
Definition: ERF_RadStruct.H:537
amrex::Real seb_leaf_area_index
Leaf area index [m^2/m^2] of the vegetated fraction (seb_vegetation_type; giving it otherwise stops a...
Definition: ERF_RadStruct.H:584
int seb_soil_type
Noah-MP soil category (STAS, 1-19, not 14 (water), as in NoahmpTable.TBL; see ERF_NoahMPSoilTable....
Definition: ERF_RadStruct.H:557
amrex::Real seb_soil_moisture_fc
Field capacity [m^3/m^3]: at or above it the soil-water factor is 1, so without seb_soil_type the sur...
Definition: ERF_RadStruct.H:545
amrex::Real seb_vegetation_fraction
Vegetated fraction of the surface [0, 1] (seb_vegetation_type; giving it otherwise stops at start-up)...
Definition: ERF_RadStruct.H:575
Here is the call graph for this function:

◆ seb_sw_net()

const amrex::MultiFab* TwoStreamRadiation::seb_sw_net ( int  lev) const
inline

The net shortwave [W/m^2] the ground balance of lev used at its last update after the dycore, with the building cover's footprints and shadow applied; nullptr when the SEB is off, before the level's first such update after a sweep (the initial plotfile, the one a restart writes), or on a level that does not sweep. Read-only: for output.

556  {
557  return (active() && m_rad->seb_enable && lev < static_cast<int>(m_sw_flux_sfc.size()) && m_seb_updated[lev] != 0)
558  ? m_sw_flux_sfc[lev].get() : nullptr;
559  }
Here is the call graph for this function:

◆ seb_t_deep()

const amrex::MultiFab* TwoStreamRadiation::seb_t_deep ( int  lev) const
inline

The deep temperature [K] and column water content of lev, or nullptr. Read-only: for output.

318  {
319  return (active() && m_rad->seb_enable && lev < static_cast<int>(m_t_deep.size())) ? m_t_deep[lev].get() : nullptr;
320  }
Here is the call graph for this function:

◆ seb_t_deep_is_state()

bool TwoStreamRadiation::seb_t_deep_is_state ( ) const
inline

True when the deep temperature is part of the state: it evolves (erf.radiation.seb_deep_prognostic_enable) or it was set per column from the initial file (erf.radiation.seb_init_t_deep_from_file). It is then not reset to erf.radiation.seb_t_deep_default at a radiation step, it is one of seb_prognostic_fields and it is written to the checkpoint and read back.

268  {
269  return active() && m_rad->seb_enable &&
272  }

Referenced by seb_t_deep_state().

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

◆ seb_t_deep_state()

amrex::MultiFab* TwoStreamRadiation::seb_t_deep_state ( int  lev)
inline

The deep temperature [K] of lev for ERF::init_seb_t_deep_from_file to write, or nullptr when it is not part of the state (seb_t_deep_is_state) or the level has not been built.

279  {
280  return (seb_t_deep_is_state() && lev >= 0 && lev < static_cast<int>(m_t_deep.size()))
281  ? m_t_deep[lev].get() : nullptr;
282  }
Here is the call graph for this function:

◆ seb_t_sfc()

amrex::MultiFab* TwoStreamRadiation::seb_t_sfc ( int  lev)
inline

The prognostic surface state of one level, or nullptr when the SEB is off or the level has not been built.

Exposed so ERF can average t_sfc and q_sfc down after the finer levels have advanced. Every level evolves its own copy, and without that transfer the two estimates of one surface drift apart – which would give the longwave boundary condition two different values for the same ground. ERF owns refRatio and the level geometries; this class does not, and should not grow them for one call.

193  {
194  return (active() && m_rad->seb_enable && lev < m_t_sfc.size()) ? m_t_sfc[lev].get() : nullptr;
195  }
Here is the call graph for this function:

◆ set_building_cover()

void TwoStreamRadiation::set_building_cover ( int  lev,
const amrex::MultiFab &  blanking,
const amrex::Box &  domain,
bool  take_ground_walls = false,
bool  start_on_roofs = false 
)

Have the columns of lev see the buildings of the immersed-boundary balance (erf.ibseb.two_stream_buildings). From now on, on this level:

  • the sweep writes no heating rate in a solid cell (blanking at or above 0.5): the light a building's cells would absorb is the roof's and the walls', which the balance takes at their own heights;
  • the ground balance (seb_enable) leaves a column whose bottom cell is solid, a building's footprint, alone: its state is held, it absorbs no shortwave and it is left out of the balance's means;
  • with the shortwave from the sweep (seb_use_radiation_fluxes, shortwave on) on a level that sweeps its own columns, the open ground loses the direct beam where the field of ground_shadow_for_step() says a building shades it, at the update after the dycore. Copies what it needs from blanking (the solid cells up to the tallest building, 4 bytes a cell, and the footprints), so the field may change or go afterwards. Call after define_level(); a later define_level() of the level drops it.
Parameters
levlevel, which must have been defined
blankingthe level's cell-centered blanking (ERF::terrain_blanking), on the state's grids: 0 in the air, 1 inside a building
domainthe level's domain Box; its bottom cell is the ground's
take_ground_wallsalso take, at the update after the dycore, what the walls send to the open ground (erf.ibseb.ground_sky_view, the field of ground_walls_for_step()): only where the ground takes the shadow and the longwave is on (takes_ground_walls())
430 {
432  "TwoStreamRadiation::set_building_cover: erf.radiation_model is not TwoStream");
433  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(lev >= 0 && lev < static_cast<int>(m_alb_sw.size()) && m_alb_sw[lev],
434  "TwoStreamRadiation::set_building_cover: level " + std::to_string(lev) + " has not been defined");
435  // The sweep and the 2D fields go by the local index of the state's boxes, so the
436  // blanking must be on the state's grids: the 2D boxes flattened from its own.
437  BoxList flat = blanking.boxArray().boxList();
438  for (Box& b : flat) { b.setRange(2, 0); }
439  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(BoxArray(std::move(flat)) == m_alb_sw[lev]->boxArray() &&
440  blanking.DistributionMap() == m_alb_sw[lev]->DistributionMap(),
441  "TwoStreamRadiation::set_building_cover: the blanking is not on the level's grids");
442  const BoxArray& ba2d = m_alb_sw[lev]->boxArray();
443  const DistributionMapping& dm = m_alb_sw[lev]->DistributionMap();
444  const int k0 = domain.smallEnd(2);
445  // The solid cells are kept only up to the highest one of the level (the tallest
446  // building), as the faces' beam is kept only up to the highest face: 4 bytes per cell
447  // of that height, not of the whole column.
448  int k_solid = k0 - 1;
449  {
450  ReduceOps<ReduceOpMax> reduce_op;
451  ReduceData<int> reduce_data(reduce_op);
452  for (MFIter mfi(blanking); mfi.isValid(); ++mfi) {
453  const auto blank = blanking.const_array(mfi);
454  reduce_op.eval(mfi.validbox(), reduce_data, [=] AMREX_GPU_DEVICE (int i, int j, int k) -> GpuTuple<int> {
455  return {(blank(i, j, k) >= Real(0.5)) ? k : std::numeric_limits<int>::lowest()};
456  });
457  }
458  k_solid = amrex::max(k_solid, amrex::get<0>(reduce_data.value(reduce_op)));
459  ParallelDescriptor::ReduceIntMax(k_solid);
460  }
461  BoxList solid_boxes = blanking.boxArray().boxList();
462  for (Box& b : solid_boxes) {
463  // A box wholly above the buildings keeps its bottom layer, all air.
464  const int hi = amrex::max(b.smallEnd(2), amrex::min(b.bigEnd(2), k_solid));
465  b.setBig(2, hi);
466  }
467  m_solid[lev] = std::make_unique<iMultiFab>(BoxArray(std::move(solid_boxes)), dm, 1, 0);
468  m_footprint[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, 0);
469  for (MFIter mfi(blanking); mfi.isValid(); ++mfi) {
470  const Box& bx = mfi.validbox();
471  const auto blank = blanking.const_array(mfi);
472  const auto solid = m_solid[lev]->array(mfi);
473  const auto foot = m_footprint[lev]->array(mfi);
474  ParallelFor((*m_solid[lev])[mfi].box(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
475  solid(i, j, k) = (blank(i, j, k) >= Real(0.5)) ? 1 : 0;
476  });
477  // A box that does not reach the ground (a level whose radiation comes from its
478  // parent) has no ground balance, and no footprint.
479  if (bx.smallEnd(2) == k0) {
480  ParallelFor(makeSlab(bx, 2, 0), [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept {
481  foot(i, j, 0) = (blank(i, j, k0) >= Real(0.5)) ? Real(1.0) : Real(0.0);
482  });
483  } else {
484  ParallelFor(makeSlab(bx, 2, 0), [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept {
485  foot(i, j, 0) = Real(0.0);
486  });
487  }
488  }
489  m_has_cover[lev] = 1;
490  // The shadow, and the beam it takes off, only where the ground balance will take them:
491  // a balance on the sweep's shortwave, with the shortwave on, on a level that sweeps its
492  // own columns (one whose rates come from its parent has no balance).
493  bool sweeps = true;
494  for (int ibox = 0; ibox < blanking.boxArray().size(); ++ibox) {
495  const Box& b = blanking.boxArray()[ibox];
496  sweeps = sweeps && b.smallEnd(2) == k0 && b.bigEnd(2) == domain.bigEnd(2);
497  }
499  m_ground_shadow[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, 0);
500  m_sw_beam_sfc[lev] = std::make_unique<MultiFab>(ba2d, dm, 1, 0);
501  m_ground_shadow[lev]->setVal(0.0);
502  m_sw_beam_sfc[lev]->setVal(0.0);
503  } else {
504  m_ground_shadow[lev].reset();
505  m_sw_beam_sfc[lev].reset();
506  }
507  // What the walls send to the ground, only where the ground takes the shadow and the
508  // longwave is on: the shortwave and the longwave terms are taken together or not at all.
509  m_ground_walls[lev].reset();
510  m_ground_keep[lev].reset();
511  if (take_ground_walls && m_ground_shadow[lev] && m_rad->lw_enabled) {
512  m_ground_walls[lev] = std::make_unique<MultiFab>(ba2d, dm, 3, 0);
513  m_ground_keep[lev] = std::make_unique<MultiFab>(ba2d, dm, 3, 0);
514  m_ground_walls[lev]->setVal(0.0);
515  m_ground_keep[lev]->setVal(0.0);
516  }
517  m_walls_step[lev] = -1;
518  // The cell on each column's roof, on a level that sweeps its own columns: the first
519  // cell above the solid cells that stand on the ground (the bottom cell on open
520  // ground; one above the kept solid cells where they are solid to their top).
521  m_roof_k[lev].reset();
522  m_roof[lev].reset();
523  if (start_on_roofs && sweeps) {
524  m_roof_k[lev] = std::make_unique<iMultiFab>(ba2d, dm, 1, 0);
525  m_roof[lev] = std::make_unique<MultiFab>(ba2d, dm, ROOF_NCOMP, 0);
526  m_roof[lev]->setVal(0.0);
527  for (MFIter mfi(*m_roof_k[lev]); mfi.isValid(); ++mfi) {
528  const auto solid = m_solid[lev]->const_array(mfi);
529  const auto roof_k = m_roof_k[lev]->array(mfi);
530  const int k_hi = (*m_solid[lev])[mfi].box().bigEnd(2);
531  ParallelFor(makeSlab(mfi.validbox(), 2, 0), [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept {
532  int k = k0;
533  while (k <= k_hi && solid(i, j, k) != 0) { ++k; }
534  roof_k(i, j, 0) = k;
535  });
536  }
537  Gpu::streamSynchronize();
538  }
539  m_roof_step[lev] = -1;
540  m_shadow_step[lev] = -1;
541  m_shaded_step[lev] = -1;
542 }
bool lw_enabled
Enable longwave (thermal) radiation computation. Only used by the two-stream model.
Definition: ERF_RadStruct.H:160
Here is the call graph for this function:

◆ snow_swe()

const amrex::MultiFab* TwoStreamRadiation::snow_swe ( int  lev)
inline

The snow water equivalent [kg/m^2] and the snow layer's running totals (ForceRestoreSnow::Total components) [kg/m^2]; nullptr without erf.radiation.seb_snow_enable. Read-only: for output.

334 { return m_snow.swe(lev); }
Here is the call graph for this function:

◆ snow_totals()

const amrex::MultiFab* TwoStreamRadiation::snow_totals ( int  lev)
inline
335 { return m_snow.totals(lev); }
Here is the call graph for this function:

◆ starts_on_roofs()

bool TwoStreamRadiation::starts_on_roofs ( int  lev) const
inlinenoexcept

True when the columns of lev under a building start on its roof (erf.ibseb.two_stream_roofs; set_building_cover() with start_on_roofs, on a level that sweeps its own columns): the one condition for the fields and for the sweep.

454  {
455  return lev >= 0 && lev < static_cast<int>(m_roof.size()) && m_roof[lev] != nullptr;
456  }

Referenced by roof_cell(), and roofs_given().

Here is the caller graph for this function:

◆ supplies_canopy_forcing()

bool TwoStreamRadiation::supplies_canopy_forcing ( int  lev) const
inlinenoexcept

True when supply_canopy_forcing() was called for lev since its last define_level().

396  {
397  return lev >= 0 && lev < static_cast<int>(m_canopy.size()) && m_canopy[lev] != nullptr;
398  }

Referenced by canopy_forcing().

Here is the caller graph for this function:

◆ supplies_land_forcing()

bool TwoStreamRadiation::supplies_land_forcing ( int  lev) const
inlinenoexcept

True when define_level allocated the land-model forcing fields on lev.

343  {
344  return lev >= 0 && lev < static_cast<int>(m_sw_dn_sfc.size()) && m_sw_dn_sfc[lev] != nullptr;
345  }

Referenced by land_forcing_cos_zenith(), land_forcing_lw_dn(), and land_forcing_sw_dn().

Here is the caller graph for this function:

◆ supply_canopy_forcing()

void TwoStreamRadiation::supply_canopy_forcing ( int  lev,
int  m_top,
bool  ground_albedo = false 
)

Have every later sweep on lev write what the building faces need besides the interface fluxes (erf.ibseb.radiation = two_stream; ERF_TwoStreamCanopyForcing.H): the direct beam on a horizontal surface at the interfaces 0 .. m_top of each column, counted from the surface, and the cosine of the zenith. Allocates one field on the level's horizontal grids given those interfaces in z and one 2D field. Call after define_level(); a later define_level() of the level (a regrid) drops the request.

Parameters
levlevel, which must have been defined; its sweep asserts that the columns reach m_top
m_tophighest interface the faces read (IBFaceSet::top_sample_interface()), in [0, number of cells in z]
ground_albedoalso keep the direct-beam albedo the sweep gives each column's ground (one more 2D field, TwoStreamCanopyView::ground_albedo_dir), for the faces of erf.ibseb.ground_view_shadow; without it that pointer is null
398 {
400  "TwoStreamRadiation::supply_canopy_forcing: erf.radiation_model is not TwoStream");
401  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(lev >= 0 && lev < static_cast<int>(m_alb_sw.size()) && m_alb_sw[lev],
402  "TwoStreamRadiation::supply_canopy_forcing: level " + std::to_string(lev) + " has not been defined");
404  "TwoStreamRadiation::supply_canopy_forcing: the top of the canopy must be at or above the surface");
405  // The level's grids flattened (the 2D fields' boxes, on their distribution), given the
406  // interfaces 0 .. m_top in z; the sweep asserts that the column reaches m_top.
407  BoxList canopy_boxes = m_alb_sw[lev]->boxArray().boxList();
408  for (Box& b : canopy_boxes) { b.setRange(2, 0, m_top + 1); }
409  // The beam alone: the diffuse light, the longwave and the ground's fluxes are the
410  // sweep's interface fluxes, which ERF keeps (rad_fluxes); only the beam and the
411  // cosine of the zenith are lost after the sweep.
412  m_canopy[lev] = std::make_unique<MultiFab>(BoxArray(std::move(canopy_boxes)), m_alb_sw[lev]->DistributionMap(), 1, 0);
413  m_canopy_cosz[lev] = std::make_unique<MultiFab>(m_alb_sw[lev]->boxArray(), m_alb_sw[lev]->DistributionMap(), 1, 0);
414  // The ground's direct-beam albedo only for the faces that read it (erf.ibseb.ground_view_shadow).
415  m_canopy_alb[lev].reset();
416  if (ground_albedo) {
417  m_canopy_alb[lev] = std::make_unique<MultiFab>(m_alb_sw[lev]->boxArray(), m_alb_sw[lev]->DistributionMap(), 2, 0);
418  m_canopy_alb[lev]->setVal(0.0);
419  }
420  // Never read before a sweep has written them: canopy_forcing() returns null until then.
421  m_canopy[lev]->setVal(0.0);
422  m_canopy_cosz[lev]->setVal(0.0);
423  m_canopy_m[lev] = m_top;
424  m_canopy_step[lev] = -1;
425 }
Here is the call graph for this function:

◆ takes_ground_walls()

bool TwoStreamRadiation::takes_ground_walls ( int  lev) const
inlinenoexcept

True when the ground balance of lev takes what the walls send it (see set_building_cover()): the one condition for the field, what the sweep keeps for it, and the shortwave and longwave terms.

487  {
488  return lev >= 0 && lev < static_cast<int>(m_ground_walls.size()) && m_ground_walls[lev] != nullptr;
489  }

◆ write_checkpoint()

void TwoStreamRadiation::write_checkpoint ( int  lev,
const std::string &  checkpointname 
) const

Write the prognostic surface state of one level (SEB on).

698 {
699  // The force-restore state is the only part of this model a restart must
700  // carry; without it T_s and q_s restart from the scalar defaults.
701  //
702  // Every level: each one evolves its own force-restore state now, so each has
703  // state worth restoring. A coarse level's values where a finer level covers it
704  // are the average of that finer level's, restored on both sides.
705  if (!active() || !m_rad->seb_enable) { return; }
706  if (m_t_sfc[lev]) {
707  VisMF::Write(*m_t_sfc[lev],
708  MultiFabFileFullPrefix(lev, checkpointname, "Level_", "TwoStream_TSfc"));
709  }
710  if (m_q_sfc[lev]) {
711  VisMF::Write(*m_q_sfc[lev],
712  MultiFabFileFullPrefix(lev, checkpointname, "Level_", "TwoStream_QSfc"));
713  }
714  // The deep state evolves only with erf.radiation.seb_deep_prognostic_enable. The deep
715  // temperature is also written when erf.radiation.seb_init_t_deep_from_file set it per
716  // column, and the deep moisture when erf.radiation.seb_init_soil_moisture_from_file
717  // did: the restart does not read the initial file again.
718  if (seb_t_deep_is_state() && m_t_deep[lev]) {
719  VisMF::Write(*m_t_deep[lev],
720  MultiFabFileFullPrefix(lev, checkpointname, "Level_", "TwoStream_TDeep"));
721  }
722  if (seb_q_deep_is_state() && m_q_deep[lev]) {
723  VisMF::Write(*m_q_deep[lev],
724  MultiFabFileFullPrefix(lev, checkpointname, "Level_", "TwoStream_QDeep"));
725  }
726  m_hydro.write_checkpoint(lev, checkpointname);
727  m_snow.write_checkpoint(lev, checkpointname);
728 }
void write_checkpoint(int lev, const std::string &checkpointname) const
Definition: ERF_ForceRestoreHydrologyState.cpp:150
void write_checkpoint(int lev, const std::string &checkpointname) const
Definition: ERF_ForceRestoreSnowState.cpp:175

◆ write_land_forcing()

void TwoStreamRadiation::write_land_forcing ( int  lev,
amrex::MultiFab *  sw_flux_dn,
amrex::MultiFab *  lw_flux_dn,
amrex::MultiFab *  cos_zenith_angle 
) const

Copy the surface forcing of the last sweep on lev into a land-surface model's radiation inputs (SurfaceModel's "sw_flux_dn", "lw_flux_dn" and "cos_zenith_angle" outputs). A null destination is skipped. Each destination must lie on this level's horizontal grids; see copy_surface_plane. Before the level's first sweep this copies the lsm_undefined sentinel, not zero.

687 {
689  "TwoStreamRadiation::write_land_forcing: level " + std::to_string(lev) +
690  " was not defined to supply a land-surface model's forcing");
691  if (sw_flux_dn != nullptr) { copy_surface_plane(*m_sw_dn_sfc[lev], *sw_flux_dn); }
692  if (lw_flux_dn != nullptr) { copy_surface_plane(*m_lw_dn_sfc[lev], *lw_flux_dn); }
693  if (cos_zenith_angle != nullptr) { copy_surface_plane(*m_cos_zenith[lev], *cos_zenith_angle); }
694 }
void copy_surface_plane(const MultiFab &src2d, MultiFab &dst)
Definition: ERF_TwoStreamRadiation.cpp:588
Here is the call graph for this function:

Member Data Documentation

◆ m_alb_sw

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_alb_sw
private

◆ m_canopy

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_canopy
private

◆ m_canopy_alb

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_canopy_alb
private

Referenced by canopy_forcing().

◆ m_canopy_cosz

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_canopy_cosz
private

Referenced by canopy_forcing().

◆ m_canopy_m

amrex::Vector<int> TwoStreamRadiation::m_canopy_m
private

◆ m_canopy_step

amrex::Vector<int> TwoStreamRadiation::m_canopy_step
private

Referenced by canopy_forcing().

◆ m_cos_zenith

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_cos_zenith
private

Referenced by land_forcing_cos_zenith().

◆ m_diag

amrex::Vector<std::unique_ptr<RadiationDiagnostics> > TwoStreamRadiation::m_diag
private

◆ m_emiss_lw

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_emiss_lw
private

◆ m_flux_diag

amrex::Vector<FluxDiag> TwoStreamRadiation::m_flux_diag
private

◆ m_footprint

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_footprint
private

◆ m_grdflx_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_grdflx_sfc
private

◆ m_ground_keep

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_ground_keep
private

◆ m_ground_shadow

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_ground_shadow
private

Referenced by ground_shadow().

◆ m_ground_walls

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_ground_walls
private

Referenced by ground_walls(), and takes_ground_walls().

◆ m_has_cover

amrex::Vector<int> TwoStreamRadiation::m_has_cover
private

Referenced by has_building_cover().

◆ m_hfx_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_hfx_sfc
private

Referenced by seb_hfx().

◆ m_hydro

ForceRestoreHydrology TwoStreamRadiation::m_hydro
private

Referenced by hydrology_totals().

◆ m_lh_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_lh_sfc
private

Referenced by seb_lh().

◆ m_lw_dn_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_lw_dn_sfc
private

Referenced by land_forcing_lw_dn().

◆ m_lw_flux_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_lw_flux_sfc
private

Referenced by seb_lw_net().

◆ m_moisture

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_moisture
private

◆ m_orbit

OrbitalCache TwoStreamRadiation::m_orbit
private

◆ m_precip

ForceRestorePrecipRate TwoStreamRadiation::m_precip
private

Referenced by hydrology_rain_rate().

◆ m_q_deep

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_q_deep
private

Referenced by seb_q_deep(), and seb_q_deep_state().

◆ m_q_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_q_sfc
private

Referenced by seb_q_sfc(), and seb_q_sfc_state().

◆ m_rad

◆ m_rdOcp

amrex::Real TwoStreamRadiation::m_rdOcp = RdoCp
private

◆ m_roof

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_roof
private

Referenced by starts_on_roofs().

◆ m_roof_k

amrex::Vector<std::unique_ptr<amrex::iMultiFab> > TwoStreamRadiation::m_roof_k
private

Referenced by roof_cell().

◆ m_roof_step

amrex::Vector<int> TwoStreamRadiation::m_roof_step
private

Referenced by roofs_given().

◆ m_seb_updated

amrex::Vector<int> TwoStreamRadiation::m_seb_updated
private

Referenced by seb_lw_net(), and seb_sw_net().

◆ m_shaded_step

amrex::Vector<int> TwoStreamRadiation::m_shaded_step
private

◆ m_shadow_step

amrex::Vector<int> TwoStreamRadiation::m_shadow_step
private

Referenced by ground_shadow().

◆ m_snow

ForceRestoreSnow TwoStreamRadiation::m_snow
private

Referenced by snow_swe(), and snow_totals().

◆ m_solid

amrex::Vector<std::unique_ptr<amrex::iMultiFab> > TwoStreamRadiation::m_solid
private

◆ m_sw_beam_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_sw_beam_sfc
private

◆ m_sw_dn_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_sw_dn_sfc
private

◆ m_sw_flux_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_sw_flux_sfc
private

Referenced by seb_sw_net().

◆ m_sweep_step

amrex::Vector<int> TwoStreamRadiation::m_sweep_step
private

◆ m_t_deep

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_t_deep
private

Referenced by seb_t_deep(), and seb_t_deep_state().

◆ m_t_sfc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > TwoStreamRadiation::m_t_sfc
private

◆ m_walls_step

amrex::Vector<int> TwoStreamRadiation::m_walls_step
private

Referenced by ground_walls().

◆ m_water_message

amrex::Vector<int> TwoStreamRadiation::m_water_message
private

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