]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Adjust expectations in a function. 15802/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 24 Jul 2023 22:24:59 +0000 (16:24 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 26 Jul 2023 18:24:26 +0000 (12:24 -0600)
source/grid/grid_tools.cc

index 6d84bbd0ede1b137f8a433c065ca6961bc8e4d8a..abf5fd4ee227a25302e70dae4de050aa8f15f86b 100644 (file)
@@ -577,19 +577,12 @@ namespace GridTools
     tuple<std::vector<Point<spacedim>>, std::vector<CellData<dim>>, SubCellData>
     get_coarse_mesh_description(const Triangulation<dim, spacedim> &tria)
   {
-    Assert(1 <= tria.n_levels(),
+    Assert(tria.n_levels() >= 1,
            ExcMessage("The input triangulation must be non-empty."));
 
-    std::vector<Point<spacedim>> vertices;
+    std::vector<Point<spacedim>> vertices = tria.get_vertices();
     std::vector<CellData<dim>>   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<dim> face_data;
     std::set<CellData<1>, 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<bool> used_vertices(vertices.size());
-      for (const CellData<dim> &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<Point<spacedim>>,
                       std::vector<CellData<dim>>,
                       SubCellData>(std::move(vertices),

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.