]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
long rows for sparse matrix
authorcvs <cvs@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 11 Oct 1999 23:33:03 +0000 (23:33 +0000)
committercvs <cvs@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 11 Oct 1999 23:33:03 +0000 (23:33 +0000)
git-svn-id: https://svn.dealii.org/trunk@1756 0785d39b-7218-0410-832d-ea1e28bc413d

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

index c95e4155e75251f25331ae95b8c902c0a6410539..06f47d0336b2baca566e1e53fe58deb991c7bece 100644 (file)
@@ -23,7 +23,7 @@ template <typename number> class Vector;
 template <typename number> class SparseMatrix;
 class ostream;
 
-
+//TODO: Documentation on full rows
 
 /**
  * Structure representing the sparsity pattern of a sparse matrix.
@@ -74,16 +74,19 @@ class SparseMatrixStruct : public Subscriptor
                                      * Initialize a rectangular matrix with
                                      * #m# rows and #n# columns.
                                      * The matrix may contain at most #max_per_row#
-                                     * nonzero entries per row.
+                                     * nonzero entries per row, with the exception
+                                     * of the first #n_long_rows# rows. These may even
+                                     * be full.
                                      */
     SparseMatrixStruct (const unsigned int m,
                        const unsigned int n,
-                       const unsigned int max_per_row);
+                       const unsigned int max_per_row,
+                       const unsigned int n_long_rows = 0);
     
                                     /**
                                      * Initialize a square matrix of dimension
-                                     * #n# with at most #max_per_row#
-                                     * nonzero entries per row.
+                                     * #n# with at most #max_per_row#. There are
+                                     * no full rows with this constructor
                                      */
     SparseMatrixStruct (const unsigned int n,
                        const unsigned int max_per_row);
@@ -146,17 +149,25 @@ class SparseMatrixStruct : public Subscriptor
                                      * with at most #max_per_row#
                                      * nonzero entries per row.
                                      *
+                                     * This matrix also allows for
+                                     * the first rows to have up to
+                                     * #n# entries, if #n_long_rows#
+                                     * is different from zero. This
+                                     * is useful in the case of
+                                     * globally coupling degrees of
+                                     * freedom.
+                                     *
                                      * If #m*n==0# all memory is freed,
                                      * resulting in a total reinitialization
                                      * of the object. If it is nonzero, new
                                      * memory is only allocated if the new
                                      * size extends the old one. This is done
                                      * to save time and to avoid fragmentation
-                                     * of the heap.
-                                     */
+                                     * of the heap.  */
     void reinit (const unsigned int m,
                 const unsigned int n,
-                const unsigned int max_per_row);
+                const unsigned int max_per_row,
+                const unsigned int n_long_rows = 0);
 
                                     /**
                                      * This function compresses the sparsity
@@ -484,6 +495,15 @@ class SparseMatrixStruct : public Subscriptor
                                      */
     unsigned int max_row_len;
 
+                                    /**
+                                     * Number of full rows. This
+                                     * value only has a meaning
+                                     * before compression and allows
+                                     * the first rows to have more
+                                     * elements than #max_per_row#
+                                     */
+    unsigned int n_long_rows;
+    
                                     /**
                                      * Array which hold for each row which
                                      * is the first element in #colnums#
@@ -504,8 +524,7 @@ class SparseMatrixStruct : public Subscriptor
                                      * allocated memory may be larger than
                                      * the region that is used. The actual
                                      * number of elements that was allocated
-                                     * is stored in #max_dim#.
-                                     */
+                                     * is stored in #max_dim#.  */
     unsigned int *rowstart;
 
                                     /**
index ef79b316547fe44ec2b8f3f55a7aa8c585f852ce..3669359bbce8c656f55291b600b89d3ce37ac578 100644 (file)
@@ -45,13 +45,14 @@ SparseMatrixStruct::SparseMatrixStruct (const SparseMatrixStruct &s) :
 
 SparseMatrixStruct::SparseMatrixStruct (const unsigned int m,
                                        const unsigned int n,
-                                       const unsigned int max_per_row) 
+                                       const unsigned int max_per_row,
+                                       const unsigned int long_rows) 
                : max_dim(0),
                  max_vec_len(0),
                  rowstart(0),
                  colnums(0)
 {
-  reinit (m,n,max_per_row);
+  reinit (m,n,max_per_row,long_rows);
 };
 
 
@@ -63,7 +64,7 @@ SparseMatrixStruct::SparseMatrixStruct (const unsigned int n,
                  rowstart(0),
                  colnums(0)
 {
-  reinit (n,n,max_per_row);
+  reinit (n,n,max_per_row,0);
 };
 
 
@@ -185,13 +186,14 @@ SparseMatrixStruct::operator = (const SparseMatrixStruct &s)
 void
 SparseMatrixStruct::reinit (const unsigned int m,
                            const unsigned int n,
-                           const unsigned int max_per_row)
+                           const unsigned int max_per_row,
+                           const unsigned int long_rows)
 {
-  Assert ((max_per_row>0) || ((m==0) && (n==0)), ExcInvalidNumber(max_per_row));
   rows = m;
   cols = n;
-  vec_len = m * max_per_row;
+  vec_len = m * max_per_row + (n-max_per_row) * long_rows;
   max_row_len = max_per_row;
+  n_long_rows = long_rows;
 
                                   // delete empty matrices
   if ((m==0) || (n==0))
@@ -200,7 +202,7 @@ SparseMatrixStruct::reinit (const unsigned int m,
       if (colnums)   delete[] colnums;
       rowstart = 0;
       colnums = 0;
-      max_vec_len = vec_len = max_dim = rows = cols = 0;
+      max_vec_len = vec_len = max_dim = rows = cols = max_row_len = n_long_rows = 0;
       compressed = false;
       return;
     };
@@ -219,8 +221,13 @@ SparseMatrixStruct::reinit (const unsigned int m,
       colnums = new int[max_vec_len];
     };
   
+  unsigned int start = 0;
   for (unsigned int i=0; i<=rows; i++)
-    rowstart[i] = i * max_per_row;
+    {
+      rowstart[i] = start;
+      start += (i<n_long_rows) ? n : max_per_row;
+    }
+  
   fill_n (&colnums[0], vec_len, -1);
 
   if (rows == cols)
@@ -243,7 +250,8 @@ SparseMatrixStruct::compress ()
 
                                   // reserve temporary storage to
                                   // store the entries of one row
-  int *tmp_entries = new int[max_row_len];
+  int safe_row_len = (n_long_rows != 0) ? n_cols() : max_row_len;
+  int *tmp_entries = new int[safe_row_len];
 
                                   // Traverse all rows
   for (unsigned int line=0; line<rows; ++line)

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.