]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
add LogStream output for Vector
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 16 Nov 2010 15:16:53 +0000 (15:16 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 16 Nov 2010 15:16:53 +0000 (15:16 +0000)
git-svn-id: https://svn.dealii.org/trunk@22751 0785d39b-7218-0410-832d-ea1e28bc413d

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

index f21cb7b5cfcbfe2747335bd2d05ed78a926a6465..4bf499550eacf3de54e5f88e7c98813e1f94ee49 100644 (file)
 
 
 #include <base/config.h>
+#include <base/logstream.h>
 #include <base/exceptions.h>
 #include <base/parallel.h>
 #include <base/subscriptor.h>
 #include <boost/lambda/lambda.hpp>
 
 #include <cstdio>
+#include <iostream>
 #include <cstring>
 #include <vector>
 
@@ -877,10 +879,26 @@ class Vector : public Subscriptor
                                      * are printed on a separate line
                                      * each.
                                      */
-    void print (std::ostream       &out,
-               const unsigned int  precision  = 3,
-               const bool          scientific = true,
-               const bool          across     = true) const;
+    void print (std::ostream& out,
+               const unsigned int precision  = 3,
+               const bool scientific = true,
+               const bool across     = true) const;
+
+                                    /**
+                                     * Print to a
+                                     * LogStream. <tt>width</tt> is
+                                     * used as argument to the
+                                     * std::setw manipulator, if
+                                     * printing across.  If @p
+                                     * across is @p true then the
+                                     * vector is printed in a line,
+                                     * while if @p false then the
+                                     * elements are printed on a
+                                     * separate line each.
+                                     */
+    void print (LogStream& out,
+               const unsigned int width = 6,
+               const bool across = true) const;
 
                                     /**
                                      * Write the vector en bloc to a
@@ -1422,7 +1440,6 @@ Vector<Number>::swap (Vector<Number> &v)
 }
 
 
-
 #endif
 
 
@@ -1446,6 +1463,31 @@ void swap (Vector<Number> &u, Vector<Number> &v)
   u.swap (v);
 }
 
+
+/**
+ * Output operator writing a vector to a stream.
+ */
+template <typename number>
+inline
+std::ostream&
+operator << (std::ostream& os, const Vector<number>& v)
+{
+  v.print(os);  
+  return os;
+}
+
+/**
+ * Output operator writing a vector to a LogStream.
+ */
+template <typename number>
+inline
+LogStream&
+operator << (LogStream& os, const Vector<number>& v)
+{
+  v.print(os);
+  return os;  
+}
+
 /*@}*/
 
 DEAL_II_NAMESPACE_CLOSE
index 858b78cdbd79082a74fe9da0ea1807e02afb9e85..7d0985e74d8d94c6a7a32bfab2c19cf27ffd8e8a 100644 (file)
@@ -32,6 +32,7 @@
 #include <cstring>
 #include <algorithm>
 #include <iostream>
+#include <iomanip>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -1143,6 +1144,22 @@ void Vector<Number>::print (std::ostream      &out,
 
 
 
+template <typename Number>
+void
+Vector<Number>::print (LogStream& out, const unsigned int width, const bool across) const
+{
+  Assert (vec_size!=0, ExcEmptyObject());
+  
+  if (across)
+    for (unsigned int i=0; i<size(); ++i)
+      out << std::setw(width) << val[i] << ' ';
+  else
+    for (unsigned int i=0; i<size(); ++i)
+      out << val[i] << std::endl;
+  out << std::endl;
+}
+
+
 template <typename Number>
 void Vector<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.