From 4f57debab52cd19c1d2328d0e7d8b5a6c6f5fe5d Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 17 Nov 1999 08:53:47 +0000 Subject: [PATCH] Remove vec_len from SparseMatrixStruct, since it is not really used and can be replaced easily by n_nonzero_elements(). git-svn-id: https://svn.dealii.org/trunk@1865 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/Todo | 5 ---- deal.II/lac/include/lac/sparse_matrix.h | 8 ------ .../lac/include/lac/sparse_matrix.templates.h | 15 ++++++----- deal.II/lac/source/sparse_matrix.cc | 26 ++++++++++++------- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/deal.II/lac/Todo b/deal.II/lac/Todo index 46425ad1d2..d89afbae90 100644 --- a/deal.II/lac/Todo +++ b/deal.II/lac/Todo @@ -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 diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 3789eb35fd..e2b0f35155 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -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 diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 503c9d0a3d..87bffb716b 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -101,16 +101,17 @@ SparseMatrix::reinit () max_len = 0; return; }; - - if (max_lenvec_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::copy_from (const SparseMatrix &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::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++; diff --git a/deal.II/lac/source/sparse_matrix.cc b/deal.II/lac/source/sparse_matrix.cc index 4ae7652adb..d0e3554cb3 100644 --- a/deal.II/lac/source/sparse_matrix.cc +++ b/deal.II/lac/source/sparse_matrix.cc @@ -214,7 +214,7 @@ SparseMatrixStruct::reinit (const unsigned int m, { // simply map this function to the // other #reinit# function - vector row_lengths (m, max_per_row); + const vector 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; }; -- 2.39.5