From: cvs Date: Mon, 11 Oct 1999 23:33:03 +0000 (+0000) Subject: long rows for sparse matrix X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdfeff3c2f98636acd1fe83b65fd2948391afb82;p=dealii-svn.git long rows for sparse matrix git-svn-id: https://svn.dealii.org/trunk@1756 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index c95e4155e7..06f47d0336 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -23,7 +23,7 @@ template class Vector; template 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; /** diff --git a/deal.II/lac/source/sparse_matrix.cc b/deal.II/lac/source/sparse_matrix.cc index ef79b31654..3669359bbc 100644 --- a/deal.II/lac/source/sparse_matrix.cc +++ b/deal.II/lac/source/sparse_matrix.cc @@ -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