Skip to content

Commit

Permalink
Add initalize function, keep constructor defaulted
Browse files Browse the repository at this point in the history
  • Loading branch information
tcclevenger committed Oct 15, 2024
1 parent 225e29c commit 2a600d9
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 69 deletions.
31 changes: 17 additions & 14 deletions components/eamxx/src/control/atmosphere_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,13 @@ void AtmosphereDriver::create_output_managers () {
auto params = io_params.sublist("model_restart");
params.set<std::string>("Averaging Type","Instant");
params.sublist("provenance") = m_atm_params.sublist("provenance");
m_output_managers.emplace_back(m_atm_comm,
params,
m_run_t0,
m_case_t0,
/*is_model_restart_output*/ true);

auto& om = m_output_managers.emplace_back();
om.initialize(m_atm_comm,
params,
m_run_t0,
m_case_t0,
/*is_model_restart_output*/ true);

// Store the "Output Control" pl of the model restart as the "Checkpoint Control" for all other output streams
checkpoint_params.set<std::string>("frequency_units",params.sublist("output_control").get<std::string>("frequency_units"));
Expand All @@ -727,11 +729,12 @@ void AtmosphereDriver::create_output_managers () {
}
params.sublist("provenance") = m_atm_params.sublist("provenance");

m_output_managers.emplace_back(m_atm_comm,
params,
m_run_t0,
m_case_t0,
/*is_model_restart_output*/ false);
auto& om = m_output_managers.emplace_back();
om.initialize(m_atm_comm,
params,
m_run_t0,
m_case_t0,
/*is_model_restart_output*/ false);
}

m_ad_status |= s_output_created;
Expand Down Expand Up @@ -1632,10 +1635,10 @@ void AtmosphereDriver::run (const int dt) {
start_timer("EAMxx::run");

// DEBUG option: Check if user has set the run to fail at a specific timestep.
auto& debug = m_atm_params.sublist("driver_debug_options");
auto fail_step = debug.get<int>("force_crash_nsteps",-1);
if (fail_step==m_current_ts.get_num_steps()) {
std::abort();
auto& debug = m_atm_params.sublist("driver_debug_options");
auto fail_step = debug.get<int>("force_crash_nsteps",-1);
if (fail_step==m_current_ts.get_num_steps()) {
std::abort();
}

// Make sure the end of the time step is after the current start_time
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/dynamics/homme/tests/dyn_grid_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ TEST_CASE("dyn_grid_io")
out_params.sublist("output_control").set<std::string>("frequency_units","nsteps");
out_params.set<std::string>("Floating Point Precision","real");

OutputManager output(comm, out_params, t0, false);
OutputManager output;
output.initialize(comm, out_params, t0, false);
output.setup (fm_dyn, gm);
output.run(t0);
output.finalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ create_om (const std::string& filename_prefix,
ctrl_pl.set("Frequency",1);
ctrl_pl.set("save_grid_data",false);

auto om = std::make_shared<OutputManager>(comm,params,t0,false);
auto om = std::make_shared<OutputManager>();
om->initialize(comm,params,t0,false);
om->setup(fm,gm);
return om;
}
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/python/libpyscream/pyatmproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ struct PyAtmProc {

// Create/setup the output mgr
output_mgr = std::make_shared<OutputManager>();
output_mgr->setup(comm,params,fms,gm,t0,t0,false);
output_mgr->initialize(comm, params, t0, false);
output_mgr->setup(fms,gm);
output_mgr->set_logger(ap->get_logger());
}

Expand Down
18 changes: 9 additions & 9 deletions components/eamxx/src/share/io/scream_output_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
namespace scream
{
OutputManager::
OutputManager (const ekat::Comm& io_comm, const ekat::ParameterList& params,
const util::TimeStamp& run_t0, const util::TimeStamp& case_t0,
const bool is_model_restart_output)
~OutputManager ()
{
finalize();
}

void OutputManager::
initialize(const ekat::Comm& io_comm, const ekat::ParameterList& params,
const util::TimeStamp& run_t0, const util::TimeStamp& case_t0,
const bool is_model_restart_output)
{
// Sanity checks
EKAT_REQUIRE_MSG (run_t0.is_valid(),
Expand All @@ -39,12 +45,6 @@ OutputManager (const ekat::Comm& io_comm, const ekat::ParameterList& params,
m_is_model_restart_output = is_model_restart_output;
}

OutputManager::
~OutputManager ()
{
finalize();
}

void OutputManager::
setup (const std::shared_ptr<fm_type>& field_mgr,
const std::shared_ptr<const gm_type>& grids_mgr)
Expand Down
29 changes: 17 additions & 12 deletions components/eamxx/src/share/io/scream_output_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,30 @@ class OutputManager
using globals_map_t = std::map<std::string,ekat::any>;

// Constructor(s) & Destructor
OutputManager (const ekat::Comm& io_comm, const ekat::ParameterList& params,
const util::TimeStamp& run_t0, const util::TimeStamp& case_t0,
const bool is_model_restart_output);
OutputManager (const ekat::Comm& io_comm, const ekat::ParameterList& params,
const util::TimeStamp& run_t0,
const bool is_model_restart_output)
: OutputManager(io_comm, params, run_t0, run_t0, is_model_restart_output) {}

OutputManager() = default;
virtual ~OutputManager ();

// Set up the manager, creating all output streams. Inputs:
// Initialize
// - params: the parameter list with file/fields info, as well as method of output options
// - field_mgr/field_mgrs: field manager(s) storing fields to be outputed
// - grids_mgr: grid manager to create remapping from field managers grids onto the IO grid.
// This is needed, e.g., when outputing SEGrid fields without duplicating dofs.
// - run_t0: the timestamp of the start of the current simulation
// - case_t0: the timestamp of the start of the overall simulation (precedes run_r0 for
// a restarted simulation. Restart logic is triggered *only* if case_t0<run_t0.
// - is_model_restart_output: whether this output stream is to write a model restart file
void initialize (const ekat::Comm& io_comm, const ekat::ParameterList& params,
const util::TimeStamp& run_t0, const util::TimeStamp& case_t0,
const bool is_model_restart_output);

void initialize (const ekat::Comm& io_comm, const ekat::ParameterList& params,
const util::TimeStamp& run_t0,
const bool is_model_restart_output) {
initialize(io_comm, params, run_t0, run_t0, is_model_restart_output);
}

// Set up the manager, creating all output streams.
// Inputs:
// - field_mgr/field_mgrs: field manager(s) storing fields to be outputed
// - grids_mgr: grid manager to create remapping from field managers grids onto the IO grid.
// This is needed, e.g., when outputing SEGrid fields without duplicating dofs.
void setup (const std::shared_ptr<fm_type>& field_mgr,
const std::shared_ptr<const gm_type>& grids_mgr);

Expand Down
14 changes: 7 additions & 7 deletions components/eamxx/src/share/io/tests/io_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ void write (const std::string& avg_type, const std::string& freq_units,
ctrl_pl.set("Frequency",freq);
ctrl_pl.set("save_grid_data",false);

// Attempt to use invalid fp precision string
{
om_pl.set("Floating Point Precision",std::string("triple"));
OutputManager om(comm,om_pl,t0,false);
REQUIRE_THROWS (om.setup(fm,gm));
}
// Create Output manager
OutputManager om;

// Attempt to use invalid fp precision string
om_pl.set("Floating Point Precision",std::string("triple"));
om.initialize(comm,om_pl,t0,false);
REQUIRE_THROWS (om.setup(fm,gm));
om_pl.set("Floating Point Precision",std::string("single"));
OutputManager om(comm,om_pl,t0,false);
om.initialize(comm,om_pl,t0,false);
om.setup(fm,gm);

// Time loop: ensure we always hit 3 output steps
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/tests/io_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ void write (const int seed, const ekat::Comm& comm)
ctrl_pl.set("save_grid_data",false);

// Create Output manager
OutputManager om(comm, om_pl, t0, false);
OutputManager om;
om.initialize(comm, om_pl, t0, false);
om.setup(fm,gm);

// Run output manager
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/tests/io_filled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ void write (const std::string& avg_type, const std::string& freq_units,
ctrl_pl.set("save_grid_data",false);

// Create Output manager
OutputManager om(comm,om_pl,t0,false);
OutputManager om;
om.initialize(comm,om_pl,t0,false);
om.setup(fm,gm);

// Time loop: ensure we always hit 3 output steps
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/tests/io_monthly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ void write (const int seed, const ekat::Comm& comm)
ctrl_pl.set("save_grid_data",false);

// Create Output manager
OutputManager om(comm,om_pl,t0,false);
OutputManager om;
om.initialize(comm,om_pl,t0,false);
om.setup(fm,gm);

// Time loop: do 11 steps, since we already did Jan output at t0
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/tests/io_packed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ void write (const int freq, const int seed, const int ps, const ekat::Comm& comm
ctrl_pl.set("save_grid_data",false);

// Create Output manager
OutputManager om(comm,om_pl,t0,false);
OutputManager om;
om.initialize(comm,om_pl,t0,false);
om.setup(fm,gm);

// Run output manager
Expand Down
17 changes: 9 additions & 8 deletions components/eamxx/src/share/io/tests/io_remap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,12 @@ TEST_CASE("io_remap_test","io_remap_test")
// Setup remapped output streams and run them
print (" -> Create output ... \n",io_comm);
register_diagnostics();
OutputManager om_source, om_vert, om_horiz, om_vert_horiz;
const int p_ref = (int)set_pressure(p_top, p_bot, nlevs_src+1,nlevs_src-1);
auto source_remap_control = set_output_params("remap_source",remap_filename,p_ref,false,false);
auto vert_remap_control = set_output_params("remap_vertical",remap_filename,p_ref,true,false);
auto horiz_remap_control = set_output_params("remap_horizontal",remap_filename,p_ref,false,true);
auto vert_horiz_remap_control = set_output_params("remap_vertical_horizontal",remap_filename,p_ref,true,true);
OutputManager om_source(io_comm,source_remap_control,t0,false),
om_vert(io_comm,vert_remap_control,t0,false),
om_horiz(io_comm,horiz_remap_control,t0,false),
om_vert_horiz(io_comm,vert_horiz_remap_control,t0,false);

print (" -> source data ... \n",io_comm);
auto source_remap_control = set_output_params("remap_source",remap_filename,p_ref,false,false);
om_source.initialize(io_comm,source_remap_control,t0,false);
om_source.setup(field_manager,gm);
io_comm.barrier();
om_source.init_timestep(t0,dt);
Expand All @@ -248,6 +243,8 @@ TEST_CASE("io_remap_test","io_remap_test")
print (" -> source data ... done\n",io_comm);

print (" -> vertical remap ... \n",io_comm);
auto vert_remap_control = set_output_params("remap_vertical",remap_filename,p_ref,true,false);
om_vert.initialize(io_comm,vert_remap_control,t0,false);
om_vert.setup(field_manager,gm);
io_comm.barrier();
om_vert.init_timestep(t0,dt);
Expand All @@ -256,6 +253,8 @@ TEST_CASE("io_remap_test","io_remap_test")
print (" -> vertical remap ... done\n",io_comm);

print (" -> horizontal remap ... \n",io_comm);
auto horiz_remap_control = set_output_params("remap_horizontal",remap_filename,p_ref,false,true);
om_horiz.initialize(io_comm,horiz_remap_control,t0,false);
om_horiz.setup(field_manager,gm);
io_comm.barrier();
om_horiz.init_timestep(t0,dt);
Expand All @@ -264,6 +263,8 @@ TEST_CASE("io_remap_test","io_remap_test")
print (" -> horizontal remap ... done\n",io_comm);

print (" -> vertical-horizontal remap ... \n",io_comm);
auto vert_horiz_remap_control = set_output_params("remap_vertical_horizontal",remap_filename,p_ref,true,true);
om_vert_horiz.initialize(io_comm,vert_horiz_remap_control,t0,false);
om_vert_horiz.setup(field_manager,gm);
io_comm.barrier();
om_vert_horiz.init_timestep(t0,dt);
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/tests/io_se_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ TEST_CASE("se_grid_io")
ctl_pl.set("Frequency",1);
ctl_pl.set<std::string>("frequency_units","nsteps");

OutputManager om(io_comm,params,t0,false);
OutputManager om;
om.initialize(io_comm,params,t0,false);
om.setup(fm0,gm);
om.init_timestep(t0,dt);
om.run(t0+dt);
Expand Down
3 changes: 2 additions & 1 deletion components/eamxx/src/share/io/tests/output_restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ TEST_CASE("output_restart","io")
const util::TimeStamp& run_t0,
const int nsteps)
{
OutputManager output_manager(comm, output_params, run_t0, case_t0, false);
OutputManager output_manager;
output_manager.initialize(comm, output_params, run_t0, case_t0, false);
output_manager.setup(fm,gm);

// We advance the fields, by adding dt to each entry of the fields at each time step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ Real my_pdf(std::mt19937_64& engine) {
class OutputManager4Test : public scream::OutputManager
{
public:
OutputManager4Test(const ekat::Comm& io_comm,
const ekat::ParameterList& params,
const util::TimeStamp& run_t0)
: OutputManager(io_comm, params,run_t0, false)
OutputManager4Test()
: OutputManager()
{
// Do Nothing
}
Expand Down Expand Up @@ -399,7 +397,8 @@ std::vector<std::string> create_test_data_files(
ctrl_pl.set("save_grid_data",false);
// Create an output manager, note we use a subclass defined in this test so we can extract
// the list of files created by the output manager.
OutputManager4Test om(comm,om_pl,t0);
OutputManager4Test om;
om.initialize(comm,om_pl,t0);
om.setup(fm,gm);

// Time loop to create and write data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ Real test_func(const int col, const int t) {
class OutputManager4Test : public scream::OutputManager
{
public:
OutputManager4Test(const ekat::Comm& io_comm,
const ekat::ParameterList& params,
const util::TimeStamp& run_t0)
: OutputManager(io_comm, params,run_t0, false) {}
OutputManager4Test() = default;

void runme(const util::TimeStamp& ts) {
run(ts);
Expand Down Expand Up @@ -102,7 +99,8 @@ std::vector<std::string> create_from_file_test_data(const ekat::Comm& comm, cons
ctrl_pl.set("frequency_units",std::string("nsteps"));
ctrl_pl.set("Frequency",1);
ctrl_pl.set("save_grid_data",false);
OutputManager4Test om(comm,om_pl,t0);
OutputManager4Test om;
om.initialize(comm,om_pl,t0,false);
om.setup(fm,gm);
// Create output data:
// T=3600, well above the max timestep for the test.
Expand Down

0 comments on commit 2a600d9

Please sign in to comment.