From aab5eac36c4b868048b40f4a8279c92166e3cb97 Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 3 Nov 2022 12:50:51 -0400 Subject: [PATCH] AffineConstraints: de-template set_sparsity_diagonals(). --- include/deal.II/lac/affine_constraints.h | 5 +++ .../lac/affine_constraints.templates.h | 37 ++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/include/deal.II/lac/affine_constraints.h b/include/deal.II/lac/affine_constraints.h index 90a723e8ee..e53dfe41bf 100644 --- a/include/deal.II/lac/affine_constraints.h +++ b/include/deal.II/lac/affine_constraints.h @@ -357,6 +357,11 @@ namespace internal */ bool in_use; + /** + * Temporary array for row indices + */ + std::vector rows; + /** * Temporary array for column indices */ diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index d6ce30a995..0e74dd88dd 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -3684,10 +3684,10 @@ namespace internal // similar function as the one above for setting matrix diagonals, but now // doing that for sparsity patterns when setting them up using - // add_entries_local_to_global. In case we keep constrained entries, add all - // the rows and columns related to the constrained dof, otherwise just add - // the diagonal - template + // add_entries_local_to_global(). In case we keep constrained entries, add + // all the rows and columns related to the constrained dof, otherwise just + // add the diagonal + template inline void set_sparsity_diagonals( const internal::AffineConstraints::GlobalRowsFromLocal @@ -3695,13 +3695,20 @@ namespace internal const std::vector &local_dof_indices, const Table<2, bool> & dof_mask, const bool keep_constrained_entries, - SparsityPatternType & sparsity_pattern) + ScratchData & scratch_data, + SparsityPatternBase & sparsity_pattern) { // if we got constraints, need to add the diagonal element and, if the // user requested so, also the rest of the entries in rows and columns // that have been left out above if (global_rows.n_constraints() > 0) { + scratch_data.rows.resize(0); + scratch_data.rows.reserve(global_rows.n_constraints() * + local_dof_indices.size()); + scratch_data.columns.resize(0); + scratch_data.columns.reserve(global_rows.n_constraints() * + local_dof_indices.size()); for (size_type i = 0; i < global_rows.n_constraints(); ++i) { const size_type local_row = global_rows.constraint_origin(i); @@ -3711,15 +3718,26 @@ namespace internal for (size_type j = 0; j < local_dof_indices.size(); ++j) { if (dof_mask(local_row, j) == true) - sparsity_pattern.add(global_row, local_dof_indices[j]); + { + scratch_data.rows.push_back(global_row); + scratch_data.columns.push_back(local_dof_indices[j]); + } if (dof_mask(j, local_row) == true) - sparsity_pattern.add(local_dof_indices[j], global_row); + { + scratch_data.rows.push_back(local_dof_indices[j]); + scratch_data.columns.push_back(global_row); + } } } else - // don't keep constrained entries - just add the diagonal. - sparsity_pattern.add(global_row, global_row); + { + // don't keep constrained entries - just add the diagonal. + scratch_data.rows.push_back(global_row); + scratch_data.columns.push_back(global_row); + } } + sparsity_pattern.add_entries(make_array_view(scratch_data.rows), + make_array_view(scratch_data.columns)); } } @@ -4365,6 +4383,7 @@ AffineConstraints::add_entries_local_to_global( local_dof_indices, dof_mask, keep_constrained_entries, + *scratch_data, sparsity_pattern); } -- 2.39.5