From e8ac0660c4bce9d250ee19702d489a2b2ac2f9c2 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Thu, 29 Nov 2018 18:21:25 +0100 Subject: [PATCH] make_periodicity_constraints: sort dofs when adding equality constraints When we add add equality constraints of the form dof2 = c dof1, we now ensure that dof2 > dof1. This helps to avoid having inconsistent equality constraints for different MPI processes. Unfortunately, we can only do this if both, dof2 and dof1 are not constrained. Otherwise the order is forced. --- source/dofs/dof_tools_constraints.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/source/dofs/dof_tools_constraints.cc b/source/dofs/dof_tools_constraints.cc index 3c098a614d..ecbe6ea596 100644 --- a/source/dofs/dof_tools_constraints.cc +++ b/source/dofs/dof_tools_constraints.cc @@ -2035,11 +2035,19 @@ namespace DoFTools cell_to_rotated_face_index[fe.face_to_cell_index( target, 0, face_orientation, face_flip, face_rotation)]; - const bool face_2_constrained = - affine_constraints.is_constrained(dofs_2[i]); - const auto dof_left = face_2_constrained ? dofs_1[j] : dofs_2[i]; - const auto dof_right = face_2_constrained ? dofs_2[i] : dofs_1[j]; - factor = face_2_constrained ? 1. / factor : factor; + auto dof_left = dofs_1[j]; + auto dof_right = dofs_2[i]; + + // If dof_left is already constrained, or dof_left < dof_right we + // flip the order to ensure that dofs are constrained in a stable + // manner on different MPI processes. + if (affine_constraints.is_constrained(dof_left) || + (dof_left < dof_right && + !affine_constraints.is_constrained(dof_right))) + { + std::swap(dof_left, dof_right); + factor = 1. / factor; + } // Next, we try to enter the constraint // dof_left = factor * dof_right; @@ -2196,7 +2204,6 @@ namespace DoFTools } return transformation; } - } /*namespace*/ -- 2.39.5