From 8e4cb44ab76eec33516613fc4df68565987fddc8 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 26 Apr 2025 16:06:49 -0400 Subject: [PATCH] set_periodicity_constraints(): remove the std::map. We can handle this table more efficiently. This also enables some extra error-checking. --- source/dofs/dof_tools_constraints.cc | 46 ++++++++++++---------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/source/dofs/dof_tools_constraints.cc b/source/dofs/dof_tools_constraints.cc index 1f8f2f1313..fb046467c0 100644 --- a/source/dofs/dof_tools_constraints.cc +++ b/source/dofs/dof_tools_constraints.cc @@ -3259,29 +3259,19 @@ namespace DoFTools return; } - // Well, this is a hack: - // - // There is no - // face_to_face_index(face_index, - // face_orientation, - // face_flip, - // face_rotation) - // function in FiniteElementData, so we have to use - // face_to_cell_index(face_index, face - // face_orientation, - // face_flip, - // face_rotation) - // But this will give us an index on a cell - something we cannot work - // with directly. But luckily we can match them back :-] - - std::map cell_to_rotated_face_index; - - // Build up a cell to face index for face_2: - for (unsigned int i = 0; i < dofs_per_face; ++i) - { - const unsigned int cell_index = fe.face_to_cell_index(i, face_no); - cell_to_rotated_face_index[cell_index] = i; - } + // To match DoFs we need to use combined_orientation to permute the face + // DoFs. FiniteElement does not offer a function to do exactly that: i.e., + // adjust_line_dof_index_for_line_orientation() only considers the + // orientation of a line and adjust_quad_dof_index_for_face_orientation() + // is only for DoFs defined on quads. Hence we compute our own lookup + // table with the necessary information: + std::vector cell_to_face_index( + fe.dofs_per_cell, numbers::invalid_unsigned_int); + + for (unsigned int face_dof = 0; face_dof < dofs_per_face; ++face_dof) + cell_to_face_index[fe.face_to_cell_index( + face_dof, face_no, numbers::default_geometric_orientation)] = + face_dof; // Build constraints in a vector of pairs that can be // arbitrarily large, but that holds up to 25 elements without @@ -3362,8 +3352,10 @@ namespace DoFTools // Get the correct dof index on face_1 respecting the // given orientation: const unsigned int j = - cell_to_rotated_face_index[fe.face_to_cell_index( + cell_to_face_index[fe.face_to_cell_index( jj, face_no, combined_orientation)]; + Assert(j != numbers::invalid_unsigned_int, + ExcInternalError()); if (std::abs(transformation(i, jj)) > eps) constraint_entries.emplace_back(dofs_1[j], @@ -3384,9 +3376,9 @@ namespace DoFTools // Get the correct dof index on face_1 respecting the given // orientation: - const unsigned int j = - cell_to_rotated_face_index[fe.face_to_cell_index( - target, face_no, combined_orientation)]; + const unsigned int j = cell_to_face_index[fe.face_to_cell_index( + target, face_no, combined_orientation)]; + Assert(j != numbers::invalid_unsigned_int, ExcInternalError()); auto dof_left = dofs_1[j]; auto dof_right = dofs_2[i]; -- 2.39.5