From: Wolfgang Bangerth Date: Mon, 24 Jul 2023 22:24:59 +0000 (-0600) Subject: Adjust expectations in a function. X-Git-Tag: relicensing~629^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c526a4dd045992346c1b61f61053c6f73509396c;p=dealii.git Adjust expectations in a function. --- diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 6d84bbd0ed..abf5fd4ee2 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -577,19 +577,12 @@ namespace GridTools tuple>, std::vector>, SubCellData> get_coarse_mesh_description(const Triangulation &tria) { - Assert(1 <= tria.n_levels(), + Assert(tria.n_levels() >= 1, ExcMessage("The input triangulation must be non-empty.")); - std::vector> vertices; + std::vector> vertices = tria.get_vertices(); std::vector> cells; - unsigned int max_level_0_vertex_n = 0; - for (const auto &cell : tria.cell_iterators_on_level(0)) - for (const unsigned int cell_vertex_n : cell->vertex_indices()) - max_level_0_vertex_n = - std::max(cell->vertex_index(cell_vertex_n), max_level_0_vertex_n); - vertices.resize(max_level_0_vertex_n + 1); - internal::FaceDataHelper face_data; std::set, internal::CellDataComparator<1>> line_data; // only used in 3d @@ -602,14 +595,12 @@ namespace GridTools { Assert(cell->vertex_index(cell_vertex_n) < vertices.size(), ExcInternalError()); - vertices[cell->vertex_index(cell_vertex_n)] = - cell->vertex(cell_vertex_n); cell_data.vertices[cell_vertex_n] = cell->vertex_index(cell_vertex_n); } cell_data.material_id = cell->material_id(); cell_data.manifold_id = cell->manifold_id(); - cells.push_back(cell_data); + cells.emplace_back(std::move(cell_data)); // Save face data if (dim > 1) @@ -645,26 +636,17 @@ namespace GridTools } } - // Double-check that there are no unused vertices: -#ifdef DEBUG - { - std::vector used_vertices(vertices.size()); - for (const CellData &cell_data : cells) - for (const auto v : cell_data.vertices) - used_vertices[v] = true; - Assert(std::find(used_vertices.begin(), used_vertices.end(), false) == - used_vertices.end(), - ExcMessage("The level zero vertices should form a contiguous " - "range.")); - } -#endif - SubCellData subcell_data = face_data.get(); if (dim == 3) for (const CellData<1> &face_line_data : line_data) subcell_data.boundary_lines.push_back(face_line_data); + // We end up with a 'vertices' array that uses some of the entries, + // but not all -- specifically, all vertices referenced by level-0 + // cells. We can compress the array: + GridTools::delete_unused_vertices(vertices, cells, subcell_data); + return std::tuple>, std::vector>, SubCellData>(std::move(vertices),