From: Peter Munch Date: Tue, 3 Aug 2021 07:53:31 +0000 (+0200) Subject: Introduce enum class X-Git-Tag: v9.4.0-rc1~1102^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0aff4aff119b7ad0e8e56447fdf5d29d5bcef590;p=dealii.git Introduce enum class --- diff --git a/include/deal.II/matrix_free/evaluation_kernels.h b/include/deal.II/matrix_free/evaluation_kernels.h index cbbabd1bf6..804fbb9d6c 100644 --- a/include/deal.II/matrix_free/evaluation_kernels.h +++ b/include/deal.II/matrix_free/evaluation_kernels.h @@ -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( @@ -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( @@ -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) diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index 871640c8e1..4f7654d2da 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -4474,7 +4474,8 @@ FEEvaluationBase:: 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:: ->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:: 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, diff --git a/include/deal.II/matrix_free/hanging_nodes_internal.h b/include/deal.II/matrix_free/hanging_nodes_internal.h index d5c1a3aa47..156f7e9c20 100644 --- a/include/deal.II/matrix_free/hanging_nodes_internal.h +++ b/include/deal.II/matrix_free/hanging_nodes_internal.h @@ -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(static_cast(f1) | - static_cast(f2)); + return static_cast(static_cast(f1) | + static_cast(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(static_cast(f1) | - static_cast(f2)); + return static_cast(f1) != static_cast(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(f1) < static_cast(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(static_cast(f1) & + static_cast(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; } diff --git a/include/deal.II/matrix_free/matrix_free.templates.h b/include/deal.II/matrix_free/matrix_free.templates.h index 27f818e8fb..d8160a3e81 100644 --- a/include/deal.II/matrix_free/matrix_free.templates.h +++ b/include/deal.II/matrix_free/matrix_free.templates.h @@ -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(); } diff --git a/include/deal.II/matrix_free/tools.h b/include/deal.II/matrix_free/tools.h index 71a3859131..0d8d701425 100644 --- a/include/deal.II/matrix_free/tools.h +++ b/include/deal.II/matrix_free/tools.h @@ -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, n_lanes> diagonals_local_constrained; - std::map>> locally_relevant_constrains_hn_map; }; diff --git a/source/matrix_free/dof_info.cc b/source/matrix_free/dof_info.cc index 9dbbb3fe54..31d17618c9 100644 --- a/source/matrix_free/dof_info.cc +++ b/source/matrix_free/dof_info.cc @@ -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( diff --git a/tests/matrix_free/hanging_node_kernels_01.cc b/tests/matrix_free/hanging_node_kernels_01.cc index fb56496180..1a5a7e3c14 100644 --- a/tests/matrix_free/hanging_node_kernels_01.cc +++ b/tests/matrix_free/hanging_node_kernels_01.cc @@ -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) {