From 7de9f714b03d4bd7b8a8ddffe121243f06d3e2d4 Mon Sep 17 00:00:00 2001 From: cvs Date: Mon, 11 Oct 1999 18:45:37 +0000 Subject: [PATCH] more flexible output for SparseMatrix and Vector git-svn-id: https://svn.dealii.org/trunk@1754 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/sparse_matrix.h | 29 +++++++++-------- .../lac/include/lac/sparse_matrix.templates.h | 31 ++++++++++++++----- deal.II/lac/include/lac/vector.h | 7 +++-- deal.II/lac/include/lac/vector.templates.h | 24 ++++++++++++-- 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 2a295495a7..c95e4155e7 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -967,7 +967,7 @@ class SparseMatrix : public Subscriptor template void precondition_SOR (Vector &dst, const Vector &src, - const number om = 1.) const; + const number om = 1.) const; /** * Perform SSOR preconditioning in-place. @@ -1048,24 +1048,27 @@ class SparseMatrix : public Subscriptor * matrix elements which are explicitely * set to zero are displayed as such. * - * Each entry is printed in scientific - * format, with one pre-comma digit and - * the number of digits given by - * #precision# after the comma, with one - * space following. - * The precision defaults to four, which - * suffices for most cases. The precision - * and output format are {\it not} - * properly reset to the old values - * when the function exits. + * The parameters allow for a flexible setting of + * the output format: #precision# and #scientific# + * are used to determine the number format, where + * #scientific# = #false# means fixed point notation. + * A zero entry for #width# makes the function compute a + * width, but it may be changed to a positive value, + * if output is crude. * - * You should be aware that this function + * Additionally, a character for an empty value + * may be specified. + * + * This function * may produce {\bf large} amounts of * output if applied to a large matrix! * Be careful with it. */ void print_formatted (ostream &out, - const unsigned int presicion=3) const; + const unsigned int presicion=3, + bool scientific=true, + unsigned int width=0, + const char * zero_string = " ") const; /** * Exception diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index ec663eee86..83c0949624 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -904,24 +904,41 @@ void SparseMatrix::print (ostream &out) const { template -void SparseMatrix::print_formatted (ostream &out, const unsigned int precision) const { +void SparseMatrix::print_formatted (ostream &out, + const unsigned int precision, + bool scientific, + unsigned int width, + const char* zero_string) const +{ Assert (cols != 0, ExcMatrixNotInitialized()); Assert (val != 0, ExcMatrixNotInitialized()); + out.precision (precision); - out.setf (ios::scientific, ios::floatfield); // set output format - - for (unsigned int i=0; ioperator()(i,j)] << ' '; else - out << setw(precision+8) << " "; + out << setw(width) << zero_string << ' '; out << endl; }; AssertThrow (out, ExcIO()); - out.setf (0, ios::floatfield); // reset output format +// see above + +// out.setf (0, ios::floatfield); // reset output format }; diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 4b51edef3f..d057326ca0 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -375,9 +375,12 @@ class Vector { void print (const char* format = 0) const; /** - * Print to given stream, one element per line. + * Print to a stream. + * */ - void print (ostream &) const; + void print (ostream &, unsigned int precision = 3, + bool scientific = true, + bool across = true) const; /** * Write the vector en bloc to a file. This diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index 0f573a2ab4..d1855941f3 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -579,11 +579,29 @@ void Vector::print (const char* format) const template -void Vector::print (ostream &out) const { +void Vector::print (ostream &out, + unsigned int precision, + bool scientific, + bool across) const +{ Assert (dim!=0, ExcEmptyVector()); - for (unsigned int i=0; i