From: Vladimir Yushutin Date: Fri, 10 Mar 2023 02:48:14 +0000 (-0500) Subject: a test is added: make_flux_sparsity_pattern() is run with a face filter which outputs... X-Git-Tag: v9.5.0-rc1~484^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b01635937cda56f86906ff1c8a5bde0f66f78e0b;p=dealii.git a test is added: make_flux_sparsity_pattern() is run with a face filter which outputs to deallog. This should happen exactly once for every face. --- diff --git a/tests/sparsity/flux_sparsity_pattern_visiting_once.cc b/tests/sparsity/flux_sparsity_pattern_visiting_once.cc new file mode 100644 index 0000000000..31ebb6b460 --- /dev/null +++ b/tests/sparsity/flux_sparsity_pattern_visiting_once.cc @@ -0,0 +1,125 @@ +/* --------------------------------------------------------------------- + * + * Copyright (C) 2021 - 2022 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. + * + * --------------------------------------------------------------------- + */ + +// @sect3{Include files} + +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "../tests.h" + + + +// @sect3{The main() function} +// test that a face is visited once +using namespace dealii; + +template +bool +is_face_on_OY(const typename Triangulation::active_cell_iterator &cell, + const unsigned int face_index) +{ + bool on_OY = (std::abs(cell->face(face_index)->center()(0)) < 0.01); + deallog.get_file_stream() + << "This sentence should appear once when the corresponding face is visited only once" + << std::endl; + deallog.get_file_stream() << cell->index() << std::endl; + return on_OY; +} + +template +void +make_two_elements(Triangulation &triangulation) +{ + GridGenerator::hyper_cube(triangulation, -2.0, 2.0); + triangulation.begin_active()->set_refine_flag( + RefinementCase::cut_axis(0)); + triangulation.execute_coarsening_and_refinement(); +} + +template +void +create_flux_pattern_with_filter(DoFHandler & dof_handler, + DynamicSparsityPattern &dsp) +{ + Table<2, DoFTools::Coupling> cell_coupling(1, 1); + Table<2, DoFTools::Coupling> face_coupling(1, 1); + cell_coupling[0][0] = DoFTools::always; + face_coupling[0][0] = DoFTools::always; + + const AffineConstraints constraints; + const bool keep_constrained_dofs = true; + + const auto face_has_flux_coupling = [&](const auto & cell, + const unsigned int face_index) { + return is_face_on_OY(cell, face_index); + }; + + DoFTools::make_flux_sparsity_pattern(dof_handler, + dsp, + constraints, + keep_constrained_dofs, + cell_coupling, + face_coupling, + numbers::invalid_subdomain_id, + face_has_flux_coupling); +} + + +int +main() +{ + initlog(); + const int dim = 2; + + // create a square with two elements + Triangulation triangulation; + make_two_elements(triangulation); + + deallog << "dealii::Sparsity" << std::endl; + { + // Generate Q1 dofs for the mesh grid + DoFHandler dof_handler(triangulation); + const FE_Q finite_element(1); + dof_handler.distribute_dofs(finite_element); + + // Compute the sparsity pattern specifying a face filter + DynamicSparsityPattern dsp(dof_handler.n_dofs(), dof_handler.n_dofs()); + create_flux_pattern_with_filter(dof_handler, dsp); + } +} diff --git a/tests/sparsity/flux_sparsity_pattern_visiting_once.output b/tests/sparsity/flux_sparsity_pattern_visiting_once.output new file mode 100644 index 0000000000..22c63b1009 --- /dev/null +++ b/tests/sparsity/flux_sparsity_pattern_visiting_once.output @@ -0,0 +1,4 @@ + +DEAL::dealii::Sparsity +This sentence should appear once when the corresponding face is visited only once +1