From f5bc7740b40ff07853ff0b4f8213e618d5cedaf5 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Tue, 11 Aug 2020 16:47:18 +0200 Subject: [PATCH] Allow AffineConstraints argument to MGTools::make_sparsity_pattern --- include/deal.II/multigrid/mg_tools.h | 23 ++++++++++++++++------- source/multigrid/mg_tools.cc | 16 ++++++++++------ source/multigrid/mg_tools.inst.in | 18 ++++++++++++++++-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/include/deal.II/multigrid/mg_tools.h b/include/deal.II/multigrid/mg_tools.h index b93635f2aa..c5cf619e3e 100644 --- a/include/deal.II/multigrid/mg_tools.h +++ b/include/deal.II/multigrid/mg_tools.h @@ -75,16 +75,25 @@ namespace MGTools * Write the sparsity structure of the matrix belonging to the specified @p * level. The sparsity pattern is not compressed, so before creating the * actual matrix you have to compress the matrix yourself, using - * SparseMatrixStruct::compress(). + * SparsityPatternType::compress(). * - * There is no need to consider hanging nodes here, since only one level is - * considered. + * The optional AffineConstraints argument allows to define constraints of + * the level matrices like Dirichlet boundary conditions. Note that there is + * need to consider hanging nodes on the typical level matrices, since only + * one level is considered. See DoFTools::make_sparsity_pattern() for more + * details about the arguments. */ - template + template void - make_sparsity_pattern(const DoFHandler &dof_handler, - SparsityPatternType & sparsity, - const unsigned int level); + make_sparsity_pattern( + const DoFHandler &dof_handler, + SparsityPatternType & sparsity, + const unsigned int level, + const AffineConstraints &constraints = AffineConstraints(), + const bool keep_constrained_dofs = true); /** * Make a sparsity pattern including fluxes of discontinuous Galerkin diff --git a/source/multigrid/mg_tools.cc b/source/multigrid/mg_tools.cc index bde170821e..a1f6556517 100644 --- a/source/multigrid/mg_tools.cc +++ b/source/multigrid/mg_tools.cc @@ -567,11 +567,16 @@ namespace MGTools - template + template void make_sparsity_pattern(const DoFHandler &dof, SparsityPatternType & sparsity, - const unsigned int level) + const unsigned int level, + const AffineConstraints &constraints, + const bool keep_constrained_dofs) { const types::global_dof_index n_dofs = dof.n_dofs(level); (void)n_dofs; @@ -592,10 +597,9 @@ namespace MGTools dof.get_triangulation().locally_owned_subdomain()) { cell->get_mg_dof_indices(dofs_on_this_cell); - // make sparsity pattern for this cell - for (unsigned int i = 0; i < dofs_per_cell; ++i) - for (unsigned int j = 0; j < dofs_per_cell; ++j) - sparsity.add(dofs_on_this_cell[i], dofs_on_this_cell[j]); + constraints.add_entries_local_to_global(dofs_on_this_cell, + sparsity, + keep_constrained_dofs); } } diff --git a/source/multigrid/mg_tools.inst.in b/source/multigrid/mg_tools.inst.in index 28c8c89ffa..0938499d6e 100644 --- a/source/multigrid/mg_tools.inst.in +++ b/source/multigrid/mg_tools.inst.in @@ -25,10 +25,24 @@ for (PATTERN : SPARSITY_PATTERNS; deal_II_dimension : DIMENSIONS; template void make_sparsity_pattern( + PATTERN, + double>( const DoFHandler &, PATTERN &, - const unsigned int); + const unsigned int, + const AffineConstraints &, + const bool); + + template void + make_sparsity_pattern( + const DoFHandler &, + PATTERN &, + const unsigned int, + const AffineConstraints &, + const bool); #endif \} } -- 2.39.5