From 2caa3b9342ec5a519a5be5a79405e830d78b6708 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Mon, 24 Jun 2013 06:54:03 +0000 Subject: [PATCH] Allow for resorting of diagonal git-svn-id: https://svn.dealii.org/trunk@29854 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/lac/sparse_matrix.h | 57 +++++++++++++++------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/deal.II/include/deal.II/lac/sparse_matrix.h b/deal.II/include/deal.II/lac/sparse_matrix.h index 0419e4d371..5c3fe719a8 100644 --- a/deal.II/include/deal.II/lac/sparse_matrix.h +++ b/deal.II/include/deal.II/lac/sparse_matrix.h @@ -1476,13 +1476,18 @@ public: //@{ /** - * Print the matrix to the given stream, using the format (row,column) - * value, i.e. one nonzero entry of the matrix per line. If @p across - * is true, print all entries on a single line, using the format - * row,column:value + * Print the matrix to the given stream, using the format + * (row,column) value, i.e. one nonzero entry of the matrix + * per line. If across is true, print all entries on a + * single line, using the format row,column:value. + * + * If the argument diagonal_first is true, diagonal + * elements of quadratic matrices are printed first in their row, + * corresponding to the internal storage scheme. If it is false, the + * elements in a row are written in ascending column order. */ template - void print (STREAM &out, bool across=false) const; + void print (STREAM &out, bool across=false, bool diagonal_first=true) const; /** * Print the matrix in the usual format, i.e. as a matrix and not as a list @@ -2464,22 +2469,40 @@ SparseMatrix::end (const size_type r) template template inline -void SparseMatrix::print (STREAM &out, bool across) const +void SparseMatrix::print (STREAM &out, bool across, bool diagonal_first) const { Assert (cols != 0, ExcNotInitialized()); Assert (val != 0, ExcNotInitialized()); - + + bool hanging_diagonal = false; + number diagonal; + + for (size_type i=0; irows; ++i) + for (size_type j=cols->rowstart[i]; jrowstart[i+1]; ++j) + { + if (!diagonal_first && i == cols->colnums[j]) + { + diagonal = val[j]; + hanging_diagonal = true; + } + else + { + if (hanging_diagonal && cols->colnums[j]>i) + { + if (across) + out << '(' << i << ',' << i << ") " << diagonal << std::endl; + else + out << ' ' << i << ',' << i << ':' << diagonal; + hanging_diagonal = false; + } + if (across) + out << ' ' << i << ',' << cols->colnums[j] << ':' << val[j]; + else + out << "(" << i << "," << cols->colnums[j] << ") " << val[j] << std::endl; + } + } if (across) - { - for (size_type i=0; irows; ++i) - for (size_type j=cols->rowstart[i]; jrowstart[i+1]; ++j) - out << ' ' << i << ',' << cols->colnums[j] << ':' << val[j]; - out << std::endl; - } - else - for (size_type i=0; irows; ++i) - for (size_type j=cols->rowstart[i]; jrowstart[i+1]; ++j) - out << "(" << i << "," << cols->colnums[j] << ") " << val[j] << std::endl; + out << std::endl; } -- 2.39.5