From aeddeac7b0d8f6e7598b66efba359a905eb4bae0 Mon Sep 17 00:00:00 2001 From: Ralf Hartmann Date: Wed, 22 Nov 2000 14:47:03 +0000 Subject: [PATCH] SparseMatrix::n_actually_nonzero_elements () counts all entries that are really nonzero. git-svn-id: https://svn.dealii.org/trunk@3496 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/sparse_matrix.h | 14 ++++++++++++++ deal.II/lac/include/lac/sparse_matrix.templates.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 3e59f49bab..57902399df 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -219,6 +219,20 @@ class SparseMatrix : public Subscriptor * be zero, it is counted anyway. */ unsigned int n_nonzero_elements () const; + + /** + * Return the number of actually + * nonzero elements of this + * matrix. + * + * Note, that this function does + * (in contrary to the + * @p{n_nonzero_elements}) NOT + * count all entries of the + * sparsity pattern but only the + * ones that are nonzero. + */ + unsigned int n_actually_nonzero_elements () const; /** * Set the element @p{(i,j)} to @p{value}. diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 40fbc14c59..1408679585 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -152,6 +152,16 @@ SparseMatrix::n_nonzero_elements () const }; +template +unsigned int +SparseMatrix::n_actually_nonzero_elements () const +{ + Assert (cols != 0, ExcMatrixNotInitialized()); + return count_if(&val[0], &val[n_nonzero_elements ()], + bind2nd(not_equal_to(), 0)); +}; + + template template SparseMatrix & -- 2.39.5