]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test of make_flux_sparsity_pattern in 1D.
authorSimon Sticko <simon@sticko.se>
Fri, 17 Jan 2020 16:10:04 +0000 (17:10 +0100)
committerSimon Sticko <simon@sticko.se>
Mon, 20 Jan 2020 09:31:03 +0000 (10:31 +0100)
For the version of make_flux_sparsity_pattern that takes face and cell
couplings, add a 1D test that fails for both types of DoFHandler. For
dealii::DoFHandler it fails because there is a bug in 1D and for the hp
case it fails because make_flux_sparsity_pattern isn't instantiated in
the 1D case.

tests/dofs/dof_tools_24.cc [new file with mode: 0644]
tests/dofs/dof_tools_24.output [new file with mode: 0644]

diff --git a/tests/dofs/dof_tools_24.cc b/tests/dofs/dof_tools_24.cc
new file mode 100644 (file)
index 0000000..09a3c91
--- /dev/null
@@ -0,0 +1,128 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2001 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+// Test created to reproduce a bug in make_flux_sparsity_pattern that occurs
+// in 1D when neighboring cells are on different levels. Set up a triangulation
+// with 3 cells in 1D, where the left-most element is on level 0 and the middle
+// and right-most element is on level 1:
+//
+// |--l0--|-l1-|-l1-|.
+//
+// Distribute FE_Q<1>(1) elements, call make_flux_sparsity_pattern and check
+// that the created pattern is the expected one.
+
+
+#include <deal.II/base/table.h>
+#include <deal.II/base/types.h>
+
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include <deal.II/hp/dof_handler.h>
+#include <deal.II/hp/fe_collection.h>
+
+#include <deal.II/lac/affine_constraints.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+/*
+ * Call the version of make_flux_sparsity_pattern that takes both cell and face
+ * integral couplings. Print the constructed sparsity pattern to deallog.
+ */
+template <class DoFHandlerType>
+void
+create_and_print_flux_sparsity_pattern(const DoFHandlerType &dof_handler)
+{
+  AffineConstraints<double> constraints;
+  constraints.close();
+
+  const bool keep_constrained_dofs = true;
+
+  // Set all couplings to be connected.
+  const unsigned int           n_components = 1;
+  Table<2, DoFTools::Coupling> couplings(n_components, n_components);
+  couplings[0][0] = DoFTools::Coupling::always;
+  Table<2, DoFTools::Coupling> face_couplings(n_components, n_components);
+  face_couplings[0][0] = DoFTools::Coupling::always;
+
+  const types::subdomain_id subdomain_id = 0;
+
+  DynamicSparsityPattern dynamic_pattern(dof_handler.n_dofs());
+
+  DoFTools::make_flux_sparsity_pattern(dof_handler,
+                                       dynamic_pattern,
+                                       constraints,
+                                       keep_constrained_dofs,
+                                       couplings,
+                                       face_couplings,
+                                       subdomain_id);
+
+  dynamic_pattern.print(deallog.get_file_stream());
+}
+
+
+
+/*
+ * Create the 3-cells-triangulation (described at the top) by first creating 2
+ * cells one the same level and then refining the right one.
+ */
+void create_3_elements_on_2_different_levels(Triangulation<1> &triangulation)
+{
+  const unsigned int n_elements = 3;
+  GridGenerator::subdivided_hyper_cube(triangulation, n_elements - 1);
+  auto cell = triangulation.begin_active();
+  cell++;
+  cell->set_refine_flag();
+  triangulation.execute_coarsening_and_refinement();
+}
+
+
+
+int
+main()
+{
+  initlog();
+  const int dim = 1;
+
+  Triangulation<dim> triangulation;
+  create_3_elements_on_2_different_levels(triangulation);
+
+  const FE_Q<dim> element(1);
+
+  // Since the implementation of make_flux_sparsity_pattern is specialized for
+  // hp::DoFHandler we create and print the sparsity pattern for both
+  // DoFHandler-types.
+  deallog << "dealii::DoFHandler" << std::endl;
+  {
+    DoFHandler<dim> dof_handler(triangulation);
+    dof_handler.distribute_dofs(element);
+    create_and_print_flux_sparsity_pattern(dof_handler);
+  }
+  deallog << "hp::DoFHandler" << std::endl;
+  {
+    hp::FECollection<dim> fe_collection(element);
+    hp::DoFHandler<dim>   dof_handler(triangulation);
+    dof_handler.distribute_dofs(fe_collection);
+    create_and_print_flux_sparsity_pattern(dof_handler);
+  }
+}
diff --git a/tests/dofs/dof_tools_24.output b/tests/dofs/dof_tools_24.output
new file mode 100644 (file)
index 0000000..0cceb8f
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL::dealii::DoFHandler
+[0,0,1,2]
+[1,0,1,2,3]
+[2,0,1,2,3]
+[3,1,2,3]
+DEAL::hp::DoFHandler
+[0,0,1,2]
+[1,0,1,2,3]
+[2,0,1,2,3]
+[3,1,2,3]

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.