]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
more flexible output for SparseMatrix and Vector
authorcvs <cvs@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 11 Oct 1999 18:45:37 +0000 (18:45 +0000)
committercvs <cvs@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 11 Oct 1999 18:45:37 +0000 (18:45 +0000)
git-svn-id: https://svn.dealii.org/trunk@1754 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix.h
deal.II/lac/include/lac/sparse_matrix.templates.h
deal.II/lac/include/lac/vector.h
deal.II/lac/include/lac/vector.templates.h

index 2a295495a711ddf76365595d4113dea1d8aa37d0..c95e4155e75251f25331ae95b8c902c0a6410539 100644 (file)
@@ -967,7 +967,7 @@ class SparseMatrix : public Subscriptor
     template <typename somenumber>
     void precondition_SOR (Vector<somenumber>       &dst,
                           const Vector<somenumber> &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
index ec663eee8694b4c685c4135e9b254fd7738f7b27..83c09496244c786f1f49177a96da6575127f774c 100644 (file)
@@ -904,24 +904,41 @@ void SparseMatrix<number>::print (ostream &out) const {
 
 
 template <typename number>
-void SparseMatrix<number>::print_formatted (ostream &out, const unsigned int precision) const {
+void SparseMatrix<number>::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; i<m(); ++i) 
+  if (scientific)
+    {
+      out.setf (ios::scientific, ios::floatfield);
+      if (!width)
+       width = precision+7;
+    } else {
+      out.setf (ios::fixed, ios::floatfield);
+      if (!width)
+       width = precision+2;
+    }
+
+  for (unsigned int i=0; i<m(); ++i)
     {
       for (unsigned int j=0; j<n(); ++j)
        if ((*cols)(i,j) != -1)
-         out << setw(precision+7)
+         out << setw(width)
              << val[cols->operator()(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
 };
 
index 4b51edef3f6bb9f510f089f8d9e1b7f158fa46b5..d057326ca009fe6033ff3a32b8952c4b9c8cd93e 100644 (file)
@@ -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
index 0f573a2ab4ed52cc682ae197e9581bde7bb37c1f..d1855941f34f2a78330db4f3cd411192fcbb919b 100644 (file)
@@ -579,11 +579,29 @@ void Vector<Number>::print (const char* format) const
 
 
 template <typename Number>
-void Vector<Number>::print (ostream &out) const {
+void Vector<Number>::print (ostream &out,
+                           unsigned int precision,
+                           bool scientific,
+                           bool across) const
+{
   Assert (dim!=0, ExcEmptyVector());
-  for (unsigned int i=0; i<size(); ++i)
-    out << val[i] << endl;
 
+  out.precision (precision);
+  if (scientific)
+    {
+      out.setf (ios::scientific, ios::floatfield);
+    } else {
+      out.setf (ios::fixed, ios::floatfield);
+    }
+
+  if (across)
+    for (unsigned int i=0; i<size(); ++i)
+      out << val[i] << ' ';
+  else
+    for (unsigned int i=0; i<size(); ++i)
+      out << val[i] << endl;
+  out << endl;
+  
   AssertThrow (out, ExcIO());
 };
 

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.