From 73fc9d43544e1ae3c469b04f066648507db92e37 Mon Sep 17 00:00:00 2001
From: bangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Date: Wed, 20 Jun 2007 13:25:26 +0000
Subject: [PATCH] Add more tests for CompressedSetSparsityPattern

git-svn-id: https://svn.dealii.org/trunk@14787 0785d39b-7218-0410-832d-ea1e28bc413d
---
 tests/deal.II/sparsity_pattern_01_x.cc        | 243 ++++++++++++++++++
 .../deal.II/sparsity_pattern_01_x/cmp/generic |  10 +
 tests/deal.II/sparsity_pattern_05_x.cc        | 200 ++++++++++++++
 .../deal.II/sparsity_pattern_05_x/cmp/generic |   7 +
 tests/deal.II/sparsity_pattern_x.cc           | 243 ++++++++++++++++++
 tests/deal.II/sparsity_pattern_x/cmp/generic  |  10 +
 6 files changed, 713 insertions(+)
 create mode 100644 tests/deal.II/sparsity_pattern_01_x.cc
 create mode 100644 tests/deal.II/sparsity_pattern_01_x/cmp/generic
 create mode 100644 tests/deal.II/sparsity_pattern_05_x.cc
 create mode 100644 tests/deal.II/sparsity_pattern_05_x/cmp/generic
 create mode 100644 tests/deal.II/sparsity_pattern_x.cc
 create mode 100644 tests/deal.II/sparsity_pattern_x/cmp/generic

diff --git a/tests/deal.II/sparsity_pattern_01_x.cc b/tests/deal.II/sparsity_pattern_01_x.cc
new file mode 100644
index 0000000000..6c3348a204
--- /dev/null
+++ b/tests/deal.II/sparsity_pattern_01_x.cc
@@ -0,0 +1,243 @@
+//----------------------------  sparsity_pattern_01_x.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2000, 2001, 2003, 2004, 2007 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  sparsity_pattern_01_x.cc  ---------------------------
+
+
+// A variant of deal.II/sparsity_pattern. use the version of
+// DoFTools::make_sparsity_pattern that takes two DoFHandler arguments. the
+// output should be the same, of course, if we use the same DoFHandler for
+// both arguments.
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/sparsity_pattern.h>
+#include <lac/block_sparsity_pattern.h>
+#include <lac/compressed_set_sparsity_pattern.h>
+#include <grid/tria.h>
+#include <grid/tria_iterator.h>
+#include <grid/tria_accessor.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_tools.h>
+#include <dofs/dof_constraints.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+
+#include <fstream>
+
+
+
+bool operator == (const SparsityPattern &sp1,
+		  const SparsityPattern &sp2)
+{
+  if (sp1.n_nonzero_elements() != sp2.n_nonzero_elements())
+    return false;
+  
+  for (unsigned int i=0; i<sp1.n_nonzero_elements(); ++i)
+    if (sp1.get_column_numbers()[i] !=
+	sp2.get_column_numbers()[i])
+      return false;
+
+  for (unsigned int i=0; i<sp1.n_rows(); ++i)
+    if (sp1.get_rowstart_indices()[i] !=
+	sp2.get_rowstart_indices()[i])
+      return false;
+  
+  return true;
+}
+
+
+
+bool operator == (const BlockSparsityPattern &sp1,
+		  const BlockSparsityPattern &sp2)
+{
+  if (sp1.n_block_rows() != sp2.n_block_rows())
+    return false;
+  
+  if (sp1.n_block_cols() != sp2.n_block_cols())
+    return false;
+  
+  for (unsigned int i=0; i<sp1.n_block_rows(); ++i)
+    for (unsigned int j=0; j<sp1.n_block_cols(); ++j)
+      if (!(sp1.block(i,j) == sp2.block(i,j)))
+	return false;
+  
+  return true;
+}
+
+
+
+template <int dim>
+void
+check_boundary (const DoFHandler<dim> &dof)
+{
+  std::vector<unsigned int> dof_to_boundary_mapping;
+  DoFTools::map_dof_to_boundary_indices (dof,
+					 dof_to_boundary_mapping);
+
+				   // first way: direct generation
+  SparsityPattern sparsity_1(dof.n_boundary_dofs(),
+			     dof.max_couplings_between_boundary_dofs());
+  DoFTools::make_boundary_sparsity_pattern (dof,
+					    dof_to_boundary_mapping,
+					    sparsity_1);
+  sparsity_1.compress ();
+
+				   // second way: via a CompressedSetSparsityPattern
+  SparsityPattern sparsity_2;
+  CompressedSetSparsityPattern csp(dof.n_boundary_dofs());
+  DoFTools::make_boundary_sparsity_pattern (dof,
+					    dof_to_boundary_mapping,
+					    csp);
+  sparsity_2.copy_from (csp);
+
+				   // the exact content of sparsity
+				   // patterns is checked in other
+				   // tests, so only make sure that
+				   // sparsity_[12] are equal
+  deallog << "Check boundary"
+	  << " -- "
+	  << (sparsity_1 == sparsity_2 ? "ok" : "failed")
+	  << std::endl;
+}
+
+
+
+
+template <int dim>
+void
+check ()
+{
+  Triangulation<dim> tr;  
+  if (dim==2)
+    GridGenerator::hyper_ball(tr, Point<dim>(), 1);
+  else
+    GridGenerator::hyper_cube(tr, -1,1);
+  tr.refine_global (1);
+  tr.begin_active()->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+  tr.begin_active(2)->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+  if (dim==1)
+    tr.refine_global(2);
+
+				   // create a system element composed
+				   // of one Q1 and one Q2 element
+  FESystem<dim> element(FE_Q<dim>(1), 1,
+			FE_Q<dim>(2), 1);
+  DoFHandler<dim> dof(tr);
+  dof.distribute_dofs(element);
+
+  ConstraintMatrix constraints;
+  DoFTools::make_hanging_node_constraints (dof, constraints);
+  constraints.close ();
+
+				   // create sparsity pattern. note
+				   // that different components should
+				   // not couple, so use pattern
+  std::vector<std::vector<bool> > mask (2, std::vector<bool>(2, false));
+  mask[0][0] = mask[1][1] = true;
+
+  
+//--------------- Regular sparsity pattern checks -----------------
+  
+				   // first way: directly
+  SparsityPattern sparsity_1 (dof.n_dofs(), dof.n_dofs());
+  DoFTools::make_sparsity_pattern (dof, mask, sparsity_1);
+  constraints.condense (sparsity_1);
+  sparsity_1.compress ();
+
+				   // second way: via
+				   // CompressedSetSparsityPattern
+  SparsityPattern sparsity_2;
+  CompressedSetSparsityPattern csp_2 (dof.n_dofs());
+  DoFTools::make_sparsity_pattern (dof, mask, csp_2);
+  constraints.condense (csp_2);
+  sparsity_2.copy_from (csp_2);
+
+
+				   // the exact content of sparsity
+				   // patterns is checked in other
+				   // tests, so only make sure that
+				   // sparsity_[12] are equal
+  deallog << "Check 1:"
+	  << " -- "
+	  << (sparsity_1 == sparsity_2 ? "ok" : "failed")
+	  << std::endl;
+
+
+  
+//--------------- Block sparsity pattern checks -----------------
+
+  const unsigned int n  = dof.n_dofs();
+  const unsigned int n1 = n/3;
+  const unsigned int n2 = n - n1;
+
+  BlockSparsityPattern sparsity_3(2,2);
+  sparsity_3.block(0,0).reinit (n1,n1,n);
+  sparsity_3.block(1,0).reinit (n2,n1,n);
+  sparsity_3.block(0,1).reinit (n1,n2,n);
+  sparsity_3.block(1,1).reinit (n2,n2,n);
+  sparsity_3.collect_sizes ();
+
+  DoFTools::make_sparsity_pattern (dof, dof, sparsity_3);
+  constraints.condense (sparsity_3);
+  sparsity_3.compress ();
+
+  BlockSparsityPattern sparsity_4;
+  BlockCompressedSetSparsityPattern csp_4(2,2);
+  csp_4.block(0,0).reinit (n1,n1);
+  csp_4.block(1,0).reinit (n2,n1);
+  csp_4.block(0,1).reinit (n1,n2);
+  csp_4.block(1,1).reinit (n2,n2);
+  csp_4.collect_sizes ();
+
+  DoFTools::make_sparsity_pattern (dof, dof, csp_4);
+  constraints.condense (csp_4);
+  csp_4.compress ();
+
+  sparsity_4.copy_from (csp_4);
+
+  deallog << "Check 2:"
+	  << " -- "
+	  << (sparsity_3 == sparsity_4 ? "ok" : "failed")
+	  << std::endl;
+
+  
+//--------------- Sparsity pattern checks for
+//                boundary sparsity generators -----------------
+
+				   // check boundary matrices
+  check_boundary (dof);
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile ("sparsity_pattern_01_x/output");
+  logfile.precision (2);
+  logfile.setf(std::ios::fixed);  
+  deallog.attach(logfile);
+  deallog.depth_console (0);
+
+  deallog.push ("1d");
+  check<1> ();
+  deallog.pop ();
+  deallog.push ("2d");
+  check<2> ();
+  deallog.pop ();
+  deallog.push ("3d");
+  check<3> ();
+  deallog.pop ();
+}
diff --git a/tests/deal.II/sparsity_pattern_01_x/cmp/generic b/tests/deal.II/sparsity_pattern_01_x/cmp/generic
new file mode 100644
index 0000000000..76b2767418
--- /dev/null
+++ b/tests/deal.II/sparsity_pattern_01_x/cmp/generic
@@ -0,0 +1,10 @@
+
+DEAL:1d::Check 1: -- ok
+DEAL:1d::Check 2: -- ok
+DEAL:1d::Check boundary -- ok
+DEAL:2d::Check 1: -- ok
+DEAL:2d::Check 2: -- ok
+DEAL:2d::Check boundary -- ok
+DEAL:3d::Check 1: -- ok
+DEAL:3d::Check 2: -- ok
+DEAL:3d::Check boundary -- ok
diff --git a/tests/deal.II/sparsity_pattern_05_x.cc b/tests/deal.II/sparsity_pattern_05_x.cc
new file mode 100644
index 0000000000..eaaf823863
--- /dev/null
+++ b/tests/deal.II/sparsity_pattern_05_x.cc
@@ -0,0 +1,200 @@
+//----------------------------  sparsity_pattern_05_x.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2000, 2001, 2003, 2004, 2007 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  sparsity_pattern_05_x.cc  ---------------------------
+
+
+// check that generating a sparsity pattern without constraints and later
+// calling constraints.condense() on it results in the same pattern as when
+// creating the condensed pattern right away
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/sparsity_pattern.h>
+#include <lac/block_sparsity_pattern.h>
+#include <lac/compressed_set_sparsity_pattern.h>
+#include <grid/tria.h>
+#include <grid/tria_iterator.h>
+#include <grid/tria_accessor.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_tools.h>
+#include <dofs/dof_constraints.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+
+#include <fstream>
+
+
+
+bool operator == (const SparsityPattern &sp1,
+		  const SparsityPattern &sp2)
+{
+  if (sp1.n_nonzero_elements() != sp2.n_nonzero_elements())
+    return false;
+  
+  for (unsigned int i=0; i<sp1.n_nonzero_elements(); ++i)
+    if (sp1.get_column_numbers()[i] !=
+	sp2.get_column_numbers()[i])
+      {
+	Assert (false, ExcInternalError());
+	return false;
+      }
+
+  for (unsigned int i=0; i<sp1.n_rows(); ++i)
+    if (sp1.get_rowstart_indices()[i] !=
+	sp2.get_rowstart_indices()[i])
+      {
+	Assert (false, ExcInternalError());
+	return false;
+      }
+  
+  return true;
+}
+
+
+
+bool operator == (const BlockSparsityPattern &sp1,
+		  const BlockSparsityPattern &sp2)
+{
+  if (sp1.n_block_rows() != sp2.n_block_rows())
+    return false;
+  
+  if (sp1.n_block_cols() != sp2.n_block_cols())
+    return false;
+  
+  for (unsigned int i=0; i<sp1.n_block_rows(); ++i)
+    for (unsigned int j=0; j<sp1.n_block_cols(); ++j)
+      if (!(sp1.block(i,j) == sp2.block(i,j)))
+	{
+	  Assert (false, ExcInternalError());
+	  return false;
+	}
+  
+  return true;
+}
+
+
+
+
+template <int dim>
+void
+check ()
+{
+  Triangulation<dim> tr;  
+  if (dim==2)
+    GridGenerator::hyper_ball(tr, Point<dim>(), 1);
+  else
+    GridGenerator::hyper_cube(tr, -1,1);
+  tr.refine_global (1);
+  tr.begin_active()->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+  tr.begin_active(2)->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+  if (dim==1)
+    tr.refine_global(2);
+
+				   // create a system element composed
+				   // of one Q1 and one Q2 element
+  FESystem<dim> element(FE_Q<dim>(1), 1,
+			FE_Q<dim>(2), 1);
+  DoFHandler<dim> dof(tr);
+  dof.distribute_dofs(element);
+
+  ConstraintMatrix constraints;
+  DoFTools::make_hanging_node_constraints (dof, constraints);
+  constraints.close ();
+
+
+//--------------- Regular sparsity pattern checks -----------------
+  
+				   // first way: directly
+  SparsityPattern sparsity_1 (dof.n_dofs(), dof.n_dofs());
+  DoFTools::make_sparsity_pattern (dof, sparsity_1);
+  constraints.condense (sparsity_1);
+  sparsity_1.compress ();
+
+				   // second way: via direct elimination of
+				   // constraints
+  SparsityPattern sparsity_2;
+  CompressedSetSparsityPattern csp_2 (dof.n_dofs());
+  DoFTools::make_sparsity_pattern (dof, csp_2, constraints);
+  sparsity_2.copy_from (csp_2);
+
+
+				   // the exact content of sparsity
+				   // patterns is checked in other
+				   // tests, so only make sure that
+				   // sparsity_[12] are equal
+  deallog << "Check 1:"
+	  << " -- "
+	  << (sparsity_1 == sparsity_2 ? "ok" : "failed")
+	  << std::endl;
+
+
+  
+//--------------- Block sparsity pattern checks -----------------
+
+  const unsigned int n  = dof.n_dofs();
+  const unsigned int n1 = n/3;
+  const unsigned int n2 = n - n1;
+
+  BlockSparsityPattern sparsity_3(2,2);
+  sparsity_3.block(0,0).reinit (n1,n1,n);
+  sparsity_3.block(1,0).reinit (n2,n1,n);
+  sparsity_3.block(0,1).reinit (n1,n2,n);
+  sparsity_3.block(1,1).reinit (n2,n2,n);
+  sparsity_3.collect_sizes ();
+
+  DoFTools::make_sparsity_pattern (dof, sparsity_3);
+  constraints.condense (sparsity_3);
+  sparsity_3.compress ();
+
+  BlockSparsityPattern sparsity_4;
+  BlockCompressedSetSparsityPattern csp_4(2,2);
+  csp_4.block(0,0).reinit (n1,n1);
+  csp_4.block(1,0).reinit (n2,n1);
+  csp_4.block(0,1).reinit (n1,n2);
+  csp_4.block(1,1).reinit (n2,n2);
+  csp_4.collect_sizes ();
+
+  DoFTools::make_sparsity_pattern (dof, csp_4, constraints);
+  csp_4.compress ();
+
+  sparsity_4.copy_from (csp_4);
+
+  deallog << "Check 2:"
+	  << " -- "
+	  << (sparsity_3 == sparsity_4 ? "ok" : "failed")
+	  << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile ("sparsity_pattern_05_x/output");
+  logfile.precision (2);
+  logfile.setf(std::ios::fixed);  
+  deallog.attach(logfile);
+  deallog.depth_console (0);
+
+  deallog.push ("1d");
+  check<1> ();
+  deallog.pop ();
+  deallog.push ("2d");
+  check<2> ();
+  deallog.pop ();
+  deallog.push ("3d");
+  check<3> ();
+  deallog.pop ();
+}
diff --git a/tests/deal.II/sparsity_pattern_05_x/cmp/generic b/tests/deal.II/sparsity_pattern_05_x/cmp/generic
new file mode 100644
index 0000000000..73a9c0b38e
--- /dev/null
+++ b/tests/deal.II/sparsity_pattern_05_x/cmp/generic
@@ -0,0 +1,7 @@
+
+DEAL:1d::Check 1: -- ok
+DEAL:1d::Check 2: -- ok
+DEAL:2d::Check 1: -- ok
+DEAL:2d::Check 2: -- ok
+DEAL:3d::Check 1: -- ok
+DEAL:3d::Check 2: -- ok
diff --git a/tests/deal.II/sparsity_pattern_x.cc b/tests/deal.II/sparsity_pattern_x.cc
new file mode 100644
index 0000000000..260e7de355
--- /dev/null
+++ b/tests/deal.II/sparsity_pattern_x.cc
@@ -0,0 +1,243 @@
+//----------------------------  sparsity_pattern_x.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2000, 2001, 2003, 2004, 2007 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  sparsity_pattern_x.cc  ---------------------------
+
+
+/* Author: Wolfgang Bangerth, University of Heidelberg, 2001 */
+
+// check that the direct generation of the sparsity pattern and that
+// via the CompressedSetSparsityPattern result in the same
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/sparsity_pattern.h>
+#include <lac/block_sparsity_pattern.h>
+#include <lac/compressed_set_sparsity_pattern.h>
+#include <grid/tria.h>
+#include <grid/tria_iterator.h>
+#include <grid/tria_accessor.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_tools.h>
+#include <dofs/dof_constraints.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+
+#include <fstream>
+
+
+
+bool operator == (const SparsityPattern &sp1,
+		  const SparsityPattern &sp2)
+{
+  if (sp1.n_nonzero_elements() != sp2.n_nonzero_elements())
+    return false;
+  
+  for (unsigned int i=0; i<sp1.n_nonzero_elements(); ++i)
+    if (sp1.get_column_numbers()[i] !=
+	sp2.get_column_numbers()[i])
+      return false;
+
+  for (unsigned int i=0; i<sp1.n_rows(); ++i)
+    if (sp1.get_rowstart_indices()[i] !=
+	sp2.get_rowstart_indices()[i])
+      return false;
+  
+  return true;
+}
+
+
+
+bool operator == (const BlockSparsityPattern &sp1,
+		  const BlockSparsityPattern &sp2)
+{
+  if (sp1.n_block_rows() != sp2.n_block_rows())
+    return false;
+  
+  if (sp1.n_block_cols() != sp2.n_block_cols())
+    return false;
+  
+  for (unsigned int i=0; i<sp1.n_block_rows(); ++i)
+    for (unsigned int j=0; j<sp1.n_block_cols(); ++j)
+      if (!(sp1.block(i,j) == sp2.block(i,j)))
+	return false;
+  
+  return true;
+}
+
+
+
+template <int dim>
+void
+check_boundary (const DoFHandler<dim> &dof)
+{
+  std::vector<unsigned int> dof_to_boundary_mapping;
+  DoFTools::map_dof_to_boundary_indices (dof,
+					 dof_to_boundary_mapping);
+
+				   // first way: direct generation
+  SparsityPattern sparsity_1(dof.n_boundary_dofs(),
+			     dof.max_couplings_between_boundary_dofs());
+  DoFTools::make_boundary_sparsity_pattern (dof,
+					    dof_to_boundary_mapping,
+					    sparsity_1);
+  sparsity_1.compress ();
+
+				   // second way: via a CompressedSetSparsityPattern
+  SparsityPattern sparsity_2;
+  CompressedSetSparsityPattern csp(dof.n_boundary_dofs());
+  DoFTools::make_boundary_sparsity_pattern (dof,
+					    dof_to_boundary_mapping,
+					    csp);
+  sparsity_2.copy_from (csp);
+
+				   // the exact content of sparsity
+				   // patterns is checked in other
+				   // tests, so only make sure that
+				   // sparsity_[12] are equal
+  deallog << "Check boundary"
+	  << " -- "
+	  << (sparsity_1 == sparsity_2 ? "ok" : "failed")
+	  << std::endl;
+}
+
+
+
+
+template <int dim>
+void
+check ()
+{
+  Triangulation<dim> tr;  
+  if (dim==2)
+    GridGenerator::hyper_ball(tr, Point<dim>(), 1);
+  else
+    GridGenerator::hyper_cube(tr, -1,1);
+  tr.refine_global (1);
+  tr.begin_active()->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+  tr.begin_active(2)->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+  if (dim==1)
+    tr.refine_global(2);
+
+				   // create a system element composed
+				   // of one Q1 and one Q2 element
+  FESystem<dim> element(FE_Q<dim>(1), 1,
+			FE_Q<dim>(2), 1);
+  DoFHandler<dim> dof(tr);
+  dof.distribute_dofs(element);
+
+  ConstraintMatrix constraints;
+  DoFTools::make_hanging_node_constraints (dof, constraints);
+  constraints.close ();
+
+				   // create sparsity pattern. note
+				   // that different components should
+				   // not couple, so use pattern
+  std::vector<std::vector<bool> > mask (2, std::vector<bool>(2, false));
+  mask[0][0] = mask[1][1] = true;
+
+  
+//--------------- Regular sparsity pattern checks -----------------
+  
+				   // first way: directly
+  SparsityPattern sparsity_1 (dof.n_dofs(), dof.n_dofs());
+  DoFTools::make_sparsity_pattern (dof, mask, sparsity_1);
+  constraints.condense (sparsity_1);
+  sparsity_1.compress ();
+
+				   // second way: via
+				   // CompressedSetSparsityPattern
+  SparsityPattern sparsity_2;
+  CompressedSetSparsityPattern csp_2 (dof.n_dofs());
+  DoFTools::make_sparsity_pattern (dof, mask, csp_2);
+  constraints.condense (csp_2);
+  sparsity_2.copy_from (csp_2);
+
+
+				   // the exact content of sparsity
+				   // patterns is checked in other
+				   // tests, so only make sure that
+				   // sparsity_[12] are equal
+  deallog << "Check 1:"
+	  << " -- "
+	  << (sparsity_1 == sparsity_2 ? "ok" : "failed")
+	  << std::endl;
+
+
+  
+//--------------- Block sparsity pattern checks -----------------
+
+  const unsigned int n  = dof.n_dofs();
+  const unsigned int n1 = n/3;
+  const unsigned int n2 = n - n1;
+
+  BlockSparsityPattern sparsity_3(2,2);
+  sparsity_3.block(0,0).reinit (n1,n1,n);
+  sparsity_3.block(1,0).reinit (n2,n1,n);
+  sparsity_3.block(0,1).reinit (n1,n2,n);
+  sparsity_3.block(1,1).reinit (n2,n2,n);
+  sparsity_3.collect_sizes ();
+
+  DoFTools::make_sparsity_pattern (dof, sparsity_3);
+  constraints.condense (sparsity_3);
+  sparsity_3.compress ();
+
+  BlockSparsityPattern sparsity_4;
+  BlockCompressedSetSparsityPattern csp_4(2,2);
+  csp_4.block(0,0).reinit (n1,n1);
+  csp_4.block(1,0).reinit (n2,n1);
+  csp_4.block(0,1).reinit (n1,n2);
+  csp_4.block(1,1).reinit (n2,n2);
+  csp_4.collect_sizes ();
+
+  DoFTools::make_sparsity_pattern (dof, csp_4);
+  constraints.condense (csp_4);
+  csp_4.compress ();
+
+  sparsity_4.copy_from (csp_4);
+
+  deallog << "Check 2:"
+	  << " -- "
+	  << (sparsity_3 == sparsity_4 ? "ok" : "failed")
+	  << std::endl;
+
+  
+//--------------- Sparsity pattern checks for
+//                boundary sparsity generators -----------------
+
+				   // check boundary matrices
+  check_boundary (dof);
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile ("sparsity_pattern_x/output");
+  logfile.precision (2);
+  logfile.setf(std::ios::fixed);  
+  deallog.attach(logfile);
+  deallog.depth_console (0);
+
+  deallog.push ("1d");
+  check<1> ();
+  deallog.pop ();
+  deallog.push ("2d");
+  check<2> ();
+  deallog.pop ();
+  deallog.push ("3d");
+  check<3> ();
+  deallog.pop ();
+}
diff --git a/tests/deal.II/sparsity_pattern_x/cmp/generic b/tests/deal.II/sparsity_pattern_x/cmp/generic
new file mode 100644
index 0000000000..76b2767418
--- /dev/null
+++ b/tests/deal.II/sparsity_pattern_x/cmp/generic
@@ -0,0 +1,10 @@
+
+DEAL:1d::Check 1: -- ok
+DEAL:1d::Check 2: -- ok
+DEAL:1d::Check boundary -- ok
+DEAL:2d::Check 1: -- ok
+DEAL:2d::Check 2: -- ok
+DEAL:2d::Check boundary -- ok
+DEAL:3d::Check 1: -- ok
+DEAL:3d::Check 2: -- ok
+DEAL:3d::Check boundary -- ok
-- 
2.39.5