From: David Wells Date: Wed, 16 Nov 2022 18:32:52 +0000 (-0500) Subject: DoFTools: convert some functions to use add_row_entries(). X-Git-Tag: v9.5.0-rc1~844^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7688e4f3ee20f8942aa75ec9a357d6332607462;p=dealii.git DoFTools: convert some functions to use add_row_entries(). --- 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); } }