]> https://gitweb.dealii.org/ - dealii.git/commitdiff
set_periodicity_constraints(): remove the std::map.
authorDavid Wells <drwells@email.unc.edu>
Sat, 26 Apr 2025 20:06:49 +0000 (16:06 -0400)
committerDavid Wells <drwells@email.unc.edu>
Sun, 27 Apr 2025 01:15:14 +0000 (21:15 -0400)
We can handle this table more efficiently. This also enables some extra
error-checking.

source/dofs/dof_tools_constraints.cc

index 1f8f2f1313176c0bfbf3a1e6652532d31f65eda0..fb046467c09f83169aaf914ae079fa2c908368d5 100644 (file)
@@ -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<unsigned int, unsigned int> 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<unsigned int> 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];

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.