From e6c9354cc3622347b93f244358413ada2746845e Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Fri, 8 Apr 2005 09:18:00 +0000 Subject: [PATCH] allow print to LogStream and add threshold to print_formatted git-svn-id: https://svn.dealii.org/trunk@10426 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/full_matrix.h | 74 ++++++++++--------- .../lac/include/lac/full_matrix.templates.h | 19 +++-- deal.II/lac/source/full_matrix.double.cc | 5 ++ deal.II/lac/source/full_matrix.float.cc | 6 ++ tests/fe/fe_data_test.cc | 1 + tests/fe/transfer.cc | 12 ++- 6 files changed, 70 insertions(+), 47 deletions(-) diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h index 4a75a0f99d..ff15dbf3b6 100644 --- a/deal.II/lac/include/lac/full_matrix.h +++ b/deal.II/lac/include/lac/full_matrix.h @@ -480,55 +480,59 @@ class FullMatrix : public Table<2,number> * Output of the matrix in * user-defined format. */ - void print (std::ostream &s, + template + void print (STREAM &s, const unsigned int width=5, const unsigned int precision=2) const; /** - * Print the matrix in the usual - * format, i.e. as a matrix and - * not as a list of nonzero - * elements. For better - * readability, elements not in - * the matrix are displayed as - * empty space, while matrix - * elements which are explicitly - * set to zero are displayed as - * such. - * + * Print the matrix and allow + * formatting of entries. + * * 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. + * format: * - * Additionally, a character for - * an empty value may be - * specified. + * @arg precision + * denotes the number of trailing + * digits. * - * Finally, the whole matrix can - * be multiplied with a common - * denominator to produce more - * readable output, even - * integers. + * @arg scientific is + * used to determine the number + * format, where + * scientific = + * false means fixed + * point notation. * - * @attention This function - * may produce large amounts of - * output if applied to a large matrix! - */ + * @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; + const double denominator = 1., + const double threshold = 0.) const; /** * Determine an estimate for the diff --git a/deal.II/lac/include/lac/full_matrix.templates.h b/deal.II/lac/include/lac/full_matrix.templates.h index 3955d0b6a4..610a0650c7 100644 --- a/deal.II/lac/include/lac/full_matrix.templates.h +++ b/deal.II/lac/include/lac/full_matrix.templates.h @@ -730,8 +730,9 @@ number FullMatrix::linfty_norm () const template +template void -FullMatrix::print (std::ostream &s, +FullMatrix::print (STREAM &s, const unsigned int w, const unsigned int p) const { @@ -1466,12 +1467,14 @@ FullMatrix::precondition_Jacobi (Vector &dst, template void -FullMatrix::print_formatted (std::ostream &out, - const unsigned int precision, - const bool scientific, - const unsigned int width_, - const char *zero_string, - const double denominator) const +FullMatrix::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_; @@ -1497,7 +1500,7 @@ FullMatrix::print_formatted (std::ostream &out, for (unsigned int i=0; iel(i,j) != 0) + if (std::fabs(this->el(i,j)) > threshold) out << std::setw(width) << this->el(i,j) * denominator << ' '; else diff --git a/deal.II/lac/source/full_matrix.double.cc b/deal.II/lac/source/full_matrix.double.cc index 2de0c3e36c..ed96b22750 100644 --- a/deal.II/lac/source/full_matrix.double.cc +++ b/deal.II/lac/source/full_matrix.double.cc @@ -19,6 +19,11 @@ template class FullMatrix; +template void FullMatrix::print( + LogStream&, const unsigned int, const unsigned int) const; +template void FullMatrix::print( + std::ostream&, const unsigned int, const unsigned int) const; + template FullMatrix& FullMatrix::operator =( const FullMatrix&); diff --git a/deal.II/lac/source/full_matrix.float.cc b/deal.II/lac/source/full_matrix.float.cc index c3f66b1fed..c9fe30d339 100644 --- a/deal.II/lac/source/full_matrix.float.cc +++ b/deal.II/lac/source/full_matrix.float.cc @@ -13,11 +13,17 @@ #include +#include #define TYPEMAT float template class FullMatrix; +template void FullMatrix::print( + LogStream&, const unsigned int, const unsigned int) const; +template void FullMatrix::print( + std::ostream&, const unsigned int, const unsigned int) const; + template FullMatrix& FullMatrix::operator =( const FullMatrix&); diff --git a/tests/fe/fe_data_test.cc b/tests/fe/fe_data_test.cc index e280365e11..5c1b4b1a99 100644 --- a/tests/fe/fe_data_test.cc +++ b/tests/fe/fe_data_test.cc @@ -142,6 +142,7 @@ int main(int,char) deallog.attach(logfile); deallog.depth_console(0); // deallog.log_execution_time(true); +// deallog.log_time_differences(true); test_fe_datas<1>(); test_fe_datas<2>(); diff --git a/tests/fe/transfer.cc b/tests/fe/transfer.cc index 1248c9a294..080b8d39af 100644 --- a/tests/fe/transfer.cc +++ b/tests/fe/transfer.cc @@ -2,7 +2,7 @@ // transfer.cc,v 1.4 2003/04/09 15:49:55 wolf Exp // Version: // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -16,6 +16,7 @@ //---------------------------- show_transfer.cc --------------------------- #include "../tests.h" +#include #include #include #include @@ -42,7 +43,7 @@ char fname[50]; template inline void -print_matrix(std::ostream& of, +print_matrix(LogStream& of, Triangulation& tr, unsigned int level, const FiniteElement& finel, @@ -74,6 +75,11 @@ print_matrix(std::ostream& of, int main() { + std::ofstream of("transfer.output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + Triangulation<2> tr2; GridGenerator::hyper_cube(tr2, -1., 1.); @@ -84,8 +90,6 @@ main() GridGenerator::hyper_cube(tr3, -1., 1.); tr3.refine_global(3); - std::ofstream of("transfer.output"); - TEST(2, 1, FE_Q, 1); TEST(2, 1, FE_Q, 2); TEST(2, 1, FE_Q, 3); -- 2.39.5