From: Peter Munch Date: Tue, 12 May 2020 21:30:49 +0000 (+0200) Subject: Merge orientation/rotation/flip to single number X-Git-Tag: v9.3.0-rc1~1573^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1ed4bdb65b1c9acb42172825d25511d21801fa9;p=dealii.git Merge orientation/rotation/flip to single number --- diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index ce7b25a5f0..6882c5bc07 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -756,6 +756,34 @@ namespace internal } + /** + * Check if the bit at position @p n in @p number is set. + */ + inline static bool + get_bit(const char number, const unsigned int n) + { + // 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(char &number, const unsigned int n, const bool x) + { + // source: + // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit + // "Changing the nth bit to x" + number ^= (-x ^ number) & (1UL << n); + } + + + template inline static bool face_flip(const TriaAccessor<3, dim, spacedim> &accessor, @@ -764,12 +792,13 @@ namespace internal AssertIndexRange(face, GeometryInfo<3>::faces_per_cell); Assert(accessor.present_index * GeometryInfo<3>::faces_per_cell + face < accessor.tria->levels[accessor.present_level] - ->cells.face_flips.size(), + ->cells.face_orientations.size(), ExcInternalError()); - return ( - accessor.tria->levels[accessor.present_level]->cells.face_flips - [accessor.present_index * GeometryInfo<3>::faces_per_cell + face]); + return get_bit( + accessor.tria->levels[accessor.present_level]->cells.face_orientations + [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], + 1 /*=flip_bit*/); } @@ -800,12 +829,13 @@ namespace internal AssertIndexRange(face, GeometryInfo<3>::faces_per_cell); Assert(accessor.present_index * GeometryInfo<3>::faces_per_cell + face < accessor.tria->levels[accessor.present_level] - ->cells.face_rotations.size(), + ->cells.face_orientations.size(), ExcInternalError()); - return ( - accessor.tria->levels[accessor.present_level]->cells.face_rotations - [accessor.present_index * GeometryInfo<3>::faces_per_cell + face]); + return get_bit( + accessor.tria->levels[accessor.present_level]->cells.face_orientations + [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], + 2 /*=rotation_bit*/); } /** @@ -957,9 +987,11 @@ namespace internal accessor.tria->levels[accessor.present_level] ->cells.face_orientations.size(), ExcInternalError()); - accessor.tria->levels[accessor.present_level]->cells.face_orientations - [accessor.present_index * GeometryInfo<3>::faces_per_cell + face] = - value; + set_bit( + accessor.tria->levels[accessor.present_level]->cells.face_orientations + [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], + 0 /*=orientation_bit*/, + value); } @@ -986,12 +1018,14 @@ namespace internal AssertIndexRange(face, GeometryInfo<3>::faces_per_cell); Assert(accessor.present_index * GeometryInfo<3>::faces_per_cell + face < accessor.tria->levels[accessor.present_level] - ->cells.face_flips.size(), + ->cells.face_orientations.size(), ExcInternalError()); - accessor.tria->levels[accessor.present_level]->cells.face_flips - [accessor.present_index * GeometryInfo<3>::faces_per_cell + face] = - value; + set_bit( + accessor.tria->levels[accessor.present_level]->cells.face_orientations + [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], + 1 /*=flip_bit*/, + value); } @@ -1018,12 +1052,14 @@ namespace internal AssertIndexRange(face, GeometryInfo<3>::faces_per_cell); Assert(accessor.present_index * GeometryInfo<3>::faces_per_cell + face < accessor.tria->levels[accessor.present_level] - ->cells.face_rotations.size(), + ->cells.face_orientations.size(), ExcInternalError()); - accessor.tria->levels[accessor.present_level]->cells.face_rotations - [accessor.present_index * GeometryInfo<3>::faces_per_cell + face] = - value; + set_bit( + accessor.tria->levels[accessor.present_level]->cells.face_orientations + [accessor.present_index * GeometryInfo<3>::faces_per_cell + face], + 2 /*=rotation_bit*/, + value); } /** diff --git a/include/deal.II/grid/tria_objects.h b/include/deal.II/grid/tria_objects.h index 704ecff65d..b640ac2c78 100644 --- a/include/deal.II/grid/tria_objects.h +++ b/include/deal.II/grid/tria_objects.h @@ -456,18 +456,12 @@ namespace internal * * In effect, this field has 6*n_cells elements, being the * number of cells times the six faces each has. - */ - std::vector face_orientations; - - /** + * * flip = rotation by 180 degrees - */ - std::vector face_flips; - - /** + * * rotation by 90 degrees */ - std::vector face_rotations; + std::vector face_orientations; /** * Assert that enough space is allocated to accommodate @@ -533,7 +527,7 @@ namespace internal * In effect, this field has 4*n_quads elements, being the * number of quads times the four lines each has. */ - std::vector line_orientations; + std::vector line_orientations; /** * Assert that enough space is allocated to accommodate @@ -748,7 +742,7 @@ namespace internal { this->TriaObjects>::serialize(ar, version); - ar &face_orientations &face_flips &face_rotations; + ar &face_orientations; } @@ -773,7 +767,8 @@ namespace internal GeometryInfo<3>::faces_per_cell); AssertIndexRange(face, GeometryInfo<3>::faces_per_cell); - return face_orientations[cell * GeometryInfo<3>::faces_per_cell + face]; + return face_orientations[cell * GeometryInfo<3>::faces_per_cell + face] & + 1; } //----------------------------------------------------------------------// @@ -782,7 +777,8 @@ namespace internal TriaObjectsQuad3D::face_orientation(const unsigned int cell, const unsigned int face) const { - return line_orientations[cell * GeometryInfo<2>::faces_per_cell + face]; + return line_orientations[cell * GeometryInfo<2>::faces_per_cell + face] & + 1; } diff --git a/source/grid/tria_objects.cc b/source/grid/tria_objects.cc index 2c65a4a180..05800a2042 100644 --- a/source/grid/tria_objects.cc +++ b/source/grid/tria_objects.cc @@ -214,17 +214,6 @@ namespace internal refinement_cases.insert(refinement_cases.end(), new_size - refinement_cases.size(), RefinementCase<3>::no_refinement); - - face_flips.reserve(new_size * GeometryInfo<3>::faces_per_cell); - face_flips.insert(face_flips.end(), - new_size * GeometryInfo<3>::faces_per_cell - - face_flips.size(), - false); - face_rotations.reserve(new_size * GeometryInfo<3>::faces_per_cell); - face_rotations.insert(face_rotations.end(), - new_size * GeometryInfo<3>::faces_per_cell - - face_rotations.size(), - false); } next_free_single = next_free_pair = 0; } @@ -360,14 +349,6 @@ namespace internal face_orientations.size(), ExcMemoryInexact(cells.size() * GeometryInfo<3>::faces_per_cell, face_orientations.size())); - Assert(cells.size() * GeometryInfo<3>::faces_per_cell == - face_flips.size(), - ExcMemoryInexact(cells.size() * GeometryInfo<3>::faces_per_cell, - face_flips.size())); - Assert(cells.size() * GeometryInfo<3>::faces_per_cell == - face_rotations.size(), - ExcMemoryInexact(cells.size() * GeometryInfo<3>::faces_per_cell, - face_rotations.size())); } @@ -406,8 +387,6 @@ namespace internal { TriaObjects>::clear(); face_orientations.clear(); - face_flips.clear(); - face_rotations.clear(); } @@ -438,8 +417,6 @@ namespace internal TriaObjectsHex::memory_consumption() const { return (MemoryConsumption::memory_consumption(face_orientations) + - MemoryConsumption::memory_consumption(face_flips) + - MemoryConsumption::memory_consumption(face_rotations) + TriaObjects>::memory_consumption()); }