]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add SparsityPattern::print_svg 1515/head
authortcclevenger <tcleven@clemson.edu>
Wed, 2 Sep 2015 20:38:03 +0000 (16:38 -0400)
committertcclevenger <tcleven@clemson.edu>
Mon, 7 Sep 2015 15:32:59 +0000 (11:32 -0400)
doc/news/changes.h
include/deal.II/lac/sparsity_pattern.h
source/lac/sparsity_pattern.cc
tests/lac/sparsity_pattern_write_svg_01.cc [new file with mode: 0644]
tests/lac/sparsity_pattern_write_svg_01.output [new file with mode: 0644]

index 3267d07f24a28a6c0584280630de560be1b8252a..c25afdc64dfa7c6762b022db4f7fb8d41a16689e 100644 (file)
@@ -260,6 +260,12 @@ inconvenience this causes.
   <br>
   (Timo Heister, 2015/09/05)
 
+  <li> New: There is now a function SparsityPattern::print_svg() which prints the sparsity of the matrix
+  in a .svg file which can be opened in a web browser.
+  <br>
+  (Conrad Clevenger, 2015/09/03)
+  </li>
+  
   <li> Openmp SIMD support is now enabled for Clang version 3.6, or newer
   (or the equivalent XCode version). Further, openmp support is not any
   more falsely activated for very old clang versions.
index daa6bbaf92937b27c874ccbf7d6aae1029e40e61..9b7a4647debdfd372356f2f518929963614b5702 100644 (file)
@@ -929,6 +929,15 @@ public:
    */
   void print_gnuplot (std::ostream &out) const;
 
+  /**
+   * Prints the sparsity of the matrix in a .svg file which can be opened in a web browser.
+   * The .svg file contains squares which correspond to the entries in the matrix. An entry
+   * in the matrix which contains a non-zero value corresponds with a red square while a
+   * zero-valued entry in the matrix correspond with a white square.
+   */
+  void print_svg (std::ostream &out) const;
+
+
   /**
    * Write the data of this object to a stream for the purpose of
    * serialization
index ebac9b601eca4278f825c10feeadc989cce43401..e2b345939bbee109510b7544098e9566a6a0d4ce 100644 (file)
@@ -856,6 +856,38 @@ SparsityPattern::print_gnuplot (std::ostream &out) const
   AssertThrow (out, ExcIO());
 }
 
+void
+SparsityPattern::print_svg (std::ostream &out) const
+{
+  unsigned int m = this->n_rows();
+  unsigned int n = this->n_cols();
+  out << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 " << n+2
+      << " " << m+2 << " \">\n"
+      "<style type=\"text/css\" >\n"
+      "     <![CDATA[\n"
+      "      rect.pixel {\n"
+      "          fill:   #ff0000;\n"
+      "      }\n"
+      "    ]]>\n"
+      "  </style>\n\n"
+      "   <rect width=\"" << n+2 << "\" height=\"" << m+2 << "\" fill=\"rgb(128, 128, 128)\"/>\n"
+      "   <rect x=\"1\" y=\"1\" width=\"" << n << "\" height=\"" << m
+      << "\" fill=\"rgb(255, 255, 255)\"/>\n\n";
+
+  SparsityPattern::iterator
+  it = this->begin(),
+  end = this->end();
+  for (; it!=end; ++it)
+    {
+      out << "  <rect class=\"pixel\" x=\"" << it->column()+1
+          << "\" y=\"" << it->row()+1
+          << "\" width=\".9\" height=\".9\"/>\n";
+    }
+  out << "</svg>" << std::endl;
+
+}
+
+
 
 
 SparsityPattern::size_type
diff --git a/tests/lac/sparsity_pattern_write_svg_01.cc b/tests/lac/sparsity_pattern_write_svg_01.cc
new file mode 100644 (file)
index 0000000..6f99ca5
--- /dev/null
@@ -0,0 +1,38 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2008 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check SparsityPattern::write_svg
+
+#include "../tests.h"
+#include <deal.II/lac/sparsity_pattern.h>
+
+int main ()
+{
+  initlog();
+
+  SparsityPattern sparsity (2,3,3);
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<3; ++j)
+      if (i<j)
+        sparsity.add (i,j);
+  sparsity.compress ();
+
+  sparsity.print_svg (deallog.get_file_stream());
+}
+
+
+
diff --git a/tests/lac/sparsity_pattern_write_svg_01.output b/tests/lac/sparsity_pattern_write_svg_01.output
new file mode 100644 (file)
index 0000000..22a1866
--- /dev/null
@@ -0,0 +1,17 @@
+
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 5 4 ">
+<style type="text/css" >
+     <![CDATA[
+      rect.pixel {
+          fill:   #ff0000;
+      }
+    ]]>
+  </style>
+
+   <rect width="5" height="4" fill="rgb(128, 128, 128)"/>
+   <rect x="1" y="1" width="3" height="2" fill="rgb(255, 255, 255)"/>
+
+  <rect class="pixel" x="2" y="1" width=".9" height=".9"/>
+  <rect class="pixel" x="3" y="1" width=".9" height=".9"/>
+  <rect class="pixel" x="3" y="2" width=".9" height=".9"/>
+</svg>

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.