]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce enum class
authorPeter Munch <peterrmuench@gmail.com>
Tue, 3 Aug 2021 07:53:31 +0000 (09:53 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Tue, 3 Aug 2021 07:53:31 +0000 (09:53 +0200)
include/deal.II/matrix_free/evaluation_kernels.h
include/deal.II/matrix_free/fe_evaluation.h
include/deal.II/matrix_free/hanging_nodes_internal.h
include/deal.II/matrix_free/matrix_free.templates.h
include/deal.II/matrix_free/tools.h
source/matrix_free/dof_info.cc
tests/matrix_free/hanging_node_kernels_01.cc

index cbbabd1bf6a9110354b3aa3794ccf51ee3bd53c2..804fbb9d6c2bb4a4bdb3201f8e253f5f32f6f24e 100644 (file)
@@ -4667,12 +4667,12 @@ namespace internal
         fe_degree != -1 ? fe_degree :
                           fe_eval.get_shape_info().data.front().fe_degree;
 
-      const auto is_set = [](const unsigned int a, const unsigned int b) {
+      const auto is_set = [](const auto a, const auto b) -> bool {
         return (a & b) == b;
       };
 
-      const auto not_set = [](const unsigned int a, const unsigned int b) {
-        return (a & b) == 0;
+      const auto not_set = [](const auto a, const auto b) -> bool {
+        return (a & b) == MatrixFreeFunctions::ConstraintTypes::unconstrained;
       };
 
       const unsigned int points = given_degree + 1;
@@ -4689,10 +4689,12 @@ namespace internal
               if (dim == 2) // 2D: only faces
                 {
                   // direction 0:
-                  if (mask & MatrixFreeFunctions::ConstraintTypes::face_y)
+                  if ((mask & MatrixFreeFunctions::ConstraintTypes::face_y) !=
+                      MatrixFreeFunctions::ConstraintTypes::unconstrained)
                     {
                       const bool is_subface_0 =
-                        mask & MatrixFreeFunctions::ConstraintTypes::type_x;
+                        (mask & MatrixFreeFunctions::ConstraintTypes::type_x) !=
+                        MatrixFreeFunctions::ConstraintTypes::unconstrained;
                       if (is_set(mask,
                                  MatrixFreeFunctions::ConstraintTypes::type_y))
                         interpolate_2D<fe_degree, 2, transpose>(
@@ -4711,10 +4713,12 @@ namespace internal
                     }
 
                   // direction 1:
-                  if (mask & MatrixFreeFunctions::ConstraintTypes::face_x)
+                  if ((mask & MatrixFreeFunctions::ConstraintTypes::face_x) !=
+                      MatrixFreeFunctions::ConstraintTypes::unconstrained)
                     {
                       const bool is_subface_0 =
-                        mask & MatrixFreeFunctions::ConstraintTypes::type_y;
+                        (mask & MatrixFreeFunctions::ConstraintTypes::type_y) !=
+                        MatrixFreeFunctions::ConstraintTypes::unconstrained;
                       if (is_set(mask,
                                  MatrixFreeFunctions::ConstraintTypes::type_x))
                         interpolate_2D<fe_degree, 0, transpose>(
@@ -4847,7 +4851,8 @@ namespace internal
                   // direction 0:
                   {
                     const bool is_subface_0 =
-                      mask & MatrixFreeFunctions::ConstraintTypes::type_x;
+                      (mask & MatrixFreeFunctions::ConstraintTypes::type_x) !=
+                      MatrixFreeFunctions::ConstraintTypes::unconstrained;
 
                     // ... faces
                     if (is_face_2)
@@ -4921,7 +4926,8 @@ namespace internal
                   // direction 1:
                   {
                     const bool is_subface_0 =
-                      mask & MatrixFreeFunctions::ConstraintTypes::type_y;
+                      (mask & MatrixFreeFunctions::ConstraintTypes::type_y) !=
+                      MatrixFreeFunctions::ConstraintTypes::unconstrained;
 
                     // ... faces
                     if (is_face_0)
@@ -4995,7 +5001,8 @@ namespace internal
                   // direction 2:
                   {
                     const bool is_subface_0 =
-                      mask & MatrixFreeFunctions::ConstraintTypes::type_z;
+                      (mask & MatrixFreeFunctions::ConstraintTypes::type_z) !=
+                      MatrixFreeFunctions::ConstraintTypes::unconstrained;
 
                     // ... faces
                     if (is_face_0)
index 871640c8e19911c92d2867b380d0f33d9a0c5d13..4f7654d2daaed086c8b2677b40bf904aa0cda781 100644 (file)
@@ -4474,7 +4474,8 @@ FEEvaluationBase<dim, n_components_, Number, is_face, VectorizedArrayType>::
             this->dof_info
                 ->hanging_node_constraint_masks[(this->cell * n_lanes + v) *
                                                   n_fe_components +
-                                                first_selected_component] != 0)
+                                                first_selected_component] !=
+              internal::MatrixFreeFunctions::ConstraintTypes::unconstrained)
           has_hn_constraints = true;
     }
 
@@ -4581,7 +4582,7 @@ FEEvaluationBase<dim, n_components_, Number, is_face, VectorizedArrayType>::
                   ->hanging_node_constraint_masks[(this->cell * n_lanes + v) *
                                                     n_fe_components +
                                                   first_selected_component] !=
-                0)
+                internal::MatrixFreeFunctions::ConstraintTypes::unconstrained)
             has_hn_constraints = true;
 
           Assert(my_index_start[n_components_read].first ==
@@ -4656,7 +4657,8 @@ FEEvaluationBase<dim, n_components_, Number, is_face, VectorizedArrayType>::
              this->dof_info->row_starts[cell_dof_index + n_components_read]
                .second ||
            (this->dof_info->hanging_node_constraint_masks.size() > 0 &&
-            this->dof_info->hanging_node_constraint_masks[cell_dof_index] > 0)))
+            this->dof_info->hanging_node_constraint_masks[cell_dof_index] !=
+              internal::MatrixFreeFunctions::ConstraintTypes::unconstrained)))
         {
           Assert(this->dof_info->row_starts_plain_indices[cell_index] !=
                    numbers::invalid_unsigned_int,
index d5c1a3aa4764a3cfc27f4ab887776098ab75c8c5..156f7e9c2054b20a19c7c1c3e4f45aeaf10faaf3 100644 (file)
@@ -50,7 +50,7 @@ namespace internal
      * determine which face is constrained. For example, in 2D, if
      * face_x and type are set, then x = 0 is constrained.
      */
-    enum ConstraintTypes : unsigned short
+    enum class ConstraintTypes : std::uint16_t
     {
       unconstrained = 0,
 
@@ -78,11 +78,11 @@ namespace internal
      * would be an integer which would in turn trigger a compiler warning when
      * we tried to assign it to an object of type UpdateFlags.
      */
-    inline ConstraintTypes
+    DEAL_II_CUDA_HOST_DEV inline ConstraintTypes
     operator|(const ConstraintTypes f1, const ConstraintTypes f2)
     {
-      return static_cast<ConstraintTypes>(static_cast<unsigned short>(f1) |
-                                          static_cast<unsigned short>(f2));
+      return static_cast<ConstraintTypes>(static_cast<std::uint16_t>(f1) |
+                                          static_cast<std::uint16_t>(f2));
     }
 
 
@@ -91,7 +91,7 @@ namespace internal
      * Global operator which sets the bits from the second argument also in the
      * first one.
      */
-    inline ConstraintTypes &
+    DEAL_II_CUDA_HOST_DEV inline ConstraintTypes &
     operator|=(ConstraintTypes &f1, const ConstraintTypes f2)
     {
       f1 = f1 | f2;
@@ -100,23 +100,38 @@ namespace internal
 
 
 
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
-    __device__ inline ConstraintTypes
-    operator|(const ConstraintTypes f1, const ConstraintTypes f2)
+    /**
+     * Global operator which checks inequality.
+     */
+    DEAL_II_CUDA_HOST_DEV inline bool
+    operator!=(const ConstraintTypes f1, const ConstraintTypes f2)
     {
-      return static_cast<ConstraintTypes>(static_cast<unsigned short>(f1) |
-                                          static_cast<unsigned short>(f2));
+      return static_cast<std::uint16_t>(f1) != static_cast<std::uint16_t>(f2);
     }
 
 
 
-    __device__ inline ConstraintTypes &
-    operator|=(ConstraintTypes &f1, const ConstraintTypes f2)
+    /**
+     * Global operator which checks if the first argument is less than the
+     * second.
+     */
+    DEAL_II_CUDA_HOST_DEV inline bool
+    operator<(const ConstraintTypes f1, const ConstraintTypes f2)
     {
-      f1 = f1 | f2;
-      return f1;
+      return static_cast<std::uint16_t>(f1) < static_cast<std::uint16_t>(f2);
+    }
+
+
+
+    /**
+     * Global operator which performs a binary and for the provided arguments.
+     */
+    DEAL_II_CUDA_HOST_DEV inline ConstraintTypes
+    operator&(const ConstraintTypes f1, const ConstraintTypes f2)
+    {
+      return static_cast<ConstraintTypes>(static_cast<std::uint16_t>(f1) &
+                                          static_cast<std::uint16_t>(f2));
     }
-#endif
 
 
 
@@ -586,7 +601,8 @@ namespace internal
                   {
                     // If we don't already have a constraint for as part of a
                     // face
-                    if (!(mask & line_to_edge[local_line][0]))
+                    if ((mask & line_to_edge[local_line][0]) ==
+                        ConstraintTypes::unconstrained)
                       {
                         // For each cell which share that edge
                         const unsigned int line =
@@ -681,7 +697,8 @@ namespace internal
                       }
                   }
               }
-            cell_has_hanging_node_constraints |= mask != 0;
+            cell_has_hanging_node_constraints |=
+              mask != ConstraintTypes::unconstrained;
           }
       return cell_has_hanging_node_constraints;
     }
index 27f818e8fb27845ec493230fa77fb6139cf6ec6d..d8160a3e816a1b19f74799428c9be24f6078373d 100644 (file)
@@ -1306,7 +1306,8 @@ namespace internal
         {
           auto &vec = dof_info[no].hanging_node_constraint_masks;
           if (std::all_of(vec.begin(), vec.end(), [](const auto i) {
-                return i == 0;
+                return i == internal::MatrixFreeFunctions::ConstraintTypes::
+                              unconstrained;
               }))
             vec.clear();
         }
index 71a3859131f0bd4709f96be0e5299a77c9b8b19d..0d8d701425f9cd186af247b5ed87e3ad60da15ed 100644 (file)
@@ -453,7 +453,8 @@ namespace MatrixFreeTools
                                                    first_selected_component];
 
                 // cell has hanging nodes
-                if (mask != 0)
+                if (mask != dealii::internal::MatrixFreeFunctions::
+                              ConstraintTypes::unconstrained)
                   {
                     // check if hanging node internpolation matrix has been set
                     // up
@@ -767,7 +768,7 @@ namespace MatrixFreeTools
       // constraints!
       std::array<std::vector<Number>, n_lanes> diagonals_local_constrained;
 
-      std::map<unsigned int,
+      std::map<dealii::internal::MatrixFreeFunctions::ConstraintTypes,
                std::vector<std::tuple<unsigned int, unsigned int, Number>>>
         locally_relevant_constrains_hn_map;
     };
index 9dbbb3fe54568a5877eb7bd4f851281573006877..31d17618c9f1904b0d74de0c6f5777a359af330b 100644 (file)
@@ -104,7 +104,8 @@ namespace internal
           // one
           const bool has_constraints =
             (hanging_node_constraint_masks.size() != 0 &&
-             hanging_node_constraint_masks[ib] != 0) ||
+             hanging_node_constraint_masks[ib] !=
+               ConstraintTypes::unconstrained) ||
             (row_starts[ib].second != row_starts[ib + n_fe_components].second);
 
           auto do_copy = [&](const unsigned int *begin,
@@ -230,7 +231,8 @@ namespace internal
                       has_hanging_nodes |=
                         hanging_node_constraint_masks[boundary_cells[i] *
                                                         n_components +
-                                                      comp] > 0;
+                                                      comp] !=
+                        ConstraintTypes::unconstrained;
 
                   if (has_hanging_nodes ||
                       row_starts[boundary_cells[i] * n_components].second !=
@@ -385,7 +387,8 @@ namespace internal
                       const auto mask =
                         hanging_node_constraint_masks[cell_no + comp];
                       new_hanging_node_constraint_masks.push_back(mask);
-                      has_hanging_nodes |= mask > 0;
+                      has_hanging_nodes |=
+                        mask != ConstraintTypes::unconstrained;
                     }
 
                   new_dof_indices.insert(
index fb564961807a0078c791041298f0e67e2a3f07d3..1a5a7e3c14989239157af2b58aa57b9a37f5d4bc 100644 (file)
@@ -130,10 +130,11 @@ namespace dealii
 
         for (unsigned int v = 0; v < Number::size(); ++v)
           {
-            if (constraint_mask[v] == 0)
+            if (constraint_mask[v] == dealii::internal::MatrixFreeFunctions::
+                                        ConstraintTypes::unconstrained)
               continue;
 
-            const unsigned int this_type =
+            const auto this_type =
               (direction == 0) ?
                 dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_x :
                 dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_y;
@@ -147,9 +148,13 @@ namespace dealii
                 ((direction == 1) ? dealii::internal::MatrixFreeFunctions::
                                       ConstraintTypes::face_x :
                                     dealii::internal::MatrixFreeFunctions::
-                                      ConstraintTypes::unconstrained)));
+                                      ConstraintTypes::unconstrained))) !=
+              dealii::internal::MatrixFreeFunctions::ConstraintTypes::
+                unconstrained;
 
-            const bool type = constraint_mask[v] & this_type;
+            const bool type = (constraint_mask[v] & this_type) !=
+                              dealii::internal::MatrixFreeFunctions::
+                                ConstraintTypes::unconstrained;
 
             for (unsigned int x_idx = 0; x_idx < fe_degree + 1; ++x_idx)
               for (unsigned int y_idx = 0; y_idx < fe_degree + 1; ++y_idx)
@@ -166,15 +171,17 @@ namespace dealii
                   // (left (= 0) or right (= fe_degree))
                   const bool constrained_dof =
                     ((direction == 0) &&
-                     ((constraint_mask[v] &
-                       dealii::internal::MatrixFreeFunctions::ConstraintTypes::
-                         type_y) ?
+                     (((constraint_mask[v] &
+                        dealii::internal::MatrixFreeFunctions::ConstraintTypes::
+                          type_y) != dealii::internal::MatrixFreeFunctions::
+                                       ConstraintTypes::unconstrained) ?
                         (y_idx == 0) :
                         (y_idx == fe_degree))) ||
                     ((direction == 1) &&
-                     ((constraint_mask[v] &
-                       dealii::internal::MatrixFreeFunctions::ConstraintTypes::
-                         type_x) ?
+                     (((constraint_mask[v] &
+                        dealii::internal::MatrixFreeFunctions::ConstraintTypes::
+                          type_x) != dealii::internal::MatrixFreeFunctions::
+                                       ConstraintTypes::unconstrained) ?
                         (x_idx == 0) :
                         (x_idx == fe_degree)));
 
@@ -260,19 +267,19 @@ namespace dealii
         for (unsigned int i = 0; i < n_dofs; ++i)
           values_temp[i] = values[i];
 
-        const unsigned int this_type =
+        const auto this_type =
           (direction == 0) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_x :
           (direction == 1) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_y :
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_z;
-        const unsigned int face1_type =
+        const auto face1_type =
           (direction == 0) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_y :
           (direction == 1) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_z :
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_x;
-        const unsigned int face2_type =
+        const auto face2_type =
           (direction == 0) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::type_z :
           (direction == 1) ?
@@ -282,19 +289,19 @@ namespace dealii
         // If computing in x-direction, need to match against
         // dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_y or
         // dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_z
-        const unsigned int face1 =
+        const auto face1 =
           (direction == 0) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_y :
           (direction == 1) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_z :
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_x;
-        const unsigned int face2 =
+        const auto face2 =
           (direction == 0) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_z :
           (direction == 1) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_x :
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::face_y;
-        const unsigned int edge =
+        const auto edge =
           (direction == 0) ?
             dealii::internal::MatrixFreeFunctions::ConstraintTypes::edge_yz :
           (direction == 1) ?
@@ -303,13 +310,16 @@ namespace dealii
 
         for (unsigned int v = 0; v < Number::size(); ++v)
           {
-            if (constraint_mask[v] == 0)
+            if (constraint_mask[v] == dealii::internal::MatrixFreeFunctions::
+                                        ConstraintTypes::unconstrained)
               continue;
 
-            const unsigned int constrained_face =
+            const auto constrained_face =
               constraint_mask[v] & (face1 | face2 | edge);
 
-            const bool type = constraint_mask[v] & this_type;
+            const bool type = (constraint_mask[v] & this_type) !=
+                              dealii::internal::MatrixFreeFunctions::
+                                ConstraintTypes::unconstrained;
 
             for (unsigned int x_idx = 0; x_idx < fe_degree + 1; ++x_idx)
               for (unsigned int y_idx = 0; y_idx < fe_degree + 1; ++y_idx)
@@ -326,18 +336,36 @@ namespace dealii
                                                                        y_idx;
 
                     typename Number::value_type t = 0;
-                    const bool on_face1 = (constraint_mask[v] & face1_type) ?
-                                            (face1_idx == 0) :
-                                            (face1_idx == fe_degree);
-                    const bool on_face2 = (constraint_mask[v] & face2_type) ?
-                                            (face2_idx == 0) :
-                                            (face2_idx == fe_degree);
+                    const bool                  on_face1 =
+                      ((constraint_mask[v] & face1_type) !=
+                       dealii::internal::MatrixFreeFunctions::ConstraintTypes::
+                         unconstrained) ?
+                                         (face1_idx == 0) :
+                                         (face1_idx == fe_degree);
+                    const bool on_face2 =
+                      ((constraint_mask[v] & face2_type) !=
+                       dealii::internal::MatrixFreeFunctions::ConstraintTypes::
+                         unconstrained) ?
+                        (face2_idx == 0) :
+                        (face2_idx == fe_degree);
                     const bool constrained_dof =
-                      (((constraint_mask[v] & face1) && on_face1) ||
-                       ((constraint_mask[v] & face2) && on_face2) ||
-                       ((constraint_mask[v] & edge) && on_face1 && on_face2));
-
-                    if (constrained_face && constrained_dof)
+                      ((((constraint_mask[v] & face1) !=
+                         dealii::internal::MatrixFreeFunctions::
+                           ConstraintTypes::unconstrained) &&
+                        on_face1) ||
+                       (((constraint_mask[v] & face2) !=
+                         dealii::internal::MatrixFreeFunctions::
+                           ConstraintTypes::unconstrained) &&
+                        on_face2) ||
+                       (((constraint_mask[v] & edge) !=
+                         dealii::internal::MatrixFreeFunctions::
+                           ConstraintTypes::unconstrained) &&
+                        on_face1 && on_face2));
+
+                    if ((constrained_face !=
+                         dealii::internal::MatrixFreeFunctions::
+                           ConstraintTypes::unconstrained) &&
+                        constrained_dof)
                       {
                         if (type)
                           {

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.