]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add formatted print function to sparse matrices.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 15 Apr 1998 10:03:44 +0000 (10:03 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 15 Apr 1998 10:03:44 +0000 (10:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@173 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 8dbfba49ffeaf98409522c01b3dd79524d280773..7ee18cddb58f4a8a3e60ac438198dca51764fd65 100644 (file)
@@ -320,6 +320,25 @@ class dSMatrix
                                      */
     void print (ostream &out) 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 explicitely
+                                     * set to zero are displayed as such.
+                                     *
+                                     * Each entry is printed as a six character
+                                     * wide field, with one space following.
+                                     *
+                                     * 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;
+    
                                     /**
                                      * Exception
                                      */
index 7c73da5cfe4a7f7cb02c6e61fb65af1f2ee4ea1b..fadb3854d109db1fdf7baa9e5ba430c071894e78 100644 (file)
@@ -5,8 +5,8 @@
 // Roland Becker, Guido Kanschat, Franz-Theo Suttmeier
 
 #include <lac/dsmatrix.h>
-#include <ostream.h>
-
+#include <iostream>
+#include <iomanip>
 
 /*----------------- from sort.h -------------------------*/
 
@@ -625,3 +625,17 @@ void dSMatrix::print (ostream &out) const {
     for (unsigned int j=cols->rowstart[i]; j<cols->rowstart[i+1]; ++j)
       out << "(" << i << "," << cols->colnums[j] << ") " << val[j] << endl;
 };
+
+
+
+void dSMatrix::print_formatted (ostream &out) const {
+  for (unsigned int i=0; i<m(); ++i) 
+    {
+      for (unsigned int j=0; j<n(); ++j)
+       if ((*cols)(i,j) != -1)
+         out << setw(6) << val[cols->operator()(i,j)] << " ";
+       else
+         out << "       ";
+      out << endl;
+    };
+};

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.