Skip to content

Commit

Permalink
tests for save_mesh opts, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Sep 14, 2020
1 parent 8807a3f commit 0638d3f
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 69 deletions.
32 changes: 0 additions & 32 deletions src/libs/relay/conduit_relay_io_blueprint.cpp
Expand Up @@ -599,38 +599,9 @@ void save_mesh(const Node &mesh,
#endif
}

// //-----------------------------------------------------------------------------
// void save_mesh(const Node &mesh,
// const std::string &path,
// int num_files
// CONDUIT_RELAY_COMMUNICATOR_ARG(MPI_Comm mpi_comm))
// {
// #ifdef CONDUIT_RELAY_IO_MPI_ENABLED
// save_mesh(mesh,
// path,
// detail::identify_protocol(path),
// num_files, // number of files (-1 == # of domains)
// mpi_comm);
// #else
// save_mesh(mesh,
// path,
// detail::identify_protocol(path),
// num_files); // number of files (-1 == # of domains)
// #endif
// }

//-----------------------------------------------------------------------------
// Main Mesh Blueprint Save, taken from Ascent
//-----------------------------------------------------------------------------
// void save_mesh(const Node &mesh,
// const std::string &path,
// const std::string &file_protocol,
// const Node &opts,
// CONDUIT_RELAY_COMMUNICATOR_ARG(MPI_Comm mpi_comm))
// {
//
// }

// opts:
// file_style: "default", "root_only", "multi_file"
// when # of domains == 1, "default" ==> "root_only"
Expand Down Expand Up @@ -750,7 +721,6 @@ void save_mesh(const Node &mesh,
{
if(opts_suffix == "cycle")
{
opts_suffix = "none";
static std::map<std::string,int> counters;
CONDUIT_INFO("Blueprint save: no 'state/cycle' present."
" Defaulting to counter");
Expand Down Expand Up @@ -1220,8 +1190,6 @@ void save_mesh(const Node &mesh,
root["file_pattern"] = output_file_pattern;
root["tree_pattern"] = output_tree_pattern;

relay::io::save(root,root_filename + "TEST", file_protocol);
//relay::io::save_merged(root,root_filename, file_protocol);
relay::io::IOHandle hnd;
hnd.open(root_filename, file_protocol);
hnd.write(root);
Expand Down
15 changes: 2 additions & 13 deletions src/libs/relay/conduit_relay_io_blueprint.hpp
Expand Up @@ -107,32 +107,20 @@ void CONDUIT_RELAY_API save_mesh(const conduit::Node &mesh,
/// file_style: "default", "root_only", "multi_file"
/// when # of domains == 1, "default" ==> "root_only"
/// else, "default" ==> "multi_file"
/// suffix: "default", "cycle", "off"
/// suffix: "default", "cycle", "none"
/// if cycle info is present "default" ==> "cycle"
/// else, "default" ==> "off"
/// number_of_files: {# of files}
/// when "multi_file":
/// <= 0, use # of files == # of domains
/// > 0, # of files == number_of_files
///

//-----------------------------------------------------------------------------
void CONDUIT_RELAY_API save_mesh(const conduit::Node &mesh,
const std::string &path,
const std::string &protocol,
const conduit::Node &opts);

// //-----------------------------------------------------------------------------
// void CONDUIT_RELAY_API save_mesh(const conduit::Node &mesh,
// const std::string &path,
// const std::string &protocol);
//
//
// void CONDUIT_RELAY_API save_mesh(const conduit::Node &mesh,
// const std::string &path,
// const std::string &protocol,
// int number_of_files);


//-----------------------------------------------------------------------------
// Load a blueprint mesh from root + file set
Expand All @@ -149,6 +137,7 @@ void CONDUIT_RELAY_API load_mesh(const std::string &root_file_path,
/// mesh_name: "{name}"
/// provide explicit mesh name, for cases where bp data includes
/// more than one mesh.
//-----------------------------------------------------------------------------
void CONDUIT_RELAY_API load_mesh(const std::string &root_file_path,
const conduit::Node &opts,
conduit::Node &mesh);
Expand Down
22 changes: 20 additions & 2 deletions src/libs/relay/conduit_relay_mpi_io_blueprint.hpp
Expand Up @@ -110,6 +110,21 @@ void CONDUIT_RELAY_API save_mesh(const conduit::Node &mesh,
const std::string &protocol,
MPI_Comm comm);


//-----------------------------------------------------------------------------
///
/// opts:
/// file_style: "default", "root_only", "multi_file"
/// when # of domains == 1, "default" ==> "root_only"
/// else, "default" ==> "multi_file"
/// suffix: "default", "cycle", "none"
/// if cycle info is present "default" ==> "cycle"
/// else, "default" ==> "off"
/// number_of_files: {# of files}
/// when "multi_file":
/// <= 0, use # of files == # of domains
/// > 0, # of files == number_of_files
///
//-----------------------------------------------------------------------------
void CONDUIT_RELAY_API save_mesh(const conduit::Node &mesh,
const std::string &path,
Expand All @@ -128,8 +143,11 @@ void CONDUIT_RELAY_API load_mesh(const std::string &root_file_path,
MPI_Comm comm);

//-----------------------------------------------------------------------------
/// Variant with explicit mesh name, for cases where bp data includes
/// more than one mesh.
///
/// opts:
/// mesh_name: "{name}"
/// provide explicit mesh name, for cases where bp data includes
/// more than one mesh.
//-----------------------------------------------------------------------------
void CONDUIT_RELAY_API load_mesh(const std::string &root_file_path,
const conduit::Node &opts,
Expand Down
136 changes: 114 additions & 22 deletions src/tests/blueprint/t_blueprint_mesh_examples.cpp
Expand Up @@ -806,43 +806,135 @@ TEST(conduit_blueprint_mesh_examples, save_load_mesh)
//-----------------------------------------------------------------------------
TEST(conduit_blueprint_mesh_examples, save_load_mesh_opts)
{
// TODO WIP


Node io_protos;
relay::io::about(io_protos["io"]);
bool hdf5_enabled = io_protos["io/protocols/hdf5"].as_string() == "enabled";
if(!hdf5_enabled)
{
CONDUIT_INFO("HDF5 disabled, skipping spiral_multi_file test");
CONDUIT_INFO("HDF5 disabled, skipping save_load_mesh_opts test");
return;
}

std::string output_base = "tout_relay_mesh_save_load";
// spiral with 3 domains
Node data;
conduit::blueprint::mesh::examples::spiral(3,data);
blueprint::mesh::examples::braid("uniform",
2,
2,
2,
data);

// spiral doesn't have domain ids, lets add some so we diff clean
data.child(0)["state/domain_id"] = 0;
data.child(1)["state/domain_id"] = 1;
data.child(2)["state/domain_id"] = 2;
//
// suffix
//

// suffix: default, cycle, none, garbage

std::string tout_base = "tout_relay_bp_mesh_opts_suffix";

Node opts;
opts["number_of_files"] = -1;
relay::io::blueprint::save_mesh(data, output_base, "hdf5", opts);
opts["file_style"] = "root_only";

data.print();
Node n_read, info;
relay::io::blueprint::load_mesh(output_base + ".cycle_000000.root",
n_read);
//
opts["suffix"] = "default";
if(conduit::utils::is_file(tout_base + ".cycle_000100.root") )
{
utils::remove_directory(tout_base + ".cycle_000100.root");
}

relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".root"));


// remove cycle from braid, default behavior will be diff
data.remove("state/cycle");


if(conduit::utils::is_file(tout_base + ".root") )
{
utils::remove_directory(tout_base + ".root");
}

relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".root"));

//
opts["suffix"] = "cycle";

if(conduit::utils::is_file(tout_base + ".cycle_000000.root") )
{
utils::remove_directory(tout_base + ".cycle_000000.root");
}

relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".cycle_000000.root"));

//
opts["suffix"] = "none";

if(conduit::utils::is_file(tout_base + ".root") )
{
utils::remove_directory(tout_base + ".root");
}
relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".root"));

// this should error
opts["suffix"] = "garbage";
EXPECT_THROW(relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts),Error);


//
// file style
//
// default, root_only, multi_file, garbage

tout_base = "tout_relay_bp_mesh_opts_file_style";

opts["file_style"] = "default";
opts["suffix"] = "none";

if(conduit::utils::is_file(tout_base + ".root") )
{
utils::remove_directory(tout_base + ".root");
}

relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".root"));

opts["file_style"] = "root_only";

if(conduit::utils::is_file(tout_base + ".root") )
{
utils::remove_directory(tout_base + ".root");
}

relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".root"));


opts["file_style"] = "multi_file";

if(conduit::utils::is_file(tout_base + ".root") )
{
utils::remove_directory(tout_base + ".root");
}

if(conduit::utils::is_directory(tout_base) )
{
utils::remove_directory(tout_base);
}

relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts);
EXPECT_TRUE(conduit::utils::is_file( tout_base + ".root"));
EXPECT_TRUE(conduit::utils::is_file(
conduit::utils::join_file_path(tout_base,
"domain_000000.hdf5")));


opts["file_style"] = "garbage";

EXPECT_THROW(relay::io::blueprint::save_mesh(data, tout_base, "hdf5", opts),Error);

n_read.print();
// reading back in will add domain_zzzzzz names, check children of read

data.child(0).diff(n_read.child(0),info);
data.child(1).diff(n_read.child(1),info);
data.child(2).diff(n_read.child(2),info);
}


Expand Down

0 comments on commit 0638d3f

Please sign in to comment.