]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Improve memory usage when reading ExodusII grids. 14587/head
authorDavid Wells <drwells@email.unc.edu>
Mon, 19 Dec 2022 17:41:47 +0000 (12:41 -0500)
committerDavid Wells <drwells@email.unc.edu>
Mon, 19 Dec 2022 22:08:13 +0000 (17:08 -0500)
For my big heart mesh (which has about 2.4 million elements) this lowers
peak memory consumption from 1.3 GB to 1.2 GB.

include/deal.II/grid/connectivity.h
source/grid/grid_in.cc

index d4264bf045dafd3516fe6199bb558a1e16fdf49f..669a5b41fefaf69e105c04079ccebe781e0df407 100644 (file)
@@ -1130,7 +1130,7 @@ namespace internal
 
           std::sort(keys.begin(), keys.end());
 
-          ptr_0.reserve(n_unique_entities);
+          ptr_0.reserve(n_unique_entities + 1);
           col_0.reserve(n_unique_entity_vertices);
         }
 
index cd75e69224ce03ffc9049779c27dea8586beccc3..312400bc28833f90df8ad25eba1c100a6aba2dfe 100644 (file)
@@ -3616,6 +3616,7 @@ namespace
         // Collect into a sortable data structure:
         std::vector<std::pair<std::size_t, std::vector<int>>>
           face_id_to_side_sets;
+        face_id_to_side_sets.reserve(face_side_sets.size());
         for (auto &pair : face_side_sets)
           {
             Assert(pair.second.size() > 0, ExcInternalError());
@@ -3632,6 +3633,10 @@ namespace
                                                         b.second.end());
                   });
 
+        if (dim == 2)
+          subcelldata.boundary_lines.reserve(face_id_to_side_sets.size());
+        else if (dim == 3)
+          subcelldata.boundary_quads.reserve(face_id_to_side_sets.size());
         types::boundary_id current_b_or_m_id = 0;
         for (const auto &pair : face_id_to_side_sets)
           {
@@ -3741,13 +3746,7 @@ GridIn<dim, spacedim>::read_exodusii(
   AssertDimension(mesh_dimension, spacedim);
 
   // Read nodes:
-  std::vector<double> xs(n_nodes);
-  std::vector<double> ys(n_nodes);
-  std::vector<double> zs(n_nodes);
-
-  ierr = ex_get_coord(ex_id, xs.data(), ys.data(), zs.data());
-  AssertThrowExodusII(ierr);
-
+  //
   // Even if there is a node numbering array the values stored inside the
   // ExodusII file must use the contiguous, internal ordering (see Section 4.5
   // of the manual - "Internal (contiguously numbered) node and element IDs
@@ -3756,29 +3755,39 @@ GridIn<dim, spacedim>::read_exodusii(
   // connectivity.")
   std::vector<Point<spacedim>> vertices;
   vertices.reserve(n_nodes);
-  for (int vertex_n = 0; vertex_n < n_nodes; ++vertex_n)
-    {
-      switch (spacedim)
-        {
-          case 1:
-            vertices.emplace_back(xs[vertex_n]);
-            break;
-          case 2:
-            vertices.emplace_back(xs[vertex_n], ys[vertex_n]);
-            break;
-          case 3:
-            vertices.emplace_back(xs[vertex_n], ys[vertex_n], zs[vertex_n]);
-            break;
-          default:
-            Assert(spacedim <= 3, ExcNotImplemented());
-        }
-    }
+  {
+    std::vector<double> xs(n_nodes);
+    std::vector<double> ys(n_nodes);
+    std::vector<double> zs(n_nodes);
+
+    ierr = ex_get_coord(ex_id, xs.data(), ys.data(), zs.data());
+    AssertThrowExodusII(ierr);
+
+    for (int vertex_n = 0; vertex_n < n_nodes; ++vertex_n)
+      {
+        switch (spacedim)
+          {
+            case 1:
+              vertices.emplace_back(xs[vertex_n]);
+              break;
+            case 2:
+              vertices.emplace_back(xs[vertex_n], ys[vertex_n]);
+              break;
+            case 3:
+              vertices.emplace_back(xs[vertex_n], ys[vertex_n], zs[vertex_n]);
+              break;
+            default:
+              Assert(spacedim <= 3, ExcNotImplemented());
+          }
+      }
+  }
 
   std::vector<int> element_block_ids(n_element_blocks);
   ierr = ex_get_ids(ex_id, EX_ELEM_BLOCK, element_block_ids.data());
   AssertThrowExodusII(ierr);
 
   std::vector<CellData<dim>> cells;
+  cells.reserve(n_elements);
   // Elements are grouped together by same reference cell type in element
   // blocks. There may be multiple blocks for a single reference cell type,
   // but "each element block may contain only one element type".
@@ -3829,7 +3838,7 @@ GridIn<dim, spacedim>::read_exodusii(
                 connection[elem_n + i] - 1;
             }
           cell.material_id = element_block_id;
-          cells.push_back(cell);
+          cells.push_back(std::move(cell));
         }
     }
 

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.