Skip to content

Commit

Permalink
rebase and fix conflicting variable usage regarding (m_)fields_inited
Browse files Browse the repository at this point in the history
  • Loading branch information
mjschmidt271 committed Jan 6, 2025
1 parent 881b558 commit e37b47b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
27 changes: 18 additions & 9 deletions components/eamxx/src/control/atmosphere_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "physics/share/physics_constants.hpp"

#include "share/scream_config.hpp"
#include "share/atm_process/atmosphere_process_group.hpp"
#include "share/atm_process/atmosphere_process_dag.hpp"
#include "share/field/field_utils.hpp"
Expand Down Expand Up @@ -694,16 +695,20 @@ void AtmosphereDriver::create_fields()
AtmProcDAG dag;
// First, add all atm processes
dag.create_dag(*m_atm_process_group);
// Write a dot file for visualization
// Write a dot file for visualizing the DAG
if (m_atm_comm.am_i_root()) {
dag.write_dag("scream_atm_createField_dag.dot", std::max(verb_lvl,0));
std::string filename = "scream_atm_createField_dag";
if (is_scream_standalone()) {
filename += ".np" + std::to_string(m_atm_comm.size());
}
filename += ".dot";
dag.write_dag(filename, verb_lvl);
}
}

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());
Expand Down Expand Up @@ -1094,7 +1099,6 @@ void AtmosphereDriver::set_initial_conditions ()
// Check which fields need to have an initial condition.
std::map<std::string,std::vector<std::string>> ic_fields_names;
std::vector<FieldIdentifier> ic_fields_to_copy;
std::map<std::string,std::vector<std::string>> fields_inited;

// Check which fields should be loaded from the topography file
std::map<std::string,std::vector<std::string>> topography_file_fields_names;
Expand Down Expand Up @@ -1123,7 +1127,7 @@ void AtmosphereDriver::set_initial_conditions ()
EKAT_ERROR_MSG ("ERROR: invalid assignment for variable " + fname + ", only scalar "
"double or string, or vector double arguments are allowed");
}
fields_inited[grid_name].push_back(fname);
m_fields_inited[grid_name].push_back(fname);
} else if (fname == "phis" or fname == "sgh30") {
// Both phis and sgh30 need to be loaded from the topography file
auto& this_grid_topo_file_fnames = topography_file_fields_names[grid_name];
Expand Down Expand Up @@ -1226,7 +1230,7 @@ void AtmosphereDriver::set_initial_conditions ()
auto p = f.get_header().get_parent().lock();
if (p) {
const auto& pname = p->get_identifier().name();
if (ekat::contains(fields_inited[grid_name],pname)) {
if (ekat::contains(m_fields_inited[grid_name],pname)) {
// The parent is already inited. No need to init this field as well.
names.erase(it2);
run_again = true;
Expand Down Expand Up @@ -1448,7 +1452,7 @@ void AtmosphereDriver::set_initial_conditions ()
// Loop through fields and apply perturbation.
for (size_t f=0; f<perturbed_fields.size(); ++f) {
const auto fname = perturbed_fields[f];
EKAT_REQUIRE_MSG(ekat::contains(fields_inited[fm->get_grid()->name()], fname),
EKAT_REQUIRE_MSG(ekat::contains(m_fields_inited[fm->get_grid()->name()], fname),
"Error! Attempting to apply perturbation to field not in initial_conditions.\n"
" - Field: "+fname+"\n"
" - Grid: "+fm->get_grid()->name()+"\n");
Expand Down Expand Up @@ -1659,9 +1663,14 @@ void AtmosphereDriver::initialize_atm_procs ()
dag.create_dag(*m_atm_process_group);
// process the initial conditions to maybe fulfill unmet dependencies
dag.process_initial_conditions(m_fields_inited);
// Write a dot file for visualization
// Write a dot file for visualizing the DAG
if (m_atm_comm.am_i_root()) {
dag.write_dag("scream_atm_initProc_dag.dot", std::max(verb_lvl,0));
std::string filename = "scream_atm_initProc_dag";
if (is_scream_standalone()) {
filename += ".np" + std::to_string(m_atm_comm.size());
}
filename += ".dot";
dag.write_dag(filename, verb_lvl);
}
}
}
Expand Down
32 changes: 19 additions & 13 deletions components/eamxx/src/share/atm_process/atmosphere_process_dag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@ void AtmProcDAG::write_dag (const std::string& fname, const int verbosity) const

for (const auto& fid : n.computed) {
std::string fc = "<font color=\"";
int fid_out = std::abs(fid);
fc += "black";
fc += "\"> ";
ofile << " <tr><td align=\"left\">" << fc
<< html_fix(print_fid(m_fids[fid],fid_verb))
<< html_fix(print_fid(m_fids[fid_out], fid_verb))
<< "</font></td></tr>\n";
}
}
Expand Down Expand Up @@ -279,9 +280,6 @@ void AtmProcDAG::write_dag (const std::string& fname, const int verbosity) const
for (const auto& gr_fid : n.gr_computed) {
std::string fc = "<font color=\"";
fc += "black";
// i suspect this, and the below, is a typo, since a computed group
// being marked unmet doesn't make sense to me
// fc += (ekat::contains(unmet,gr_fid) ? "red" : "black");
fc += "\"> ";
ofile << " <tr><td align=\"left\">" << fc << html_fix(print_fid(m_fids[gr_fid],fid_verb));
ofile << "</font></td></tr>\n";
Expand Down Expand Up @@ -613,6 +611,7 @@ void AtmProcDAG::process_initial_conditions(const grid_field_map &ic_inited) {
if (ic_inited.size() == 0) {
return;
}
std::set<int> to_be_marked;
for (auto &node : m_nodes) {
if (m_unmet_deps.at(node.id).empty()) {
continue;
Expand All @@ -621,32 +620,39 @@ void AtmProcDAG::process_initial_conditions(const grid_field_map &ic_inited) {
auto &node_unmet_fields = m_unmet_deps.at(node.id);
// add the current node as a child of the IC node
ic_node.children.push_back(node.id);
for (auto um_fid : node_unmet_fields) {
for (auto &um_fid : node_unmet_fields) {
for (auto &it1 : ic_inited) {
const auto &grid_name = it1.first;
// if this unmet-dependency field's name is in the ic_inited map for
// the provided grid_name key, then we flip its value negative and
// break from the for (ic_inited) and for (node_unmet_fields) loops;
// otherwise, keep trying for the next grid_name
// the provided grid_name key, we record the field id in to_be_marked
// (because changing it messes up the iterator)
if (ekat::contains(ic_inited.at(grid_name), m_fids[um_fid].name())) {
auto id_now_met = node_unmet_fields.extract(um_fid);
id_now_met.value() = -id_now_met.value();
node_unmet_fields.insert(std::move(id_now_met));
to_be_marked.insert(um_fid);
// add the fid of the formerly unmet dep to the initial condition
// node's computed list
ic_node.computed.insert(um_fid);
goto endloop;
} else {
continue;
}
}
endloop:;
}
if (to_be_marked.empty()) {
continue;
} else {
// change the previously unmet dependency's field id to be negative,
// indicating that it is now met and provided by the initial condition
for (auto &fid : to_be_marked) {
node_unmet_fields.erase(fid);
node_unmet_fields.insert(-fid);
}
}
}
}
m_IC_processed = true;
}



int AtmProcDAG::add_fid (const FieldIdentifier& fid) {
auto it = ekat::find(m_fids,fid);
if (it==m_fids.end()) {
Expand Down

0 comments on commit e37b47b

Please sign in to comment.