]> https://gitweb.dealii.org/ - dealii.git/commitdiff
BlockSparsityPatternBase: inherit from SparsityPatternBase. 14419/head
authorDavid Wells <drwells@email.unc.edu>
Sun, 30 Oct 2022 13:05:50 +0000 (09:05 -0400)
committerDavid Wells <drwells@email.unc.edu>
Mon, 14 Nov 2022 00:11:26 +0000 (19:11 -0500)
include/deal.II/lac/block_sparsity_pattern.h
source/lac/block_sparsity_pattern.cc

index 469c84bc45230498725ccd31af133e1eb0b9e540..6b148ced4c5087c0af5eff048adfe5da1f292883 100644 (file)
@@ -27,6 +27,7 @@
 #include <deal.II/lac/block_indices.h>
 #include <deal.II/lac/dynamic_sparsity_pattern.h>
 #include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/sparsity_pattern_base.h>
 #include <deal.II/lac/trilinos_sparsity_pattern.h>
 
 DEAL_II_NAMESPACE_OPEN
@@ -76,7 +77,7 @@ class BlockDynamicSparsityPattern;
  * @ref GlossBlockLA "Block (linear algebra)"
  */
 template <typename SparsityPatternType>
-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<const size_type> &columns,
+                  const bool indices_are_sorted = false) override;
+
+  virtual void
+  add_entries(const ArrayView<const size_type> &rows,
+              const ArrayView<const size_type> &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<SparsityPatternType>::add_entries(
 
 
 
+template <typename SparsityPatternType>
+void
+BlockSparsityPatternBase<SparsityPatternType>::add_row_entries(
+  const size_type &                 row,
+  const ArrayView<const size_type> &columns,
+  const bool                        indices_are_sorted)
+{
+  add_entries(row, columns.begin(), columns.end(), indices_are_sorted);
+}
+
+
+
+template <typename SparsityPatternType>
+inline void
+BlockSparsityPatternBase<SparsityPatternType>::add_entries(
+  const ArrayView<const size_type> &rows,
+  const ArrayView<const size_type> &columns)
+{
+  AssertDimension(rows.size(), columns.size());
+  for (std::size_t i = 0; i < rows.size(); ++i)
+    add(rows[i], columns[i]);
+}
+
+
+
 template <typename SparsityPatternType>
 inline bool
 BlockSparsityPatternBase<SparsityPatternType>::exists(const size_type i,
index 676f9d51419ad3e83526df9a0cbbe460ef10da37..ce343b486c7081472f1f433947e79239d4f62033 100644 (file)
@@ -124,6 +124,8 @@ template <class SparsityPatternType>
 void
 BlockSparsityPatternBase<SparsityPatternType>::collect_sizes()
 {
+  SparsityPatternBase::resize(compute_n_rows(), compute_n_cols());
+
   std::vector<size_type> row_sizes(n_block_rows());
   std::vector<size_type> col_sizes(n_block_cols());
 
@@ -202,28 +204,6 @@ BlockSparsityPatternBase<SparsityPatternType>::max_entries_per_row() const
 
 
 
-template <class SparsityPatternType>
-typename BlockSparsityPatternBase<SparsityPatternType>::size_type
-BlockSparsityPatternBase<SparsityPatternType>::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 <class SparsityPatternType>
-typename BlockSparsityPatternBase<SparsityPatternType>::size_type
-BlockSparsityPatternBase<SparsityPatternType>::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 <class SparsityPatternType>
 typename BlockSparsityPatternBase<SparsityPatternType>::size_type
 BlockSparsityPatternBase<SparsityPatternType>::n_nonzero_elements() const

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.