]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Added SparseMatrixEZ::print_formatted
authorallmaras <allmaras@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Feb 2007 23:32:55 +0000 (23:32 +0000)
committerallmaras <allmaras@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Feb 2007 23:32:55 +0000 (23:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@14427 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.html
deal.II/lac/include/lac/sparse_matrix_ez.h
deal.II/lac/include/lac/sparse_matrix_ez.templates.h

index 836eb3a794a2da37babfe3d0e33d133136380ef0..b9434e91c6206d8773472648cf7fa98be0e93f62 100644 (file)
@@ -705,6 +705,12 @@ inconvenience this causes.
 <h3>lac</h3>
 
 <ol>
+  <li> <p>Improved: A simple <code class="member">print_formatted</code> 
+       function has been added to <code class="class">SparseMatrixEZ</code>.
+       <br>
+       (Moritz Allmaras 2007/02/08)
+       </p>
+
   <li> <p>Fixed: The <code class="class">SparseDirectMA27</code> 
        class works for symmetric matrices and had a check to make sure the
        matrix is indeed symmetric. However, the check compared entries for
index 7405970921bd1b3cc234e60d3b95e7a1b0babe27..eb59a78c7e163ad92762d55e49fd9566684633b9 100644 (file)
@@ -930,12 +930,12 @@ class SparseMatrixEZ : public Subscriptor
                                      * may produce @em large amounts of
                                      * output if applied to a large matrix!
                                      */
-//      void print_formatted (std::ostream       &out,
-//                       const unsigned int  precision   = 3,
-//                       const bool          scientific  = true,
-//                       const unsigned int  width       = 0,
-//                       const char         *zero_string = " ",
-//                       const double        denominator = 1.) const;
+    void print_formatted (std::ostream       &out,
+                         const unsigned int  precision   = 3,
+                         const bool          scientific  = true,
+                         const unsigned int  width       = 0,
+                         const char         *zero_string = " ",
+                         const double        denominator = 1.) const;
 
                                     /**
                                      * Write the data of this object
index b65f226d35e2a88b160adc4a8b26340fdae04a08..128aa2924262b9957c9cad6bca67dcc763af98ad 100644 (file)
@@ -18,6 +18,7 @@
 #include <lac/vector.h>
 
 #include <iostream>
+#include <iomanip>
 #include <algorithm>
 #include <cmath>
 
@@ -438,6 +439,56 @@ SparseMatrixEZ<number>::print (std::ostream &out) const
 }
 
 
+template <typename number>
+void 
+SparseMatrixEZ<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
+{
+  AssertThrow (out, ExcIO());
+  Assert (m() != 0, ExcNotInitialized());
+  Assert (n() != 0, ExcNotInitialized());
+
+  unsigned int width = width_;
+       
+  std::ios::fmtflags old_flags = out.flags();
+  unsigned int old_precision = out.precision (precision);
+
+  if (scientific)
+    {
+      out.setf (std::ios::scientific, std::ios::floatfield);
+      if (!width)
+       width = precision+7;
+    } else {
+      out.setf (std::ios::fixed, std::ios::floatfield);
+      if (!width)
+       width = precision+2;
+    }
+
+                                  // TODO: Skip nonexisting entries
+  for (unsigned int i=0; i<m(); ++i)
+    {
+      for (unsigned int j=0; j<n(); ++j)
+       {
+         const Entry* entry = locate(i,j);
+         if (entry)
+           out << std::setw(width)
+               << entry->value * denominator << ' ';
+         else
+           out << std::setw(width) << zero_string << ' ';
+       }
+      out << std::endl;
+    };
+  
+                                  // reset output format
+  out.precision(old_precision);
+  out.flags (old_flags);
+}
+
+
 template <typename number>
 void
 SparseMatrixEZ<number>::block_write (std::ostream &out) const 

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.