Skip to content

Commit c578206

Browse files
authored
Merge branch 'bartgol/eamxx/step-tends-refactor' (PR #7824)
Allow calculation also of tendency of groups monolithic/individual fields. [non-BFB] Only for newly added var to eamxx-prod output.
2 parents f29cfa4 + 2e9b7fa commit c578206

File tree

14 files changed

+173
-207
lines changed

14 files changed

+173
-207
lines changed

components/eamxx/cime_config/namelist_defaults_eamxx.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ be lost if SCREAM_HACK_XML is not enabled.
153153
>0</internal_diagnostics_level>
154154
<compute_tendencies
155155
type="array(string)"
156-
doc="list of computed fields for which this process will back out tendencies"
156+
doc="list of computed fields/groups for which this process will back out tendencies"
157157
/>
158158
</atm_proc_base>
159159

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/prod/shell_commands

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $atmchange -b physics::cosp::cosp_frequency=1
2525
$atmchange -b physics::mac_aero_mic::shoc::compute_tendencies=T_mid,qv
2626
$atmchange -b physics::mac_aero_mic::p3::compute_tendencies=T_mid,qv
2727
$atmchange -b physics::rrtmgp::compute_tendencies=T_mid
28-
$atmchange -b homme::compute_tendencies=T_mid,qv
28+
$atmchange -b homme::compute_tendencies=T_mid,qv,qc
2929

3030
# Set temperature cut off in dycore threshold to 180K
3131
$atmchange -b vtheta_thresh=180

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/prod/yaml_outs/eamxx_output.decadal.4hourlyAVG_coarse.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fields:
1616
- p3_qv_tend
1717
- shoc_qv_tend
1818
- homme_qv_tend
19+
- homme_qc_tend
1920
- SW_flux_dn
2021
- SW_flux_up
2122
- LW_flux_dn

components/eamxx/src/control/atmosphere_driver.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,6 @@ void AtmosphereDriver::create_grids()
310310
// Each process will grab what they need
311311
m_atm_process_group->set_grids(m_grids_manager);
312312

313-
314-
// Also make each atm proc build requests for tendency fields, if needed
315-
m_atm_process_group->setup_tendencies_requests();
316-
317313
m_ad_status |= s_grids_created;
318314

319315
stop_timer("EAMxx::create_grids");
@@ -592,6 +588,9 @@ void AtmosphereDriver::create_fields()
592588
m_atm_process_group->set_required_field(m_field_mgr->get_field(fid).get_const());
593589
}
594590

591+
// Make atm procs create the proc-level tendency fields (if requested)
592+
m_atm_process_group->setup_step_tendencies(m_grids_manager->get_grid("physics")->name());
593+
595594
// Now that all processes have all the required/computed fields/groups, they
596595
// have also created any possible internal field (if needed). Notice that some
597596
// atm proc might have created internal fields already during the set_grids
@@ -606,8 +605,8 @@ void AtmosphereDriver::create_fields()
606605
m_field_mgr->add_field(f);
607606
}
608607

609-
// Now go through the input fields/groups to the atm proc group, as well as
610-
// the internal fields/groups, and mark them as part of the RESTART group.
608+
// Now go through the input fields/groups to the atm proc group,
609+
// and mark them as part of the RESTART group.
611610
for (const auto& f : m_atm_process_group->get_fields_in()) {
612611
const auto& fid = f.get_header().get_identifier();
613612
m_field_mgr->add_to_group(fid, "RESTART");
@@ -621,9 +620,14 @@ void AtmosphereDriver::create_fields()
621620
}
622621
}
623622
}
623+
// Internal fields have their group names set by the processes that create them.
624+
// Hence, simply add them to all the groups they are marked as part of
624625
for (const auto& f : m_atm_process_group->get_internal_fields()) {
625-
const auto& fid = f.get_header().get_identifier();
626-
m_field_mgr->add_to_group(fid, "RESTART");
626+
const auto& ftrack = f.get_header().get_tracking();
627+
const auto& fid = f.get_header().get_identifier();
628+
for (const auto& gn : ftrack.get_groups_names()) {
629+
m_field_mgr->add_to_group(fid, gn);
630+
}
627631
}
628632

629633
auto& driver_options_pl = m_atm_params.sublist("driver_options");
@@ -944,9 +948,16 @@ void AtmosphereDriver::restart_model ()
944948
// No field needs to be restarted on this grid.
945949
continue;
946950
}
947-
const auto& restart_group = m_field_mgr->get_group_info("RESTART", gn);
951+
const auto& restart_fnames = m_field_mgr->get_group_info("RESTART", gn).m_fields_names;
948952
std::vector<Field> fields;
949-
for (const auto& fn : restart_group.m_fields_names) {
953+
for (const auto& fn : restart_fnames) {
954+
// If the field has a parent, and the parent is also in the RESTART group,
955+
// then skip it, since restarting the parent will restart the child too
956+
auto f = m_field_mgr->get_field(fn,gn);
957+
auto p = f.get_header().get_parent();
958+
if (p and ekat::contains(p->get_tracking().get_groups_names(),"RESTART")) {
959+
continue;
960+
}
950961
fields.push_back(m_field_mgr->get_field(fn,gn));
951962
}
952963
read_fields_from_file (fields,m_grids_manager->get_grid(gn),filename);

components/eamxx/src/control/tests/ad_tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ grids_manager:
3131
grids_names: ["point_grid"]
3232
point_grid:
3333
type: point_grid
34+
aliases: ["physics"]
3435
number_of_global_columns: 24
3536
number_of_vertical_levels: 3
3637
...

components/eamxx/src/dynamics/homme/eamxx_homme_process_interface.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,20 @@ void HommeDynamics::set_grids (const std::shared_ptr<const GridsManager> grids_m
225225
// NOTE: 'true' is for 'dynamic' subfield; the idx of the subfield slice will move
226226
// during execution (this class will take care of moving it, by calling
227227
// reset_subview_idx on each field).
228-
add_internal_field (m_helper_fields.at("v_dyn").subfield(1,tl.n0,true));
229-
add_internal_field (m_helper_fields.at("vtheta_dp_dyn").subfield(1,tl.n0,true));
230-
add_internal_field (m_helper_fields.at("dp3d_dyn").subfield(1,tl.n0,true));
231-
add_internal_field (m_helper_fields.at("phi_int_dyn").subfield(1,tl.n0,true));
232-
add_internal_field (m_helper_fields.at("ps_dyn").subfield(1,tl.n0,true));
233-
add_internal_field (m_helper_fields.at("Qdp_dyn").subfield(1,tl.n0_qdp,true));
228+
add_internal_field (m_helper_fields.at("v_dyn").subfield(1,tl.n0,true),{"RESTART"});
229+
add_internal_field (m_helper_fields.at("vtheta_dp_dyn").subfield(1,tl.n0,true),{"RESTART"});
230+
add_internal_field (m_helper_fields.at("dp3d_dyn").subfield(1,tl.n0,true),{"RESTART"});
231+
add_internal_field (m_helper_fields.at("phi_int_dyn").subfield(1,tl.n0,true),{"RESTART"});
232+
add_internal_field (m_helper_fields.at("ps_dyn").subfield(1,tl.n0,true),{"RESTART"});
233+
add_internal_field (m_helper_fields.at("Qdp_dyn").subfield(1,tl.n0_qdp,true),{"RESTART"});
234234
if (not params.theta_hydrostatic_mode) {
235-
add_internal_field (m_helper_fields.at("w_int_dyn").subfield(1,tl.n0,true));
235+
add_internal_field (m_helper_fields.at("w_int_dyn").subfield(1,tl.n0,true),{"RESTART"});
236236
}
237237

238238
// The output manager pulls from the atm process fields. Add
239239
// helper fields for the case that a user request output.
240240
add_internal_field (m_helper_fields.at("omega_dyn"));
241-
add_internal_field (m_helper_fields.at("phis_dyn"));
241+
add_internal_field (m_helper_fields.at("phis_dyn"),{"RESTART"});
242242

243243
if (not fv_phys_active()) {
244244
// Dynamics backs out tendencies from the states, and passes those to Homme.
@@ -937,12 +937,15 @@ void HommeDynamics::init_homme_views () {
937937
}
938938

939939
void HommeDynamics::restart_homme_state () {
940-
// Safety checks: internal fields *should* have been restarted (and therefore have a valid timestamp)
940+
// Safety checks: RESTART fields *should* have been restarted (and therefore have a valid timestamp)
941941
for (auto& f : get_internal_fields()) {
942-
auto ts = f.get_header().get_tracking().get_time_stamp();
943-
EKAT_REQUIRE_MSG(ts.is_valid(),
944-
"Error! Found HommeDynamics internal field not restarted.\n"
945-
" - field name: " + f.get_header().get_identifier().name() + "\n");
942+
const auto& track = f.get_header().get_tracking();
943+
if (ekat::contains(track.get_groups_names(),"RESTART")) {
944+
auto ts = track.get_time_stamp();
945+
EKAT_REQUIRE_MSG(track.get_time_stamp().is_valid(),
946+
"Error! Found HommeDynamics internal field not restarted.\n"
947+
" - field name: " + f.get_header().get_identifier().name() + "\n");
948+
}
946949
}
947950

948951
using TPF = ekat::TeamPolicyFactory<KT::ExeSpace>;
@@ -1320,7 +1323,7 @@ void HommeDynamics::update_pressure(const std::shared_ptr<const AbstractGrid>& g
13201323
const auto p_int_view = get_field_out("p_int",gn).get_view<Pack**>();
13211324
const auto p_mid_view = get_field_out("p_mid",gn).get_view<Pack**>();
13221325

1323-
const auto qv_view = get_field_in("qv").get_view<const Pack**>();
1326+
const auto qv_view = get_field_in("qv",gn).get_view<const Pack**>();
13241327
const auto dp_dry_view = get_field_out("pseudo_density_dry").get_view<Pack**>();
13251328
const auto p_dry_int_view = get_field_out("p_dry_int").get_view<Pack**>();
13261329
const auto p_dry_mid_view = get_field_out("p_dry_mid").get_view<Pack**>();

components/eamxx/src/physics/rrtmgp/eamxx_rrtmgp_process_interface.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,12 +1219,17 @@ void RRTMGPRadiation::run_impl (const double dt) {
12191219
// =========================================================================================
12201220

12211221
void RRTMGPRadiation::finalize_impl () {
1222-
m_gas_concs_k.reset();
1223-
// Finalize the interface, passing a bool for rank 0
1224-
// to print info about memory stats on that rank
1225-
interface_t::rrtmgp_finalize(m_comm.am_i_root());
1226-
1227-
finalize_kls();
1222+
// Guard the finalization, since it would throw if initialize was not called.
1223+
// This can happen if an atm proc that is inited before RRTMGP throws during init,
1224+
// and the stack gets destroyed. The driver calls the 'finalize' method on all atm procs
1225+
if (is_initialized()) {
1226+
m_gas_concs_k.reset();
1227+
// Finalize the interface, passing a bool for rank 0
1228+
// to print info about memory stats on that rank
1229+
interface_t::rrtmgp_finalize(m_comm.am_i_root());
1230+
1231+
finalize_kls();
1232+
}
12281233
}
12291234
// =========================================================================================
12301235

0 commit comments

Comments
 (0)