From: kanschat Date: Mon, 24 Jun 2013 06:54:03 +0000 (+0000) Subject: Allow for resorting of diagonal X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b7647c083061e87a6590b96dc3253c316031296;p=dealii-svn.git Allow for resorting of diagonal git-svn-id: https://svn.dealii.org/trunk@29854 0785d39b-7218-0410-832d-ea1e28bc413d --- 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; }