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

Interface between ERF and land-surface and urban models. More...

#include <ERF_SurfaceModel.H>

Collaboration diagram for SurfaceModel:

Classes

struct  Field
 Describes a registered land/urban field mapping. More...
 
struct  InterpTransfer
 
struct  RadiationField
 

Public Member Functions

 SurfaceModel (int nlevs, const amrex::Vector< amrex::BoxArray > &ba, const amrex::Vector< amrex::Geometry > &geom, const amrex::Vector< amrex::DistributionMapping > &dm, const SolverChoice &, amrex::Vector< amrex::Vector< std::unique_ptr< amrex::iMultiFab >>> &)
 Constructs a surface-model interface for the supplied AMR levels. More...
 
void initialize_for_level (int lev, const amrex::BoxArray &ba, const amrex::Geometry &geom, const amrex::DistributionMapping &dm, const amrex::Vector< std::unique_ptr< amrex::iMultiFab >> &lmask_lev, const amrex::Vector< amrex::BCRec > &domain_bcs_type, const amrex::Vector< amrex::IntVect > &refRatio)
 Initializes storage and boundary data for an AMR level. More...
 
void clear_level (int lev)
 Removes an AMR level, and every level above it, from the surface model. More...
 
void set_model_data (const int lev, const amrex::Vector< amrex::MultiFab * > model_data, const amrex::Vector< std::string > &data_names, SurfaceModelType type)
 Registers model variables used in weighted averaging. More...
 
void set_model_fluxes (const int lev, const amrex::Vector< amrex::MultiFab * > model_fluxes, const amrex::Vector< std::string > &flux_names, SurfaceModelType type)
 Registers model fluxes as additional weighted-average inputs. More...
 
void set_model_fields (SurfaceModelType type, const amrex::Vector< int > &field_indices, const bool use_fluxes=true)
 Selects the model fields that participate in weighted averaging. More...
 
void apply_weight_average (int lev, const amrex::MultiFab *lsm_data, amrex::MultiFab *lsm_weighted, const amrex::MultiFab *urban_data, amrex::MultiFab *urban_weighted)
 Applies land and urban weights into separate output fields. More...
 
void calculate_weight_average (int lev, amrex::MultiFab *const urban_frac, bool update_derived=true)
 Computes land and urban weights and applies them to registered fields. More...
 
bool are_fluxes ()
 Returns whether the interface exports fluxes rather than MOST variables. More...
 
void request_surface_outputs (const bool persistent=true)
 Enables and materializes the surface outputs consumed by ERF. More...
 
void request_surface_layer_outputs ()
 Enables blended surface outputs needed by the SurfaceLayer. More...
 
void mark_fields_valid ()
 Marks the registered surface fields as filled by an actual model advance. More...
 
bool fields_are_valid () const
 Returns whether the surface models have advanced at least once. More...
 
amrex::MultiFab * get_ustar (const int &lev)
 Returns the weighted horizontal momentum output for a level. More...
 
amrex::MultiFab * get_tstar (const int &lev)
 Returns the weighted thermal output for a level. More...
 
amrex::MultiFab * get_qstar (const int &lev)
 Returns the weighted moisture output for a level. More...
 
amrex::MultiFab * get_tsurf (const int &lev)
 Returns the weighted surface-temperature output for a level. More...
 
SurfaceFluxView get_surface_flux_view (const int lev, const amrex::MFIter &mfi) const
 Returns provider or blended surface-flux views for one tile. More...
 
const amrex::MultiFab * get_weighted_model_data (const int lev, SurfaceModelType type, const int field_idx) const
 Returns weighted data for a selected model field. More...
 
amrex::MultiFab * get_wavg_factors (const int &lev)
 Returns the land and urban weighting factors for a level. More...
 
void activate_all_field_maps (const bool persistent=true)
 Activates all registered mapped fields for an output consumer. More...
 
void write_output (const int &finest_lev, const amrex::Real &time, const std::string &plot_prefix, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &ref_ratio)
 Writes registered surface-model fields to plotfile output. More...
 
void register_field_map (std::string name, const std::pair< int, int > &lsm_urb_map, bool fill_boundary=false)
 Registers a field map using land and urban field indices. More...
 
void register_field_map (std::string name, amrex::Vector< amrex::MultiFab * > &lsm_lev_mf, amrex::Vector< amrex::MultiFab * > &urb_lev_mf, bool fill_boundary=false)
 Registers a field map using per-level land and urban pointers. More...
 
void set_field_map_pointers (const std::string &name, int lev, amrex::MultiFab *lsm_mf, amrex::MultiFab *urban_mf)
 Updates a pointer-based field mapping for one level. More...
 
void register_radiation_input (const std::string &name, const std::pair< int, int > &lsm_urb_map)
 Registers a canonical radiation input mapping. More...
 
void register_radiation_inputs (const std::unordered_map< std::string, std::pair< int, int >> &input_map)
 Registers canonical radiation input mappings. More...
 
void register_radiation_output (const std::string &name, const std::pair< int, int > &lsm_urb_map)
 Registers a canonical radiation output mapping. More...
 
void register_radiation_outputs (const std::unordered_map< std::string, std::pair< int, int >> &output_map)
 Registers canonical radiation output mappings. More...
 
amrex::MultiFab * get_field (const std::string &name, int lev=0)
 Retrieves a registered field by its common name. More...
 
const amrex::Vector< const amrex::MultiFab * > get_radiation_fields (int lev=0)
 Returns fields registered under the RRTMGP radiation names. More...
 
const amrex::Vector< amrex::MultiFab * > get_radiation_output_fields (int lev=0)
 Returns canonical radiation output destinations for one level. More...
 
amrex::MultiFab * get_radiation_output_field (int lev, const std::string &name)
 Returns the destination of one canonical radiation output by name. More...
 
void distribute_radiation_outputs (int lev)
 Distributes updated canonical radiation outputs to other providers. More...
 
void distribute_radiation_output (int lev, int output_index)
 Distributes one updated canonical radiation output to other providers. More...
 
void WriteCheckpoint (const std::string &checkpointname)
 Writes surface-model state to a checkpoint file. More...
 
void ReadCheckpoint (const std::string &checkpointname)
 Restores surface-model state from a checkpoint file. More...
 
void validate_radiation_output_layout (int lev, const amrex::MultiFab *mf) const
 Validates the layout contract for a canonical radiation output. More...
 
void calculate_simple_average (int lev, amrex::MultiFab *const urban_frac)
 Computes simple land and urban weights from the urban fraction. More...
 
void build_radiation_fieldlist (int lev)
 Builds the ordered radiation-field list for one AMR level. More...
 
void weight_average_fields (int lev, amrex::MultiFab *const)
 Applies the current land and urban weights to selected model fields. More...
 
void activate_field_map (const std::string &name, const bool persistent=true)
 Activates a mapped field and allocates its storage on all levels. More...
 
void deactivate_transient_field_maps ()
 Disables and releases mapped fields used only by the last output. More...
 
bool is_field_mapped (int lev, SurfaceModelType type, int field_idx, const amrex::MultiFab *mf) const
 Checks whether a model field participates in a registered mapping. More...
 
void weight_model_field (int lev, const amrex::MultiFab *source, amrex::MultiFab *weighted, SurfaceModelType type)
 Writes a weighted copy of a model field. More...
 
void interp_surface_fields_from_coarse (const int lev, const amrex::Vector< InterpTransfer > &transfers, const amrex::BCRec &bc, const amrex::IntVect &ratio)
 Fills fine-level surface fields from the next coarser level with interp_by_type. More...
 

Static Public Member Functions

static void GotoNextLine (std::istream &is)
 Advances an input stream to the next line. More...
 

Private Member Functions

void resize_levels (int nlevs)
 Sets the number of AMR levels and resizes all per-level storage to match. More...
 
void update_provider_mode (const int lev)
 Updates the provider mode after model data are registered. More...
 
void ensure_weight_factors (const int lev)
 Creates weighting factors when an external caller requests them. More...
 
void ensure_surface_outputs (const int lev)
 Allocates surface-output fields for one level. More...
 
void release_transient_surface_outputs ()
 Releases surface outputs that have no persistent consumer. More...
 

Private Attributes

int m_nlevs
 
bool m_use_urban = false
 
bool m_use_land = false
 
bool m_export_fluxes = true
 
bool m_export_fluxes_set = false
 
amrex::GpuArray< bool, 2 > m_output_fields_registered {{false, false}}
 
bool m_fields_are_valid = false
 
bool m_weights_updated = false
 
amrex::Vector< SurfaceProviderMode > m_provider_mode
 
amrex::Vector< amrex::BoxArray > m_ba
 
amrex::Vector< amrex::BoxArray > m_ba2d
 
amrex::Vector< amrex::Geometry > m_geom
 
amrex::Vector< amrex::DistributionMapping > m_dmap
 
amrex::Vector< amrex::Geometry > m_geom2d
 
amrex::Vector< amrex::iMultiFab * > m_lmask
 
amrex::Vector< amrex::MultiFab * > urban_frac_lev
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > lsm_data_lev
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > urban_data_lev
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > weighted_lsm_data_lev
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > weighted_urban_data_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_star
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
 
amrex::Vector< int > m_surface_outputs_requested
 
bool m_surface_outputs_enabled = false
 
bool m_surface_layer_outputs_enabled = false
 
amrex::Vector< amrex::MultiFab * > m_last_urban_frac
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > wavg
 
amrex::Vector< int > lsm_fields
 
amrex::Vector< int > urban_fields
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > fields
 
std::unordered_map< std::string, Field > fieldmap
 
amrex::Vector< std::string > m_lsm_names
 
amrex::Vector< std::string > m_urban_names
 
amrex::Vector< amrex::Vector< const amrex::MultiFab * > > rad_fields
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > rad_output_fields
 
std::unordered_map< std::string, RadiationField > radiation_input_map
 
std::unordered_map< std::string, RadiationField > radiation_output_map
 

Static Private Attributes

static const std::vector< std::string > radnames = {"tskin", "emiss", "albedo_vis", "albedo_nir", "albedo_vis_diff", "albedo_nir_diff"}
 
static const std::vector< std::string > rad_output_names
 
static const std::vector< std::string > field_names
 

Detailed Description

Interface between ERF and land-surface and urban models.

SurfaceModel collects data and fluxes from the LSM and urban models, performs the land-urban weight averaging and exposes the resulting fields for use by ERF boundary-condition and physics components.

Models may register data and mappings independently, without requiring a fixed ordering or one-to-one correspondence between their fields.

Model-specific field names can also be registered under a common name for consumers such as RRTMGP and MOST.

This class supports its own checkpoint state, ensuring the mappings are restored correctly on restart. This class also provides a surface plotfile for weight-averaged model data for the fields registered.

Constructor & Destructor Documentation

◆ SurfaceModel()

SurfaceModel::SurfaceModel ( int  nlevs,
const amrex::Vector< amrex::BoxArray > &  ba,
const amrex::Vector< amrex::Geometry > &  geom,
const amrex::Vector< amrex::DistributionMapping > &  dm,
const SolverChoice &  ,
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::iMultiFab >>> &   
)
inlineexplicit

Constructs a surface-model interface for the supplied AMR levels.

Parameters
nlevsNumber of AMR levels initially available.
baCell-centered box arrays for each level.
geomGeometry for each level.
dmDistribution mappings for each level.
solverChoiceERF solver configuration.
lmask_levLand-mask data for each level.
79  : m_nlevs(nlevs), m_ba(ba), m_geom(geom), m_dmap(dm) {
80 
82  m_output_fields_registered = {false, false};
83 
84  // set initial fields for each model to none
85  lsm_fields = amrex::Vector<int>(5, -1);
86  urban_fields = amrex::Vector<int>(5, -1);
87  }
void resize_levels(int nlevs)
Sets the number of AMR levels and resizes all per-level storage to match.
Definition: ERF_SurfaceModel.H:942
int m_nlevs
Definition: ERF_SurfaceModel.H:1061
amrex::Vector< amrex::Geometry > m_geom
Definition: ERF_SurfaceModel.H:1081
amrex::Vector< amrex::BoxArray > m_ba
Definition: ERF_SurfaceModel.H:1079
amrex::Vector< int > lsm_fields
Definition: ERF_SurfaceModel.H:1112
amrex::GpuArray< bool, 2 > m_output_fields_registered
Definition: ERF_SurfaceModel.H:1068
amrex::Vector< int > urban_fields
Definition: ERF_SurfaceModel.H:1113
amrex::Vector< amrex::DistributionMapping > m_dmap
Definition: ERF_SurfaceModel.H:1082
Here is the call graph for this function:

Member Function Documentation

◆ activate_all_field_maps()

void SurfaceModel::activate_all_field_maps ( const bool  persistent = true)

Activates all registered mapped fields for an output consumer.

670 {
671  for (const auto& entry : fieldmap) {
672  activate_field_map(entry.first, persistent);
673  }
674 }
void activate_field_map(const std::string &name, const bool persistent=true)
Activates a mapped field and allocates its storage on all levels.
Definition: ERF_SurfaceModel.cpp:647
std::unordered_map< std::string, Field > fieldmap
Definition: ERF_SurfaceModel.H:1143

◆ activate_field_map()

void SurfaceModel::activate_field_map ( const std::string &  name,
const bool  persistent = true 
)

Activates a mapped field and allocates its storage on all levels.

Parameters
nameCommon mapped field name.
648 {
649  auto field_it = fieldmap.find(name);
650  if (field_it == fieldmap.end()) { return; }
651 
652  Field& field = field_it->second;
653  field.active = true;
654  field.persistent_consumer = field.persistent_consumer || persistent;
655  if (field.mf_ind == -1) {
656  field.mf_ind = static_cast<int>(fields.size());
657  fields.emplace_back(m_nlevs);
658  }
659 
660  for (int lev = 0; lev < m_nlevs; ++lev) {
661  if (fields[field.mf_ind][lev] == nullptr) {
662  fields[field.mf_ind][lev] = std::make_unique<amrex::MultiFab>(
663  m_ba2d[lev], m_dmap[lev], 1, IntVect(1,1,0));
664  fields[field.mf_ind][lev]->setVal(0.0);
665  }
666  }
667 }
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
amrex::Vector< amrex::BoxArray > m_ba2d
Definition: ERF_SurfaceModel.H:1080
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > fields
Definition: ERF_SurfaceModel.H:1142

Referenced by get_field(), and initialize_for_level().

Here is the caller graph for this function:

◆ apply_weight_average()

void SurfaceModel::apply_weight_average ( int  lev,
const amrex::MultiFab *  lsm_data,
amrex::MultiFab *  lsm_weighted,
const amrex::MultiFab *  urban_data,
amrex::MultiFab *  urban_weighted 
)

Applies land and urban weights into separate output fields.

A null land or urban source is skipped, but both sources cannot be null. The source fields are not modified and the fields may use different underlying grids.

Parameters
levAMR level whose weights are used.
lsm_dataLand-model source data to weight.
lsm_weightedDestination for weighted land data.
urban_dataUrban-model source data to weight.
urban_weightedDestination for weighted urban data.
16 {
17  bool valid_land = (lsm_data != nullptr);
18  bool valid_urban = (urban_data != nullptr);
19 
20  AMREX_ASSERT_WITH_MESSAGE(valid_land || valid_urban, "Need at least one pointer to apply weights");
21  AMREX_ASSERT_WITH_MESSAGE(!valid_land || lsm_weighted != nullptr,
22  "Need a destination for weighted land data");
23  AMREX_ASSERT_WITH_MESSAGE(!valid_urban || urban_weighted != nullptr,
24  "Need a destination for weighted urban data");
25  AMREX_ASSERT_WITH_MESSAGE(lsm_data == nullptr || lsm_data != lsm_weighted,
26  "Weighted land data must use separate storage");
27  AMREX_ASSERT_WITH_MESSAGE(urban_data == nullptr || urban_data != urban_weighted,
28  "Weighted urban data must use separate storage");
29 
30  // make sure the weights have been calculated before applying them
32 
33  // Apply weights separately to support different underlying grids between lsm_data and urban_data
34  if (valid_land) {
35  weight_model_field(lev, lsm_data, lsm_weighted, SurfaceModelType::LAND);
36  }
37 
38  if (valid_urban) {
39  weight_model_field(lev, urban_data, urban_weighted, SurfaceModelType::URBAN);
40  }
41 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
@ LAND
Definition: ERF_SurfaceModel.H:17
@ URBAN
Definition: ERF_SurfaceModel.H:17
AMREX_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
bool m_weights_updated
Definition: ERF_SurfaceModel.H:1075
void weight_model_field(int lev, const amrex::MultiFab *source, amrex::MultiFab *weighted, SurfaceModelType type)
Writes a weighted copy of a model field.
Definition: ERF_SurfaceModel.cpp:43
Here is the call graph for this function:

◆ are_fluxes()

bool SurfaceModel::are_fluxes ( )
inline

Returns whether the interface exports fluxes rather than MOST variables.

Returns
True when weighted outputs are fluxes.
391 { return m_export_fluxes; }
bool m_export_fluxes
Definition: ERF_SurfaceModel.H:1066

◆ build_radiation_fieldlist()

void SurfaceModel::build_radiation_fieldlist ( int  lev)
inline

Builds the ordered radiation-field list for one AMR level.

Parameters
levAMR level to update.
736  {
737  amrex::Print() << " --- building radiation field list" << std::endl;
738 
739  // loop over fields and check against names of radiation variables
740  for (int li = 0; li < static_cast<int>(radnames.size()); ++li) {
741  amrex::Print() << " - Checking for radiation variable '" << radnames[li] << "'" << std::endl;
742 
743  amrex::MultiFab* mf = nullptr;
744  auto rad_it = radiation_input_map.find(radnames[li]);
745  if (rad_it != radiation_input_map.end()) {
746  const int land_idx = rad_it->second.map.first;
747  const int urban_idx = rad_it->second.map.second;
748  const SurfaceProviderMode mode = m_provider_mode[lev];
749  const bool use_land = mode == SurfaceProviderMode::LandOnly ||
751  const bool use_urban = mode == SurfaceProviderMode::UrbanOnly ||
753  const bool valid_land = use_land && land_idx >= 0 &&
754  lev < static_cast<int>(lsm_data_lev.size()) &&
755  land_idx < static_cast<int>(lsm_data_lev[lev].size()) &&
756  lsm_data_lev[lev][land_idx] != nullptr;
757  const bool valid_urban = use_urban && urban_idx >= 0 &&
758  lev < static_cast<int>(urban_data_lev.size()) &&
759  urban_idx < static_cast<int>(urban_data_lev[lev].size()) &&
760  urban_data_lev[lev][urban_idx] != nullptr;
761  if (valid_land && valid_urban) {
762  if (!rad_it->second.weighted[lev]) {
763  rad_it->second.weighted[lev] = std::make_unique<amrex::MultiFab>(
764  m_ba2d[lev], m_dmap[lev], 1, amrex::IntVect(1,1,0));
765  }
766  auto& weighted = *rad_it->second.weighted[lev];
767  const auto& land = *lsm_data_lev[lev][land_idx];
768  const auto& urban = *urban_data_lev[lev][urban_idx];
769  for (amrex::MFIter mfi(weighted); mfi.isValid(); ++mfi) {
770  const amrex::Box bx = mfi.tilebox();
771  const auto weights = wavg[lev]->const_array(mfi);
772  const auto land_arr = land.const_array(mfi);
773  const auto urban_arr = urban.const_array(mfi);
774  // LSM surface fields may be stored at k <= 0; use the top valid LSM
775  // plane, which matches k=0 when the LSM keeps those fields synchronized
776  // at the surface (such as SLM). Urban surface fields are stored at k=0.
777  const int land_k = land.box(mfi.index()).bigEnd(2);
778  const int urban_k = urban.box(mfi.index()).smallEnd(2);
779  auto output = weighted.array(mfi);
780  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
781  output(i,j,k) = land_arr(i,j,land_k) *
782  weights(i,j,0,SurfaceModelType::LAND) +
783  urban_arr(i,j,urban_k) *
784  weights(i,j,0,SurfaceModelType::URBAN);
785  });
786  }
787  weighted.FillBoundary(m_geom[lev].periodicity());
788  mf = rad_it->second.weighted[lev].get();
789  } else if (valid_land) {
790  mf = lsm_data_lev[lev][land_idx];
791  } else if (valid_urban) {
792  mf = urban_data_lev[lev][urban_idx];
793  }
794  }
795  if (mf) {
796  rad_fields[lev].push_back(mf);
797  } else {
798  amrex::Print() << " - WARNING: did not find radiation variable, setting to null to use default RRTMGP value!" << std::endl;
799  rad_fields[lev].push_back(nullptr);
800  }
801  }
803  static_cast<int>(rad_fields[lev].size()) == static_cast<int>(radnames.size()),
804  "Did not find all radiation fields");
805  }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
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);})
SurfaceProviderMode
Definition: ERF_SurfaceModel.H:19
std::unordered_map< std::string, RadiationField > radiation_input_map
Definition: ERF_SurfaceModel.H:1160
amrex::Vector< SurfaceProviderMode > m_provider_mode
Definition: ERF_SurfaceModel.H:1077
static const std::vector< std::string > radnames
Definition: ERF_SurfaceModel.H:1116
amrex::Vector< amrex::Vector< amrex::MultiFab * > > lsm_data_lev
Definition: ERF_SurfaceModel.H:1089
amrex::Vector< amrex::Vector< const amrex::MultiFab * > > rad_fields
Definition: ERF_SurfaceModel.H:1148
amrex::Vector< std::unique_ptr< amrex::MultiFab > > wavg
Definition: ERF_SurfaceModel.H:1107
amrex::Vector< amrex::Vector< amrex::MultiFab * > > urban_data_lev
Definition: ERF_SurfaceModel.H:1090

Referenced by get_radiation_fields().

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

◆ calculate_simple_average()

void SurfaceModel::calculate_simple_average ( int  lev,
amrex::MultiFab *const  urban_frac 
)

Computes simple land and urban weights from the urban fraction.

Parameters
levAMR level to update.
urban_fracUrban fraction used to compute the weights.
538 {
539  const SurfaceProviderMode mode = m_provider_mode[lev];
540 
541  // If no urban fraction is available, use the only enabled model as the
542  // complete surface. A missing fraction is ambiguous when both models
543  // are enabled, so fail explicitly rather than silently choosing a model.
544  if (urban_frac == nullptr) {
547  "Urban fraction is required when both land and urban models are enabled");
548  }
549 
550  if (mode != SurfaceProviderMode::Both) {
551  m_weights_updated = true;
552  return;
553  }
554 
555  for (MFIter mfi(*wavg[lev], TileNoZ()); mfi.isValid(); ++mfi)
556  {
557  Box tbx = mfi.tilebox();
558  // weights are defined only on k = 0
559  tbx = tbx.makeSlab(2, 0);
560 
561  auto urban_frac_arr = (urban_frac != nullptr) ? urban_frac->const_array(mfi) : Array4<const Real>{};
562  auto weights_arr = wavg[lev]->array(mfi);
563 
564  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/)
565  {
566  // Weights are proportional to urban fraction coverage in the current cell.
567  weights_arr(i, j, 0, SurfaceModelType::URBAN) = urban_frac_arr(i, j, 0);
568  weights_arr(i, j, 0, SurfaceModelType::LAND) = 1.0 - urban_frac_arr(i, j, 0);
569  });
570  }
571 
572  m_weights_updated = true;
573 }
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
Here is the call graph for this function:

◆ calculate_weight_average()

void SurfaceModel::calculate_weight_average ( int  lev,
amrex::MultiFab *const  urban_frac,
bool  update_derived = true 
)

Computes land and urban weights and applies them to registered fields.

Parameters
levAMR level to update.
urban_fracUrban fraction used to compute the weights.
73 {
74  m_last_urban_frac[lev] = urban_frac;
75  const SurfaceProviderMode mode = m_provider_mode[lev];
76  // An urban model can be enabled on only a subset of AMR levels. Those
77  // inactive levels have no surface-provider data to update.
78  if (mode == SurfaceProviderMode::None) {
79  return;
80  }
81 
82  // Calculate weighted averages between Land and Urban. Output consumers
83  // can reuse the weights computed during the timestep update.
84  if (update_derived || !m_weights_updated) {
85  calculate_simple_average(lev, urban_frac);
86  }
87 
88  const bool use_urban = mode == SurfaceProviderMode::UrbanOnly ||
90  const bool use_land = mode == SurfaceProviderMode::LandOnly ||
92  const bool use_weights = mode == SurfaceProviderMode::Both;
93  const bool use_fluxes = m_export_fluxes;
94  const bool output_fields_registered =
97 
98  amrex::MultiFab* const outputs[] = {u_star[lev].get(), t_star[lev].get(), q_star[lev].get(), t_surf[lev].get()};
99 
100  const int nfields = (m_export_fluxes) ? 5 : 4;
101 
102  if (m_surface_outputs_requested[lev] && output_fields_registered && !use_weights) {
103  const auto& provider_fields = use_land ? lsm_fields : urban_fields;
104  const auto& provider_data = use_land ? lsm_data_lev[lev] : urban_data_lev[lev];
105  auto source_for = [&] (const int field) -> const amrex::MultiFab* {
106  if (field >= static_cast<int>(provider_fields.size()) ||
107  provider_fields[field] < 0 ||
108  provider_fields[field] >= static_cast<int>(provider_data.size())) {
109  return nullptr;
110  }
111  return provider_data[provider_fields[field]];
112  };
113 
114  const amrex::MultiFab* source0 = source_for(0);
115  const amrex::MultiFab* source1 = source_for(1);
116  const amrex::MultiFab* source2 = source_for(2);
117  const amrex::MultiFab* source3 = source_for(3);
118  const amrex::MultiFab* source4 = source_for(4);
119 
120  for (MFIter mfi(*u_star[lev], TileNoZ()); mfi.isValid(); ++mfi)
121  {
122  const Box tbx = mfi.tilebox();
123  const auto source0_arr = source0 ? source0->const_array(mfi) : Array4<const Real>{};
124  const auto source1_arr = source1 ? source1->const_array(mfi) : Array4<const Real>{};
125  const auto source2_arr = source2 ? source2->const_array(mfi) : Array4<const Real>{};
126  const auto source3_arr = source3 ? source3->const_array(mfi) : Array4<const Real>{};
127  const auto source4_arr = source4 ? source4->const_array(mfi) : Array4<const Real>{};
128  const int source0_k = source0 ? (use_land ? source0->box(mfi.index()).bigEnd(2)
129  : source0->box(mfi.index()).smallEnd(2)) : 0;
130  const int source1_k = source1 ? (use_land ? source1->box(mfi.index()).bigEnd(2)
131  : source1->box(mfi.index()).smallEnd(2)) : 0;
132  const int source2_k = source2 ? (use_land ? source2->box(mfi.index()).bigEnd(2)
133  : source2->box(mfi.index()).smallEnd(2)) : 0;
134  const int source3_k = source3 ? (use_land ? source3->box(mfi.index()).bigEnd(2)
135  : source3->box(mfi.index()).smallEnd(2)) : 0;
136  const int source4_k = source4 ? (use_land ? source4->box(mfi.index()).bigEnd(2)
137  : source4->box(mfi.index()).smallEnd(2)) : 0;
138 
139  auto u_arr = u_star[lev]->array(mfi);
140  auto t_arr = t_star[lev]->array(mfi);
141  auto q_arr = q_star[lev]->array(mfi);
142  auto tsurf_arr = t_surf[lev]->array(mfi);
143  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
144  {
145  if (use_fluxes) {
146  u_arr(i, j, k, 0) = source0_arr ? source0_arr(i, j, source0_k) : lsm_undefined;
147  u_arr(i, j, k, 1) = source1_arr ? source1_arr(i, j, source1_k) : lsm_undefined;
148  t_arr(i, j, k) = source2_arr ? source2_arr(i, j, source2_k) : lsm_undefined;
149  q_arr(i, j, k) = source3_arr ? source3_arr(i, j, source3_k) : lsm_undefined;
150  tsurf_arr(i, j, k) = source4_arr ? source4_arr(i, j, source4_k) : lsm_undefined;
151  } else {
152  u_arr(i, j, k, 0) = source0_arr ? source0_arr(i, j, source0_k) : lsm_undefined;
153  u_arr(i, j, k, 1) = lsm_undefined;
154  t_arr(i, j, k) = source1_arr ? source1_arr(i, j, source1_k) : lsm_undefined;
155  q_arr(i, j, k) = source2_arr ? source2_arr(i, j, source2_k) : lsm_undefined;
156  tsurf_arr(i, j, k) = source3_arr ? source3_arr(i, j, source3_k) : lsm_undefined;
157  }
158  });
159  }
160 
161  u_star[lev]->FillBoundary(m_geom[lev].periodicity());
162  t_star[lev]->FillBoundary(m_geom[lev].periodicity());
163  q_star[lev]->FillBoundary(m_geom[lev].periodicity());
164  t_surf[lev]->FillBoundary(m_geom[lev].periodicity());
165  }
166 
167  // Output weighted surface fluxes into ustar, tstar, qstar and surface temperature into tsurf
168  // TODO: make sure grids of urban and LSM inputs match
169  if (m_surface_outputs_requested[lev] && output_fields_registered && use_weights) {
170  // Component 1 is unused without fluxes; match the single-provider copy
171  if (!use_fluxes) {
172  u_star[lev]->setVal(lsm_undefined, 1, 1, 0);
173  }
174  for (int field = 0; field < nfields; ++field)
175  {
176  int output_field = (use_fluxes && field > 0) ? field - 1 : field;
177  int comp = (use_fluxes && field < 2) ? field : 0;
178 
179  // whether we have a valid LSM multifab
180  bool valid_land = (use_land &&
181  lsm_fields[field] != -1 &&
182  lsm_data_lev[lev][lsm_fields[field]]);
183 
184  // whether we have a valid urban multifab
185  bool valid_urban = (use_urban &&
186  urban_fields[field] != -1 &&
187  urban_data_lev[lev][urban_fields[field]]);
188 
189  for (MFIter mfi(*u_star[lev], TileNoZ()); mfi.isValid(); ++mfi)
190  {
191  Box tbx = mfi.tilebox();
192 
193  const auto weights_arr = use_weights
194  ? wavg[lev]->const_array(mfi) : Array4<const Real>{};
195 
196  // Outputs for surface boundary condition
197  auto output_arr = outputs[output_field]->array(mfi);
198  const amrex::MultiFab* lsm_mf = valid_land ? lsm_data_lev[lev][lsm_fields[field]] : nullptr;
199  const amrex::MultiFab* urban_mf = valid_urban ? urban_data_lev[lev][urban_fields[field]] : nullptr;
200  const int lsm_khi = valid_land ? lsm_mf->box(mfi.index()).bigEnd(2) : 0;
201  const int urban_klo = valid_urban ? urban_mf->box(mfi.index()).smallEnd(2) : 0;
202  auto lsm_data_arr = valid_land ? lsm_mf->const_array(mfi) : Array4<const Real>{};
203  auto urban_data_arr = valid_urban ? urban_mf->const_array(mfi) : Array4<const Real>{};
204 
205  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
206  {
207  if (valid_land && use_land && !use_urban) {
208  output_arr(i, j, k, comp) = lsm_data_arr(i, j, lsm_khi);
209  } else if (valid_urban && use_urban && !use_land) {
210  output_arr(i, j, k, comp) = urban_data_arr(i, j, urban_klo);
211  } else {
212  // A provider weighted in this cell must hold a valid value: blending its
213  // lsm_undefined sentinel gives a value below lsm_undefined, and leaving out
214  // a provider with no field gives a partial value, either of which the
215  // SurfaceLayer would take as a valid flux. Such a cell is left undefined
216  // so the SurfaceLayer falls back to MOST there, as the single-provider
217  // copy does for a missing field.
218  const Real w_land = weights_arr(i, j, 0, SurfaceModelType::LAND );
219  const Real w_urb = weights_arr(i, j, 0, SurfaceModelType::URBAN);
220  const Real land = (w_land > 0.0) ? (lsm_data_arr ? lsm_data_arr(i, j, lsm_khi ) : lsm_undefined) : 0.0;
221  const Real urb = (w_urb > 0.0) ? (urban_data_arr ? urban_data_arr(i, j, urban_klo) : lsm_undefined) : 0.0;
222  output_arr(i, j, k, comp) = (is_valid_lsm_value(land) && is_valid_lsm_value(urb))
223  ? land * w_land + urb * w_urb : lsm_undefined;
224  }
225 
226  });
227  }
228 
229  outputs[output_field]->FillBoundary(comp, 1, m_geom[lev].periodicity());
230  } // field
231  } // weighted
232 
233  // Write weighted copies only when both providers contribute. With one
234  // provider, get_weighted_model_data() returns the provider-owned source.
235  if (update_derived && use_weights && use_land) {
236  for (int field = nfields; field < static_cast<int>(lsm_fields.size()); ++field) {
237  if (lsm_fields[field] == -1) continue;
239  lsm_data_lev[lev][lsm_fields[field]])) continue;
240  const int field_idx = lsm_fields[field];
241  if (static_cast<int>(weighted_lsm_data_lev[lev].size()) <= field_idx) {
242  weighted_lsm_data_lev[lev].resize(lsm_data_lev[lev].size());
243  }
244  if (weighted_lsm_data_lev[lev][field_idx] == nullptr) {
245  const auto* source = lsm_data_lev[lev][field_idx];
246  weighted_lsm_data_lev[lev][field_idx] = std::make_unique<MultiFab>(
247  source->boxArray(), source->DistributionMap(), source->nComp(),
248  source->nGrowVect());
249  }
250  weight_model_field(lev, lsm_data_lev[lev][field_idx],
251  weighted_lsm_data_lev[lev][field_idx].get(),
253  }
254  }
255 
256  if (update_derived && use_weights && use_urban) {
257  for (int field = nfields; field < static_cast<int>(urban_fields.size()); ++field) {
258  if (urban_fields[field] == -1) continue;
260  urban_data_lev[lev][urban_fields[field]])) continue;
261  const int field_idx = urban_fields[field];
262  if (static_cast<int>(weighted_urban_data_lev[lev].size()) <= field_idx) {
263  weighted_urban_data_lev[lev].resize(urban_data_lev[lev].size());
264  }
265  if (weighted_urban_data_lev[lev][field_idx] == nullptr) {
266  const auto* source = urban_data_lev[lev][field_idx];
267  weighted_urban_data_lev[lev][field_idx] = std::make_unique<MultiFab>(
268  source->boxArray(), source->DistributionMap(), source->nComp(),
269  source->nGrowVect());
270  }
271  weight_model_field(lev, urban_data_lev[lev][field_idx],
272  weighted_urban_data_lev[lev][field_idx].get(),
274  }
275  }
276 
277  weight_average_fields(lev, urban_frac);
278 
279  if (!update_derived) { return; }
280 
281  for (auto& entry : radiation_input_map) {
282  const int land_idx = entry.second.map.first;
283  const int urban_idx = entry.second.map.second;
284  const bool valid_land = use_land && land_idx >= 0 &&
285  land_idx < static_cast<int>(lsm_data_lev[lev].size()) &&
286  lsm_data_lev[lev][land_idx] != nullptr;
287  const bool valid_urban = use_urban && urban_idx >= 0 &&
288  urban_idx < static_cast<int>(urban_data_lev[lev].size()) &&
289  urban_data_lev[lev][urban_idx] != nullptr;
290  if (!(valid_land && valid_urban)) { continue; }
291 
292  if (entry.second.weighted[lev] == nullptr) {
293  entry.second.weighted[lev] = std::make_unique<MultiFab>(
294  m_ba2d[lev], m_dmap[lev], 1, IntVect(1,1,0));
295  }
296  MultiFab& output = *entry.second.weighted[lev];
297  const MultiFab& land = *lsm_data_lev[lev][land_idx];
298  const MultiFab& urban = *urban_data_lev[lev][urban_idx];
299  for (MFIter mfi(output, TileNoZ()); mfi.isValid(); ++mfi) {
300  const Box bx = mfi.tilebox();
301  const auto weights = wavg[lev]->const_array(mfi);
302  const auto land_arr = land.const_array(mfi);
303  const auto urban_arr = urban.const_array(mfi);
304  // LSM surface fields may be stored at k <= 0; use the top valid LSM
305  // plane, which matches k=0 when the LSM keeps those fields synchronized
306  // at the surface (such as SLM). Urban surface fields are stored at k=0.
307  const int land_k = land.box(mfi.index()).bigEnd(2);
308  const int urban_k = urban.box(mfi.index()).smallEnd(2);
309  auto out = output.array(mfi);
310  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
311  out(i,j,k) = land_arr(i,j,land_k) * weights(i,j,0,SurfaceModelType::LAND) +
312  urban_arr(i,j,urban_k) * weights(i,j,0,SurfaceModelType::URBAN);
313  });
314  }
315  output.FillBoundary(m_geom[lev].periodicity());
316  }
317 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool is_valid_lsm_value(amrex::Real v)
Definition: ERF_Constants.H:38
constexpr amrex::Real lsm_undefined
Definition: ERF_Constants.H:28
pp_for_pert_vels get("prob_type", prob_type)
bool is_field_mapped(int lev, SurfaceModelType type, int field_idx, const amrex::MultiFab *mf) const
Checks whether a model field participates in a registered mapping.
Definition: ERF_SurfaceModel.cpp:502
amrex::Vector< amrex::MultiFab * > m_last_urban_frac
Definition: ERF_SurfaceModel.H:1104
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_star
Definition: ERF_SurfaceModel.H:1098
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
Definition: ERF_SurfaceModel.H:1099
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > weighted_urban_data_lev
Definition: ERF_SurfaceModel.H:1092
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > weighted_lsm_data_lev
Definition: ERF_SurfaceModel.H:1091
void calculate_simple_average(int lev, amrex::MultiFab *const urban_frac)
Computes simple land and urban weights from the urban fraction.
Definition: ERF_SurfaceModel.cpp:537
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
Definition: ERF_SurfaceModel.H:1096
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
Definition: ERF_SurfaceModel.H:1097
void weight_average_fields(int lev, amrex::MultiFab *const)
Applies the current land and urban weights to selected model fields.
Definition: ERF_SurfaceModel.cpp:689
amrex::Vector< int > m_surface_outputs_requested
Definition: ERF_SurfaceModel.H:1101
Here is the call graph for this function:

◆ clear_level()

void SurfaceModel::clear_level ( int  lev)
inline

Removes an AMR level, and every level above it, from the surface model.

Called when ERF destroys a level during regridding so that m_nlevs tracks the levels that actually exist. Otherwise the checkpoint and other level loops would still visit the destroyed levels and their stale provider pointers.

Parameters
levAMR level being destroyed.
194  {
195  if (lev < 0 || lev >= m_nlevs) { return; }
196  resize_levels(lev);
197  }
Here is the call graph for this function:

◆ deactivate_transient_field_maps()

void SurfaceModel::deactivate_transient_field_maps ( )

Disables and releases mapped fields used only by the last output.

677 {
678  for (auto& entry : fieldmap) {
679  Field& field = entry.second;
680  if (field.persistent_consumer) { continue; }
681  field.active = false;
682  if (field.mf_ind == -1) { continue; }
683  for (auto& mf : fields[field.mf_ind]) {
684  mf.reset();
685  }
686  }
687 }

◆ distribute_radiation_output()

void SurfaceModel::distribute_radiation_output ( int  lev,
int  output_index 
)

Distributes one updated canonical radiation output to other providers.

Parameters
levAMR level to update.
output_indexIndex in the canonical radiation output list.
457 {
458  AMREX_ALWAYS_ASSERT(output_index >= 0 &&
459  output_index < static_cast<int>(rad_output_names.size()));
460  auto it = radiation_output_map.find(rad_output_names[output_index]);
461  if (it == radiation_output_map.end()) { return; }
462 
463  const int land_idx = it->second.map.first;
464  const int urban_idx = it->second.map.second;
465  const SurfaceProviderMode mode = m_provider_mode[lev];
466  const bool use_land = mode == SurfaceProviderMode::LandOnly ||
468  const bool use_urban = mode == SurfaceProviderMode::UrbanOnly ||
470  MultiFab* lsm = (use_land && land_idx >= 0 && land_idx < static_cast<int>(lsm_data_lev[lev].size()))
471  ? lsm_data_lev[lev][land_idx] : nullptr;
472  MultiFab* urban = (use_urban && urban_idx >= 0 && urban_idx < static_cast<int>(urban_data_lev[lev].size()))
473  ? urban_data_lev[lev][urban_idx] : nullptr;
474 
475  // The LSM destination is always primary when it is available. Urban
476  // receives the updated surface plane only when both destinations exist.
477  if (lsm && urban && lsm != urban) {
478  for (MFIter mfi(*urban, TileNoZ()); mfi.isValid(); ++mfi) {
479  const Box& source_box = (*lsm)[mfi].box();
480  const Box& target_box = (*urban)[mfi].box();
482  source_box.smallEnd(2) <= 0 && source_box.bigEnd(2) >= 0 &&
483  target_box.smallEnd(2) <= 0 && target_box.bigEnd(2) >= 0,
484  "Radiation output destinations must contain the k=0 surface plane");
485  //
486  // These are the *grown* boxes, so the two destinations need not carry the same
487  // ghost vector. Loop over the intersection of the two surface planes rather than
488  // over the target alone: indexing the source at the target's indices would read
489  // out of bounds wherever the urban halo reaches past the LSM one.
490  //
491  const Box copy_slab = makeSlab(source_box, 2, 0) & makeSlab(target_box, 2, 0);
492  if (copy_slab.isEmpty()) { continue; }
493  const auto source = (*lsm)[mfi].array();
494  auto target = (*urban)[mfi].array();
495  amrex::ParallelFor(copy_slab, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
496  target(i, j, k) = source(i, j, k);
497  });
498  }
499  }
500 }
std::unordered_map< std::string, RadiationField > radiation_output_map
Definition: ERF_SurfaceModel.H:1161
static const std::vector< std::string > rad_output_names
Definition: ERF_SurfaceModel.H:1151
Here is the call graph for this function:

◆ distribute_radiation_outputs()

void SurfaceModel::distribute_radiation_outputs ( int  lev)

Distributes updated canonical radiation outputs to other providers.

Parameters
levAMR level to update.
450 {
451  for (int i = 0; i < static_cast<int>(rad_output_names.size()); ++i) {
453  }
454 }
void distribute_radiation_output(int lev, int output_index)
Distributes one updated canonical radiation output to other providers.
Definition: ERF_SurfaceModel.cpp:456

◆ ensure_surface_outputs()

void SurfaceModel::ensure_surface_outputs ( const int  lev)
inlineprivate

Allocates surface-output fields for one level.

Parameters
levAMR level whose outputs should be materialized.
1028  {
1029  if (u_star[lev] != nullptr) { return; }
1030 
1031  const amrex::IntVect ng(1,1,0);
1032  u_star[lev] = std::make_unique<amrex::MultiFab>(m_ba2d[lev], m_dmap[lev], 2, ng);
1033  t_star[lev] = std::make_unique<amrex::MultiFab>(m_ba2d[lev], m_dmap[lev], 1, ng);
1034  q_star[lev] = std::make_unique<amrex::MultiFab>(m_ba2d[lev], m_dmap[lev], 1, ng);
1035  t_surf[lev] = std::make_unique<amrex::MultiFab>(m_ba2d[lev], m_dmap[lev], 1, ng);
1036  u_star[lev]->setVal(lsm_undefined);
1037  t_star[lev]->setVal(lsm_undefined);
1038  q_star[lev]->setVal(lsm_undefined);
1039  t_surf[lev]->setVal(300.0);
1040  }
@ ng
Definition: ERF_Morrison.H:51

Referenced by initialize_for_level(), request_surface_layer_outputs(), request_surface_outputs(), and update_provider_mode().

Here is the caller graph for this function:

◆ ensure_weight_factors()

void SurfaceModel::ensure_weight_factors ( const int  lev)
inlineprivate

Creates weighting factors when an external caller requests them.

Parameters
levAMR level whose weighting factors should be materialized.
1011  {
1012  if (wavg[lev] != nullptr) { return; }
1013 
1014  const amrex::IntVect ng(1,1,0);
1015  wavg[lev] = std::make_unique<amrex::MultiFab>(m_ba2d[lev], m_dmap[lev], 2, ng);
1016  const SurfaceProviderMode mode = m_provider_mode[lev];
1017  wavg[lev]->setVal(mode != SurfaceProviderMode::UrbanOnly ? 1.0 : 0.0,
1018  SurfaceModelType::LAND, 1, 0);
1019  wavg[lev]->setVal(mode == SurfaceProviderMode::UrbanOnly ? 1.0 : 0.0,
1020  SurfaceModelType::URBAN, 1, 0);
1021  }

Referenced by get_wavg_factors(), and update_provider_mode().

Here is the caller graph for this function:

◆ fields_are_valid()

bool SurfaceModel::fields_are_valid ( ) const
inline

Returns whether the surface models have advanced at least once.

Returns
False until the first advance, while the registered fields still hold their initial values rather than anything the models computed.
429 { return m_fields_are_valid; }
bool m_fields_are_valid
Definition: ERF_SurfaceModel.H:1072

◆ get_field()

amrex::MultiFab* SurfaceModel::get_field ( const std::string &  name,
int  lev = 0 
)
inline

Retrieves a registered field by its common name.

Parameters
nameRegistered field name.
levAMR level to query.
Returns
Pointer to the registered field, or nullptr if it is unknown.
642  {
643  if (auto field = fieldmap.find(name); field != fieldmap.end()) {
645  return fields[field->second.mf_ind][lev].get();
646  } else {
647  return nullptr;
648  }
649  }
Here is the call graph for this function:

◆ get_qstar()

amrex::MultiFab* SurfaceModel::get_qstar ( const int &  lev)
inline

Returns the weighted moisture output for a level.

Parameters
levAMR level to query.
Returns
Pointer to the weighted q-star or vapor-flux field.
454  {
455  return q_star[lev].get();
456  }

◆ get_radiation_fields()

const amrex::Vector<const amrex::MultiFab*> SurfaceModel::get_radiation_fields ( int  lev = 0)
inline

Returns fields registered under the RRTMGP radiation names.

The resulting map is cached after the first call for reuse on subsequent timesteps. When an expected field is missing, it is marked nullptr for the RRTMGP implementation to apply its fallback values.

Parameters
levAMR level to query.
Returns
Radiation fields in the order expected by RRTMGP.
661  {
662  // check if we need to build the radiation list (for first time step,)
663  if (rad_fields[lev].size() == 0) {
665  }
666  return rad_fields[lev];
667  }
void build_radiation_fieldlist(int lev)
Builds the ordered radiation-field list for one AMR level.
Definition: ERF_SurfaceModel.H:736
Here is the call graph for this function:

◆ get_radiation_output_field()

MultiFab * SurfaceModel::get_radiation_output_field ( int  lev,
const std::string &  name 
)

Returns the destination of one canonical radiation output by name.

Parameters
levAMR level to query.
nameCanonical radiation output name (aborts on an unknown name).
Returns
The registered destination, or nullptr when none is registered.
422 {
423  const auto it = std::find(rad_output_names.begin(), rad_output_names.end(), name);
425  "Unknown canonical radiation output: " + name);
426  return get_radiation_output_fields(lev)[static_cast<int>(it - rad_output_names.begin())];
427 }
const amrex::Vector< amrex::MultiFab * > get_radiation_output_fields(int lev=0)
Returns canonical radiation output destinations for one level.
Definition: ERF_SurfaceModel.cpp:388
Here is the call graph for this function:

◆ get_radiation_output_fields()

const Vector< MultiFab * > SurfaceModel::get_radiation_output_fields ( int  lev = 0)

Returns canonical radiation output destinations for one level.

Parameters
levAMR level to query.
Returns
One destination per canonical radiation output.
389 {
390  if (!rad_output_fields[lev].empty()) { return rad_output_fields[lev]; }
391  rad_output_fields[lev].resize(rad_output_names.size(), nullptr);
392  const SurfaceProviderMode mode = m_provider_mode[lev];
393  const bool use_land = mode == SurfaceProviderMode::LandOnly ||
395  const bool use_urban = mode == SurfaceProviderMode::UrbanOnly ||
397  for (int i = 0; i < static_cast<int>(rad_output_names.size()); ++i) {
398  auto it = radiation_output_map.find(rad_output_names[i]);
399  if (it == radiation_output_map.end()) { continue; }
400  const int land_idx = it->second.map.first;
401  const int urban_idx = it->second.map.second;
402  const bool valid_land = use_land && land_idx >= 0 &&
403  land_idx < static_cast<int>(lsm_data_lev[lev].size()) &&
404  lsm_data_lev[lev][land_idx];
405  const bool valid_urban = use_urban && urban_idx >= 0 &&
406  urban_idx < static_cast<int>(urban_data_lev[lev].size()) &&
407  urban_data_lev[lev][urban_idx];
408  if (valid_land) {
409  validate_radiation_output_layout(lev, lsm_data_lev[lev][land_idx]);
410  rad_output_fields[lev][i] = lsm_data_lev[lev][land_idx];
411  } else if (valid_urban) {
412  rad_output_fields[lev][i] = urban_data_lev[lev][urban_idx];
413  }
414  if (valid_urban) {
415  validate_radiation_output_layout(lev, urban_data_lev[lev][urban_idx]);
416  }
417  }
418  return rad_output_fields[lev];
419 }
amrex::Vector< amrex::Vector< amrex::MultiFab * > > rad_output_fields
Definition: ERF_SurfaceModel.H:1149
void validate_radiation_output_layout(int lev, const amrex::MultiFab *mf) const
Validates the layout contract for a canonical radiation output.
Definition: ERF_SurfaceModel.cpp:429

◆ get_surface_flux_view()

SurfaceFluxView SurfaceModel::get_surface_flux_view ( const int  lev,
const amrex::MFIter &  mfi 
) const
inline

Returns provider or blended surface-flux views for one tile.

Parameters
levAMR level to query.
mfiTile whose flux arrays are requested.
Returns
Read-only flux views selected for the level's provider mode.
474  {
476 
477  const SurfaceProviderMode mode = m_provider_mode[lev];
478  if (mode == SurfaceProviderMode::Both) {
479  AMREX_ALWAYS_ASSERT(u_star[lev] != nullptr);
480  AMREX_ALWAYS_ASSERT(t_star[lev] != nullptr);
481  AMREX_ALWAYS_ASSERT(q_star[lev] != nullptr);
482  return {u_star[lev]->const_array(mfi, 0),
483  u_star[lev]->const_array(mfi, 1),
484  t_star[lev]->const_array(mfi),
485  q_star[lev]->const_array(mfi)};
486  }
487 
488  const auto& provider_fields = (mode == SurfaceProviderMode::LandOnly)
490  const auto& provider_data = (mode == SurfaceProviderMode::LandOnly)
491  ? lsm_data_lev[lev] : urban_data_lev[lev];
492  auto get_provider_field = [&] (const int field) -> amrex::Array4<const amrex::Real> {
493  if (field >= static_cast<int>(provider_fields.size())) {
494  return {};
495  }
496  const int index = provider_fields[field];
497  if (index < 0 || index >= static_cast<int>(provider_data.size()) ||
498  provider_data[index] == nullptr) {
499  return {};
500  }
501  return provider_data[index]->const_array(mfi);
502  };
503 
504  return {get_provider_field(0), get_provider_field(1),
505  get_provider_field(2), get_provider_field(3)};
506  }
Here is the call graph for this function:

◆ get_tstar()

amrex::MultiFab* SurfaceModel::get_tstar ( const int &  lev)
inline

Returns the weighted thermal output for a level.

Parameters
levAMR level to query.
Returns
Pointer to the weighted t-star or heat-flux field.
445  {
446  return t_star[lev].get();
447  }

◆ get_tsurf()

amrex::MultiFab* SurfaceModel::get_tsurf ( const int &  lev)
inline

Returns the weighted surface-temperature output for a level.

Parameters
levAMR level to query.
Returns
Pointer to the weighted surface-temperature field.
463  {
464  return t_surf[lev].get();
465  }

◆ get_ustar()

amrex::MultiFab* SurfaceModel::get_ustar ( const int &  lev)
inline

Returns the weighted horizontal momentum output for a level.

Parameters
levAMR level to query.
Returns
Pointer to the weighted u-star or momentum-flux field.
436  {
437  return u_star[lev].get();
438  }

◆ get_wavg_factors()

amrex::MultiFab* SurfaceModel::get_wavg_factors ( const int &  lev)
inline

Returns the land and urban weighting factors for a level.

Parameters
levAMR level to query.
Returns
Pointer to the weighting-factor field.
559  {
561  return wavg[lev].get();
562  }
void ensure_weight_factors(const int lev)
Creates weighting factors when an external caller requests them.
Definition: ERF_SurfaceModel.H:1010
Here is the call graph for this function:

◆ get_weighted_model_data()

const amrex::MultiFab* SurfaceModel::get_weighted_model_data ( const int  lev,
SurfaceModelType  type,
const int  field_idx 
) const
inline

Returns weighted data for a selected model field.

Parameters
levAMR level to query.
typeProvider type owning the field.
field_idxProvider field index.
Returns
Weighted field or the source field for a single provider, or nullptr if it has not been selected.
517  {
518  const SurfaceProviderMode mode = m_provider_mode[lev];
519  const bool single_provider =
522  if (single_provider) {
523  const auto& selected = (type == SurfaceModelType::LAND)
525  const int first_output_field = m_export_fluxes ? 5 : 4;
526  bool is_weighted_field = false;
527  for (int field = first_output_field;
528  field < static_cast<int>(selected.size()); ++field) {
529  if (selected[field] == field_idx) {
530  is_weighted_field = true;
531  break;
532  }
533  }
534  if (!is_weighted_field) {
535  return nullptr;
536  }
537 
538  const auto& source = (type == SurfaceModelType::LAND)
539  ? lsm_data_lev[lev] : urban_data_lev[lev];
540  if (field_idx < 0 || field_idx >= static_cast<int>(source.size())) {
541  return nullptr;
542  }
543  return source[field_idx];
544  }
545 
546  const auto& weighted = (type == SurfaceModelType::LAND)
548  if (field_idx < 0 || field_idx >= static_cast<int>(weighted.size())) {
549  return nullptr;
550  }
551  return weighted[field_idx].get();
552  }

◆ GotoNextLine()

void SurfaceModel::GotoNextLine ( std::istream &  is)
static

Advances an input stream to the next line.

taken from ERF_Checkpoint, reuse?

Parameters
isInput stream to advance.
847 {
848  constexpr std::streamsize bl_ignore_max { 100000 };
849  is.ignore(bl_ignore_max, '\n');
850 }

◆ initialize_for_level()

void SurfaceModel::initialize_for_level ( int  lev,
const amrex::BoxArray &  ba,
const amrex::Geometry &  geom,
const amrex::DistributionMapping &  dm,
const amrex::Vector< std::unique_ptr< amrex::iMultiFab >> &  lmask_lev,
const amrex::Vector< amrex::BCRec > &  domain_bcs_type,
const amrex::Vector< amrex::IntVect > &  refRatio 
)
inline

Initializes storage and boundary data for an AMR level.

Existing coarser-level data are interpolated when a finer level is initialized.

Parameters
levAMR level to initialize.
baCell-centered box array for the level.
geomGeometry for the level.
dmDistribution mapping for the level.
lmask_levLand-mask data used by the level.
domain_bcs_typeBoundary conditions for interpolation.
refRatioRefinement ratios between adjacent levels.
104  {
105  if (lev >= m_nlevs) { resize_levels(lev+1); }
106 
107  m_ba[lev] = ba;
108  m_geom[lev] = geom;
109  m_dmap[lev] = dm;
110 
111  // Create a 2D ba, dm, & ghost cells
112  amrex::BoxList bl2d = ba.boxList();
113  for (auto& b : bl2d) {
114  b.setRange(2, 0);
115  }
116  m_ba2d[lev] = amrex::BoxArray(std::move(bl2d));
117 
118  amrex::RealBox dom2d = geom.ProbDomain();
119  dom2d.setHi(2, geom.CellSize(2));
120  m_geom2d[lev].define(makeSlab(m_geom[lev].Domain(), 2, 0), dom2d, geom.Coord(), geom.isPeriodic());
121 
122  m_lmask[lev] = lmask_lev[0].get();
123 
124  weighted_lsm_data_lev[lev].clear();
125  weighted_urban_data_lev[lev].clear();
126 
127  u_star[lev].reset();
128  t_star[lev].reset();
129  q_star[lev].reset();
130  t_surf[lev].reset();
131  wavg[lev].reset();
132  if (m_surface_outputs_requested[lev]) {
134  }
136 
137  // Recreate registered fields on the current level layout. This is also
138  // needed when an existing AMR level is remade with a new grid layout.
139  for (int field = 0; field < static_cast<int>(fields.size()); ++field) {
140  fields[field][lev].reset();
141  }
142  // Keep each map's consumer kind: a map active only for one output must not
143  // become persistent because a regrid happened while it was active
144  for (const auto& entry : fieldmap) {
145  if (entry.second.active) {
146  activate_field_map(entry.first, entry.second.persistent_consumer);
147  }
148  }
149  for (auto& entry : radiation_input_map) {
150  entry.second.weighted[lev].reset();
151  }
152 
153  // Cached radiation fields point into the registered storage above.
154  // Rebuild the cache when this level's fields have been replaced.
155  rad_fields[lev].clear();
156  rad_output_fields[lev].clear();
157 
158  // Interpolate the new finer level using coarse data. These fields hold lsm_undefined
159  // where no provider has a value, and their consumers fall back to MOST there. A valid
160  // and an invalid value are two types (interp_by_type), so no valid fine cell takes a
161  // slope toward an invalid coarse cell, and a fine cell under an invalid one is
162  // lsm_undefined. Every field moves in one pack: one ghost exchange and one
163  // coarse-to-fine copy.
164  if (lev > 0) {
165  amrex::Vector<InterpTransfer> transfers;
166  if (u_star[lev] != nullptr && u_star[lev-1] != nullptr) {
167  transfers.push_back({u_star[lev].get(), u_star[lev-1].get(), 2});
168  transfers.push_back({t_star[lev].get(), t_star[lev-1].get(), 1});
169  transfers.push_back({q_star[lev].get(), q_star[lev-1].get(), 1});
170  // t_surf starts at 300 but is lsm_undefined where its provider has no field
171  transfers.push_back({t_surf[lev].get(), t_surf[lev-1].get(), 1});
172  }
173  for (int field = 0; field < static_cast<int>(fields.size()); ++field) {
174  if (fields[field][lev] == nullptr || fields[field][lev-1] == nullptr) { continue; }
175  transfers.push_back({fields[field][lev].get(), fields[field][lev-1].get(), 1});
176  }
177  if (!transfers.empty()) {
178  interp_surface_fields_from_coarse(lev, transfers, domain_bcs_type[BCVars::cons_bc],
179  refRatio[lev-1]);
180  }
181  }
182  }
void interp_surface_fields_from_coarse(const int lev, const amrex::Vector< InterpTransfer > &transfers, const amrex::BCRec &bc, const amrex::IntVect &ratio)
Fills fine-level surface fields from the next coarser level with interp_by_type.
Definition: ERF_SurfaceModel.H:867
void ensure_surface_outputs(const int lev)
Allocates surface-output fields for one level.
Definition: ERF_SurfaceModel.H:1027
amrex::Vector< amrex::Geometry > m_geom2d
Definition: ERF_SurfaceModel.H:1084
amrex::Vector< amrex::iMultiFab * > m_lmask
Definition: ERF_SurfaceModel.H:1085
@ cons_bc
Definition: ERF_IndexDefines.H:122
Here is the call graph for this function:

◆ interp_surface_fields_from_coarse()

void SurfaceModel::interp_surface_fields_from_coarse ( const int  lev,
const amrex::Vector< InterpTransfer > &  transfers,
const amrex::BCRec &  bc,
const amrex::IntVect &  ratio 
)
inline

Fills fine-level surface fields from the next coarser level with interp_by_type.

Each component is typed valid or invalid (is_valid_lsm_value) per coarse cell, so a valid fine cell takes no slope toward an invalid coarse cell; where every neighbor is valid this is cell_cons_interp. A fine cell whose parent is invalid is set to lsm_undefined. Fine ghost cells outside the domain keep their values.

Parameters
levFine AMR level.
transfersFields to fill; all share one fine and one coarse layout.
bcBoundary condition every field takes.
ratioRefinement ratio from level lev-1 to lev.
870  {
871  constexpr amrex::Real valid_type = 0.0;
872  constexpr amrex::Real undefined_type = 1.0;
873 
874  int nfield = 0;
875  for (const auto& t : transfers) { nfield += t.ncomp; }
876 
877  // Each pack holds the nfield components and then their nfield types
878  const amrex::MultiFab& f0 = *transfers[0].fine;
879  const amrex::MultiFab& c0 = *transfers[0].crse;
880  amrex::MultiFab fine_pack(f0.boxArray(), f0.DistributionMap(), 2*nfield, f0.nGrowVect());
881  amrex::MultiFab crse_pack(c0.boxArray(), c0.DistributionMap(), 2*nfield, c0.nGrowVect());
882  int n0 = 0;
883  for (const auto& t : transfers) {
884  AMREX_ALWAYS_ASSERT(t.fine->boxArray() == f0.boxArray() &&
885  t.fine->DistributionMap() == f0.DistributionMap() &&
886  t.fine->nGrowVect() == f0.nGrowVect());
887  AMREX_ALWAYS_ASSERT(t.crse->boxArray() == c0.boxArray() &&
888  t.crse->DistributionMap() == c0.DistributionMap() &&
889  t.crse->nGrowVect() == c0.nGrowVect());
890  amrex::MultiFab::Copy(fine_pack, *t.fine, 0, n0, t.ncomp, f0.nGrowVect());
891  amrex::MultiFab::Copy(crse_pack, *t.crse, 0, n0, t.ncomp, c0.nGrowVect());
892  n0 += t.ncomp;
893  }
894 
895  // The interpolation reads the coarse ghost cells; fill them in the pack only, so the
896  // coarse fields themselves are not touched
897  crse_pack.FillBoundary(0, nfield, m_geom2d[lev-1].periodicity());
898  for (amrex::MFIter mfi(crse_pack, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
899  const auto p = crse_pack.array(mfi);
900  amrex::ParallelFor(mfi.growntilebox(), nfield,
901  [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
902  {
903  p(i,j,k,nfield+n) = is_valid_lsm_value(p(i,j,k,n)) ? valid_type : undefined_type;
904  });
905  }
906  // The fine types come out as their parents'; a cell the interpolation does not fill
907  // keeps valid_type and so its value
908  fine_pack.setVal(valid_type, nfield, nfield, f0.nGrowVect());
909 
910  // The fields are planar
911  amrex::IntVect rr2d = ratio;
912  rr2d[2] = 1;
913  interp_by_type_packed(fine_pack, crse_pack, nfield, m_geom2d[lev-1], m_geom2d[lev], rr2d,
914  bc);
915 
916  for (amrex::MFIter mfi(fine_pack, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
917  const auto p = fine_pack.array(mfi);
918  amrex::ParallelFor(mfi.growntilebox(), nfield,
919  [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
920  {
921  if (p(i,j,k,nfield+n) != valid_type) { p(i,j,k,n) = lsm_undefined; }
922  });
923  }
924 
925  n0 = 0;
926  for (const auto& t : transfers) {
927  amrex::MultiFab::Copy(*t.fine, fine_pack, n0, 0, t.ncomp, f0.nGrowVect());
928  n0 += t.ncomp;
929  }
930  }
void interp_by_type_packed(amrex::MultiFab &fdst, amrex::MultiFab &csrc, int nind, const amrex::Geometry &cgeom, const amrex::Geometry &fgeom, const amrex::IntVect &ratio, const amrex::BCRec &bc)
Definition: ERF_TypedInterp.H:200
@ t
Definition: ERF_WSM6.H:295
@ p
Definition: ERF_WSM6.H:303
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182

Referenced by initialize_for_level().

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

◆ is_field_mapped()

bool SurfaceModel::is_field_mapped ( int  lev,
SurfaceModelType  type,
int  field_idx,
const amrex::MultiFab *  mf 
) const

Checks whether a model field participates in a registered mapping.

Parameters
levAMR level to query.
typeLand or urban model owning the field.
field_idxIndex of the model field.
mfField pointer to test.
Returns
True when the field is part of a registered mapping.
504 {
505  for (const auto& entry : fieldmap) {
506  const Field& field = entry.second;
507 
508  const int mapped_idx = (type == SurfaceModelType::LAND)
509  ? field.map.first : field.map.second;
510  if (mapped_idx == field_idx) {
511  return true;
512  }
513 
514  // Pointer-based mappings have no model-field index. Match the
515  // registered pointer for the current level instead.
516  if (field.map.first == -1 && field.map.second == -1 && mf != nullptr) {
517  const auto& ptrs = (type == SurfaceModelType::LAND)
518  ? field.lsm_ptr : field.urb_ptr;
519  if (lev < static_cast<int>(ptrs.size()) && ptrs[lev] == mf) {
520  return true;
521  }
522  }
523  }
524 
525  for (const auto& entry : radiation_input_map) {
526  const auto& map = entry.second.map;
527  const int mapped_idx = (type == SurfaceModelType::LAND)
528  ? map.first : map.second;
529  if (mapped_idx == field_idx) {
530  return true;
531  }
532  }
533 
534  return false;
535 }
if(add_bubble)
Definition: ERF_InitCustomPert_ABL.H:60
real(c_double), private map
Definition: ERF_module_mp_morr_two_moment.F90:222
Here is the call graph for this function:

◆ mark_fields_valid()

void SurfaceModel::mark_fields_valid ( )
inline

Marks the registered surface fields as filled by an actual model advance.

422 { m_fields_are_valid = true; }

◆ ReadCheckpoint()

void SurfaceModel::ReadCheckpoint ( const std::string &  checkpointname)

Restores surface-model state from a checkpoint file.

Parameters
checkpointnameCheckpoint file name.
970 {
973  auto check_start = amrex::second();
974 
975  amrex::Print() << " Reading SurfaceModel checkpoint " << std::endl;
976 
977  auto checkpoint_error = [&] (const std::string& message) {
978  amrex::Abort("SurfaceModel checkpoint '" + checkpointname + "': " + message);
979  };
980 
981  // Header
982  const std::string File(checkpointname + "/SurfaceModel_Header");
983  if (!amrex::FileExists(File)) {
984  checkpoint_error("missing SurfaceModel_Header");
985  }
986 
987  Vector<char> fileCharPtr;
988  ParallelDescriptor::ReadAndBcastFile(File, fileCharPtr);
989  std::string fileCharPtrString(fileCharPtr.dataPtr(), fileCharPtr.size());
990  std::istringstream is(fileCharPtrString, std::istringstream::in);
991 
992  std::string line;
993 
994  // read in title line
995  if (!std::getline(is, line) || line != "Checkpoint file for SurfaceModel") {
996  checkpoint_error("invalid or truncated header title");
997  }
998 
999  // read in number of levels
1000  int chk_nlevs = -1;
1001  if (!(is >> chk_nlevs) || chk_nlevs < 1) {
1002  checkpoint_error("invalid number of levels");
1003  }
1004 
1005  // read in flags
1006  bool chk_use_urban = false;
1007  bool chk_use_land = false;
1008  bool chk_export_fluxes = false;
1009  bool chk_weights_updated = false;
1010  bool chk_fields_are_valid = false;
1011  if (!(is >> chk_use_urban >> chk_use_land >> chk_export_fluxes >> chk_weights_updated
1012  >> chk_fields_are_valid)) {
1013  checkpoint_error("invalid flags in header");
1014  }
1015  GotoNextLine(is);
1016 
1017  if (chk_nlevs != m_nlevs) {
1018  checkpoint_error("level count mismatch: checkpoint has " + std::to_string(chk_nlevs) +
1019  ", current SurfaceModel has " + std::to_string(m_nlevs));
1020  }
1021  if (chk_use_urban != m_use_urban || chk_use_land != m_use_land ||
1022  chk_export_fluxes != m_export_fluxes) {
1023  checkpoint_error("model configuration flags do not match the current SurfaceModel");
1024  }
1025 
1026  // Read box arrays into temporaries so current runtime geometry is not
1027  // overwritten before it has been validated.
1028  amrex::Vector<amrex::BoxArray> chk_ba(chk_nlevs);
1029  amrex::Vector<amrex::BoxArray> chk_ba2d(chk_nlevs);
1030  for (int lev = 0; lev < chk_nlevs; ++lev) {
1031  chk_ba[lev].readFrom(is);
1032  if (!is) checkpoint_error("invalid 3D BoxArray for level " + std::to_string(lev));
1033  GotoNextLine(is);
1034  }
1035  GotoNextLine(is);
1036  for (int lev = 0; lev < chk_nlevs; ++lev) {
1037  chk_ba2d[lev].readFrom(is);
1038  if (!is) checkpoint_error("invalid 2D BoxArray for level " + std::to_string(lev));
1039  GotoNextLine(is);
1040  }
1041  GotoNextLine(is);
1042 
1043  // The checkpointed fields are read back on the decomposition they were written with and
1044  // then redistributed onto the live one, so the two BoxArrays need not match box for box.
1045  // They do have to cover the same index space: ERF turns regridding of level 0 on by itself
1046  // when a restart uses more ranks than level 0 has boxes (see ERF::restart), which changes
1047  // the boxes but not the region they tile.
1048  const std::string coverage_hint =
1049  "; the SurfaceModel checkpoint can be read back on a different decomposition, but not "
1050  "on a different domain -- check that the restart uses the same grid extents and "
1051  "refinement as the run that wrote the checkpoint";
1052  amrex::Vector<amrex::DistributionMapping> chk_dmap(chk_nlevs);
1053  for (int lev = 0; lev < chk_nlevs; ++lev) {
1054  if (chk_ba[lev].minimalBox() != m_ba[lev].minimalBox()) {
1055  checkpoint_error("3D domain coverage mismatch at level " + std::to_string(lev) +
1056  coverage_hint);
1057  }
1058  if (chk_ba2d[lev].minimalBox() != m_ba2d[lev].minimalBox()) {
1059  checkpoint_error("2D domain coverage mismatch at level " + std::to_string(lev) +
1060  coverage_hint);
1061  }
1062  chk_dmap[lev].define(chk_ba2d[lev]);
1063  }
1064 
1065  // Read in LSM fields
1066  if (!std::getline(is, line)) {
1067  checkpoint_error("missing LSM field list");
1068  }
1069  amrex::Vector<int> chk_lsm_fields;
1070  std::istringstream lsm_stream(line);
1071  int field_idx = -1;
1072  while (lsm_stream >> field_idx) chk_lsm_fields.push_back(field_idx);
1073 
1074  // Read in Urban fields
1075  if (!std::getline(is, line)) {
1076  checkpoint_error("missing urban field list");
1077  }
1078  amrex::Vector<int> chk_urban_fields;
1079  std::istringstream urban_stream(line);
1080  while (urban_stream >> field_idx) chk_urban_fields.push_back(field_idx);
1081  GotoNextLine(is);
1082 
1083  // The entries are indices into the provider's data list, with the fluxes appended after
1084  // the data fields, so they move whenever a model adds a data field (Noah-MP grew from 27
1085  // to 29 when snow and snowh were added). Nothing is restored from them -- the fields
1086  // themselves are read by name below -- so only require that the same slots are in use.
1087  auto same_slots = [] (const amrex::Vector<int>& a, const amrex::Vector<int>& b) {
1088  if (a.size() != b.size()) return false;
1089  for (int i = 0; i < static_cast<int>(a.size()); ++i) {
1090  if ((a[i] == -1) != (b[i] == -1)) return false;
1091  }
1092  return true;
1093  };
1094  if (!same_slots(chk_lsm_fields, lsm_fields) || !same_slots(chk_urban_fields, urban_fields)) {
1095  checkpoint_error("model field lists do not match the current SurfaceModel");
1096  }
1097 
1098  // Read number of mapped fields
1099  int nfields = 0;
1100  if (!(is >> nfields) || nfields < 0) {
1101  checkpoint_error("invalid mapped-field count");
1102  }
1103  GotoNextLine(is);
1104 
1105  // Read any mapped fields
1106  if (nfields != static_cast<int>(fieldmap.size())) {
1107  checkpoint_error("mapped-field count does not match the current SurfaceModel");
1108  }
1109 
1110  // The field mapping should already be created before the restart, but verify consistency with the file
1111  amrex::Vector<std::string> checkpoint_field_names;
1112  for (int i = 0; i < nfields; i++) {
1113  if (!std::getline(is, line)) {
1114  checkpoint_error("missing mapped-field entry " + std::to_string(i));
1115  }
1116  std::istringstream lis(line);
1117 
1118  std::string field_name;
1119  int chk_mf_ind = -1;
1120  int lsm_ind = -1;
1121  int urb_ind = -1;
1122  int fill_bound_int = -1;
1123  if (!(lis >> field_name >> chk_mf_ind >> lsm_ind >> urb_ind >> fill_bound_int) ||
1124  chk_mf_ind < 0 || lsm_ind < -1 || urb_ind < -1 ||
1125  (fill_bound_int != 0 && fill_bound_int != 1)) {
1126  checkpoint_error("invalid mapped-field entry for '" + field_name + "'");
1127  }
1128  const bool fill_bound = (fill_bound_int != 0);
1129 
1130  auto field_it = fieldmap.find(field_name);
1131  if (field_it == fieldmap.end()) {
1132  checkpoint_error("checkpoint mapping '" + field_name + "' is not registered");
1133  }
1134  for (const auto& seen_name : checkpoint_field_names) {
1135  if (seen_name == field_name) {
1136  checkpoint_error("duplicate mapped-field entry for '" + field_name + "'");
1137  }
1138  }
1139  checkpoint_field_names.push_back(field_name);
1140  const auto &field = field_it->second;
1141  if (field.mf_ind < 0 || field.mf_ind >= static_cast<int>(fields.size())) {
1142  checkpoint_error("current mapped-field storage is invalid for '" + field_name + "'");
1143  }
1144  if (static_cast<int>(fields[field.mf_ind].size()) != m_nlevs) {
1145  checkpoint_error("current mapped-field level storage is invalid for '" + field_name + "'");
1146  }
1147  // As above, the provider indices may have shifted; only whether the field maps to the
1148  // land and/or urban provider has to match.
1149  if ((field.map.first == -1) != (lsm_ind == -1) ||
1150  (field.map.second == -1) != (urb_ind == -1) ||
1151  field.fill_bound != fill_bound) {
1152  checkpoint_error("mapped-field metadata mismatch for '" + field_name + "'");
1153  }
1154  if (lsm_ind == -1 && urb_ind == -1) {
1155  if (static_cast<int>(field.lsm_ptr.size()) != m_nlevs ||
1156  static_cast<int>(field.urb_ptr.size()) != m_nlevs) {
1157  checkpoint_error("pointer mapping has the wrong number of levels for '" + field_name + "'");
1158  }
1159  for (int lev = 0; lev < m_nlevs; ++lev) {
1160  if (fields[field.mf_ind][lev] == nullptr) {
1161  checkpoint_error("mapped-field storage is missing at level " +
1162  std::to_string(lev) + " for '" + field_name + "'");
1163  }
1164  }
1165  } else {
1166  for (int lev = 0; lev < m_nlevs; ++lev) {
1167  const bool invalid_land_index =
1168  !lsm_data_lev[lev].empty() &&
1169  field.map.first >= static_cast<int>(lsm_data_lev[lev].size());
1170  const bool invalid_urban_index =
1171  !urban_data_lev[lev].empty() &&
1172  field.map.second >= static_cast<int>(urban_data_lev[lev].size());
1173  if (invalid_land_index || invalid_urban_index) {
1174  checkpoint_error("mapped-field index is out of range for '" + field_name + "'");
1175  }
1176  if (fields[field.mf_ind][lev] == nullptr) {
1177  checkpoint_error("mapped-field storage is missing at level " +
1178  std::to_string(lev) + " for '" + field_name + "'");
1179  }
1180  }
1181  }
1182  amrex::ignore_unused(chk_mf_ind);
1183  }
1184 
1185  const std::string prefix = "SurfaceModel_";
1186 
1187  IntVect ng = IntVect(1,1,0);
1188  auto validate_multifab_header = [&] (const std::string& name, int lev, int ncomp) {
1189  const std::string header_name = name + "_H";
1190  if (!amrex::FileExists(header_name)) {
1191  checkpoint_error("missing MultiFab header '" + header_name + "'");
1192  }
1193 
1194  Vector<char> header_data;
1195  ParallelDescriptor::ReadAndBcastFile(header_name, header_data);
1196  std::istringstream header_stream(
1197  std::string(header_data.dataPtr(), header_data.size()), std::istringstream::in);
1198  VisMF::Header header;
1199  if (!(header_stream >> header)) {
1200  checkpoint_error("invalid MultiFab header '" + header_name + "'");
1201  }
1202  if (header.m_ncomp != ncomp || header.m_ngrow != ng ||
1203  !(header.m_ba == chk_ba2d[lev])) {
1204  checkpoint_error("MultiFab layout mismatch for level " + std::to_string(lev) +
1205  " in '" + name + "'");
1206  }
1207  if (static_cast<amrex::Long>(header.m_fod.size()) != chk_ba2d[lev].size()) {
1208  checkpoint_error("MultiFab FAB count mismatch for level " + std::to_string(lev) +
1209  " in '" + name + "'");
1210  }
1211  const std::string data_dir = VisMF::DirName(name);
1212  for (const auto& fab_file : header.m_fod) {
1213  if (!amrex::FileExists(data_dir + fab_file.m_name)) {
1214  checkpoint_error("missing MultiFab data file '" + data_dir + fab_file.m_name + "'");
1215  }
1216  }
1217  };
1218 
1219  // Validate all required data headers before changing any runtime fields.
1220  for (int lev = 0; lev < m_nlevs; ++lev) {
1221  validate_multifab_header(MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "ustar"), lev, 2);
1222  validate_multifab_header(MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "wavg"), lev, 2);
1223  validate_multifab_header(MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "tstar"), lev, 1);
1224  validate_multifab_header(MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "qstar"), lev, 1);
1225  validate_multifab_header(MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "tsurf"), lev, 1);
1226  for (const auto &field : fieldmap) {
1227  validate_multifab_header(
1228  MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "_f_" + field.first), lev, 1);
1229  }
1230  }
1231 
1232  //
1233  // Move a field that was read on the checkpointed layout onto the live one. When the two
1234  // layouts are identical this is the same local copy it always was, so an unchanged restart
1235  // stays bitwise identical; otherwise the data is redistributed.
1236  //
1237  // The redistribution is done in two passes because the checkpoint carries ghost cells and
1238  // a single ParallelCopy over grown source boxes would leave the outcome up to the order in
1239  // which overlapping sources happen to be applied. The first pass seeds everything,
1240  // including the ghost cells outside a non-periodic physical boundary, which no amount of
1241  // valid-region copying can reach. The second pass then lays the valid data over the top,
1242  // so wherever a cell is covered by a valid source cell that value wins.
1243  //
1244  auto redistribute = [&] (MultiFab& dst, const MultiFab& src, int ncomp, int lev)
1245  {
1246  if (dst.boxArray() == src.boxArray() && dst.DistributionMap() == src.DistributionMap()) {
1247  MultiFab::Copy(dst, src, 0, 0, ncomp, ng);
1248  return;
1249  }
1250  dst.ParallelCopy(src, 0, 0, ncomp, ng, ng);
1251  dst.ParallelCopy(src, 0, 0, ncomp, IntVect(0), ng, m_geom2d[lev].periodicity());
1252  };
1253 
1254  for (int lev = 0; lev < m_nlevs; lev++) {
1255  {
1256  MultiFab mf(chk_ba2d[lev],chk_dmap[lev],2,ng);
1257  VisMF::Read(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "ustar"));
1258  redistribute(*(u_star[lev]),mf,2,lev);
1259 
1260  VisMF::Read(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "wavg"));
1261  ensure_weight_factors(lev);
1262  redistribute(*wavg[lev],mf,2,lev);
1263  }
1264 
1265  MultiFab mf(chk_ba2d[lev],chk_dmap[lev],1,ng);
1266 
1267  VisMF::Read(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "tstar"));
1268  redistribute(*t_star[lev],mf,1,lev);
1269 
1270  VisMF::Read(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "qstar"));
1271  redistribute(*q_star[lev],mf,1,lev);
1272 
1273  VisMF::Read(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "tsurf"));
1274  redistribute(*t_surf[lev],mf,1,lev);
1275 
1276  for (auto &field : fieldmap) {
1277  VisMF::Read(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "_f_" + field.first));
1278  redistribute(*(fields[field.second.mf_ind][lev]), mf, 1, lev);
1279  }
1280  }
1281 
1282  m_weights_updated = chk_weights_updated;
1283  // Restore whether the surface models had already integrated a step when the checkpoint
1284  // was written. Without this a restart would spend its first step treating the
1285  // checkpointed u*/t*/q* as unfilled and fall back to the MOST values instead.
1286  m_fields_are_valid = chk_fields_are_valid;
1287 
1290 
1291  auto check_end = amrex::second() - check_start;
1292  ParallelDescriptor::ReduceRealMax(check_end,ParallelDescriptor::IOProcessorNumber());
1293  amrex::Print() << " SurfaceModel Checkpoint load time = " << check_end << " seconds." << '\n';
1294 }
std::string message
Definition: ERF_InputPreflight.cpp:25
static void GotoNextLine(std::istream &is)
Advances an input stream to the next line.
Definition: ERF_SurfaceModel.cpp:846
void release_transient_surface_outputs()
Releases surface outputs that have no persistent consumer.
Definition: ERF_SurfaceModel.H:1045
bool m_use_urban
Definition: ERF_SurfaceModel.H:1063
void activate_all_field_maps(const bool persistent=true)
Activates all registered mapped fields for an output consumer.
Definition: ERF_SurfaceModel.cpp:669
void request_surface_outputs(const bool persistent=true)
Enables and materializes the surface outputs consumed by ERF.
Definition: ERF_SurfaceModel.H:396
void deactivate_transient_field_maps()
Disables and releases mapped fields used only by the last output.
Definition: ERF_SurfaceModel.cpp:676
bool m_use_land
Definition: ERF_SurfaceModel.H:1064

◆ register_field_map() [1/2]

void SurfaceModel::register_field_map ( std::string  name,
amrex::Vector< amrex::MultiFab * > &  lsm_lev_mf,
amrex::Vector< amrex::MultiFab * > &  urb_lev_mf,
bool  fill_boundary = false 
)

Registers a field map using per-level land and urban pointers.

Parameters
nameCommon name used to retrieve the mapped field.
lsm_lev_mfLand-model fields, indexed by AMR level.
urb_lev_mfUrban-model fields, indexed by AMR level.
fill_boundaryWhether to fill mapped-field boundaries.
601 {
602  // Register a field using explicit data pointers, rather than indices into lsm_data and urban_data
603  AMREX_ALWAYS_ASSERT(lsm_lev_mf.size() > 0);
604  amrex::Print() << " adding mapping between LSM<->Urban mfs <"<<lsm_lev_mf[0] << "," << urb_lev_mf[0] << "> to common surface name " << name << std::endl;
605 
606  AMREX_ALWAYS_ASSERT(lsm_lev_mf.size() == urb_lev_mf.size());
607  if (fieldmap.find(name) == fieldmap.end()) {
608 
609  Field field;
610  field.map = std::pair<int,int>(-1,-1);
611  field.mf_ind = -1;
612  field.fill_bound = fill_boundary;
613  field.lsm_ptr = lsm_lev_mf;
614  field.urb_ptr = urb_lev_mf;
615 
616  // Storage is allocated when a consumer activates this mapping.
617  amrex::Vector<std::unique_ptr<amrex::MultiFab>> mf_lev(m_nlevs);
618  fields.push_back(std::move(mf_lev));
619  field.mf_ind = fields.size() - 1;
620 
621  amrex::Print() << " -- created at ind = " << field.mf_ind << std::endl;
622 
623  fieldmap.insert({name, field});
624  } else {
625  return;
626  }
627 }
Here is the call graph for this function:

◆ register_field_map() [2/2]

void SurfaceModel::register_field_map ( std::string  name,
const std::pair< int, int > &  lsm_urb_map,
bool  fill_boundary = false 
)

Registers a field map using land and urban field indices.

Parameters
nameCommon name used to retrieve the mapped field.
lsm_urb_mapPair of land and urban field indices.
fill_boundaryWhether to fill mapped-field boundaries.
576 {
577  amrex::Print() << " adding mapping between LSM<->Urban fields <"<<lsm_urb_map.first << "," << lsm_urb_map.second << "> to common surface name " << name << std::endl;
578 
579  AMREX_ALWAYS_ASSERT(!(lsm_urb_map.first == -1 && lsm_urb_map.second == -1));
580  if (fieldmap.find(name) == fieldmap.end()) {
581 
582  Field field;
583  field.map = lsm_urb_map;
584  field.mf_ind = -1;
585  field.fill_bound = fill_boundary;
586 
587  // Storage is allocated when a consumer activates this mapping.
588  amrex::Vector<std::unique_ptr<amrex::MultiFab>> mf_lev(m_nlevs);
589  fields.push_back(std::move(mf_lev));
590  field.mf_ind = fields.size() - 1;
591 
592  amrex::Print() << " -- created at ind = " << field.mf_ind << std::endl;
593 
594  fieldmap.insert({name, field});
595  } else {
596  return;
597  }
598 }
Here is the call graph for this function:

◆ register_radiation_input()

void SurfaceModel::register_radiation_input ( const std::string &  name,
const std::pair< int, int > &  lsm_urb_map 
)

Registers a canonical radiation input mapping.

Parameters
nameCanonical radiation input name.
lsm_urb_mapPair of land and urban model field indices.
321 {
322  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!(map.first == -1 && map.second == -1),
323  "A radiation input must have a provider mapping");
325  std::find(radnames.begin(), radnames.end(), name) != radnames.end(),
326  "Unknown canonical radiation input: " + name);
327  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(map.first >= -1 && map.second >= -1,
328  "Radiation input indices must be -1 or nonnegative");
329  if (map.first >= 0) {
330  AMREX_ALWAYS_ASSERT(map.first < static_cast<int>(m_lsm_names.size()));
331  }
332  if (map.second >= 0) {
333  AMREX_ALWAYS_ASSERT(map.second < static_cast<int>(m_urban_names.size()));
334  }
335  RadiationField field;
336  field.map = map;
337  field.weighted.resize(m_nlevs);
338  radiation_input_map[name] = std::move(field);
339  for (auto& fields_at_level : rad_fields) { fields_at_level.clear(); }
340 }
amrex::Vector< std::string > m_lsm_names
Definition: ERF_SurfaceModel.H:1145
amrex::Vector< std::string > m_urban_names
Definition: ERF_SurfaceModel.H:1146
Here is the call graph for this function:

◆ register_radiation_inputs()

void SurfaceModel::register_radiation_inputs ( const std::unordered_map< std::string, std::pair< int, int >> &  input_map)

Registers canonical radiation input mappings.

Parameters
input_mapCanonical names mapped to land and urban indices.
344 {
345  for (const auto& entry : input_map) {
346  register_radiation_input(entry.first, entry.second);
347  }
348 }
void register_radiation_input(const std::string &name, const std::pair< int, int > &lsm_urb_map)
Registers a canonical radiation input mapping.
Definition: ERF_SurfaceModel.cpp:319

◆ register_radiation_output()

void SurfaceModel::register_radiation_output ( const std::string &  name,
const std::pair< int, int > &  lsm_urb_map 
)

Registers a canonical radiation output mapping.

Parameters
nameCanonical radiation output name.
lsm_urb_mapPair of land and urban model field indices.
352 {
353  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!(map.first == -1 && map.second == -1),
354  "A radiation output must have a provider mapping");
356  std::find(rad_output_names.begin(), rad_output_names.end(), name) != rad_output_names.end(),
357  "Unknown canonical radiation output: " + name);
358  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(map.first >= -1 && map.second >= -1,
359  "Radiation output indices must be -1 or nonnegative");
360  if (map.first >= 0) {
361  AMREX_ALWAYS_ASSERT(map.first < static_cast<int>(m_lsm_names.size()));
362  }
363  if (map.second >= 0) {
364  AMREX_ALWAYS_ASSERT(map.second < static_cast<int>(m_urban_names.size()));
365  }
366  for (int lev = 0; lev < m_nlevs; ++lev) {
367  if (map.first >= 0 && map.first < static_cast<int>(lsm_data_lev[lev].size())) {
369  }
370  if (map.second >= 0 && map.second < static_cast<int>(urban_data_lev[lev].size())) {
372  }
373  }
374  RadiationField field;
375  field.map = map;
376  radiation_output_map[name] = std::move(field);
377  for (auto& fields_at_level : rad_output_fields) { fields_at_level.clear(); }
378 }
Here is the call graph for this function:

◆ register_radiation_outputs()

void SurfaceModel::register_radiation_outputs ( const std::unordered_map< std::string, std::pair< int, int >> &  output_map)

Registers canonical radiation output mappings.

Parameters
output_mapCanonical names mapped to land and urban indices.
382 {
383  for (const auto& entry : output_map) {
384  register_radiation_output(entry.first, entry.second);
385  }
386 }
void register_radiation_output(const std::string &name, const std::pair< int, int > &lsm_urb_map)
Registers a canonical radiation output mapping.
Definition: ERF_SurfaceModel.cpp:350

◆ release_transient_surface_outputs()

void SurfaceModel::release_transient_surface_outputs ( )
inlineprivate

Releases surface outputs that have no persistent consumer.

1046  {
1047  if (m_surface_outputs_enabled) { return; }
1048  for (int lev = 0; lev < m_nlevs; ++lev) {
1051  continue;
1052  }
1053  m_surface_outputs_requested[lev] = false;
1054  u_star[lev].reset();
1055  t_star[lev].reset();
1056  q_star[lev].reset();
1057  t_surf[lev].reset();
1058  }
1059  }
bool m_surface_layer_outputs_enabled
Definition: ERF_SurfaceModel.H:1103
bool m_surface_outputs_enabled
Definition: ERF_SurfaceModel.H:1102

◆ request_surface_layer_outputs()

void SurfaceModel::request_surface_layer_outputs ( )
inline

Enables blended surface outputs needed by the SurfaceLayer.

409  {
411  for (int lev = 0; lev < m_nlevs; ++lev) {
413  m_surface_outputs_requested[lev] = true;
415  }
416  }
417  }
Here is the call graph for this function:

◆ request_surface_outputs()

void SurfaceModel::request_surface_outputs ( const bool  persistent = true)
inline

Enables and materializes the surface outputs consumed by ERF.

397  {
399  for (int lev = 0; lev < m_nlevs; ++lev) {
400  m_surface_outputs_requested[lev] = true;
402  }
403  }
Here is the call graph for this function:

◆ resize_levels()

void SurfaceModel::resize_levels ( int  nlevs)
inlineprivate

Sets the number of AMR levels and resizes all per-level storage to match.

Shared by the constructor, initialize_for_level and clear_level so that every per-level member is grown and shrunk together. New levels start empty.

Parameters
nlevsNew number of AMR levels.
943  {
944  m_nlevs = nlevs;
945 
946  u_star.resize(m_nlevs);
947  t_star.resize(m_nlevs);
948  q_star.resize(m_nlevs);
949  t_surf.resize(m_nlevs);
950 
951  wavg.resize(m_nlevs);
953 
954  m_dmap.resize(m_nlevs);
955  m_ba.resize(m_nlevs);
956  m_ba2d.resize(m_nlevs);
957  m_geom.resize(m_nlevs);
958  m_geom2d.resize(m_nlevs);
959  m_lmask.resize(m_nlevs);
960 
961  urban_frac_lev.resize(m_nlevs);
962  lsm_data_lev.resize(m_nlevs);
963  urban_data_lev.resize(m_nlevs);
966 
967  rad_fields.resize(m_nlevs);
968  rad_output_fields.resize(m_nlevs);
970  m_last_urban_frac.resize(m_nlevs, nullptr);
971 
972  for (auto& field_lev : fields) { field_lev.resize(m_nlevs); }
973  for (auto& entry : fieldmap) {
974  entry.second.lsm_ptr.resize(m_nlevs, nullptr);
975  entry.second.urb_ptr.resize(m_nlevs, nullptr);
976  }
977  for (auto& entry : radiation_input_map) { entry.second.weighted.resize(m_nlevs); }
978  }
amrex::Vector< amrex::MultiFab * > urban_frac_lev
Definition: ERF_SurfaceModel.H:1088

Referenced by clear_level(), initialize_for_level(), and SurfaceModel().

Here is the caller graph for this function:

◆ set_field_map_pointers()

void SurfaceModel::set_field_map_pointers ( const std::string &  name,
int  lev,
amrex::MultiFab *  lsm_mf,
amrex::MultiFab *  urban_mf 
)

Updates a pointer-based field mapping for one level.

Parameters
nameCommon name of the mapped field.
levAMR level to update.
lsm_mfLand-model field pointer, or nullptr.
urban_mfUrban-model field pointer, or nullptr.
632 {
633  auto field_it = fieldmap.find(name);
634  AMREX_ALWAYS_ASSERT(field_it != fieldmap.end());
635 
636  Field& field = field_it->second;
637  AMREX_ALWAYS_ASSERT(field.map.first == -1 && field.map.second == -1);
638  if (static_cast<int>(field.lsm_ptr.size()) < m_nlevs) {
639  field.lsm_ptr.resize(m_nlevs, nullptr);
640  field.urb_ptr.resize(m_nlevs, nullptr);
641  }
643  field.lsm_ptr[lev] = lsm_mf;
644  field.urb_ptr[lev] = urban_mf;
645 }
Here is the call graph for this function:

◆ set_model_data()

void SurfaceModel::set_model_data ( const int  lev,
const amrex::Vector< amrex::MultiFab * >  model_data,
const amrex::Vector< std::string > &  data_names,
SurfaceModelType  type 
)
inline

Registers model variables used in weighted averaging.

Parameters
levAMR level associated with the data.
model_dataPointers to the model variables.
data_namesNames corresponding to model_data.
typeWhether the data belong to the land or urban model.
208  {
209  if (type == SurfaceModelType::LAND) {
210  lsm_data_lev[lev].resize(model_data.size());
211  weighted_lsm_data_lev[lev].clear();
212  weighted_lsm_data_lev[lev].resize(model_data.size());
213  if (lev == 0) {
214  // only set names on first level, since they are the same for all levels
215  m_lsm_names.resize(model_data.size());
216  AMREX_ALWAYS_ASSERT(data_names.size() == model_data.size());
217  for (int i = 0; i < static_cast<int>(data_names.size()); ++i) {
218  m_lsm_names[i] = data_names[i];
219  }
220  }
221 
222  for (int i = 0; i < static_cast<int>(lsm_data_lev[lev].size()); ++i) {
223  AMREX_ALWAYS_ASSERT(model_data[i]);
224  lsm_data_lev[lev][i] = model_data[i];
225  }
226  m_use_land = true;
228  for (auto& fields_at_level : rad_fields) { fields_at_level.clear(); }
229  for (auto& fields_at_level : rad_output_fields) { fields_at_level.clear(); }
230  for (auto& entry : radiation_input_map) {
231  if (lev < static_cast<int>(entry.second.weighted.size())) {
232  entry.second.weighted[lev].reset();
233  }
234  }
235  } else if (type == SurfaceModelType::URBAN) {
236  urban_data_lev[lev].resize(model_data.size());
237  weighted_urban_data_lev[lev].clear();
238  weighted_urban_data_lev[lev].resize(model_data.size());
239  if (lev == 0) {
240  // only set names on first level, since they are the same for all levels
241  m_urban_names.resize(model_data.size());
242  AMREX_ALWAYS_ASSERT(data_names.size() == model_data.size());
243  for (int i = 0; i < static_cast<int>(data_names.size()); ++i) {
244  m_urban_names[i] = data_names[i];
245  }
246  }
247  for (int i = 0; i < static_cast<int>(urban_data_lev[lev].size()); ++i) {
248  AMREX_ALWAYS_ASSERT(model_data[i]);
249  urban_data_lev[lev][i] = model_data[i];
250  }
251  m_use_urban = true;
253  for (auto& fields_at_level : rad_fields) { fields_at_level.clear(); }
254  for (auto& fields_at_level : rad_output_fields) { fields_at_level.clear(); }
255  for (auto& entry : radiation_input_map) {
256  if (lev < static_cast<int>(entry.second.weighted.size())) {
257  entry.second.weighted[lev].reset();
258  }
259  }
260  }
261  }
void update_provider_mode(const int lev)
Updates the provider mode after model data are registered.
Definition: ERF_SurfaceModel.H:984
Here is the call graph for this function:

◆ set_model_fields()

void SurfaceModel::set_model_fields ( SurfaceModelType  type,
const amrex::Vector< int > &  field_indices,
const bool  use_fluxes = true 
)
inline

Selects the model fields that participate in weighted averaging.

When using fluxes, the first five elements map to u-stress, v-stress, heat flux, vapor flux, and surface temperature. Otherwise, the first four elements map to ustar, tstar, qstar, and surface temperature. A field index of -1 skips that field.

Parameters
typeWhether the fields belong to the land or urban model.
field_indicesIndices of the fields to average.
use_fluxesWhether the selected fields are fluxes.
317  {
318  const int nfields = static_cast<int>(field_indices.size());
319  if (!use_fluxes) {
320  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(nfields >= 4, "Must have at least four fields to average (ustar, tstar, qstar, tsurf)");
321  } else {
322  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(nfields >= 5, "Must have at least five fields to average (u-stress, v-stress, hfx, qfx, tsurf)");
323  }
324 
325  // Latch the export mode off the first model that registers, then make sure every
326  // subsequent model agrees: either all of them supply fluxes, or all of them supply
327  // u*, t*, q* directly. Taking the mode from the caller rather than assuming the
328  // default is what makes the non-flux path reachable at all.
329  if (!m_export_fluxes_set) {
330  m_export_fluxes = use_fluxes;
331  m_export_fluxes_set = true;
332  }
334  "All registered surface models must export either fluxes or u*/t*/q*, not a mix");
335 
336  const int nregistered = (type == SurfaceModelType::LAND)
337  ? static_cast<int>(m_lsm_names.size())
338  : static_cast<int>(m_urban_names.size());
339  for (const int field : field_indices) {
341  field == -1 || (field >= 0 && field < nregistered),
342  "Model field index must be -1 or within the registered provider data range");
343  }
344 
345  if (type == SurfaceModelType::LAND) {
346  lsm_fields = amrex::Vector<int>(field_indices);
348  for (auto& fields_at_level : weighted_lsm_data_lev) {
349  fields_at_level.clear();
350  }
351  } else if (type == SurfaceModelType::URBAN) {
352  urban_fields = amrex::Vector<int>(field_indices);
354  for (auto& fields_at_level : weighted_urban_data_lev) {
355  fields_at_level.clear();
356  }
357  }
358  }
bool m_export_fluxes_set
Definition: ERF_SurfaceModel.H:1067
Here is the call graph for this function:

◆ set_model_fluxes()

void SurfaceModel::set_model_fluxes ( const int  lev,
const amrex::Vector< amrex::MultiFab * >  model_fluxes,
const amrex::Vector< std::string > &  flux_names,
SurfaceModelType  type 
)
inline

Registers model fluxes as additional weighted-average inputs.

Parameters
levAMR level associated with the fluxes.
model_fluxesPointers to the model flux fields.
flux_namesNames corresponding to model_fluxes.
typeWhether the fluxes belong to the land or urban model.
273  {
274  amrex::Vector<amrex::MultiFab*>* model_data = nullptr;
275  amrex::Vector<std::string>* model_names = nullptr;
276 
277  if (type == SurfaceModelType::LAND) {
278  model_data = &lsm_data_lev[lev];
279  model_names = &m_lsm_names;
280  } else if (type == SurfaceModelType::URBAN) {
281  model_data = &urban_data_lev[lev];
282  model_names = &m_urban_names;
283  }
284 
285  AMREX_ALWAYS_ASSERT(model_data != nullptr);
286  AMREX_ALWAYS_ASSERT(model_names != nullptr);
287  AMREX_ALWAYS_ASSERT(flux_names.size() == model_fluxes.size());
288 
289  const int data_size = static_cast<int>(model_data->size());
290  model_data->resize(data_size + static_cast<int>(model_fluxes.size()));
291  if (lev == 0) {
292  model_names->resize(data_size + static_cast<int>(model_fluxes.size()));
293  }
294 
295  for (int i = 0; i < static_cast<int>(model_fluxes.size()); ++i) {
296  AMREX_ALWAYS_ASSERT(model_fluxes[i]);
297  (*model_data)[data_size + i] = model_fluxes[i];
298  if (lev == 0) {
299  (*model_names)[data_size + i] = flux_names[i];
300  }
301  }
302  }
Here is the call graph for this function:

◆ update_provider_mode()

void SurfaceModel::update_provider_mode ( const int  lev)
inlineprivate

Updates the provider mode after model data are registered.

Parameters
levAMR level whose provider mode should be updated.
985  {
986  const bool has_land = !lsm_data_lev[lev].empty();
987  const bool has_urban = !urban_data_lev[lev].empty();
988  if (has_land && has_urban) {
992  m_surface_outputs_requested[lev] = true;
994  }
995  } else if (has_land) {
997  wavg[lev].reset();
998  } else if (has_urban) {
1000  wavg[lev].reset();
1001  } else {
1003  }
1004  }

Referenced by set_model_data().

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

◆ validate_radiation_output_layout()

void SurfaceModel::validate_radiation_output_layout ( int  lev,
const amrex::MultiFab *  mf 
) const

Validates the layout contract for a canonical radiation output.

Parameters
levAMR level associated with the destination.
mfRadiation output destination to validate.
430 {
431  if (mf == nullptr) { return; }
432  BoxList horizontal_boxes = mf->boxArray().boxList();
433  // include the ghost cells here for SLM: surface values are exchanged at
434  // k = 0 which is a ghost cell for SLM.
435  const int k_grow = mf->nGrowVect()[2];
436  for (Box& box : horizontal_boxes) {
438  box.smallEnd(2) <= 0 && box.bigEnd(2) + k_grow >= 0,
439  "Radiation output destination must contain the k=0 surface plane "
440  "in its valid or ghost region");
441  box.setRange(2, 0);
442  }
443  const BoxArray horizontal_ba(std::move(horizontal_boxes));
445  horizontal_ba == m_ba2d[lev] && mf->DistributionMap() == m_dmap[lev],
446  "Radiation output destination must match the level horizontal layout");
447 }
Here is the call graph for this function:

◆ weight_average_fields()

void SurfaceModel::weight_average_fields ( int  lev,
amrex::MultiFab * const   
)

Applies the current land and urban weights to selected model fields.

Parameters
levAMR level to update.
urban_fracUrban fraction used to compute the weights.
690 {
691  const SurfaceProviderMode mode = m_provider_mode[lev];
692  const bool use_land = mode == SurfaceProviderMode::LandOnly ||
694  const bool use_urban = mode == SurfaceProviderMode::UrbanOnly ||
696 
697  for (auto &field : fieldmap)
698  {
699  if (!field.second.active) { continue; }
700  int mf_idx = field.second.mf_ind;
701  AMREX_ASSERT(mf_idx != -1);
702 
703  int lsm_idx = field.second.map.first;
704  int urb_idx = field.second.map.second;
705 
706  // whether we have a valid LSM multifab
707  bool valid_land = (use_land &&
708  lsm_idx != -1 &&
709  lsm_data_lev[lev][lsm_idx]);
710 
711  // whether we have a valid urban multifab
712  bool valid_urban = (use_urban &&
713  urb_idx != -1 &&
714  urban_data_lev[lev][urb_idx]);
715 
716  bool use_mf = false;
717  if (lsm_idx == -1 && urb_idx == -1) {
718  // use explicit MF ptrs rather than indices
719  use_mf = true;
720  valid_land = (use_land && field.second.lsm_ptr[lev]);
721  valid_urban = (use_urban && field.second.urb_ptr[lev]);
722  }
723 
724  for (MFIter mfi(*fields[mf_idx][lev], TileNoZ()); mfi.isValid(); ++mfi)
725  {
726  Box tbx = mfi.tilebox();
727  const auto weights_arr = (mode == SurfaceProviderMode::Both)
728  ? wavg[lev]->const_array(mfi) : Array4<const Real>{};
729 
730  // Calculate weight average into output
731  auto output_arr = fields[mf_idx][lev]->array(mfi);
732  const amrex::MultiFab *lsm_mf = (use_mf) ? field.second.lsm_ptr[lev] : (lsm_idx != -1 ? lsm_data_lev[lev][lsm_idx] : nullptr);
733  const amrex::MultiFab *urb_mf = (use_mf) ? field.second.urb_ptr[lev] : (urb_idx != -1 ? urban_data_lev[lev][urb_idx] : nullptr);
734 
735  auto lsm_data_arr = (valid_land) ? lsm_mf->const_array(mfi) : Array4<const Real>{};
736  auto urban_data_arr = (valid_urban) ? urb_mf->const_array(mfi) : Array4<const Real>{};
737 
738  if (valid_land && !valid_urban) {
739  // use solely land value
740  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
741  {
742  output_arr(i, j, k) = lsm_data_arr(i, j, k);
743  });
744  } else if (!valid_land && valid_urban) {
745  // use solely urban value
746  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
747  {
748  output_arr(i, j, k) = urban_data_arr(i, j, k);
749  });
750  } else {
751  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
752  {
753  Real land = (lsm_data_arr) ? lsm_data_arr(i, j, k) * weights_arr(i, j, 0, SurfaceModelType::LAND) : 0.0;
754  Real urb = (urban_data_arr) ? urban_data_arr(i, j, k) * weights_arr(i, j, 0, SurfaceModelType::URBAN) : 0.0;
755 
756  output_arr(i, j, k) = land + urb;
757  });
758  }
759  }
760  if (field.second.fill_bound) {
761  fields[mf_idx][lev]->FillBoundary(m_geom[lev].periodicity());
762  }
763  //outputs[output_field]->FillBoundary(comp, 1, m_geom[lev].periodicity());
764  }
765 }
Here is the call graph for this function:

◆ weight_model_field()

void SurfaceModel::weight_model_field ( int  lev,
const amrex::MultiFab *  source,
amrex::MultiFab *  weighted,
SurfaceModelType  type 
)

Writes a weighted copy of a model field.

Parameters
levAMR level whose weights are used.
sourceModel-owned source field.
weightedSurfaceModel-owned destination field.
typeProvider type owning the source field.
46 {
47  AMREX_ASSERT(source != nullptr);
48  AMREX_ASSERT(weighted != nullptr);
49 
50  for (MFIter mfi(*source, TileNoZ()); mfi.isValid(); ++mfi)
51  {
52  Box tbx = mfi.tilebox();
53  const auto source_arr = source->const_array(mfi);
54  auto weighted_arr = weighted->array(mfi);
55  const bool use_weights = m_provider_mode[lev] == SurfaceProviderMode::Both;
56  const auto weights_arr = use_weights
57  ? wavg[lev]->const_array(mfi) : Array4<const Real>{};
58 
59  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
60  {
61  weighted_arr(i, j, k) = use_weights
62  ? source_arr(i, j, k) * weights_arr(i, j, 0, type)
63  : source_arr(i, j, k);
64  });
65  }
66 
67  weighted->FillBoundary(m_geom[lev].periodicity());
68 }
Here is the call graph for this function:

◆ write_output()

void SurfaceModel::write_output ( const int &  finest_lev,
const amrex::Real &  time,
const std::string &  plot_prefix,
const amrex::Vector< int > &  level_steps,
const amrex::Vector< amrex::IntVect > &  ref_ratio 
)

Writes registered surface-model fields to plotfile output.

Parameters
finest_levFinest AMR level to write.
timeSimulation time associated with the output.
plot_prefixOutput plotfile prefix.
level_stepsNumber of steps represented at each level.
ref_ratioRefinement ratios between adjacent levels.
769 {
772  std::string plotfilename = amrex::Concatenate(plot_prefix + "2D_", level_steps[0], 5);
773 
774  const int nfields = (m_export_fluxes) ? 5 : 4;
775  // Surface outputs, land mask, urban fraction, and mapped fields.
776  const int noutput = nfields + 2 + fieldmap.size();
777  IntVect ng(0, 0, 0);
778 
779  amrex::Vector<std::string> varnames(nfields);
780 
781  amrex::Vector<amrex::MultiFab> fab(finest_lev+1);
782  for (int lev = 0; lev <= finest_lev; lev++) {
784  amrex::MultiFab* const outputs[] = {u_star[lev].get(), t_star[lev].get(), q_star[lev].get(), t_surf[lev].get()};
785  fab[lev].define(outputs[0]->boxArray(), m_dmap[lev], noutput, ng);
786 
787  //fab[lev].setVal(0.0);
788 
789  // Output weighted surface fluxes into ustar, tstar, qstar and surface temperature into tsurf
790  // TODO: make sure grids of urban and LSM inputs match
791  for (int field=0; field < nfields; field++)
792  {
793  int output_field = (m_export_fluxes && field > 0) ? field - 1 : field;
794  int comp = (m_export_fluxes && field < 2) ? field : 0;
795 
796  MultiFab::Copy(fab[lev], *(outputs[output_field]), comp, field, 1, ng);
797 
798  varnames[field] = field_names[field];
799  }
800 
801  // The outputs hold lsm_undefined where no provider gives a valid value (water, an
802  // unprocessed cell, u_star component 1 in non-flux mode), which consumers test for.
803  // Plot 0 there instead, as before the outputs started at the sentinel.
804  for (MFIter mfi(fab[lev], TileNoZ()); mfi.isValid(); ++mfi) {
805  const auto out = fab[lev].array(mfi);
806  ParallelFor(mfi.tilebox(), nfields,
807  [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
808  {
809  if (!is_valid_lsm_value(out(i,j,k,n))) { out(i,j,k,n) = 0.0; }
810  });
811  }
812 
813  int nout = nfields;
814 
815  MultiFab lmask_tmp = amrex::ToMultiFab(*m_lmask[lev]); // iMultiFab -> MultiFab
816  MultiFab::Copy(fab[lev], lmask_tmp, 0, nout, 1, ng);
817  nout++;
818  MultiFab::Copy(fab[lev], *get_wavg_factors(lev), SurfaceModelType::URBAN, nout, 1, ng);
819  nout++;
820 
821  if (lev == 0) {
822  varnames.push_back("lmask");
823  varnames.push_back("urb_frac");
824  }
825 
826  // Add any mapped fields
827  for (auto &field : fieldmap) {
828  MultiFab::Copy(fab[lev], *(fields[field.second.mf_ind][lev]), 0, nout, 1, ng);
829  if (lev == 0) {
830  varnames.push_back(field.first);
831  }
832  nout++;
833  }
834 
835  AMREX_ALWAYS_ASSERT(varnames.size() == noutput);
836  }
837 
838  amrex::WriteMultiLevelPlotfile(plotfilename, finest_lev+1, GetVecOfConstPtrs(fab), varnames, m_geom2d, time, level_steps, ref_ratio);
841 }
amrex::MultiFab * get_wavg_factors(const int &lev)
Returns the land and urban weighting factors for a level.
Definition: ERF_SurfaceModel.H:559
void calculate_weight_average(int lev, amrex::MultiFab *const urban_frac, bool update_derived=true)
Computes land and urban weights and applies them to registered fields.
Definition: ERF_SurfaceModel.cpp:71
static const std::vector< std::string > field_names
Definition: ERF_SurfaceModel.H:1164
Here is the call graph for this function:

◆ WriteCheckpoint()

void SurfaceModel::WriteCheckpoint ( const std::string &  checkpointname)

Writes surface-model state to a checkpoint file.

Parameters
checkpointnameCheckpoint file name.
853 {
856  auto check_start = amrex::second();
857 
858  // write header
859  if (ParallelDescriptor::IOProcessor()) {
860 
861  amrex::Print() << " Writing SurfaceModel checkpoint " << std::endl;
862 
863  std::string HeaderFileName(checkpointname + "/SurfaceModel_Header");
864  VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
865  std::ofstream HeaderFile;
866  HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
867  HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
868  std::ofstream::trunc |
869  std::ofstream::binary);
870  if(! HeaderFile.good()) {
871  FileOpenFailed(HeaderFileName);
872  }
873 
874  HeaderFile.precision(17);
875 
876  // write out title line
877  HeaderFile << "Checkpoint file for SurfaceModel\n";
878 
879  // write out number of levels
880  HeaderFile << m_nlevs << "\n";
881 
882  // write out flags
883  HeaderFile << m_use_urban << "\n";
884  HeaderFile << m_use_land << "\n";
885  HeaderFile << m_export_fluxes << "\n";
886  HeaderFile << m_weights_updated << "\n";
887  HeaderFile << m_fields_are_valid << "\n";
888  HeaderFile << "\n";
889 
890  // Write box arrays
891  for (int lev = 0; lev < m_nlevs; lev++) {
892  m_ba[lev].writeOn(HeaderFile);
893  HeaderFile << '\n';
894 
895  }
896  HeaderFile << '\n';
897  for (int lev = 0; lev < m_nlevs; lev++) {
898  m_ba2d[lev].writeOn(HeaderFile);
899  HeaderFile << '\n';
900  }
901  HeaderFile << '\n';
902 
903  // Write out fields
904  // LSM fields
905  for (int i = 0; i < static_cast<int>(lsm_fields.size()); ++i) {
906  HeaderFile << lsm_fields[i] << " ";
907  }
908  HeaderFile << '\n';
909 
910  // Urban fields
911  for (int i = 0; i < static_cast<int>(urban_fields.size()); ++i) {
912  HeaderFile << urban_fields[i] << " ";
913  }
914  HeaderFile << '\n';
915 
916  // Field mapping
917  HeaderFile << '\n';
918  HeaderFile << fieldmap.size() << "\n";
919  for (auto &field : fieldmap) {
920  // pointer fields are reconstructed at load
921  HeaderFile << field.first << " " << field.second.mf_ind << " " << field.second.map.first << " " << field.second.map.second << " " << field.second.fill_bound << '\n';
922  }
923  HeaderFile << '\n';
924  }
925 
926  amrex::ParallelDescriptor::Barrier();
927 
928  const std::string prefix = "SurfaceModel_";
929 
930  // Radiation input fields are derived from provider data and are intentionally
931  // rebuilt after restart rather than written to the checkpoint.
932  for (int lev = 0; lev < m_nlevs; lev++) {
933  IntVect ng(1,1,0);
935 
936  {
937  MultiFab mf(m_ba2d[lev],m_dmap[lev],2,ng);
938  MultiFab::Copy(mf,*u_star[lev],0,0,2,ng);
939  VisMF::Write(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "ustar"));
940 
941  MultiFab::Copy(mf,*get_wavg_factors(lev),0,0,2,ng);
942  VisMF::Write(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "wavg"));
943  }
944 
945  MultiFab mf(m_ba2d[lev],m_dmap[lev],1,ng);
946 
947  MultiFab::Copy(mf,*t_star[lev],0,0,1,ng);
948  VisMF::Write(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "tstar"));
949 
950  MultiFab::Copy(mf,*q_star[lev],0,0,1,ng);
951  VisMF::Write(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "qstar"));
952 
953  MultiFab::Copy(mf,*t_surf[lev],0,0,1,ng);
954  VisMF::Write(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "tsurf"));
955 
956  for (auto &field : fieldmap) {
957  MultiFab::Copy(mf, *(fields[field.second.mf_ind][lev]), 0, 0, 1, ng);
958  VisMF::Write(mf, MultiFabFileFullPrefix(lev, checkpointname, "Level_", prefix + "_f_" + field.first));
959  }
960  }
961 
962  auto check_end = amrex::second() - check_start;
965  ParallelDescriptor::ReduceRealMax(check_end,ParallelDescriptor::IOProcessorNumber());
966  amrex::Print() << " SurfaceModel Checkpoint write time = " << check_end << " seconds." << '\n';
967 }

Member Data Documentation

◆ field_names

const std::vector<std::string> SurfaceModel::field_names
inlinestaticprivate
Initial value:
= {
"uflux",
"vflux",
"hfx",
"qfx",
"tskin",
}

◆ fieldmap

std::unordered_map<std::string, Field> SurfaceModel::fieldmap
private

◆ fields

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > SurfaceModel::fields
private

◆ lsm_data_lev

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceModel::lsm_data_lev
private

◆ lsm_fields

amrex::Vector<int> SurfaceModel::lsm_fields
private

◆ m_ba

amrex::Vector<amrex::BoxArray> SurfaceModel::m_ba
private

◆ m_ba2d

amrex::Vector<amrex::BoxArray> SurfaceModel::m_ba2d
private

◆ m_dmap

amrex::Vector<amrex::DistributionMapping> SurfaceModel::m_dmap
private

◆ m_export_fluxes

bool SurfaceModel::m_export_fluxes = true
private

◆ m_export_fluxes_set

bool SurfaceModel::m_export_fluxes_set = false
private

Referenced by set_model_fields().

◆ m_fields_are_valid

bool SurfaceModel::m_fields_are_valid = false
private

◆ m_geom

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

◆ m_geom2d

amrex::Vector<amrex::Geometry> SurfaceModel::m_geom2d
private

◆ m_last_urban_frac

amrex::Vector<amrex::MultiFab*> SurfaceModel::m_last_urban_frac
private

Referenced by resize_levels().

◆ m_lmask

amrex::Vector<amrex::iMultiFab*> SurfaceModel::m_lmask
private

◆ m_lsm_names

amrex::Vector<std::string> SurfaceModel::m_lsm_names
private

◆ m_nlevs

◆ m_output_fields_registered

amrex::GpuArray<bool, 2> SurfaceModel::m_output_fields_registered {{false, false}}
private

Referenced by set_model_fields(), and SurfaceModel().

◆ m_provider_mode

◆ m_surface_layer_outputs_enabled

bool SurfaceModel::m_surface_layer_outputs_enabled = false
private

◆ m_surface_outputs_enabled

bool SurfaceModel::m_surface_outputs_enabled = false
private

◆ m_surface_outputs_requested

amrex::Vector<int> SurfaceModel::m_surface_outputs_requested
private

◆ m_urban_names

amrex::Vector<std::string> SurfaceModel::m_urban_names
private

◆ m_use_land

bool SurfaceModel::m_use_land = false
private

Referenced by set_model_data().

◆ m_use_urban

bool SurfaceModel::m_use_urban = false
private

Referenced by set_model_data().

◆ m_weights_updated

bool SurfaceModel::m_weights_updated = false
private

◆ q_star

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

◆ rad_fields

amrex::Vector<amrex::Vector<const amrex::MultiFab*> > SurfaceModel::rad_fields
private

◆ rad_output_fields

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceModel::rad_output_fields
private

◆ rad_output_names

const std::vector<std::string> SurfaceModel::rad_output_names
inlinestaticprivate
Initial value:
= {
"cos_zenith_angle", "sw_flux_dn", "sw_flux_dn_dir_vis",
"sw_flux_dn_dir_nir", "sw_flux_dn_dif_vis", "sw_flux_dn_dif_nir",
"lw_flux_dn"}

◆ radiation_input_map

std::unordered_map<std::string, RadiationField> SurfaceModel::radiation_input_map
private

◆ radiation_output_map

std::unordered_map<std::string, RadiationField> SurfaceModel::radiation_output_map
private

◆ radnames

const std::vector<std::string> SurfaceModel::radnames = {"tskin", "emiss", "albedo_vis", "albedo_nir", "albedo_vis_diff", "albedo_nir_diff"}
inlinestaticprivate

◆ t_star

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

◆ t_surf

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

◆ u_star

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

◆ urban_data_lev

amrex::Vector<amrex::Vector<amrex::MultiFab*> > SurfaceModel::urban_data_lev
private

◆ urban_fields

amrex::Vector<int> SurfaceModel::urban_fields
private

◆ urban_frac_lev

amrex::Vector<amrex::MultiFab*> SurfaceModel::urban_frac_lev
private

Referenced by resize_levels().

◆ wavg

amrex::Vector<std::unique_ptr<amrex::MultiFab> > SurfaceModel::wavg
private

◆ weighted_lsm_data_lev

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > SurfaceModel::weighted_lsm_data_lev
private

◆ weighted_urban_data_lev

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > SurfaceModel::weighted_urban_data_lev
private

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