Skip to content

Commit

Permalink
Correct mistakes with Blueprint Silo I/O Add root file extension option
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinPrivitera committed Nov 13, 2023
1 parent 145ea8e commit e5466ed
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/libs/relay/conduit_relay_io_silo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4023,6 +4023,10 @@ write_multimats(DBfile *dbfile,
/// when cycle is present, "default" ==> "cycle"
/// else, "default" ==> "none"
///
/// root_file_ext: "default", "root", "silo"
/// "default" ==> "root"
/// if overlink, this parameter is unused.
///
/// mesh_name: (used if present, default ==> "mesh")
///
/// ovl_topo_name: (used if present, default ==> "")
Expand Down Expand Up @@ -4056,6 +4060,7 @@ void CONDUIT_RELAY_API write_mesh(const Node &mesh,

std::string opts_file_style = "default";
std::string opts_suffix = "default";
std::string opts_root_file_ext = "default";
std::string opts_out_mesh_name = "mesh"; // used only for the non-overlink case
std::string opts_ovl_topo_name = ""; // used only for the overlink case
std::string opts_silo_type = "default";
Expand Down Expand Up @@ -4095,6 +4100,21 @@ void CONDUIT_RELAY_API write_mesh(const Node &mesh,
" expected: \"default\", \"cycle\", or \"none\"");
}
}

// check for + validate root_file_ext option
if(opts.has_child("root_file_ext") && opts["root_file_ext"].dtype().is_string())
{
opts_root_file_ext = opts["root_file_ext"].as_string();

if(opts_root_file_ext != "default" &&
opts_root_file_ext != "root" &&
opts_root_file_ext != "silo" )
{
CONDUIT_ERROR("write_mesh invalid root_file_ext option: \""
<< opts_root_file_ext << "\"\n"
" expected: \"default\", \"root\", or \"silo\"");
}
}

// check for + validate mesh_name option
if(opts.has_child("mesh_name") && opts["mesh_name"].dtype().is_string())
Expand Down Expand Up @@ -4185,13 +4205,19 @@ void CONDUIT_RELAY_API write_mesh(const Node &mesh,
// silo_type = DB_TAURUS;
// }

if (opts_root_file_ext == "default")
{
opts_root_file_ext = "root";
}

// more will happen for this case later
if (opts_file_style == "overlink")
{
CONDUIT_INFO("Overlink is not yet fully supported. Outputted files "
"with this option will be missing several components "
"that Overlink requires.")
opts_suffix = "none"; // force no suffix for overlink case
opts_root_file_ext = "silo"; // force .silo file extension for root file
}

int num_files = opts_num_files;
Expand Down Expand Up @@ -4471,7 +4497,7 @@ void CONDUIT_RELAY_API write_mesh(const Node &mesh,
std::string root_filename;
if (opts_file_style == "overlink")
{
root_filename = utils::join_file_path(output_dir, "OvlTop.silo");
root_filename = utils::join_file_path(output_dir, "OvlTop." + opts_root_file_ext);
}
else
{
Expand All @@ -4484,7 +4510,7 @@ void CONDUIT_RELAY_API write_mesh(const Node &mesh,
root_filename += conduit_fmt::format(".cycle_{:06d}",cycle);
}

root_filename += ".root";
root_filename += "." + opts_root_file_ext;
}

// ----------------------------------------------------
Expand Down
43 changes: 43 additions & 0 deletions src/tests/relay/t_relay_io_silo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ TEST(conduit_relay_io_silo, unstructured_points)
/// when cycle is present, "default" ==> "cycle"
/// else, "default" ==> "none"
///
/// root_file_ext: "default", "root", "silo"
/// "default" ==> "root"
/// if overlink, this parameter is unused.
///
/// mesh_name: (used if present, default ==> "mesh")
///
/// ovl_topo_name: (used if present, default ==> "")
Expand Down Expand Up @@ -1121,6 +1125,45 @@ TEST(conduit_relay_io_silo, round_trip_save_option_suffix)
}
}

//-----------------------------------------------------------------------------
TEST(conduit_relay_io_silo, round_trip_save_option_root_file_ext)
{
const std::vector<std::string> root_file_exts = {"default", "root", "silo"};

for (int i = 0; i < root_file_exts.size(); i ++)
{
Node opts;
opts["root_file_ext"] = root_file_exts[i];

std::string actual_file_ext = root_file_exts[i];
if (actual_file_ext == "default")
{
actual_file_ext = "root";
}

const std::string basename = "round_trip_save_option_root_file_ext_" +
root_file_exts[i] + "_basic";
const std::string filename = basename + "." + actual_file_ext;

Node save_mesh, load_mesh, info;
blueprint::mesh::examples::basic("rectilinear", 3, 4, 0, save_mesh);
remove_path_if_exists(filename);
io::silo::save_mesh(save_mesh, basename, opts);
io::silo::load_mesh(filename, load_mesh);
EXPECT_TRUE(blueprint::mesh::verify(load_mesh, info));

save_mesh["state/cycle"] = (int64) 0;
save_mesh["state/domain_id"] = 0;
silo_name_changer("mesh", save_mesh);

// the loaded mesh will be in the multidomain format
// but the saved mesh is in the single domain format
EXPECT_EQ(load_mesh.number_of_children(), 1);
EXPECT_EQ(load_mesh[0].number_of_children(), save_mesh.number_of_children());
EXPECT_FALSE(load_mesh[0].diff(save_mesh, info));
}
}

//-----------------------------------------------------------------------------
TEST(conduit_relay_io_silo, round_trip_save_option_mesh_name)
{
Expand Down

0 comments on commit e5466ed

Please sign in to comment.