From: Wolfgang Bangerth Date: Mon, 18 May 1998 08:26:56 +0000 (+0000) Subject: Add function to inquire the number of nonzero elements. X-Git-Tag: v8.0.0~22958 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ae3ff601c152d7ea0a1d1474476a0e09f37d1b9;p=dealii.git Add function to inquire the number of nonzero elements. git-svn-id: https://svn.dealii.org/trunk@296 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/dsmatrix.h b/deal.II/lac/include/lac/dsmatrix.h index 73e874750b..064cf26a48 100644 --- a/deal.II/lac/include/lac/dsmatrix.h +++ b/deal.II/lac/include/lac/dsmatrix.h @@ -189,6 +189,20 @@ class dSMatrixStruct */ unsigned int bandwidth () 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. + * + * This function may only be called if the + * matrix struct is compressed. It does not + * make too much sense otherwise anyway. + */ + unsigned int n_nonzero_elements () const; + /** * Return whether the structure is * compressed or not. @@ -366,7 +380,7 @@ class dSMatrix void clear (); /** - * Return the dimension of the imga space. + * Return the dimension of the image space. * To remember: the matrix is of dimension * $m \times n$. */ @@ -379,6 +393,16 @@ class dSMatrix */ unsigned int n () 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. + */ + unsigned int n_nonzero_elements () const; + /** * Set the element #(i,j)# to #value#. * Throws an error if the entry does diff --git a/deal.II/lac/source/dsmatrix.cc b/deal.II/lac/source/dsmatrix.cc index a0ac457eb9..972864c4df 100644 --- a/deal.II/lac/source/dsmatrix.cc +++ b/deal.II/lac/source/dsmatrix.cc @@ -291,7 +291,15 @@ dSMatrixStruct::bandwidth () const // the entries of this line break; return b; -} +}; + + + +unsigned int +dSMatrixStruct::n_nonzero_elements () const { + Assert (compressed, ExcNotCompressed()); + return colnums[rows]-colnums[0]; +}; @@ -358,6 +366,14 @@ dSMatrix::clear () { +unsigned int +dSMatrix::n_nonzero_elements () const { + Assert (cols != 0, ExcMatrixNotInitialized()); + return cols->n_nonzero_elements (); +}; + + + dSMatrix & dSMatrix::copy_from (const dSMatrix &matrix) { Assert (cols != 0, ExcMatrixNotInitialized());