]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Remove some duplication; also simplify VTK code. 14622/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 29 Dec 2022 18:11:48 +0000 (11:11 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 29 Dec 2022 18:11:48 +0000 (11:11 -0700)
The VTK tags are already defined in helper functions in class ReferenceCell; get them from
there. While there, the previous version of a helper function was rather hard to read
because of a long list of if-else cases; make it a bit easier to read.

source/base/data_out_base.cc

index 331f1d3be357351d93383c9fb2170c218046f711..d3d5972c5ca32a05b4b8fed2e3d7d2302873acc9 100644 (file)
@@ -726,44 +726,9 @@ namespace
   const unsigned int tecplot_binary_cell_type[4] = {0, 0, 1, 3};
 #endif
 
-  // Define cell id using VTK nomenclature for linear, quadratic and
-  // high-order Lagrange cells
-  enum vtk_linear_cell_type
-  {
-    VTK_VERTEX     = 1,
-    VTK_LINE       = 3,
-    VTK_TRIANGLE   = 5,
-    VTK_QUAD       = 9,
-    VTK_TETRA      = 10,
-    VTK_HEXAHEDRON = 12,
-    VTK_WEDGE      = 13,
-    VTK_PYRAMID    = 14
-  };
-
-  enum vtk_quadratic_cell_type
-  {
-    VTK_QUADRATIC_EDGE       = 21,
-    VTK_QUADRATIC_TRIANGLE   = 22,
-    VTK_QUADRATIC_QUAD       = 23,
-    VTK_QUADRATIC_TETRA      = 24,
-    VTK_QUADRATIC_HEXAHEDRON = 25,
-    VTK_QUADRATIC_WEDGE      = 26,
-    VTK_QUADRATIC_PYRAMID    = 27
-  };
-
-  enum vtk_lagrange_cell_type
-  {
-    VTK_LAGRANGE_CURVE         = 68,
-    VTK_LAGRANGE_TRIANGLE      = 69,
-    VTK_LAGRANGE_QUADRILATERAL = 70,
-    VTK_LAGRANGE_TETRAHEDRON   = 71,
-    VTK_LAGRANGE_HEXAHEDRON    = 72,
-    VTK_LAGRANGE_WEDGE         = 73,
-    VTK_LAGRANGE_PYRAMID       = 74
-  };
 
   /**
-   * Return the tuple (vtk cell type, number of cells, number of vertices)
+   * Return the tuple (vtk cell type, number of cells, number of nodes)
    * for a patch.
    */
   template <int dim, int spacedim>
@@ -771,71 +736,36 @@ namespace
   extract_vtk_patch_info(const DataOutBase::Patch<dim, spacedim> &patch,
                          const bool write_higher_order_cells)
   {
-    std::array<unsigned int, 3> vtk_cell_id{};
+    std::array<unsigned int, 3> vtk_cell_id = {
+      {/* cell type, tbd: */ numbers::invalid_unsigned_int,
+       /* # of cells, default: just one cell */ 1,
+       /* # of nodes, default: as many nodes as vertices */
+       patch.reference_cell.n_vertices()}};
 
     if (write_higher_order_cells)
       {
-        if (patch.reference_cell.is_hyper_cube())
-          {
-            const std::array<unsigned int, 4> cell_type_by_dim{
-              {VTK_VERTEX,
-               VTK_LAGRANGE_CURVE,
-               VTK_LAGRANGE_QUADRILATERAL,
-               VTK_LAGRANGE_HEXAHEDRON}};
-            vtk_cell_id[0] = cell_type_by_dim[dim];
-            vtk_cell_id[1] = 1;
-          }
-        else if (patch.reference_cell == ReferenceCells::Triangle)
-          {
-            vtk_cell_id[0] = VTK_LAGRANGE_TRIANGLE;
-            vtk_cell_id[1] = 1;
-          }
-        else
-          {
-            Assert(false, ExcNotImplemented());
-          }
-      }
-    else if (patch.reference_cell == ReferenceCells::Triangle &&
-             patch.data.n_cols() == 3)
-      {
-        vtk_cell_id[0] = VTK_TRIANGLE;
-        vtk_cell_id[1] = 1;
+        vtk_cell_id[0] = patch.reference_cell.vtk_lagrange_type();
+        vtk_cell_id[2] = patch.data.n_cols();
       }
+    else if (patch.data.n_cols() == patch.reference_cell.n_vertices())
+      // One data set per vertex -> a linear cell
+      vtk_cell_id[0] = patch.reference_cell.vtk_linear_type();
     else if (patch.reference_cell == ReferenceCells::Triangle &&
              patch.data.n_cols() == 6)
       {
-        vtk_cell_id[0] = VTK_QUADRATIC_TRIANGLE;
-        vtk_cell_id[1] = 1;
-      }
-    else if (patch.reference_cell == ReferenceCells::Tetrahedron &&
-             patch.data.n_cols() == 4)
-      {
-        vtk_cell_id[0] = VTK_TETRA;
-        vtk_cell_id[1] = 1;
+        vtk_cell_id[0] = patch.reference_cell.vtk_quadratic_type();
+        vtk_cell_id[2] = patch.data.n_cols();
       }
     else if (patch.reference_cell == ReferenceCells::Tetrahedron &&
              patch.data.n_cols() == 10)
       {
-        vtk_cell_id[0] = VTK_QUADRATIC_TETRA;
-        vtk_cell_id[1] = 1;
-      }
-    else if (patch.reference_cell == ReferenceCells::Wedge &&
-             patch.data.n_cols() == 6)
-      {
-        vtk_cell_id[0] = VTK_WEDGE;
-        vtk_cell_id[1] = 1;
-      }
-    else if (patch.reference_cell == ReferenceCells::Pyramid &&
-             patch.data.n_cols() == 5)
-      {
-        vtk_cell_id[0] = VTK_PYRAMID;
-        vtk_cell_id[1] = 1;
+        vtk_cell_id[0] = patch.reference_cell.vtk_quadratic_type();
+        vtk_cell_id[2] = patch.data.n_cols();
       }
     else if (patch.reference_cell.is_hyper_cube())
       {
-        const std::array<unsigned int, 4> cell_type_by_dim{
-          {VTK_VERTEX, VTK_LINE, VTK_QUAD, VTK_HEXAHEDRON}};
-        vtk_cell_id[0] = cell_type_by_dim[dim];
+        // For hypercubes, we support sub-divided linear cells
+        vtk_cell_id[0] = patch.reference_cell.vtk_linear_type();
         vtk_cell_id[1] = Utilities::pow(patch.n_subdivisions, dim);
       }
     else
@@ -843,12 +773,6 @@ namespace
         Assert(false, ExcNotImplemented());
       }
 
-    if (patch.reference_cell != ReferenceCells::get_hypercube<dim>() ||
-        write_higher_order_cells)
-      vtk_cell_id[2] = patch.data.n_cols();
-    else
-      vtk_cell_id[2] = GeometryInfo<dim>::vertices_per_cell;
-
     return vtk_cell_id;
   }
 

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.