Skip to content

Commit

Permalink
Merge pull request #1227 from LLNL/bugfix/whitlock/more_strict_adjset…
Browse files Browse the repository at this point in the history
…_is_canonical

Make adjset::is_canonical more strict
  • Loading branch information
BradWhitlock committed Jan 8, 2024
2 parents 5a5b11d + 7ef641b commit 4fceb68
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
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 @@ -2868,7 +2868,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 @@ -799,3 +799,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"]));
}

0 comments on commit 4fceb68

Please sign in to comment.