From: David Wells Date: Mon, 19 Dec 2022 17:41:47 +0000 (-0500) Subject: Improve memory usage when reading ExodusII grids. X-Git-Tag: v9.5.0-rc1~718^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14587%2Fhead;p=dealii.git Improve memory usage when reading ExodusII grids. 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. --- diff --git a/include/deal.II/grid/connectivity.h b/include/deal.II/grid/connectivity.h index d4264bf045..669a5b41fe 100644 --- a/include/deal.II/grid/connectivity.h +++ b/include/deal.II/grid/connectivity.h @@ -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); } diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index cd75e69224..312400bc28 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -3616,6 +3616,7 @@ namespace // Collect into a sortable data structure: std::vector>> 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::read_exodusii( AssertDimension(mesh_dimension, spacedim); // Read nodes: - std::vector xs(n_nodes); - std::vector ys(n_nodes); - std::vector 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::read_exodusii( // connectivity.") std::vector> 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 xs(n_nodes); + std::vector ys(n_nodes); + std::vector 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 element_block_ids(n_element_blocks); ierr = ex_get_ids(ex_id, EX_ELEM_BLOCK, element_block_ids.data()); AssertThrowExodusII(ierr); std::vector> 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::read_exodusii( connection[elem_n + i] - 1; } cell.material_id = element_block_id; - cells.push_back(cell); + cells.push_back(std::move(cell)); } }