]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge orientation/rotation/flip to single number
authorPeter Munch <peterrmuench@gmail.com>
Tue, 12 May 2020 21:30:49 +0000 (23:30 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Tue, 12 May 2020 21:30:49 +0000 (23:30 +0200)
include/deal.II/grid/tria_accessor.templates.h
include/deal.II/grid/tria_objects.h
source/grid/tria_objects.cc

index ce7b25a5f0c70f02a4eebfd4898d646413b67385..6882c5bc07ca33850516b314aa0d34232ce84fea 100644 (file)
@@ -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 <int dim, int spacedim>
       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);
       }
 
       /**
index 704ecff65d8b4fcd229f5d5539fdf70468ae53e5..b640ac2c78be45eabf7ca3562f96ae61f53e3990 100644 (file)
@@ -456,18 +456,12 @@ namespace internal
        *
        * In effect, this field has <code>6*n_cells</code> elements, being the
        * number of cells times the six faces each has.
-       */
-      std::vector<bool> face_orientations;
-
-      /**
+       *
        * flip = rotation by 180 degrees
-       */
-      std::vector<bool> face_flips;
-
-      /**
+       *
        * rotation by 90 degrees
        */
-      std::vector<bool> face_rotations;
+      std::vector<char> face_orientations;
 
       /**
        * Assert that enough space is allocated to accommodate
@@ -533,7 +527,7 @@ namespace internal
        * In effect, this field has <code>4*n_quads</code> elements, being the
        * number of quads times the four lines each has.
        */
-      std::vector<bool> line_orientations;
+      std::vector<char> line_orientations;
 
       /**
        * Assert that enough space is allocated to accommodate
@@ -748,7 +742,7 @@ namespace internal
     {
       this->TriaObjects<TriaObject<3>>::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;
     }
 
 
index 2c65a4a180061d6fba175756588d8a1dbbda4dd3..05800a2042af19ee7fd47fbe7103ad3ca7c72f6a 100644 (file)
@@ -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<TriaObject<3>>::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<TriaObject<3>>::memory_consumption());
     }
 

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.