]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Remove vec_len from SparseMatrixStruct, since it is not really used and can be replac...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 17 Nov 1999 08:53:47 +0000 (08:53 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 17 Nov 1999 08:53:47 +0000 (08:53 +0000)
git-svn-id: https://svn.dealii.org/trunk@1865 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 46425ad1d2ef0b9dd5e457a8053350ac16a6fbaa..d89afbae906d5bc0bdfe1e6c16dcd713da7e0855 100644 (file)
@@ -26,11 +26,6 @@ Make ILU decomposition faster by following the comment in the
 Change in-class defined SolverSelector functions out-of-class to
   conform to general style guide. (Ralf?)
 
-Eliminate #vec_len# from the SparseMatrixStruct class. This should
-  be rather simple since as far as I can see it is only used once
-  (at all other places, it is only written) and also its value
-  should be equal to rowstart[row].
-
 Why not replace Vector::scale by Vector::operator *= ?
 
 Use the commented-out version in PreconditionBlock::invert_diagblocks
index 3789eb35fdc9872e41e43c79cd01d71d6872fbc9..e2b0f35155f871e3a6963e0a81a3e1a561a0ea0f 100644 (file)
@@ -497,14 +497,6 @@ class SparseMatrixStruct : public Subscriptor
                                      */
     unsigned int cols;
 
-                                    /**
-                                     * Size of the used part of the
-                                     * #colnums# array. Might be lower than
-                                     * #max_vec_len# if the size was reduced
-                                     * somewhen in the past.
-                                     */
-    unsigned int vec_len;
-
                                     /**
                                      * Size of the actually allocated array
                                      * #colnums#. Here, the same applies as
index 503c9d0a3d4652a15246a6e56eaf520106c8138e..87bffb716b747509a18f485f12f644de46f3bee7 100644 (file)
@@ -101,16 +101,17 @@ SparseMatrix<number>::reinit ()
       max_len = 0;
       return;
     };
-        
-  if (max_len<cols->vec_len)
+
+  const unsigned int N = cols->n_nonzero_elements();
+  if (N > max_len)
     {
       if (val) delete[] val;
-      val = new number[cols->vec_len];
-      max_len = cols->vec_len;
+      val = new number[N];
+      max_len = N;
     };
 
   if (val)
-    fill_n (&val[0], cols->vec_len, 0);
+    fill_n (&val[0], N, 0);
 }
 
 
@@ -175,7 +176,7 @@ SparseMatrix<number>::copy_from (const SparseMatrix<somenumber> &matrix)
   Assert (val != 0, ExcMatrixNotInitialized());
   Assert (cols == matrix.cols, ExcDifferentSparsityPatterns());
 
-  copy (&matrix.val[0], &matrix.val[cols->vec_len],
+  copy (&matrix.val[0], &matrix.val[cols->n_nonzero_elements()],
        &val[0]);
   
   return *this;
@@ -195,7 +196,7 @@ SparseMatrix<number>::add_scaled (const number factor,
 
   number             *val_ptr    = &val[0];
   const somenumber   *matrix_ptr = &matrix.val[0];
-  const number *const end_ptr    = &val[cols->vec_len];
+  const number *const end_ptr    = &val[cols->n_nonzero_elements()];
 
   while (val_ptr != end_ptr)
     *val_ptr++ += factor * *matrix_ptr++;
index 4ae7652adb9cf37af15e4cc3d46ffc7a1f62e0a0..d0e3554cb3ad7d594c599c4f1d151759a9c92256 100644 (file)
@@ -214,7 +214,7 @@ SparseMatrixStruct::reinit (const unsigned int m,
 {
                                   // simply map this function to the
                                   // other #reinit# function
-  vector<unsigned int> row_lengths (m, max_per_row);
+  const vector<unsigned int> row_lengths (m, max_per_row);
   reinit (m, n, row_lengths);
 };
 
@@ -231,10 +231,6 @@ SparseMatrixStruct::reinit (const unsigned int m,
          
   rows = m;
   cols = n;
-  vec_len = accumulate (row_lengths.begin(), row_lengths.end(), 0);
-  max_row_length = (row_lengths.size() == 0 ?
-                   0 :
-                   *max_element(row_lengths.begin(), row_lengths.end()));
 
                                   // delete empty matrices
   if ((m==0) || (n==0))
@@ -243,7 +239,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 = max_dim = rows = cols = 0;
                                       // if dimension is zero: ignore
                                       // max_per_row
       max_row_length = 0;
@@ -251,6 +247,18 @@ SparseMatrixStruct::reinit (const unsigned int m,
       return;
     };
 
+                                  // find out how many entries we
+                                  // need in the #colnums# array. if
+                                  // this number is larger than
+                                  // #max_vec_len#, then we will need
+                                  // to reallocate memory
+  const unsigned int vec_len = accumulate (row_lengths.begin(),
+                                          row_lengths.end(), 0);
+  max_row_length = (row_lengths.size() == 0 ?
+                   0 :
+                   *max_element(row_lengths.begin(), row_lengths.end()));
+
+
                                   // allocate memory for the rowstart
                                   // values, if necessary
   if (rows > max_dim)
@@ -271,7 +279,7 @@ SparseMatrixStruct::reinit (const unsigned int m,
 
                                   // set the rowstart array 
   rowstart[0] = 0;
-  for (unsigned int i=1; i<=rows; i++)
+  for (unsigned int i=1; i<=rows; ++i)
     rowstart[i] = rowstart[i-1]+row_lengths[i-1];
   Assert (rowstart[rows]==vec_len, ExcInternalError());
 
@@ -361,7 +369,7 @@ SparseMatrixStruct::compress ()
              ExcInternalError());
     };
   
-  vec_len = rowstart[rows] = next_row_start;
+  rowstart[rows] = next_row_start;
   compressed = true;
 };
 
@@ -384,9 +392,7 @@ SparseMatrixStruct::empty () const {
       Assert (rows==0, ExcInternalError());
       Assert (cols==0, ExcInternalError());
       Assert (colnums==0, ExcInternalError());
-      Assert (vec_len==0, ExcInternalError());
       Assert (max_vec_len==0, ExcInternalError());
-      Assert (vec_len==0, ExcInternalError());
 
       return true;
     };

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.