Skip to content

Commit

Permalink
std::set_... -> std::ranges::set_... (#3298)
Browse files Browse the repository at this point in the history
  • Loading branch information
schnellerhase committed Jul 12, 2024
1 parent 6e9b57a commit c4acb41
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
6 changes: 2 additions & 4 deletions cpp/dolfinx/fem/DirichletBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ std::vector<std::int32_t> fem::locate_dofs_topological(
std::span src = map->src();
std::span dest = map->dest();
std::vector<int> ranks;
std::set_union(src.begin(), src.end(), dest.begin(), dest.end(),
std::back_inserter(ranks));
std::ranges::set_union(src, dest, std::back_inserter(ranks));
ranks.erase(std::unique(ranks.begin(), ranks.end()), ranks.end());
MPI_Dist_graph_create_adjacent(
map->comm(), ranks.size(), ranks.data(), MPI_UNWEIGHTED, ranks.size(),
Expand Down Expand Up @@ -385,8 +384,7 @@ std::array<std::vector<std::int32_t>, 2> fem::locate_dofs_topological(
std::span src = map0->src();
std::span dest = map0->dest();
std::vector<int> ranks;
std::set_union(src.begin(), src.end(), dest.begin(), dest.end(),
std::back_inserter(ranks));
std::ranges::set_union(src, dest, std::back_inserter(ranks));
ranks.erase(std::unique(ranks.begin(), ranks.end()), ranks.end());
MPI_Dist_graph_create_adjacent(map0->comm(), ranks.size(), ranks.data(),
MPI_UNWEIGHTED, ranks.size(), ranks.data(),
Expand Down
4 changes: 2 additions & 2 deletions cpp/dolfinx/fem/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ std::vector<std::int32_t> fem::compute_integration_domains(
// Create list of tagged boundary facets
const std::vector bfacets = mesh::exterior_facet_indices(topology);
std::vector<std::int32_t> facets;
std::set_intersection(entities.begin(), entities.end(), bfacets.begin(),
bfacets.end(), std::back_inserter(facets));
std::ranges::set_intersection(entities, bfacets,
std::back_inserter(facets));
for (auto f : facets)
{
// Get the facet as a pair of (cell, local facet)
Expand Down
15 changes: 6 additions & 9 deletions cpp/dolfinx/mesh/Topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,21 @@ std::array<std::vector<std::int64_t>, 2> vertex_ownership_groups(
// Build difference 1: Vertices attached only to owned cells, and
// therefore owned by this rank
std::vector<std::int64_t> owned_vertices;
std::set_difference(local_vertex_set.begin(), local_vertex_set.end(),
boundary_vertices.begin(), boundary_vertices.end(),
std::back_inserter(owned_vertices));
std::ranges::set_difference(local_vertex_set, boundary_vertices,
std::back_inserter(owned_vertices));

// Build difference 2: Vertices attached only to ghost cells, and
// therefore not owned by this rank
std::vector<std::int64_t> unowned_vertices;
std::set_difference(ghost_vertex_set.begin(), ghost_vertex_set.end(),
local_vertex_set.begin(), local_vertex_set.end(),
std::back_inserter(unowned_vertices));
std::ranges::set_difference(ghost_vertex_set, local_vertex_set,
std::back_inserter(unowned_vertices));

// TODO Check this in debug mode only?
// Sanity check
// No vertices in unowned should also be in boundary...
std::vector<std::int64_t> unowned_vertices_in_error;
std::set_intersection(unowned_vertices.begin(), unowned_vertices.end(),
boundary_vertices.begin(), boundary_vertices.end(),
std::back_inserter(unowned_vertices_in_error));
std::ranges::set_intersection(unowned_vertices, boundary_vertices,
std::back_inserter(unowned_vertices_in_error));

if (!unowned_vertices_in_error.empty())
{
Expand Down
7 changes: 2 additions & 5 deletions cpp/dolfinx/mesh/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@ std::vector<std::int32_t> mesh::exterior_facet_indices(const Topology& topology)
}

// Remove facets on internal inter-process boundary
const std::vector<std::int32_t>& interprocess_facets
= topology.interprocess_facets();
std::vector<std::int32_t> ext_facets;
std::set_difference(facets.begin(), facets.end(), interprocess_facets.begin(),
interprocess_facets.end(),
std::back_inserter(ext_facets));
std::ranges::set_difference(facets, topology.interprocess_facets(),
std::back_inserter(ext_facets));
return ext_facets;
}
//------------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions cpp/dolfinx/refinement/plaza.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ auto compute_parent_facets(std::span<const std::int32_t> simplex_set)
{
for (int j = 0; j < tdim; ++j)
cf[j] = simplex_set[cc * 3 + facet_table_2d[fci][j]];

std::ranges::sort(cf);
auto it = std::set_intersection(facet_table_2d[fpi].begin(),
facet_table_2d[fpi].end(), cf.begin(),
cf.end(), set_output.begin());
num_common_vertices = std::distance(set_output.begin(), it);
auto [last1, last2, it_last] = std::ranges::set_intersection(
facet_table_2d[fpi], cf, set_output.begin());
num_common_vertices = std::distance(set_output.begin(), it_last);
}
else
{
for (int j = 0; j < tdim; ++j)
cf[j] = simplex_set[cc * 4 + facet_table_3d[fci][j]];

std::ranges::sort(cf);
auto it = std::set_intersection(facet_table_3d[fpi].begin(),
facet_table_3d[fpi].end(), cf.begin(),
cf.end(), set_output.begin());
num_common_vertices = std::distance(set_output.begin(), it);
auto [last1, last2, it_last] = std::ranges::set_intersection(
facet_table_3d[fpi], cf, set_output.begin());
num_common_vertices = std::distance(set_output.begin(), it_last);
}

if (num_common_vertices == tdim)
Expand Down

0 comments on commit c4acb41

Please sign in to comment.