]> https://gitweb.dealii.org/ - dealii.git/commitdiff
allow print to LogStream and add threshold to print_formatted
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Fri, 8 Apr 2005 09:18:00 +0000 (09:18 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Fri, 8 Apr 2005 09:18:00 +0000 (09:18 +0000)
git-svn-id: https://svn.dealii.org/trunk@10426 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/full_matrix.h
deal.II/lac/include/lac/full_matrix.templates.h
deal.II/lac/source/full_matrix.double.cc
deal.II/lac/source/full_matrix.float.cc
tests/fe/fe_data_test.cc
tests/fe/transfer.cc

index 4a75a0f99dc5457afdba7419fe124ad2b2d3f234..ff15dbf3b6ac9848ea68465e9817ccad8d292bcb 100644 (file)
@@ -480,55 +480,59 @@ class FullMatrix : public Table<2,number>
                                      * Output of the matrix in
                                      * user-defined format.
                                      */
-    void print (std::ostream       &s,
+    template <class STREAM>
+    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: <tt>precision</tt> and
-                                     * <tt>scientific</tt> are used to
-                                     * determine the number format,
-                                     * where <tt>scientific</tt> = <tt>false</tt>
-                                     * means fixed point notation.  A
-                                     * zero entry for <tt>width</tt> 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 <tt>precision</tt>
+                                     * 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 <tt>scientific</tt> is
+                                     * used to determine the number
+                                     * format, where
+                                     * <tt>scientific</tt> =
+                                     * <tt>false</tt> means fixed
+                                     * point notation.
                                      *
-                                     * @attention This function
-                                     * may produce <b>large</b> amounts of
-                                     * output if applied to a large matrix!
-                                     */
+                                     * @arg <tt>width</tt> denotes
+                                     * the with of each column. A
+                                     * zero entry for <tt>width</tt>
+                                     * makes the function compute a
+                                     * width, but it may be changed
+                                     * to a positive value, if output
+                                     * is crude.
+                                     *
+                                     * @arg <tt>zero_string</tt>
+                                     * specifies a string printed for
+                                     * zero entries.
+                                     *
+                                     * @arg <tt>denominator</tt>
+                                     * Multiply the whole matrix by
+                                     * this common denominator to get
+                                     * nicer numbers.
+                                     *
+                                     * @arg <tt>threshold</tt>: 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
index 3955d0b6a4ffd13efdca77b8ac3bf2ff2554c32a..610a0650c75bbf2a91ce7d88ee9af4f17c99f9b1 100644 (file)
@@ -730,8 +730,9 @@ number FullMatrix<number>::linfty_norm () const
 
 
 template <typename number>
+template <class STREAM>
 void
-FullMatrix<number>::print (std::ostream       &s,
+FullMatrix<number>::print (STREAM             &s,
                           const unsigned int  w,
                           const unsigned int  p) const
 {
@@ -1466,12 +1467,14 @@ FullMatrix<number>::precondition_Jacobi (Vector<somenumber>       &dst,
 
 template <typename number>
 void
-FullMatrix<number>::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<number>::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<number>::print_formatted (std::ostream       &out,
   for (unsigned int i=0; i<m(); ++i) 
     {
       for (unsigned int j=0; j<n(); ++j)
-       if (this->el(i,j) != 0)
+       if (std::fabs(this->el(i,j)) > threshold)
          out << std::setw(width)
              << this->el(i,j) * denominator << ' ';
        else
index 2de0c3e36ce6572952ddb28ef1efb011f23df6fb..ed96b2275091cb25d38cb13e520cc76c734e7ebc 100644 (file)
 
 template class FullMatrix<TYPEMAT>;
 
+template void FullMatrix<TYPEMAT>::print(
+  LogStream&, const unsigned int, const unsigned int) const;
+template void FullMatrix<TYPEMAT>::print(
+  std::ostream&, const unsigned int, const unsigned int) const;
+
 template FullMatrix<TYPEMAT>& FullMatrix<TYPEMAT>::operator =(
   const FullMatrix<float>&);
 
index c3f66b1fed05128a38153eee7d93fb546276215f..c9fe30d339e5fb020eb0549203debd1a8e7b38a9 100644 (file)
 
 
 #include <lac/full_matrix.templates.h>
+#include <base/logstream.h>
 
 #define TYPEMAT float
 
 template class FullMatrix<TYPEMAT>;
 
+template void FullMatrix<TYPEMAT>::print(
+  LogStream&, const unsigned int, const unsigned int) const;
+template void FullMatrix<TYPEMAT>::print(
+  std::ostream&, const unsigned int, const unsigned int) const;
+
 template FullMatrix<TYPEMAT>& FullMatrix<TYPEMAT>::operator =(
   const FullMatrix<double>&);
 
index e280365e11531ba3efeaf0e8d8fae02ed7b6ff49..5c1b4b1a9911a91f7831cb44e4d6ef9a3d2187c7 100644 (file)
@@ -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>();
index 1248c9a2943f2838ef69e84df052e4d045f48455..080b8d39af88f84cbd809d979bc1bd6c96e9a515 100644 (file)
@@ -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 <base/logstream.h>
 #include <base/quadrature_lib.h>
 #include <lac/vector.h>
 #include <lac/sparse_matrix.h>
@@ -42,7 +43,7 @@ char fname[50];
 
 template<int dim>
 inline void
-print_matrix(std::ostream& of,
+print_matrix(LogStream& of,
             Triangulation<dim>& tr,
             unsigned int level,
             const FiniteElement<dim>& 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);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.