Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/eamxx/cime_config/namelist_defaults_eamxx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ be lost if SCREAM_HACK_XML is not enabled.
<soil_erodibility_file type="file" doc="File containing soil erodibility">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/dst_ne30pg2_c20241028.nc</soil_erodibility_file>
<soil_erodibility_file hgrid="ne4np4.pg2" type="file" doc="File containing soil erodibility">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne4pg2/dst_ne4pg2_c20241028.nc</soil_erodibility_file>

<marine_organics_file type="file" doc="File containing marine organics emissions">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/monthly_macromolecules_0.1deg_bilinear_year01_merge_ne30pg2_c20241030.nc</marine_organics_file>
<marine_organics_file hgrid="ne4np4.pg2" type="file" doc="File containing marine organics emissions">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne4pg2/monthly_macromolecules_0.1deg_bilinear_year01_merge_ne4pg2_c20241030.nc</marine_organics_file>
<marine_organics_file type="file" doc="File containing marine organics emissions">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/monthly_macromolecules_0.1deg_bilinear_year01_merge_ne30pg2_c20260807.nc</marine_organics_file>
<marine_organics_file hgrid="ne4np4.pg2" type="file" doc="File containing marine organics emissions">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne4pg2/monthly_macromolecules_0.1deg_bilinear_year01_merge_ne4pg2_c20260807.nc</marine_organics_file>

<!-- Mapping Files for finer resolutions -->
<srf_remap_file type="file" doc="File containing mapping data from the grid of emission files to the model grid. Unused if the grid is the same.">none</srf_remap_file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
// Drydep functions are stored in the following hpp file
#include <physics/mam/eamxx_mam_dry_deposition_functions.hpp>

// For reading fractional land use file
#include <physics/mam/readfiles/fractional_land_use.hpp>
#include "share/algorithm/eamxx_data_interpolation.hpp"

#include <ekat_team_policy_utils.hpp>

namespace scream {

using FracLandUseFunc = frac_landuse::fracLandUseFunctions<Real, DefaultDevice>;

MAMDryDep::MAMDryDep(const ekat::Comm &comm, const ekat::ParameterList &params)
: MAMGenericInterface(comm, params) {
/* Anything that can be initialized without grid information can be
Expand Down Expand Up @@ -147,25 +144,6 @@ void MAMDryDep::create_requests() {

// Fractional land use [fraction]
add_field<Computed>("fraction_landuse", vector2d_class, none, grid_name);
// -------------------------------------------------------------
// setup to enable reading fractional land use file
// -------------------------------------------------------------

const auto mapping_file = m_params.get<std::string>("drydep_remap_file", "");
const std::string frac_landuse_data_file =
m_params.get<std::string>("fractional_land_use_file");

// Field to be read from file
const std::string field_name = "fraction_landuse";

// Dimensions of the filed
const std::string dim_name1 = "ncol";
const std::string dim_name2 = "class";

// initialize the file read
FracLandUseFunc::init_frac_landuse_file_read(
ncol_, field_name, dim_name1, dim_name2, grid_, frac_landuse_data_file,
mapping_file, horizInterp_, dataReader_); // output

} // set_grids

Expand Down Expand Up @@ -321,17 +299,30 @@ void MAMDryDep::initialize_impl(const RunType run_type) {
//-----------------------------------------------------------------
// Read fractional land use data
//-----------------------------------------------------------------
frac_landuse_fm_ = get_field_out("fraction_landuse").get_view<Real **>();
// This data is time-independent, we read all data here for the
// entire simulation
FracLandUseFunc::update_frac_land_use_data_from_file(
dataReader_, *horizInterp_,
frac_landuse_); // output

// Copy fractional landuse values to a FM array to be used by other processes
Kokkos::deep_copy(frac_landuse_fm_, frac_landuse_);
read_fractional_land_use_data();
} // initialize_impl

// =========================================================================================
void MAMDryDep::read_fractional_land_use_data() {
const auto mapping_file = m_params.get<std::string>("drydep_remap_file", "");
const auto frac_landuse_data_file =
m_params.get<std::string>("fractional_land_use_file");
std::vector<Field> frac_landuse_fields = {
get_field_out("fraction_landuse")};
auto frac_landuse_interp =
std::make_shared<DataInterpolation>(grid_, frac_landuse_fields);
frac_landuse_interp->set_logger(m_atm_logger);
frac_landuse_interp->setup_static_database({frac_landuse_data_file});
frac_landuse_interp->create_horiz_remappers(
mapping_file == "none" ? "" : mapping_file, m_iop_data_manager);
DataInterpolation::VertRemapData remap_data;
remap_data.vr_type = DataInterpolation::None;
frac_landuse_interp->create_vert_remapper(remap_data);
frac_landuse_interp->run();

frac_landuse_ = get_field_out("fraction_landuse").get_view<const Real **>();
}

// =========================================================================================
void MAMDryDep::run_impl(const double dt) {
using TPF = ekat::TeamPolicyFactory<KT::ExeSpace>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// For MAM4 aerosol configuration
#include <physics/mam/mam_coupling.hpp>

#include "share/field/field_reader.hpp"

// For component name
#include <string>

Expand Down Expand Up @@ -89,11 +87,7 @@ class MAMDryDep final : public MAMGenericInterface {
// Filled with Prognostics::n_mode_c and Prognostics::q_aero_c
view_3d qqcw_;

// For reading fractional land use file
std::shared_ptr<AbstractRemapper> horizInterp_;
std::shared_ptr<FieldReader> dataReader_;
const_view_2d frac_landuse_;
view_2d frac_landuse_fm_;
// aerosol state variables
mam_coupling::AerosolState wet_aero_, dry_aero_;
// wet mixing ratios (water species)
Expand All @@ -106,6 +100,9 @@ class MAMDryDep final : public MAMGenericInterface {
int get_len_temporary_views();
void init_temporary_views();
int len_temporary_views_{0};

// Read fractional land use data from file
void read_fractional_land_use_data();

public:
using KT = ekat::KokkosTypes<DefaultDevice>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ void MAMMicrophysics::set_oxid_reader()

data_interp_oxid_ = std::make_shared<DataInterpolation>(grid_,oxid_fields);
data_interp_oxid_->setup_periodic_time_database ({oxid_file_name});
data_interp_oxid_->create_horiz_remappers (oxid_map_file=="none" ? "" : oxid_map_file);
data_interp_oxid_->create_horiz_remappers (oxid_map_file=="none" ? "" : oxid_map_file, m_iop_data_manager);
data_interp_oxid_->set_logger(m_atm_logger);
DataInterpolation::VertRemapData remap_data_oxid;
remap_data_oxid.vr_type = DataInterpolation::Dynamic3DRef;
Expand Down Expand Up @@ -505,7 +505,7 @@ void MAMMicrophysics::set_linoz_reader(){

data_interp_linoz_ = std::make_shared<DataInterpolation>(grid_,linoz_fields);
data_interp_linoz_->setup_periodic_time_database ({m_linoz_file_name});
data_interp_linoz_->create_horiz_remappers (linoz_map_file=="none" ? "" : linoz_map_file);
data_interp_linoz_->create_horiz_remappers (linoz_map_file=="none" ? "" : linoz_map_file, m_iop_data_manager);
data_interp_linoz_->set_logger(m_atm_logger);

DataInterpolation::VertRemapData remap_data_linoz;
Expand Down Expand Up @@ -553,7 +553,7 @@ void MAMMicrophysics::set_exo_coldens_reader()

data_interp_exo_coldens_ = std::make_shared<DataInterpolation>(grid_exo_coldens,exo_coldens_fields_);
data_interp_exo_coldens_->setup_periodic_time_database ({exo_coldens_file_name});
data_interp_exo_coldens_->create_horiz_remappers (exo_coldens_map_file=="none" ? "" : exo_coldens_map_file);
data_interp_exo_coldens_->create_horiz_remappers (exo_coldens_map_file=="none" ? "" : exo_coldens_map_file, m_iop_data_manager);
data_interp_exo_coldens_->set_logger(m_atm_logger);
DataInterpolation::VertRemapData remap_exo_coldens;
remap_exo_coldens.vr_type = DataInterpolation::Custom;
Expand Down Expand Up @@ -588,7 +588,7 @@ void MAMMicrophysics::set_elevated_emissions_reader()
di_vertical->set_input_files_dimname(e2str(LEV),"altitude");
di_vertical->set_input_files_dimname(e2str(ILEV),"altitude_int");
di_vertical->setup_periodic_time_database ({file_name});
di_vertical->create_horiz_remappers (extfrc_map_file=="none" ? "" : extfrc_map_file);
di_vertical->create_horiz_remappers (extfrc_map_file=="none" ? "" : extfrc_map_file, m_iop_data_manager);
di_vertical->set_logger(m_atm_logger);
DataInterpolation::VertRemapData remap_data_vertical;
remap_data_vertical.vr_type = DataInterpolation::Custom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
// For surface and online emission functions
#include <physics/mam/eamxx_mam_srf_and_online_emissions_functions.hpp>

// For reading soil erodibility file
#include <physics/mam/readfiles/soil_erodibility.hpp>
#include "share/algorithm/eamxx_data_interpolation.hpp"

#include <ekat_team_policy_utils.hpp>
#include <iostream>

namespace scream {

// For reading soil erodibility file
using soilErodibilityFunc =
soil_erodibility::soilErodibilityFunctions<Real, DefaultDevice>;

// ================================================================
// Constructor
// ================================================================
Expand Down Expand Up @@ -106,7 +102,10 @@ void MAMSrfOnlineEmiss::create_requests() {
// Constituent fluxes of species in [kg/m2/s]
// FIXME: confirm if it is Updated or Computed
add_field<Updated>("constituent_fluxes", vector2d_pcnst, kg / m2 / s,
grid_name);
grid_name);

// Soil erodibility [fraction]
add_field<Computed>("soil_erodibility", scalar2d, none, grid_name);

// Surface emissions remapping file
auto srf_map_file = m_params.get<std::string>("srf_remap_file", "");
Expand Down Expand Up @@ -213,47 +212,19 @@ void MAMSrfOnlineEmiss::create_requests() {
// Register sector fields in FM for surface emissions.
// DataInterpolation is set up in initialize_impl.
//--------------------------------------------------------------------

// -------------------------------------------------------------
// Setup to enable reading soil erodibility file
// -------------------------------------------------------------

const std::string soil_erodibility_data_file =
m_params.get<std::string>("soil_erodibility_file");

// Field to be read from file
const std::string soil_erod_fld_name = "mbl_bsn_fct_geo";

// Dimensions of the field
const std::string soil_erod_dname = "ncol";

// initialize the file read
soilErodibilityFunc::init_soil_erodibility_file_read(
ncol_, soil_erod_fld_name, soil_erod_dname, grid_,
soil_erodibility_data_file, srf_map_file, serod_horizInterp_,
serod_dataReader_); // output

// -------------------------------------------------------------
// Setup to enable reading marine organics file
// -------------------------------------------------------------
const std::string marine_organics_data_file =
m_params.get<std::string>("marine_organics_file");


// Fields to be read from file (order matters as they are read in the same
// order)
const std::vector<std::string> marine_org_fld_name = {
"TRUEPOLYC", "TRUEPROTC", "TRUELIPC"};
for (const auto &field_name : marine_org_fld_name) {
add_field<Computed>("morg_" + field_name, scalar2d, none, grid_name);
}

// Dimensions of the field
const std::string marine_org_dname = "ncol";

// initialize the file read
marineOrganicsFunc::init_marine_organics_file_read(
ncol_, marine_org_fld_name, marine_org_dname, grid_,
marine_organics_data_file, srf_map_file,
// output
morg_horizInterp_, morg_data_start_, morg_data_end_, morg_data_out_,
morg_dataReader_);

} // set_grid ends

Expand Down Expand Up @@ -312,6 +283,27 @@ void MAMSrfOnlineEmiss::initialize_impl(const RunType run_type) {
// Constituent fluxes of species in [kg/m2/s]
constituent_fluxes_ = get_field_out("constituent_fluxes");

const std::string marine_organics_data_file =
m_params.get<std::string>("marine_organics_file");
const auto marine_map_file = m_params.get<std::string>("srf_remap_file", "");

const std::vector<std::string> marine_org_fld_name = {
"TRUEPOLYC", "TRUEPROTC", "TRUELIPC"};
morg_fields_={};
morg_fields_.reserve(marine_org_fld_name.size());
for (const auto &field_name : marine_org_fld_name) {
morg_fields_.push_back(
get_field_out("morg_" + field_name).alias(field_name));
}

morg_data_interp_ = std::make_shared<DataInterpolation>(grid_, morg_fields_);
morg_data_interp_->set_logger(m_atm_logger);
morg_data_interp_->setup_periodic_time_database({marine_organics_data_file});
morg_data_interp_->create_horiz_remappers(
marine_map_file == "none" ? "" : marine_map_file, m_iop_data_manager);
DataInterpolation::VertRemapData remap_data;
remap_data.vr_type = DataInterpolation::None;
morg_data_interp_->create_vert_remapper(remap_data);
//--------------------------------------------------------------------
// Setup data interpolation for surface emissions.
//--------------------------------------------------------------------
Expand All @@ -336,7 +328,7 @@ void MAMSrfOnlineEmiss::initialize_impl(const RunType run_type) {
ispec_srf.data_interp_->setup_periodic_time_database(
{ispec_srf.data_file});
ispec_srf.data_interp_->create_horiz_remappers(
srf_map_file == "none" ? "" : srf_map_file);
srf_map_file == "none" ? "" : srf_map_file, m_iop_data_manager);

DataInterpolation::VertRemapData remap_data;
remap_data.vr_type = DataInterpolation::None;
Expand All @@ -355,9 +347,7 @@ void MAMSrfOnlineEmiss::initialize_impl(const RunType run_type) {
if (dust_emis_scheme == 1) {
// This data is time-independent, we read all data here for the
// entire simulation
soilErodibilityFunc::update_soil_erodibility_data_from_file(
serod_dataReader_, *serod_horizInterp_,
soil_erodibility_); // output
read_soil_erodibility_data();
} else if (dust_emis_scheme == 2) {
// For dust emission scheme 2, override soil erodibility to 1
auto soil_erod_ones = view_1d("soil_erod_ones", ncol_);
Expand All @@ -368,10 +358,8 @@ void MAMSrfOnlineEmiss::initialize_impl(const RunType run_type) {
//--------------------------------------------------------------------
// Update marine orgaincs from file
//--------------------------------------------------------------------
// Time dependent data
marineOrganicsFunc::update_marine_organics_data_from_file(
morg_dataReader_, start_of_step_ts(), curr_month, *morg_horizInterp_,
morg_data_end_); // output
morg_data_interp_->init_time_interpolation(start_of_step_ts(),
DataInterpolation::Linear);

//-----------------------------------------------------------------
// Setup preprocessing and post processing
Expand All @@ -380,6 +368,29 @@ void MAMSrfOnlineEmiss::initialize_impl(const RunType run_type) {

} // end initialize_impl()

// =========================================================================================
void MAMSrfOnlineEmiss::read_soil_erodibility_data() {
const auto soil_erodibility_data_file =
m_params.get<std::string>("soil_erodibility_file");
const auto srf_map_file = m_params.get<std::string>("srf_remap_file", "");
const std::string soil_erod_fld_name = "mbl_bsn_fct_geo";

std::vector<Field> soil_erod_fields = {
get_field_out("soil_erodibility").alias(soil_erod_fld_name)};
auto soil_erod_data_interp =
std::make_shared<DataInterpolation>(grid_, soil_erod_fields);
soil_erod_data_interp->set_logger(m_atm_logger);
soil_erod_data_interp->setup_static_database({soil_erodibility_data_file});
soil_erod_data_interp->create_horiz_remappers(
srf_map_file == "none" ? "" : srf_map_file, m_iop_data_manager);
DataInterpolation::VertRemapData remap_data;
remap_data.vr_type = DataInterpolation::None;
soil_erod_data_interp->create_vert_remapper(remap_data);
soil_erod_data_interp->run();

soil_erodibility_ = get_field_out("soil_erodibility").get_view<const Real *>();
}

// ================================================================
// RUN_IMPL
// ================================================================
Expand All @@ -406,24 +417,12 @@ void MAMSrfOnlineEmiss::run_impl(const double dt) {
//--------------------------------------------------------------------

// --- Interpolate marine organics data --

// Update TimeState, note the addition of dt
morg_timeState_.t_now = ts.frac_of_year_in_days();

// Update time state and if the month has changed, update the data.
marineOrganicsFunc::update_marine_organics_timestate(
morg_dataReader_, ts, *morg_horizInterp_,
// output
morg_timeState_, morg_data_start_, morg_data_end_);

// Call the main marine organics routine to get interpolated forcings.
marineOrganicsFunc::marineOrganics_main(morg_timeState_, morg_data_start_,
morg_data_end_, morg_data_out_);
morg_data_interp_->run(ts);

// Marine organics emission data read from the file (order is important here)
const const_view_1d mpoly = ekat::subview(morg_data_out_.emiss_sectors, 0);
const const_view_1d mprot = ekat::subview(morg_data_out_.emiss_sectors, 1);
const const_view_1d mlip = ekat::subview(morg_data_out_.emiss_sectors, 2);
const const_view_1d mpoly = morg_fields_[0].get_view<const Real *>();
const const_view_1d mprot = morg_fields_[1].get_view<const Real *>();
const const_view_1d mlip = morg_fields_[2].get_view<const Real *>();

// Ocean fraction [unitless]
const const_view_1d ocnfrac =
Expand Down
Loading
Loading