From c67c533c3f9e0d0cf742040e67eae9dc11a73873 Mon Sep 17 00:00:00 2001 From: David Wells Date: Mon, 21 Nov 2022 15:47:59 -0500 Subject: [PATCH] Redo SparsityPatternBase::add_entries() to use pairs. --- include/deal.II/lac/affine_constraints.h | 5 + .../lac/affine_constraints.templates.h | 86 ++++----- include/deal.II/lac/block_sparsity_pattern.h | 17 +- .../deal.II/lac/dynamic_sparsity_pattern.h | 4 +- include/deal.II/lac/sparsity_pattern.h | 5 +- include/deal.II/lac/sparsity_pattern_base.h | 26 +-- .../deal.II/lac/trilinos_sparsity_pattern.h | 4 +- source/dofs/dof_tools_sparsity.cc | 182 ++++++++++-------- source/lac/CMakeLists.txt | 1 + source/lac/dynamic_sparsity_pattern.cc | 11 -- source/lac/sparsity_pattern.cc | 11 -- source/lac/sparsity_pattern_base.cc | 64 ++++++ source/lac/trilinos_sparsity_pattern.cc | 11 -- tests/sparsity/sparsity_pattern_base_01.cc | 66 +++++++ .../sparsity/sparsity_pattern_base_01.output | 111 +++++++++++ 15 files changed, 390 insertions(+), 214 deletions(-) create mode 100644 source/lac/sparsity_pattern_base.cc create mode 100644 tests/sparsity/sparsity_pattern_base_01.cc create mode 100644 tests/sparsity/sparsity_pattern_base_01.output diff --git a/include/deal.II/lac/affine_constraints.h b/include/deal.II/lac/affine_constraints.h index cb640ff5cf..816a61f6f2 100644 --- a/include/deal.II/lac/affine_constraints.h +++ b/include/deal.II/lac/affine_constraints.h @@ -358,6 +358,11 @@ namespace internal */ bool in_use; + /** + * Temporary array for pairs of indices + */ + std::vector> new_entries; + /** * Temporary array for row indices */ diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index babfd8ef06..584ceb3970 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -3703,12 +3703,10 @@ namespace internal // 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()); + std::vector> &cell_entries = + scratch_data.new_entries; + cell_entries.resize(0); + cell_entries.reserve(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); @@ -3718,26 +3716,18 @@ namespace internal for (size_type j = 0; j < local_dof_indices.size(); ++j) { if (dof_mask(local_row, j) == true) - { - scratch_data.rows.push_back(global_row); - scratch_data.columns.push_back(local_dof_indices[j]); - } + cell_entries.emplace_back(global_row, + local_dof_indices[j]); if (dof_mask(j, local_row) == true) - { - scratch_data.rows.push_back(local_dof_indices[j]); - scratch_data.columns.push_back(global_row); - } + cell_entries.emplace_back(local_dof_indices[j], + global_row); } } else - { - // don't keep constrained entries - just add the diagonal. - scratch_data.rows.push_back(global_row); - scratch_data.columns.push_back(global_row); - } + // don't keep constrained entries - just add the diagonal. + cell_entries.emplace_back(global_row, global_row); } - sparsity_pattern.add_entries(make_array_view(scratch_data.rows), - make_array_view(scratch_data.columns)); + sparsity_pattern.add_entries(make_array_view(cell_entries)); } } @@ -4331,32 +4321,29 @@ AffineConstraints::add_entries_local_to_global( true); // need to add the whole row and column structure in case we keep - // constrained entries. Unfortunately, we can't use the nice matrix - // structure we use elsewhere, so use the more general update function - actual_dof_indices.resize(0); - actual_dof_indices.reserve(n_local_dofs * n_local_dofs); - std::vector &rows = scratch_data->rows; - rows.resize(0); - rows.reserve(n_local_dofs * n_local_dofs); + // constrained entries. + std::vector> &cell_entries = + scratch_data->new_entries; + cell_entries.resize(0); + cell_entries.reserve(n_local_dofs); for (size_type i = 0; i < n_local_dofs; ++i) if (is_constrained(local_dof_indices[i])) { if (keep_constrained_entries == true) for (size_type j = 0; j < n_local_dofs; ++j) { - rows.push_back(local_dof_indices[i]); - actual_dof_indices.push_back(local_dof_indices[j]); - rows.push_back(local_dof_indices[j]); - actual_dof_indices.push_back(local_dof_indices[i]); + cell_entries.emplace_back(local_dof_indices[i], + local_dof_indices[j]); + cell_entries.emplace_back(local_dof_indices[j], + local_dof_indices[i]); } else { - rows.push_back(local_dof_indices[i]); - actual_dof_indices.push_back(local_dof_indices[i]); + cell_entries.emplace_back(local_dof_indices[i], + local_dof_indices[i]); } } - sparsity_pattern.add_entries(make_array_view(rows), - make_array_view(actual_dof_indices)); + sparsity_pattern.add_entries(make_array_view(cell_entries)); return; } @@ -4413,13 +4400,11 @@ AffineConstraints::add_entries_local_to_global( const size_type n_local_cols = col_indices.size(); typename internal::AffineConstraints::ScratchDataAccessor - scratch_data(this->scratch_data); - std::vector &rows = scratch_data->rows; - std::vector &cols = scratch_data->columns; - rows.resize(0); - rows.reserve(row_indices.size() * col_indices.size()); - cols.resize(0); - cols.reserve(row_indices.size() * col_indices.size()); + scratch_data(this->scratch_data); + std::vector> &cell_entries = + scratch_data->new_entries; + cell_entries.resize(0); + cell_entries.reserve(row_indices.size() * col_indices.size()); // if constrained entries should be kept, need to add rows and columns of // those to the sparsity pattern @@ -4428,19 +4413,12 @@ AffineConstraints::add_entries_local_to_global( for (const size_type row_index : row_indices) if (is_constrained(row_index)) for (const size_type col_index : col_indices) - { - rows.push_back(row_index); - cols.push_back(col_index); - } + cell_entries.emplace_back(row_index, col_index); for (const size_type col_index : col_indices) if (col_constraints.is_constrained(col_index)) for (const size_type row_index : row_indices) - { - rows.push_back(row_index); - cols.push_back(col_index); - } - sparsity_pattern.add_entries(make_array_view(rows), - make_array_view(cols)); + cell_entries.emplace_back(row_index, col_index); + sparsity_pattern.add_entries(make_array_view(cell_entries)); } // if the dof mask is not active, all we have to do is to add some indices @@ -4451,6 +4429,8 @@ AffineConstraints::add_entries_local_to_global( dof_mask.n_rows() == n_local_rows && dof_mask.n_cols() == n_local_cols; if (dof_mask_is_active == false) { + std::vector &rows = scratch_data->rows; + std::vector &cols = scratch_data->columns; rows.resize(n_local_rows); cols.resize(n_local_cols); // TODO these fills may not be necessary: previously we assumed all zeros diff --git a/include/deal.II/lac/block_sparsity_pattern.h b/include/deal.II/lac/block_sparsity_pattern.h index aac3dd42c4..156dc64b76 100644 --- a/include/deal.II/lac/block_sparsity_pattern.h +++ b/include/deal.II/lac/block_sparsity_pattern.h @@ -253,9 +253,7 @@ public: const ArrayView &columns, const bool indices_are_sorted = false) override; - virtual void - add_entries(const ArrayView &rows, - const ArrayView &columns) override; + using SparsityPatternBase::add_entries; /** * Return number of rows of this matrix, which equals the dimension of the @@ -996,19 +994,6 @@ BlockSparsityPatternBase::add_row_entries( -template -inline void -BlockSparsityPatternBase::add_entries( - const ArrayView &rows, - const ArrayView &columns) -{ - AssertDimension(rows.size(), columns.size()); - for (std::size_t i = 0; i < rows.size(); ++i) - add(rows[i], columns[i]); -} - - - template inline bool BlockSparsityPatternBase::exists(const size_type i, diff --git a/include/deal.II/lac/dynamic_sparsity_pattern.h b/include/deal.II/lac/dynamic_sparsity_pattern.h index d363425431..7b032fbe94 100644 --- a/include/deal.II/lac/dynamic_sparsity_pattern.h +++ b/include/deal.II/lac/dynamic_sparsity_pattern.h @@ -445,9 +445,7 @@ public: const ArrayView &columns, const bool indices_are_sorted = false) override; - virtual void - add_entries(const ArrayView &rows, - const ArrayView &columns) override; + using SparsityPatternBase::add_entries; /** * Check if a value at a certain position may be non-zero. diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index 78d907d431..7e7985e9bf 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -735,10 +735,7 @@ public: const ArrayView &columns, const bool indices_are_sorted = false) override; - virtual void - add_entries(const ArrayView &rows, - const ArrayView &columns) override; - + using SparsityPatternBase::add_entries; /** * Make the sparsity pattern symmetric by adding the sparsity pattern of the diff --git a/include/deal.II/lac/sparsity_pattern_base.h b/include/deal.II/lac/sparsity_pattern_base.h index 8fcf366567..d8fa38325b 100644 --- a/include/deal.II/lac/sparsity_pattern_base.h +++ b/include/deal.II/lac/sparsity_pattern_base.h @@ -23,6 +23,8 @@ #include #include +#include + DEAL_II_NAMESPACE_OPEN /** @@ -98,13 +100,14 @@ public: const bool indices_are_sorted = false) = 0; /** - * General function for adding new entries. By default this function calls - * add_row_entries() for each new entry: inheriting classes may want to add a - * more optimized implementation. + * General function for adding new entries from an unsorted list of pairs. + * + * This function is useful when multiple entries need to be added which do + * not correspond to a particular row, e.g., when assembling a flux sparsity + * pattern. */ virtual void - add_entries(const ArrayView &rows, - const ArrayView &columns); + add_entries(const ArrayView> &entries); protected: /** @@ -164,19 +167,6 @@ SparsityPatternBase::n_cols() const -inline void -SparsityPatternBase::add_entries(const ArrayView &rows, - const ArrayView &columns) -{ - AssertDimension(rows.size(), columns.size()); - for (std::size_t i = 0; i < rows.size(); ++i) - add_row_entries(rows[i], - make_array_view(columns.begin() + i, - columns.begin() + i + 1)); -} - - - inline void SparsityPatternBase::resize(const size_type rows, const size_type cols) { diff --git a/include/deal.II/lac/trilinos_sparsity_pattern.h b/include/deal.II/lac/trilinos_sparsity_pattern.h index 4c6e575106..0f918eea89 100644 --- a/include/deal.II/lac/trilinos_sparsity_pattern.h +++ b/include/deal.II/lac/trilinos_sparsity_pattern.h @@ -778,9 +778,7 @@ namespace TrilinosWrappers const ArrayView &columns, const bool indices_are_sorted = false) override; - virtual void - add_entries(const ArrayView &rows, - const ArrayView &columns) override; + using SparsityPatternBase::add_entries; /** @} */ /** diff --git a/source/dofs/dof_tools_sparsity.cc b/source/dofs/dof_tools_sparsity.cc index 68a2be4ac8..310ee84492 100644 --- a/source/dofs/dof_tools_sparsity.cc +++ b/source/dofs/dof_tools_sparsity.cc @@ -774,13 +774,9 @@ namespace DoFTools const unsigned int)> &face_has_flux_coupling) { 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); - }; + std::vector> + cell_entries; if (dof.has_hp_capabilities() == false) { @@ -849,14 +845,13 @@ namespace DoFTools if (flux_dof_mask(i, j) == always || (flux_dof_mask(i, j) == nonzero && i_non_zero_i && j_non_zero_i)) - append_pair(dofs_on_this_cell[i], - dofs_on_this_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_this_cell[j]); } } - sparsity.add_entries(make_array_view(rows), - make_array_view(cols)); - rows.clear(); - cols.clear(); + sparsity.add_entries(make_array_view(cell_entries)); + cell_entries.clear(); } else { @@ -948,14 +943,16 @@ namespace DoFTools if (flux_dof_mask(i, j) == always) { - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[i], dofs_on_other_cell[j]); - append_pair(dofs_on_other_cell[i], - dofs_on_this_cell[j]); - append_pair(dofs_on_this_cell[i], - dofs_on_this_cell[j]); - append_pair( + cell_entries.emplace_back( + dofs_on_other_cell[i], + dofs_on_this_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_this_cell[j]); + cell_entries.emplace_back( dofs_on_other_cell[i], dofs_on_other_cell[j]); } @@ -963,33 +960,35 @@ namespace DoFTools nonzero) { if (i_non_zero_i && j_non_zero_e) - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[i], dofs_on_other_cell[j]); if (i_non_zero_e && j_non_zero_i) - append_pair( + cell_entries.emplace_back( dofs_on_other_cell[i], dofs_on_this_cell[j]); if (i_non_zero_i && j_non_zero_i) - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[i], dofs_on_this_cell[j]); if (i_non_zero_e && j_non_zero_e) - append_pair( + cell_entries.emplace_back( dofs_on_other_cell[i], dofs_on_other_cell[j]); } if (flux_dof_mask(j, i) == always) { - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[j], dofs_on_other_cell[i]); - append_pair(dofs_on_other_cell[j], - dofs_on_this_cell[i]); - append_pair(dofs_on_this_cell[j], - dofs_on_this_cell[i]); - append_pair( + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_this_cell[j], + dofs_on_this_cell[i]); + cell_entries.emplace_back( dofs_on_other_cell[j], dofs_on_other_cell[i]); } @@ -997,29 +996,28 @@ namespace DoFTools nonzero) { if (j_non_zero_i && i_non_zero_e) - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[j], dofs_on_other_cell[i]); if (j_non_zero_e && i_non_zero_i) - append_pair( + cell_entries.emplace_back( dofs_on_other_cell[j], dofs_on_this_cell[i]); if (j_non_zero_i && i_non_zero_i) - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[j], dofs_on_this_cell[i]); if (j_non_zero_e && i_non_zero_e) - append_pair( + cell_entries.emplace_back( dofs_on_other_cell[j], dofs_on_other_cell[i]); } } } } - sparsity.add_entries(make_array_view(rows), - make_array_view(cols)); - rows.clear(); - cols.clear(); + sparsity.add_entries( + make_array_view(cell_entries)); + cell_entries.clear(); } else { @@ -1041,63 +1039,78 @@ namespace DoFTools support_on_face(j, neighbor_face_n); if (flux_dof_mask(i, j) == always) { - append_pair(dofs_on_this_cell[i], - dofs_on_other_cell[j]); - append_pair(dofs_on_other_cell[i], - dofs_on_this_cell[j]); - append_pair(dofs_on_this_cell[i], - dofs_on_this_cell[j]); - append_pair(dofs_on_other_cell[i], - dofs_on_other_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_other_cell[j]); + cell_entries.emplace_back( + dofs_on_other_cell[i], + dofs_on_this_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_this_cell[j]); + cell_entries.emplace_back( + dofs_on_other_cell[i], + dofs_on_other_cell[j]); } if (flux_dof_mask(i, j) == nonzero) { if (i_non_zero_i && j_non_zero_e) - append_pair(dofs_on_this_cell[i], - dofs_on_other_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_other_cell[j]); if (i_non_zero_e && j_non_zero_i) - append_pair(dofs_on_other_cell[i], - dofs_on_this_cell[j]); + cell_entries.emplace_back( + dofs_on_other_cell[i], + dofs_on_this_cell[j]); if (i_non_zero_i && j_non_zero_i) - append_pair(dofs_on_this_cell[i], - dofs_on_this_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_this_cell[j]); if (i_non_zero_e && j_non_zero_e) - append_pair(dofs_on_other_cell[i], - dofs_on_other_cell[j]); + cell_entries.emplace_back( + dofs_on_other_cell[i], + dofs_on_other_cell[j]); } if (flux_dof_mask(j, i) == always) { - append_pair(dofs_on_this_cell[j], - dofs_on_other_cell[i]); - append_pair(dofs_on_other_cell[j], - dofs_on_this_cell[i]); - append_pair(dofs_on_this_cell[j], - dofs_on_this_cell[i]); - append_pair(dofs_on_other_cell[j], - dofs_on_other_cell[i]); + cell_entries.emplace_back( + dofs_on_this_cell[j], + dofs_on_other_cell[i]); + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_this_cell[j], + dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_other_cell[i]); } if (flux_dof_mask(j, i) == nonzero) { if (j_non_zero_i && i_non_zero_e) - append_pair(dofs_on_this_cell[j], - dofs_on_other_cell[i]); + cell_entries.emplace_back( + dofs_on_this_cell[j], + dofs_on_other_cell[i]); if (j_non_zero_e && i_non_zero_i) - append_pair(dofs_on_other_cell[j], - dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_this_cell[i]); if (j_non_zero_i && i_non_zero_i) - append_pair(dofs_on_this_cell[j], - dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_this_cell[j], + dofs_on_this_cell[i]); if (j_non_zero_e && i_non_zero_e) - append_pair(dofs_on_other_cell[j], - dofs_on_other_cell[i]); + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_other_cell[i]); } } } - sparsity.add_entries(make_array_view(rows), - make_array_view(cols)); - rows.clear(); - cols.clear(); + sparsity.add_entries( + make_array_view(cell_entries)); + cell_entries.clear(); } } } @@ -1287,7 +1300,7 @@ namespace DoFTools if ((flux_mask(ii, jj) == always) || (flux_mask(ii, jj) == nonzero)) { - append_pair( + cell_entries.emplace_back( dofs_on_this_cell[i], dofs_on_other_cell[j]); } @@ -1295,8 +1308,9 @@ namespace DoFTools if ((flux_mask(jj, ii) == always) || (flux_mask(jj, ii) == nonzero)) { - append_pair(dofs_on_other_cell[j], - dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_this_cell[i]); } } } @@ -1343,25 +1357,25 @@ namespace DoFTools if ((flux_mask(ii, jj) == always) || (flux_mask(ii, jj) == nonzero)) { - append_pair(dofs_on_this_cell[i], - dofs_on_other_cell[j]); + cell_entries.emplace_back( + dofs_on_this_cell[i], + dofs_on_other_cell[j]); } if ((flux_mask(jj, ii) == always) || (flux_mask(jj, ii) == nonzero)) { - append_pair(dofs_on_other_cell[j], - dofs_on_this_cell[i]); + cell_entries.emplace_back( + dofs_on_other_cell[j], + dofs_on_this_cell[i]); } } } } } } - sparsity.add_entries(make_array_view(rows), - make_array_view(cols)); - rows.clear(); - cols.clear(); + sparsity.add_entries(make_array_view(cell_entries)); + cell_entries.clear(); } } } diff --git a/source/lac/CMakeLists.txt b/source/lac/CMakeLists.txt index 57373d13d1..3d907f8be1 100644 --- a/source/lac/CMakeLists.txt +++ b/source/lac/CMakeLists.txt @@ -42,6 +42,7 @@ SET(_unity_include_src sparse_matrix_ez.cc sparse_mic.cc sparse_vanka.cc + sparsity_pattern_base.cc sparsity_pattern.cc sparsity_tools.cc tensor_product_matrix.cc diff --git a/source/lac/dynamic_sparsity_pattern.cc b/source/lac/dynamic_sparsity_pattern.cc index 0dabe209fe..e43e2dbc61 100644 --- a/source/lac/dynamic_sparsity_pattern.cc +++ b/source/lac/dynamic_sparsity_pattern.cc @@ -358,17 +358,6 @@ DynamicSparsityPattern::add_row_entries( -void -DynamicSparsityPattern::add_entries(const ArrayView &rows, - const ArrayView &columns) -{ - AssertDimension(rows.size(), columns.size()); - for (std::size_t i = 0; i < rows.size(); ++i) - add(rows[i], columns[i]); -} - - - bool DynamicSparsityPattern::exists(const size_type i, const size_type j) const { diff --git a/source/lac/sparsity_pattern.cc b/source/lac/sparsity_pattern.cc index 8094e9098a..8b022eaa29 100644 --- a/source/lac/sparsity_pattern.cc +++ b/source/lac/sparsity_pattern.cc @@ -838,17 +838,6 @@ SparsityPattern::add_row_entries(const size_type & row, -void -SparsityPattern::add_entries(const ArrayView &rows, - const ArrayView &columns) -{ - AssertDimension(rows.size(), columns.size()); - for (std::size_t i = 0; i < rows.size(); ++i) - add(rows[i], columns[i]); -} - - - void SparsityPattern::symmetrize() { diff --git a/source/lac/sparsity_pattern_base.cc b/source/lac/sparsity_pattern_base.cc new file mode 100644 index 0000000000..78d46aa538 --- /dev/null +++ b/source/lac/sparsity_pattern_base.cc @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2022 - 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +#include + +DEAL_II_DISABLE_EXTRA_DIAGNOSTICS +#include +DEAL_II_ENABLE_EXTRA_DIAGNOSTICS + +#include +#include + +DEAL_II_NAMESPACE_OPEN + +void +SparsityPatternBase::add_entries( + const ArrayView> &inputs) +{ + // We always want to sort so that we can use the optimized add_row_entries() + // function + boost::container::small_vector, 128> entries( + inputs.begin(), inputs.end()); + std::sort(entries.begin(), entries.end()); + boost::container::small_vector columns; + + auto entry = entries.begin(); + while (entry != entries.end()) + { + const auto row = entry->first; + auto row_end = entry; + while (row_end != entries.end() && row_end->first == row) + ++row_end; + + columns.resize(0); + columns.reserve(row_end - entry); + // Simultaneously transform and uniquify + columns.push_back(entry->second); + ++entry; + while (entry != row_end) + { + if (columns.back() != entry->second) + columns.push_back(entry->second); + ++entry; + } + + add_row_entries(row, + make_array_view(columns.begin(), columns.end()), + true); + } +} + +DEAL_II_NAMESPACE_CLOSE diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index fe31d1da8c..b84c7bc78d 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -990,17 +990,6 @@ namespace TrilinosWrappers - void - SparsityPattern::add_entries(const ArrayView &rows, - const ArrayView &columns) - { - AssertDimension(rows.size(), columns.size()); - for (std::size_t i = 0; i < rows.size(); ++i) - add(rows[i], columns[i]); - } - - - const Epetra_Map & SparsityPattern::domain_partitioner() const { diff --git a/tests/sparsity/sparsity_pattern_base_01.cc b/tests/sparsity/sparsity_pattern_base_01.cc new file mode 100644 index 0000000000..2cd55e6f02 --- /dev/null +++ b/tests/sparsity/sparsity_pattern_base_01.cc @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2001 - 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Test SparsityPatternBase::add_entries() + + +#include + +#include "../tests.h" + +class TestPattern : public SparsityPatternBase +{ + using SparsityPatternBase::SparsityPatternBase; + + using SparsityPatternBase::size_type; + + virtual void + add_row_entries(const size_type & row, + const ArrayView &columns, + const bool indices_are_sorted = false) override + { + deallog << "row = " << row; + + AssertThrow(std::is_sorted(columns.begin(), columns.end()), + ExcInternalError()); + + for (const auto &col : columns) + deallog << " " << col; + + deallog << std::endl; + } +}; + + + +int +main() +{ + initlog(); + + std::vector< + std::pair> + entries; + + for (unsigned int i = 0; i < 100; ++i) + entries.emplace_back(rand() % 10, rand() % 100); + + for (auto &entry : entries) + deallog << entry.first << ", " << entry.second << std::endl; + + TestPattern test(100, 100); + test.add_entries(make_array_view(entries)); +} diff --git a/tests/sparsity/sparsity_pattern_base_01.output b/tests/sparsity/sparsity_pattern_base_01.output new file mode 100644 index 0000000000..f70a8ae05a --- /dev/null +++ b/tests/sparsity/sparsity_pattern_base_01.output @@ -0,0 +1,111 @@ + +DEAL::6, 83 +DEAL::5, 77 +DEAL::5, 93 +DEAL::2, 86 +DEAL::1, 49 +DEAL::7, 62 +DEAL::9, 90 +DEAL::6, 63 +DEAL::6, 40 +DEAL::6, 72 +DEAL::8, 11 +DEAL::9, 67 +DEAL::0, 82 +DEAL::3, 62 +DEAL::5, 67 +DEAL::2, 29 +DEAL::8, 22 +DEAL::7, 69 +DEAL::6, 93 +DEAL::2, 11 +DEAL::3, 29 +DEAL::9, 21 +DEAL::7, 84 +DEAL::4, 98 +DEAL::0, 15 +DEAL::6, 13 +DEAL::0, 91 +DEAL::3, 56 +DEAL::0, 62 +DEAL::1, 96 +DEAL::5, 5 +DEAL::7, 84 +DEAL::5, 36 +DEAL::9, 46 +DEAL::7, 13 +DEAL::5, 24 +DEAL::5, 82 +DEAL::7, 14 +DEAL::4, 34 +DEAL::0, 43 +DEAL::8, 87 +DEAL::8, 76 +DEAL::4, 88 +DEAL::1, 3 +DEAL::9, 54 +DEAL::0, 32 +DEAL::8, 76 +DEAL::2, 39 +DEAL::6, 26 +DEAL::9, 94 +DEAL::0, 95 +DEAL::8, 34 +DEAL::1, 67 +DEAL::2, 97 +DEAL::2, 17 +DEAL::6, 52 +DEAL::0, 1 +DEAL::1, 86 +DEAL::9, 65 +DEAL::9, 44 +DEAL::9, 40 +DEAL::7, 31 +DEAL::1, 97 +DEAL::5, 81 +DEAL::7, 9 +DEAL::6, 67 +DEAL::3, 97 +DEAL::5, 86 +DEAL::3, 6 +DEAL::4, 19 +DEAL::1, 28 +DEAL::9, 32 +DEAL::9, 3 +DEAL::8, 70 +DEAL::5, 8 +DEAL::9, 40 +DEAL::3, 96 +DEAL::5, 18 +DEAL::1, 46 +DEAL::5, 21 +DEAL::8, 79 +DEAL::8, 64 +DEAL::0, 41 +DEAL::0, 93 +DEAL::4, 34 +DEAL::4, 24 +DEAL::6, 87 +DEAL::1, 43 +DEAL::5, 27 +DEAL::6, 59 +DEAL::1, 32 +DEAL::8, 37 +DEAL::7, 75 +DEAL::1, 74 +DEAL::5, 58 +DEAL::7, 29 +DEAL::3, 35 +DEAL::8, 18 +DEAL::1, 43 +DEAL::9, 28 +DEAL::row = 0 1 15 32 41 43 62 82 91 93 95 +DEAL::row = 1 3 28 32 43 46 49 67 74 86 96 97 +DEAL::row = 2 11 17 29 39 86 97 +DEAL::row = 3 6 29 35 56 62 96 97 +DEAL::row = 4 19 24 34 88 98 +DEAL::row = 5 5 8 18 21 24 27 36 58 67 77 81 82 86 93 +DEAL::row = 6 13 26 40 52 59 63 67 72 83 87 93 +DEAL::row = 7 9 13 14 29 31 62 69 75 84 +DEAL::row = 8 11 18 22 34 37 64 70 76 79 87 +DEAL::row = 9 3 21 28 32 40 44 46 54 65 67 90 94 -- 2.39.5