]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add function to inquire the number of nonzero elements.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 18 May 1998 08:26:56 +0000 (08:26 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 18 May 1998 08:26:56 +0000 (08:26 +0000)
git-svn-id: https://svn.dealii.org/trunk@296 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/dsmatrix.h
deal.II/lac/source/dsmatrix.cc

index 73e874750b8fffd77a32726faf1c5108821f5c3a..064cf26a48a504ff953d340d9dc1fcac079f7ac9 100644 (file)
@@ -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
index a0ac457eb9cad70d5e60e54c8890cc1a05da64d9..972864c4dfa09fe129fde9a55739bba6fe615bb7 100644 (file)
@@ -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());

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.