]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Compress face types to a single bit.
authorDavid Wells <drwells@email.unc.edu>
Tue, 20 Dec 2022 15:20:16 +0000 (10:20 -0500)
committerDavid Wells <drwells@email.unc.edu>
Tue, 20 Dec 2022 17:26:37 +0000 (12:26 -0500)
This lowers memory consumption from 712 MB to 707 MB for my 2.4 million
cell tet mesh.

include/deal.II/grid/tria_accessor.templates.h
include/deal.II/grid/tria_faces.h
source/grid/tria.cc
source/grid/tria_faces.cc

index a3bb8eb9c6459bb7f20442e2fca8dedd3ba89262..20ea7a9f05fa7a00aa86271b4d2f0c28dc05ff75 100644 (file)
@@ -1358,7 +1358,7 @@ TriaAccessor<structdim, dim, spacedim>::reference_cell() const
     return this->tria->levels[this->present_level]
       ->reference_cell[this->present_index];
   else
-    return this->tria->faces->quad_reference_cell[this->present_index];
+    return this->tria->faces->get_quad_type(this->present_index);
 }
 
 
index 56ef15c61d7286a06932b7ac0476c0713fa830ed..ad12e541fdfd88e684c624226cbf0c0d0f5cd17d 100644 (file)
@@ -73,11 +73,26 @@ namespace internal
       std::vector<unsigned char> quads_line_orientations;
 
       /**
-       * Reference cell type of each quad.
+       * Whether or not each quad is a Quadrilateral. Since, if dim = 3, faces
+       * are either Triangles or Quadrilaterals, it suffices to store a
+       * boolean.
        *
        * @note Used only for dim=3.
        */
-      std::vector<dealii::ReferenceCell> quad_reference_cell;
+      std::vector<bool> quad_is_quadrilateral;
+
+      /**
+       * Helper accessor function for quad_is_quadrilateral
+       */
+      dealii::ReferenceCell
+      get_quad_type(const std::size_t index) const;
+
+      /**
+       * Helper accessor function for quad_is_quadrilateral
+       */
+      void
+      set_quad_type(const std::size_t           index,
+                    const dealii::ReferenceCell face_type);
 
       /**
        * The TriaObject containing the data of lines.
@@ -105,12 +120,38 @@ namespace internal
 
 
 
+    inline dealii::ReferenceCell
+    TriaFaces::get_quad_type(const std::size_t index) const
+    {
+      AssertIndexRange(index, quad_is_quadrilateral.size());
+      return quad_is_quadrilateral[index] ? ReferenceCells::Quadrilateral :
+                                            ReferenceCells::Triangle;
+    }
+
+
+
+    inline void
+    TriaFaces::set_quad_type(const std::size_t           index,
+                             const dealii::ReferenceCell face_type)
+    {
+      AssertIndexRange(index, quad_is_quadrilateral.size());
+      Assert(face_type == ReferenceCells::Quadrilateral ||
+               face_type == ReferenceCells::Triangle,
+             ExcInternalError());
+      if (face_type == ReferenceCells::Quadrilateral)
+        quad_is_quadrilateral[index] = true;
+      else
+        quad_is_quadrilateral[index] = false;
+    }
+
+
+
     template <class Archive>
     void
     TriaFaces::serialize(Archive &ar, const unsigned int)
     {
       ar &dim;
-      ar &quads &lines &quads_line_orientations &quad_reference_cell;
+      ar &quads &lines &quads_line_orientations &quad_is_quadrilateral;
     }
   } // namespace TriangulationImplementation
 } // namespace internal
index 11a3e08b06bd5b48e8990426c36090192b508d7c..91072928a5944891c624d10eb0b9b82ae595ac3b 100644 (file)
@@ -1126,11 +1126,9 @@ namespace internal
               tria_faces.quads_line_orientations.size(),
             1u);
 
-          tria_faces.quad_reference_cell.reserve(new_size);
-          tria_faces.quad_reference_cell.insert(
-            tria_faces.quad_reference_cell.end(),
-            new_size - tria_faces.quad_reference_cell.size(),
-            dealii::ReferenceCells::Quadrilateral);
+          auto &q_is_q = tria_faces.quad_is_quadrilateral;
+          q_is_q.reserve(new_size);
+          q_is_q.insert(q_is_q.end(), new_size - q_is_q.size(), true);
         }
     }
 
@@ -2347,7 +2345,7 @@ namespace internal
             for (unsigned int q = 0, k = 0; q < n_quads; ++q)
               {
                 // set entity type of quads
-                faces.quad_reference_cell[q] = connectivity.entity_types(2)[q];
+                faces.set_quad_type(q, connectivity.entity_types(2)[q]);
 
                 // loop over all its lines
                 for (unsigned int i = crs.ptr[q], j = 0; i < crs.ptr[q + 1];
@@ -2622,8 +2620,7 @@ namespace internal
         if (dim == 3 && structdim == 2)
           {
             // quad entity types
-            faces.quad_reference_cell.assign(size,
-                                             dealii::ReferenceCells::Invalid);
+            faces.quad_is_quadrilateral.assign(size, true);
 
             // quad line orientations
             faces.quads_line_orientations.assign(size * max_faces_per_cell, -1);
@@ -5477,8 +5474,8 @@ namespace internal
 
                   // TODO: we assume here that all children have the same type
                   // as the parent
-                  triangulation.faces->quad_reference_cell[new_quad->index()] =
-                    reference_face_type;
+                  triangulation.faces->set_quad_type(new_quad->index(),
+                                                     reference_face_type);
 
                   if (reference_face_type == ReferenceCells::Triangle)
                     new_quad->set_bounding_object_indices(
@@ -5634,11 +5631,9 @@ namespace internal
 
                     // TODO: faces of children have the same type as the faces
                     //  of the parent
-                    triangulation.faces
-                      ->quad_reference_cell[new_quad->index()] =
-                      (reference_cell_type == ReferenceCells::Hexahedron) ?
-                        ReferenceCells::Quadrilateral :
-                        ReferenceCells::Triangle;
+                    triangulation.faces->set_quad_type(
+                      new_quad->index(),
+                      reference_cell_type.face_reference_cell(0));
 
                     AssertIsNotUsed(new_quad);
                     new_quad->set_used_flag();
index a747850864a6b92d703a763e5c0d0f57617d7c8a..ac0c9271a1f9b5b77956e57cb5f7a1a5f64e257e 100644 (file)
@@ -39,7 +39,7 @@ namespace internal
       if (dim == 3)
         return (MemoryConsumption::memory_consumption(quads) +
                 MemoryConsumption::memory_consumption(quads_line_orientations) +
-                MemoryConsumption::memory_consumption(quad_reference_cell) +
+                MemoryConsumption::memory_consumption(quad_is_quadrilateral) +
                 MemoryConsumption::memory_consumption(lines));
 
       return 0;

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.