Skip to content

Commit b9e2717

Browse files
committed
EAMxx: Fixing variable names and add comments.
1 parent d812409 commit b9e2717

File tree

4 files changed

+122
-90
lines changed

4 files changed

+122
-90
lines changed

components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp

Lines changed: 93 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,28 @@ void MAMMicrophysics::set_grids(
238238
add_field<Computed>("mam4_microphysics_tendency_renaming_cloud_borne", vector3d_num_gas_aerosol_constituents, nondim, grid_name);
239239
}
240240

241+
<<<<<<< HEAD
241242
// Creating a Linoz reader and setting Linoz parameters involves reading data
242243
// from a file and configuring the necessary parameters for the Linoz model.
243244
#ifdef USE_OLD_LINOZ_FILE_READ
244245
if (config_.linoz.compute) {
245246

247+
=======
248+
>>>>>>> b16a6664e4 (EAMxx: Fixing variable names and add comments.)
246249
// NOTE: order matches mam4xx:
247-
m_var_names_oxi={"O3", "OH", "NO3", "HO2"};
248-
// linoz
249-
m_var_names_linoz = {
250+
// names of variables in oxid file.
251+
var_names_oxi_={"O3", "OH", "NO3", "HO2"};
252+
// names of variables for linoz
253+
var_names_linoz_ = {
250254
"o3_clim", "o3col_clim", "t_clim", "PmL_clim",
251255
"dPmL_dO3", "dPmL_dT", "dPmL_dO3col", "cariolle_pscs"};
256+
<<<<<<< HEAD
252257
std::cout << "Using former reader..." << "\n";
258+
=======
259+
260+
#ifdef USE_OLD_LINOZ_FILE_READ
261+
{
262+
>>>>>>> b16a6664e4 (EAMxx: Fixing variable names and add comments.)
253263
linoz_file_name_ = m_params.get<std::string>("mam4_linoz_file_name");
254264
const std::string linoz_map_file =
255265
m_params.get<std::string>("aero_microphys_remap_file", "");
@@ -258,7 +268,7 @@ void MAMMicrophysics::set_grids(
258268
scream::mam_coupling::setup_tracer_data(linoz_data_, linoz_file_name_,
259269
linoz_cyclical_ymd);
260270
LinozHorizInterp_ = scream::mam_coupling::create_horiz_remapper(
261-
grid_, linoz_file_name_, linoz_map_file, m_var_names_linoz, linoz_data_);
271+
grid_, linoz_file_name_, linoz_map_file, var_names_linoz_, linoz_data_);
262272
LinozDataReader_ = scream::mam_coupling::create_tracer_data_reader(
263273
LinozHorizInterp_, linoz_file_name_);
264274

@@ -269,7 +279,7 @@ void MAMMicrophysics::set_grids(
269279
const int num_levs_io_linoz =
270280
io_grid_linoz
271281
->get_num_vertical_levels(); // Number of levels per column
272-
const int nvars = int(m_var_names_linoz.size());
282+
const int nvars = int(var_names_linoz_.size());
273283
linoz_data_.init(num_cols_io_linoz, num_levs_io_linoz, nvars);
274284
linoz_data_.allocate_temporary_views();
275285
} // LINOZ reader
@@ -284,11 +294,11 @@ void MAMMicrophysics::set_grids(
284294
scream::mam_coupling::setup_tracer_data(tracer_data_, oxid_file_name_,
285295
oxid_ymd);
286296
TracerHorizInterp_ = scream::mam_coupling::create_horiz_remapper(
287-
grid_, oxid_file_name_, oxid_map_file, m_var_names_oxi, tracer_data_);
297+
grid_, oxid_file_name_, oxid_map_file, var_names_oxi_, tracer_data_);
288298
TracerDataReader_ = scream::mam_coupling::create_tracer_data_reader(
289299
TracerHorizInterp_, oxid_file_name_);
290300

291-
const int nvars = int(m_var_names_oxi.size());
301+
const int nvars = int(var_names_oxi_.size());
292302
const auto io_grid = TracerHorizInterp_->get_tgt_grid();
293303
const int num_cols_io =
294304
io_grid->get_num_local_dofs(); // Number of columns on this rank
@@ -303,41 +313,35 @@ void MAMMicrophysics::set_grids(
303313
} // oxid file reader
304314

305315
#else
306-
std::cout << "Using DataInterpolation Class..." << "\n";
307-
std::vector<std::string> var_names_linoz = {
308-
"o3_clim", "o3col_clim", "t_clim", "PmL_clim",
309-
"dPmL_dO3", "dPmL_dT", "dPmL_dO3col", "cariolle_pscs"};
310-
311-
for(const auto &var_name : var_names_linoz) {
312-
// FIXME: switch to Required
313-
add_field<Computed>(var_name, scalar3d_mid, nondim, grid_name);
316+
// The DataInterpolation class uses Field. We save these fields in FM.
317+
for(const auto &field_name : var_names_linoz_) {
318+
add_field<Computed>(field_name, scalar3d_mid, nondim, grid_name);
314319
}
315-
316-
std::vector<std::string> var_names_oxi = {"O3", "OH", "NO3", "HO2"};
317-
for(const auto &field_name : var_names_oxi) {
320+
for(const auto &field_name : var_names_oxi_) {
318321
add_field<Computed>(field_name, scalar3d_mid, nondim, grid_name);
319322
}
320323
#endif
321-
324+
// list of species for elevated emissiones.
322325
extfrc_lst_ = {"so2", "so4_a1", "so4_a2", "pom_a4", "bc_a4",
323326
"num_a1", "num_a2", "num_a4", "soag"};
324-
m_elevated_emis_var_names["so2"] = {"BB", "ENE_ELEV", "IND_ELEV",
327+
// sectors or variables for each species.
328+
elevated_emis_var_names_["so2"] = {"BB", "ENE_ELEV", "IND_ELEV",
325329
"contvolc"};
326-
m_elevated_emis_var_names["so4_a1"] = {"BB", "ENE_ELEV", "IND_ELEV",
330+
elevated_emis_var_names_["so4_a1"] = {"BB", "ENE_ELEV", "IND_ELEV",
327331
"contvolc"};
328-
m_elevated_emis_var_names["so4_a2"] = {"contvolc"};
329-
m_elevated_emis_var_names["pom_a4"] = {"BB"};
330-
m_elevated_emis_var_names["bc_a4"] = {"BB"};
331-
m_elevated_emis_var_names["num_a1"] = {
332+
elevated_emis_var_names_["so4_a2"] = {"contvolc"};
333+
elevated_emis_var_names_["pom_a4"] = {"BB"};
334+
elevated_emis_var_names_["bc_a4"] = {"BB"};
335+
elevated_emis_var_names_["num_a1"] = {
332336
"num_a1_SO4_ELEV_BB", "num_a1_SO4_ELEV_ENE", "num_a1_SO4_ELEV_IND",
333337
"num_a1_SO4_ELEV_contvolc"};
334-
m_elevated_emis_var_names["num_a2"] = {"num_a2_SO4_ELEV_contvolc"};
338+
elevated_emis_var_names_["num_a2"] = {"num_a2_SO4_ELEV_contvolc"};
335339
// num_a4
336340
// FIXME: why the sectors in this files are num_a1;
337341
// I guess this should be num_a4? Is this a bug in the orginal nc files?
338-
m_elevated_emis_var_names["num_a4"] = {"num_a1_BC_ELEV_BB",
342+
elevated_emis_var_names_["num_a4"] = {"num_a1_BC_ELEV_BB",
339343
"num_a1_POM_ELEV_BB"};
340-
m_elevated_emis_var_names["soag"] = {"SOAbb_src", "SOAbg_src", "SOAff_src"};
344+
elevated_emis_var_names_["soag"] = {"SOAbb_src", "SOAbg_src", "SOAff_src"};
341345

342346
#ifdef USE_OLD_VERTICAL_FILE_READ
343347
{
@@ -357,7 +361,7 @@ void MAMMicrophysics::set_grids(
357361

358362
for(const auto &var_name : extfrc_lst_) {
359363
const auto file_name = elevated_emis_file_name_[var_name];
360-
const auto var_names = m_elevated_emis_var_names[var_name];
364+
const auto var_names = elevated_emis_var_names_[var_name];
361365

362366
scream::mam_coupling::TracerData data_tracer;
363367
scream::mam_coupling::setup_tracer_data(data_tracer, file_name,
@@ -374,7 +378,7 @@ void MAMMicrophysics::set_grids(
374378
int i = 0;
375379
for(const auto &var_name : extfrc_lst_) {
376380
const auto file_name = elevated_emis_file_name_[var_name];
377-
const auto var_names = m_elevated_emis_var_names[var_name];
381+
const auto var_names = elevated_emis_var_names_[var_name];
378382
const int nvars = static_cast<int>(var_names.size());
379383

380384
forcings_[i].nsectors = nvars;
@@ -405,7 +409,8 @@ void MAMMicrophysics::set_grids(
405409

406410
} // Tracer external forcing data
407411
#else
408-
for(const auto &pair : m_elevated_emis_var_names) {
412+
// Fields for elevated emissions.
413+
for(const auto &pair : elevated_emis_var_names_) {
409414
const auto &var_name =pair.first;
410415
for(const auto &field_name : pair.second) {
411416
add_field<Computed>(field_name+"_"+var_name, scalar3d_mid, nondim, grid_name);
@@ -502,81 +507,94 @@ void MAMMicrophysics::init_temporary_views() {
502507
") should be equal. \n");
503508
}
504509
#ifndef USE_OLD_LINOZ_FILE_READ
510+
// set DataInterpolation object for oxid reader.
505511
void MAMMicrophysics::set_oxid_reader()
506512
{
507-
// Oxid fields read initialization
513+
508514
auto pmid = get_field_in("p_mid");
509-
std::vector<Field> oxid_fields;
515+
// Oxid fields read initialization
510516
const auto oxid_file_name = m_params.get<std::string>("mam4_oxid_file_name");
511517
const std::string oxid_map_file =
512518
m_params.get<std::string>("aero_microphys_remap_file", "");
513-
for(const auto &field_name : m_var_names_oxi) {
519+
// get fields from FM.
520+
std::vector<Field> oxid_fields;
521+
for(const auto &field_name : var_names_oxi_) {
514522
oxid_fields.push_back(get_field_out(field_name));
515523
}
516524

517525
const int oxid_ymd = m_params.get<int>("mam4_oxid_ymd");
518526
util::TimeStamp ref_ts_oxid= mam_coupling::convert_date(oxid_ymd);
519-
m_data_interpolation = std::make_shared<DataInterpolation>(grid_,oxid_fields);
520-
m_data_interpolation->setup_time_database ({oxid_file_name},util::TimeLine::YearlyPeriodic, ref_ts_oxid);
521-
m_data_interpolation->create_horiz_remappers (oxid_map_file=="none" ? "" : oxid_map_file);
522-
523-
DataInterpolation::VertRemapData remap_data;
524-
remap_data.vr_type = DataInterpolation::Dynamic3DRef;
525-
remap_data.pname = "PS";
526-
remap_data.pmid = pmid;
527+
data_interp_oxid_ = std::make_shared<DataInterpolation>(grid_,oxid_fields);
528+
data_interp_oxid_->setup_time_database ({oxid_file_name},util::TimeLine::YearlyPeriodic, ref_ts_oxid);
529+
data_interp_oxid_->create_horiz_remappers (oxid_map_file=="none" ? "" : oxid_map_file);
530+
531+
DataInterpolation::VertRemapData remap_data_oxid;
532+
remap_data_oxid.vr_type = DataInterpolation::Dynamic3DRef;
533+
remap_data_oxid.pname = "PS";
534+
remap_data_oxid.pmid = pmid;
527535
//FIXME: make it a namelist parameter.
528-
bool mam4_use_eamxx_vertical_remp=false;
529-
if (mam4_use_eamxx_vertical_remp){
530-
auto grid_after_hremap = m_data_interpolation->get_grid_after_hremap();
536+
// Dynamic3DRef can also be employed instead of mam4xx routine.
537+
bool mam4_use_mam4xx_oxi_vert_remap=true;
538+
if (mam4_use_mam4xx_oxi_vert_remap){
539+
// We are using a custom remapper that invokes the MAM4XX routine
540+
// for vertical interpolation.
541+
// The type used is VertRemapType::MAM4_PSRef.
542+
auto grid_after_hremap = data_interp_oxid_->get_grid_after_hremap();
531543
auto vertical_remapper= std::make_shared<VerticalRemapperMAM4>(grid_after_hremap, grid_,
532544
VerticalRemapperMAM4::VertRemapType::MAM4_PSRef);
533-
remap_data.custom_remapper=vertical_remapper;
545+
remap_data_oxid.custom_remapper=vertical_remapper;
534546
}
535-
m_data_interpolation->create_vert_remapper (remap_data);
536-
m_data_interpolation->init_data_interval (start_of_step_ts());
547+
data_interp_oxid_->create_vert_remapper (remap_data);
548+
data_interp_oxid_->init_data_interval (start_of_step_ts());
537549
}
538-
550+
// set DataInterpolation object for linoz reader.
539551
void MAMMicrophysics::set_linoz_reader(){
540-
// linoz
541-
// in format YYYYMMDD
542552
auto pmid = get_field_in("p_mid");
543-
544553
const int linoz_cyclical_ymd = m_params.get<int>("mam4_linoz_ymd");
554+
// in format YYYYMMDD
545555
util::TimeStamp ref_ts_linoz = mam_coupling::convert_date(linoz_cyclical_ymd);
546-
// util::TimeStamp ref_ts_linoz (1,1,1,0,0,0); // Beg of any year, since we use yearly periodic timeline
547556
const auto m_linoz_file_name = m_params.get<std::string>("mam4_linoz_file_name");
548557
const std::string linoz_map_file =
549558
m_params.get<std::string>("aero_microphys_remap_file", "");
550559
std::vector<Field> linoz_fields;
551-
for(const auto &field_name : m_var_names_linoz) {
560+
for(const auto &field_name : var_names_linoz_) {
552561
linoz_fields.push_back(get_field_out(field_name));
553562
}
554563

555-
m_data_interpolation_linoz = std::make_shared<DataInterpolation>(grid_,linoz_fields);
556-
m_data_interpolation_linoz->setup_time_database ({m_linoz_file_name},util::TimeLine::YearlyPeriodic, ref_ts_linoz);
557-
m_data_interpolation_linoz->create_horiz_remappers (linoz_map_file=="none" ? "" : linoz_map_file);
564+
data_interp_linoz_ = std::make_shared<DataInterpolation>(grid_,linoz_fields);
565+
data_interp_linoz_->setup_time_database ({m_linoz_file_name},util::TimeLine::YearlyPeriodic, ref_ts_linoz);
566+
data_interp_linoz_->create_horiz_remappers (linoz_map_file=="none" ? "" : linoz_map_file);
558567

559568
DataInterpolation::VertRemapData remap_data_linoz;
560569
remap_data_linoz.vr_type = DataInterpolation::Static1D;
570+
// lev is the name of variables for vertical interpolation
561571
remap_data_linoz.pname = "lev";
562572
remap_data_linoz.pmid = pmid;
563-
auto grid_after_hremap_linoz = m_data_interpolation_linoz->get_grid_after_hremap();
564-
auto vertical_remapper_linoz = std::make_shared<VerticalRemapperMAM4>(grid_after_hremap_linoz, grid_,
565-
VerticalRemapperMAM4::VertRemapType::MAM4_ZONAL);
566-
remap_data_linoz.custom_remapper=vertical_remapper_linoz;
567-
m_data_interpolation_linoz->create_vert_remapper (remap_data_linoz);
568-
m_data_interpolation_linoz->init_data_interval (start_of_step_ts());
573+
// Static1D can also be employed instead of mam4xx routine.
574+
bool mam4_use_mam4xx_linoz_vert_remap=true;
575+
if (mam4_use_mam4xx_linoz_vert_remap){
576+
// We are using a custom remapper that invokes the MAM4XX routine
577+
// for vertical interpolation.
578+
// The type used is VertRemapType::MAM4_ZONAL.
579+
auto grid_after_hremap_linoz = data_interp_linoz_->get_grid_after_hremap();
580+
auto vertical_remapper_linoz = std::make_shared<VerticalRemapperMAM4>(grid_after_hremap_linoz, grid_,
581+
VerticalRemapperMAM4::VertRemapType::MAM4_ZONAL);
582+
remap_data_linoz.custom_remapper=vertical_remapper_linoz;
583+
}
584+
data_interp_linoz_->create_vert_remapper (remap_data_linoz);
585+
data_interp_linoz_->init_data_interval (start_of_step_ts());
569586
}
570587
#endif
571588

572589
#ifndef USE_OLD_VERTICAL_FILE_READ
573-
void MAMMicrophysics::set_vertical_emissions_reader()
590+
// set DataInterpolation object for elevated emissions reader.
591+
void MAMMicrophysics::set_elevated_emissions_reader()
574592
{
575593
const auto z_iface = get_field_out("z_iface");
576594
const std::string extfrc_map_file =
577595
m_params.get<std::string>("aero_microphys_remap_file", "");
578596
int elevated_emiss_cyclical_ymd = m_params.get<int>("elevated_emiss_ymd");
579-
for(const auto &pair : m_elevated_emis_var_names) {
597+
for(const auto &pair : elevated_emis_var_names_) {
580598
const auto& var_name=pair.first;
581599
std::string item_name = "mam4_" + var_name + "_elevated_emiss_file_name";
582600
const auto file_name = m_params.get<std::string>(item_name);
@@ -595,14 +613,16 @@ void MAMMicrophysics::set_vertical_emissions_reader()
595613
auto grid_after_hremap_vertical = di_vertical->get_grid_after_hremap();
596614
grid_after_hremap_vertical->reset_field_tag_name(ShortFieldTagsNames::LEV, "altitude");
597615
grid_after_hremap_vertical->reset_field_tag_name(ShortFieldTagsNames::ILEV, "altitude_int");
616+
// we create elevated emission remapper
598617
auto vertical_remapper_elevated = std::make_shared<VerticalRemapperMAM4>(grid_after_hremap_vertical, grid_,
599618
VerticalRemapperMAM4::VertRemapType::MAM4_ELEVATED_EMISSIONS);
619+
// we set source and target variables for interpolation
600620
vertical_remapper_elevated->set_source_pressure(file_name);
601621
vertical_remapper_elevated->set_target_pressure(z_iface);
602622
remap_data_vertical.custom_remapper=vertical_remapper_elevated;
603623
di_vertical->create_vert_remapper (remap_data_vertical);
604624
di_vertical->init_data_interval (start_of_step_ts());
605-
m_data_interpolation_vertical.push_back(di_vertical);
625+
data_interp_elevated_emissions_.push_back(di_vertical);
606626
}//end var_name
607627
}
608628
#endif
@@ -771,10 +791,10 @@ void MAMMicrophysics::initialize_impl(const RunType run_type) {
771791
}
772792
#else
773793
{
774-
set_vertical_emissions_reader();
794+
set_elevated_emissions_reader();
775795
for(size_t i = 0; i < extfrc_lst_.size(); ++i) {
776796
std::string var_name = extfrc_lst_[i];
777-
const auto sector_names = m_elevated_emis_var_names[var_name];
797+
const auto sector_names = elevated_emis_var_names_[var_name];
778798
const int nvars = static_cast<int>(sector_names.size());
779799
forcings_[i].nsectors = nvars;
780800
// I am assuming the order of species in extfrc_lst_.
@@ -936,8 +956,8 @@ void MAMMicrophysics::run_impl(const double dt) {
936956
// const auto linoz_dPmL_dT = get_field_in("dPmL_dT").get_view<const Real **>();
937957
// const auto linoz_dPmL_dO3col = get_field_in("dPmL_dO3col").get_view<const Real **>();
938958
// const auto linoz_cariolle_pscs = get_field_in("cariolle_pscs").get_view<const Real **>();
939-
m_data_interpolation->run(end_of_step_ts());
940-
m_data_interpolation_linoz->run(end_of_step_ts());
959+
data_interp_oxid_->run(end_of_step_ts());
960+
data_interp_linoz_->run(end_of_step_ts());
941961

942962
const auto linoz_o3_clim = get_field_out("o3_clim").get_view<Real **>();
943963
const auto linoz_o3col_clim = get_field_out("o3col_clim").get_view<Real **>();
@@ -1006,7 +1026,7 @@ void MAMMicrophysics::run_impl(const double dt) {
10061026
for(const auto &var_name : extfrc_lst_) {
10071027
elevated_emiss_time_state_[i].t_now = ts.frac_of_year_in_days();
10081028
const auto file_name = elevated_emis_file_name_[var_name];
1009-
const auto var_names = m_elevated_emis_var_names[var_name];
1029+
const auto var_names = elevated_emis_var_names_[var_name];
10101030
auto& elevated_emis_output= forcings_[i].fields;
10111031
scream::mam_coupling::advance_tracer_data(
10121032
ElevatedEmissionsDataReader_[i], *ElevatedEmissionsHorizInterp_[i], ts,
@@ -1016,8 +1036,8 @@ void MAMMicrophysics::run_impl(const double dt) {
10161036
Kokkos::fence();
10171037
}
10181038
#else
1019-
for (size_t i = 0; i < m_elevated_emis_var_names.size(); ++i) {
1020-
m_data_interpolation_vertical[i]->run(end_of_step_ts());
1039+
for (size_t i = 0; i < elevated_emis_var_names_.size(); ++i) {
1040+
data_interp_elevated_emissions_[i]->run(end_of_step_ts());
10211041
}
10221042
#endif
10231043

components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ class MAMMicrophysics final : public MAMGenericInterface {
106106
std::vector<Real> chlorine_values_;
107107
std::vector<int> chlorine_time_secs_;
108108
view_3d photo_rates_;
109-
110-
std::vector<std::string> m_var_names_oxi;
111-
std::vector<std::string> m_var_names_linoz;
109+
// names of oxi variants
110+
std::vector<std::string> var_names_oxi_;
111+
// names of linoz field
112+
std::vector<std::string> var_names_linoz_;
112113

113114
#ifdef USE_OLD_LINOZ_FILE_READ
114115
// invariants members
@@ -119,9 +120,11 @@ class MAMMicrophysics final : public MAMGenericInterface {
119120
std::string oxid_file_name_;
120121
view_2d cnst_offline_[4];
121122
#else
122-
std::shared_ptr<DataInterpolation> m_data_interpolation;
123+
// data interpolation object for oxi invariants
124+
std::shared_ptr<DataInterpolation> data_interp_oxid_;
123125
void set_oxid_reader();
124-
std::shared_ptr<DataInterpolation> m_data_interpolation_linoz;
126+
// data interpolation object for linoz fields
127+
std::shared_ptr<DataInterpolation> data_interp_linoz_;
125128
void set_linoz_reader();
126129
#endif
127130
view_3d invariants_;
@@ -135,16 +138,17 @@ class MAMMicrophysics final : public MAMGenericInterface {
135138
#endif
136139
// Vertical emission uses 9 files, here I am using std::vector to stote
137140
// instance of each file.
138-
std::map<std::string, std::vector<std::string>> m_elevated_emis_var_names;
141+
std::map<std::string, std::vector<std::string>> elevated_emis_var_names_;
139142
#ifdef USE_OLD_VERTICAL_FILE_READ
140143
mam_coupling::TracerTimeState elevated_emiss_time_state_[mam4::gas_chemistry::extcnt];
141144
std::vector<std::shared_ptr<AtmosphereInput>> ElevatedEmissionsDataReader_;
142145
std::vector<std::shared_ptr<AbstractRemapper>> ElevatedEmissionsHorizInterp_;
143146
std::vector<mam_coupling::TracerData> elevated_emis_data_;
144147
std::map<std::string, std::string> elevated_emis_file_name_;
145148
#else
146-
std::vector<std::shared_ptr<DataInterpolation>> m_data_interpolation_vertical;
147-
void set_vertical_emissions_reader();
149+
// data interpolation object for elevated emissions
150+
std::vector<std::shared_ptr<DataInterpolation>> data_interp_elevated_emissions_;
151+
void set_elevated_emissions_reader();
148152
#endif
149153
std::vector<std::string> extfrc_lst_;
150154

0 commit comments

Comments
 (0)