Skip to content

Commit

Permalink
enhancements to matset to_silo (#677)
Browse files Browse the repository at this point in the history
* enhancements to matset to_silo

* fix missing hdf5 guard, use diff to check to_silo results

* fix from joe for unibuffer case
  • Loading branch information
cyrush committed Jan 13, 2021
1 parent 51d0b71 commit f04d8fe
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 127 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
- Added `truncate` option to `conduit::relay::io::blueprint::write_mesh`, this is used by `save_mesh`.
- Improve capture and reporting of I/O errors in `conduit::relay::[mpi::]io::blueprint::{save_mesh|write_mesh}`. Now in the MPI case, If any rank fails to open or write to a file all ranks will throw an exception.

#### Blueprint
- Added `conduit::blueprint::mesh::matset::to_silo()` which converts a valid blueprint matset to a node that contains arrays that follow Silo's sparse mix slot volume fraction representation.


## [0.6.0] - Released 2020-11-02

Expand Down
3 changes: 1 addition & 2 deletions src/libs/blueprint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ set(blueprint_headers
conduit_blueprint_mesh_examples.hpp
conduit_blueprint_mesh_examples_julia.hpp
conduit_blueprint_mesh_examples_venn.hpp
conduit_blueprint_util_mesh.hpp
conduit_blueprint_mcarray.hpp
conduit_blueprint_mcarray_examples.hpp
conduit_blueprint_o2mrelation.hpp
Expand All @@ -48,10 +47,10 @@ set(blueprint_c_headers
set(blueprint_sources
conduit_blueprint.cpp
conduit_blueprint_mesh.cpp
conduit_blueprint_mesh_matset_xforms.cpp
conduit_blueprint_mesh_examples.cpp
conduit_blueprint_mesh_examples_julia.cpp
conduit_blueprint_mesh_examples_venn.cpp
conduit_blueprint_util_mesh.cpp
conduit_blueprint_mcarray.cpp
conduit_blueprint_mcarray_examples.cpp
conduit_blueprint_o2mrelation.cpp
Expand Down
2 changes: 0 additions & 2 deletions src/libs/blueprint/conduit_blueprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "conduit_blueprint_mesh_examples_julia.hpp"
#include "conduit_blueprint_mesh_examples_venn.hpp"

#include "conduit_blueprint_util_mesh.hpp"

#include "conduit_blueprint_o2mrelation.hpp"
#include "conduit_blueprint_o2mrelation_examples.hpp"
#include "conduit_blueprint_o2mrelation_iterator.hpp"
Expand Down
11 changes: 11 additions & 0 deletions src/libs/blueprint/conduit_blueprint_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,17 @@ namespace matset
//-------------------------------------------------------------------------
bool CONDUIT_BLUEPRINT_API is_material_dominant(const conduit::Node &n);

//-------------------------------------------------------------------------
// Converts a blueprint matset to the silo style sparse mixed slot
// representation.
//
// For details about the silo format, see documentation for
// 'DBPutMaterial' at:
// https://wci.llnl.gov/content/assets/docs/simulation/computer-codes/silo/LLNL-SM-654357.pdf
void CONDUIT_BLUEPRINT_API to_silo(const conduit::Node &n,
conduit::Node &dest,
const float64 epsilon = CONDUIT_EPSILON);

//-------------------------------------------------------------------------
// blueprint::mesh::matset::index protocol interface
//-------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/libs/blueprint/conduit_blueprint_mesh_examples_venn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ void venn_sparse_by_element_matset(Node &res)
// Build the rest of the single-buffer matset
res["matsets/matset/topology"] = "topo";
// This is the "key" that tells what material each volume fraction refers to
res["matsets/matset/material_map/cir_a"] = 1;
res["matsets/matset/material_map/cir_b"] = 2;
res["matsets/matset/material_map/cir_c"] = 3;
res["matsets/matset/material_map/bg"] = 0;
res["matsets/matset/material_map/circle_a"] = 1;
res["matsets/matset/material_map/circle_b"] = 2;
res["matsets/matset/material_map/circle_c"] = 3;
res["matsets/matset/material_map/background"] = 0;

// All the volume fractions go here ("one big buffer")
res["matsets/matset/volume_fractions"].set(DataType::float64(vfcount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//-----------------------------------------------------------------------------
///
/// file: conduit_blueprint_util_mesh.cpp
/// file: conduit_blueprint_mesh_matset_xforms.cpp
///
//-----------------------------------------------------------------------------

Expand All @@ -22,7 +22,6 @@
#include "conduit_blueprint_mesh.hpp"
#include "conduit_blueprint_o2mrelation.hpp"
#include "conduit_blueprint_o2mrelation_iterator.hpp"
#include "conduit_blueprint_util_mesh.hpp"

// FIXME(JRC): The helper functions below are hackily copied over from
// 'conduit_blueprint_mesh.cpp'; these helpers should ultimately be abstracted
Expand Down Expand Up @@ -118,19 +117,13 @@ namespace blueprint
{

//-----------------------------------------------------------------------------
// -- begin conduit::blueprint::util --
//-----------------------------------------------------------------------------
namespace util
{

//-----------------------------------------------------------------------------
// -- begin conduit::blueprint::util::mesh --
// -- begin conduit::blueprint::mesh --
//-----------------------------------------------------------------------------
namespace mesh
{

//-----------------------------------------------------------------------------
// -- begin conduit::blueprint::util::mesh::matset --
// -- begin conduit::blueprint::mesh::matset --
//-----------------------------------------------------------------------------
namespace matset
{
Expand All @@ -154,7 +147,7 @@ to_silo(const conduit::Node &n,
Node matset_mat_map;
if(mset_is_unibuffer)
{
matset_mat_map.set_external(n["volume_fractions/material_map"]);
matset_mat_map.set_external(n["material_map"]);
}
else // if(!mset_is_unibuffer)
{
Expand Down Expand Up @@ -187,12 +180,12 @@ to_silo(const conduit::Node &n,
}
else // if(!mset_is_matdom)
{
// may need to do a bit of sculping here; embed the base array into
// may need to do a bit of sculpting here; embed the base array into
// something w/ "values" child, as below
Node mat_vfs;
if(mset_is_unibuffer)
{
mat_vfs["values"].set_external(n["volume_fractions/values"]);
mat_vfs.set_external(n);
}
else
{
Expand Down Expand Up @@ -253,8 +246,8 @@ to_silo(const conduit::Node &n,
(void*)mat_mids.element_ptr(mat_ind_index));
const index_t mat_id = temp.to_index_t();

// if this elem has a non-zero (or non-trival) volume fraction for this
// materal, add it do the map
// if this elem has a non-zero (or non-trivial) volume fraction for this
// material, add it do the map
if(mat_vf > epsilon)
{
elem_mat_maps[elem_index][mat_id] = mat_vf;
Expand Down Expand Up @@ -312,8 +305,8 @@ to_silo(const conduit::Node &n,
}
const index_t mat_elem = mset_is_matdom ? temp.to_index_t() : mat_index;

// if this elem has a non-zero (or non-trival) volume fraction for this
// materal, add it do the map
// if this elem has a non-zero (or non-trivial) volume fraction for this
// material, add it do the map
if(mat_vf > epsilon)
{
elem_mat_maps[mat_elem][mat_id] = mat_vf;
Expand All @@ -333,6 +326,9 @@ to_silo(const conduit::Node &n,

dest.reset();
dest["topology"].set(n["topology"]);
// in some cases, this method will sort the material names
// so always include the material map
dest["material_map"].set(matset_mat_map);
dest["matlist"].set(DataType(int_dtype.id(), mset_num_elems));
dest["mix_next"].set(DataType(int_dtype.id(), mset_num_slots));
dest["mix_mat"].set(DataType(int_dtype.id(), mset_num_slots));
Expand Down Expand Up @@ -388,7 +384,7 @@ to_silo(const conduit::Node &n,
//-----------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
// -- end conduit::blueprint::util::mesh::matset --
// -- end conduit::blueprint::mesh::matset --
//-----------------------------------------------------------------------------


Expand All @@ -397,13 +393,6 @@ to_silo(const conduit::Node &n,
// -- end conduit::blueprint::util::mesh --
//-----------------------------------------------------------------------------


}
//-----------------------------------------------------------------------------
// -- end conduit::blueprint::util --
//-----------------------------------------------------------------------------


}
//-----------------------------------------------------------------------------
// -- end conduit::blueprint --
Expand Down
86 changes: 0 additions & 86 deletions src/libs/blueprint/conduit_blueprint_util_mesh.hpp

This file was deleted.

5 changes: 4 additions & 1 deletion src/libs/relay/conduit_relay_io_blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,10 @@ void read_mesh(const std::string &root_file_path,

// assume hdf5, but check for json file
std::string root_protocol = "hdf5";
char buff[5] = {0,0,0,0,0};
// we will read the first 5 bytes, but
// make sure our buff is null termed, unless you
// want a random chance at sadness.
char buff[6] = {0,0,0,0,0,0};

// heuristic, if json, we expect to see "{" in the first 5 chars of the file.
std::ifstream ifs;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/blueprint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(BLUEPRINT_TESTS t_blueprint_smoke
t_blueprint_mesh_relay
t_blueprint_mesh_generate
t_blueprint_mesh_examples
t_blueprint_util_mesh)
t_blueprint_mesh_matset_xforms)

################################
# Add our Main Unit Tests
Expand Down
45 changes: 41 additions & 4 deletions src/tests/blueprint/t_blueprint_mesh_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,40 @@ TEST(conduit_blueprint_mesh_examples, check_gen_index_state_prop)
EXPECT_TRUE(idx.has_path("state/time"));
}



//-----------------------------------------------------------------------------
void venn_test_small_yaml(const std::string &venn_type)
{
// provide small example save to yaml for folks to look at
const int nx = 25, ny = 25;
const int nx = 4, ny = 4;
const double radius = 0.25;

Node res, info, n_idx;
blueprint::mesh::examples::venn(venn_type, nx, ny, radius, res);
blueprint::mesh::examples::venn(venn_type, nx, ny, radius, res);

EXPECT_TRUE(blueprint::mesh::verify(res, info));
blueprint::mesh::generate_index(res,"",1,n_idx);
EXPECT_TRUE(blueprint::verify("mesh/index",n_idx,info));
res.save("venn_small_example_" + venn_type + ".yaml");

std::string ofbase= "venn_small_example_" + venn_type;

// save yaml and hdf5 versions
relay::io::blueprint::save_mesh(res,
ofbase + ".yaml",
"yaml");

Node io_protos;
relay::io::about(io_protos["io"]);
bool hdf5_enabled =io_protos["io/protocols/hdf5"].as_string() == "enabled";

if(hdf5_enabled)
{
relay::io::blueprint::save_mesh(res,
ofbase+ ".blueprint_root",
"hdf5");
}

}

//-----------------------------------------------------------------------------
Expand All @@ -499,7 +519,24 @@ void venn_test(const std::string &venn_type)

std::string ofbase = "venn_example_" + venn_type;
std::cout << "[Saving " << ofbase << "]" << std::endl;
relay::io_blueprint::save(res, ofbase + ".blueprint_root");

std::string ofile_root= "venn_small_example_" + venn_type;

// save yaml and hdf5 versions
relay::io::blueprint::save_mesh(res,
ofbase + ".yaml",
"yaml");

Node io_protos;
relay::io::about(io_protos["io"]);
bool hdf5_enabled =io_protos["io/protocols/hdf5"].as_string() == "enabled";

if(hdf5_enabled)
{
relay::io::blueprint::save_mesh(res,
ofbase+ ".blueprint_root",
"hdf5");
}

{
std::cout << "[Verifying field area is correct]" << std::endl;
Expand Down
Loading

0 comments on commit f04d8fe

Please sign in to comment.