]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement BlockSparsityPattern::print_svg().
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 25 Sep 2020 22:00:45 +0000 (16:00 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 30 Sep 2020 13:01:20 +0000 (07:01 -0600)
include/deal.II/lac/block_sparsity_pattern.h
source/lac/block_sparsity_pattern.cc

index 2654968448ea335a485edfc6cfa15207c460ea89..c0460d904f84793cd90f65e900922d19f566006b 100644 (file)
@@ -307,6 +307,14 @@ public:
   void
   print_gnuplot(std::ostream &out) const;
 
+  /**
+   * Print the sparsity of the matrix in <tt>svg</tt> format. This is the same
+   * functionality implemented for usual sparsity patterns, see
+   * @ref SparsityPattern.
+   */
+  void
+  print_svg(std::ostream &out) const;
+
   /**
    * @addtogroup Exceptions
    * @{
index 1cc0392e53b948fc55270f74ed06d1b180ecd10a..b4237527b4f2662472fbc36377bf039a4ca8a33e 100644 (file)
@@ -303,6 +303,7 @@ BlockSparsityPatternBase<DynamicSparsityPattern>::print(std::ostream &out) const
 #endif
 
 
+
 template <class SparsityPatternBase>
 void
 BlockSparsityPatternBase<SparsityPatternBase>::print_gnuplot(
@@ -330,6 +331,47 @@ BlockSparsityPatternBase<SparsityPatternBase>::print_gnuplot(
 
 
 
+template <class SparsityPatternBase>
+void
+BlockSparsityPatternBase<SparsityPatternBase>::print_svg(
+  std::ostream &out) const
+{
+  const unsigned int m = this->n_rows();
+  const 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 + 0.1 << "\" height=\"" << m + 0.1
+    << "\" fill=\"rgb(255, 255, 255)\"/>\n\n";
+
+  for (unsigned int block_i = 0; block_i < n_block_rows(); ++block_i)
+    for (unsigned int block_j = 0; block_j < n_block_rows(); ++block_j)
+      for (const auto &entry : block(block_i, block_j))
+        {
+          out << "  <rect class=\"pixel\" x=\""
+              << column_indices.local_to_global(block_j, entry.column()) + 1
+              << "\" y=\""
+              << row_indices.local_to_global(block_i, entry.row()) + 1
+              << "\" width=\".9\" height=\".9\"/>\n";
+        }
+
+  out << "</svg>" << std::endl;
+}
+
+
+
 BlockSparsityPattern::BlockSparsityPattern(const size_type n_rows,
                                            const size_type n_columns)
   : BlockSparsityPatternBase<SparsityPattern>(n_rows, n_columns)
@@ -443,6 +485,7 @@ BlockDynamicSparsityPattern::BlockDynamicSparsityPattern(
 }
 
 
+
 BlockDynamicSparsityPattern::BlockDynamicSparsityPattern(
   const std::vector<IndexSet> &partitioning)
   : BlockSparsityPatternBase<DynamicSparsityPattern>(partitioning.size(),
@@ -457,6 +500,7 @@ BlockDynamicSparsityPattern::BlockDynamicSparsityPattern(
 }
 
 
+
 BlockDynamicSparsityPattern::BlockDynamicSparsityPattern(
   const BlockIndices &row_indices,
   const BlockIndices &col_indices)
@@ -465,6 +509,7 @@ BlockDynamicSparsityPattern::BlockDynamicSparsityPattern(
 }
 
 
+
 void
 BlockDynamicSparsityPattern::reinit(
   const std::vector<size_type> &row_block_sizes,
@@ -478,6 +523,8 @@ BlockDynamicSparsityPattern::reinit(
   this->collect_sizes();
 }
 
+
+
 void
 BlockDynamicSparsityPattern::reinit(const std::vector<IndexSet> &partitioning)
 {
@@ -491,6 +538,8 @@ BlockDynamicSparsityPattern::reinit(const std::vector<IndexSet> &partitioning)
   this->collect_sizes();
 }
 
+
+
 void
 BlockDynamicSparsityPattern::reinit(const BlockIndices &row_indices,
                                     const BlockIndices &col_indices)

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.