Skip to content

Commit

Permalink
Merge branch 'bartgol/eamxx/dump-fields-dictionary' (PR #6842)
Browse files Browse the repository at this point in the history
The option (off by default) allows to save a yaml file containing a dictionary of the fields on the "Physics" grid, with some of their details.
  • Loading branch information
bartgol authored Dec 17, 2024
2 parents 8818556 + 7eb5d2c commit e58531e
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 107 deletions.
1 change: 1 addition & 0 deletions components/eamxx/cime_config/namelist_defaults_scream.xml
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ be lost if SCREAM_HACK_XML is not enabled.
<!-- driver_options options for scream -->
<driver_options>
<atmosphere_dag_verbosity_level>0</atmosphere_dag_verbosity_level>
<save_field_manager_dictionary type="logical">false</save_field_manager_dictionary>
<atm_log_level type="string"
valid_values="trace,debug,info,warn,error"
doc="Verbosity level for the atm logger">
Expand Down
41 changes: 41 additions & 0 deletions components/eamxx/src/control/atmosphere_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,47 @@ void AtmosphereDriver::create_fields()

m_ad_status |= s_fields_created;

// If the user requested it, we can save a dictionary of the FM fields to file
auto& driver_options_pl = m_atm_params.sublist("driver_options");
if (driver_options_pl.get("save_field_manager_content",false)) {
auto pg = m_grids_manager->get_grid("Physics");
const auto& fm = m_field_mgrs.at(pg->name());
ekat::ParameterList pl_out("field_manager_content");
pl_out.sublist("provenance") = m_atm_params.sublist("provenance");
DefaultMetadata std_names;
std::string desc;
desc = "content of the EAMxx FieldManager corresponding to the 'Physics' grid.\n"
"The dict keys are the field names as used in EAMxx.\n"
"For each field, we add the following entries:\n"
" - standard_name: the name commonly used to refer to this field in atm sciences (if applicable)\n"
" - units: the units for this field used in EAMxx\n"
" - layout: the names of the dimensions for this field (time excluded)\n"
" - providers: the atm processes that update/compute this field\n"
" - customers: the atm processes that require this field as an input\n";
pl_out.set("description", desc);
auto& dict = pl_out.sublist("fields");
for (const auto& it : *fm) {
const auto& fid = it.second->get_header().get_identifier();
auto& pl = dict.sublist(fid.name());

pl.set("units",fid.get_units().to_string());
pl.set("layout",fid.get_layout().names());
pl.set("standard_name",std_names.get_standardname(fid.name()));
std::vector<std::string> providers,customers;
const auto& track = it.second->get_header().get_tracking();
for (auto ap : track.get_providers()) {
providers.push_back(ap.lock()->name());
}
for (auto ap : track.get_customers()) {
customers.push_back(ap.lock()->name());
}
pl.set("providers",providers);
pl.set("customers",customers);
}

ekat::write_yaml_file("eamxx_field_manager_content.yaml",pl_out);
}

stop_timer("EAMxx::create_fields");
stop_timer("EAMxx::init");
m_atm_logger->info("[EAMxx] create_fields ... done!");
Expand Down
20 changes: 20 additions & 0 deletions components/eamxx/src/share/atm_process/atmosphere_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ get_field_in_impl(const std::string& field_name, const std::string& grid_name) c
" field name: " + field_name + "\n"
" grid name: " + grid_name + "\n");
}
static Field f;
return f;
}

Field& AtmosphereProcess::
Expand All @@ -917,6 +919,8 @@ get_field_in_impl(const std::string& field_name) const {
" atm proc name: " + this->name() + "\n"
" field name: " + field_name + "\n");
}
static Field f;
return f;
}

Field& AtmosphereProcess::
Expand All @@ -932,6 +936,8 @@ get_field_out_impl(const std::string& field_name, const std::string& grid_name)
" field name: " + field_name + "\n"
" grid name: " + grid_name + "\n");
}
static Field f;
return f;
}

Field& AtmosphereProcess::
Expand All @@ -953,6 +959,8 @@ get_field_out_impl(const std::string& field_name) const {
" atm proc name: " + this->name() + "\n"
" field name: " + field_name + "\n");
}
static Field f;
return f;
}

FieldGroup& AtmosphereProcess::
Expand All @@ -968,6 +976,8 @@ get_group_in_impl(const std::string& group_name, const std::string& grid_name) c
" group name: " + group_name + "\n"
" grid name: " + grid_name + "\n");
}
static FieldGroup g("");
return g;
}

FieldGroup& AtmosphereProcess::
Expand All @@ -989,6 +999,8 @@ get_group_in_impl(const std::string& group_name) const {
" atm proc name: " + this->name() + "\n"
" group name: " + group_name + "\n");
}
static FieldGroup g("");
return g;
}

FieldGroup& AtmosphereProcess::
Expand All @@ -1004,6 +1016,8 @@ get_group_out_impl(const std::string& group_name, const std::string& grid_name)
" group name: " + group_name + "\n"
" grid name: " + grid_name + "\n");
}
static FieldGroup g("");
return g;
}

FieldGroup& AtmosphereProcess::
Expand All @@ -1025,6 +1039,8 @@ get_group_out_impl(const std::string& group_name) const {
" atm proc name: " + this->name() + "\n"
" group name: " + group_name + "\n");
}
static FieldGroup g("");
return g;
}

Field& AtmosphereProcess::
Expand All @@ -1040,6 +1056,8 @@ get_internal_field_impl(const std::string& field_name, const std::string& grid_n
" field name: " + field_name + "\n"
" grid name: " + grid_name + "\n");
}
static Field f;
return f;
}

Field& AtmosphereProcess::
Expand All @@ -1061,6 +1079,8 @@ get_internal_field_impl(const std::string& field_name) const {
" atm proc name: " + this->name() + "\n"
" field name: " + field_name + "\n");
}
static Field f;
return f;
}

void AtmosphereProcess
Expand Down
1 change: 1 addition & 0 deletions components/eamxx/src/share/field/field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class Field {
get_subview_1 (const get_view_type<data_nd_t<T,N>,HD>&, const int) const {
EKAT_ERROR_MSG ("Error! Cannot subview a rank2 view along the second "
"dimension without losing LayoutRight.\n");
return get_view_type<data_nd_t<T,N-1>,HD>();
}

template<HostOrDevice HD,typename T,int N>
Expand Down
1 change: 1 addition & 0 deletions components/eamxx/src/share/field/field_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ auto Field::get_ND_view () const
"MaxRank = 6.\n"
"This should never be called at run time.\n"
"Please contact developer if this functionality is required\n");
return get_view_type<data_nd_t<T,N>,HD>();
}

} // namespace scream
Expand Down
1 change: 1 addition & 0 deletions components/eamxx/src/share/grid/library_grids_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class LibraryGridsManager : public GridsManager
"Error! LibraryGridsManager is not capable of creating remappers.\n"
" - from_grid: " + from_grid->name() + "\n"
" - to_grid: " + to_grid->name() + "\n");
return nullptr;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ create_src_layout (const FieldLayout& tgt_layout) const
// we cannot infer what the corresponding src layout was.
// This function should never be used for this remapper.
EKAT_ERROR_MSG ("Error! VerticalRemapper does not support creating a src layout from a tgt layout.\n");
return FieldLayout();
}

FieldLayout VerticalRemapper::
Expand Down
2 changes: 2 additions & 0 deletions components/eamxx/src/share/io/scorpio_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,8 @@ get_field(const std::string& name, const std::string& mode) const
} else {
EKAT_ERROR_MSG ("ERROR::AtmosphereOutput::get_field Field " + name + " not found in " + mode + " field manager or diagnostics list.");
}
static Field f;
return f;
}
/* ---------------------------------------------------------- */
void AtmosphereOutput::set_diagnostics()
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/scorpio_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "share/field/field_manager.hpp"
#include "share/grid/abstract_grid.hpp"
#include "share/grid/grids_manager.hpp"
#include "share/util//scream_time_stamp.hpp"
#include "share/util/scream_time_stamp.hpp"
#include "share/util/scream_utils.hpp"
#include "share/atm_process/atmosphere_diagnostic.hpp"

#include "ekat/ekat_parameter_list.hpp"
Expand Down
1 change: 1 addition & 0 deletions components/eamxx/src/share/io/scream_io_file_specs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct StorageSpecs {
default:
EKAT_ERROR_MSG ("Error! Unrecognized/unsupported file storage type.\n");
}
return false;
}

void update_storage (const util::TimeStamp& t) {
Expand Down
105 changes: 0 additions & 105 deletions components/eamxx/src/share/io/scream_io_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,111 +75,6 @@ std::string find_filename_in_rpointer (
const OutputAvgType avg_type = OutputAvgType::Instant,
const IOControl& control = {});

struct DefaultMetadata {

std::string get_longname (const std::string& name) {
if (name_2_longname.count(name)>0) {
return name_2_longname.at(name);
} else {
// TODO: Do we want to print a Warning message? I'm not sure if its needed.
return name;
}
}

std::string get_standardname (const std::string& name) {
if (name_2_standardname.count(name)>0) {
return name_2_standardname.at(name);
} else {
// TODO: Do we want to print a Warning message? I'm not sure if its needed.
return name;
}
}

// Create map of longnames, can be added to as developers see fit.
std::map<std::string,std::string> name_2_longname = {
{"lev","hybrid level at midpoints (1000*(A+B))"},
{"ilev","hybrid level at interfaces (1000*(A+B))"},
{"hyai","hybrid A coefficient at layer interfaces"},
{"hybi","hybrid B coefficient at layer interfaces"},
{"hyam","hybrid A coefficient at layer midpoints"},
{"hybm","hybrid B coefficient at layer midpoints"}
};

// Create map of longnames, can be added to as developers see fit.
std::map<std::string,std::string> name_2_standardname = {
{"p_mid" , "air_pressure"},
{"p_mid_at_cldtop" , "air_pressure_at_cloud_top"},
{"T_2m" , "air_temperature"},
{"T_mid" , "air_temperature"},
{"T_mid_at_cldtop" , "air_temperature_at_cloud_top"},
{"aero_g_sw" , "asymmetry_factor_of_ambient_aerosol_particles"},
{"pbl_height" , "atmosphere_boundary_layer_thickness"},
{"precip_liq_surf_mass" , "atmosphere_mass_content_of_liquid_precipitation"},
{"cldlow" , "low_type_cloud_area_fraction"},
{"cldmed" , "medium_type_cloud_area_fraction"},
{"cldhgh" , "high_type_cloud_area_fraction"},
{"cldtot" , "cloud_area_fraction"},
{"cldfrac_tot_at_cldtop" , "cloud_area_fraction"},
{"cldfrac_tot" , "cloud_area_fraction_in_atmosphere_layer"},
{"cldfrac_tot_for_analysis" , "cloud_area_fraction_in_atmosphere_layer"},
{"cldfrac_rad" , "cloud_area_fraction_in_atmosphere_layer"},
{"qi" , "cloud_ice_mixing_ratio"},
{"qc" , "cloud_liquid_water_mixing_ratio"},
{"U" , "eastward_wind"},
{"eff_radius_qi" , "effective_radius_of_cloud_ice_particles"},
{"eff_radius_qc" , "effective_radius_of_cloud_liquid_water_particles"},
{"eff_radius_qc_at_cldtop" , "effective_radius_of_cloud_liquid_water_particles_at_liquid_water_cloud_top"},
{"eff_radius_qr" , "effective_radius_of_cloud_rain_particles"},
{"qv" , "humidity_mixing_ratio"},
{"cldfrac_ice_at_cldtop" , "ice_cloud_area_fraction"},
{"cldfrac_ice" , "ice_cloud_area_fraction_in_atmosphere_layer"},
{"omega" , "lagrangian_tendency_of_air_pressure"},
{"landfrac" , "land_area_fraction"},
{"latitude" , "latitude"},
{"cldfrac_liq_at_cldtop" , "liquid_water_cloud_area_fraction"},
{"cldfrac_liq" , "liquid_water_cloud_area_fraction_in_atmosphere_layer"},
{"longitude" , "longitude"},
{"rainfrac" , "mass_fraction_of_liquid_precipitation_in_air"},
{"V" , "northward_wind"},
{"nc" , "number_concentration_of_cloud_liquid_water_particles_in_air"},
{"cdnc_at_cldtop" , "number_concentration_of_cloud_liquid_water_particles_in_air_at_liquid_water_cloud_top"},
{"ni" , "number_concentration_of_ice_crystals_in_air"},
{"aero_tau_sw" , "optical_thickness_of_atmosphere_layer_due_to_ambient_aerosol_particles"},
{"aero_tau_lw" , "optical_thickness_of_atmosphere_layer_due_to_ambient_aerosol_particles"},
{"aero_ssa_sw" , "single_scattering_albedo_in_air_due_to_ambient_aerosol_particles"},
{"sunlit" , "sunlit_binary_mask"},
{"ps" , "surface_air_pressure"},
{"LW_flux_dn_at_model_bot" , "surface_downwelling_longwave_flux_in_air"},
{"SW_flux_dn_at_model_bot" , "surface_downwelling_shortwave_flux_in_air"},
{"SW_clrsky_flux_dn_at_model_bot" , "surface_downwelling_shortwave_flux_in_air_assuming_clear_sky"},
{"phis" , "surface_geopotential"},
{"surf_radiative_T" , "surface_temperature"},
{"surf_sens_flux" , "surface_upward_sensible_heat_flux"},
{"SW_flux_dn_at_model_top" , "toa_incoming_shortwave_flux"},
{"LW_flux_up_at_model_top" , "toa_outgoing_longwave_flux"},
{"LW_clrsky_flux_up_at_model_top" , "toa_outgoing_longwave_flux_assuming_clear_sky"},
{"surf_evap" , "water_evapotranspiration_flux"},
{"AtmosphereDensity" , "air_density"},
{"PotentialTemperature" , "air_potential_temperature"},
{"SeaLevelPressure" , "air_pressure_at_mean_sea_level"},
{"IceWaterPath" , "atmosphere_mass_content_of_cloud_ice"},
{"LiqWaterPath" , "atmosphere_mass_content_of_cloud_liquid_water"},
{"VapWaterPath" , "atmosphere_mass_content_of_water_vapor"},
{"AerosolOpticalDepth550nm" , "atmosphere_optical_thickness_due_to_ambient_aerosol_particles"},
{"Exner" , "dimensionless_exner_function"},
{"z_mid" , "geopotential_height"},
{"geopotential_mid" , "geopotential_height"},
{"RelativeHumidity" , "relative_humidity"},
{"surface_upward_latent_heat_flux" , "surface_upward_latent_heat_flux"},
{"LongwaveCloudForcing" , "toa_longwave_cloud_radiative_effect"},
{"ShortwaveCloudForcing" , "toa_shortwave_cloud_radiative_effect"},
{"VirtualTemperature" , "virtual_temperature"},
{"VaporFlux" , "water_evapotranspiration_flux"},
{"wind_speed" , "wind_speed"}
};

};

// Shortcut to write/read to/from YYYYMMDD/HHMMSS attributes in the NC file
void write_timestamp (const std::string& filename, const std::string& ts_name,
const util::TimeStamp& ts, const bool write_nsteps = false);
Expand Down
1 change: 1 addition & 0 deletions components/eamxx/src/share/io/scream_scorpio_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ int nctype (const std::string& type) {
} else {
EKAT_ERROR_MSG ("Error! Unrecognized/unsupported data type '" + type + "'.\n");
}
return -1;
}

template<typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ PropertyCheck::ResultAndMsg FieldNaNCheck::check() const {
"Internal error in FieldNaNCheck: unsupported field data type.\n"
"You should not have reached this line. Please, contact developers.\n");
}
return ResultAndMsg{};
}

} // namespace scream
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ PropertyCheck::ResultAndMsg FieldWithinIntervalCheck::check() const {
"Internal error in FieldWithinIntervalCheck: unsupported field data type.\n"
"You should not have reached this line. Please, contact developers.\n");
}
return ResultAndMsg{};
}

template<typename ST>
Expand Down
2 changes: 2 additions & 0 deletions components/eamxx/src/share/util/scream_data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ inline std::string e2str (const DataType data_type) {
default:
EKAT_ERROR_MSG("Error! Unsupported DataType value.\n");
}
return "";
}

inline int get_type_size (const DataType data_type) {
Expand All @@ -62,6 +63,7 @@ inline int get_type_size (const DataType data_type) {
default:
EKAT_ERROR_MSG("Error! Unsupported DataType value.\n");
}
return -1;
}

} // namespace scream
Expand Down
Loading

0 comments on commit e58531e

Please sign in to comment.