bool
exists(const size_type i, const size_type j) const;
+ /**
+ * Return a view of this sparsity pattern.
+ * That is, for all rows in @p rows extract non-empty columns.
+ * The resulting sparsity pattern will have number of rows equal
+ * `rows.n_elements()`.
+ */
+ DynamicSparsityPattern
+ get_view(const IndexSet &rows) const;
+
/**
* Make the sparsity pattern symmetric by adding the sparsity pattern of the
* transpose object.
+DynamicSparsityPattern
+DynamicSparsityPattern::get_view(const IndexSet &rows) const
+{
+ DynamicSparsityPattern view;
+ view.reinit(rows.n_elements(), this->n_cols());
+ AssertDimension(rows.size(), this->n_rows());
+
+ const auto end = rows.end();
+ DynamicSparsityPattern::size_type view_row = 0;
+ for (auto it = rows.begin(); it != end; ++it, ++view_row)
+ {
+ const size_type rowindex =
+ rowset.size() == 0 ? *it : rowset.index_within_set(*it);
+
+ view.lines[view_row].entries = lines[rowindex].entries;
+ view.have_entries |= (lines[rowindex].entries.size() > 0);
+ }
+ return view;
+}
+
+
+
template <typename SparsityPatternTypeLeft, typename SparsityPatternTypeRight>
void
DynamicSparsityPattern::compute_Tmmult_pattern(
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check DynamicSparsityPattern::get_view()
+
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+
+#include "../tests.h"
+
+
+void
+test()
+{
+ const unsigned int N = 10;
+ DynamicSparsityPattern dsp(N, N);
+
+ for (unsigned int i = 0; i < N; ++i)
+ if (i != 2 && i != 4)
+ for (unsigned int j = (i == 0 ? 0 : i - 1); j < (i == N - 1 ? N : i + 1);
+ ++j)
+ dsp.add(i, j);
+
+ IndexSet rows(N);
+ rows.add_range(1, 5);
+
+ DynamicSparsityPattern view = dsp.get_view(rows);
+
+ deallog << "Initial sparsity:" << std::endl;
+ dsp.print(deallog.get_file_stream());
+ deallog << "Rows:" << std::endl;
+ rows.print(deallog.get_file_stream());
+ deallog << "View:" << std::endl;
+ view.print(deallog.get_file_stream());
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ test();
+ return 0;
+}