Skip to content

Commit

Permalink
Check during MF::reinit() if AffineConstraints are closed
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrum committed Mar 8, 2022
1 parent a5d36df commit ac097b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
9 changes: 9 additions & 0 deletions doc/news/changes/incompatibilities/20220308Munch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changed: To be able to guarantee correctness of
the application of constraints in MatrixFree, we
require that users call AffineConstraints::close()
before calling MatrixFree::reinit() if AffineConstraints
objects are passed that are not empty. One can check
if an AffineConstraints object is closed with the
new function AffineConstraints::is_closed().
<br>
(Peter Munch, 2022/03/08)
16 changes: 13 additions & 3 deletions include/deal.II/matrix_free/matrix_free.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void
MatrixFree<dim, Number, VectorizedArrayType>::internal_reinit(
const std::shared_ptr<hp::MappingCollection<dim>> & mapping,
const std::vector<const DoFHandler<dim, dim> *> & dof_handler,
const std::vector<const AffineConstraints<number2> *> &constraint,
const std::vector<const AffineConstraints<number2> *> &constraints,
const std::vector<IndexSet> & locally_owned_dofs,
const std::vector<hp::QCollection<q_dim>> & quad,
const typename MatrixFree<dim, Number, VectorizedArrayType>::AdditionalData
Expand Down Expand Up @@ -414,7 +414,7 @@ MatrixFree<dim, Number, VectorizedArrayType>::internal_reinit(
{
clear();
Assert(dof_handler.size() > 0, ExcMessage("No DoFHandler is given."));
AssertDimension(dof_handler.size(), constraint.size());
AssertDimension(dof_handler.size(), constraints.size());
AssertDimension(dof_handler.size(), locally_owned_dofs.size());

task_info.allow_ghosted_vectors_in_loops =
Expand All @@ -439,6 +439,16 @@ MatrixFree<dim, Number, VectorizedArrayType>::internal_reinit(
task_info.n_procs = 1;
}

#ifdef DEBUG
for (const auto &constraint : constraints)
Assert(
constraint->is_closed(task_info.communicator),
ExcMessage(
"You have proveded a non-empty AffineConstraint object that has not "
"been closed. Please call AffineConstraints::close() before "
"calling MatrixFree::reinit()!"));
#endif

initialize_dof_handlers(dof_handler, additional_data);
for (unsigned int no = 0; no < dof_handler.size(); ++no)
{
Expand Down Expand Up @@ -469,7 +479,7 @@ MatrixFree<dim, Number, VectorizedArrayType>::internal_reinit(
// constraint_pool_data. It also reorders the way cells are gone through
// (to separate cells with overlap to other processors from others
// without).
initialize_indices(constraint, locally_owned_dofs, additional_data);
initialize_indices(constraints, locally_owned_dofs, additional_data);
}

// initialize bare structures
Expand Down
1 change: 1 addition & 0 deletions tests/matrix_free/mixed_mesh_hn_algorithm_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ main()

AffineConstraints<double> constraints;
DoFTools::make_hanging_node_constraints(dof_handler, constraints);
constraints.close();

const auto print = [](const auto &label, const auto &matrix_free) {
deallog << label << std::endl;
Expand Down
16 changes: 8 additions & 8 deletions tests/matrix_free/mixed_mesh_hn_algorithm_01.output
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

DEAL::use_fast_hanging_node_algorithm = true
DEAL::0 : 12 13 14
DEAL::0 : 13 2 2 1
DEAL::0 : 14 2 1 1
DEAL::0 : 13 2 1 14
DEAL::0 : 13 2 1 2
DEAL::0 : 14 1 2 1
DEAL::0 : 13 1 2 14
DEAL::0 : 0 1 2
DEAL::0 : 3 1 4
DEAL::0 : 5 4 1
Expand All @@ -17,16 +17,16 @@ DEAL::
DEAL::
DEAL::use_fast_hanging_node_algorithm = false
DEAL::0 : 12 13 14
DEAL::0 : 13 2 2 1
DEAL::0 : 14 2 1 1
DEAL::0 : 13 2 1 14
DEAL::0 : 13 2 1 2
DEAL::0 : 14 1 2 1
DEAL::0 : 13 1 2 14
DEAL::0 : 0 1 2
DEAL::0 : 3 1 4
DEAL::0 : 5 4 1
DEAL::0 : 1 0 5
DEAL::0 : 6 5 0
DEAL::0 : 7 8 9 10
DEAL::0 : 8 12 10 14
DEAL::0 : 9 10 3 3 1
DEAL::0 : 10 14 3 1 1
DEAL::0 : 9 10 3 1 3
DEAL::0 : 10 14 1 3 1
DEAL::

0 comments on commit ac097b9

Please sign in to comment.