From 8d4fc9008265574c59f2e6d29c0ce81ec8757405 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 3 Feb 2021 11:14:07 -0700 Subject: [PATCH] Move the get/set_bit() functions into namespace Utilities. --- include/deal.II/base/utilities.h | 40 +++++++++ include/deal.II/grid/reference_cell.h | 86 +++++++------------ .../deal.II/grid/tria_accessor.templates.h | 12 +-- 3 files changed, 75 insertions(+), 63 deletions(-) diff --git a/include/deal.II/base/utilities.h b/include/deal.II/base/utilities.h index b545314492..a7fda7316a 100644 --- a/include/deal.II/base/utilities.h +++ b/include/deal.II/base/utilities.h @@ -690,6 +690,20 @@ namespace Utilities T (&unpacked_object)[N], const bool allow_compression = true); + /** + * Check if the bit at position @p n in @p number is set. + */ + bool + get_bit(const unsigned char number, const unsigned int n); + + + /** + * Set the bit at position @p n in @p number to value @p x. + */ + void + set_bit(unsigned char &number, const unsigned int n, const bool x); + + /** * Convert an object of type `std::unique_ptr` to an object of * type `std::unique_ptr`, where it is assumed that we can cast @@ -1336,6 +1350,32 @@ namespace Utilities + inline bool + get_bit(const unsigned char number, const unsigned int n) + { + AssertIndexRange(n, 8); + + // source: + // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit + // "Checking a bit" + return (number >> n) & 1U; + } + + + + inline void + set_bit(unsigned char &number, const unsigned int n, const bool x) + { + AssertIndexRange(n, 8); + + // source: + // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit + // "Changing the nth bit to x" + number ^= (-static_cast(x) ^ number) & (1U << n); + } + + + template std::vector reverse_permutation(const std::vector &permutation) diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index e8a64b167e..f4c7f0bd6a 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -21,6 +21,7 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -766,36 +767,6 @@ get_default_linear_mapping(const Triangulation &triangulation); namespace internal { - /** - * Check if the bit at position @p n in @p number is set. - */ - inline static bool - get_bit(const unsigned char number, const unsigned int n) - { - AssertIndexRange(n, 8); - - // source: - // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit - // "Checking a bit" - return (number >> n) & 1U; - } - - - - /** - * Set the bit at position @p n in @p number to value @p x. - */ - inline static void - set_bit(unsigned char &number, const unsigned int n, const bool x) - { - AssertIndexRange(n, 8); - - // source: - // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit - // "Changing the nth bit to x" - number ^= (-static_cast(x) ^ number) & (1U << n); - } - /** * A namespace for geometric information on reference cells. */ @@ -1070,9 +1041,9 @@ namespace internal return GeometryInfo::face_to_cell_lines( face, line, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } unsigned int @@ -1083,9 +1054,9 @@ namespace internal return GeometryInfo::face_to_cell_vertices( face, vertex, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } }; @@ -1506,9 +1477,9 @@ namespace internal { return GeometryInfo<3>::standard_to_real_face_line( line, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } else // TRI { @@ -1556,9 +1527,9 @@ namespace internal { return GeometryInfo<3>::standard_to_real_face_vertex( vertex, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } else // Tri { @@ -1680,9 +1651,9 @@ namespace internal { return GeometryInfo<3>::standard_to_real_face_line( line, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } else // TRI { @@ -1730,9 +1701,9 @@ namespace internal { return GeometryInfo<3>::standard_to_real_face_vertex( vertex, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } else // TRI { @@ -1827,9 +1798,9 @@ namespace internal return GeometryInfo<3>::standard_to_real_face_line( line, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } bool @@ -1852,9 +1823,10 @@ namespace internal {false, false}}, {{true, false}, {false, true}}}}; - const bool face_orientation = get_bit(face_orientation_raw, 0); - const bool face_flip = get_bit(face_orientation_raw, 2); - const bool face_rotation = get_bit(face_orientation_raw, 1); + const bool face_orientation = + Utilities::get_bit(face_orientation_raw, 0); + const bool face_flip = Utilities::get_bit(face_orientation_raw, 2); + const bool face_rotation = Utilities::get_bit(face_orientation_raw, 1); return ( static_cast(line_orientation) == @@ -1879,9 +1851,9 @@ namespace internal return GeometryInfo<3>::standard_to_real_face_vertex( vertex, - get_bit(face_orientation, 0), - get_bit(face_orientation, 2), - get_bit(face_orientation, 1)); + Utilities::get_bit(face_orientation, 0), + Utilities::get_bit(face_orientation, 2), + Utilities::get_bit(face_orientation, 1)); } dealii::ReferenceCell diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index a274e69e7a..0030fbe8e4 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -689,7 +689,7 @@ namespace internal face_orientation(const TriaAccessor<3, 3, 3> &accessor, const unsigned int face) { - return internal::get_bit( + return Utilities::get_bit( accessor.tria->levels[accessor.present_level]->face_orientations [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], 0 /*=orientation_bit*/); @@ -739,7 +739,7 @@ namespace internal ->face_orientations.size(), ExcInternalError()); - return internal::get_bit( + return Utilities::get_bit( accessor.tria->levels[accessor.present_level]->face_orientations [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], 2 /*=flip_bit*/); @@ -775,7 +775,7 @@ namespace internal ->face_orientations.size(), ExcInternalError()); - return internal::get_bit( + return Utilities::get_bit( accessor.tria->levels[accessor.present_level]->face_orientations [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], 1 /*=rotation_bit*/); @@ -873,7 +873,7 @@ namespace internal accessor.tria->levels[accessor.present_level] ->face_orientations.size(), ExcInternalError()); - internal::set_bit( + Utilities::set_bit( accessor.tria->levels[accessor.present_level]->face_orientations [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], 0 /*=orientation_bit*/, @@ -906,7 +906,7 @@ namespace internal ->face_orientations.size(), ExcInternalError()); - internal::set_bit( + Utilities::set_bit( accessor.tria->levels[accessor.present_level]->face_orientations [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], 2 /*=flip_bit*/, @@ -939,7 +939,7 @@ namespace internal ->face_orientations.size(), ExcInternalError()); - internal::set_bit( + Utilities::set_bit( accessor.tria->levels[accessor.present_level]->face_orientations [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], 1 /*=rotation_bit*/, -- 2.39.5