From d9c413524567f2d50a52f70f1c95cf1e409e59d1 Mon Sep 17 00:00:00 2001 From: guido Date: Mon, 18 Apr 2005 18:25:07 +0000 Subject: [PATCH] new function print_formatted, fill fixed git-svn-id: https://svn.dealii.org/trunk@10511 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/lapack_full_matrix.h | 74 +++++++++++++++++--- deal.II/lac/source/lapack_full_matrix.cc | 50 +++++++++++++ 2 files changed, 113 insertions(+), 11 deletions(-) diff --git a/deal.II/lac/include/lac/lapack_full_matrix.h b/deal.II/lac/include/lac/lapack_full_matrix.h index 4074d84510..538729829c 100644 --- a/deal.II/lac/include/lac/lapack_full_matrix.h +++ b/deal.II/lac/include/lac/lapack_full_matrix.h @@ -229,6 +229,55 @@ class LAPACKFullMatrix : public TransposeTable std::complex eigenvalue (unsigned int i) const; + /** + * Print the matrix and allow + * formatting of entries. + * + * The parameters allow for a + * flexible setting of the output + * format: + * + * @arg precision + * denotes the number of trailing + * digits. + * + * @arg scientific is + * used to determine the number + * format, where + * scientific = + * false means fixed + * point notation. + * + * @arg width denotes + * the with of each column. A + * zero entry for width + * makes the function compute a + * width, but it may be changed + * to a positive value, if output + * is crude. + * + * @arg zero_string + * specifies a string printed for + * zero entries. + * + * @arg denominator + * Multiply the whole matrix by + * this common denominator to get + * nicer numbers. + * + * @arg threshold: all + * entries with absolute value + * smaller than this are + * considered zero. + */ + void print_formatted (std::ostream &out, + const unsigned int presicion=3, + const bool scientific = true, + const unsigned int width = 0, + const char *zero_string = " ", + const double denominator = 1., + const double threshold = 0.) const; + private: /** * Since LAPACK operations @@ -294,18 +343,21 @@ LAPACKFullMatrix::fill ( const unsigned int src_offset_i, const unsigned int src_offset_j) { - const unsigned int endrow = src_offset_i + this->m(); - const unsigned int endcol = src_offset_j + this->n(); - - for (unsigned int i=0;im();++i) + const unsigned int endrow = this->n_rows() - dst_offset_i; + const unsigned int endcol = src_offset_j + this->n_cols(); + + const typename MATRIX::const_iterator + end = M.end(src_offset_i+n_rows()-dst_offset_i-1); + for (typename MATRIX::const_iterator entry = M.begin(src_offset_i); + entry != end; ++entry) { - const typename MATRIX::const_iterator end = M.end(src_offset_i+i); - for (typename MATRIX::const_iterator entry = M.begin(src_offset_i+i); - entry != end; ++entry) - if (entry->column() < endcol) - this->el(dst_offset_i+i, - dst_offset_j+entry->column()-src_offset_j) - = entry->value(); + const unsigned int i = entry->row(); + const unsigned int j = entry->column(); + + if (j >= src_offset_j && j < endcol) + this->operator()(dst_offset_i-src_offset_i+i, + dst_offset_j-src_offset_j+j) + = entry->value(); } state = LAPACKSupport::matrix; diff --git a/deal.II/lac/source/lapack_full_matrix.cc b/deal.II/lac/source/lapack_full_matrix.cc index d2c4b2c6c6..8565a5072e 100644 --- a/deal.II/lac/source/lapack_full_matrix.cc +++ b/deal.II/lac/source/lapack_full_matrix.cc @@ -18,6 +18,7 @@ #include #include +#include using namespace LAPACKSupport; @@ -225,6 +226,55 @@ LAPACKFullMatrix::Tvmult_add ( Tvmult(w, v, true); } +template +void +LAPACKFullMatrix::print_formatted ( + std::ostream &out, + const unsigned int precision, + const bool scientific, + const unsigned int width_, + const char *zero_string, + const double denominator, + const double threshold) const +{ + unsigned int width = width_; + + Assert ((!this->empty()) || (this->n_cols()+this->n_rows()==0), + ExcInternalError()); + + // set output format, but store old + // state + 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; + } + + for (unsigned int i=0; iel(i,j)) > threshold) + out << std::setw(width) + << this->el(i,j) * denominator << ' '; + else + out << std::setw(width) << zero_string << ' '; + out << std::endl; + }; + + AssertThrow (out, ExcIO()); + // reset output format + out.flags (old_flags); + out.precision(old_precision); +} + template class LAPACKFullMatrix; template LAPACKFullMatrix & -- 2.39.5