@@ -1001,11 +1001,14 @@ void AtmosphereDriver::restart_model ()
10011001 continue ;
10021002 }
10031003 const auto & restart_group = it.second ->get_groups_info ().at (" RESTART" );
1004- std::vector<std::string> fnames ;
1004+ std::vector<Field> fields ;
10051005 for (const auto & fn : restart_group->m_fields_names ) {
1006- fnames.push_back (fn);
1006+ fields.push_back (it.second ->get_field (fn));
1007+ }
1008+ read_fields_from_file (fields,it.second ->get_grid (),filename);
1009+ for (auto & f : fields) {
1010+ f.get_header ().get_tracking ().update_time_stamp (m_current_ts);
10071011 }
1008- read_fields_from_file (fnames,it.second ->get_grid (),filename,m_current_ts);
10091012 }
10101013
10111014 // Restart the num steps counter in the atm time stamp
@@ -1267,17 +1270,20 @@ void AtmosphereDriver::set_initial_conditions ()
12671270 // Now loop over all grids, and load from file the needed fields on each grid (if any).
12681271 const auto & file_name = ic_pl.get <std::string>(" Filename" );
12691272 m_atm_logger->info (" [EAMxx] IC filename: " + file_name);
1270- for (const auto & it : m_field_mgrs) {
1271- const auto & grid_name = it.first ;
1273+ for (const auto & [grid_name,fm] : m_field_mgrs) {
1274+ std::vector<Field> ic_fields;
1275+ for (const auto & fn : ic_fields_names[grid_name]) {
1276+ ic_fields.push_back (fm->get_field (fn));
1277+ }
12721278 if (not m_iop_data_manager) {
1273- read_fields_from_file (ic_fields_names[grid_name],it. second ->get_grid (),file_name,m_current_ts );
1279+ read_fields_from_file (ic_fields,fm ->get_grid (),file_name);
12741280 } else {
12751281 // For IOP enabled, we load from file and copy data from the closest
12761282 // lat/lon column to every other column
1277- m_iop_data_manager->read_fields_from_file_for_iop (file_name,
1278- ic_fields_names[grid_name],
1279- m_current_ts,
1280- it. second );
1283+ m_iop_data_manager->read_fields_from_file_for_iop (file_name,ic_fields,fm-> get_grid ());
1284+ }
1285+ for ( auto & f : ic_fields) {
1286+ f. get_header (). get_tracking (). update_time_stamp (m_current_ts );
12811287 }
12821288 }
12831289 }
@@ -1342,29 +1348,33 @@ void AtmosphereDriver::set_initial_conditions ()
13421348 m_atm_logger->info (" [EAMxx] Reading topography from file ..." );
13431349 const auto & file_name = ic_pl.get <std::string>(" topography_filename" );
13441350 m_atm_logger->info (" filename: " + file_name);
1345- for (const auto & it : m_field_mgrs) {
1346- const auto & grid_name = it.first ;
1351+ for (const auto & [grid_name,fm] : m_field_mgrs) {
1352+ std::vector<Field> topo_fields;
1353+ int nfields = topography_eamxx_fields_names[grid_name].size ();
1354+ for (int i=0 ; i<nfields; ++i) {
1355+ auto eamxx_fname = topography_eamxx_fields_names[grid_name][i];
1356+ auto file_fname = topography_file_fields_names[grid_name][i];
1357+ topo_fields.push_back (fm->get_field (eamxx_fname).alias (file_fname));
1358+ }
1359+
13471360 if (not m_iop_data_manager) {
13481361 // Topography files always use "ncol_d" for the GLL grid value of ncol.
13491362 // To ensure we read in the correct value, we must change the name for that dimension
1350- auto io_grid = it. second ->get_grid ();
1363+ auto io_grid = fm ->get_grid ();
13511364 if (grid_name==" Physics GLL" ) {
13521365 using namespace ShortFieldTagsNames ;
13531366 auto grid = io_grid->clone (io_grid->name (),true );
13541367 grid->reset_field_tag_name (COL," ncol_d" );
13551368 io_grid = grid;
13561369 }
1357- read_fields_from_file (topography_file_fields_names[grid_name],
1358- topography_eamxx_fields_names[grid_name],
1359- io_grid,file_name,m_current_ts);
1370+ read_fields_from_file (topo_fields,io_grid,file_name);
13601371 } else {
13611372 // For IOP enabled, we load from file and copy data from the closest
13621373 // lat/lon column to every other column
1363- m_iop_data_manager->read_fields_from_file_for_iop (file_name,
1364- topography_file_fields_names[grid_name],
1365- topography_eamxx_fields_names[grid_name],
1366- m_current_ts,
1367- it.second );
1374+ m_iop_data_manager->read_fields_from_file_for_iop (file_name,topo_fields,fm->get_grid ());
1375+ }
1376+ for (auto & f : topo_fields) {
1377+ f.get_header ().get_tracking ().update_time_stamp (m_current_ts);
13681378 }
13691379 }
13701380 // Store in provenance list, for later usage in output file metadata
@@ -1469,83 +1479,17 @@ void AtmosphereDriver::set_initial_conditions ()
14691479}
14701480
14711481void AtmosphereDriver::
1472- read_fields_from_file (const std::vector<std::string>& field_names_nc,
1473- const std::vector<std::string>& field_names_eamxx,
1474- const std::shared_ptr<const AbstractGrid>& grid,
1475- const std::string& file_name,
1476- const util::TimeStamp& t0)
1477- {
1478- EKAT_REQUIRE_MSG (field_names_nc.size ()==field_names_eamxx.size (),
1479- " Error! Field name arrays must have same size.\n " );
1480-
1481- if (field_names_nc.size ()==0 ) {
1482- return ;
1483- }
1484-
1485- // NOTE: we cannot pass the field_mgr and m_grids_mgr, since the input
1486- // grid may not be in the grids_manager and may not be the grid
1487- // of the field mgr. This sounds weird, but there is a precise
1488- // use case: when grid is a shallow clone of the fm grid, where
1489- // we changed the name of some field tags (e.g., we set the name
1490- // of COL to ncol_d). This is used when reading the topography,
1491- // since the topo file *always* uses ncol_d for GLL points data,
1492- // while a non-PG2 run would have the tag name be "ncol".
1493- const auto & field_mgr = m_field_mgrs.at (grid->name ());
1494- std::vector<Field> fields;
1495- for (size_t i=0 ; i<field_names_nc.size (); ++i) {
1496- const auto & eamxx_name = field_names_eamxx[i];
1497- const auto & nc_name = field_names_nc[i];
1498- fields.push_back (field_mgr->get_field (eamxx_name).alias (nc_name));
1499- }
1500-
1501- AtmosphereInput ic_reader (file_name,grid,fields);
1502- ic_reader.set_logger (m_atm_logger);
1503- ic_reader.read_variables ();
1504- ic_reader.finalize ();
1505-
1506- for (auto & f : fields) {
1507- // Set the initial time stamp
1508- // NOTE: f is an alias of the field from field_mgr, so it shares all
1509- // pointers to the metadata (except for the FieldIdentifier),
1510- // so changing its timestamp will also change the timestamp
1511- // of the field in field_mgr
1512- f.get_header ().get_tracking ().update_time_stamp (t0);
1513- }
1514- }
1515-
1516- void AtmosphereDriver::
1517- read_fields_from_file (const std::vector<std::string>& field_names,
1482+ read_fields_from_file (const std::vector<Field>& fields,
15181483 const std::shared_ptr<const AbstractGrid>& grid,
1519- const std::string& file_name,
1520- const util::TimeStamp& t0)
1484+ const std::string& file_name)
15211485{
1522- if (field_names .size ()==0 ) {
1486+ if (fields .size ()==0 ) {
15231487 return ;
15241488 }
15251489
1526- // NOTE: we cannot pass the field_mgr and m_grids_mgr, since the input
1527- // grid may not be in the grids_manager and may not be the grid
1528- // of the field mgr. This sounds weird, but there is a precise
1529- // use case: when grid is a shallow clone of the fm grid, where
1530- // we changed the name of some field tags (e.g., we set the name
1531- // of COL to ncol_d). This is used when reading the topography,
1532- // since the topo file *always* uses ncol_d for GLL points data,
1533- // while a non-PG2 run would have the tag name be "ncol".
1534- const auto & field_mgr = m_field_mgrs.at (grid->name ());
1535- std::vector<Field> fields;
1536- for (const auto & fn : field_names) {
1537- fields.push_back (field_mgr->get_field (fn));
1538- }
1539-
15401490 AtmosphereInput ic_reader (file_name,grid,fields);
15411491 ic_reader.set_logger (m_atm_logger);
15421492 ic_reader.read_variables ();
1543- ic_reader.finalize ();
1544-
1545- for (auto & f : fields) {
1546- // Set the initial time stamp
1547- f.get_header ().get_tracking ().update_time_stamp (t0);
1548- }
15491493}
15501494
15511495void AtmosphereDriver::
0 commit comments