Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make adjset::is_canonical more strict #1227

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/libs/blueprint/conduit_blueprint_mesh_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,27 @@ bool adjset::is_canonical(const Node &adjset)
for(conduit::index_t i = 0; i < groups.number_of_children() && retval; i++)
{
auto pos = groups[i].name().find(conduit::blueprint::mesh::adjset::group_prefix());
retval &= (pos == 0);

bool canonical = (pos == 0);
if(canonical)
{
std::vector<std::string> tokens;
conduit::utils::split_string(groups[i].name(), '_', tokens);
canonical = tokens.size() >= 3;
if(canonical)
{
std::vector<int> doms;
doms.reserve(tokens.size() - 1);
// Start at 1 to skip the groups prefix.
for(size_t j = 1; j < tokens.size(); j++)
doms.push_back(atoi(tokens[j].c_str()));
// Start at 1 because we'll compare pairs. Make sure domains are sorted.
for(size_t j = 1; j < doms.size(); j++)
canonical &= doms[j - 1] < doms[j];
}
}

retval &= canonical;
}
return retval;
}
Expand Down
51 changes: 51 additions & 0 deletions src/tests/blueprint/t_blueprint_mesh_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,54 @@ TEST(conduit_blueprint_mesh_utils, topology_search_2d_nohit)
EXPECT_EQ(resCA.size(), 4);
EXPECT_EQ(resCA, answersCA);
};

//-----------------------------------------------------------------------------
TEST(conduit_blueprint_mesh_utils, is_canonical)
{
const char *adjsets = R"(
adjsets:
correct:
topology: mesh
association: vertex
groups:
group_0_1:
neighbors: 1
values: [0,1,2]
wrong_prefix:
topology: mesh
association: vertex
groups:
prefix_0_1:
neighbors: 1
values: [0,1,2]
out_of_order:
topology: mesh
association: vertex
groups:
group_1_0:
neighbors: 1
values: [0,1,2]
multi:
topology: mesh
association: vertex
groups:
group_0_1_2:
neighbors: [1,2]
values: [0,1,2]
multi_out_of_order:
topology: mesh
association: vertex
groups:
group_0_2_1:
neighbors: [1,2]
values: [0,1,2]
)";

conduit::Node n;
n.parse(adjsets);
EXPECT_TRUE( conduit::blueprint::mesh::utils::adjset::is_canonical(n["adjsets/correct"]));
EXPECT_FALSE(conduit::blueprint::mesh::utils::adjset::is_canonical(n["adjsets/wrong_prefix"]));
EXPECT_FALSE(conduit::blueprint::mesh::utils::adjset::is_canonical(n["adjsets/out_of_order"]));
EXPECT_TRUE( conduit::blueprint::mesh::utils::adjset::is_canonical(n["adjsets/multi"]));
EXPECT_FALSE(conduit::blueprint::mesh::utils::adjset::is_canonical(n["adjsets/multi_out_of_order"]));
}
Loading