From: David Wells Date: Sun, 30 Oct 2022 13:05:50 +0000 (-0400) Subject: BlockSparsityPatternBase: inherit from SparsityPatternBase. X-Git-Tag: v9.5.0-rc1~857^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14419%2Fhead;p=dealii.git BlockSparsityPatternBase: inherit from SparsityPatternBase. --- diff --git a/include/deal.II/lac/block_sparsity_pattern.h b/include/deal.II/lac/block_sparsity_pattern.h index 469c84bc45..6b148ced4c 100644 --- a/include/deal.II/lac/block_sparsity_pattern.h +++ b/include/deal.II/lac/block_sparsity_pattern.h @@ -27,6 +27,7 @@ #include #include #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -76,7 +77,7 @@ class BlockDynamicSparsityPattern; * @ref GlossBlockLA "Block (linear algebra)" */ template -class BlockSparsityPatternBase : public Subscriptor +class BlockSparsityPatternBase : public SparsityPatternBase { public: /** @@ -242,20 +243,32 @@ public: ForwardIterator end, const bool indices_are_sorted = false); + /** + * Add several nonzero entries to the specified matrix row. This function may + * only be called for non-compressed sparsity patterns and works the same way + * as the overload which takes iterators. + */ + virtual void + add_row_entries(const size_type & row, + const ArrayView &columns, + const bool indices_are_sorted = false) override; + + virtual void + add_entries(const ArrayView &rows, + const ArrayView &columns) override; + /** * Return number of rows of this matrix, which equals the dimension of the * image space. It is the sum of rows of the (block-)rows of sub-matrices. */ - size_type - n_rows() const; + using SparsityPatternBase::n_rows; /** * Return number of columns of this matrix, which equals the dimension of * the range space. It is the sum of columns of the (block-)columns of sub- * matrices. */ - size_type - n_cols() const; + using SparsityPatternBase::n_cols; /** * Check if a value at a certain position may be non-zero. @@ -920,6 +933,31 @@ BlockSparsityPatternBase::add_entries( +template +void +BlockSparsityPatternBase::add_row_entries( + const size_type & row, + const ArrayView &columns, + const bool indices_are_sorted) +{ + add_entries(row, columns.begin(), columns.end(), indices_are_sorted); +} + + + +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/source/lac/block_sparsity_pattern.cc b/source/lac/block_sparsity_pattern.cc index 676f9d5141..ce343b486c 100644 --- a/source/lac/block_sparsity_pattern.cc +++ b/source/lac/block_sparsity_pattern.cc @@ -124,6 +124,8 @@ template void BlockSparsityPatternBase::collect_sizes() { + SparsityPatternBase::resize(compute_n_rows(), compute_n_cols()); + std::vector row_sizes(n_block_rows()); std::vector col_sizes(n_block_cols()); @@ -202,28 +204,6 @@ BlockSparsityPatternBase::max_entries_per_row() const -template -typename BlockSparsityPatternBase::size_type -BlockSparsityPatternBase::n_rows() const -{ - // While trivial for the moment, this will be replaced by a base class - // function in a future patch - return compute_n_rows(); -} - - - -template -typename BlockSparsityPatternBase::size_type -BlockSparsityPatternBase::n_cols() const -{ - // While trivial for the moment, this will be replaced by a base class - // function in a future patch - return compute_n_cols(); -} - - - template typename BlockSparsityPatternBase::size_type BlockSparsityPatternBase::n_nonzero_elements() const