From 47711e5289d73da6f94243a2b69e454b543f9d4c Mon Sep 17 00:00:00 2001 From: tcclevenger Date: Wed, 2 Sep 2015 16:38:03 -0400 Subject: [PATCH] Add SparsityPattern::print_svg --- doc/news/changes.h | 6 +++ include/deal.II/lac/sparsity_pattern.h | 9 +++++ source/lac/sparsity_pattern.cc | 32 ++++++++++++++++ tests/lac/sparsity_pattern_write_svg_01.cc | 38 +++++++++++++++++++ .../lac/sparsity_pattern_write_svg_01.output | 17 +++++++++ 5 files changed, 102 insertions(+) create mode 100644 tests/lac/sparsity_pattern_write_svg_01.cc create mode 100644 tests/lac/sparsity_pattern_write_svg_01.output diff --git a/doc/news/changes.h b/doc/news/changes.h index 3267d07f24..c25afdc64d 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -260,6 +260,12 @@ inconvenience this causes.
(Timo Heister, 2015/09/05) +
  • 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. +
    + (Conrad Clevenger, 2015/09/03) +
  • +
  • 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. diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index daa6bbaf92..9b7a4647de 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -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 diff --git a/source/lac/sparsity_pattern.cc b/source/lac/sparsity_pattern.cc index ebac9b601e..e2b345939b 100644 --- a/source/lac/sparsity_pattern.cc +++ b/source/lac/sparsity_pattern.cc @@ -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 << "\n" + "\n\n" + " \n" + " \n\n"; + + SparsityPattern::iterator + it = this->begin(), + end = this->end(); + for (; it!=end; ++it) + { + out << " column()+1 + << "\" y=\"" << it->row()+1 + << "\" width=\".9\" height=\".9\"/>\n"; + } + out << "" << 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 index 0000000000..6f99ca50d0 --- /dev/null +++ b/tests/lac/sparsity_pattern_write_svg_01.cc @@ -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 + +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 + + + + + + + + + -- 2.39.5