template <typename number> class SparseMatrix;
class ostream;
-
+//TODO: Documentation on full rows
/**
* Structure representing the sparsity pattern of a sparse matrix.
* 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);
* 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
*/
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#
* 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;
/**
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);
};
rowstart(0),
colnums(0)
{
- reinit (n,n,max_per_row);
+ reinit (n,n,max_per_row,0);
};
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))
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;
};
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)
// 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)