From f114ce15f8524d39f89c8c481e485555c9f5b0c2 Mon Sep 17 00:00:00 2001 From: Moritz Allmaras Date: Thu, 8 Feb 2007 23:32:55 +0000 Subject: [PATCH] Added SparseMatrixEZ::print_formatted git-svn-id: https://svn.dealii.org/trunk@14427 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.html | 6 +++ deal.II/lac/include/lac/sparse_matrix_ez.h | 12 ++--- .../include/lac/sparse_matrix_ez.templates.h | 51 +++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 836eb3a794..b9434e91c6 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -705,6 +705,12 @@ inconvenience this causes.

lac

    +
  1. Improved: A simple print_formatted + function has been added to SparseMatrixEZ. +
    + (Moritz Allmaras 2007/02/08) +

    +
  2. Fixed: The SparseDirectMA27 class works for symmetric matrices and had a check to make sure the matrix is indeed symmetric. However, the check compared entries for diff --git a/deal.II/lac/include/lac/sparse_matrix_ez.h b/deal.II/lac/include/lac/sparse_matrix_ez.h index 7405970921..eb59a78c7e 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.h @@ -930,12 +930,12 @@ class SparseMatrixEZ : public Subscriptor * may produce @em large amounts of * output if applied to a large matrix! */ -// void print_formatted (std::ostream &out, -// const unsigned int precision = 3, -// const bool scientific = true, -// const unsigned int width = 0, -// const char *zero_string = " ", -// const double denominator = 1.) const; + void print_formatted (std::ostream &out, + const unsigned int precision = 3, + const bool scientific = true, + const unsigned int width = 0, + const char *zero_string = " ", + const double denominator = 1.) const; /** * Write the data of this object diff --git a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h index b65f226d35..128aa29242 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -438,6 +439,56 @@ SparseMatrixEZ::print (std::ostream &out) const } +template +void +SparseMatrixEZ::print_formatted ( std::ostream &out, + const unsigned int precision, + const bool scientific, + const unsigned int width_, + const char* zero_string, + const double denominator) const +{ + AssertThrow (out, ExcIO()); + Assert (m() != 0, ExcNotInitialized()); + Assert (n() != 0, ExcNotInitialized()); + + unsigned int width = width_; + + std::ios::fmtflags old_flags = out.flags(); + unsigned int old_precision = out.precision (precision); + + if (scientific) + { + out.setf (std::ios::scientific, std::ios::floatfield); + if (!width) + width = precision+7; + } else { + out.setf (std::ios::fixed, std::ios::floatfield); + if (!width) + width = precision+2; + } + + // TODO: Skip nonexisting entries + for (unsigned int i=0; ivalue * denominator << ' '; + else + out << std::setw(width) << zero_string << ' '; + } + out << std::endl; + }; + + // reset output format + out.precision(old_precision); + out.flags (old_flags); +} + + template void SparseMatrixEZ::block_write (std::ostream &out) const -- 2.39.5