From: Denis Davydov Date: Thu, 29 Nov 2018 17:21:25 +0000 (+0100) Subject: make_periodicity_constraints: sort dofs when adding equality constraints X-Git-Tag: v9.1.0-rc1~405^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8ac0660c4bce9d250ee19702d489a2b2ac2f9c2;p=dealii.git 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. --- 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*/