From c7688e4f3ee20f8942aa75ec9a357d6332607462 Mon Sep 17 00:00:00 2001 From: David Wells Date: Wed, 16 Nov 2022 13:32:52 -0500 Subject: [PATCH] DoFTools: convert some functions to use add_row_entries(). --- source/dofs/dof_tools_sparsity.cc | 56 ++++++++++++++----------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/source/dofs/dof_tools_sparsity.cc b/source/dofs/dof_tools_sparsity.cc index 5f850fd097..40dd06b458 100644 --- a/source/dofs/dof_tools_sparsity.cc +++ b/source/dofs/dof_tools_sparsity.cc @@ -385,16 +385,8 @@ namespace DoFTools std::vector dofs_on_this_face; dofs_on_this_face.reserve(dof.get_fe_collection().max_dofs_per_face()); - - std::vector rows; std::vector cols; - auto append_pair = [&](const types::global_dof_index i, - const types::global_dof_index j) { - rows.push_back(i); - cols.push_back(j); - }; - // loop over all faces to check whether they are at a boundary. note // that we need not take special care of single lines (using // @p{cell->has_boundary_lines}), since we do not support boundaries of @@ -411,14 +403,18 @@ namespace DoFTools cell->active_fe_index()); // make sparsity pattern for this cell - for (unsigned int i = 0; i < dofs_per_face; ++i) - for (unsigned int j = 0; j < dofs_per_face; ++j) - append_pair(dof_to_boundary_mapping[dofs_on_this_face[i]], - dof_to_boundary_mapping[dofs_on_this_face[j]]); - - sparsity.add_entries(make_array_view(rows), make_array_view(cols)); - rows.clear(); cols.clear(); + for (unsigned int j = 0; j < dofs_per_face; ++j) + cols.push_back(dof_to_boundary_mapping[dofs_on_this_face[j]]); + // We are not guaranteed that the mapping to a second index space + // is increasing so sort here to use the faster add_row_entries() + // path + std::sort(cols.begin(), cols.end()); + for (unsigned int i = 0; i < dofs_per_face; ++i) + sparsity.add_row_entries( + dof_to_boundary_mapping[dofs_on_this_face[i]], + make_array_view(cols), + true); } } @@ -461,10 +457,13 @@ namespace DoFTools boundary_dof_boundary_indices[i] = dof_to_boundary_mapping[cell->vertex_dof_index(direction, i)]; + std::sort(boundary_dof_boundary_indices.begin(), + boundary_dof_boundary_indices.end()); for (unsigned int i = 0; i < dofs_per_vertex; ++i) sparsity.add_row_entries(boundary_dof_boundary_indices[i], make_array_view( - boundary_dof_boundary_indices)); + boundary_dof_boundary_indices), + true); } return; } @@ -495,16 +494,8 @@ namespace DoFTools std::vector dofs_on_this_face; dofs_on_this_face.reserve(dof.get_fe_collection().max_dofs_per_face()); - - std::vector rows; std::vector cols; - auto append_pair = [&](const types::global_dof_index i, - const types::global_dof_index j) { - rows.push_back(i); - cols.push_back(j); - }; - for (const auto &cell : dof.active_cell_iterators()) for (const unsigned int f : cell->face_indices()) if (boundary_ids.find(cell->face(f)->boundary_id()) != @@ -517,14 +508,17 @@ namespace DoFTools cell->active_fe_index()); // make sparsity pattern for this cell - for (unsigned int i = 0; i < dofs_per_face; ++i) - for (unsigned int j = 0; j < dofs_per_face; ++j) - append_pair(dof_to_boundary_mapping[dofs_on_this_face[i]], - dof_to_boundary_mapping[dofs_on_this_face[j]]); - - sparsity.add_entries(make_array_view(rows), make_array_view(cols)); - rows.clear(); cols.clear(); + for (unsigned int j = 0; j < dofs_per_face; ++j) + cols.push_back(dof_to_boundary_mapping[dofs_on_this_face[j]]); + // Like the other one: sort once. + std::sort(cols.begin(), cols.end()); + + for (unsigned int i = 0; i < dofs_per_face; ++i) + sparsity.add_row_entries( + dof_to_boundary_mapping[dofs_on_this_face[i]], + make_array_view(cols), + true); } } -- 2.39.5