Skip to content

Commit 61a7c90

Browse files
authored
Topology simplifications (#4111)
* Small improvements * Speed up topology * Performance improvements * Small improrvements * Test fix * Tidy
1 parent b64d7e4 commit 61a7c90

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

cpp/dolfinx/mesh/Topology.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ determine_sharing_ranks(MPI_Comm comm, std::span<const std::int64_t> indices)
5656
// Build {dest, pos} list, and sort
5757
std::vector<std::array<int, 2>> dest_to_index;
5858
{
59-
const int size = dolfinx::MPI::size(comm);
59+
int size = dolfinx::MPI::size(comm);
6060
dest_to_index.reserve(indices.size());
6161
for (auto idx : indices)
6262
{
@@ -256,7 +256,7 @@ determine_sharing_ranks(MPI_Comm comm, std::span<const std::int64_t> indices)
256256
auto it = recv_buffer1.begin();
257257
while (it != recv_buffer1.end())
258258
{
259-
const std::size_t d = std::distance(recv_buffer1.begin(), it);
259+
std::size_t d = std::distance(recv_buffer1.begin(), it);
260260
std::int64_t num_ranks = *it;
261261

262262
std::span ranks(recv_buffer1.data() + d + 1, num_ranks);
@@ -1000,12 +1000,12 @@ void Topology::create_connectivity(int d0, int d1)
10001000
= mesh::compute_connectivity(*this, {d0, i0}, {d1, i1});
10011001

10021002
// NOTE: that to compute the (d0, d1) connections is it sometimes
1003-
// necessary to compute the (d1, d0) connections. We store the (d1,
1004-
// d0) for possible later use, but there is a memory overhead if they
1005-
// are not required. It may be better to not automatically store
1006-
// connectivity that was not requested, but advise in a docstring the
1007-
// most efficient order in which to call this function if several
1008-
// connectivities are needed.
1003+
// necessary to compute the (d1, d0) connections. We store the
1004+
// (d1, d0) for possible later use, but there is a memory overhead
1005+
// if they are not required. It may be better to not automatically
1006+
// store connectivity that was not requested, but advise in a
1007+
// docstring the most efficient order in which to call this
1008+
// function if several connectivities are needed.
10091009

10101010
// TODO: Caching policy/strategy.
10111011
// Concerning the note above: Provide an overload
@@ -1108,7 +1108,7 @@ Topology mesh::create_topology(
11081108
{
11091109
common::Timer timer2("Topology: 2");
11101110

1111-
const int mpi_rank = dolfinx::MPI::rank(comm);
1111+
int mpi_rank = dolfinx::MPI::rank(comm);
11121112
std::vector<std::int64_t> owned_shared_vertices;
11131113
for (std::size_t i = 0; i < boundary_vertices.size(); ++i)
11141114
{
@@ -1158,7 +1158,7 @@ Topology mesh::create_topology(
11581158
// Compute the global offset for owned (local) vertex indices
11591159
std::int64_t global_offset_v = 0;
11601160
{
1161-
const std::int64_t nlocal = owned_vertices.size();
1161+
std::int64_t nlocal = owned_vertices.size();
11621162
MPI_Exscan(&nlocal, &global_offset_v, 1, MPI_INT64_T, MPI_SUM, comm);
11631163
}
11641164

@@ -1206,7 +1206,7 @@ Topology mesh::create_topology(
12061206
std::int32_t v = owned_vertices.size();
12071207
for (std::size_t i = 0; i < unowned_vertex_data.size(); i += 3)
12081208
{
1209-
const std::int64_t idx_global = unowned_vertex_data[i];
1209+
std::int64_t idx_global = unowned_vertex_data[i];
12101210
auto it = std::ranges::lower_bound(unowned_vertices, idx_global);
12111211
assert(it != unowned_vertices.end() and *it == idx_global);
12121212
std::size_t pos = std::distance(unowned_vertices.begin(), it);
@@ -1390,16 +1390,15 @@ mesh::create_subtopology(const Topology& topology, int dim,
13901390
subentities = std::move(_subentities);
13911391
}
13921392

1393-
// Get the vertices in the sub-topology. Use subentities
1394-
// (instead of entities) to ensure vertices for ghost entities are
1395-
// included.
1393+
// Get the vertices in the sub-topology. Use subentities (instead of
1394+
// entities) to ensure vertices for ghost entities are included.
13961395

13971396
// Get the vertices in the sub-topology owned by this process
13981397
auto map0 = topology.index_map(0);
13991398
assert(map0);
14001399

1401-
// Create map from the vertices in the sub-topology to the vertices in the
1402-
// parent topology, and an index map
1400+
// Create map from the vertices in the sub-topology to the vertices in
1401+
// the parent topology, and an index map
14031402
std::shared_ptr<common::IndexMap> submap0;
14041403
std::vector<int32_t> subvertices0;
14051404
{
@@ -1412,7 +1411,7 @@ mesh::create_subtopology(const Topology& topology, int dim,
14121411
}
14131412

14141413
// Sub-topology entity to vertex connectivity
1415-
const CellType entity_type = cell_entity_type(topology.cell_type(), dim, 0);
1414+
CellType entity_type = cell_entity_type(topology.cell_type(), dim, 0);
14161415
int num_vertices_per_entity = cell_num_entities(entity_type, 0);
14171416
auto e_to_v = topology.connectivity(dim, 0);
14181417
assert(e_to_v);
@@ -1423,8 +1422,8 @@ mesh::create_subtopology(const Topology& topology, int dim,
14231422

14241423
// Create vertex-to-subvertex vertex map (i.e. the inverse of
14251424
// subvertex_to_vertex)
1426-
// NOTE: Depending on the sub-topology, this may be densely or sparsely
1427-
// populated. Is a different data structure more appropriate?
1425+
// NOTE: Depending on the sub-topology, this may be densely or
1426+
// sparsely populated. Is a different data structure more appropriate?
14281427
std::vector<std::int32_t> vertex_to_subvertex(
14291428
map0->size_local() + map0->num_ghosts(), -1);
14301429
for (std::size_t i = 0; i < subvertices0.size(); ++i)
@@ -1472,8 +1471,7 @@ mesh::entities_to_index(const Topology& topology, int dim,
14721471
// (value)
14731472
std::map<std::vector<std::int32_t>, std::int32_t> entity_key_to_index;
14741473
std::vector<std::int32_t> key(num_vertices_per_entity);
1475-
const int num_entities_mesh = map_e->size_local() + map_e->num_ghosts();
1476-
for (int e = 0; e < num_entities_mesh; ++e)
1474+
for (std::int32_t e = 0; e < map_e->size_local() + map_e->num_ghosts(); ++e)
14771475
{
14781476
auto vertices = e_to_v->links(e);
14791477
std::ranges::copy(vertices, key.begin());

0 commit comments

Comments
 (0)