From: Martin Kronbichler Date: Thu, 20 Mar 2025 08:31:45 +0000 (+0100) Subject: SparseMatrixTools: speed up a function to extract a sub-matrix X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12c10210fac2d52461a9feaabbbe204ca4167ce3;p=dealii.git SparseMatrixTools: speed up a function to extract a sub-matrix --- diff --git a/include/deal.II/lac/sparse_matrix_tools.h b/include/deal.II/lac/sparse_matrix_tools.h index e361e8ca22..a1c93cd126 100644 --- a/include/deal.II/lac/sparse_matrix_tools.h +++ b/include/deal.II/lac/sparse_matrix_tools.h @@ -504,12 +504,26 @@ namespace SparseMatrixTools if (locally_owned_dofs.is_element( local_dof_indices[i])) // row is local { - cell_matrix(i, j) = - sparsity_pattern.exists(local_dof_indices[i], - local_dof_indices[j]) ? - system_matrix(local_dof_indices[i], - local_dof_indices[j]) : - 0; + if constexpr (std::is_same_v>) + { + const types::global_dof_index ind = + system_matrix.get_sparsity_pattern()( + local_dof_indices[i], local_dof_indices[j]); + if (ind != numbers::invalid_dof_index) + { + SparseMatrixIterators::Accessor + accessor(&system_matrix, ind); + cell_matrix(i, j) = accessor.value(); + } + } + else + cell_matrix(i, j) = + sparsity_pattern.exists(local_dof_indices[i], + local_dof_indices[j]) ? + system_matrix(local_dof_indices[i], + local_dof_indices[j]) : + 0.0; } else // row is ghost {