From: Simon Sticko Date: Fri, 17 Jan 2020 16:10:04 +0000 (+0100) Subject: Add test of make_flux_sparsity_pattern in 1D. X-Git-Tag: v9.2.0-rc1~629^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e535845dbc12596b54ea449e236869b32fefa2a;p=dealii.git Add test of make_flux_sparsity_pattern in 1D. 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. --- diff --git a/tests/dofs/dof_tools_24.cc b/tests/dofs/dof_tools_24.cc new file mode 100644 index 0000000000..09a3c91bec --- /dev/null +++ b/tests/dofs/dof_tools_24.cc @@ -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 +#include + +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include + +#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 +void +create_and_print_flux_sparsity_pattern(const DoFHandlerType &dof_handler) +{ + AffineConstraints 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 triangulation; + create_3_elements_on_2_different_levels(triangulation); + + const FE_Q 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 dof_handler(triangulation); + dof_handler.distribute_dofs(element); + create_and_print_flux_sparsity_pattern(dof_handler); + } + deallog << "hp::DoFHandler" << std::endl; + { + hp::FECollection fe_collection(element); + hp::DoFHandler 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 index 0000000000..0cceb8f4c1 --- /dev/null +++ b/tests/dofs/dof_tools_24.output @@ -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]