]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add output function.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 27 Apr 1998 09:32:59 +0000 (09:32 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 27 Apr 1998 09:32:59 +0000 (09:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@200 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/dfmatrix.h
deal.II/lac/source/dfmatrix.cc

index 82c9ecde43f99c584f0b33ddaaecafe0c0176fc5..54306adf013a3eef81f1bb50288b122cf9ecdffc 100644 (file)
@@ -361,6 +361,32 @@ class dFMatrix
                                      * Output of the matrix in user-defined format.
                                      */
     void print (FILE* fp, const char* format = 0) const;
+
+                                    /**
+                                     * Print the matrix in the usual format,
+                                     * i.e. as a matrix and not as a list of
+                                     * nonzero elements. For better
+                                     * readability, zero elements
+                                     * are displayed as empty space.
+                                     *
+                                     * 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.
+                                     *
+                                     * You should be aware that 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;
                                     //@}
 
                                     /**
index c2e943d0ac83dcb011234954db98b4d66ecdbfd1..dd42cbabeda527293874e8d1ef76c256fe2289d2 100644 (file)
@@ -1,10 +1,10 @@
 // $Id$
 
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstdio>
 #include <lac/dfmatrix.h>
-
+#include <iomanip>
 
 
 
@@ -980,3 +980,22 @@ void dFMatrix::invert (const dFMatrix &M) {
     };    
 };
   
+
+
+void dFMatrix::print_formatted (ostream &out, const unsigned int precision) const {
+  out.precision (precision);
+  out.setf (ios::scientific, ios::floatfield);   // set output format
+  
+  for (unsigned int i=0; i<m(); ++i) 
+    {
+      for (unsigned int j=0; j<n(); ++j)
+       if (el(i,j) != 0)
+         out << setw(precision+7)
+             << el(i,j) << ' ';
+       else
+         out << setw(precision+8) << " ";
+      out << endl;
+    };
+
+  out.setf (0, ios::floatfield);                 // reset output format
+};

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.