]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added `n_nonzero_elements` to PETSc `BlockSparseMatrix`.
authorMarc Fehling <mafehling.git@gmail.com>
Fri, 4 Mar 2022 05:30:28 +0000 (22:30 -0700)
committerMarc Fehling <mafehling.git@gmail.com>
Fri, 4 Mar 2022 05:30:28 +0000 (22:30 -0700)
include/deal.II/lac/petsc_block_sparse_matrix.h
source/lac/petsc_parallel_block_sparse_matrix.cc

index d7ebe0819cd828f81dcc5eabf315612e987487a4..60ac2c3e93f5925f2424ca34a09b66a48372e63c 100644 (file)
@@ -250,6 +250,14 @@ namespace PETScWrappers
       std::vector<IndexSet>
       locally_owned_range_indices() const;
 
+      /**
+       * Return the number of nonzero elements of this matrix. Actually, it
+       * returns the number of entries in the sparsity pattern; if any of the
+       * entries should happen to be zero, it is counted anyway.
+       */
+      size_type
+      n_nonzero_elements() const;
+
       /**
        * Return a reference to the MPI communicator object in use with this
        * matrix.
index 598f3a57ff1cd52951701094dad58220b1dd744d..0d0a553838dbe847ed964a5f1bcc9b05ed8f3d82 100644 (file)
@@ -133,6 +133,17 @@ namespace PETScWrappers
       return index_sets;
     }
 
+    BlockSparseMatrix::size_type
+    BlockSparseMatrix::n_nonzero_elements() const
+    {
+      size_type n_nonzero = 0;
+      for (size_type rows = 0; rows < this->n_block_rows(); ++rows)
+        for (size_type cols = 0; cols < this->n_block_cols(); ++cols)
+          n_nonzero += this->block(rows, cols).n_nonzero_elements();
+
+      return n_nonzero;
+    }
+
     const MPI_Comm &
     BlockSparseMatrix::get_mpi_communicator() 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.