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

#include <ERF_IBFaceSet.H>

Collaboration diagram for IBFaceSet:

Classes

struct  SunState
 A sun and its irradiances: sun() holds those of the last compute_shortwave() call, for reports. More...
 
struct  TwoStreamSun
 The two-stream sun of the next compute_shortwave() or fill_roofs() (sun_mode = two_stream). More...
 

Public Types

enum  GroundWalls : int { GW_VIEW = 0 , GW_SW = 1 , GW_LW = 2 , GW_NCOMP = 3 }
 Components of the field of compute_ground_walls(). More...
 

Public Member Functions

 IBFaceSet (const IBSEBParams &params, int lev, int qv_comp=-1)
 
void build (const amrex::MultiFab &blanking, const amrex::Geometry &geom)
 
void add_outside_occluders (const std::vector< const IBFaceSet * > &below)
 
void set_two_stream_sun (amrex::Real declination, amrex::Real hour_angle, amrex::Real latitude_deg, amrex::Real toa_irradiance)
 
void map_buildings_to_level0 (const IBFaceSet &coarser, const amrex::IntVect &ratio)
 
int building_level0 (int b) const
 
void release_labels ()
 
ibseb::RayMap ray_map () const
 
amrex::IntVect ray_halo () const
 
bool ray_map_spans_domain () const
 
int n_faces () const
 
int n_buildings () const
 
int n_layers () const
 
void compute_view_fractions ()
 
void build_ground_landings ()
 
void fill_roofs (amrex::MultiFab &out, const amrex::iMultiFab &roof_cell, bool with_fixed, amrex::Real time)
 
void compute_ground_walls (amrex::MultiFab &out, bool with_view)
 
void compute_longwave (const amrex::MultiFab &cons, const TwoStreamCanopyView &canopy=TwoStreamCanopyView{})
 
void assign_materials ()
 
void compute_ground (amrex::Real dt)
 
void solve_balance (amrex::Real dt)
 
void compute_sensible (const amrex::MultiFab &cons, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, const amrex::MultiFab &zvel, amrex::Real c_p, const amrex::MultiFab *olen_ground=nullptr, const amrex::MultiFab *pblh_ground=nullptr, amrex::Real z_i_bulk=0.0)
 
void add_heat_flux_to_source (amrex::MultiFab &source, const amrex::MultiFab &cons, const amrex::Geometry &geom, amrex::Real c_p, amrex::Real rdOcp) const
 
void compute_shortwave (amrex::Real time, const TwoStreamCanopyView &canopy=TwoStreamCanopyView{})
 
void compute_ground_shadow (amrex::MultiFab &shadow) const
 
int top_sample_interface () const
 
bool has_faces () const
 
void check_canopy_layout (const amrex::MultiFab &cons, const TwoStreamCanopyView &canopy) const
 
void compute_shortwave_two_stream (const TwoStreamCanopyView &canopy)
 
void compute_longwave_two_stream (const amrex::MultiFab &cons, const TwoStreamCanopyView &canopy)
 
void scatter_field (const amrex::Gpu::DeviceVector< amrex::Real > &v, amrex::MultiFab &out) const
 
void dump_faces (const std::string &prefix) const
 
void scatter_diagnostics (amrex::MultiFab &nfaces, amrex::MultiFab &tskin) const
 
void write_state (const std::string &file) const
 
void read_state (const std::string &file)
 
void report (amrex::Real time, int step, bool write_csv) const
 
const SunState & sun () const
 
SunState sun_at (amrex::Real time) const
 The sun at time by erf.ibseb.sun_mode; changes nothing in the set (see the definition). More...
 
void print_debug_summary () const
 
void add_cost (double seconds)
 
void set_init_cost (double seconds)
 
const std::vector< int > & fab_start () const
 
void build_ray_map (const std::vector< const IBFaceSet * > &below)
 

Public Attributes

amrex::Gpu::DeviceVector< int > d_i
 
amrex::Gpu::DeviceVector< int > d_j
 
amrex::Gpu::DeviceVector< int > d_k
 Fluid cell of the face. More...
 
amrex::Gpu::DeviceVector< int > d_dir
 Face direction: 0 x, 1 y, 2 z. More...
 
amrex::Gpu::DeviceVector< int > d_side
 Solid neighbor at -1 (low) or +1 (high) side. More...
 
amrex::Gpu::DeviceVector< int > d_bid
 Building id (1-based) More...
 
amrex::Gpu::DeviceVector< int > d_mat
 Material id (0 = uniform inputs) More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_albedo
 
amrex::Gpu::DeviceVector< amrex::Real > d_emis
 Optical properties of the face. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_kth
 
amrex::Gpu::DeviceVector< amrex::Real > d_rhocp
 
amrex::Gpu::DeviceVector< amrex::Real > d_thick
 Slab conductivity [W/m/K], heat capacity [J/m3/K], thickness [m]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_area
 Face area [m2]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_xf
 
amrex::Gpu::DeviceVector< amrex::Real > d_yf
 
amrex::Gpu::DeviceVector< amrex::Real > d_zf
 Face center [m]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_T_skin
 Skin temperature [K]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_T_slab
 Slab layers [K], face-major: [face * n_layers + layer]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_f_sky
 
amrex::Gpu::DeviceVector< amrex::Real > d_f_ground
 
amrex::Gpu::DeviceVector< amrex::Real > d_f_bldg
 
amrex::Gpu::DeviceVector< amrex::Real > d_f_ground_lit
 
amrex::Gpu::DeviceVector< int > d_gnd_start
 
amrex::Gpu::DeviceVector< int > d_gnd_far
 
amrex::Gpu::DeviceVector< int > d_gnd_rays
 
amrex::Gpu::DeviceVector< unsigned int > d_gnd_land
 
amrex::Gpu::DeviceVector< int > d_roof_face
 fill_roofs(): the roof faces (indices into the face arrays), fab by fab More...
 
std::vector< int > m_roof_fab_start
 fill_roofs(): fab n owns the entries [m_roof_fab_start[n], m_roof_fab_start[n+1]) of d_roof_face More...
 
bool m_roof_faces_built = false
 d_roof_face has been built since build() More...
 
amrex::MultiFab m_gnd_patch
 compute_ground_walls(): per rank, the box of the columns its faces' landings reach (k = 0), GW_NCOMP components More...
 
bool m_gnd_patch_built = false
 m_gnd_patch has been sized since the ray map was built More...
 
bool m_landings_built = false
 build_ground_landings() has run since build() More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_SW_abs
 
amrex::Gpu::DeviceVector< amrex::Real > d_LW_net
 
amrex::Gpu::DeviceVector< amrex::Real > d_H
 
amrex::Gpu::DeviceVector< amrex::Real > d_LE
 
amrex::Gpu::DeviceVector< amrex::Real > d_G
 
amrex::Gpu::DeviceVector< amrex::Real > d_Q_ext
 External incident flux [W/m2], e.g. fire radiation. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_shadow
 1 when the ray to the sun hits a building, else 0 More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_SW_direct_in
 Direct beam incident on the face. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_SW_diffuse_in
 Sky and ground-reflected diffuse incident. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_LW_down_in
 Incoming longwave on the face (sky, ground and walls) More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_T_air
 Air temperature of the fluid cell. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_theta_air
 Potential temperature of the fluid cell [K]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_rho
 Density of the fluid cell [kg/m3]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_U_tan
 Tangential wind speed at the fluid cell [m/s]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_ustar
 Friction velocity of the wall function [m/s]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_H_coeff
 H = H_coeff (theta_skin - theta_air) [W/m2/K]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_hbld
 Height of the face's building column [m]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_w_star
 Convective velocity scale of the step [m/s]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_olen
 Obukhov length used [m] (1e30 when neutral) More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_z_i
 Depth in w* [m]: mixed layer above a roof, building height for a wall. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_LW_ext
 Incoming longwave from sky and ground only [W/m2]. More...
 
amrex::Gpu::DeviceVector< amrex::Real > d_resid
 |balance| after the solve [W/m2] More...
 
amrex::Gpu::DeviceVector< int > d_niter
 Newton iterations of the last solve. More...
 
amrex::iMultiFab m_col_valid
 
amrex::iMultiFab m_ray_patch
 
amrex::Box m_patch_box
 This rank's patch (empty without boxes) More...
 
amrex::IntVect m_halo {AMREX_D_DECL(0, 0, 0)}
 Halo of the patch in cells. More...
 
bool m_wrap_x = false
 
bool m_wrap_y = false
 The patch spans the periodic domain in x / y. More...
 
bool m_map_spans_domain = false
 Every rank's patch spans the domain. More...
 
int m_max_steps = 0
 Columns a walk is followed for: the halo's reach in x plus y, before the domain cap. More...
 
int m_reach [2] = {0, 0}
 The halo's reach in x and in y before the domain cap [columns]. More...
 

Private Member Functions

void warn_fixed_sun_below_floor () const
 

Private Attributes

IBSEBParams m_params
 Copy of the inputs. More...
 
int m_lev = 0
 AMR level, for reports. More...
 
int m_qv_comp = -1
 State component of rho qv, -1 without a moisture model. More...
 
int m_nface = 0
 Faces owned by this rank. More...
 
int m_top_sample = -1
 Highest interface a face samples, over all ranks (-1: no faces) More...
 
int m_nbld = 0
 Buildings of the level (global) More...
 
std::vector< int > m_fab_start
 See fab_start() More...
 
std::vector< amrex::Long > m_bld_nface
 Faces per building. More...
 
std::vector< amrex::Real > m_bld_area
 Face area per building [m2]. More...
 
amrex::Long m_nface_dir [3] = {0, 0, 0}
 Faces per direction. More...
 
amrex::Real m_area_total = 0.0
 Total face area [m2]. More...
 
std::vector< amrex::Long > m_bld_ncol
 
std::vector< int > m_bld_ilo
 
std::vector< int > m_bld_ihi
 
std::vector< int > m_bld_jlo
 
std::vector< int > m_bld_jhi
 
std::vector< int > m_to_lev0
 
amrex::iMultiFab m_lab
 
amrex::Geometry m_geom
 Geometry of the level. More...
 
int m_nx = 0
 
int m_ny = 0
 
int m_nz = 0
 Cells of the domain in x, y and z. More...
 
amrex::IntVect m_dom_lo {AMREX_D_DECL(0, 0, 0)}
 Low corner of the level's domain. More...
 
amrex::Real m_x_lo = 0.0
 
amrex::Real m_y_lo = 0.0
 Domain origin [m]. More...
 
amrex::Real m_dx [3] = {0.0, 0.0, 0.0}
 Cell sizes [m]. More...
 
bool m_per_x = false
 
bool m_per_y = false
 Periodicity in x and y. More...
 
amrex::Real m_col_top_max = 0.0
 Tallest column the ray map holds [m] (the levels below included after add_outside_occluders()) More...
 
amrex::Real m_z_ground = 0.0
 Ground height [m] (flat, the domain bottom) More...
 
SunState m_sun
 
TwoStreamSun m_ts_sun
 
double m_cost_s = 0.0
 Wall-clock seconds spent in the per-step update on this rank. More...
 
amrex::Long m_cost_n = 0
 Number of per-step updates timed. More...
 
double m_init_cost_s = 0.0
 Wall-clock seconds of build() and compute_view_fractions() More...
 

Member Enumeration Documentation

◆ GroundWalls

Components of the field of compute_ground_walls().

Enumerator
GW_VIEW 
GW_SW 
GW_LW 
GW_NCOMP 
248 : int { GW_VIEW = 0, GW_SW = 1, GW_LW = 2, GW_NCOMP = 3 };
@ GW_LW
Definition: ERF_IBFaceSet.H:248
@ GW_SW
Definition: ERF_IBFaceSet.H:248
@ GW_VIEW
Definition: ERF_IBFaceSet.H:248
@ GW_NCOMP
Definition: ERF_IBFaceSet.H:248

Constructor & Destructor Documentation

◆ IBFaceSet()

IBFaceSet::IBFaceSet ( const IBSEBParams &  params,
int  lev,
int  qv_comp = -1 
)
inline

Construct an empty face set for one level; build() fills it.

Parameters
paramsInputs of the balance (copied; the set never reads ParmParse).
levAMR level the set belongs to, for reports only.
qv_compState component of rho qv (SolverChoice::moisture_indices.qv), negative without a moisture model. The air temperature and the Exner function of a fluid cell take its vapor through the equation of state, as the rest of ERF does; with no moisture model they take none.
101  : m_params(params), m_lev(lev), m_qv_comp(qv_comp) {}
int m_lev
AMR level, for reports.
Definition: ERF_IBFaceSet.H:664
int m_qv_comp
State component of rho qv, -1 without a moisture model.
Definition: ERF_IBFaceSet.H:665
IBSEBParams m_params
Copy of the inputs.
Definition: ERF_IBFaceSet.H:663

Member Function Documentation

◆ add_cost()

void IBFaceSet::add_cost ( double  seconds)
inline

Add the wall-clock time of one per-step update of this rank, for the cost line of report().

628 { m_cost_s += seconds; ++m_cost_n; }
double m_cost_s
Wall-clock seconds spent in the per-step update on this rank.
Definition: ERF_IBFaceSet.H:699
amrex::Long m_cost_n
Number of per-step updates timed.
Definition: ERF_IBFaceSet.H:700

◆ add_heat_flux_to_source()

void IBFaceSet::add_heat_flux_to_source ( amrex::MultiFab &  source,
const amrex::MultiFab &  cons,
const amrex::Geometry &  geom,
amrex::Real  c_p,
amrex::Real  rdOcp 
) const

Add the face heat flux to the temperature equation: every face deposits H A / (c_p V Pi) into the rho-theta source of its fluid cell (Pi the Exner function, so the flux heats the cell by H A / (c_p V) in temperature). Called after the sources are rebuilt at every slow stage; adds, never overwrites, and uses atomic adds because a corner cell receives several faces.

Face flux into the temperature equation. The rho-theta tendency of the fluid cell is H A / (c_p V Pi); with several faces on one cell the adds are atomic.

1488 {
1489  const auto dx = geom.CellSizeArray();
1490  const Real vol = dx[0] * dx[1] * dx[2];
1491  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
1492  const Real* pH = d_H.data(); const Real* pA = d_area.data();
1493  const int qv_comp = m_qv_comp;
1494  for (MFIter mfi(source); mfi.isValid(); ++mfi) {
1495  const int f0 = m_fab_start[mfi.LocalIndex()];
1496  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
1497  auto const& src = source.array(mfi);
1498  auto const& c = cons.const_array(mfi);
1499  ParallelFor(f1 - f0, [=] AMREX_GPU_DEVICE (int m) noexcept {
1500  const int f = f0 + m;
1501  const int i = pi[f], j = pj[f], k = pk[f];
1502  const Real exner = getExnergivenRTh(c(i, j, k, RhoTheta_comp), rdOcp, cell_qv(c, i, j, k, qv_comp));
1503  const Real tend = pH[f] * pA[f] / (c_p * vol * exner);
1504  Gpu::Atomic::AddNoRet(&src(i, j, k, RhoTheta_comp), tend);
1505  });
1506  }
1507  Gpu::streamSynchronize();
1508 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenRTh(const amrex::Real rhotheta, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:156
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
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);})
amrex::Gpu::DeviceVector< int > d_k
Fluid cell of the face.
Definition: ERF_IBFaceSet.H:532
amrex::Gpu::DeviceVector< amrex::Real > d_H
Definition: ERF_IBFaceSet.H:564
amrex::Gpu::DeviceVector< amrex::Real > d_area
Face area [m2].
Definition: ERF_IBFaceSet.H:539
amrex::Gpu::DeviceVector< int > d_j
Definition: ERF_IBFaceSet.H:532
std::vector< int > m_fab_start
See fab_start()
Definition: ERF_IBFaceSet.H:669
amrex::Gpu::DeviceVector< int > d_i
Definition: ERF_IBFaceSet.H:532
@ cons
Definition: ERF_IndexDefines.H:231
real(c_double), parameter, private pi
Definition: ERF_module_mp_morr_two_moment.F90:100
Here is the call graph for this function:

◆ add_outside_occluders()

void IBFaceSet::add_outside_occluders ( const std::vector< const IBFaceSet * > &  below)

Add the buildings this refined level does not hold to the ray map of its ray cast, from the column maps of the levels below.

build() takes the map from the level's own cells, so on a refined level that covers part of the domain the rays of the shortwave and the view fractions would pass through every building outside it. The ray map is rebuilt with the halo for the tallest column of every level, and each column of the patch that this level's grids do not cover takes the top of the finest level below that covers it (ERF::ibseb_check_refined_levels() has made sure a building is wholly inside or wholly outside each level), on the ratio x ratio columns of this level beneath the coarse one, at the same height. Only the ray cast reads the result: the building ids, the face heights of the wall function and the reports keep the level's own buildings. Call after build() of every level involved and before compute_view_fractions().

Parameters
belowFace sets of levels 0 to this level's minus one, in that order.

Rebuild the ray map with the buildings of the levels below (see the header and build_ray_map()).

809 {
810  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!below.empty(), "erf.ibseb: add_outside_occluders() needs the levels below");
811  build_ray_map(below);
813 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
void build_ray_map(const std::vector< const IBFaceSet * > &below)
Definition: ERF_IBFaceSet.cpp:635
void warn_fixed_sun_below_floor() const
Definition: ERF_IBFaceSet.cpp:769
Here is the call graph for this function:

◆ assign_materials()

void IBFaceSet::assign_materials ( )

Assign every face its material properties: from the material library by building id, or the uniform inputs. Called once after build(); fills d_mat, d_albedo, d_emis, d_k, d_rhocp, d_thick and initializes the slab layers to the skin temperature.

Materials per face from the library by building id, or the uniform inputs. Host work on the static geometry, once.

1188 {
1189  if (m_params.material_file.empty()) { return; }
1190  const Vector<IBSEBMaterial> table = read_ibseb_materials(m_params.material_file);
1191  auto find = [&](int id) -> const IBSEBMaterial& {
1192  for (const auto& m : table) { if (m.mat_id == id) return m; }
1193  Abort("erf.ibseb: material id " + std::to_string(id) + " is not in " + m_params.material_file);
1194  return table[0];
1195  };
1196  std::vector<int> h_b(m_nface);
1197  Gpu::copy(Gpu::deviceToHost, d_bid.begin(), d_bid.end(), h_b.begin());
1198  Gpu::streamSynchronize();
1199  std::vector<int> h_mat(m_nface);
1200  std::vector<Real> h_alb(m_nface), h_emi(m_nface), h_k(m_nface), h_rc(m_nface), h_th(m_nface);
1201  for (int n = 0; n < m_nface; ++n) {
1202  // erf.ibseb.material_by_building follows level 0's numbering; a
1203  // building only a refined level resolves (0 here) takes the default.
1204  const int b = m_to_lev0[h_b[n]];
1205  int id = m_params.material_default;
1206  if (b >= 1 && b <= static_cast<int>(m_params.material_by_building.size())) {
1207  id = m_params.material_by_building[b - 1];
1208  }
1209  const IBSEBMaterial& m = find(id);
1210  h_mat[n] = m.mat_id; h_alb[n] = m.albedo; h_emi[n] = m.emissivity;
1211  h_k[n] = m.k_therm; h_rc[n] = m.rho_cp; h_th[n] = m.thickness;
1212  }
1213  upload(d_mat, h_mat); upload(d_albedo, h_alb); upload(d_emis, h_emi);
1214  upload(d_kth, h_k); upload(d_rhocp, h_rc); upload(d_thick, h_th);
1215  Gpu::streamSynchronize();
1216  if (m_params.debug) {
1217  Print() << "[IBSEB DEBUG] lev=" << m_lev << " materials: " << table.size() << " in "
1218  << m_params.material_file << ", default id " << m_params.material_default;
1219  for (size_t b = 0; b < m_params.material_by_building.size(); ++b) {
1220  Print() << ", building " << b + 1 << " -> " << m_params.material_by_building[b];
1221  }
1222  Print() << "\n";
1223  for (const auto& m : table) {
1224  Print() << "[IBSEB DEBUG] material " << m.mat_id << " (" << m.name << "): albedo=" << m.albedo
1225  << " emissivity=" << m.emissivity << " k=" << m.k_therm << " W/m/K rho_cp=" << m.rho_cp
1226  << " J/m3/K thickness=" << m.thickness << " m\n";
1227  }
1228  }
1229 }
Vector< IBSEBMaterial > read_ibseb_materials(const std::string &file)
Definition: ERF_IBSEBMaterials.cpp:25
DiagnosticID id
Definition: ERF_Plotfile2DWaterPath.cpp:28
amrex::Gpu::DeviceVector< amrex::Real > d_thick
Slab conductivity [W/m/K], heat capacity [J/m3/K], thickness [m].
Definition: ERF_IBFaceSet.H:538
amrex::Gpu::DeviceVector< amrex::Real > d_albedo
Definition: ERF_IBFaceSet.H:537
amrex::Gpu::DeviceVector< int > d_mat
Material id (0 = uniform inputs)
Definition: ERF_IBFaceSet.H:536
std::vector< int > m_to_lev0
Definition: ERF_IBFaceSet.H:683
amrex::Gpu::DeviceVector< amrex::Real > d_emis
Optical properties of the face.
Definition: ERF_IBFaceSet.H:537
int m_nface
Faces owned by this rank.
Definition: ERF_IBFaceSet.H:666
amrex::Gpu::DeviceVector< int > d_bid
Building id (1-based)
Definition: ERF_IBFaceSet.H:535
amrex::Gpu::DeviceVector< amrex::Real > d_rhocp
Definition: ERF_IBFaceSet.H:538
amrex::Gpu::DeviceVector< amrex::Real > d_kth
Definition: ERF_IBFaceSet.H:538
Definition: ERF_IBSEBMaterials.H:24
amrex::Real albedo
Definition: ERF_IBSEBMaterials.H:26
amrex::Real k_therm
[W/m/K]
Definition: ERF_IBSEBMaterials.H:28
amrex::Real thickness
[m]
Definition: ERF_IBSEBMaterials.H:30
int mat_id
Definition: ERF_IBSEBMaterials.H:25
amrex::Real rho_cp
[J/m3/K]
Definition: ERF_IBSEBMaterials.H:29
amrex::Real emissivity
Definition: ERF_IBSEBMaterials.H:27
int material_default
Definition: ERF_IBSEBParams.H:158
std::string material_file
Definition: ERF_IBSEBParams.H:157
std::vector< int > material_by_building
Definition: ERF_IBSEBParams.H:159
bool debug
[IBSEB DEBUG] prints: set description at build, per-step summary, per-building rows
Definition: ERF_IBSEBParams.H:32
Here is the call graph for this function:

◆ build()

void IBFaceSet::build ( const amrex::MultiFab &  blanking,
const amrex::Geometry &  geom 
)

Detect this rank's faces from the cell-centered blanking and allocate every per-face array.

Runs on the host once at initialization: the blanking is copied fab by fab (a pinned copy on GPU builds), the valid cells are scanned, and the arrays are uploaded to the device at the end. Must be called after the blanking has been built and its ghost cells filled, since the solid neighbor of a fluid cell on a box edge lives in a ghost cell. Stops when a solid cell outside the level's grids neighbors a cell of the level, fluid or solid: a building across the edge of a refined level.

Parameters
blankingCell-centered blanking of the level (needs at least one ghost cell, filled).
geomGeometry of the level: cell sizes for the face areas, domain and periodicity for the neighbor tests.

Detect the faces owned by this rank and allocate the per-face arrays.

The scan visits every valid cell of every local fab in MFIter order, once. A fluid cell (blanking < 0.5) contributes one face for each of its six neighbors that is solid (blanking >= 0.5); the neighbor may sit in a ghost cell, which is why the blanking must have its ghost cells filled. Neighbors outside the domain in a non-periodic direction are skipped, so a building against a non-periodic boundary has no face there. Solid cells contribute no face, only the column map (the highest solid cell of each column of the level's own boxes) that the building ids and the ray cast read. A solid neighbor outside the level's grids, of a fluid or a solid cell, means a building crosses the edge of a refined level; the scan counts them and stops the run once all ranks have reported.

Faces are appended in scan order, which makes them contiguous per fab; m_fab_start records where each fab's faces begin. The per-direction, per-building and total counts are reduced over all ranks here, once, so report() does not have to reduce static numbers every time. Nothing of the size of the domain is gathered: the column map is exchanged through its ghost cells, the building labels through theirs (see the header), and the one gather is of the distinct labels, one per building.

180 {
181  const Box& domain = geom.Domain();
182  const int nx = domain.length(0);
183  const int ny = domain.length(1);
184  const int ilo = domain.smallEnd(0);
185  const int jlo = domain.smallEnd(1);
186  const int klo = domain.smallEnd(2);
187  const auto dx = geom.CellSizeArray();
188  const auto plo = geom.ProbLoArray();
189  const Real face_area[3] = { dx[1] * dx[2], dx[0] * dx[2], dx[0] * dx[1] };
190  m_geom = geom;
191  m_nx = nx; m_ny = ny; m_nz = domain.length(2);
192  m_dom_lo = domain.smallEnd();
193  m_x_lo = plo[0]; m_y_lo = plo[1];
194  for (int d = 0; d < 3; ++d) { m_dx[d] = dx[d]; }
195  m_per_x = geom.isPeriodic(0); m_per_y = geom.isPeriodic(1);
196  m_z_ground = plo[2];
197 
198  // The face list of a cell must not depend on the decomposition: every
199  // valid cell has to see its six neighbors, which needs a filled ghost
200  // layer on the blanking.
201  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(blanking.nGrowVect().min() >= 1,
202  "erf.ibseb: the blanking needs at least one ghost cell");
203  // The labeling below gives every column its scan index plus one as a label, in an int.
204  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(Long(nx) * ny < Long(std::numeric_limits<int>::max()),
205  "erf.ibseb: the level has more columns than an int can label");
206 
207  // The level's own column map: one cell per column of each of the level's
208  // boxes, with one ghost cell for the neighbors the faces and the
209  // labeling read across boxes and periodic seams.
210  const BoxArray col_ba = column_box_array(blanking.boxArray(), domain);
211  m_col_valid.define(col_ba, blanking.DistributionMap(), 1, IntVect(AMREX_D_DECL(1, 1, 0)));
212  m_col_valid.setVal(-1);
213 
214  std::vector<int> h_i, h_j, h_k, h_dir, h_side, h_nbi, h_nbj;
215  std::vector<Real> h_area, h_xf, h_yf, h_zf;
216  // Solid neighbors outside the level's grids, of a fluid cell (a wall
217  // against the edge) or of a solid one (a building running across the
218  // edge, which a low roof can do with no fluid cell in between): a
219  // building that crosses the edge of a refined level, whose columns there
220  // this level cannot see.
221  const BoxArray& level_ba = blanking.boxArray();
222  Long n_outside = 0;
223  Long first_outside = std::numeric_limits<Long>::max(); // lowest such cell, as a linear domain index
224  auto solid_outside = [&] (const Array4<const Real>& b, const Box& vbox, const Box& fbox, const IntVect& nb) {
225  // A neighbor in the same valid box is in the level (the common case,
226  // and every case on level 0): no lookup.
227  if (vbox.contains(nb) || !fbox.contains(nb) || b(nb) < 0.5) { return false; }
228  IntVect nbw = nb;
229  for (int dp = 0; dp < 2; ++dp) {
230  if (!geom.isPeriodic(dp)) { continue; }
231  const int lo_d = domain.smallEnd(dp), len_d = domain.length(dp);
232  nbw[dp] = lo_d + ((nbw[dp] - lo_d) % len_d + len_d) % len_d;
233  }
234  if (level_ba.contains(nbw)) { return false; }
235  const IntVect r = nbw - domain.smallEnd();
236  first_outside = std::min(first_outside,
237  (Long(r[0]) * domain.length(1) + r[1]) * domain.length(2) + r[2]);
238  ++n_outside;
239  return true;
240  };
241 
242  m_fab_start.clear();
243  for (MFIter mfi(blanking); mfi.isValid(); ++mfi) {
244  m_fab_start.push_back(static_cast<int>(h_i.size()));
245  const Box& bx = mfi.validbox();
246  const HostFab hf(blanking[mfi]);
247  auto const& b = hf.array();
248  const Box& fbox = Box(b);
249  // The column map of this box: the highest solid cell of each of its
250  // columns, as a domain-relative k index, -1 where the column carries
251  // no solid cell. It is an index rather than a height so that it costs
252  // 4 bytes per column.
253  IArrayBox& cfab = m_col_valid[mfi];
254  HostInts top(cfab.box(), -1);
255  auto const& t = top.array();
256  const auto lo = lbound(bx);
257  const auto hi = ubound(bx);
258  for (int k = lo.z; k <= hi.z; ++k) {
259  for (int j = lo.y; j <= hi.y; ++j) {
260  for (int i = lo.x; i <= hi.x; ++i) {
261  if (b(i, j, k) >= 0.5) {
262  t(i, j, klo) = std::max(t(i, j, klo), k - klo);
263  for (int d = 0; d < 3; ++d) {
264  for (int s = -1; s <= 1; s += 2) {
265  IntVect nb(i, j, k);
266  nb[d] += s;
267  if (!geom.isPeriodic(d) && !domain.contains(nb)) { continue; }
268  solid_outside(b, bx, fbox, nb);
269  }
270  }
271  continue;
272  }
273  for (int d = 0; d < 3; ++d) {
274  for (int s = -1; s <= 1; s += 2) {
275  IntVect nb(i, j, k);
276  nb[d] += s;
277  if (!fbox.contains(nb)) { continue; }
278  if (!geom.isPeriodic(d) && !domain.contains(nb)) { continue; }
279  if (b(nb) < 0.5) { continue; }
280  solid_outside(b, bx, fbox, nb);
281  h_i.push_back(i); h_j.push_back(j); h_k.push_back(k);
282  h_dir.push_back(d); h_side.push_back(s);
283  // Face center: the fluid cell center moved half a cell toward the solid
284  // (plo is the position of the domain's low corner cell).
285  Real c[3] = { Real(plo[0] + (i - ilo + 0.5) * dx[0]), Real(plo[1] + (j - jlo + 0.5) * dx[1]), Real(plo[2] + (k - klo + 0.5) * dx[2]) };
286  c[d] += 0.5 * s * dx[d];
287  h_xf.push_back(c[0]); h_yf.push_back(c[1]); h_zf.push_back(c[2]);
288  // Column of the solid neighbor, unwrapped: it lies in this
289  // box or in its ghost cell, where the periodic image is.
290  h_nbi.push_back(nb[0]); h_nbj.push_back(nb[1]);
291  h_area.push_back(face_area[d]);
292  }
293  }
294  }}}
295  top.upload(cfab);
296  }
297  m_fab_start.push_back(static_cast<int>(h_i.size()));
298  m_nface = static_cast<int>(h_i.size());
299  m_col_valid.FillBoundary(geom.periodicity());
300 
301  // The column map, the building ids and the ray cast below see only the
302  // level's own cells, so a building must lie wholly inside the level.
303  // ERF::init_ibseb() checks that for the buildings of the level below; this
304  // catches one only the refined level resolves.
305  {
306  Long n_out_all = n_outside;
307  Long first_all = first_outside;
308  ParallelDescriptor::ReduceLongSum(n_out_all);
309  ParallelDescriptor::ReduceLongMin(first_all);
310  if (n_out_all > 0) {
311  const Long nyz = Long(domain.length(1)) * domain.length(2);
312  const int fi = static_cast<int>(first_all / nyz);
313  const int fj = static_cast<int>((first_all / domain.length(2)) % domain.length(1));
314  const int fk = static_cast<int>(first_all % domain.length(2));
315  std::ostringstream os;
316  os << "erf.ibseb: level " << m_lev << " has " << n_out_all
317  << " cell faces against solid cells outside its grids (the first solid one at x = "
318  << plo[0] + (fi + 0.5) * dx[0] << " m, y = " << plo[1] + (fj + 0.5) * dx[1]
319  << " m, z = " << plo[2] + (fk + 0.5) * dx[2] << " m)";
320  os << ": a building crosses the edge of the refined level. To fix the refined box, run"
321  " `python3 Exec/CanonicalTests/SEB/ibseb_refinement_box.py <inputs>`: it checks the deck's"
322  " erf.<name>.in_box_lo / in_box_hi against the height map and prints a box that no building"
323  " crosses (or `... <inputs> --all --fit tight|relaxed` for a box around every building).";
324  Abort(os.str());
325  }
326  }
327 
328  // The highest interface any face samples (two_stream_canopy_sample(): a roof its
329  // fluid cell's bottom, a ceiling and a wall the top of its cell too), counted from the domain
330  // bottom; -1 when the level has no faces. The two-stream beam the faces read needs
331  // no interface above it.
332  m_top_sample = -1;
333  for (int n = 0; n < m_nface; ++n) {
334  m_top_sample = std::max(m_top_sample, h_k[n] - domain.smallEnd(2) + ((h_dir[n] != 2 || h_side[n] > 0) ? 1 : 0));
335  }
336  ParallelDescriptor::ReduceIntMax(m_top_sample);
337 
338  // Tallest column of the level over all ranks: the height a rising ray
339  // stops at (one cell above the highest solid cell; the ground when the
340  // level holds no solid cell).
341  {
342  const int kmax = m_col_valid.max(0);
343  m_col_top_max = (kmax >= 0) ? Real(m_z_ground + (kmax + 1.0) * dx[2]) : Real(m_z_ground);
344  }
345 
346  // Host copies of the column map, ghost cells filled: the column of a
347  // face's solid neighbor is in its fab's box or its ghost ring.
348  std::vector<HostInts> tops;
349  std::vector<Box> vboxes;
350  for (MFIter mfi(m_col_valid); mfi.isValid(); ++mfi) {
351  tops.emplace_back(m_col_valid[mfi]);
352  vboxes.push_back(mfi.validbox());
353  }
354  const int nfab = static_cast<int>(tops.size());
355  AMREX_ALWAYS_ASSERT(nfab + 1 == static_cast<int>(m_fab_start.size()));
356  // Height of each face's building column, for the wall-function depth.
357  {
358  std::vector<Real> h_hb(h_i.size());
359  for (int li = 0; li < nfab; ++li) {
360  auto const& t = tops[li].array();
361  for (int n = m_fab_start[li]; n < m_fab_start[li + 1]; ++n) {
362  const int kt = t(h_nbi[n], h_nbj[n], klo);
363  h_hb[n] = (kt >= 0) ? (kt + 1.0) * dx[2] : 0.0;
364  }
365  }
366  upload(d_hbld, h_hb);
367  }
368 
369  // ---- Buildings: 4-connected solid columns, numbered in scan order ----
370  // Each box splits its solid columns into connected pieces (a depth-first
371  // flood fill); a piece's label starts as the lowest scan index plus one
372  // of its columns, and the pieces then take the lowest label of their
373  // neighbors across the box edges, through one ghost cell of m_lab,
374  // until no label changes anywhere: the pieces of one building all end
375  // with the scan index of its first column. The rounds are as many as a
376  // building's pieces are deep, so the exchange never depends on the
377  // number of columns.
378  m_lab.define(col_ba, blanking.DistributionMap(), 1, IntVect(AMREX_D_DECL(1, 1, 0)));
379  m_lab.setVal(0);
380  std::vector<std::vector<int>> piece_of(nfab); // per fab, per valid column: its piece, -1 where fluid
381  std::vector<std::vector<int>> piece_label(nfab); // per fab, per piece: its label
382  auto scan_label = [=] (int i, int j) { return (i - ilo) * ny + (j - jlo) + 1; };
383  for (int li = 0; li < nfab; ++li) {
384  const Box& vb = vboxes[li];
385  auto const& t = tops[li].array();
386  const auto lo = lbound(vb);
387  const int lx = vb.length(0), ly = vb.length(1);
388  auto idx = [=] (int i, int j) { return (j - lo.y) * lx + (i - lo.x); };
389  std::vector<int>& piece = piece_of[li];
390  piece.assign(static_cast<size_t>(lx) * ly, -1);
391  std::vector<int> stack;
392  for (int i = lo.x; i < lo.x + lx; ++i) {
393  for (int j = lo.y; j < lo.y + ly; ++j) {
394  if (t(i, j, klo) < 0 || piece[idx(i, j)] >= 0) { continue; }
395  const int p = static_cast<int>(piece_label[li].size());
396  int lab = scan_label(i, j);
397  piece[idx(i, j)] = p;
398  stack.clear();
399  stack.push_back(idx(i, j));
400  while (!stack.empty()) {
401  const int q = stack.back(); stack.pop_back();
402  const int qi = lo.x + q % lx, qj = lo.y + q / lx;
403  lab = std::min(lab, scan_label(qi, qj));
404  const int ni[4] = {qi - 1, qi + 1, qi, qi};
405  const int nj[4] = {qj, qj, qj - 1, qj + 1};
406  for (int n = 0; n < 4; ++n) {
407  if (!vb.contains(IntVect(ni[n], nj[n], klo))) { continue; }
408  const int r = idx(ni[n], nj[n]);
409  if (t(ni[n], nj[n], klo) >= 0 && piece[r] < 0) {
410  piece[r] = p;
411  stack.push_back(r);
412  }
413  }
414  }
415  piece_label[li].push_back(lab);
416  }
417  }
418  }
419  // Write the labels into the map, exchange, lower, repeat.
420  auto write_labels = [&] (const std::vector<std::vector<int>>& value) {
421  int li = 0;
422  for (MFIter mfi(m_lab); mfi.isValid(); ++mfi, ++li) {
423  IArrayBox& fab = m_lab[mfi];
424  HostInts L(fab.box(), 0);
425  auto const& a = L.array();
426  const Box& vb = vboxes[li];
427  const auto lo = lbound(vb);
428  const int lx = vb.length(0), ly = vb.length(1);
429  for (int j = lo.y; j < lo.y + ly; ++j) {
430  for (int i = lo.x; i < lo.x + lx; ++i) {
431  const int p = piece_of[li][(j - lo.y) * lx + (i - lo.x)];
432  if (p >= 0) { a(i, j, klo) = value[li][p]; }
433  }
434  }
435  L.upload(fab);
436  }
437  m_lab.FillBoundary(geom.periodicity());
438  };
439  int n_rounds = 0;
440  for (;;) {
441  write_labels(piece_label);
442  ++n_rounds;
443  bool changed = false;
444  int li = 0;
445  for (MFIter mfi(m_lab); mfi.isValid(); ++mfi, ++li) {
446  const HostInts L(m_lab[mfi]);
447  auto const& a = L.array();
448  const Box& vb = vboxes[li];
449  const auto lo = lbound(vb);
450  const auto hi = ubound(vb);
451  const int lx = vb.length(0);
452  for (int j = lo.y; j <= hi.y; ++j) {
453  for (int i = lo.x; i <= hi.x; ++i) {
454  if (i != lo.x && i != hi.x && j != lo.y && j != hi.y) { continue; } // an inner column has no neighbor outside the box
455  const int p = piece_of[li][(j - lo.y) * lx + (i - lo.x)];
456  if (p < 0) { continue; }
457  const int ni[4] = {i - 1, i + 1, i, i};
458  const int nj[4] = {j, j, j - 1, j + 1};
459  for (int n = 0; n < 4; ++n) {
460  const IntVect nb(ni[n], nj[n], klo);
461  if (vb.contains(nb) || !L.box.contains(nb)) { continue; }
462  const int g = a(nb);
463  if (g > 0 && g < piece_label[li][p]) { piece_label[li][p] = g; changed = true; }
464  }
465  }
466  }
467  }
468  ParallelDescriptor::ReduceBoolOr(changed);
469  if (!changed) { break; }
470  }
471  // The distinct labels, one per building, gathered from every rank and
472  // numbered in scan order; the pieces take the number of their label.
473  std::vector<int> labels_all;
474  {
475  std::set<int> mine;
476  for (const auto& pl : piece_label) { mine.insert(pl.begin(), pl.end()); }
477  const std::vector<int> labels_mine(mine.begin(), mine.end());
478  labels_all = all_gather(labels_mine);
479  std::sort(labels_all.begin(), labels_all.end());
480  labels_all.erase(std::unique(labels_all.begin(), labels_all.end()), labels_all.end());
481  }
482  m_nbld = static_cast<int>(labels_all.size());
483  std::vector<std::vector<int>> piece_id(nfab);
484  for (int li = 0; li < nfab; ++li) {
485  for (int lab : piece_label[li]) {
486  const auto it = std::lower_bound(labels_all.begin(), labels_all.end(), lab);
487  AMREX_ALWAYS_ASSERT(it != labels_all.end() && *it == lab);
488  piece_id[li].push_back(static_cast<int>(it - labels_all.begin()) + 1);
489  }
490  }
491  write_labels(piece_id);
492  // The id of each face: that of the column of its solid neighbor, in the
493  // fab's box or its ghost ring.
494  std::vector<int> h_bid(m_nface);
495  {
496  int li = 0;
497  for (MFIter mfi(m_lab); mfi.isValid(); ++mfi, ++li) {
498  const HostInts L(m_lab[mfi]);
499  auto const& a = L.array();
500  for (int n = m_fab_start[li]; n < m_fab_start[li + 1]; ++n) {
501  h_bid[n] = a(h_nbi[n], h_nbj[n], klo);
502  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(h_bid[n] >= 1, "erf.ibseb: a face's solid neighbour has no building id");
503  }
504  }
505  }
506  // Footprints, for the debug summary: columns and bounding box per building.
507  m_bld_ncol.assign(m_nbld + 1, 0);
508  m_bld_ilo.assign(m_nbld + 1, std::numeric_limits<int>::max()); m_bld_ihi.assign(m_nbld + 1, std::numeric_limits<int>::min());
509  m_bld_jlo.assign(m_nbld + 1, std::numeric_limits<int>::max()); m_bld_jhi.assign(m_nbld + 1, std::numeric_limits<int>::min());
510  for (int li = 0; li < nfab; ++li) {
511  const Box& vb = vboxes[li];
512  const auto lo = lbound(vb);
513  const int lx = vb.length(0), ly = vb.length(1);
514  for (int j = lo.y; j < lo.y + ly; ++j) {
515  for (int i = lo.x; i < lo.x + lx; ++i) {
516  const int p = piece_of[li][(j - lo.y) * lx + (i - lo.x)];
517  if (p < 0) { continue; }
518  const int bb = piece_id[li][p];
519  m_bld_ncol[bb] += 1;
520  m_bld_ilo[bb] = std::min(m_bld_ilo[bb], i); m_bld_ihi[bb] = std::max(m_bld_ihi[bb], i);
521  m_bld_jlo[bb] = std::min(m_bld_jlo[bb], j); m_bld_jhi[bb] = std::max(m_bld_jhi[bb], j);
522  }
523  }
524  }
525  ParallelDescriptor::ReduceLongSum(m_bld_ncol.data(), m_nbld + 1);
526  ParallelDescriptor::ReduceIntMin(m_bld_ilo.data(), m_nbld + 1); ParallelDescriptor::ReduceIntMax(m_bld_ihi.data(), m_nbld + 1);
527  ParallelDescriptor::ReduceIntMin(m_bld_jlo.data(), m_nbld + 1); ParallelDescriptor::ReduceIntMax(m_bld_jhi.data(), m_nbld + 1);
528  // The column labels, by which a refined level finds its buildings in the
529  // level below (map_buildings_to_level0()), are kept until then.
530  m_to_lev0.resize(m_nbld + 1);
531  for (int b = 0; b <= m_nbld; ++b) { m_to_lev0[b] = b; }
532  tops.clear();
533  piece_of.clear();
534 
535  // The ray map of this rank, from the level's own columns; a refined
536  // level rebuilds it with the levels below (add_outside_occluders()).
537  build_ray_map({});
538  if (m_params.debug) {
539  Print() << "[IBSEB DEBUG] lev=" << m_lev << " buildings labelled in " << n_rounds << " exchange round(s)\n";
540  }
541  if (m_lev == 0) { warn_fixed_sun_below_floor(); }
542 
543  // Static totals: per direction, per building, and the summed area.
544  std::vector<Long> nd(3, 0);
545  std::vector<Long> bn(m_nbld + 1, 0);
546  std::vector<Real> ba(m_nbld + 1, 0.0);
547  Real area = 0.0;
548  for (int n = 0; n < m_nface; ++n) {
549  nd[h_dir[n]] += 1;
550  bn[h_bid[n]] += 1;
551  ba[h_bid[n]] += h_area[n];
552  area += h_area[n];
553  }
554  ParallelDescriptor::ReduceLongSum(nd.data(), 3);
555  ParallelDescriptor::ReduceLongSum(bn.data(), m_nbld + 1);
556  ParallelDescriptor::ReduceRealSum(ba.data(), m_nbld + 1);
557  ParallelDescriptor::ReduceRealSum(area);
558  for (int d = 0; d < 3; ++d) { m_nface_dir[d] = nd[d]; }
559  m_bld_nface = bn;
560  m_bld_area = ba;
561  m_area_total = area;
562 
563  // Device arrays. The state starts uniform at T_skin_init (the slab too;
564  // the interior boundary is applied when the slab is advanced); the view
565  // fractions and fluxes start at zero and are filled by
566  // compute_view_fractions() and the per-step routines.
567  const size_t nf = static_cast<size_t>(m_nface);
568  upload(d_i, h_i); upload(d_j, h_j); upload(d_k, h_k);
569  upload(d_dir, h_dir); upload(d_side, h_side); upload(d_bid, h_bid);
570  upload(d_area, h_area);
571  upload(d_xf, h_xf); upload(d_yf, h_yf); upload(d_zf, h_zf);
572  fill(d_mat, nf, 0);
575  fill(d_kth, nf, m_params.k_therm);
576  fill(d_rhocp, nf, m_params.rho_cp);
579  fill(d_T_slab, nf * static_cast<size_t>(n_layers()), m_params.T_skin_init);
580  // View fractions: placeholders (a roof sees the whole sky, a wall half sky
581  // and half ground) that compute_view_fractions() replaces at initialization.
582  {
583  std::vector<Real> fs(nf), fg(nf), fb(nf, 0.0);
584  for (size_t n = 0; n < nf; ++n) {
585  const bool roof = (h_dir[n] == 2);
586  fs[n] = roof ? 1.0 : 0.5;
587  fg[n] = roof ? 0.0 : 0.5;
588  }
589  upload(d_f_sky, fs); upload(d_f_ground, fg); upload(d_f_bldg, fb);
590  }
591  fill(d_f_ground_lit, nf, Real(0.0));
592  // No ground landings until build_ground_landings() has run.
593  fill(d_gnd_start, nf + 1, 0);
594  fill(d_gnd_far, nf, 0);
595  d_gnd_land.clear();
596  d_gnd_rays.clear();
597  d_roof_face.clear();
598  m_roof_fab_start.clear();
599  m_roof_faces_built = false;
600  m_landings_built = false;
601  fill(d_shadow, nf, Real(0.0));
602  fill(d_SW_direct_in, nf, Real(0.0));
603  fill(d_SW_diffuse_in, nf, Real(0.0));
604  fill(d_LW_down_in, nf, Real(0.0));
607  fill(d_rho, nf, Real(1.0));
608  fill(d_U_tan, nf, Real(0.0));
609  fill(d_ustar, nf, Real(0.0));
610  fill(d_SW_abs, nf, Real(0.0));
611  fill(d_LW_net, nf, Real(0.0));
612  fill(d_H, nf, Real(0.0));
613  fill(d_LE, nf, Real(0.0));
614  fill(d_G, nf, Real(0.0));
616  fill(d_H_coeff, nf, Real(0.0));
617  fill(d_w_star, nf, Real(0.0));
618  fill(d_olen, nf, Real(1.0e30));
619  fill(d_z_i, nf, Real(0.0));
620  fill(d_LW_ext, nf, Real(0.0));
621  fill(d_resid, nf, Real(0.0));
622  fill(d_niter, nf, 0);
623  Gpu::streamSynchronize();
624 
626 }
GpuArray< Real, AMREX_SPACEDIM > plo
Definition: ERF_ActuatorSpreading.cpp:131
const Real lx
Definition: ERF_InitCustomPertVels_CloudChamber.H:10
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
const Real ly
Definition: ERF_InitCustomPertVels_CloudChamber.H:11
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
amrex::Gpu::DeviceVector< amrex::Real > d_resid
|balance| after the solve [W/m2]
Definition: ERF_IBFaceSet.H:586
amrex::Gpu::DeviceVector< amrex::Real > d_theta_air
Potential temperature of the fluid cell [K].
Definition: ERF_IBFaceSet.H:574
amrex::Gpu::DeviceVector< int > d_gnd_rays
Definition: ERF_IBFaceSet.H:554
std::vector< int > m_bld_jhi
Definition: ERF_IBFaceSet.H:678
amrex::Gpu::DeviceVector< amrex::Real > d_f_ground_lit
Definition: ERF_IBFaceSet.H:549
amrex::Gpu::DeviceVector< amrex::Real > d_hbld
Height of the face's building column [m].
Definition: ERF_IBFaceSet.H:580
int m_ny
Definition: ERF_IBFaceSet.H:688
amrex::Gpu::DeviceVector< amrex::Real > d_shadow
1 when the ray to the sun hits a building, else 0
Definition: ERF_IBFaceSet.H:567
amrex::Gpu::DeviceVector< amrex::Real > d_yf
Definition: ERF_IBFaceSet.H:540
amrex::iMultiFab m_lab
Definition: ERF_IBFaceSet.H:684
std::vector< amrex::Long > m_bld_ncol
Definition: ERF_IBFaceSet.H:677
amrex::Gpu::DeviceVector< amrex::Real > d_SW_abs
Definition: ERF_IBFaceSet.H:564
amrex::Real m_col_top_max
Tallest column the ray map holds [m] (the levels below included after add_outside_occluders())
Definition: ERF_IBFaceSet.H:693
void print_debug_summary() const
Definition: ERF_IBFaceSet.cpp:2095
amrex::Gpu::DeviceVector< int > d_gnd_start
Definition: ERF_IBFaceSet.H:554
amrex::Gpu::DeviceVector< amrex::Real > d_LW_ext
Incoming longwave from sky and ground only [W/m2].
Definition: ERF_IBFaceSet.H:585
bool m_per_x
Definition: ERF_IBFaceSet.H:692
amrex::Long m_nface_dir[3]
Faces per direction.
Definition: ERF_IBFaceSet.H:674
std::vector< int > m_bld_jlo
Definition: ERF_IBFaceSet.H:678
int m_nz
Cells of the domain in x, y and z.
Definition: ERF_IBFaceSet.H:688
amrex::Gpu::DeviceVector< amrex::Real > d_w_star
Convective velocity scale of the step [m/s].
Definition: ERF_IBFaceSet.H:581
amrex::Gpu::DeviceVector< amrex::Real > d_rho
Density of the fluid cell [kg/m3].
Definition: ERF_IBFaceSet.H:575
amrex::Gpu::DeviceVector< amrex::Real > d_T_skin
Skin temperature [K].
Definition: ERF_IBFaceSet.H:542
amrex::Gpu::DeviceVector< amrex::Real > d_LW_net
Definition: ERF_IBFaceSet.H:564
amrex::Gpu::DeviceVector< amrex::Real > d_z_i
Depth in w* [m]: mixed layer above a roof, building height for a wall.
Definition: ERF_IBFaceSet.H:583
amrex::Gpu::DeviceVector< int > d_side
Solid neighbor at -1 (low) or +1 (high) side.
Definition: ERF_IBFaceSet.H:534
int m_top_sample
Highest interface a face samples, over all ranks (-1: no faces)
Definition: ERF_IBFaceSet.H:667
std::vector< amrex::Real > m_bld_area
Face area per building [m2].
Definition: ERF_IBFaceSet.H:673
amrex::Gpu::DeviceVector< unsigned int > d_gnd_land
Definition: ERF_IBFaceSet.H:555
amrex::Gpu::DeviceVector< int > d_niter
Newton iterations of the last solve.
Definition: ERF_IBFaceSet.H:587
amrex::Gpu::DeviceVector< amrex::Real > d_SW_diffuse_in
Sky and ground-reflected diffuse incident.
Definition: ERF_IBFaceSet.H:569
amrex::Gpu::DeviceVector< amrex::Real > d_f_sky
Definition: ERF_IBFaceSet.H:545
amrex::iMultiFab m_col_valid
Definition: ERF_IBFaceSet.H:594
amrex::Gpu::DeviceVector< amrex::Real > d_olen
Obukhov length used [m] (1e30 when neutral)
Definition: ERF_IBFaceSet.H:582
amrex::Real m_z_ground
Ground height [m] (flat, the domain bottom)
Definition: ERF_IBFaceSet.H:694
amrex::Gpu::DeviceVector< int > d_dir
Face direction: 0 x, 1 y, 2 z.
Definition: ERF_IBFaceSet.H:533
amrex::Gpu::DeviceVector< amrex::Real > d_f_bldg
Definition: ERF_IBFaceSet.H:545
std::vector< int > m_bld_ilo
Definition: ERF_IBFaceSet.H:678
amrex::Gpu::DeviceVector< amrex::Real > d_T_slab
Slab layers [K], face-major: [face * n_layers + layer].
Definition: ERF_IBFaceSet.H:543
int n_layers() const
Definition: ERF_IBFaceSet.H:203
amrex::Real m_y_lo
Domain origin [m].
Definition: ERF_IBFaceSet.H:690
amrex::Gpu::DeviceVector< amrex::Real > d_SW_direct_in
Direct beam incident on the face.
Definition: ERF_IBFaceSet.H:568
amrex::Gpu::DeviceVector< amrex::Real > d_G
Definition: ERF_IBFaceSet.H:564
amrex::Gpu::DeviceVector< amrex::Real > d_T_air
Air temperature of the fluid cell.
Definition: ERF_IBFaceSet.H:572
amrex::Gpu::DeviceVector< amrex::Real > d_Q_ext
External incident flux [W/m2], e.g. fire radiation.
Definition: ERF_IBFaceSet.H:565
amrex::Real m_area_total
Total face area [m2].
Definition: ERF_IBFaceSet.H:675
bool m_landings_built
build_ground_landings() has run since build()
Definition: ERF_IBFaceSet.H:561
bool m_per_y
Periodicity in x and y.
Definition: ERF_IBFaceSet.H:692
amrex::Gpu::DeviceVector< amrex::Real > d_f_ground
Definition: ERF_IBFaceSet.H:545
int m_nx
Definition: ERF_IBFaceSet.H:688
bool m_roof_faces_built
d_roof_face has been built since build()
Definition: ERF_IBFaceSet.H:558
amrex::Gpu::DeviceVector< amrex::Real > d_LE
Definition: ERF_IBFaceSet.H:564
amrex::Gpu::DeviceVector< amrex::Real > d_H_coeff
H = H_coeff (theta_skin - theta_air) [W/m2/K].
Definition: ERF_IBFaceSet.H:578
int m_nbld
Buildings of the level (global)
Definition: ERF_IBFaceSet.H:668
amrex::Real m_dx[3]
Cell sizes [m].
Definition: ERF_IBFaceSet.H:691
amrex::Gpu::DeviceVector< amrex::Real > d_xf
Definition: ERF_IBFaceSet.H:540
amrex::Gpu::DeviceVector< amrex::Real > d_zf
Face center [m].
Definition: ERF_IBFaceSet.H:540
amrex::Gpu::DeviceVector< int > d_gnd_far
Definition: ERF_IBFaceSet.H:554
std::vector< int > m_roof_fab_start
fill_roofs(): fab n owns the entries [m_roof_fab_start[n], m_roof_fab_start[n+1]) of d_roof_face
Definition: ERF_IBFaceSet.H:557
amrex::Geometry m_geom
Geometry of the level.
Definition: ERF_IBFaceSet.H:687
std::vector< amrex::Long > m_bld_nface
Faces per building.
Definition: ERF_IBFaceSet.H:672
amrex::Gpu::DeviceVector< amrex::Real > d_LW_down_in
Incoming longwave on the face (sky, ground and walls)
Definition: ERF_IBFaceSet.H:571
amrex::IntVect m_dom_lo
Low corner of the level's domain.
Definition: ERF_IBFaceSet.H:689
std::vector< int > m_bld_ihi
Definition: ERF_IBFaceSet.H:678
amrex::Gpu::DeviceVector< int > d_roof_face
fill_roofs(): the roof faces (indices into the face arrays), fab by fab
Definition: ERF_IBFaceSet.H:556
amrex::Real m_x_lo
Definition: ERF_IBFaceSet.H:690
amrex::Gpu::DeviceVector< amrex::Real > d_ustar
Friction velocity of the wall function [m/s].
Definition: ERF_IBFaceSet.H:577
amrex::Gpu::DeviceVector< amrex::Real > d_U_tan
Tangential wind speed at the fluid cell [m/s].
Definition: ERF_IBFaceSet.H:576
@ fi
Definition: ERF_AdvanceMorrison.cpp:109
@ fs
Definition: ERF_AdvanceMorrison.cpp:124
@ fg
Definition: ERF_AdvanceMorrison.cpp:111
@ ni
Definition: ERF_Morrison.H:49
@ qi
Definition: ERF_Morrison.H:111
@ q
Definition: ERF_WSM6.H:296
@ t
Definition: ERF_WSM6.H:295
@ p
Definition: ERF_WSM6.H:303
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19
void fill(MultiFab &dst, int temperature_comp, int mixing_ratio_comp, int source_comp, const Sources &sources, Real missing_value)
Definition: ERF_NearSurfaceDiagnostics.cpp:42
amrex::Real Q_ext_uniform
Uniform external incident flux on every face [W/m2] (test hook)
Definition: ERF_IBSEBParams.H:178
amrex::Real k_therm
Uniform conductivity [W/m/K].
Definition: ERF_IBSEBParams.H:160
amrex::Real rho_cp
Uniform volumetric heat capacity [J/m3/K].
Definition: ERF_IBSEBParams.H:161
amrex::Real thickness
Uniform slab thickness [m].
Definition: ERF_IBSEBParams.H:162
amrex::Real albedo
Face shortwave albedo.
Definition: ERF_IBSEBParams.H:77
amrex::Real T_skin_init
Initial skin temperature [K].
Definition: ERF_IBSEBParams.H:28
amrex::Real emissivity
Face longwave emissivity.
Definition: ERF_IBSEBParams.H:79
Here is the call graph for this function:

◆ build_ground_landings()

void IBFaceSet::build_ground_landings ( )

For erf.ibseb.ground_view_shadow: keep, for every face, the columns its ground rays land in (the rays of compute_view_fractions(), which calls this), so that each step only the rays from those columns toward the sun are cast (ibseb::ground_view_lit()). The distinct columns are kept with the number of rays that land in each, 8 bytes per column. Found in one pass over the rays, so the columns and the counts cannot disagree.

Where every face's ground rays land (see the header). One pass over the rays of the view fractions writes one word per ray (ibseb::ray_landing_word()); on the host each face's words are sorted and the equal ones counted, which gives the distinct landing columns, the rays in each, and the rays to the far field. The faces go through in batches so the words of the pass never take more than about 16 MB.

952 {
953  const int n_az = m_params.view_n_az, n_el = m_params.view_n_el;
954  const int n_rays = n_az * n_el;
955  const ibseb::RayMap rm = ray_map();
956  const int* pd = d_dir.data(); const int* ps = d_side.data();
957  const int* pi = d_i.data(); const int* pj = d_j.data();
958  const Real* pxf = d_xf.data(); const Real* pyf = d_yf.data(); const Real* pzf = d_zf.data();
959  std::vector<int> start(static_cast<size_t>(m_nface) + 1, 0), far_rays(m_nface, 0), rays;
960  std::vector<unsigned int> land;
961  const int batch = amrex::max(1, (1 << 22) / n_rays);
962  Gpu::DeviceVector<unsigned int> d_word;
963  std::vector<unsigned int> word;
964  Long n_kept = 0;
965  for (int f0 = 0; f0 < m_nface; f0 += batch) {
966  const int nb = amrex::min(batch, m_nface - f0);
967  d_word.resize(static_cast<size_t>(nb) * n_rays);
968  unsigned int* pword = d_word.data();
969  ParallelFor(nb, [=] AMREX_GPU_DEVICE (int m) noexcept {
970  const int f = f0 + m;
971  unsigned int* w = pword + static_cast<Long>(m) * n_rays;
972  for (int ie = 0; ie < n_el; ++ie) {
973  for (int ia = 0; ia < n_az; ++ia) {
974  Real sx, sy, sz;
975  ibseb::hemisphere_direction(pd[f], -ps[f], ia, ie, n_az, n_el, sx, sy, sz);
976  w[ie * n_az + ia] = ibseb::ray_landing_word(pxf[f], pyf[f], pzf[f], sx, sy, sz, rm, pi[f], pj[f]);
977  }
978  }
979  });
980  Gpu::streamSynchronize();
981  word.resize(d_word.size());
982  Gpu::copy(Gpu::deviceToHost, d_word.begin(), d_word.end(), word.begin());
983  Gpu::streamSynchronize();
984  for (int m = 0; m < nb; ++m) {
985  const int f = f0 + m;
986  unsigned int* w = word.data() + static_cast<size_t>(m) * n_rays;
987  std::sort(w, w + n_rays);
988  for (int n = 0; n < n_rays; ++n) {
989  if (w[n] == ibseb::landing_none) { continue; }
990  if (w[n] == ibseb::landing_far) { ++far_rays[f]; continue; }
991  ++n_kept;
992  if (n > 0 && w[n] == w[n - 1]) { ++rays.back(); }
993  else { land.push_back(w[n]); rays.push_back(1); }
994  }
995  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(land.size() < static_cast<size_t>(std::numeric_limits<int>::max()),
996  "erf.ibseb.ground_view_shadow: more ground landings on one rank than an int counts;"
997  " lower erf.ibseb.view_n_az / view_n_el or use more ranks");
998  start[f + 1] = static_cast<int>(land.size());
999  }
1000  }
1001  upload(d_gnd_start, start);
1002  upload(d_gnd_far, far_rays);
1003  upload(d_gnd_land, land);
1004  upload(d_gnd_rays, rays);
1005  Gpu::streamSynchronize();
1006  m_landings_built = true;
1007 
1008  if (m_params.debug) {
1009  Long sums[3] = {static_cast<Long>(land.size()), n_kept, 0};
1010  for (int n = 0; n < m_nface; ++n) { sums[2] += far_rays[n]; }
1011  ParallelDescriptor::ReduceLongSum(sums, 3);
1012  Print() << "[IBSEB DEBUG] lev=" << m_lev << " ground view shadow: " << sums[1] << " ground rays land in "
1013  << sums[0] << " columns kept (" << sums[0] * Long(sizeof(unsigned int) + sizeof(int)) << " bytes), "
1014  << sums[2] << " ground rays to the far field\n";
1015  }
1016 }
int start
Definition: ERF_ActuatorSpreading.cpp:263
ibseb::RayMap ray_map() const
Definition: ERF_IBFaceSet.cpp:783
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE unsigned int ray_landing_word(amrex::Real x0, amrex::Real y0, amrex::Real z0, amrex::Real sx, amrex::Real sy, amrex::Real sz, const RayMap &m, int ci_f, int cj_f)
Definition: ERF_IBSEBSolar.H:586
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void hemisphere_direction(int dir, int nsign, int ia, int ie, int n_az, int n_el, amrex::Real &sx, amrex::Real &sy, amrex::Real &sz)
Definition: ERF_IBSEBSolar.H:524
constexpr unsigned int landing_none
The ray does not end on the ground.
Definition: ERF_IBSEBSolar.H:551
constexpr unsigned int landing_far
The ray ends on the far field's open ground.
Definition: ERF_IBSEBSolar.H:552
int view_n_az
Definition: ERF_IBSEBParams.H:104
int view_n_el
Definition: ERF_IBSEBParams.H:105
Definition: ERF_IBSEBSolar.H:219
Here is the call graph for this function:

◆ build_ray_map()

void IBFaceSet::build_ray_map ( const std::vector< const IBFaceSet * > &  below)

Build the ray map (m_ray_patch) from m_col_valid and the levels below. The halo is sized for the shallowest ray the map must follow to its end: the shallowest ray of the hemisphere sampling (ibseb::hemisphere_min_sz()) and a sun erf.ibseb.sun_min_elev_deg above the horizon, over the tallest column of this level and the levels below, height / tan(elevation) cells in x and in y (ibseb::ray_halo_cells()). A rising ray stops above the tallest column and a falling one at the ground, so within that reach the walk is exact, and beyond it only a sun lower than the floor is concerned, whose direct beam the clear-sky attenuation has all but removed; a building farther than the halo from a face then casts no shadow on it (the far field is open ground). The patch is this rank's boxes grown by the halo, clipped to the domain where it is not periodic and, where it is, reduced to one domain width when the grown box is at least that wide, in which case the walk wraps round and is exact for any reach.

Parameters
belowFace sets of the levels below (empty on level 0), each with its build() done.

Public because it launches a GPU lambda, which nvcc rejects in a private member function.

The ray map of this rank (see the header): the halo, this rank's patch, every rank's patch as one box array, and its contents from the levels below (coarsest first, so the finest level that covers a column has the last word) and then this level's own columns with their periodic images.

636 {
637  const Box& domain = m_geom.Domain();
638  // The tallest column of this level and of the levels below: the height
639  // a rising ray stops at, and what sizes the halo.
640  Real z_max = m_col_top_max;
641  for (const IBFaceSet* c : below) {
642  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(c->m_col_valid.ok(), "erf.ibseb: a level below has not been built");
643  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(c->m_geom.Domain().smallEnd(2) == domain.smallEnd(2) && c->m_z_ground == m_z_ground,
644  "erf.ibseb: the levels do not share the ground");
645  z_max = std::max(z_max, c->m_col_top_max);
646  }
647  m_col_top_max = z_max;
648  // The shallowest ray the map follows to its end: the hemisphere's and the
649  // sun's floor; the halo is its horizontal reach over the tallest column.
651  const Real sz_sun = std::sin(m_params.sun_min_elev_deg * PI / 180.0);
652  const Real sz_min = std::min(sz_view, sz_sun);
653  const Real height = z_max - m_z_ground;
654  const int halo[2] = { ibseb::ray_halo_cells(height, m_dx[0], sz_min), ibseb::ray_halo_cells(height, m_dx[1], sz_min) };
655  // The columns a ray at the floor can cross in x plus in y: what a walk is
656  // followed for, however the patch is cut or wrapped.
657  m_max_steps = static_cast<int>(std::min(Long(std::numeric_limits<int>::max() / 2), Long(halo[0]) + Long(halo[1])));
658  m_reach[0] = halo[0];
659  m_reach[1] = halo[1];
660 
661  // This rank's patch: its boxes grown by the halo. A halo wider than the
662  // domain adds nothing beyond one domain width: where the direction is
663  // periodic the patch is then the whole domain, wrapped; where it is not
664  // the patch stops at the domain's edge.
665  Box bbox;
666  for (MFIter mfi(m_col_valid); mfi.isValid(); ++mfi) {
667  if (bbox.ok()) { bbox.minBox(mfi.validbox()); } else { bbox = mfi.validbox(); }
668  }
669  Box patch;
670  m_wrap_x = m_wrap_y = false;
671  bool spans = true;
672  for (int d = 0; d < 2; ++d) { m_halo[d] = std::min(halo[d], domain.length(d)); }
673  m_halo[2] = 0;
674  if (bbox.ok()) {
675  patch = bbox;
676  for (int d = 0; d < 2; ++d) {
677  patch.grow(d, m_halo[d]);
678  if (m_geom.isPeriodic(d)) {
679  if (patch.length(d) >= domain.length(d)) {
680  patch.setRange(d, domain.smallEnd(d), domain.length(d));
681  (d == 0 ? m_wrap_x : m_wrap_y) = true;
682  }
683  } else {
684  patch.setSmall(d, std::max(patch.smallEnd(d), domain.smallEnd(d)));
685  patch.setBig(d, std::min(patch.bigEnd(d), domain.bigEnd(d)));
686  }
687  spans = spans && (patch.smallEnd(d) == domain.smallEnd(d) && patch.length(d) == domain.length(d));
688  }
689  }
690  m_patch_box = patch;
691  ParallelDescriptor::ReduceBoolAnd(spans);
692  m_map_spans_domain = spans;
693 
694  // Every rank's patch, one box each for the ranks that have boxes.
695  std::vector<int> mine;
696  if (patch.ok()) {
697  mine = { patch.smallEnd(0), patch.smallEnd(1), patch.smallEnd(2),
698  patch.bigEnd(0), patch.bigEnd(1), patch.bigEnd(2), ParallelDescriptor::MyProc() };
699  }
700  const std::vector<int> all = all_gather(mine);
701  BoxList bl;
702  Vector<int> pmap;
703  for (size_t n = 0; n + 7 <= all.size(); n += 7) {
704  bl.push_back(Box(IntVect(all[n], all[n + 1], all[n + 2]), IntVect(all[n + 3], all[n + 4], all[n + 5])));
705  pmap.push_back(all[n + 6]);
706  }
707  m_ray_patch.clear();
708  m_gnd_patch.clear();
709  m_gnd_patch_built = false;
710  if (bl.isEmpty()) { return; }
711  const BoxArray patch_ba(std::move(bl));
712  const DistributionMapping patch_dm(pmap);
713  m_ray_patch.define(patch_ba, patch_dm, 1, 0);
714  m_ray_patch.setVal(-1);
715 
716  // The levels below: each column of the patch that a level covers takes
717  // that level's top, on the ratio x ratio columns of this level beneath
718  // the coarse one, at the same height; the finest level wins.
719  for (const IBFaceSet* c : below) {
720  const Box& cdom = c->m_geom.Domain();
721  const IntVect ratio(AMREX_D_DECL(domain.length(0) / cdom.length(0), domain.length(1) / cdom.length(1), 1));
722  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ratio[0] * cdom.length(0) == domain.length(0) && ratio[1] * cdom.length(1) == domain.length(1),
723  "erf.ibseb: the domains of the levels are not refinements of one another");
724  iMultiFab crse(amrex::coarsen(patch_ba, ratio), patch_dm, 1, 0);
725  crse.setVal(-2); // -2: that level does not cover the column
726  crse.ParallelCopy(c->m_col_valid, 0, 0, 1, IntVect(0), IntVect(0), c->m_geom.periodicity());
727  const Real dz_c = c->m_dx[2], dz_f = m_dx[2];
728  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(std::abs(dz_c / dz_f - std::round(dz_c / dz_f)) < 1.0e-6,
729  "erf.ibseb: the vertical cell sizes of the levels are not a whole ratio");
730  const int rx = ratio[0], ry = ratio[1];
731  for (MFIter mfi(m_ray_patch); mfi.isValid(); ++mfi) {
732  const Box& pb = mfi.validbox();
733  auto const& p = m_ray_patch.array(mfi);
734  auto const& cr = crse.const_array(mfi);
735  ParallelFor(pb, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
736  const int kc = cr(amrex::coarsen(i, rx), amrex::coarsen(j, ry), k);
737  if (kc == -2) { return; }
738  // The same height here: the top is kc + 1 cells of that level
739  // up, a whole number of cells of this one (rounded to keep it
740  // so whatever the precision of the division).
741  p(i, j, k) = (kc < 0) ? -1 : static_cast<int>((kc + 1) * dz_c / dz_f + Real(0.5)) - 1;
742  });
743  }
744  }
745  // This level's own columns, with their periodic images.
746  m_ray_patch.ParallelCopy(m_col_valid, 0, 0, 1, IntVect(0), IntVect(0), m_geom.periodicity());
747  Gpu::streamSynchronize();
748 
749  if (m_params.debug) {
750  Print() << "[IBSEB DEBUG] lev=" << m_lev << " ray map: halo " << m_halo[0] << " x " << m_halo[1]
751  << " cells for rays " << std::asin(sz_min) * 180.0 / PI << " deg above the horizon over "
752  << height << " m (hemisphere " << std::asin(sz_view) * 180.0 / PI << " deg, sun floor "
753  << m_params.sun_min_elev_deg << " deg); " << (spans ? "every rank's patch spans the domain" : "the patches do not span the domain")
754  << "; " << below.size() << " level(s) below merged\n";
755  std::ostringstream os;
756  os << "[IBSEB DEBUG] lev=" << m_lev << " rank " << ParallelDescriptor::MyProc() << ": ray map patch " << patch
757  << (m_wrap_x ? " wraps in x" : "") << (m_wrap_y ? " wraps in y" : "")
758  << ", " << (patch.ok() ? patch.numPts() * sizeof(int) / 1024.0 : 0.0) << " kB\n";
759  AllPrint() << os.str();
760  }
761 }
Real height
Definition: ERF_InitCustomPert_SquallLine.H:37
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
Definition: ERF_IBFaceSet.H:88
int m_reach[2]
The halo's reach in x and in y before the domain cap [columns].
Definition: ERF_IBFaceSet.H:606
amrex::iMultiFab m_ray_patch
Definition: ERF_IBFaceSet.H:600
amrex::Box m_patch_box
This rank's patch (empty without boxes)
Definition: ERF_IBFaceSet.H:601
amrex::IntVect m_halo
Halo of the patch in cells.
Definition: ERF_IBFaceSet.H:602
int m_max_steps
Columns a walk is followed for: the halo's reach in x plus y, before the domain cap.
Definition: ERF_IBFaceSet.H:605
bool m_wrap_y
The patch spans the periodic domain in x / y.
Definition: ERF_IBFaceSet.H:603
bool m_map_spans_domain
Every rank's patch spans the domain.
Definition: ERF_IBFaceSet.H:604
bool m_gnd_patch_built
m_gnd_patch has been sized since the ray map was built
Definition: ERF_IBFaceSet.H:560
amrex::MultiFab m_gnd_patch
compute_ground_walls(): per rank, the box of the columns its faces' landings reach (k = 0),...
Definition: ERF_IBFaceSet.H:559
bool m_wrap_x
Definition: ERF_IBFaceSet.H:603
amrex::Real hemisphere_min_sz(int n_az, int n_el)
Definition: ERF_IBSEBSolar.H:288
int ray_halo_cells(amrex::Real height, amrex::Real dx, amrex::Real sz_min)
Definition: ERF_IBSEBSolar.H:269
amrex::Real sun_min_elev_deg
Definition: ERF_IBSEBParams.H:75
Here is the call graph for this function:

◆ building_level0()

int IBFaceSet::building_level0 ( int  b) const
inline

Level 0's number for building b of this level (1-based; 0 for one only this level resolves).

180 { return m_to_lev0.at(b); }

◆ check_canopy_layout()

void IBFaceSet::check_canopy_layout ( const amrex::MultiFab &  cons,
const TwoStreamCanopyView &  canopy 
) const

Stop unless the fields of canopy (this level's two-stream view) lie on the columns of cons, with the same distribution: the two-stream kernels read the column of a face from the fabs with the local index of the face's own fab.

The fields of a two-stream view must lie on this level's columns, with the level's distribution, so that the fabs of local index n hold the columns of the faces fab_start()[n] .. fab_start()[n+1]-1 own: the interface fluxes on the level's own grids (with the top-of-atmosphere ghost, which a face whose cell is the top of the domain reads); the beam on its boxes in x and y with the interfaces from the surface up to at least top_sample_interface() in z; the cosine of the zenith on them flattened to index 0 in z.

1133 {
1135  "erf.ibseb.radiation = two_stream: level " + std::to_string(m_lev) + "'s two-stream view is incomplete");
1136  const BoxArray& ba = cons.boxArray();
1137  const DistributionMapping& dm = cons.DistributionMap();
1138  const auto& beam = *canopy.beam;
1139  const auto& cosz = *canopy.cos_zenith;
1140  const auto& flux = *canopy.fluxes;
1141  bool ok = flux.boxArray() == ba && flux.DistributionMap() == dm && flux.nComp() >= 4 && flux.nGrowVect()[2] >= 1 &&
1142  beam.boxArray().size() == ba.size() && beam.DistributionMap() == dm &&
1143  cosz.boxArray().size() == ba.size() && cosz.DistributionMap() == dm;
1144  // Same columns: the boxes agree in x and y.
1145  for (int n = 0; ok && n < static_cast<int>(ba.size()); ++n) {
1146  const Box& b = beam.boxArray()[n];
1147  const Box& c = cosz.boxArray()[n];
1148  for (int d = 0; d < 2; ++d) {
1149  ok = ok && b.smallEnd(d) == ba[n].smallEnd(d) && b.bigEnd(d) == ba[n].bigEnd(d) &&
1150  c.smallEnd(d) == ba[n].smallEnd(d) && c.bigEnd(d) == ba[n].bigEnd(d);
1151  }
1152  // The kernels read the beam at interfaces 0 .. top_sample_interface() and the
1153  // cosine of the zenith at index 0 in z.
1154  ok = ok && b.smallEnd(2) == 0 && b.bigEnd(2) >= top_sample_interface() && c.smallEnd(2) == 0;
1155  }
1157  "erf.ibseb.radiation = two_stream: level " + std::to_string(m_lev) +
1158  "'s two-stream beam, cosine of the zenith or interface fluxes are not laid out on the level's grids");
1159  // The ground's direct-beam albedo, read at index 0 in z of the face's column.
1162  "erf.ibseb.ground_view_shadow with erf.ibseb.radiation = two_stream: level " + std::to_string(m_lev) +
1163  "'s two-stream view holds no direct-beam albedo of the ground");
1164  const auto& alb = *canopy.ground_albedo_dir;
1165  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(alb.nComp() >= 2,
1166  "erf.ibseb.ground_view_shadow with erf.ibseb.radiation = two_stream: level " + std::to_string(m_lev) +
1167  "'s field of the columns' direct-beam albedo holds no second component (the interface each column starts on)");
1168  bool ok_alb = alb.boxArray().size() == ba.size() && alb.DistributionMap() == dm;
1169  for (int n = 0; ok_alb && n < static_cast<int>(ba.size()); ++n) {
1170  const Box& a = alb.boxArray()[n];
1171  for (int d = 0; d < 2; ++d) {
1172  ok_alb = ok_alb && a.smallEnd(d) == ba[n].smallEnd(d) && a.bigEnd(d) == ba[n].bigEnd(d);
1173  }
1174  ok_alb = ok_alb && a.smallEnd(2) == 0;
1175  }
1177  "erf.ibseb.ground_view_shadow with erf.ibseb.radiation = two_stream: level " + std::to_string(m_lev) +
1178  "'s direct-beam albedo of the ground is not laid out on the level's columns");
1179  }
1180 }
int top_sample_interface() const
Definition: ERF_IBFaceSet.H:414
bool ground_view_shadow
Definition: ERF_IBSEBParams.H:89
const amrex::MultiFab * fluxes
Definition: ERF_TwoStreamCanopyForcing.H:48
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
bool valid() const noexcept
Definition: ERF_TwoStreamCanopyForcing.H:54
const amrex::MultiFab * ground_albedo_dir
Definition: ERF_TwoStreamCanopyForcing.H:53
Here is the call graph for this function:

◆ compute_ground()

void IBFaceSet::compute_ground ( amrex::Real  dt)

Ground heat flux of the current step: advance every face's slab by dt with the skin temperature at the top and the interior temperature at the bottom (implicit, ERF_IBSEBSlab.H) and store the conduction into the slab, G, positive into the wall.

Slab conduction on every face: one kernel over the faces, each solving its own tridiagonal system with the skin at the top and the interior at the bottom.

1238 {
1239  const int nl = n_layers();
1240  const Real Tint = m_params.T_interior;
1241  const Real* pT = d_T_skin.data();
1242  const Real* pkt = d_kth.data(); const Real* prc = d_rhocp.data(); const Real* pth = d_thick.data();
1243  Real* pS = d_T_slab.data(); Real* pG = d_G.data();
1244  ParallelFor(m_nface, [=] AMREX_GPU_DEVICE (int f) noexcept {
1245  // Zero-initialized: only the first nl entries are ever used, but the
1246  // compiler cannot see that through the inlined solve and warns otherwise.
1247  Real T[ibseb::SLAB_MAX_LAYERS] = {};
1248  for (int l = 0; l < nl; ++l) { T[l] = pS[f * nl + l]; }
1249  const Real dz = pth[f] / nl;
1250  pG[f] = ibseb::advance_slab_dirichlet(T, pT[f], Tint, pkt[f], prc[f], dz, dt, nl);
1251  for (int l = 0; l < nl; ++l) { pS[f * nl + l] = T[l]; }
1252  });
1253  Gpu::streamSynchronize();
1254 }
@ T
Definition: ERF_IndexDefines.H:180
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real advance_slab_dirichlet(amrex::Real *T, amrex::Real T_skin, amrex::Real T_int, amrex::Real k, amrex::Real rho_cp, amrex::Real dz, amrex::Real dt, int N)
Definition: ERF_IBSEBSlab.H:51
constexpr int SLAB_MAX_LAYERS
Definition: ERF_IBSEBSlab.H:28
amrex::Real T_interior
Interior (deep) temperature [K].
Definition: ERF_IBSEBParams.H:29
Here is the call graph for this function:

◆ compute_ground_shadow()

void IBFaceSet::compute_ground_shadow ( amrex::MultiFab &  shadow) const

The buildings' shadow on the ground of the level, for the two-stream ground balance (erf.ibseb.two_stream_buildings): 1 in a column where the ray from the center of its ground toward the sun of the last compute_shortwave() meets a building (the same column walk as the faces' shadow, ibseb::ray_blocked(), on the rank's ray map, build_ray_map(), with the buildings outside a refined level included and the far field beyond its halo open ground), and where the sun is at or below the horizon; 0 where the sun reaches the ground. A column under a building, or under an overhang, is in shadow. One ray per column, so a column is shaded or not, as a face is.

Parameters
[out]shadowA 2D field (k = 0) on the level's grids flattened in z; its valid cells are written.
1803 {
1804  const Real sx = m_sun.sx, sy = m_sun.sy, sz = m_sun.sz;
1805  // The rank's ray map holds every column of its boxes and the halo a ray from
1806  // them can cross (build_ray_map()), so the walk from a ground center needs no
1807  // communication: the shadow field is on this level's boxes.
1808  const ibseb::RayMap rm = ray_map();
1809  const Real z_ground = m_z_ground;
1810  for (MFIter mfi(shadow); mfi.isValid(); ++mfi) {
1811  const auto out = shadow.array(mfi);
1812  ParallelFor(makeSlab(mfi.validbox(), 2, 0), [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept {
1813  // The start of ibseb::ray_blocked_near(), so the faces' sunlit ground view and
1814  // this shadow are one walk from one point.
1815  out(i, j, 0) = ibseb::ray_blocked(rm.centre_x(i), rm.centre_y(j), z_ground, sx, sy, sz, rm) ? Real(1.0) : Real(0.0);
1816  });
1817  }
1818  Gpu::streamSynchronize();
1819 }
SunState m_sun
Definition: ERF_IBFaceSet.H:695
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool ray_blocked(amrex::Real x0, amrex::Real y0, amrex::Real z0, amrex::Real sx, amrex::Real sy, amrex::Real sz, const RayMap &m)
Definition: ERF_IBSEBSolar.H:387
amrex::Real sy
Definition: ERF_IBFaceSet.H:611
amrex::Real sx
Definition: ERF_IBFaceSet.H:611
amrex::Real sz
Unit vector toward the sun.
Definition: ERF_IBFaceSet.H:611
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real centre_y(int cj) const noexcept
Definition: ERF_IBSEBSolar.H:258
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real centre_x(int ci) const noexcept
Definition: ERF_IBSEBSolar.H:256
Here is the call graph for this function:

◆ compute_ground_walls()

void IBFaceSet::compute_ground_walls ( amrex::MultiFab &  out,
bool  with_view 
)

For erf.ibseb.ground_sky_view: what the walls of this level send to the ground of each column, from the faces' own ground rays (build_ground_landings()). A face of area A_f whose n rays of N land in a column of area A_c sends that column A_f (n / N) J_f of its radiosity J_f, so by the reciprocity of view factors the walls take sum_f A_f n / (N A_c) of that ground's view (GW_VIEW), and the ground receives, per unit of its area, that sum weighted with the faces' reflected shortwave, albedo (SW_direct_in + SW_diffuse_in) (GW_SW), and with their longwave, emissivity sigma T_skin^4 + (1 - emissivity) LW_in (GW_LW), in W/m2. Where the level's columns hold every kept landing (a level that covers the domain) what the faces send through their kept rays is what the ground gets; on a refined level the landings outside its grids are dropped, and rays to the far field are never kept. Each rank adds its faces' shares to the part of its ray-map patch its landings reach (found at the first call) and the parts are summed onto the level's columns, across ranks and periodic edges. Call after compute_shortwave() and compute_longwave() of the step.

Parameters
outthe level's columns (k = 0), GW_NCOMP components, no ghost cells needed
with_viewalso form GW_VIEW, which depends on the geometry alone: true at the first call for a field, false afterwards (GW_VIEW is then left as it is)

What the walls send to the ground of each column (see the header). One kernel over the faces adds each face's share to the columns its ground rays land in, on this rank's box of those columns (atomic adds: several faces land in one column); the boxes are then summed onto the level's columns.

1908 {
1910  "erf.ibseb.ground_sky_view: the walls' share of the ground's view needs the faces' ground landings; call"
1911  " IBFaceSet::compute_view_fractions() first");
1913  "erf.ibseb.ground_sky_view: the field of the walls' share holds fewer than three components");
1914  // The share of the view is the geometry's: formed once per field.
1915  const int c0 = with_view ? GW_VIEW : GW_SW;
1916  const int nc = GW_NCOMP - c0;
1917  out.setVal(0.0, c0, nc, 0);
1918  const ibseb::RayMap rm = ray_map();
1919  if (!m_gnd_patch_built) {
1920  // The columns this rank's landings reach, as one box inside its patch of the ray
1921  // map (a landing is a column of the patch, wrapped where the patch spans the
1922  // domain): found on the host, once. Every rank's box, one each for the ranks that
1923  // have landings, makes the layout the sums are sent from.
1924  std::vector<int> mine;
1925  if (m_nface > 0 && m_patch_box.ok()) {
1926  std::vector<int> hi(m_nface), hj(m_nface), start(static_cast<size_t>(m_nface) + 1);
1927  std::vector<unsigned int> land(d_gnd_land.size());
1928  Gpu::copy(Gpu::deviceToHost, d_i.begin(), d_i.end(), hi.begin());
1929  Gpu::copy(Gpu::deviceToHost, d_j.begin(), d_j.end(), hj.begin());
1930  Gpu::copy(Gpu::deviceToHost, d_gnd_start.begin(), d_gnd_start.end(), start.begin());
1931  Gpu::copy(Gpu::deviceToHost, d_gnd_land.begin(), d_gnd_land.end(), land.begin());
1932  Gpu::streamSynchronize();
1933  Box reached;
1934  for (int f = 0; f < m_nface; ++f) {
1935  for (int n = start[f]; n < start[f + 1]; ++n) {
1936  int di = 0, dj = 0;
1937  ibseb::unpack_landing(land[n], di, dj);
1938  int ci = hi[f] + di, cj = hj[f] + dj;
1939  if (!rm.locate(ci, cj)) { continue; }
1940  const Box col(IntVect(ci, cj, 0), IntVect(ci, cj, 0));
1941  if (reached.ok()) { reached.minBox(col); } else { reached = col; }
1942  }
1943  }
1944  if (reached.ok()) {
1945  mine = { reached.smallEnd(0), reached.smallEnd(1), reached.bigEnd(0), reached.bigEnd(1),
1946  ParallelDescriptor::MyProc() };
1947  }
1948  }
1949  const std::vector<int> all = all_gather(mine);
1950  BoxList bl;
1951  Vector<int> pmap;
1952  for (size_t n = 0; n + 5 <= all.size(); n += 5) {
1953  bl.push_back(Box(IntVect(all[n], all[n + 1], 0), IntVect(all[n + 2], all[n + 3], 0)));
1954  pmap.push_back(all[n + 4]);
1955  }
1956  m_gnd_patch.clear();
1957  if (!bl.isEmpty()) { m_gnd_patch.define(BoxArray(std::move(bl)), DistributionMapping(pmap), GW_NCOMP, 0); }
1958  m_gnd_patch_built = true;
1959  }
1960  // No rank's faces send anything to the ground: the field stays at zero.
1961  if (m_gnd_patch.boxArray().empty()) { return; }
1962  m_gnd_patch.setVal(0.0);
1963  if (m_gnd_patch.local_size() > 0) {
1964  const auto p = m_gnd_patch.array(m_gnd_patch.IndexArray()[0]);
1966  const Real inv_col = Real(1.0) / (m_dx[0] * m_dx[1]);
1967  const Real sigma = ibseb::SIGMA_SB;
1968  const int* pi = d_i.data(); const int* pj = d_j.data();
1969  const int* pgs = d_gnd_start.data(); const int* pgr = d_gnd_rays.data();
1970  const unsigned int* pgl = d_gnd_land.data();
1971  const Real* parea = d_area.data(); const Real* palb = d_albedo.data(); const Real* peps = d_emis.data();
1972  const Real* pdir = d_SW_direct_in.data(); const Real* pdif = d_SW_diffuse_in.data();
1973  const Real* pT = d_T_skin.data(); const Real* plw = d_LW_down_in.data();
1974  ParallelFor(m_nface, [=] AMREX_GPU_DEVICE (int f) noexcept {
1975  if (pgs[f + 1] == pgs[f]) { return; }
1976  // The face's radiosity: the shortwave it reflects and the longwave it emits and reflects.
1977  const Real j_sw = palb[f] * (pdir[f] + pdif[f]);
1978  const Real j_lw = peps[f] * sigma * pT[f] * pT[f] * pT[f] * pT[f] + (Real(1.0) - peps[f]) * plw[f];
1979  const Real per_ray = parea[f] * inv_ray * inv_col;
1980  for (int n = pgs[f]; n < pgs[f + 1]; ++n) {
1981  int di = 0, dj = 0;
1982  ibseb::unpack_landing(pgl[n], di, dj);
1983  int ci = pi[f] + di, cj = pj[f] + dj;
1984  // A kept landing is a column of the map (wrapped where the patch spans the domain).
1985  if (!rm.locate(ci, cj)) { continue; }
1986  const Real w = per_ray * static_cast<Real>(pgr[n]);
1987  if (with_view) { HostDevice::Atomic::Add(&p(ci, cj, 0, GW_VIEW), w); }
1988  HostDevice::Atomic::Add(&p(ci, cj, 0, GW_SW), w * j_sw);
1989  HostDevice::Atomic::Add(&p(ci, cj, 0, GW_LW), w * j_lw);
1990  }
1991  });
1992  Gpu::streamSynchronize();
1993  }
1994  out.ParallelAdd(m_gnd_patch, c0, c0, nc, IntVect(0), IntVect(0), m_geom.periodicity());
1995 }
amrex::Real sigma
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:11
@ nc
Definition: ERF_Morrison.H:47
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void unpack_landing(unsigned int w, int &di, int &dj) noexcept
Definition: ERF_IBSEBSolar.H:572
constexpr amrex::Real SIGMA_SB
Stefan-Boltzmann constant [W/m2/K4].
Definition: ERF_IBSEBBalance.H:54
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real hemisphere_ray_weight(int n_az, int n_el) noexcept
Definition: ERF_IBSEBSolar.H:303
real(c_double), private ci
Definition: ERF_module_mp_morr_two_moment.F90:203
real(c_double), private di
Definition: ERF_module_mp_morr_two_moment.F90:203
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool locate(int &ci, int &cj) const noexcept
Definition: ERF_IBSEBSolar.H:233
Here is the call graph for this function:

◆ compute_longwave()

void IBFaceSet::compute_longwave ( const amrex::MultiFab &  cons,
const TwoStreamCanopyView &  canopy = TwoStreamCanopyView{} 
)

Longwave of the current step. Incoming on a face: f_sky LW_sky + f_ground LW_ground + f_bldg sigma T_skin^4, the sky term fixed or gray (sky_emissivity sigma T_air^4 with the air temperature of the face's fluid cell, its water vapor included) with the ground term eps_g sigma T_g^4, or with lw_mode = two_stream the longwave down and up at the face's height in the face's column (canopy); the building term is the isothermal-surroundings approximation. Net: eps (LW_in - sigma T_skin^4), positive into the face.

Parameters
consConserved state of the level, for the air temperature.
canopyWith lw_mode = two_stream, this step's two-stream view of the level (ERF_TwoStreamCanopyForcing.H), or an empty one before the first sweep, when the incoming and net longwave are zero.

Longwave of the current step. One kernel per fab over that fab's faces, reading the air temperature of the fluid cell from the conserved state (dry density, potential temperature and, with a moisture model, water vapor through the equation of state; cell_qv()). With lw_mode = two_stream the sky and ground terms come from the canopy forcing of the face's column, read from the 2D fab of the same local index (the level's grids flattened, on the same distribution).

1029 {
1030  if (m_params.lw_mode == "two_stream") {
1032  return;
1033  }
1034  const Real sigma = ibseb::SIGMA_SB;
1035  const bool gray = (m_params.lw_mode == "gray");
1036  const Real lw_fix = m_params.lw_down, eps_sky = m_params.sky_emissivity;
1037  const Real eps_g = m_params.emissivity_ground;
1038  const Real* peps = d_emis.data();
1039  const Real Tg4 = std::pow(m_params.T_ground, 4);
1040  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
1041  const Real* pfs = d_f_sky.data(); const Real* pfg = d_f_ground.data(); const Real* pfb = d_f_bldg.data();
1042  const Real* pT = d_T_skin.data();
1043  Real* pTa = d_T_air.data(); Real* pin = d_LW_down_in.data(); Real* pnet = d_LW_net.data();
1044  Real* pext = d_LW_ext.data();
1045  const int qv_comp = m_qv_comp;
1046  for (MFIter mfi(cons); mfi.isValid(); ++mfi) {
1047  const int f0 = m_fab_start[mfi.LocalIndex()];
1048  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
1049  auto const& c = cons.const_array(mfi);
1050  ParallelFor(f1 - f0, [=] AMREX_GPU_DEVICE (int m) noexcept {
1051  const int f = f0 + m;
1052  const Real rho = c(pi[f], pj[f], pk[f], Rho_comp);
1053  const Real qv = cell_qv(c, pi[f], pj[f], pk[f], qv_comp);
1054  const Real Ta = getTgivenRandRTh(rho, c(pi[f], pj[f], pk[f], RhoTheta_comp), qv);
1055  const Real lw_sky = gray ? eps_sky * sigma * Ta * Ta * Ta * Ta : lw_fix;
1056  const Real Ts4 = pT[f] * pT[f] * pT[f] * pT[f];
1057  // Sky and ground do not depend on the face; the wall term does
1058  // (isothermal surroundings), so the balance keeps them apart.
1059  const Real lw_ext = pfs[f] * lw_sky + pfg[f] * eps_g * sigma * Tg4;
1060  const Real lw_in = lw_ext + pfb[f] * sigma * Ts4;
1061  pTa[f] = Ta;
1062  pext[f] = lw_ext;
1063  pin[f] = lw_in;
1064  pnet[f] = peps[f] * (lw_in - sigma * Ts4);
1065  });
1066  }
1067  Gpu::streamSynchronize();
1068 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:46
#define Rho_comp
Definition: ERF_IndexDefines.H:61
void compute_longwave_two_stream(const amrex::MultiFab &cons, const TwoStreamCanopyView &canopy)
Definition: ERF_IBFaceSet.cpp:1081
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
amrex::Real T_ground
Ground temperature for the ground term [K].
Definition: ERF_IBSEBParams.H:129
amrex::Real sky_emissivity
gray: effective clear-sky emissivity
Definition: ERF_IBSEBParams.H:128
std::string lw_mode
Definition: ERF_IBSEBParams.H:114
amrex::Real emissivity_ground
Ground emissivity for the ground term.
Definition: ERF_IBSEBParams.H:80
amrex::Real lw_down
fixed: sky longwave [W/m2]
Definition: ERF_IBSEBParams.H:127
Here is the call graph for this function:

◆ compute_longwave_two_stream()

void IBFaceSet::compute_longwave_two_stream ( const amrex::MultiFab &  cons,
const TwoStreamCanopyView &  canopy 
)

Longwave of the current step with lw_mode = two_stream: the sky term is the longwave down of the face's column at the face's height (a roof's interface, a wall's mean of its cell's two; two_stream_canopy_sample()), the ground term its longwave up at the same height (the ground seen through the air in between), so the ground's temperature, emissivity and reflection of the sky are the column's (two_stream_face_sky()). Before the level's first sweep (an empty canopy, the initial report) the air temperature is read and the incoming and net longwave are zero.

1082 {
1083  const Real sigma = ibseb::SIGMA_SB;
1084  const bool have = canopy.valid();
1085  const int k0 = m_dom_lo[2];
1086  const Real* peps = d_emis.data();
1087  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
1088  const int* pd = d_dir.data(); const int* ps = d_side.data();
1089  const Real* pfs = d_f_sky.data(); const Real* pfg = d_f_ground.data(); const Real* pfb = d_f_bldg.data();
1090  const Real* pT = d_T_skin.data();
1091  Real* pTa = d_T_air.data(); Real* pin = d_LW_down_in.data(); Real* pnet = d_LW_net.data();
1092  Real* pext = d_LW_ext.data();
1093  const int qv_comp = m_qv_comp;
1094  for (MFIter mfi(cons); mfi.isValid(); ++mfi) {
1095  const int f0 = m_fab_start[mfi.LocalIndex()];
1096  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
1097  auto const& c = cons.const_array(mfi);
1098  const auto beam = have ? canopy.beam->const_array(mfi) : Array4<const Real>{};
1099  const auto cosz = have ? canopy.cos_zenith->const_array(mfi) : Array4<const Real>{};
1100  const auto flux = have ? canopy.fluxes->const_array(mfi) : Array4<const Real>{};
1101  ParallelFor(f1 - f0, [=] AMREX_GPU_DEVICE (int m) noexcept {
1102  const int f = f0 + m;
1103  const Real rho = c(pi[f], pj[f], pk[f], Rho_comp);
1104  pTa[f] = getTgivenRandRTh(rho, c(pi[f], pj[f], pk[f], RhoTheta_comp),
1105  cell_qv(c, pi[f], pj[f], pk[f], qv_comp));
1106  if (!have) {
1107  pext[f] = 0.0; pin[f] = 0.0; pnet[f] = 0.0;
1108  return;
1109  }
1110  const Real Ts4 = pT[f] * pT[f] * pT[f] * pT[f];
1111  const TwoStreamFaceSky sky = two_stream_face_sky(pi[f], pj[f], pk[f], k0, pd[f], ps[f], beam, cosz, flux);
1112  const Real lw_ext = pfs[f] * sky.lw_down + pfg[f] * sky.lw_up;
1113  const Real lw_in = lw_ext + pfb[f] * sigma * Ts4;
1114  pext[f] = lw_ext;
1115  pin[f] = lw_in;
1116  pnet[f] = peps[f] * (lw_in - sigma * Ts4);
1117  });
1118  }
1119  Gpu::streamSynchronize();
1120 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TwoStreamFaceSky two_stream_face_sky(int i, int j, int k, int k0, int dir, int side, const amrex::Array4< const amrex::Real > &beam, const amrex::Array4< const amrex::Real > &cosz, const amrex::Array4< const amrex::Real > &fluxes)
The column radiation a face at fluid cell (i,j,k) of direction dir, with its solid on side side,...
Definition: ERF_TwoStreamCanopyForcing.H:150
What one face takes from its column (all W/m^2).
Definition: ERF_TwoStreamCanopyForcing.H:129
amrex::Real lw_up
Longwave up at the face's height (the ground's emission and the air's below)
Definition: ERF_TwoStreamCanopyForcing.H:134
amrex::Real lw_down
Longwave down at the face's height.
Definition: ERF_TwoStreamCanopyForcing.H:132
Here is the call graph for this function:

◆ compute_sensible()

void IBFaceSet::compute_sensible ( const amrex::MultiFab &  cons,
const amrex::MultiFab &  xvel,
const amrex::MultiFab &  yvel,
const amrex::MultiFab &  zvel,
amrex::Real  c_p,
const amrex::MultiFab *  olen_ground = nullptr,
const amrex::MultiFab *  pblh_ground = nullptr,
amrex::Real  z_i_bulk = 0.0 
)

Sensible heat of the current step through a wall function on every face: the tangential wind of the fluid cell at half a cell from the wall gives u* with the roughness z0_wall, the skin-to-air potential-temperature difference gives theta* with z0h_wall, and H = rho c_p u* theta*, positive out of the face. Neutral, or with the surface layer's stability functions on roofs when asked. The latent flux is not modeled and stays zero.

Beyond neutral: with convective_velocity = deardorff the wind is sqrt(U_tan^2 + (beta w*)^2) with w* from the previous step's H (zero when H is into the face) and a depth that is the mixed layer above a roof or the building height for a wall; with stability_correction the roofs are corrected for stability: stability_scheme = iterative iterates the similarity functions on the face's own Obukhov length, seeded from the ground surface layer's 2D field at the face's column when given; louis applies the Louis (1979) factors on the bulk Richardson number between the skin and the cell center, without iteration.

Fills d_H, d_ustar, d_U_tan, d_rho, d_theta_air, d_H_coeff (the coefficient of the skin-to-air potential-temperature difference that the balance keeps frozen), d_w_star, d_olen and d_z_i; T_air was read by compute_longwave(), which must run first in a step.

Parameters
consConserved state of the level (density, rho theta).
xvel,yvel,zvelFace-centered velocities of the level.
c_pSpecific heat of air [J/kg/K].
olen_groundGround surface layer's Obukhov length (2D field on the level's box array collapsed to k = 0), or null.
pblh_groundIts boundary-layer height field, or null.
z_i_bulkMixed-layer depth of the level from the bulk Richardson diagnostic or the fixed input [m].

Wall function on every face. One kernel per fab over that fab's faces: the cell-centered velocity of the fluid cell from its face values, its tangential part with respect to the wall, the neutral log law for u* and theta*, and on request two additions: a convective velocity scale in the wind (Beljaars' gustiness form with Deardorff's w* from the previous step's flux) and, on roofs, the surface layer's similarity functions iterated on the face's own Obukhov length. The skin temperature is converted to a potential temperature with the fluid cell's Exner function before the difference is taken.

The Obukhov length of a face is L = u*^2 theta / (kappa g theta*) (negative over a hot face). Walls stay on the log law even with the stability correction: the similarity functions assume a horizontal surface, and the convective scale is what carries free convection on a wall. The ground's 2D Obukhov field only seeds the roof iteration.

1351 {
1352  const Real z0 = m_params.z0_wall, z0h = m_params.z0h_wall;
1353  const bool stab = m_params.stability_correction;
1354  const bool louis = stab && (m_params.stability_scheme == "louis");
1355  const bool conv = (m_params.convective_velocity == "deardorff");
1356  const bool seed = stab && !louis && (olen_ground != nullptr) && (m_params.obukhov_seed == "ground");
1357  const bool use_pblh = conv && (pblh_ground != nullptr) && (m_params.z_i_mode == "pblh");
1358  const Real beta = m_params.beta_conv;
1359  const Real relax = m_params.obukhov_relax;
1360  const Real zi_fallback = (z_i_bulk > 0.0) ? z_i_bulk : m_params.z_i;
1361  const Real dxa[3] = {m_dx[0], m_dx[1], m_dx[2]};
1362  const Real z_lo = m_z_ground;
1363  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
1364  const int* pd = d_dir.data();
1365  const Real* pT = d_T_skin.data(); const Real* phb = d_hbld.data(); const Real* pzf = d_zf.data();
1366  Real* pth = d_theta_air.data(); Real* prho = d_rho.data(); Real* pU = d_U_tan.data();
1367  Real* pus = d_ustar.data(); Real* pH = d_H.data(); Real* pTa = d_T_air.data();
1368  Real* pHc = d_H_coeff.data(); Real* pws = d_w_star.data(); Real* pol = d_olen.data(); Real* pzi = d_z_i.data();
1369  const int qv_comp = m_qv_comp;
1370  for (MFIter mfi(cons); mfi.isValid(); ++mfi) {
1371  const int f0 = m_fab_start[mfi.LocalIndex()];
1372  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
1373  auto const& c = cons.const_array(mfi);
1374  auto const& u = xvel.const_array(mfi);
1375  auto const& v = yvel.const_array(mfi);
1376  auto const& w = zvel.const_array(mfi);
1377  // The surface layer's 2D fields share the level's distribution with
1378  // the boxes collapsed to k = 0, so the same iterator indexes them.
1379  Array4<const Real> ol = seed ? olen_ground->const_array(mfi) : Array4<const Real>{};
1380  Array4<const Real> pb = use_pblh ? pblh_ground->const_array(mfi) : Array4<const Real>{};
1381  ParallelFor(f1 - f0, [=] AMREX_GPU_DEVICE (int m) noexcept {
1382  const int f = f0 + m;
1383  const int i = pi[f], j = pj[f], k = pk[f], d = pd[f];
1384  const Real rho = c(i, j, k, Rho_comp);
1385  const Real rth = c(i, j, k, RhoTheta_comp);
1386  const Real th = rth / rho;
1387  const Real Ta = getTgivenRandRTh(rho, rth, cell_qv(c, i, j, k, qv_comp));
1388  const Real th_skin = pT[f] * th / Ta; // skin temperature as a potential temperature
1389  // Cell-centered velocity and its tangential part with respect to the wall.
1390  Real U[3] = { Real(0.5) * (u(i, j, k) + u(i + 1, j, k)),
1391  Real(0.5) * (v(i, j, k) + v(i, j + 1, k)),
1392  Real(0.5) * (w(i, j, k) + w(i, j, k + 1)) };
1393  U[d] = 0.0;
1394  const Real Ut = amrex::max(std::sqrt(U[0] * U[0] + U[1] * U[1] + U[2] * U[2]), Real(1.0e-3));
1395  // Convective velocity scale from the previous step's flux out of the face.
1396  Real wstar = 0.0, depth = 0.0;
1397  if (conv && pH[f] > 0.0) {
1398  if (d == 2) {
1399  Real zi = use_pblh ? pb(i, j, 0) : zi_fallback;
1400  if (!(zi > 0.0 && zi < 1.0e5)) { zi = zi_fallback; }
1401  depth = amrex::max(zi - (pzf[f] - z_lo), phb[f]);
1402  } else {
1403  depth = phb[f];
1404  }
1405  wstar = std::cbrt(CONST_GRAV / th * pH[f] / (rho * c_p) * depth);
1406  }
1407  const Real Ut_eff = std::sqrt(Ut * Ut + beta * beta * wstar * wstar);
1408  const Real delta = 0.5 * dxa[d];
1409  const Real lnm = std::log(delta / z0), lnh = std::log(delta / z0h);
1410  Real ustar = KAPPA * Ut_eff / lnm;
1411  Real thstar = KAPPA * (th - th_skin) / lnh;
1412  Real lnh_eff = lnh;
1413  Real olen = 1.0e30;
1414  if (louis && d == 2) {
1415  // Roofs, Louis (1979): explicit factors on the bulk Richardson
1416  // number between the skin and the cell center, no iteration.
1417  // u*^2 = (kappa U / ln(delta/z0))^2 F_m and u* theta* =
1418  // kappa^2 U dtheta F_h / (ln(delta/z0) ln(delta/z0h)), so the
1419  // neutral limit is the two log laws above; the heat law's
1420  // effective logarithm carries both factors.
1421  const Real Rib = CONST_GRAV / th * delta * (th - th_skin) / (Ut_eff * Ut_eff);
1422  Real Fm = 1.0, Fh = 1.0;
1423  ibseb::louis_factors(Rib, delta / z0, KAPPA * KAPPA / (lnm * lnm), Fm, Fh);
1424  ustar = KAPPA * Ut_eff * std::sqrt(Fm) / lnm;
1425  lnh_eff = amrex::max(lnh * std::sqrt(Fm) / Fh, Real(0.1));
1426  thstar = KAPPA * (th - th_skin) / lnh_eff;
1427  olen = ustar * ustar * th / (KAPPA * CONST_GRAV * thstar + 1.0e-20);
1428  } else if (stab && d == 2) {
1429  // Roofs: the surface layer's similarity functions on the
1430  // face's own Obukhov length, a few fixed-point passes, seeded
1431  // from the ground's field at this column when available.
1432  similarity_funs sf;
1433  Real L = 1.0e30;
1434  if (seed) {
1435  const Real Lg = ol(i, j, 0);
1436  if (std::abs(Lg) > 0.0 && std::abs(Lg) < 1.0e5) { L = Lg; }
1437  }
1438  if (!(std::abs(L) < 1.0e5)) {
1439  L = ustar * ustar * th / (KAPPA * CONST_GRAV * thstar + 1.0e-20);
1440  }
1441  // Fixed point on L until u*, theta* and L agree to 1e-6, so
1442  // the stored values are mutually consistent (a fixed number
1443  // of passes leaves L one pass behind). u* is under-relaxed
1444  // between passes, as the surface layer's iteration is in
1445  // erf-model #3486, which keeps a strongly unstable roof from
1446  // oscillating at low wind; the converged values do not
1447  // depend on the factor.
1448  Real us_it = ustar;
1449  for (int it = 0; it < 50; ++it) {
1450  const Real zeta = delta / L;
1451  const Real psi_m = sf.calc_psi_m(zeta), psi_h = sf.calc_psi_h(zeta);
1452  const Real us_new = KAPPA * Ut_eff / amrex::max(lnm - psi_m, Real(0.1));
1453  us_it = (it == 0) ? us_new : (1.0 - relax) * us_it + relax * us_new;
1454  lnh_eff = amrex::max(lnh - psi_h, Real(0.1));
1455  thstar = KAPPA * (th - th_skin) / lnh_eff;
1456  const Real L_new = us_it * us_it * th / (KAPPA * CONST_GRAV * thstar + 1.0e-20);
1457  const bool done = std::abs(L_new - L) <= 1.0e-6 * std::abs(L_new) &&
1458  std::abs(us_new - us_it) <= 1.0e-6 * us_new;
1459  L = L_new;
1460  if (done) { us_it = us_new; break; }
1461  }
1462  ustar = us_it;
1463  olen = L;
1464  }
1465  pth[f] = th;
1466  pTa[f] = Ta;
1467  prho[f] = rho;
1468  pU[f] = Ut;
1469  pus[f] = ustar;
1470  pws[f] = wstar;
1471  pol[f] = olen;
1472  pzi[f] = depth;
1473  pHc[f] = rho * c_p * KAPPA * ustar / lnh_eff; // H = H_coeff (theta_skin - theta_air)
1474  pH[f] = -rho * c_p * ustar * thstar; // positive out of the face
1475  });
1476  }
1477  Gpu::streamSynchronize();
1478 }
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
@ olen
Definition: ERF_SLM.H:106
@ ustar
Definition: ERF_SLM.H:30
@ U
Definition: ERF_IndexDefines.H:178
@ beta
Definition: ERF_SLM.H:154
@ xvel
Definition: ERF_IndexDefines.H:232
@ zvel
Definition: ERF_IndexDefines.H:234
@ yvel
Definition: ERF_IndexDefines.H:233
@ zi
Definition: ERF_AdvanceWDM6.cpp:277
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void louis_factors(amrex::Real Rib, amrex::Real z_over_z0, amrex::Real a2, amrex::Real &Fm, amrex::Real &Fh) noexcept
Definition: ERF_IBSEBWallFunction.H:34
std::string convective_velocity
"none" or "deardorff"
Definition: ERF_IBSEBParams.H:194
std::string stability_scheme
"iterative" or "louis" (with stability_correction)
Definition: ERF_IBSEBParams.H:145
amrex::Real obukhov_relax
Under-relaxation of the roof's u*, theta* iteration (1 = none), as erf-model #3486.
Definition: ERF_IBSEBParams.H:199
amrex::Real z0_wall
Momentum roughness of the faces [m].
Definition: ERF_IBSEBParams.H:142
std::string z_i_mode
"bulk_ri", "pblh" or "fixed"
Definition: ERF_IBSEBParams.H:196
amrex::Real beta_conv
Gustiness factor on w*.
Definition: ERF_IBSEBParams.H:195
amrex::Real z_i
Fixed mixed-layer depth [m] (z_i_mode = fixed, and the fallback)
Definition: ERF_IBSEBParams.H:197
amrex::Real z0h_wall
Heat roughness of the faces [m].
Definition: ERF_IBSEBParams.H:143
bool stability_correction
Definition: ERF_IBSEBParams.H:144
std::string obukhov_seed
"ground" or "neutral"
Definition: ERF_IBSEBParams.H:193
Definition: ERF_MOSTUtils.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_m(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:149
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_h(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:168

◆ compute_shortwave()

void IBFaceSet::compute_shortwave ( amrex::Real  time,
const TwoStreamCanopyView &  canopy = TwoStreamCanopyView{} 
)

Shortwave of the current step: the sun's position (sun_mode), the irradiances of the prescribed provider or, with radiation = two_stream, those of the face's own column at its height (canopy), then per face the direct beam on the face (zero when the ray toward the sun hits a building), the diffuse light through the view fractions, and the absorbed sum.

Fills d_shadow, d_SW_direct_in, d_SW_diffuse_in and d_SW_abs; stores the sun vector and irradiances for the reports (with two_stream the means over all the level's faces of the direct-normal and diffuse irradiance each takes, written to every row of the level).

Parameters
timeSimulation time [s]; with sun_mode = solar it is added to time_zero_utc_s (with sun_mode = two_stream the sun comes from set_two_stream_sun()).
canopyWith radiation = two_stream, this step's two-stream view of the level (see compute_longwave()), or an empty one before the first sweep, when every face gets no shortwave.

Shortwave of the current step. The sun and the irradiances are scalars computed on the host from the provider inputs; the per-face work is one kernel: incidence cosine, ray cast against the column tops, direct and diffuse incident, absorbed.

With sun_mode = fixed the direct-normal irradiance and the horizontal diffuse are the inputs as given. With sun_mode = solar the sun follows the site and time and the clear-sky formulas give both irradiances; with sun_mode = two_stream the position and the top-of-atmosphere irradiance are the two-stream radiation's (set_two_stream_sun()) and the same clear-sky formulas give the irradiances. The sun below the horizon gives zero everywhere.

Diffuse on a face: f_sky * diffuse_h + f_ground * albedo_ground * (direct_h + diffuse_h), the second term being the ground-reflected part, with the direct on a horizontal surface direct_h = dni * cos z. With erf.ibseb.ground_view_shadow the ground reflects the beam through the sunlit part of the face's ground view only (ibseb::ground_view_lit(), kept in d_f_ground_lit): f_sky * diffuse_h + albedo_ground * (f_ground * diffuse_h + f_ground_lit * direct_h), formed as the line above less (f_ground - f_ground_lit) * albedo_ground * direct_h. The view fractions are the placeholders of build() until compute_view_fractions() has run.

1585 {
1586  // ---- Sun and irradiances (host scalars) ----
1587  SunState s = sun_at(time);
1588  // The two-stream sun is used once: the next shortwave needs the sun of its own time.
1589  if (m_params.sun_mode == "two_stream") { m_ts_sun.set = false; }
1590  m_sun = s;
1592  "erf.ibseb.ground_view_shadow: the shortwave needs the faces' ground landings; call"
1593  " IBFaceSet::compute_view_fractions() first");
1594 
1595  if (m_params.radiation == "two_stream") {
1597  return;
1598  }
1599 
1600  // ---- Per face ----
1601  const Real sx = s.sx, sy = s.sy, sz = s.sz;
1602  const Real dni = s.dni, dif_h = s.diffuse_h;
1603  const Real dir_h = dni * amrex::max(Real(0.0), sz);
1604  const Real alb_g = m_params.albedo_ground;
1605  const Real* palb = d_albedo.data();
1606  const ibseb::RayMap rm = ray_map();
1607  const int* pd = d_dir.data(); const int* ps = d_side.data();
1608  const Real* pxf = d_xf.data(); const Real* pyf = d_yf.data(); const Real* pzf = d_zf.data();
1609  const Real* pfs = d_f_sky.data(); const Real* pfg = d_f_ground.data();
1610  Real* psh = d_shadow.data(); Real* pdir = d_SW_direct_in.data();
1611  Real* pdif = d_SW_diffuse_in.data(); Real* pabs = d_SW_abs.data();
1612  // The sunlit part of each face's ground view (erf.ibseb.ground_view_shadow).
1613  const bool lit_ground = m_params.ground_view_shadow;
1615  const int* pi = d_i.data(); const int* pj = d_j.data();
1616  const int* pgs = d_gnd_start.data(); const int* pgf = d_gnd_far.data();
1617  const unsigned int* pgl = d_gnd_land.data(); const int* pgr = d_gnd_rays.data();
1618  Real* pfgl = d_f_ground_lit.data();
1619  ParallelFor(m_nface, [=] AMREX_GPU_DEVICE (int f) noexcept {
1620  // Outward normal: opposite to the side the solid is on.
1621  Real n[3] = {0.0, 0.0, 0.0};
1622  n[pd[f]] = -static_cast<Real>(ps[f]);
1623  const Real cosi = n[0] * sx + n[1] * sy + n[2] * sz;
1624  Real shadow = 0.0, direct = 0.0;
1625  if (sz > 0.0 && cosi > 0.0 && dni > 0.0) {
1626  shadow = ibseb::ray_blocked(pxf[f], pyf[f], pzf[f], sx, sy, sz, rm) ? 1.0 : 0.0;
1627  direct = dni * cosi * (1.0 - shadow);
1628  }
1629  Real diffuse;
1630  if (lit_ground) {
1631  // One ray toward the sun from each column the face's ground rays land in,
1632  // when there is a beam for the ground to reflect.
1633  const Real fgl = (dir_h > 0.0)
1634  ? ibseb::ground_view_lit(pi[f], pj[f], pgf[f], pgl + pgs[f], pgr + pgs[f],
1635  pgs[f + 1] - pgs[f], ray_weight, sx, sy, sz, rm)
1636  : Real(0.0);
1637  pfgl[f] = fgl;
1638  // The uniform ground's light less the beam the shaded part does not reflect:
1639  // a face that sees no shaded ground gets the former to the last bit.
1640  diffuse = pfs[f] * dif_h + pfg[f] * alb_g * (dir_h + dif_h) - (pfg[f] - fgl) * alb_g * dir_h;
1641  } else {
1642  diffuse = pfs[f] * dif_h + pfg[f] * alb_g * (dir_h + dif_h);
1643  }
1644  psh[f] = shadow;
1645  pdir[f] = direct;
1646  pdif[f] = diffuse;
1647  pabs[f] = (1.0 - palb[f]) * (direct + diffuse);
1648  });
1649  Gpu::streamSynchronize();
1650 
1651  if (m_params.debug) {
1652  Print() << "[IBSEB DEBUG] lev=" << m_lev << " sun: zenith=" << s.zenith * 180.0 / PI
1653  << " deg azimuth=" << s.azimuth * 180.0 / PI << " deg s=(" << s.sx << "," << s.sy << "," << s.sz
1654  << ") DNI=" << s.dni << " W/m2 diffuse_h=" << s.diffuse_h << " W/m2\n";
1655  }
1656 }
void compute_shortwave_two_stream(const TwoStreamCanopyView &canopy)
Definition: ERF_IBFaceSet.cpp:1683
SunState sun_at(amrex::Real time) const
The sun at time by erf.ibseb.sun_mode; changes nothing in the set (see the definition).
Definition: ERF_IBFaceSet.cpp:1518
TwoStreamSun m_ts_sun
Definition: ERF_IBFaceSet.H:698
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ground_view_lit(int ci_f, int cj_f, int n_far, const unsigned int *land, const int *rays, int n_land, amrex::Real inv, amrex::Real sx, amrex::Real sy, amrex::Real sz, const RayMap &m)
Definition: ERF_IBSEBSolar.H:629
bool set
Definition: ERF_IBFaceSet.H:697
std::string sun_mode
Definition: ERF_IBSEBParams.H:56
amrex::Real albedo_ground
Ground albedo for the reflected diffuse term.
Definition: ERF_IBSEBParams.H:78
std::string radiation
Definition: ERF_IBSEBParams.H:46
Here is the call graph for this function:

◆ compute_shortwave_two_stream()

void IBFaceSet::compute_shortwave_two_stream ( const TwoStreamCanopyView &  canopy)

Shortwave of the current step with radiation = two_stream, after compute_shortwave() has placed the sun (m_sun): per face, the direct-normal irradiance of its column at its height (two_stream_face_sky(): a roof's interface, a wall's mean of its cell's two), the beam over the column's own cosine of the zenith, on the face (shadowed by the same ray cast), the diffuse light of the sky there through f_sky, and the ground's reflection, the column's shortwave up at the face's height, through f_ground. With erf.ibseb.ground_view_shadow the part of that shortwave up which is the ground's reflection of the beam (two_stream_ground_beam_share()) counts through the sunlit part of the face's ground view only (ibseb::ground_view_lit()). One kernel per fab, reading the view's fields of the same local index.

The faces' sun (sun_mode) and the sweep's are required to be one sun (ERF::ibseb_check_sun_matches_two_stream()); the kernel checks it, column by column: a cosine of the zenith more than 1e-4 (1e-3 in single precision) from the faces' stops the run, since a direct beam divided by the wrong cosine and laid along the wrong direction would still look plausible.

Before the level's first sweep (an empty canopy, the initial report) every face gets no shortwave. The reported direct-normal and diffuse irradiances are the means over the level's faces of their columns'.

1684 {
1685  const Real sx = m_sun.sx, sy = m_sun.sy, sz = m_sun.sz;
1686  const Real* palb = d_albedo.data();
1687  const ibseb::RayMap rm = ray_map();
1688  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
1689  const int k0 = m_dom_lo[2];
1690  const int* pd = d_dir.data(); const int* ps = d_side.data();
1691  const Real* pxf = d_xf.data(); const Real* pyf = d_yf.data(); const Real* pzf = d_zf.data();
1692  const Real* pfs = d_f_sky.data(); const Real* pfg = d_f_ground.data();
1693  Real* psh = d_shadow.data(); Real* pdir = d_SW_direct_in.data();
1694  Real* pdif = d_SW_diffuse_in.data(); Real* pabs = d_SW_abs.data();
1695 
1696  // The sunlit part of each face's ground view (erf.ibseb.ground_view_shadow).
1697  const bool lit_ground = m_params.ground_view_shadow;
1699  const int* pgs = d_gnd_start.data(); const int* pgf = d_gnd_far.data();
1700  const unsigned int* pgl = d_gnd_land.data(); const int* pgr = d_gnd_rays.data();
1701  Real* pfgl = d_f_ground_lit.data();
1702 
1703  if (!canopy.valid()) {
1704  ParallelFor(m_nface, [=] AMREX_GPU_DEVICE (int f) noexcept {
1705  psh[f] = 0.0; pdir[f] = 0.0; pdif[f] = 0.0; pabs[f] = 0.0; pfgl[f] = 0.0;
1706  });
1707  Gpu::streamSynchronize();
1708  m_sun.dni = 0.0;
1709  m_sun.diffuse_h = 0.0;
1710  return;
1711  }
1712 
1713  // Sums of the columns' direct-normal and diffuse irradiance over the faces,
1714  // for the report, and the largest disagreement of the two suns.
1715  ReduceOps<ReduceOpSum, ReduceOpSum, ReduceOpMax> reduce_op;
1716  ReduceData<Real, Real, Real> reduce_data(reduce_op);
1717  using ReduceTuple = typename decltype(reduce_data)::Type;
1718  const Real sz_up = amrex::max(Real(0.0), sz);
1719  const int nfab = static_cast<int>(m_fab_start.size()) - 1;
1720  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(canopy.beam->local_size() == nfab,
1721  "erf.ibseb.radiation = two_stream: the two-stream beam holds another number of boxes than the faces' level");
1722  for (MFIter mfi(*canopy.beam); mfi.isValid(); ++mfi) {
1723  const int f0 = m_fab_start[mfi.LocalIndex()];
1724  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
1725  const auto beam = canopy.beam->const_array(mfi);
1726  const auto cosz = canopy.cos_zenith->const_array(mfi);
1727  const auto flux = canopy.fluxes->const_array(mfi);
1728  const auto alb_g = lit_ground ? canopy.ground_albedo_dir->const_array(mfi) : Array4<const Real>{};
1729  reduce_op.eval(f1 - f0, reduce_data, [=] AMREX_GPU_DEVICE (int m) noexcept -> ReduceTuple {
1730  const int f = f0 + m;
1731  const Real cz = cosz(pi[f], pj[f], 0);
1732  const TwoStreamFaceSky sky = two_stream_face_sky(pi[f], pj[f], pk[f], k0, pd[f], ps[f], beam, cosz, flux);
1733  const Real dni = sky.dni, dif_h = sky.diffuse, refl = sky.sw_up;
1734  // Outward normal: opposite to the side the solid is on.
1735  Real n[3] = {0.0, 0.0, 0.0};
1736  n[pd[f]] = -static_cast<Real>(ps[f]);
1737  const Real cosi = n[0] * sx + n[1] * sy + n[2] * sz;
1738  Real shadow = 0.0, direct = 0.0;
1739  if (sz > 0.0 && cosi > 0.0 && dni > 0.0) {
1740  shadow = ibseb::ray_blocked(pxf[f], pyf[f], pzf[f], sx, sy, sz, rm) ? 1.0 : 0.0;
1741  direct = dni * cosi * (1.0 - shadow);
1742  }
1743  Real diffuse;
1744  if (lit_ground) {
1745  // One ray toward the sun from each column the face's ground rays land in,
1746  // when the column brings a beam to its ground and the faces' sun, which
1747  // casts the shadows, is above the horizon. The two suns may differ by the
1748  // tolerance below, so at sunrise and sunset the column can have a beam
1749  // while the faces' sun has none: no shadow is cast then and the ground
1750  // view takes the whole reflection, as without the input.
1751  // (The beam at the column's lower boundary: the ground, or the roof it starts on.)
1752  const bool beam_up = ibseb::ground_view_beam_up(
1753  sz, beam(pi[f], pj[f], two_stream_column_base(pi[f], pj[f], alb_g)));
1754  const Real fgl = beam_up
1755  ? ibseb::ground_view_lit(pi[f], pj[f], pgf[f], pgl + pgs[f], pgr + pgs[f],
1756  pgs[f + 1] - pgs[f], ray_weight, sx, sy, sz, rm)
1757  : Real(0.0);
1758  pfgl[f] = fgl;
1759  // The shaded part of the ground view loses the beam's share of the reflection.
1760  const Real share = beam_up ? two_stream_ground_beam_share(pi[f], pj[f], k0, beam, flux, alb_g)
1761  : Real(0.0);
1762  diffuse = pfs[f] * dif_h + (pfg[f] - (pfg[f] - fgl) * share) * refl;
1763  } else {
1764  diffuse = pfs[f] * dif_h + pfg[f] * refl;
1765  }
1766  psh[f] = shadow;
1767  pdir[f] = direct;
1768  pdif[f] = diffuse;
1769  pabs[f] = (1.0 - palb[f]) * (direct + diffuse);
1770  return {dni, dif_h, std::abs(cz - sz_up)};
1771  });
1772  }
1773  Gpu::streamSynchronize();
1774  const auto rv = reduce_data.value(reduce_op);
1775  Real sums[2] = {amrex::get<0>(rv), amrex::get<1>(rv)};
1776  Real sun_gap = amrex::get<2>(rv);
1777  ParallelDescriptor::ReduceRealSum(sums, 2);
1778  ParallelDescriptor::ReduceRealMax(sun_gap);
1779  const Real nf_all = static_cast<Real>(m_nface_dir[0] + m_nface_dir[1] + m_nface_dir[2]);
1780  m_sun.dni = (nf_all > 0.0) ? sums[0] / nf_all : Real(0.0);
1781  m_sun.diffuse_h = (nf_all > 0.0) ? sums[1] / nf_all : Real(0.0);
1782  // The two suns are one formula evaluated twice; a float calendar day resolves
1783  // about a second of the hour angle, hence the looser single-precision bound.
1784  const Real sun_tol = (sizeof(Real) == 8) ? Real(1.e-4) : Real(1.e-3);
1785  if (sun_gap > sun_tol) {
1786  Abort("erf.ibseb.radiation = two_stream: on level " + std::to_string(m_lev) + " the faces' sun (zenith "
1787  + std::to_string(m_sun.zenith * 180.0 / PI) + " deg) and the two-stream sweep's differ by up to "
1788  + std::to_string(sun_gap) + " in the cosine of the zenith angle (more than " + std::to_string(sun_tol)
1789  + "); the faces must take the sweep's sun"
1790  " (erf.ibseb.sun_mode = two_stream, or fixed at erf.fixed_solar_zenith_angle)");
1791  }
1792  if (m_params.debug) {
1793  Print() << "[IBSEB DEBUG] lev=" << m_lev << " sun: zenith=" << m_sun.zenith * 180.0 / PI
1794  << " deg azimuth=" << m_sun.azimuth * 180.0 / PI << " deg s=(" << m_sun.sx << "," << m_sun.sy << ","
1795  << m_sun.sz << "); two-stream columns: mean DNI=" << m_sun.dni
1796  << " W/m2 mean diffuse_h=" << m_sun.diffuse_h << " W/m2 over the faces, largest sun gap "
1797  << sun_gap << " in cos z\n";
1798  }
1799 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int two_stream_column_base(int i, int j, const amrex::Array4< const amrex::Real > &alb_dir) noexcept
The interface a column starts on, counted from the ground: 0, or the roof's with erf....
Definition: ERF_TwoStreamCanopyForcing.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real two_stream_ground_beam_share(int i, int j, int k0, const amrex::Array4< const amrex::Real > &beam, const amrex::Array4< const amrex::Real > &fluxes, const amrex::Array4< const amrex::Real > &alb_dir)
The share of column (i,j)'s shortwave up that is its ground's reflection of the direct beam: (direct-...
Definition: ERF_TwoStreamCanopyForcing.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool ground_view_beam_up(amrex::Real sz, amrex::Real beam_ground) noexcept
Definition: ERF_IBSEBSolar.H:605
amrex::Real diffuse_h
Diffuse on a horizontal surface [W/m2].
Definition: ERF_IBFaceSet.H:613
amrex::Real dni
Direct-normal irradiance [W/m2].
Definition: ERF_IBFaceSet.H:612
amrex::Real zenith
Definition: ERF_IBFaceSet.H:610
amrex::Real azimuth
[rad]
Definition: ERF_IBFaceSet.H:610
amrex::Real sw_up
Shortwave up at the face's height (the ground's reflection, seen from there)
Definition: ERF_TwoStreamCanopyForcing.H:133
amrex::Real diffuse
Diffuse shortwave down at the face's height.
Definition: ERF_TwoStreamCanopyForcing.H:131
amrex::Real dni
Direct-normal irradiance at the face's height.
Definition: ERF_TwoStreamCanopyForcing.H:130

Referenced by compute_shortwave().

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

◆ compute_view_fractions()

void IBFaceSet::compute_view_fractions ( )

View fractions: sample a cosine-weighted hemisphere around every face's outward normal with view_n_az x view_n_el rays through the column walk and count where they end: sky, ground or a building. The three fractions sum to one and are view factors. Called once at initialization; the geometry is static.

Hemisphere sampling for the view fractions. One kernel over the faces, each looping over its rays; the count of rays ending on the sky, the ground and a building over the total gives the three fractions. Roofs point up and never see the ground; a wall on flat open ground sees half sky and half ground, which the regression test checks.

904 {
905  const int n_az = m_params.view_n_az, n_el = m_params.view_n_el;
906  const ibseb::RayMap rm = ray_map();
907  const int* pd = d_dir.data(); const int* ps = d_side.data();
908  const Real* pxf = d_xf.data(); const Real* pyf = d_yf.data(); const Real* pzf = d_zf.data();
909  Real* pfs = d_f_sky.data(); Real* pfg = d_f_ground.data(); Real* pfb = d_f_bldg.data();
910  ParallelFor(m_nface, [=] AMREX_GPU_DEVICE (int f) noexcept {
911  int n_sky = 0, n_gnd = 0, n_bld = 0;
912  for (int ie = 0; ie < n_el; ++ie) {
913  for (int ia = 0; ia < n_az; ++ia) {
914  Real sx, sy, sz;
915  ibseb::hemisphere_direction(pd[f], -ps[f], ia, ie, n_az, n_el, sx, sy, sz);
916  const int hit = ibseb::ray_hit(pxf[f], pyf[f], pzf[f], sx, sy, sz, rm);
917  if (hit == ibseb::RAY_SKY) ++n_sky; else if (hit == ibseb::RAY_GROUND) ++n_gnd; else ++n_bld;
918  }
919  }
920  const Real inv = ibseb::hemisphere_ray_weight(n_az, n_el);
921  pfs[f] = n_sky * inv; pfg[f] = n_gnd * inv; pfb[f] = n_bld * inv;
922  });
923  Gpu::streamSynchronize();
925 
926  if (m_params.debug) {
927  std::vector<Real> fs(m_nface), fg(m_nface), fb(m_nface);
928  Gpu::copy(Gpu::deviceToHost, d_f_sky.begin(), d_f_sky.end(), fs.begin());
929  Gpu::copy(Gpu::deviceToHost, d_f_ground.begin(), d_f_ground.end(), fg.begin());
930  Gpu::copy(Gpu::deviceToHost, d_f_bldg.begin(), d_f_bldg.end(), fb.begin());
931  Gpu::streamSynchronize();
932  Real s[3] = {0.0, 0.0, 0.0};
933  for (int n = 0; n < m_nface; ++n) { s[0] += fs[n]; s[1] += fg[n]; s[2] += fb[n]; }
934  ParallelDescriptor::ReduceRealSum(s, 3);
935  // A refined level can hold no building at all.
936  const Real nf_all = amrex::max(Real(1.0), static_cast<Real>(m_nface_dir[0] + m_nface_dir[1] + m_nface_dir[2]));
937  Print() << "[IBSEB DEBUG] lev=" << m_lev << " view fractions: " << n_az * n_el
938  << " rays per face, mean f_sky=" << s[0] / nf_all << " f_ground=" << s[1] / nf_all
939  << " f_bldg=" << s[2] / nf_all << "\n";
940  }
941 }
void build_ground_landings()
Definition: ERF_IBFaceSet.cpp:951
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int ray_hit(amrex::Real x0, amrex::Real y0, amrex::Real z0, amrex::Real sx, amrex::Real sy, amrex::Real sz, const RayMap &m)
Definition: ERF_IBSEBSolar.H:507
@ RAY_GROUND
Definition: ERF_IBSEBSolar.H:418
@ RAY_SKY
Definition: ERF_IBSEBSolar.H:418
bool ground_sky_view
Definition: ERF_IBSEBParams.H:94
Here is the call graph for this function:

◆ dump_faces()

void IBFaceSet::dump_faces ( const std::string &  prefix) const

Write every face of this rank to <prefix>.rank<N>.csv with its geometry, view fractions, shadow flag, shortwave terms and skin temperature, for the regression tests and for users who want the raw list.

Per-rank face dump. Every rank writes its own file so no gather is needed; readers concatenate <prefix>.rank*.csv.

2032 {
2033  const int nf = m_nface;
2034  auto host = [&](const Gpu::DeviceVector<Real>& d) {
2035  std::vector<Real> h(nf);
2036  Gpu::copy(Gpu::deviceToHost, d.begin(), d.end(), h.begin());
2037  return h;
2038  };
2039  auto hosti = [&](const Gpu::DeviceVector<int>& d) {
2040  std::vector<int> h(nf);
2041  Gpu::copy(Gpu::deviceToHost, d.begin(), d.end(), h.begin());
2042  return h;
2043  };
2044  const auto i = hosti(d_i), j = hosti(d_j), k = hosti(d_k), dir = hosti(d_dir), side = hosti(d_side), bid = hosti(d_bid);
2045  const auto xf = host(d_xf), yf = host(d_yf), zf = host(d_zf), area = host(d_area);
2046  const auto fs = host(d_f_sky), fg = host(d_f_ground), fb = host(d_f_bldg);
2047  // The sunlit part of the ground view, a column only with erf.ibseb.ground_view_shadow.
2048  const bool lit_ground = m_params.ground_view_shadow;
2049  const auto fgl = lit_ground ? host(d_f_ground_lit) : std::vector<Real>{};
2050  const auto sh = host(d_shadow), sdir = host(d_SW_direct_in), sdif = host(d_SW_diffuse_in), sabs = host(d_SW_abs);
2051  const auto T = host(d_T_skin), Ta = host(d_T_air), lwin = host(d_LW_down_in), lwn = host(d_LW_net);
2052  const auto th = host(d_theta_air), rho = host(d_rho), Ut = host(d_U_tan), us = host(d_ustar), H = host(d_H);
2053  const auto mat = hosti(d_mat);
2054  const auto alb = host(d_albedo), emi = host(d_emis), kk = host(d_kth), rc = host(d_rhocp), thk = host(d_thick), G = host(d_G);
2055  const auto Hc = host(d_H_coeff), Qx = host(d_Q_ext), LE = host(d_LE), lwe = host(d_LW_ext), res = host(d_resid);
2056  const auto nit = hosti(d_niter);
2057  const auto ws = host(d_w_star), ol = host(d_olen), zi = host(d_z_i), hb = host(d_hbld);
2058  const int nl = n_layers();
2059  std::vector<Real> slab(static_cast<size_t>(nf) * nl);
2060  Gpu::copy(Gpu::deviceToHost, d_T_slab.begin(), d_T_slab.end(), slab.begin());
2061  Gpu::streamSynchronize();
2062  std::ofstream f(prefix + ".rank" + std::to_string(ParallelDescriptor::MyProc()) + ".csv");
2063  f << "i,j,k,dir,side,bid,x_m,y_m,z_m,area_m2,f_sky,f_ground,f_bldg," << (lit_ground ? "f_ground_lit," : "")
2064  << "shadow,SW_direct_in,SW_diffuse_in,SW_abs,T_skin,T_air,LW_in,LW_net,"
2065  "theta_air,rho,U_tan,ustar,H,mat,albedo,emissivity,k_therm,rho_cp,thickness,G,T_slab_top,T_slab_bottom,"
2066  "H_coeff,Q_ext,LE,LW_ext,resid,n_iter,w_star,Olen,z_i,h_bld";
2067  for (int l = 0; l < nl; ++l) { f << ",T_slab_" << l; }
2068  f << "\n";
2069  f << std::setprecision(12);
2070  for (int n = 0; n < nf; ++n) {
2071  f << i[n] << "," << j[n] << "," << k[n] << "," << dir[n] << "," << side[n] << "," << bid[n] << ","
2072  << xf[n] << "," << yf[n] << "," << zf[n] << "," << area[n] << ","
2073  << fs[n] << "," << fg[n] << "," << fb[n] << ",";
2074  if (lit_ground) { f << fgl[n] << ","; }
2075  f << sh[n] << ","
2076  << sdir[n] << "," << sdif[n] << "," << sabs[n] << "," << T[n] << ","
2077  << Ta[n] << "," << lwin[n] << "," << lwn[n] << ","
2078  << th[n] << "," << rho[n] << "," << Ut[n] << "," << us[n] << "," << H[n] << ","
2079  << mat[n] << "," << alb[n] << "," << emi[n] << "," << kk[n] << "," << rc[n] << "," << thk[n] << ","
2080  << G[n] << "," << slab[static_cast<size_t>(n) * nl] << "," << slab[static_cast<size_t>(n) * nl + nl - 1] << ","
2081  << Hc[n] << "," << Qx[n] << "," << LE[n] << "," << lwe[n] << "," << res[n] << "," << nit[n]
2082  << "," << ws[n] << "," << ol[n] << "," << zi[n] << "," << hb[n];
2083  for (int l = 0; l < nl; ++l) { f << "," << slab[static_cast<size_t>(n) * nl + l]; }
2084  f << "\n";
2085  }
2086 }
Real H
Definition: ERF_InitCustomPert_MovingTerrain.H:8
constexpr std::array< amrex::Real, num_veg_params > rc
Definition: ERF_SLM_DefaultParams.H:22

Referenced by report().

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

◆ fab_start()

const std::vector<int>& IBFaceSet::fab_start ( ) const
inline

First face of each local fab in MFIter order; size number of fabs + 1. Faces fab_start()[n] to fab_start()[n+1]-1 belong to the fab with local index n, which is what the scatter kernels rely on.

637 { return m_fab_start; }

◆ fill_roofs()

void IBFaceSet::fill_roofs ( amrex::MultiFab &  out,
const amrex::iMultiFab &  roof_cell,
bool  with_fixed,
amrex::Real  time 
)

For erf.ibseb.two_stream_roofs: give each column under a building the roof face that stands on it. roof_cell holds, per column, the cell on the roof of the building that stands on the ground (TwoStreamRadiation::roof_cell()); the upward face whose fluid cell is that cell writes 1, its albedo, its emissivity, its skin temperature and the share of the direct beam that reaches it (0 where a taller building shades the roof under the sun at time, by the shadow ray of the faces) into the five components of out (TwoStreamRadiation::roofs_for_step()). Every other column gets zeros: open ground, and a building that fills the column. Both fields are the level's columns (k = 0), box for box with the faces. The roof faces are found at the first call.

Parameters
with_fixedtrue at the first fill of a field: zero it and write what does not change (the first three components) too; false afterwards, when only the skin temperature and the lit share are written
timesimulation time [s] of the sweep that takes the roofs: the roofs' shadow is cast under the sun of that time (sun_at()), which does not depend on the faces' last shortwave. With sun_mode = two_stream the two-stream sun of that time must have been given first (set_two_stream_sun()).

The roof face of each column under a building (see the header). The roof faces are found once, on the host: the upward faces whose cell is the cell on their column's roof, listed fab by fab. Each call then runs one kernel per fab over that fab's roof faces only; a column has at most one upward face on a given cell, so no two faces write the same column.

1830 {
1831  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(out.nComp() >= 5,
1832  "erf.ibseb.two_stream_roofs: the field of the roofs holds fewer than five components");
1833  const int nfab = static_cast<int>(m_fab_start.size()) - 1;
1834  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(out.local_size() == nfab && roof_cell.local_size() == nfab,
1835  "erf.ibseb.two_stream_roofs: the field of the roofs holds another number of boxes than the faces' level");
1836  if (!m_roof_faces_built) {
1837  std::vector<int> hi(m_nface), hj(m_nface), hk(m_nface), hd(m_nface), hs(m_nface), list;
1838  Gpu::copy(Gpu::deviceToHost, d_i.begin(), d_i.end(), hi.begin());
1839  Gpu::copy(Gpu::deviceToHost, d_j.begin(), d_j.end(), hj.begin());
1840  Gpu::copy(Gpu::deviceToHost, d_k.begin(), d_k.end(), hk.begin());
1841  Gpu::copy(Gpu::deviceToHost, d_dir.begin(), d_dir.end(), hd.begin());
1842  Gpu::copy(Gpu::deviceToHost, d_side.begin(), d_side.end(), hs.begin());
1843  Gpu::streamSynchronize();
1844  m_roof_fab_start.assign(static_cast<size_t>(nfab) + 1, 0);
1845  for (MFIter mfi(roof_cell); mfi.isValid(); ++mfi) {
1846  const int li = mfi.LocalIndex();
1847  IArrayBox cell(mfi.validbox(), 1, The_Pinned_Arena());
1848  Gpu::dtoh_memcpy(cell.dataPtr(), roof_cell[mfi].dataPtr(), cell.nBytes());
1849  const auto rk = cell.const_array();
1850  m_roof_fab_start[li] = static_cast<int>(list.size());
1851  for (int f = m_fab_start[li]; f < m_fab_start[li + 1]; ++f) {
1852  // An upward face (the solid below it) on the cell the column's roof carries.
1853  if (hd[f] == 2 && hs[f] < 0 && hk[f] == rk(hi[f], hj[f], 0)) { list.push_back(f); }
1854  }
1855  m_roof_fab_start[li + 1] = static_cast<int>(list.size());
1856  }
1857  upload(d_roof_face, list);
1858  Gpu::streamSynchronize();
1859  m_roof_faces_built = true;
1860  }
1861  // The first fill of a field: zeros everywhere, then what does not change (that a roof
1862  // stands there, its albedo, its emissivity). Every fill: what does change.
1863  if (with_fixed) { out.setVal(0.0, 0, 5, 0); }
1864  const int* prf = d_roof_face.data();
1865  const int* pi = d_i.data(); const int* pj = d_j.data();
1866  const Real* palb = d_albedo.data(); const Real* peps = d_emis.data();
1867  const Real* pT = d_T_skin.data();
1868  // The roof's shadow under the sun of the sweep's own time, not the sun the faces hold
1869  // from their last shortwave (m_sun): that one is the previous step's with the two-stream
1870  // columns and the start-up sun after a restart, and it is not in the checkpoint, so a
1871  // moving sun would give a restarted run another shadow in its first step.
1872  const ibseb::RayMap rm = ray_map();
1873  const SunState sun_now = sun_at(time);
1874  // The two-stream sun is used once here too: the faces' next shortwave is given its own.
1875  if (m_params.sun_mode == "two_stream") { m_ts_sun.set = false; }
1876  const Real sx = sun_now.sx, sy = sun_now.sy, sz = sun_now.sz;
1877  const Real* pxf = d_xf.data(); const Real* pyf = d_yf.data(); const Real* pzf = d_zf.data();
1878  for (MFIter mfi(out); mfi.isValid(); ++mfi) {
1879  const int r0 = m_roof_fab_start[mfi.LocalIndex()];
1880  const int r1 = m_roof_fab_start[mfi.LocalIndex() + 1];
1881  if (r1 == r0) { continue; }
1882  const auto o = out.array(mfi);
1883  ParallelFor(r1 - r0, [=] AMREX_GPU_DEVICE (int m) noexcept {
1884  const int f = prf[r0 + m];
1885  if (with_fixed) {
1886  o(pi[f], pj[f], 0, 0) = Real(1.0);
1887  o(pi[f], pj[f], 0, 1) = palb[f];
1888  o(pi[f], pj[f], 0, 2) = peps[f];
1889  }
1890  o(pi[f], pj[f], 0, 3) = pT[f];
1891  // The share of the beam that reaches the roof: none where a taller building
1892  // shades it. With the sun down there is no beam and the share plays no part.
1893  const bool shaded = sz > Real(0.0) && ibseb::ray_blocked(pxf[f], pyf[f], pzf[f], sx, sy, sz, rm);
1894  o(pi[f], pj[f], 0, 4) = shaded ? Real(0.0) : Real(1.0);
1895  });
1896  }
1897  Gpu::streamSynchronize();
1898 }
real(kind=kind_phys), parameter, private r0
Definition: ERF_module_mp_wdm6.F90:75
Here is the call graph for this function:

◆ has_faces()

bool IBFaceSet::has_faces ( ) const
inline

Whether the level has faces on any rank.

417 { return m_top_sample >= 0; }

◆ map_buildings_to_level0()

void IBFaceSet::map_buildings_to_level0 ( const IBFaceSet &  coarser,
const amrex::IntVect &  ratio 
)

Number this refined level's buildings as level 0 numbers them.

Each level labels its buildings from its own cells, so the ids of a refined level differ from level 0's wherever the levels see different buildings: a building outside the refined level, or two that level 0 merges into one. Inputs that go by building (erf.ibseb.material_by_building) and the report's building_level0 column use level 0's numbering, so every building of this level is looked up in the labels of the level below, and through that level's own map in level 0's: each of its columns votes with the id under it and the majority wins. A building only this level resolves maps to 0 (the default material), with a warning. Call after build() of both levels; the level below keeps its labels until release_labels().

Parameters
coarserFace set of the level below, already mapped.
ratioRefinement ratio from the level below to this one.

Map this level's buildings to level 0's numbering through the labels of the level below (see the header). Every column of a building votes with the level-0 id of the coarse column under it (through the level below's own map), unlabeled coarse columns abstaining, and the most frequent id wins (the lowest on a tie). No single column is trusted: the coarse blanking is a volume average, so a column the coarse level leaves unlabeled (a spire alone in its coarse cell) cannot unmap a building the level below resolves through its other columns. A building none of whose columns lies under a labeled coarse column is one only this level resolves; it maps to 0, and a warning names it when the level below has buildings at all. The level below's ids are brought under this level's columns by a parallel copy; the votes, a few per building, are gathered from every rank and summed, so every rank reaches the same verdict.

832 {
834  "erf.ibseb: the level below released its labels before this level was mapped");
835  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(coarser.m_geom.Domain().smallEnd(2) == m_geom.Domain().smallEnd(2),
836  "erf.ibseb: the levels do not share the ground");
837  const int klo = m_geom.Domain().smallEnd(2);
838  const IntVect ratio_h(AMREX_D_DECL(ratio[0], ratio[1], 1));
839  iMultiFab crse(amrex::coarsen(m_lab.boxArray(), ratio_h), m_lab.DistributionMap(), 1, 0);
840  crse.setVal(0);
841  crse.ParallelCopy(coarser.m_lab, 0, 0, 1, IntVect(0), IntVect(0), coarser.m_geom.periodicity());
842  // This rank's votes: (this level's id, level 0's id) -> columns.
843  std::map<std::pair<int, int>, Long> votes;
844  for (MFIter mfi(m_lab); mfi.isValid(); ++mfi) {
845  const Box& vb = mfi.validbox();
846  const HostInts lab(m_lab[mfi]);
847  const HostInts cl(crse[mfi]);
848  auto const& a = lab.array();
849  auto const& c = cl.array();
850  const auto lo = lbound(vb);
851  const auto hi = ubound(vb);
852  for (int j = lo.y; j <= hi.y; ++j) {
853  for (int i = lo.x; i <= hi.x; ++i) {
854  const int b = a(i, j, klo);
855  if (b == 0) { continue; }
856  // amrex::coarsen, not a division: integer division truncates
857  // towards zero, which would send a negative index to the
858  // coarse column above the one that covers it.
859  const int bc = c(amrex::coarsen(i, ratio[0]), amrex::coarsen(j, ratio[1]), klo);
860  if (bc > 0 && coarser.m_to_lev0[bc] > 0) { ++votes[{b, coarser.m_to_lev0[bc]}]; }
861  }
862  }
863  }
864  std::vector<Long> mine;
865  for (const auto& [key, n] : votes) { mine.push_back(key.first); mine.push_back(key.second); mine.push_back(n); }
866  const std::vector<Long> all = all_gather(mine);
867  std::vector<std::map<int, Long>> tally(m_nbld + 1);
868  for (size_t n = 0; n + 3 <= all.size(); n += 3) { tally[static_cast<int>(all[n])][static_cast<int>(all[n + 1])] += all[n + 2]; }
869  std::vector<int> unmapped;
870  for (int b = 1; b <= m_nbld; ++b) {
871  int best = 0;
872  Long n_best = 0;
873  for (const auto& [id, n] : tally[b]) { // ascending id: the lowest wins a tie
874  if (n > n_best) { best = id; n_best = n; }
875  }
876  m_to_lev0[b] = best;
877  if (best == 0) { unmapped.push_back(b); }
878  }
879  if (!unmapped.empty() && coarser.m_nbld > 0) {
880  std::ostringstream os;
881  os << "erf.ibseb: level " << m_lev << " has " << unmapped.size()
882  << " building(s) that no labelled column of the level below lies under (level " << m_lev << " number";
883  for (int b : unmapped) { os << " " << b; }
884  os << "); they take erf.ibseb.material_default and building_level0 = 0 in the report";
885  // Every rank holds the same votes and reaches the same verdict.
886  if (ParallelDescriptor::IOProcessor()) { Warning(os.str().c_str()); }
887  }
888  if (m_params.debug) {
889  Print() << "[IBSEB DEBUG] lev=" << m_lev << " buildings as level 0 numbers them:";
890  for (int b = 1; b <= m_nbld; ++b) { Print() << " " << b << "->" << m_to_lev0[b]; }
891  Print() << "\n";
892  }
893 }
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182
Here is the call graph for this function:

◆ n_buildings()

int IBFaceSet::n_buildings ( ) const
inline

Number of buildings of the level, the same on every rank.

201 { return m_nbld; }

◆ n_faces()

int IBFaceSet::n_faces ( ) const
inline

Number of faces owned by this rank (not the global count; see report()).

199 { return m_nface; }

◆ n_layers()

int IBFaceSet::n_layers ( ) const
inline

Conduction layers per face, from erf.ibseb.n_slab_layers.

203 { return m_params.n_slab_layers; }
int n_slab_layers
Conduction layers per face.
Definition: ERF_IBSEBParams.H:27

Referenced by dump_faces(), print_debug_summary(), read_state(), and write_state().

Here is the caller graph for this function:

◆ print_debug_summary()

void IBFaceSet::print_debug_summary ( ) const

Print the [IBSEB DEBUG] description of the set: the inputs, every rank's face count and per-fab ranges, the buildings with their footprint columns and bounding boxes, and the device memory of the arrays. Called once from build() when erf.ibseb.debug is set.

Debug description of the set, in the style of the fire module's [FIRE DEBUG] lines: what was read, what every rank holds, what the buildings look like, and what the arrays cost. Per-rank lines use AllPrint() so every rank reports; the rest is printed by the I/O rank.

2096 {
2097  const int nl = n_layers();
2098  Print() << "[IBSEB DEBUG] lev=" << m_lev << " inputs: n_slab_layers=" << nl
2099  << " T_skin_init=" << m_params.T_skin_init << " K"
2100  << " T_interior=" << m_params.T_interior << " K"
2101  << " csv_file=" << m_params.csv_file << " csv_int=" << m_params.csv_int << "\n";
2102  Print() << "[IBSEB DEBUG] lev=" << m_lev << " global faces=" << (m_nface_dir[0] + m_nface_dir[1] + m_nface_dir[2])
2103  << " (x=" << m_nface_dir[0] << " y=" << m_nface_dir[1] << " z=" << m_nface_dir[2] << ")"
2104  << " area=" << m_area_total << " m2 buildings=" << m_nbld << "\n";
2105  for (int b = 1; b <= m_nbld; ++b) {
2106  Print() << "[IBSEB DEBUG] building " << b << ": columns=" << m_bld_ncol[b]
2107  << " i=[" << m_bld_ilo[b] << "," << m_bld_ihi[b] << "]"
2108  << " j=[" << m_bld_jlo[b] << "," << m_bld_jhi[b] << "]"
2109  << " faces=" << m_bld_nface[b] << " area=" << m_bld_area[b] << " m2\n";
2110  }
2111  // Per-rank ownership: one line per rank with its fab ranges.
2112  const int nfab = static_cast<int>(m_fab_start.size()) - 1;
2113  const size_t bytes = static_cast<size_t>(m_nface) *
2114  (7 * sizeof(int) + (11 + static_cast<size_t>(nl)) * sizeof(Real));
2115  // The ray map: this rank's patch and its share of the column map and labels.
2116  size_t map_cells = static_cast<size_t>(m_patch_box.ok() ? m_patch_box.numPts() : 0);
2117  const size_t per_column = m_lab.ok() ? 2 : 1; // ok() iterates the fabs itself: not inside the loop below
2118  for (MFIter mfi(m_col_valid); mfi.isValid(); ++mfi) {
2119  map_cells += per_column * static_cast<size_t>(m_col_valid[mfi].box().numPts());
2120  }
2121  const size_t map_bytes = map_cells * sizeof(int);
2122  std::ostringstream os;
2123  os << "[IBSEB DEBUG] lev=" << m_lev << " rank " << ParallelDescriptor::MyProc()
2124  << ": faces=" << m_nface << " over " << nfab << " fab(s), device memory "
2125  << bytes / 1024.0 << " kB for the faces, " << map_bytes / 1024.0 << " kB for the ray map; fab ranges:";
2126  for (int f = 0; f < nfab; ++f) { os << " [" << m_fab_start[f] << "," << m_fab_start[f + 1] << ")"; }
2127  AllPrint() << os.str() << "\n";
2128 }
std::string csv_file
Per-building report.
Definition: ERF_IBSEBParams.H:30
int csv_int
Steps between report rows; <= 0 disables.
Definition: ERF_IBSEBParams.H:31
Here is the call graph for this function:

◆ ray_halo()

amrex::IntVect IBFaceSet::ray_halo ( ) const
inline

Halo of the ray map in cells (x, y), from the last build_ray_map().

193 { return m_halo; }

◆ ray_map()

ibseb::RayMap IBFaceSet::ray_map ( ) const

The ray map of this rank for the kernels of the shortwave and the view fractions: the column tops over this rank's patch and the grid they are drawn on (ibseb::RayMap). A rank without boxes has no patch and no faces.

784 {
785  ibseb::RayMap m;
786  if (m_patch_box.ok()) {
787  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_ray_patch.local_size() == 1, "erf.ibseb: the ray map holds no patch for this rank");
788  m.top = m_ray_patch.const_array(m_ray_patch.IndexArray()[0]);
789  }
790  m.ilo = m_dom_lo[0]; m.jlo = m_dom_lo[1];
791  m.nx = m_nx; m.ny = m_ny;
792  m.wrap_x = m_wrap_x; m.wrap_y = m_wrap_y;
793  m.x_lo = m_x_lo; m.y_lo = m_y_lo;
794  m.dx = m_dx[0]; m.dy = m_dx[1]; m.dz = m_dx[2];
795  m.z_ground = m_z_ground;
796  m.z_max = m_col_top_max;
798  m.reach_x = m_reach[0];
799  m.reach_y = m_reach[1];
800  return m;
801 }
amrex::Real x_lo
Definition: ERF_IBSEBSolar.H:224
amrex::Array4< const int > top
Column tops over the patch (any k index; use top.begin[2])
Definition: ERF_IBSEBSolar.H:220
int reach_x
Definition: ERF_IBSEBSolar.H:229
int ilo
Definition: ERF_IBSEBSolar.H:221
amrex::Real y_lo
Physical position of the domain's low corner [m].
Definition: ERF_IBSEBSolar.H:224
amrex::Real z_max
Tallest column the map holds [m]; a ray above it meets nothing.
Definition: ERF_IBSEBSolar.H:227
bool wrap_x
Definition: ERF_IBSEBSolar.H:223
int ny
Columns of the domain in x and y.
Definition: ERF_IBSEBSolar.H:222
amrex::Real dx
Definition: ERF_IBSEBSolar.H:225
amrex::Real z_ground
Ground height [m].
Definition: ERF_IBSEBSolar.H:226
bool wrap_y
The patch spans the periodic domain in x / y.
Definition: ERF_IBSEBSolar.H:223
int max_steps
Columns a ray at the map's floor elevation crosses before it clears z_max (the halo's reach in x plus...
Definition: ERF_IBSEBSolar.H:228
amrex::Real dy
Definition: ERF_IBSEBSolar.H:225
amrex::Real dz
Cell sizes [m].
Definition: ERF_IBSEBSolar.H:225
int jlo
Low corner of the domain, in cells.
Definition: ERF_IBSEBSolar.H:221
int reach_y
The halo's reach in x and in y, in columns, before the domain cap: every patch holds that many column...
Definition: ERF_IBSEBSolar.H:229
int nx
Definition: ERF_IBSEBSolar.H:222

Referenced by compute_ground_shadow(), compute_ground_walls(), compute_shortwave(), compute_shortwave_two_stream(), and fill_roofs().

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

◆ ray_map_spans_domain()

bool IBFaceSet::ray_map_spans_domain ( ) const
inline

Whether every rank's patch spans the whole domain, so every ray is followed to its end.

196 { return m_map_spans_domain; }

◆ read_state()

void IBFaceSet::read_state ( const std::string &  file)

Read the face state back from a file written by write_state(), after build() has recreated the list from the blanking.

The I/O rank reads the table; every rank sends it the keys of its own faces; the I/O rank finds each one by binary search and sends the records back. Only the I/O rank ever holds the whole table, and a restart on any number of ranks finds every face. Stops when the file holds another number of slab layers than the deck's erf.ibseb.n_slab_layers, another domain size or another number of faces, or when a face of this list has no record: a checkpoint of other buildings. Collective: every rank must call it.

The inverse of write_state(): the I/O rank reads the table and checks the header against this level (every rank gets the header, so all stop together on a mismatch); each rank sends the keys of its own faces, the I/O rank looks them up by binary search and sends the records back; each rank then unpacks its records into the device arrays.

2317 {
2318  const int nl = n_layers();
2319  const int nrec = 2 + nl;
2320  const int nf = m_nface;
2321  const bool io = ParallelDescriptor::IOProcessor();
2322  const int root = ParallelDescriptor::IOProcessorNumber();
2323 
2324  // The I/O rank reads the whole file: the header (face count, slab layers,
2325  // domain size), the marker word and the table. What it found goes to every
2326  // rank as hdr[5], so all ranks stop together on any fault. The table is
2327  // read only when the header matches this level, so a header mismatch is
2328  // reported as such below rather than as a short file.
2329  enum : Long { ok = 1, cannot_open, bad_header, bad_marker, too_short, unsorted };
2330  const Long nface_level = m_nface_dir[0] + m_nface_dir[1] + m_nface_dir[2];
2331  std::array<Long, 6> hdr{};
2332  std::vector<Long> tkey;
2333  std::vector<double> tval;
2334  if (io) {
2335  std::ifstream f(file, std::ifstream::in | std::ifstream::binary);
2336  std::string tag;
2337  int version = 0;
2338  Long marker = 0;
2339  if (!f) {
2340  hdr[5] = cannot_open;
2341  } else if (!(f >> tag >> version >> hdr[0] >> hdr[1] >> hdr[2] >> hdr[3] >> hdr[4])
2342  || tag != "IBSEBFaces" || version != 1 || hdr[0] < 0) {
2343  hdr[5] = bad_header;
2344  } else {
2345  f.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
2346  f.read(reinterpret_cast<char*>(&marker), sizeof(Long));
2347  if (!f || marker != face_file_marker) {
2348  hdr[5] = bad_marker;
2349  } else if (hdr[1] != nl || hdr[2] != m_nx || hdr[3] != m_ny || hdr[4] != m_nz || hdr[0] != nface_level) {
2350  hdr[5] = ok; // the checks below say which header entry differs
2351  } else {
2352  const Long n = hdr[0];
2353  tkey.resize(n);
2354  tval.resize(static_cast<size_t>(n) * nrec);
2355  f.read(reinterpret_cast<char*>(tkey.data()), static_cast<std::streamsize>(n * sizeof(Long)));
2356  f.read(reinterpret_cast<char*>(tval.data()), static_cast<std::streamsize>(tval.size() * sizeof(double)));
2357  hdr[5] = f ? ok : too_short;
2358  for (Long m = 1; hdr[5] == ok && m < n; ++m) {
2359  if (tkey[m] <= tkey[m - 1]) { hdr[5] = unsorted; }
2360  }
2361  }
2362  }
2363  }
2364  ParallelDescriptor::Bcast(hdr.data(), hdr.size(), root);
2365  switch (hdr[5]) {
2366  case ok: break;
2367  case cannot_open: Abort("erf.ibseb: cannot open " + file + " for reading"); break;
2368  case bad_header: Abort("erf.ibseb: " + file + " is not a face-state file of this ERF (its first line should read"
2369  " 'IBSEBFaces 1 <faces> <layers> <nx> <ny> <nz>')"); break;
2370  case bad_marker: Abort("erf.ibseb: " + file + " was written on a machine with another byte order or integer"
2371  " width; restart from a checkpoint written on this kind of machine"); break;
2372  case too_short: Abort("erf.ibseb: " + file + " ends before the " + std::to_string(hdr[0])
2373  + " records its header announces"); break;
2374  default: Abort("erf.ibseb: the face keys of " + file + " are not in ascending order"); break;
2375  }
2376  if (hdr[1] != nl) {
2377  Abort("erf.ibseb: " + file + " holds " + std::to_string(hdr[1]) + " slab layers per face; the deck sets"
2378  " erf.ibseb.n_slab_layers = " + std::to_string(nl) + ". Restart with the checkpoint's value.");
2379  }
2380  if (hdr[2] != m_nx || hdr[3] != m_ny || hdr[4] != m_nz) {
2381  Abort("erf.ibseb: " + file + " was written for a different domain (" + std::to_string(hdr[2]) + " x "
2382  + std::to_string(hdr[3]) + " x " + std::to_string(hdr[4]) + " cells against " + std::to_string(m_nx)
2383  + " x " + std::to_string(m_ny) + " x " + std::to_string(m_nz) + " here)");
2384  }
2385  if (hdr[0] != nface_level) {
2386  Abort("erf.ibseb: " + file + " was written for a different building layout (" + std::to_string(hdr[0])
2387  + " faces against the " + std::to_string(nface_level)
2388  + " the blanking gives); restart from a checkpoint of the same buildings");
2389  }
2390 
2391  const Long ntot = hdr[0];
2392 
2393  // This rank's keys to the I/O rank.
2394  std::vector<int> h_i(nf), h_j(nf), h_k(nf), h_dir(nf), h_side(nf);
2395  Gpu::copy(Gpu::deviceToHost, d_i.begin(), d_i.end(), h_i.begin());
2396  Gpu::copy(Gpu::deviceToHost, d_j.begin(), d_j.end(), h_j.begin());
2397  Gpu::copy(Gpu::deviceToHost, d_k.begin(), d_k.end(), h_k.begin());
2398  Gpu::copy(Gpu::deviceToHost, d_dir.begin(), d_dir.end(), h_dir.begin());
2399  Gpu::copy(Gpu::deviceToHost, d_side.begin(), d_side.end(), h_side.begin());
2400  Gpu::streamSynchronize();
2401  std::vector<Long> key(nf);
2402  for (int n = 0; n < nf; ++n) {
2403  key[n] = face_key(h_i[n] - m_dom_lo[0], h_j[n] - m_dom_lo[1], h_k[n] - m_dom_lo[2],
2404  h_dir[n], h_side[n], m_ny, m_nz);
2405  }
2406  std::vector<int> counts, disp, vcounts, vdisp;
2407  gather_counts(nf, counts, disp);
2408  scale_counts(counts, disp, nrec, vcounts, vdisp);
2409  std::vector<Long> all_key(io ? ntot : 0);
2410  ParallelDescriptor::Gatherv(key.data(), nf, all_key.data(), counts, disp, root);
2411 
2412  // Look every face up; a face without a record means other buildings.
2413  std::vector<double> all_val(io ? ntot * nrec : 0);
2414  std::array<Long, 2> missing{0, -1}; // count, first key
2415  if (io) {
2416  for (Long m = 0; m < ntot; ++m) {
2417  const auto it = std::lower_bound(tkey.begin(), tkey.end(), all_key[m]);
2418  if (it == tkey.end() || *it != all_key[m]) {
2419  if (missing[0] == 0) { missing[1] = all_key[m]; }
2420  ++missing[0];
2421  continue;
2422  }
2423  const Long t = it - tkey.begin();
2424  std::copy_n(&tval[static_cast<size_t>(t) * nrec], nrec, &all_val[static_cast<size_t>(m) * nrec]);
2425  }
2426  }
2427  ParallelDescriptor::Bcast(missing.data(), missing.size(), root);
2428  if (missing[0] > 0) {
2429  const auto fc = face_from_key(missing[1], m_ny, m_nz);
2430  Abort("erf.ibseb: " + file + " was written for a different building layout (" + std::to_string(missing[0])
2431  + " faces of this blanking have no record there, the first at i=" + std::to_string(fc[0] + m_dom_lo[0])
2432  + " j=" + std::to_string(fc[1] + m_dom_lo[1]) + " k=" + std::to_string(fc[2] + m_dom_lo[2])
2433  + " dir=" + std::to_string(fc[3]) + " side=" + std::to_string(fc[4])
2434  + "); restart from a checkpoint of the same buildings");
2435  }
2436 
2437  // The records back to the ranks that asked for them, in the order they asked.
2438  std::vector<double> val(static_cast<size_t>(nf) * nrec);
2439 #ifdef AMREX_USE_MPI
2440  BL_MPI_REQUIRE(MPI_Scatterv(all_val.data(), vcounts.data(), vdisp.data(), MPI_DOUBLE,
2441  val.data(), nf * nrec, MPI_DOUBLE, root, ParallelDescriptor::Communicator()));
2442 #else
2443  val = all_val;
2444 #endif
2445  std::vector<Real> h_T(nf), h_H(nf), h_S(static_cast<size_t>(nf) * nl);
2446  for (int n = 0; n < nf; ++n) {
2447  const double* r = &val[static_cast<size_t>(n) * nrec];
2448  h_T[n] = static_cast<Real>(r[0]);
2449  h_H[n] = static_cast<Real>(r[1]);
2450  for (int l = 0; l < nl; ++l) { h_S[static_cast<size_t>(n) * nl + l] = static_cast<Real>(r[2 + l]); }
2451  }
2452  Gpu::copy(Gpu::hostToDevice, h_T.begin(), h_T.end(), d_T_skin.begin());
2453  Gpu::copy(Gpu::hostToDevice, h_H.begin(), h_H.end(), d_H.begin());
2454  Gpu::copy(Gpu::hostToDevice, h_S.begin(), h_S.end(), d_T_slab.begin());
2455  Gpu::streamSynchronize();
2456  if (m_params.debug) {
2457  Real tmin = 1.0e30, tmax = -1.0e30;
2458  for (int n = 0; n < nf; ++n) { tmin = std::min(tmin, h_T[n]); tmax = std::max(tmax, h_T[n]); }
2459  ParallelDescriptor::ReduceRealMin(tmin);
2460  ParallelDescriptor::ReduceRealMax(tmax);
2461  Print() << "[IBSEB DEBUG] lev=" << m_lev << " face state loaded: " << ntot << " records from " << file
2462  << ", T_skin in [" << tmin << ", " << tmax << "] K\n";
2463  }
2464 }
@ fc
Definition: ERF_AdvanceMorrison.cpp:141
constexpr Real missing
Definition: ERF_TopographicShading.cpp:10
Here is the call graph for this function:

◆ release_labels()

void IBFaceSet::release_labels ( )
inline

Free the column labels once the level above has been mapped (map_buildings_to_level0()).

183 { m_lab.clear(); }

◆ report()

void IBFaceSet::report ( amrex::Real  time,
int  step,
bool  write_csv 
) const

Print the [IBSEB] summary line and, when asked, append one row per building to erf.ibseb.csv_file.

The summary carries the global face counts per direction, the number of buildings, the total face area and the range of the skin temperature; the CSV rows carry per building the face count, the area, the area-weighted mean fluxes and skin temperature with its range, the largest balance residual, and the sun the step used, from its start (zenith, azimuth, direct-normal and diffuse irradiance), on a row stamped with the time at the end of the step. All numbers are reduced over the ranks; the file is written by the I/O rank only, with a header only when the file does not exist yet, so a restarted run appends. Every level appends to the same file, its rows marked by the level column. With erf.ibseb.dump_faces_file the rows come with a face dump, dump_faces() to <prefix>[.levN][.stepNNNNNN].rank<N>.csv: a refined level N adds .levN so it does not overwrite the level below, and erf.ibseb.dump_faces_tag_step the step.

Parameters
timeSimulation time [s] written to the rows.
stepStep number written to the rows.
write_csvWhether to append rows, or only print the summary.

Summary line and per-building CSV rows. The dynamic quantities (skin temperature range and area-weighted mean per building) are gathered on the host from the device arrays and reduced; the static counts and areas were reduced in build().

2474 {
2475  // Skin temperature: min, max and per-building mean over all ranks.
2476  std::vector<Real> h_T(m_nface), h_A(m_nface);
2477  std::vector<int> h_b(m_nface);
2478  Gpu::copy(Gpu::deviceToHost, d_T_skin.begin(), d_T_skin.end(), h_T.begin());
2479  Gpu::copy(Gpu::deviceToHost, d_area.begin(), d_area.end(), h_A.begin());
2480  Gpu::copy(Gpu::deviceToHost, d_bid.begin(), d_bid.end(), h_b.begin());
2481  Gpu::streamSynchronize();
2482 
2483  std::vector<Real> h_S(m_nface), h_sh(m_nface), h_L(m_nface), h_H(m_nface), h_G(m_nface), h_r(m_nface), h_Q(m_nface), h_w(m_nface);
2484  Gpu::copy(Gpu::deviceToHost, d_w_star.begin(), d_w_star.end(), h_w.begin());
2485  Gpu::copy(Gpu::deviceToHost, d_resid.begin(), d_resid.end(), h_r.begin());
2486  Gpu::copy(Gpu::deviceToHost, d_Q_ext.begin(), d_Q_ext.end(), h_Q.begin());
2487  Gpu::copy(Gpu::deviceToHost, d_SW_abs.begin(), d_SW_abs.end(), h_S.begin());
2488  Gpu::copy(Gpu::deviceToHost, d_shadow.begin(), d_shadow.end(), h_sh.begin());
2489  Gpu::copy(Gpu::deviceToHost, d_LW_net.begin(), d_LW_net.end(), h_L.begin());
2490  Gpu::copy(Gpu::deviceToHost, d_H.begin(), d_H.end(), h_H.begin());
2491  Gpu::copy(Gpu::deviceToHost, d_G.begin(), d_G.end(), h_G.begin());
2492  Gpu::streamSynchronize();
2493 
2494  std::vector<Real> bsum(m_nbld + 1, 0.0), bsw(m_nbld + 1, 0.0), bsh(m_nbld + 1, 0.0), blw(m_nbld + 1, 0.0), bH(m_nbld + 1, 0.0);
2495  std::vector<Real> bG(m_nbld + 1, 0.0), bQ(m_nbld + 1, 0.0), btmin(m_nbld + 1, 1.0e30), btmax(m_nbld + 1, -1.0e30), bres(m_nbld + 1, 0.0);
2496  Real tmin = 1.0e30, tmax = -1.0e30, sw_sum = 0.0, sw_max = 0.0, sh_area = 0.0, lw_sum = 0.0, H_sum = 0.0, G_sum = 0.0;
2497  Real res_max = 0.0, Q_sum = 0.0, w_max = 0.0;
2498  for (int n = 0; n < m_nface; ++n) {
2499  w_max = std::max(w_max, h_w[n]);
2500  G_sum += h_G[n] * h_A[n];
2501  Q_sum += h_Q[n] * h_A[n];
2502  res_max = std::max(res_max, h_r[n]);
2503  bG[h_b[n]] += h_G[n] * h_A[n];
2504  bQ[h_b[n]] += h_Q[n] * h_A[n];
2505  btmin[h_b[n]] = std::min(btmin[h_b[n]], h_T[n]);
2506  btmax[h_b[n]] = std::max(btmax[h_b[n]], h_T[n]);
2507  bres[h_b[n]] = std::max(bres[h_b[n]], h_r[n]);
2508  bsum[h_b[n]] += h_T[n] * h_A[n];
2509  bsw[h_b[n]] += h_S[n] * h_A[n];
2510  bsh[h_b[n]] += h_sh[n] * h_A[n];
2511  blw[h_b[n]] += h_L[n] * h_A[n];
2512  bH[h_b[n]] += h_H[n] * h_A[n];
2513  tmin = std::min(tmin, h_T[n]);
2514  tmax = std::max(tmax, h_T[n]);
2515  sw_sum += h_S[n] * h_A[n];
2516  sw_max = std::max(sw_max, h_S[n]);
2517  sh_area += h_sh[n] * h_A[n];
2518  lw_sum += h_L[n] * h_A[n];
2519  H_sum += h_H[n] * h_A[n];
2520  }
2521  ParallelDescriptor::ReduceRealSum(bsum.data(), m_nbld + 1);
2522  ParallelDescriptor::ReduceRealSum(bsw.data(), m_nbld + 1);
2523  ParallelDescriptor::ReduceRealSum(bsh.data(), m_nbld + 1);
2524  ParallelDescriptor::ReduceRealSum(blw.data(), m_nbld + 1);
2525  ParallelDescriptor::ReduceRealSum(bH.data(), m_nbld + 1);
2526  ParallelDescriptor::ReduceRealSum(bG.data(), m_nbld + 1);
2527  ParallelDescriptor::ReduceRealSum(bQ.data(), m_nbld + 1);
2528  ParallelDescriptor::ReduceRealMin(btmin.data(), m_nbld + 1);
2529  ParallelDescriptor::ReduceRealMax(btmax.data(), m_nbld + 1);
2530  ParallelDescriptor::ReduceRealMax(bres.data(), m_nbld + 1);
2531  ParallelDescriptor::ReduceRealMax(res_max);
2532  ParallelDescriptor::ReduceRealMax(w_max);
2533  ParallelDescriptor::ReduceRealSum(Q_sum);
2534  ParallelDescriptor::ReduceRealMin(tmin);
2535  ParallelDescriptor::ReduceRealMax(tmax);
2536  ParallelDescriptor::ReduceRealSum(sw_sum);
2537  ParallelDescriptor::ReduceRealMax(sw_max);
2538  ParallelDescriptor::ReduceRealSum(sh_area);
2539  ParallelDescriptor::ReduceRealSum(lw_sum);
2540  ParallelDescriptor::ReduceRealSum(H_sum);
2541  ParallelDescriptor::ReduceRealSum(G_sum);
2542  const Real G_mean = (m_area_total > 0.0) ? G_sum / m_area_total : 0.0;
2543  const Real sw_mean = (m_area_total > 0.0) ? sw_sum / m_area_total : 0.0;
2544  const Real sh_frac = (m_area_total > 0.0) ? sh_area / m_area_total : 0.0;
2545  const Real lw_mean = (m_area_total > 0.0) ? lw_sum / m_area_total : 0.0;
2546  const Real H_mean = (m_area_total > 0.0) ? H_sum / m_area_total : 0.0;
2547 
2548  const Long nf_all = m_nface_dir[0] + m_nface_dir[1] + m_nface_dir[2];
2549  Print() << "[IBSEB] lev=" << m_lev << " step=" << step << " t=" << time
2550  << " faces=" << nf_all
2551  << " (x=" << m_nface_dir[0] << " y=" << m_nface_dir[1] << " z=" << m_nface_dir[2] << ")"
2552  << " buildings=" << m_nbld
2553  << " area=" << std::setprecision(10) << m_area_total << " m2"
2554  << " T_skin_min=" << ((nf_all > 0) ? tmin : Real(0.0))
2555  << " T_skin_max=" << ((nf_all > 0) ? tmax : Real(0.0))
2556  << " SW_abs_mean=" << sw_mean << " SW_abs_max=" << sw_max
2557  << " shadow_frac=" << sh_frac << " LW_net_mean=" << lw_mean
2558  << " H_mean=" << H_mean << " G_mean=" << G_mean
2559  << " Q_ext_mean=" << ((m_area_total > 0.0) ? Q_sum / m_area_total : Real(0.0))
2560  << " resid_max=" << res_max
2561  << " w_star_max=" << w_max
2562  << " H_total_W=" << std::setprecision(12) << H_sum << "\n";
2563  // Cost line: the slowest rank's per-step time of the balance and its face
2564  // count, so the cost of the face list on a larger case can be estimated.
2565  {
2566  Real ms = (m_cost_n > 0) ? 1000.0 * m_cost_s / m_cost_n : 0.0;
2567  Real ms_max = ms; int nf_max = m_nface;
2568  ParallelDescriptor::ReduceRealMax(ms_max);
2569  ParallelDescriptor::ReduceIntMax(nf_max);
2570  Print() << "[IBSEB] cost: lev=" << m_lev << " advance_ms_per_step_max=" << std::setprecision(4) << ms_max
2571  << " faces_per_rank_max=" << nf_max << " ranks=" << ParallelDescriptor::NProcs()
2572  << " init_s=" << m_init_cost_s << "\n";
2573  }
2574 
2575  if (m_params.debug) {
2576  for (int b = 1; b <= m_nbld; ++b) {
2577  const Real tmean = (m_bld_area[b] > 0.0) ? bsum[b] / m_bld_area[b] : Real(0.0);
2578  const Real swm = (m_bld_area[b] > 0.0) ? bsw[b] / m_bld_area[b] : Real(0.0);
2579  const Real shf = (m_bld_area[b] > 0.0) ? bsh[b] / m_bld_area[b] : Real(0.0);
2580  const Real lwm = (m_bld_area[b] > 0.0) ? blw[b] / m_bld_area[b] : Real(0.0);
2581  const Real Hm = (m_bld_area[b] > 0.0) ? bH[b] / m_bld_area[b] : Real(0.0);
2582  const Real Gm = (m_bld_area[b] > 0.0) ? bG[b] / m_bld_area[b] : Real(0.0);
2583  Print() << "[IBSEB DEBUG] building " << b << ": faces=" << m_bld_nface[b]
2584  << " area=" << m_bld_area[b] << " m2 T_skin_mean=" << tmean << " K"
2585  << " [" << btmin[b] << ", " << btmax[b] << "]"
2586  << " SW_abs_mean=" << swm << " W/m2 shadow_frac=" << shf
2587  << " LW_net_mean=" << lwm << " W/m2 H_mean=" << Hm << " W/m2 G_mean=" << Gm
2588  << " W/m2 resid_max=" << bres[b] << " W/m2\n";
2589  }
2590  }
2591 
2592  if (write_csv && !m_params.dump_faces_file.empty()) {
2593  std::string prefix = m_params.dump_faces_file;
2594  // Each level has its own list; a refined level tags its files so it
2595  // does not overwrite the dump of the level below.
2596  if (m_lev > 0) { prefix += ".lev" + std::to_string(m_lev); }
2598  std::ostringstream os;
2599  os << prefix << ".step" << std::setw(6) << std::setfill('0') << step;
2600  prefix = os.str();
2601  }
2602  dump_faces(prefix);
2603  }
2604 
2605  if (!write_csv || !ParallelDescriptor::IOProcessor()) { return; }
2606  const std::string header =
2607  "time_s,step,level,building,n_faces,area_m2,T_skin_mean_K,SW_abs_mean_Wm2,shadow_frac,LW_net_mean_Wm2,H_mean_Wm2,"
2608  "G_mean_Wm2,Q_ext_mean_Wm2,T_skin_min_K,T_skin_max_K,resid_max_Wm2,"
2609  "sun_zenith_deg,sun_azimuth_deg,dni_Wm2,diffuse_h_Wm2,building_level0";
2610  bool need_header = true;
2611  {
2612  // A restarted run appends; a file another version of the report wrote
2613  // (other columns) would take rows its header does not describe.
2614  std::ifstream probe(m_params.csv_file);
2615  std::string first;
2616  if (probe.good() && std::getline(probe, first)) {
2617  if (!first.empty() && first.back() == '\r') { first.pop_back(); }
2618  if (first != header) {
2619  Abort("erf.ibseb: " + m_params.csv_file + " has another set of columns than this version writes ("
2620  + first.substr(0, 60) + "...); move it aside or set erf.ibseb.csv_file to a new name");
2621  }
2622  need_header = false;
2623  }
2624  }
2625  std::ofstream csv(m_params.csv_file, std::ios::app);
2626  if (need_header) { csv << header << "\n"; }
2627  for (int b = 1; b <= m_nbld; ++b) {
2628  const Real tmean = (m_bld_area[b] > 0.0) ? bsum[b] / m_bld_area[b] : Real(0.0);
2629  const Real swm = (m_bld_area[b] > 0.0) ? bsw[b] / m_bld_area[b] : Real(0.0);
2630  const Real shf = (m_bld_area[b] > 0.0) ? bsh[b] / m_bld_area[b] : Real(0.0);
2631  const Real lwm = (m_bld_area[b] > 0.0) ? blw[b] / m_bld_area[b] : Real(0.0);
2632  const Real Hm = (m_bld_area[b] > 0.0) ? bH[b] / m_bld_area[b] : Real(0.0);
2633  const Real Gm = (m_bld_area[b] > 0.0) ? bG[b] / m_bld_area[b] : Real(0.0);
2634  const Real Qm = (m_bld_area[b] > 0.0) ? bQ[b] / m_bld_area[b] : Real(0.0);
2635  csv << std::setprecision(10) << time << "," << step << "," << m_lev << "," << b << ","
2636  << m_bld_nface[b] << "," << m_bld_area[b] << "," << tmean << "," << swm << "," << shf << "," << lwm << "," << Hm << ","
2637  << Gm << "," << Qm << "," << btmin[b] << "," << btmax[b] << "," << bres[b] << ","
2638  << m_sun.zenith * 180.0 / PI << "," << m_sun.azimuth * 180.0 / PI << "," << m_sun.dni << "," << m_sun.diffuse_h << ","
2639  << m_to_lev0[b] << "\n";
2640  }
2641 }
Vector< Real > h_r(khi+2)
void dump_faces(const std::string &prefix) const
Definition: ERF_IBFaceSet.cpp:2031
double m_init_cost_s
Wall-clock seconds of build() and compute_view_fractions()
Definition: ERF_IBFaceSet.H:701
bool dump_faces_tag_step
Name each dump by its step (keeps every one) instead of overwriting.
Definition: ERF_IBSEBParams.H:34
std::string dump_faces_file
Per-rank face dump at report time (empty = off); a refined level N adds ".levN".
Definition: ERF_IBSEBParams.H:33
Here is the call graph for this function:

◆ scatter_diagnostics()

void IBFaceSet::scatter_diagnostics ( amrex::MultiFab &  nfaces,
amrex::MultiFab &  tskin 
) const

Scatter the faces into two cell-centered diagnostics for the plotfile.

Parameters
[out]nfacesNumber of wall faces touching each fluid cell (0 away from buildings; up to 3 at an outside corner, 6 in a one-cell slot).
[out]tskinMean skin temperature of those faces, 0 where there are none.

Both fields must be on the level's box array with no ghost cells. Faces of one fab are accumulated with atomic adds because a corner cell receives several faces.

Scatter the face count and the mean skin temperature into cell-centered fields. One kernel per fab over that fab's faces (contiguous, see fab_start()), with atomic adds since a corner cell collects several faces, then a kernel over the box divides the temperature sum by the count.

2138 {
2139  nfaces.setVal(0.0);
2140  tskin.setVal(0.0);
2141  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
2142  const Real* pT = d_T_skin.data();
2143  for (MFIter mfi(nfaces); mfi.isValid(); ++mfi) {
2144  const int f0 = m_fab_start[mfi.LocalIndex()];
2145  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
2146  auto const& n = nfaces.array(mfi);
2147  auto const& t = tskin.array(mfi);
2148  ParallelFor(f1 - f0, [=] AMREX_GPU_DEVICE (int m) noexcept {
2149  const int f = f0 + m;
2150  Gpu::Atomic::AddNoRet(&n(pi[f], pj[f], pk[f]), Real(1.0));
2151  Gpu::Atomic::AddNoRet(&t(pi[f], pj[f], pk[f]), pT[f]);
2152  });
2153  const Box& bx = mfi.validbox();
2154  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
2155  if (n(i, j, k) > 0.0) { t(i, j, k) /= n(i, j, k); }
2156  });
2157  }
2158  Gpu::streamSynchronize();
2159 }
Here is the call graph for this function:

◆ scatter_field()

void IBFaceSet::scatter_field ( const amrex::Gpu::DeviceVector< amrex::Real > &  v,
amrex::MultiFab &  out 
) const

Scatter one per-face array into a cell-centered field as the mean over the faces touching each cell (zero where there are none).

Scatter one per-face array as a per-cell mean, the same accumulation as scatter_diagnostics() with the face count as the divisor.

2003 {
2004  MultiFab cnt(out.boxArray(), out.DistributionMap(), 1, 0);
2005  cnt.setVal(0.0);
2006  out.setVal(0.0);
2007  const int* pi = d_i.data(); const int* pj = d_j.data(); const int* pk = d_k.data();
2008  const Real* pv = v.data();
2009  for (MFIter mfi(out); mfi.isValid(); ++mfi) {
2010  const int f0 = m_fab_start[mfi.LocalIndex()];
2011  const int f1 = m_fab_start[mfi.LocalIndex() + 1];
2012  auto const& n = cnt.array(mfi);
2013  auto const& o = out.array(mfi);
2014  ParallelFor(f1 - f0, [=] AMREX_GPU_DEVICE (int m) noexcept {
2015  const int f = f0 + m;
2016  Gpu::Atomic::AddNoRet(&n(pi[f], pj[f], pk[f]), Real(1.0));
2017  Gpu::Atomic::AddNoRet(&o(pi[f], pj[f], pk[f]), pv[f]);
2018  });
2019  ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
2020  if (n(i, j, k) > 0.0) { o(i, j, k) /= n(i, j, k); }
2021  });
2022  }
2023  Gpu::streamSynchronize();
2024 }
Here is the call graph for this function:

◆ set_init_cost()

void IBFaceSet::set_init_cost ( double  seconds)
inline

Record the wall-clock time of the initialization (build and view fractions).

630 { m_init_cost_s = seconds; }

◆ set_two_stream_sun()

void IBFaceSet::set_two_stream_sun ( amrex::Real  declination,
amrex::Real  hour_angle,
amrex::Real  latitude_deg,
amrex::Real  toa_irradiance 
)
inline

Give the sun of the next compute_shortwave() or fill_roofs() with erf.ibseb.sun_mode = two_stream: the two-stream radiation's declination and hour angle at that time, its site latitude and its top-of-atmosphere irradiance (the date's distance factor included). ERF::ibseb_set_two_stream_sun() calls it before every call; the call uses it up, so a shortwave or a roofs' shadow without a fresh sun stops rather than reusing an old one.

154  {
155  m_ts_sun = {true, declination, hour_angle, latitude_deg, toa_irradiance};
156  }

◆ solve_balance()

void IBFaceSet::solve_balance ( amrex::Real  dt)

Prognostic balance of the current step. Per face: the slab's linear response to the skin temperature for this step, the Newton solve of ERF_IBSEBBalance.H with the shortwave, the external flux, the sky and ground longwave, the frozen wall-function coefficient and the latent flux, the slab advanced with the solution, and the fluxes (LW_in, LW_net, H, G) rewritten at the solution. Fills d_resid (|balance| at the end, non-zero only at a bound or the iteration cap) and d_niter. Needs compute_shortwave(), compute_longwave() and compute_sensible() of the same step first.

Parameters
dtAtmospheric time step [s], the slab's step.

Prognostic balance on every face: one kernel over the faces, each with its own slab response, Newton solve and slab advance. Everything the solve needs was stored by the three flux routines of the step, so no fab data is touched here. The fluxes are rewritten at the solution so that the dump, the reports and the heat deposited into the air all describe the same closed balance; d_resid holds what is left of it.

1266 {
1267  const int nl = n_layers();
1268  const Real Tint = m_params.T_interior;
1269  const Real Tmin = m_params.T_skin_min, Tmax = m_params.T_skin_max;
1270  const Real tol = m_params.newton_tol_K, max_step = m_params.newton_max_step_K;
1271  const int max_iter = m_params.newton_max_iter;
1272  const Real* pkt = d_kth.data(); const Real* prc = d_rhocp.data(); const Real* pth = d_thick.data();
1273  const Real* peps = d_emis.data(); const Real* pfb = d_f_bldg.data();
1274  const Real* psw = d_SW_abs.data(); const Real* pq = d_Q_ext.data(); const Real* pext = d_LW_ext.data();
1275  const Real* pHc = d_H_coeff.data(); const Real* pTa = d_T_air.data(); const Real* ptha = d_theta_air.data();
1276  const Real* pLE = d_LE.data();
1277  Real* pT = d_T_skin.data(); Real* pS = d_T_slab.data(); Real* pG = d_G.data();
1278  Real* pH = d_H.data(); Real* pin = d_LW_down_in.data(); Real* pnet = d_LW_net.data();
1279  Real* pres = d_resid.data(); int* pnit = d_niter.data();
1280  ParallelFor(m_nface, [=] AMREX_GPU_DEVICE (int f) noexcept {
1281  // Zero-initialized: only the first nl entries are ever used, but the
1282  // compiler cannot see that through the inlined solve and warns otherwise.
1283  Real T[ibseb::SLAB_MAX_LAYERS] = {};
1284  for (int l = 0; l < nl; ++l) { T[l] = pS[f * nl + l]; }
1285  const Real dz = pth[f] / nl;
1286  // Conduction the implicit slab step will take for a skin temperature Ts: a Ts - b.
1287  Real a = 0.0, b = 0.0;
1288  ibseb::slab_skin_response(T, Tint, pkt[f], prc[f], dz, dt, nl, a, b);
1289  const Real exner = pTa[f] / ptha[f];
1290  const Real q_abs = peps[f] * pq[f];
1291  int n_it = 0; Real res = 0.0;
1292  const Real Ts = ibseb::solve_skin_balance(pT[f], psw[f], q_abs, pext[f], peps[f], pfb[f],
1293  pHc[f], exner, ptha[f], pLE[f], a, b,
1294  Tmin, Tmax, max_step, tol, max_iter, n_it, res);
1295  // Advance the slab with the solution and store every term at it.
1296  pG[f] = ibseb::advance_slab_dirichlet(T, Ts, Tint, pkt[f], prc[f], dz, dt, nl);
1297  for (int l = 0; l < nl; ++l) { pS[f * nl + l] = T[l]; }
1298  const Real Ts4 = Ts * Ts * Ts * Ts;
1299  pin[f] = pext[f] + pfb[f] * ibseb::SIGMA_SB * Ts4;
1300  pnet[f] = peps[f] * (pin[f] - ibseb::SIGMA_SB * Ts4);
1301  pH[f] = pHc[f] * (Ts / exner - ptha[f]);
1302  pT[f] = Ts;
1303  // The residual with the stored terms (the slab's own G, not a Ts - b),
1304  // so it reports the closure of what is written out.
1305  pres[f] = std::abs(psw[f] + q_abs + pnet[f] - pH[f] - pLE[f] - pG[f]);
1306  pnit[f] = n_it;
1307  });
1308  Gpu::streamSynchronize();
1309 
1310  if (m_params.debug) {
1311  std::vector<Real> h_r(m_nface), h_T(m_nface);
1312  std::vector<int> h_n(m_nface);
1313  Gpu::copy(Gpu::deviceToHost, d_resid.begin(), d_resid.end(), h_r.begin());
1314  Gpu::copy(Gpu::deviceToHost, d_T_skin.begin(), d_T_skin.end(), h_T.begin());
1315  Gpu::copy(Gpu::deviceToHost, d_niter.begin(), d_niter.end(), h_n.begin());
1316  Gpu::streamSynchronize();
1317  Real rmax = 0.0; int nmax = 0; Long nclamp = 0;
1318  for (int n = 0; n < m_nface; ++n) {
1319  rmax = std::max(rmax, h_r[n]); nmax = std::max(nmax, h_n[n]);
1320  if (h_T[n] <= Tmin || h_T[n] >= Tmax) { ++nclamp; }
1321  }
1322  ParallelDescriptor::ReduceRealMax(rmax);
1323  ParallelDescriptor::ReduceIntMax(nmax);
1324  ParallelDescriptor::ReduceLongSum(nclamp);
1325  Print() << "[IBSEB DEBUG] lev=" << m_lev << " balance: dt=" << dt << " s newton iterations max=" << nmax
1326  << " residual max=" << rmax << " W/m2 faces at a bound=" << nclamp << "\n";
1327  }
1328 }
@ pres
Definition: ERF_Kessler.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void slab_skin_response(const amrex::Real *T, amrex::Real T_int, amrex::Real k, amrex::Real rho_cp, amrex::Real dz, amrex::Real dt, int N, amrex::Real &a, amrex::Real &b)
Definition: ERF_IBSEBSlab.H:105
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real solve_skin_balance(amrex::Real T_start, amrex::Real SW_abs, amrex::Real Q_abs, amrex::Real LW_ext, amrex::Real emis, amrex::Real f_bldg, amrex::Real C_H, amrex::Real exner, amrex::Real theta_air, amrex::Real LE, amrex::Real slab_a, amrex::Real slab_b, amrex::Real T_min, amrex::Real T_max, amrex::Real max_step, amrex::Real tol, int max_iter, int &n_iter, amrex::Real &resid)
Definition: ERF_IBSEBBalance.H:80
amrex::Real newton_max_step_K
Largest Newton step [K].
Definition: ERF_IBSEBParams.H:177
amrex::Real newton_tol_K
Newton stops when a step changes T_skin by less than this [K].
Definition: ERF_IBSEBParams.H:176
amrex::Real T_skin_min
Lower bound of the skin temperature [K].
Definition: ERF_IBSEBParams.H:173
amrex::Real T_skin_max
Upper bound [K]; raise it for faces under a fire.
Definition: ERF_IBSEBParams.H:174
int newton_max_iter
Newton iteration cap per face and step.
Definition: ERF_IBSEBParams.H:175
Here is the call graph for this function:

◆ sun()

const SunState& IBFaceSet::sun ( ) const
inline
615 { return m_sun; }

◆ sun_at()

IBFaceSet::SunState IBFaceSet::sun_at ( amrex::Real  time) const

The sun at time by erf.ibseb.sun_mode; changes nothing in the set (see the definition).

The sun at time by erf.ibseb.sun_mode: its position and unit vector, and the clear-sky irradiances of the faces' own radiation. It changes nothing in the set, so the shortwave (compute_shortwave()) and the roofs' shadow (fill_roofs()) each ask for the sun of their own time. With sun_mode = two_stream the two-stream sun of that time must have been given (set_two_stream_sun()).

1519 {
1520  SunState s;
1521  if (m_params.sun_mode == "fixed") {
1522  s.zenith = m_params.sun_zenith_deg * PI / 180.0;
1523  s.azimuth = m_params.sun_azimuth_deg * PI / 180.0;
1524  const Real cz = std::cos(s.zenith);
1525  s.dni = (cz > 0.0) ? m_params.sw_direct_normal : 0.0;
1526  s.diffuse_h = (cz > 0.0) ? m_params.sw_diffuse : 0.0;
1527  } else if (m_params.sun_mode == "two_stream") {
1529  "erf.ibseb.sun_mode = two_stream: the two-stream sun was not given before the shortwave or the roofs' shadow");
1530  const Real decl = m_ts_sun.decl;
1531  const Real ha = m_ts_sun.hour_angle;
1532  s.zenith = ibseb::solar_zenith(m_ts_sun.lat_deg, decl, ha);
1533  s.azimuth = ibseb::solar_azimuth(m_ts_sun.lat_deg, decl, ha, s.zenith);
1534  const Real cz = std::cos(s.zenith);
1535  // The irradiance carries the date's distance factor already.
1536  s.dni = ibseb::clear_sky_dni(cz, m_ts_sun.S0, m_params.sw_transmission, Real(1.0));
1538  Real(1.0), m_params.sw_diffuse_coeff);
1539  } else {
1540  const Real t_utc = m_params.time_zero_utc_s + time;
1541  // The date advances at each 00:00 UTC, so a run of several days follows the season.
1542  const Real day = ibseb::day_of_year_at(m_params.day_of_year, t_utc);
1543  const Real decl = ibseb::solar_declination(day);
1544  // Hour angle from UTC and the longitude (a time-zone offset would cancel).
1545  const Real ha = ibseb::solar_hour_angle(t_utc, m_params.longitude_deg, day);
1546  s.zenith = ibseb::solar_zenith(m_params.latitude_deg, decl, ha);
1547  s.azimuth = ibseb::solar_azimuth(m_params.latitude_deg, decl, ha, s.zenith);
1548  const Real cz = std::cos(s.zenith);
1549  const Real e0 = ibseb::earth_sun_distance_factor(day);
1553  }
1554  ibseb::sun_vector(s.zenith, s.azimuth, s.sx, s.sy, s.sz);
1555  return s;
1556 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real solar_zenith(amrex::Real latitude_deg, amrex::Real decl, amrex::Real hour_angle)
Definition: ERF_IBSEBSolar.H:116
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real clear_sky_dni(amrex::Real cos_zenith, amrex::Real S0, amrex::Real tau, amrex::Real distance_factor)
Definition: ERF_IBSEBSolar.H:179
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real earth_sun_distance_factor(amrex::Real day_of_year)
Definition: ERF_IBSEBSolar.H:155
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void sun_vector(amrex::Real zenith, amrex::Real azimuth, amrex::Real &sx, amrex::Real &sy, amrex::Real &sz)
Definition: ERF_IBSEBSolar.H:164
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real solar_azimuth(amrex::Real latitude_deg, amrex::Real decl, amrex::Real hour_angle, amrex::Real zenith)
Definition: ERF_IBSEBSolar.H:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real day_of_year_at(amrex::Real day0, amrex::Real t_utc_s)
Definition: ERF_IBSEBSolar.H:55
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real solar_declination(amrex::Real day_of_year)
Definition: ERF_IBSEBSolar.H:62
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real solar_hour_angle(amrex::Real time_utc_s, amrex::Real longitude_deg, amrex::Real day_of_year)
Definition: ERF_IBSEBSolar.H:87
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real clear_sky_diffuse_h(amrex::Real cos_zenith, amrex::Real S0, amrex::Real tau, amrex::Real distance_factor, amrex::Real k_d)
Definition: ERF_IBSEBSolar.H:192
amrex::Real lat_deg
Definition: ERF_IBFaceSet.H:697
amrex::Real S0
Definition: ERF_IBFaceSet.H:697
amrex::Real decl
Definition: ERF_IBFaceSet.H:697
amrex::Real hour_angle
Definition: ERF_IBFaceSet.H:697
amrex::Real day_of_year
solar: day of year
Definition: ERF_IBSEBParams.H:63
amrex::Real sw_transmission
solar, two_stream: bulk clear-sky transmission (Bird)
Definition: ERF_IBSEBParams.H:66
amrex::Real longitude_deg
solar: site longitude, east positive
Definition: ERF_IBSEBParams.H:62
amrex::Real solar_constant
solar: [W/m2]
Definition: ERF_IBSEBParams.H:65
amrex::Real sw_direct_normal
fixed: direct-normal irradiance [W/m2]
Definition: ERF_IBSEBParams.H:59
amrex::Real time_zero_utc_s
solar: seconds after 00:00 UTC at simulation time zero (the sun follows UTC and the longitude)
Definition: ERF_IBSEBParams.H:64
amrex::Real sun_zenith_deg
fixed: zenith angle [deg]
Definition: ERF_IBSEBParams.H:57
amrex::Real sw_diffuse
fixed: diffuse irradiance on a horizontal surface [W/m2]
Definition: ERF_IBSEBParams.H:60
amrex::Real sun_azimuth_deg
fixed: azimuth clockwise from north [deg]; 180 = sun in the south
Definition: ERF_IBSEBParams.H:58
amrex::Real latitude_deg
solar: site latitude, north positive
Definition: ERF_IBSEBParams.H:61
amrex::Real sw_diffuse_coeff
solar, two_stream: share of the attenuated beam that arrives as diffuse light
Definition: ERF_IBSEBParams.H:67

Referenced by compute_shortwave(), and fill_roofs().

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

◆ top_sample_interface()

int IBFaceSet::top_sample_interface ( ) const
inline

The highest interface of the level's vertical grid that any of its faces samples with radiation = two_stream (a roof the bottom of its fluid cell, a ceiling and a wall the top of its cell too), counted from the domain bottom, over all ranks; -1 when the level has no faces. The two-stream beam the faces read holds the interfaces up to there.

414 { return m_top_sample; }

◆ warn_fixed_sun_below_floor()

void IBFaceSet::warn_fixed_sun_below_floor ( ) const
private

Warn once when a fixed sun stands below erf.ibseb.sun_min_elev_deg and the map does not span the domain.

Warn when a fixed sun stands below erf.ibseb.sun_min_elev_deg and the ray map does not span the domain: the shadows of buildings beyond the halo are then not cast. Printed once per level by the I/O rank.

770 {
771  if (m_params.sun_mode != "fixed" || m_map_spans_domain) { return; }
772  const Real elev = 90.0 - m_params.sun_zenith_deg;
773  if (elev >= m_params.sun_min_elev_deg) { return; }
774  std::ostringstream os;
775  os << "erf.ibseb: the fixed sun stands " << elev << " deg above the horizon, below erf.ibseb.sun_min_elev_deg = "
776  << m_params.sun_min_elev_deg << ", and the ray map of level " << m_lev << " does not span the domain: a building"
777  " farther than " << m_halo[0] * m_dx[0] << " m in x or " << m_halo[1] * m_dx[1] << " m in y from a face casts no shadow"
778  " on it, nor on the ground beneath the face's column (erf.ibseb.two_stream_buildings). Lower erf.ibseb.sun_min_elev_deg to the sun's elevation for exact shadows.";
779  if (ParallelDescriptor::IOProcessor()) { Warning(os.str().c_str()); }
780 }

◆ write_state()

void IBFaceSet::write_state ( const std::string &  file) const

Write the face state (skin temperature, sensible flux and slab temperatures) to file for the checkpoint: one record per face of the level, in one global order, written by the I/O rank.

The file holds one text line, IBSEBFaces 1 <nface> <n_layers> <nx> <ny> <nz> (the format version, the level's face count, the slab layers per face and the domain size in cells), then in binary a marker word (0x0102030405060708 as a 64-bit integer, so a file from a machine with another byte order is refused), the nface keys as 64-bit integers in ascending order, then the nface x (2 + n_layers) values as doubles: a face's skin temperature, its sensible flux (read as the previous step's by the convective velocity scale) and its slab layers from the skin inward. The key of a face is ((i ny + j) nz + k) 6 + 2 dir + (side > 0) with (i, j, k) counted from the domain's low corner, so it names the face whatever the rank count. The values are doubles whatever amrex::Real is, so a single-precision run reads a double-precision checkpoint and the other way round. The file costs 8 (3 + n_layers) bytes per face beyond its header line and marker, which is the data itself: the cell field it replaces covered the face-owning cells with whole boxes and was about eleven times larger on the FaceStorage skyscraper (erf-model/ERF#4019).

Every rank copies its faces to the host and sorts them by key; the I/O rank gathers the records, orders them and writes the file. Collective: every rank must call it.

One record per face, gathered on the I/O rank and written in key order: the header line, the sorted keys, then the values record by record. Every rank sorts its own faces first so the gathered runs are ordered; the I/O rank then merges them by sorting an index over all the records.

2226 {
2227  const int nl = n_layers();
2228  const int nrec = 2 + nl;
2229  const int nf = m_nface;
2230  const bool io = ParallelDescriptor::IOProcessor();
2231  const int root = ParallelDescriptor::IOProcessorNumber();
2232 
2233  std::vector<int> h_i(nf), h_j(nf), h_k(nf), h_dir(nf), h_side(nf);
2234  std::vector<Real> h_T(nf), h_H(nf), h_S(static_cast<size_t>(nf) * nl);
2235  Gpu::copy(Gpu::deviceToHost, d_i.begin(), d_i.end(), h_i.begin());
2236  Gpu::copy(Gpu::deviceToHost, d_j.begin(), d_j.end(), h_j.begin());
2237  Gpu::copy(Gpu::deviceToHost, d_k.begin(), d_k.end(), h_k.begin());
2238  Gpu::copy(Gpu::deviceToHost, d_dir.begin(), d_dir.end(), h_dir.begin());
2239  Gpu::copy(Gpu::deviceToHost, d_side.begin(), d_side.end(), h_side.begin());
2240  Gpu::copy(Gpu::deviceToHost, d_T_skin.begin(), d_T_skin.end(), h_T.begin());
2241  Gpu::copy(Gpu::deviceToHost, d_H.begin(), d_H.end(), h_H.begin());
2242  Gpu::copy(Gpu::deviceToHost, d_T_slab.begin(), d_T_slab.end(), h_S.begin());
2243  Gpu::streamSynchronize();
2244 
2245  // This rank's records in key order.
2246  std::vector<Long> my_key(nf);
2247  for (int n = 0; n < nf; ++n) {
2248  my_key[n] = face_key(h_i[n] - m_dom_lo[0], h_j[n] - m_dom_lo[1], h_k[n] - m_dom_lo[2],
2249  h_dir[n], h_side[n], m_ny, m_nz);
2250  }
2251  std::vector<int> order(nf);
2252  std::iota(order.begin(), order.end(), 0);
2253  std::sort(order.begin(), order.end(), [&] (int a, int b) { return my_key[a] < my_key[b]; });
2254  std::vector<Long> key(nf);
2255  std::vector<double> val(static_cast<size_t>(nf) * nrec);
2256  for (int m = 0; m < nf; ++m) {
2257  const int n = order[m];
2258  key[m] = my_key[n];
2259  double* r = &val[static_cast<size_t>(m) * nrec];
2260  r[0] = static_cast<double>(h_T[n]);
2261  r[1] = static_cast<double>(h_H[n]);
2262  for (int l = 0; l < nl; ++l) { r[2 + l] = static_cast<double>(h_S[static_cast<size_t>(n) * nl + l]); }
2263  }
2264 
2265  // Every rank's records on the I/O rank.
2266  std::vector<int> counts, disp, vcounts, vdisp;
2267  gather_counts(nf, counts, disp);
2268  scale_counts(counts, disp, nrec, vcounts, vdisp);
2269  Long ntot = 0;
2270  for (int c : counts) { ntot += c; }
2271  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ntot * nrec < std::numeric_limits<int>::max(),
2272  "erf.ibseb: too many face records for one checkpoint file");
2273  std::vector<Long> all_key(io ? ntot : 0);
2274  std::vector<double> all_val(io ? ntot * nrec : 0);
2275  ParallelDescriptor::Gatherv(key.data(), nf, all_key.data(), counts, disp, root);
2276  ParallelDescriptor::Gatherv(val.data(), nf * nrec, all_val.data(), vcounts, vdisp, root);
2277 
2278  if (io) {
2279  std::vector<Long> perm(ntot);
2280  std::iota(perm.begin(), perm.end(), 0);
2281  std::sort(perm.begin(), perm.end(), [&] (Long a, Long b) { return all_key[a] < all_key[b]; });
2282  for (Long m = 1; m < ntot; ++m) {
2283  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(all_key[perm[m]] != all_key[perm[m - 1]],
2284  "erf.ibseb: two faces of the level share a checkpoint key");
2285  }
2286  std::vector<Long> skey(ntot);
2287  std::vector<double> sval(static_cast<size_t>(ntot) * nrec);
2288  for (Long m = 0; m < ntot; ++m) {
2289  skey[m] = all_key[perm[m]];
2290  std::copy_n(&all_val[static_cast<size_t>(perm[m]) * nrec], nrec, &sval[static_cast<size_t>(m) * nrec]);
2291  }
2292  std::ofstream f(file, std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
2293  if (!f) { Abort("erf.ibseb: cannot open " + file + " for writing"); }
2294  f << "IBSEBFaces 1 " << ntot << " " << nl << " " << m_nx << " " << m_ny << " " << m_nz << "\n";
2295  const Long marker = face_file_marker;
2296  f.write(reinterpret_cast<const char*>(&marker), sizeof(Long));
2297  f.write(reinterpret_cast<const char*>(skey.data()), static_cast<std::streamsize>(ntot * sizeof(Long)));
2298  f.write(reinterpret_cast<const char*>(sval.data()), static_cast<std::streamsize>(sval.size() * sizeof(double)));
2299  if (!f) { Abort("erf.ibseb: writing " + file + " failed"); }
2300  if (m_params.debug) {
2301  Print() << "[IBSEB DEBUG] lev=" << m_lev << " face state saved: " << ntot << " records x "
2302  << nrec << " values (" << ntot * nrec << " values, "
2303  << ntot * (sizeof(Long) + nrec * sizeof(double)) << " bytes of records) to " << file << "\n";
2304  }
2305  }
2306 }
Here is the call graph for this function:

Member Data Documentation

◆ d_albedo

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_albedo

◆ d_area

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_area

◆ d_bid

amrex::Gpu::DeviceVector<int> IBFaceSet::d_bid

Building id (1-based)

Referenced by dump_faces(), and report().

◆ d_dir

amrex::Gpu::DeviceVector<int> IBFaceSet::d_dir

◆ d_emis

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_emis

Optical properties of the face.

Referenced by compute_ground_walls(), dump_faces(), and fill_roofs().

◆ d_f_bldg

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_f_bldg

View fractions, sum to 1

Referenced by dump_faces().

◆ d_f_ground

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_f_ground

◆ d_f_ground_lit

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_f_ground_lit

With erf.ibseb.ground_view_shadow, the part of f_ground that is ground the sun of the last compute_shortwave() reaches (0 at night or where the ground gets no beam; 0 and unused without the input). Not state: recomputed every step.

Referenced by compute_shortwave(), compute_shortwave_two_stream(), and dump_faces().

◆ d_f_sky

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_f_sky

◆ d_G

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_G

Referenced by dump_faces(), and report().

◆ d_gnd_far

amrex::Gpu::DeviceVector<int> IBFaceSet::d_gnd_far

◆ d_gnd_land

amrex::Gpu::DeviceVector<unsigned int> IBFaceSet::d_gnd_land

◆ d_gnd_rays

amrex::Gpu::DeviceVector<int> IBFaceSet::d_gnd_rays

◆ d_gnd_start

amrex::Gpu::DeviceVector<int> IBFaceSet::d_gnd_start

With erf.ibseb.ground_view_shadow, where each face's ground rays land (build_ground_landings()): face f owns the entries [d_gnd_start[f], d_gnd_start[f+1]) of d_gnd_land (the distinct landing columns, ibseb::pack_landing()) and of d_gnd_rays (the rays that land in each), and d_gnd_far[f] of its ground rays end on the far field's open ground. Static, like the view fractions.

Referenced by compute_ground_walls(), compute_shortwave(), and compute_shortwave_two_stream().

◆ d_H

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_H

◆ d_H_coeff

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_H_coeff

H = H_coeff (theta_skin - theta_air) [W/m2/K].

Referenced by dump_faces().

◆ d_hbld

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_hbld

Height of the face's building column [m].

Referenced by dump_faces().

◆ d_i

◆ d_j

◆ d_k

amrex::Gpu::DeviceVector<int> IBFaceSet::d_k

◆ d_kth

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_kth

Referenced by dump_faces().

◆ d_LE

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_LE

Referenced by dump_faces().

◆ d_LW_down_in

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_LW_down_in

Incoming longwave on the face (sky, ground and walls)

Referenced by compute_ground_walls(), and dump_faces().

◆ d_LW_ext

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_LW_ext

Incoming longwave from sky and ground only [W/m2].

Referenced by dump_faces().

◆ d_LW_net

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_LW_net

Referenced by dump_faces(), and report().

◆ d_mat

amrex::Gpu::DeviceVector<int> IBFaceSet::d_mat

Material id (0 = uniform inputs)

Referenced by dump_faces().

◆ d_niter

amrex::Gpu::DeviceVector<int> IBFaceSet::d_niter

Newton iterations of the last solve.

Referenced by dump_faces().

◆ d_olen

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_olen

Obukhov length used [m] (1e30 when neutral)

Referenced by dump_faces().

◆ d_Q_ext

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_Q_ext

External incident flux [W/m2], e.g. fire radiation.

Referenced by dump_faces(), and report().

◆ d_resid

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_resid

|balance| after the solve [W/m2]

Referenced by dump_faces(), and report().

◆ d_rho

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_rho

Density of the fluid cell [kg/m3].

Referenced by dump_faces().

◆ d_rhocp

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_rhocp

Referenced by dump_faces().

◆ d_roof_face

amrex::Gpu::DeviceVector<int> IBFaceSet::d_roof_face

fill_roofs(): the roof faces (indices into the face arrays), fab by fab

Referenced by fill_roofs().

◆ d_shadow

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_shadow

1 when the ray to the sun hits a building, else 0

Referenced by compute_shortwave(), compute_shortwave_two_stream(), dump_faces(), and report().

◆ d_side

amrex::Gpu::DeviceVector<int> IBFaceSet::d_side

Solid neighbor at -1 (low) or +1 (high) side.

Referenced by compute_shortwave(), compute_shortwave_two_stream(), dump_faces(), fill_roofs(), read_state(), and write_state().

◆ d_SW_abs

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_SW_abs

◆ d_SW_diffuse_in

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_SW_diffuse_in

Sky and ground-reflected diffuse incident.

Referenced by compute_ground_walls(), compute_shortwave(), compute_shortwave_two_stream(), and dump_faces().

◆ d_SW_direct_in

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_SW_direct_in

Direct beam incident on the face.

Referenced by compute_ground_walls(), compute_shortwave(), compute_shortwave_two_stream(), and dump_faces().

◆ d_T_air

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_T_air

Air temperature of the fluid cell.

Referenced by dump_faces().

◆ d_T_skin

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_T_skin

◆ d_T_slab

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_T_slab

Slab layers [K], face-major: [face * n_layers + layer].

Referenced by dump_faces(), read_state(), and write_state().

◆ d_theta_air

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_theta_air

Potential temperature of the fluid cell [K].

Referenced by dump_faces().

◆ d_thick

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_thick

Slab conductivity [W/m/K], heat capacity [J/m3/K], thickness [m].

Referenced by dump_faces().

◆ d_U_tan

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_U_tan

Tangential wind speed at the fluid cell [m/s].

Referenced by dump_faces().

◆ d_ustar

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_ustar

Friction velocity of the wall function [m/s].

Referenced by dump_faces().

◆ d_w_star

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_w_star

Convective velocity scale of the step [m/s].

Referenced by dump_faces(), and report().

◆ d_xf

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_xf

◆ d_yf

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_yf

◆ d_z_i

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_z_i

Depth in w* [m]: mixed layer above a roof, building height for a wall.

Referenced by dump_faces().

◆ d_zf

amrex::Gpu::DeviceVector<amrex::Real> IBFaceSet::d_zf

◆ m_area_total

amrex::Real IBFaceSet::m_area_total = 0.0
private

Total face area [m2].

Referenced by print_debug_summary(), and report().

◆ m_bld_area

std::vector<amrex::Real> IBFaceSet::m_bld_area
private

Face area per building [m2].

Referenced by print_debug_summary(), and report().

◆ m_bld_ihi

std::vector<int> IBFaceSet::m_bld_ihi
private

Referenced by print_debug_summary().

◆ m_bld_ilo

std::vector<int> IBFaceSet::m_bld_ilo
private

Referenced by print_debug_summary().

◆ m_bld_jhi

std::vector<int> IBFaceSet::m_bld_jhi
private

Referenced by print_debug_summary().

◆ m_bld_jlo

std::vector<int> IBFaceSet::m_bld_jlo
private

Referenced by print_debug_summary().

◆ m_bld_ncol

std::vector<amrex::Long> IBFaceSet::m_bld_ncol
private

Referenced by print_debug_summary().

◆ m_bld_nface

std::vector<amrex::Long> IBFaceSet::m_bld_nface
private

Faces per building.

Referenced by print_debug_summary(), and report().

◆ m_col_top_max

amrex::Real IBFaceSet::m_col_top_max = 0.0
private

Tallest column the ray map holds [m] (the levels below included after add_outside_occluders())

◆ m_col_valid

amrex::iMultiFab IBFaceSet::m_col_valid

Referenced by print_debug_summary().

◆ m_cost_n

amrex::Long IBFaceSet::m_cost_n = 0
private

Number of per-step updates timed.

Referenced by add_cost(), and report().

◆ m_cost_s

double IBFaceSet::m_cost_s = 0.0
private

Wall-clock seconds spent in the per-step update on this rank.

Referenced by add_cost(), and report().

◆ m_dom_lo

amrex::IntVect IBFaceSet::m_dom_lo {AMREX_D_DECL(0, 0, 0)}
private

Low corner of the level's domain.

Referenced by compute_shortwave_two_stream(), read_state(), and write_state().

◆ m_dx

amrex::Real IBFaceSet::m_dx[3] = {0.0, 0.0, 0.0}
private

Cell sizes [m].

Referenced by compute_ground_walls().

◆ m_fab_start

◆ m_geom

amrex::Geometry IBFaceSet::m_geom
private

Geometry of the level.

Referenced by compute_ground_walls(), and map_buildings_to_level0().

◆ m_gnd_patch

amrex::MultiFab IBFaceSet::m_gnd_patch

compute_ground_walls(): per rank, the box of the columns its faces' landings reach (k = 0), GW_NCOMP components

Referenced by compute_ground_walls().

◆ m_gnd_patch_built

bool IBFaceSet::m_gnd_patch_built = false

m_gnd_patch has been sized since the ray map was built

Referenced by compute_ground_walls().

◆ m_halo

amrex::IntVect IBFaceSet::m_halo {AMREX_D_DECL(0, 0, 0)}

Halo of the patch in cells.

Referenced by ray_halo().

◆ m_init_cost_s

double IBFaceSet::m_init_cost_s = 0.0
private

Wall-clock seconds of build() and compute_view_fractions()

Referenced by report(), and set_init_cost().

◆ m_lab

amrex::iMultiFab IBFaceSet::m_lab
private

◆ m_landings_built

bool IBFaceSet::m_landings_built = false

◆ m_lev

int IBFaceSet::m_lev = 0
private

◆ m_map_spans_domain

bool IBFaceSet::m_map_spans_domain = false

Every rank's patch spans the domain.

Referenced by ray_map_spans_domain().

◆ m_max_steps

int IBFaceSet::m_max_steps = 0

Columns a walk is followed for: the halo's reach in x plus y, before the domain cap.

◆ m_nbld

int IBFaceSet::m_nbld = 0
private

Buildings of the level (global)

Referenced by map_buildings_to_level0(), n_buildings(), print_debug_summary(), and report().

◆ m_nface

◆ m_nface_dir

amrex::Long IBFaceSet::m_nface_dir[3] = {0, 0, 0}
private

Faces per direction.

Referenced by compute_shortwave_two_stream(), print_debug_summary(), read_state(), and report().

◆ m_nx

int IBFaceSet::m_nx = 0
private

Referenced by read_state(), and write_state().

◆ m_ny

int IBFaceSet::m_ny = 0
private

Referenced by read_state(), and write_state().

◆ m_nz

int IBFaceSet::m_nz = 0
private

Cells of the domain in x, y and z.

Referenced by read_state(), and write_state().

◆ m_params

◆ m_patch_box

amrex::Box IBFaceSet::m_patch_box

This rank's patch (empty without boxes)

Referenced by compute_ground_walls(), and print_debug_summary().

◆ m_per_x

bool IBFaceSet::m_per_x = false
private

◆ m_per_y

bool IBFaceSet::m_per_y = false
private

Periodicity in x and y.

◆ m_qv_comp

int IBFaceSet::m_qv_comp = -1
private

State component of rho qv, -1 without a moisture model.

Referenced by add_heat_flux_to_source().

◆ m_ray_patch

amrex::iMultiFab IBFaceSet::m_ray_patch

◆ m_reach

int IBFaceSet::m_reach[2] = {0, 0}

The halo's reach in x and in y before the domain cap [columns].

◆ m_roof_fab_start

std::vector<int> IBFaceSet::m_roof_fab_start

fill_roofs(): fab n owns the entries [m_roof_fab_start[n], m_roof_fab_start[n+1]) of d_roof_face

Referenced by fill_roofs().

◆ m_roof_faces_built

bool IBFaceSet::m_roof_faces_built = false

d_roof_face has been built since build()

Referenced by fill_roofs().

◆ m_sun

◆ m_to_lev0

std::vector<int> IBFaceSet::m_to_lev0
private

◆ m_top_sample

int IBFaceSet::m_top_sample = -1
private

Highest interface a face samples, over all ranks (-1: no faces)

Referenced by has_faces(), and top_sample_interface().

◆ m_ts_sun

TwoStreamSun IBFaceSet::m_ts_sun
private

◆ m_wrap_x

bool IBFaceSet::m_wrap_x = false

◆ m_wrap_y

bool IBFaceSet::m_wrap_y = false

The patch spans the periodic domain in x / y.

◆ m_x_lo

amrex::Real IBFaceSet::m_x_lo = 0.0
private

◆ m_y_lo

amrex::Real IBFaceSet::m_y_lo = 0.0
private

Domain origin [m].

◆ m_z_ground

amrex::Real IBFaceSet::m_z_ground = 0.0
private

Ground height [m] (flat, the domain bottom)

Referenced by compute_ground_shadow().


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