From cc49a0467b83f2dcca82e8c4a76f204cb72310df Mon Sep 17 00:00:00 2001 From: Jiaqi Zhang Date: Sun, 19 Jun 2022 23:04:04 -0400 Subject: [PATCH] clear user constraints --- .../deal.II/multigrid/mg_constrained_dofs.h | 16 +++ tests/multigrid/constrained_dofs_07.cc | 101 ++++++++++++++++++ tests/multigrid/constrained_dofs_07.output | 11 ++ 3 files changed, 128 insertions(+) create mode 100644 tests/multigrid/constrained_dofs_07.cc create mode 100644 tests/multigrid/constrained_dofs_07.output diff --git a/include/deal.II/multigrid/mg_constrained_dofs.h b/include/deal.II/multigrid/mg_constrained_dofs.h index 1b8304a1e3..64694b461c 100644 --- a/include/deal.II/multigrid/mg_constrained_dofs.h +++ b/include/deal.II/multigrid/mg_constrained_dofs.h @@ -145,6 +145,12 @@ public: const types::boundary_id bid, const unsigned int first_vector_component); + /** + * Clear the user constraints on all levels. + */ + void + clear_user_constraints(); + /** * Reset the data structures. */ @@ -459,6 +465,16 @@ MGConstrainedDoFs::add_user_constraints( } + +inline void +MGConstrainedDoFs::clear_user_constraints() +{ + for (auto &constraint : user_constraints) + constraint.clear(); +} + + + inline void MGConstrainedDoFs::clear() { diff --git a/tests/multigrid/constrained_dofs_07.cc b/tests/multigrid/constrained_dofs_07.cc new file mode 100644 index 0000000000..9f543778cc --- /dev/null +++ b/tests/multigrid/constrained_dofs_07.cc @@ -0,0 +1,101 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 - 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. +// +// --------------------------------------------------------------------- + + +// Check clear_user_constraints() +#include + +#include + +#include + +#include + +#include +#include + +#include "../tests.h" + +template +void +check() +{ + Triangulation tr(Triangulation::limit_level_difference_at_vertices); + GridGenerator::hyper_cube(tr, 0, 1, false); + + typename Triangulation::active_cell_iterator cell = tr.begin_active(); + cell->face(0)->set_all_boundary_ids(1); + + tr.refine_global(1); + + FE_Q fe = FE_Q(1); + + DoFHandler mgdof(tr); + mgdof.distribute_dofs(fe); + mgdof.distribute_mg_dofs(); + + MGConstrainedDoFs mg_constrained_dofs; + mg_constrained_dofs.initialize(mgdof); + + for (unsigned int level = 0; level < tr.n_levels(); ++level) + { + IndexSet relevant_dofs; + DoFTools::extract_locally_relevant_level_dofs(mgdof, + level, + relevant_dofs); + AffineConstraints level_constraints; + level_constraints.reinit(relevant_dofs); + + typename DoFHandler::level_face_iterator face0 = + mgdof.begin(level)->face(0); + std::vector face_dofs(fe.dofs_per_face); + face0->get_mg_dof_indices(level, face_dofs); + for (unsigned int i = 0; i < face_dofs.size(); ++i) + { + if (level_constraints.can_store_line(face_dofs[i])) + { + level_constraints.add_line(face_dofs[i]); + level_constraints.set_inhomogeneity(face_dofs[i], 5.0); + } + } + level_constraints.close(); + mg_constrained_dofs.add_user_constraints(level, level_constraints); + deallog << " level: " << level + << " n_constraints: " << level_constraints.n_constraints() + << std::endl; + } + + mg_constrained_dofs.clear_user_constraints(); + for (unsigned int level = 0; level < tr.n_levels(); ++level) + { + const AffineConstraints &level_constraints = + mg_constrained_dofs.get_user_constraint_matrix(level); + deallog << " level: " << level + << " n_constraints: " << level_constraints.n_constraints() + << std::endl; + } +} + + +int +main() +{ + initlog(); + + check<2>(); + deallog << std::endl; + check<3>(); + deallog << std::endl; +} diff --git a/tests/multigrid/constrained_dofs_07.output b/tests/multigrid/constrained_dofs_07.output new file mode 100644 index 0000000000..a42fd4ab0f --- /dev/null +++ b/tests/multigrid/constrained_dofs_07.output @@ -0,0 +1,11 @@ + +DEAL:: level: 0 n_constraints: 2 +DEAL:: level: 1 n_constraints: 2 +DEAL:: level: 0 n_constraints: 0 +DEAL:: level: 1 n_constraints: 0 +DEAL:: +DEAL:: level: 0 n_constraints: 4 +DEAL:: level: 1 n_constraints: 4 +DEAL:: level: 0 n_constraints: 0 +DEAL:: level: 1 n_constraints: 0 +DEAL:: -- 2.39.5