Skip to content

Commit

Permalink
Merge 85f42c7 into 9cc085a
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Apr 28, 2021
2 parents 9cc085a + 85f42c7 commit 13f7fbf
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 80 deletions.
171 changes: 91 additions & 80 deletions src/libs/blueprint/conduit_blueprint_mesh.cpp
Expand Up @@ -1532,110 +1532,121 @@ mesh::generate_index(const Node &mesh,
index_out["state/path"] = join_path(ref_path, "state");
}

NodeConstIterator itr = mesh["coordsets"].children();
while(itr.has_next())
{
const Node &coordset = itr.next();
std::string coordset_name = itr.name();
Node &idx_coordset = index_out["coordsets"][coordset_name];
// an empty node is a valid blueprint mesh
// so we nede to check for coordsets, can't assume they exist

std::string coordset_type = coordset["type"].as_string();
idx_coordset["type"] = coordset_type;
if(coordset_type == "uniform")
if(mesh.has_child("coordsets"))
{
NodeConstIterator itr = mesh["coordsets"].children();
while(itr.has_next())
{
// default to cartesian, but check if origin or spacing exist
// b/c they may name axes from cyln or sph
if(coordset.has_child("origin"))
const Node &coordset = itr.next();
std::string coordset_name = itr.name();
Node &idx_coordset = index_out["coordsets"][coordset_name];

std::string coordset_type = coordset["type"].as_string();
idx_coordset["type"] = coordset_type;
if(coordset_type == "uniform")
{
NodeConstIterator origin_itr = coordset["origin"].children();
while(origin_itr.has_next())
// default to cartesian, but check if origin or spacing exist
// b/c they may name axes from cyln or sph
if(coordset.has_child("origin"))
{
origin_itr.next();
idx_coordset["coord_system/axes"][origin_itr.name()];
NodeConstIterator origin_itr = coordset["origin"].children();
while(origin_itr.has_next())
{
origin_itr.next();
idx_coordset["coord_system/axes"][origin_itr.name()];
}
}
}
else if(coordset.has_child("spacing"))
{
NodeConstIterator spacing_itr = coordset["spacing"].children();
while(spacing_itr.has_next())
else if(coordset.has_child("spacing"))
{
spacing_itr.next();
std::string axis_name = spacing_itr.name();
NodeConstIterator spacing_itr = coordset["spacing"].children();
while(spacing_itr.has_next())
{
spacing_itr.next();
std::string axis_name = spacing_itr.name();

// if spacing names start with "d", use substr
// to determine axis name

// otherwise use spacing name directly, to avoid empty
// path fetch if just 'x', etc are passed
if(axis_name[0] == 'd' && axis_name.size() > 1)
{
axis_name = axis_name.substr(1);
}
idx_coordset["coord_system/axes"][axis_name];
}
}
else
{
// assume cartesian
index_t num_comps = coordset["dims"].number_of_children();

// if spacing names start with "d", use substr
// to determine axis name
if(num_comps > 0)
{
idx_coordset["coord_system/axes/x"];
}

// otherwise use spacing name directly, to avoid empty
// path fetch if just 'x', etc are passed
if(axis_name[0] == 'd' && axis_name.size() > 1)
if(num_comps > 1)
{
axis_name = axis_name.substr(1);
idx_coordset["coord_system/axes/y"];
}

if(num_comps > 2)
{
idx_coordset["coord_system/axes/z"];
}
idx_coordset["coord_system/axes"][axis_name];
}
}
else
{
// assume cartesian
index_t num_comps = coordset["dims"].number_of_children();

if(num_comps > 0)
// use child names as axes
NodeConstIterator values_itr = coordset["values"].children();
while(values_itr.has_next())
{
idx_coordset["coord_system/axes/x"];
values_itr.next();
idx_coordset["coord_system/axes"][values_itr.name()];
}

if(num_comps > 1)
{
idx_coordset["coord_system/axes/y"];
}

if(num_comps > 2)
{
idx_coordset["coord_system/axes/z"];
}
}
}
else
{
// use child names as axes
NodeConstIterator values_itr = coordset["values"].children();
while(values_itr.has_next())
{
values_itr.next();
idx_coordset["coord_system/axes"][values_itr.name()];
}
}

idx_coordset["coord_system/type"] = bputils::coordset::coordsys(coordset);
idx_coordset["coord_system/type"] = bputils::coordset::coordsys(coordset);

std::string cs_ref_path = join_path(ref_path, "coordsets");
cs_ref_path = join_path(cs_ref_path, coordset_name);
idx_coordset["path"] = cs_ref_path;
std::string cs_ref_path = join_path(ref_path, "coordsets");
cs_ref_path = join_path(cs_ref_path, coordset_name);
idx_coordset["path"] = cs_ref_path;
}
}

itr = mesh["topologies"].children();
while(itr.has_next())
// an empty node is a valid blueprint mesh
// so we nede to check for topologies, can't assume they exist
if(mesh.has_child("topologies"))
{
const Node &topo = itr.next();
std::string topo_name = itr.name();
Node &idx_topo = index_out["topologies"][topo_name];
idx_topo["type"] = topo["type"].as_string();
idx_topo["coordset"] = topo["coordset"].as_string();

std::string tp_ref_path = join_path(ref_path,"topologies");
tp_ref_path = join_path(tp_ref_path,topo_name);
idx_topo["path"] = tp_ref_path;

// a topology may also specify a grid_function
if(topo.has_child("grid_function"))
NodeConstIterator itr = mesh["topologies"].children();
while(itr.has_next())
{
idx_topo["grid_function"] = topo["grid_function"].as_string();
const Node &topo = itr.next();
std::string topo_name = itr.name();
Node &idx_topo = index_out["topologies"][topo_name];
idx_topo["type"] = topo["type"].as_string();
idx_topo["coordset"] = topo["coordset"].as_string();

std::string tp_ref_path = join_path(ref_path,"topologies");
tp_ref_path = join_path(tp_ref_path,topo_name);
idx_topo["path"] = tp_ref_path;

// a topology may also specify a grid_function
if(topo.has_child("grid_function"))
{
idx_topo["grid_function"] = topo["grid_function"].as_string();
}
}
}

if(mesh.has_child("matsets"))
{
itr = mesh["matsets"].children();
NodeConstIterator itr = mesh["matsets"].children();
while(itr.has_next())
{
const Node &matset = itr.next();
Expand Down Expand Up @@ -1689,7 +1700,7 @@ mesh::generate_index(const Node &mesh,

if(mesh.has_child("specsets"))
{
itr = mesh["specsets"].children();
NodeConstIterator itr = mesh["specsets"].children();
while(itr.has_next())
{
const Node &specset = itr.next();
Expand All @@ -1714,7 +1725,7 @@ mesh::generate_index(const Node &mesh,

if(mesh.has_child("fields"))
{
itr = mesh["fields"].children();
NodeConstIterator itr = mesh["fields"].children();
while(itr.has_next())
{
const Node &fld = itr.next();
Expand Down Expand Up @@ -1764,7 +1775,7 @@ mesh::generate_index(const Node &mesh,

if(mesh.has_child("adjsets"))
{
itr = mesh["adjsets"].children();
NodeConstIterator itr = mesh["adjsets"].children();
while(itr.has_next())
{
const Node &adjset = itr.next();
Expand All @@ -1784,7 +1795,7 @@ mesh::generate_index(const Node &mesh,

if(mesh.has_child("nestsets"))
{
itr = mesh["nestsets"].children();
NodeConstIterator itr = mesh["nestsets"].children();
while(itr.has_next())
{
const Node &nestset = itr.next();
Expand Down
13 changes: 13 additions & 0 deletions src/tests/blueprint/t_blueprint_mesh_verify.cpp
Expand Up @@ -2685,3 +2685,16 @@ TEST(conduit_blueprint_mesh_verify, mesh_bad_spacing_name)
Node n_idx;
blueprint::mesh::generate_index(n_test,"",1,n_idx);
}

//-----------------------------------------------------------------------------
TEST(conduit_blueprint_mesh_verify, empty_mesh_vs_gen_index)
{
Node empty;
Node info;
//empty.append();
bool res = blueprint::mesh::verify(empty,info);
EXPECT_TRUE(res);
Node n_idx;
blueprint::mesh::generate_index(empty,"",1,n_idx);
}

0 comments on commit 13f7fbf

Please sign in to comment.