]> https://gitweb.dealii.org/ - dealii.git/commitdiff
ReferenceCell: use more switch statements.
authorDavid Wells <drwells@email.unc.edu>
Sat, 21 Jan 2023 23:15:59 +0000 (18:15 -0500)
committerDavid Wells <drwells@email.unc.edu>
Sun, 22 Jan 2023 20:23:57 +0000 (15:23 -0500)
source/grid/reference_cell.cc

index 83e75fffdc7a54b418f069e66d37de750876487d..8d0987d5a6569a5c32872701f469f9994b97388e 100644 (file)
@@ -80,26 +80,29 @@ namespace
 std::string
 ReferenceCell::to_string() const
 {
-  if (*this == ReferenceCells::Vertex)
-    return "Vertex";
-  else if (*this == ReferenceCells::Line)
-    return "Line";
-  else if (*this == ReferenceCells::Triangle)
-    return "Tri";
-  else if (*this == ReferenceCells::Quadrilateral)
-    return "Quad";
-  else if (*this == ReferenceCells::Tetrahedron)
-    return "Tet";
-  else if (*this == ReferenceCells::Pyramid)
-    return "Pyramid";
-  else if (*this == ReferenceCells::Wedge)
-    return "Wedge";
-  else if (*this == ReferenceCells::Hexahedron)
-    return "Hex";
-  else if (*this == ReferenceCells::Invalid)
-    return "Invalid";
-
-  Assert(false, ExcNotImplemented());
+  switch (this->kind)
+    {
+      case ReferenceCells::Vertex:
+        return "Vertex";
+      case ReferenceCells::Line:
+        return "Line";
+      case ReferenceCells::Triangle:
+        return "Tri";
+      case ReferenceCells::Quadrilateral:
+        return "Quad";
+      case ReferenceCells::Tetrahedron:
+        return "Tet";
+      case ReferenceCells::Pyramid:
+        return "Pyramid";
+      case ReferenceCells::Wedge:
+        return "Wedge";
+      case ReferenceCells::Hexahedron:
+        return "Hex";
+      case ReferenceCells::Invalid:
+        return "Invalid";
+      default:
+        Assert(false, ExcNotImplemented());
+    }
 
   return "Invalid";
 }
@@ -244,42 +247,39 @@ ReferenceCell::exodusii_vertex_to_deal_vertex(const unsigned int vertex_n) const
 {
   AssertIndexRange(vertex_n, n_vertices());
 
-  if (*this == ReferenceCells::Line)
-    {
-      return vertex_n;
-    }
-  else if (*this == ReferenceCells::Triangle)
-    {
-      return vertex_n;
-    }
-  else if (*this == ReferenceCells::Quadrilateral)
+  switch (this->kind)
     {
-      constexpr std::array<unsigned int, 4> exodus_to_deal{{0, 1, 3, 2}};
-      return exodus_to_deal[vertex_n];
-    }
-  else if (*this == ReferenceCells::Tetrahedron)
-    {
-      return vertex_n;
-    }
-  else if (*this == ReferenceCells::Hexahedron)
-    {
-      constexpr std::array<unsigned int, 8> exodus_to_deal{
-        {0, 1, 3, 2, 4, 5, 7, 6}};
-      return exodus_to_deal[vertex_n];
-    }
-  else if (*this == ReferenceCells::Wedge)
-    {
-      constexpr std::array<unsigned int, 6> exodus_to_deal{{2, 1, 0, 5, 4, 3}};
-      return exodus_to_deal[vertex_n];
-    }
-  else if (*this == ReferenceCells::Pyramid)
-    {
-      constexpr std::array<unsigned int, 5> exodus_to_deal{{0, 1, 3, 2, 4}};
-      return exodus_to_deal[vertex_n];
+      case ReferenceCells::Line:
+      case ReferenceCells::Triangle:
+        return vertex_n;
+      case ReferenceCells::Quadrilateral:
+        {
+          constexpr std::array<unsigned int, 4> exodus_to_deal{{0, 1, 3, 2}};
+          return exodus_to_deal[vertex_n];
+        }
+      case ReferenceCells::Tetrahedron:
+        return vertex_n;
+      case ReferenceCells::Hexahedron:
+        {
+          constexpr std::array<unsigned int, 8> exodus_to_deal{
+            {0, 1, 3, 2, 4, 5, 7, 6}};
+          return exodus_to_deal[vertex_n];
+        }
+      case ReferenceCells::Wedge:
+        {
+          constexpr std::array<unsigned int, 6> exodus_to_deal{
+            {2, 1, 0, 5, 4, 3}};
+          return exodus_to_deal[vertex_n];
+        }
+      case ReferenceCells::Pyramid:
+        {
+          constexpr std::array<unsigned int, 5> exodus_to_deal{{0, 1, 3, 2, 4}};
+          return exodus_to_deal[vertex_n];
+        }
+      default:
+        Assert(false, ExcNotImplemented());
     }
 
-  Assert(false, ExcNotImplemented());
-
   return numbers::invalid_unsigned_int;
 }
 
@@ -290,46 +290,43 @@ ReferenceCell::exodusii_face_to_deal_face(const unsigned int face_n) const
 {
   AssertIndexRange(face_n, n_faces());
 
-  if (*this == ReferenceCells::Vertex)
-    {
-      return 0;
-    }
-  if (*this == ReferenceCells::Line)
-    {
-      return face_n;
-    }
-  else if (*this == ReferenceCells::Triangle)
-    {
-      return face_n;
-    }
-  else if (*this == ReferenceCells::Quadrilateral)
+  switch (this->kind)
     {
-      constexpr std::array<unsigned int, 4> exodus_to_deal{{2, 1, 3, 0}};
-      return exodus_to_deal[face_n];
-    }
-  else if (*this == ReferenceCells::Tetrahedron)
-    {
-      constexpr std::array<unsigned int, 4> exodus_to_deal{{1, 3, 2, 0}};
-      return exodus_to_deal[face_n];
-    }
-  else if (*this == ReferenceCells::Hexahedron)
-    {
-      constexpr std::array<unsigned int, 6> exodus_to_deal{{2, 1, 3, 0, 4, 5}};
-      return exodus_to_deal[face_n];
-    }
-  else if (*this == ReferenceCells::Wedge)
-    {
-      constexpr std::array<unsigned int, 6> exodus_to_deal{{3, 4, 2, 0, 1}};
-      return exodus_to_deal[face_n];
-    }
-  else if (*this == ReferenceCells::Pyramid)
-    {
-      constexpr std::array<unsigned int, 5> exodus_to_deal{{3, 2, 4, 1, 0}};
-      return exodus_to_deal[face_n];
+      case ReferenceCells::Vertex:
+        return 0;
+      case ReferenceCells::Line:
+      case ReferenceCells::Triangle:
+        return face_n;
+      case ReferenceCells::Quadrilateral:
+        {
+          constexpr std::array<unsigned int, 4> exodus_to_deal{{2, 1, 3, 0}};
+          return exodus_to_deal[face_n];
+        }
+      case ReferenceCells::Tetrahedron:
+        {
+          constexpr std::array<unsigned int, 4> exodus_to_deal{{1, 3, 2, 0}};
+          return exodus_to_deal[face_n];
+        }
+      case ReferenceCells::Hexahedron:
+        {
+          constexpr std::array<unsigned int, 6> exodus_to_deal{
+            {2, 1, 3, 0, 4, 5}};
+          return exodus_to_deal[face_n];
+        }
+      case ReferenceCells::Wedge:
+        {
+          constexpr std::array<unsigned int, 6> exodus_to_deal{{3, 4, 2, 0, 1}};
+          return exodus_to_deal[face_n];
+        }
+      case ReferenceCells::Pyramid:
+        {
+          constexpr std::array<unsigned int, 5> exodus_to_deal{{3, 2, 4, 1, 0}};
+          return exodus_to_deal[face_n];
+        }
+      default:
+        Assert(false, ExcNotImplemented());
     }
 
-  Assert(false, ExcNotImplemented());
-
   return numbers::invalid_unsigned_int;
 }
 
@@ -374,26 +371,29 @@ ReferenceCell::unv_vertex_to_deal_vertex(const unsigned int vertex_n) const
 unsigned int
 ReferenceCell::vtk_linear_type() const
 {
-  if (*this == ReferenceCells::Vertex)
-    return VTKCellType::VTK_VERTEX;
-  else if (*this == ReferenceCells::Line)
-    return VTKCellType::VTK_LINE;
-  else if (*this == ReferenceCells::Triangle)
-    return VTKCellType::VTK_TRIANGLE;
-  else if (*this == ReferenceCells::Quadrilateral)
-    return VTKCellType::VTK_QUAD;
-  else if (*this == ReferenceCells::Tetrahedron)
-    return VTKCellType::VTK_TETRA;
-  else if (*this == ReferenceCells::Pyramid)
-    return VTKCellType::VTK_PYRAMID;
-  else if (*this == ReferenceCells::Wedge)
-    return VTKCellType::VTK_WEDGE;
-  else if (*this == ReferenceCells::Hexahedron)
-    return VTKCellType::VTK_HEXAHEDRON;
-  else if (*this == ReferenceCells::Invalid)
-    return VTKCellType::VTK_INVALID;
-
-  Assert(false, ExcNotImplemented());
+  switch (this->kind)
+    {
+      case ReferenceCells::Vertex:
+        return VTKCellType::VTK_VERTEX;
+      case ReferenceCells::Line:
+        return VTKCellType::VTK_LINE;
+      case ReferenceCells::Triangle:
+        return VTKCellType::VTK_TRIANGLE;
+      case ReferenceCells::Quadrilateral:
+        return VTKCellType::VTK_QUAD;
+      case ReferenceCells::Tetrahedron:
+        return VTKCellType::VTK_TETRA;
+      case ReferenceCells::Pyramid:
+        return VTKCellType::VTK_PYRAMID;
+      case ReferenceCells::Wedge:
+        return VTKCellType::VTK_WEDGE;
+      case ReferenceCells::Hexahedron:
+        return VTKCellType::VTK_HEXAHEDRON;
+      case ReferenceCells::Invalid:
+        return VTKCellType::VTK_INVALID;
+      default:
+        Assert(false, ExcNotImplemented());
+    }
 
   return VTKCellType::VTK_INVALID;
 }
@@ -403,26 +403,29 @@ ReferenceCell::vtk_linear_type() const
 unsigned int
 ReferenceCell::vtk_quadratic_type() const
 {
-  if (*this == ReferenceCells::Vertex)
-    return VTKCellType::VTK_VERTEX;
-  else if (*this == ReferenceCells::Line)
-    return VTKCellType::VTK_QUADRATIC_EDGE;
-  else if (*this == ReferenceCells::Triangle)
-    return VTKCellType::VTK_QUADRATIC_TRIANGLE;
-  else if (*this == ReferenceCells::Quadrilateral)
-    return VTKCellType::VTK_QUADRATIC_QUAD;
-  else if (*this == ReferenceCells::Tetrahedron)
-    return VTKCellType::VTK_QUADRATIC_TETRA;
-  else if (*this == ReferenceCells::Pyramid)
-    return VTKCellType::VTK_QUADRATIC_PYRAMID;
-  else if (*this == ReferenceCells::Wedge)
-    return VTKCellType::VTK_QUADRATIC_WEDGE;
-  else if (*this == ReferenceCells::Hexahedron)
-    return VTKCellType::VTK_QUADRATIC_HEXAHEDRON;
-  else if (*this == ReferenceCells::Invalid)
-    return VTKCellType::VTK_INVALID;
-
-  Assert(false, ExcNotImplemented());
+  switch (this->kind)
+    {
+      case ReferenceCells::Vertex:
+        return VTKCellType::VTK_VERTEX;
+      case ReferenceCells::Line:
+        return VTKCellType::VTK_QUADRATIC_EDGE;
+      case ReferenceCells::Triangle:
+        return VTKCellType::VTK_QUADRATIC_TRIANGLE;
+      case ReferenceCells::Quadrilateral:
+        return VTKCellType::VTK_QUADRATIC_QUAD;
+      case ReferenceCells::Tetrahedron:
+        return VTKCellType::VTK_QUADRATIC_TETRA;
+      case ReferenceCells::Pyramid:
+        return VTKCellType::VTK_QUADRATIC_PYRAMID;
+      case ReferenceCells::Wedge:
+        return VTKCellType::VTK_QUADRATIC_WEDGE;
+      case ReferenceCells::Hexahedron:
+        return VTKCellType::VTK_QUADRATIC_HEXAHEDRON;
+      case ReferenceCells::Invalid:
+        return VTKCellType::VTK_INVALID;
+      default:
+        Assert(false, ExcNotImplemented());
+    }
 
   return VTKCellType::VTK_INVALID;
 }
@@ -432,26 +435,29 @@ ReferenceCell::vtk_quadratic_type() const
 unsigned int
 ReferenceCell::vtk_lagrange_type() const
 {
-  if (*this == ReferenceCells::Vertex)
-    return VTKCellType::VTK_VERTEX;
-  else if (*this == ReferenceCells::Line)
-    return VTKCellType::VTK_LAGRANGE_CURVE;
-  else if (*this == ReferenceCells::Triangle)
-    return VTKCellType::VTK_LAGRANGE_TRIANGLE;
-  else if (*this == ReferenceCells::Quadrilateral)
-    return VTKCellType::VTK_LAGRANGE_QUADRILATERAL;
-  else if (*this == ReferenceCells::Tetrahedron)
-    return VTKCellType::VTK_LAGRANGE_TETRAHEDRON;
-  else if (*this == ReferenceCells::Pyramid)
-    return VTKCellType::VTK_LAGRANGE_PYRAMID;
-  else if (*this == ReferenceCells::Wedge)
-    return VTKCellType::VTK_LAGRANGE_WEDGE;
-  else if (*this == ReferenceCells::Hexahedron)
-    return VTKCellType::VTK_LAGRANGE_HEXAHEDRON;
-  else if (*this == ReferenceCells::Invalid)
-    return VTKCellType::VTK_INVALID;
-
-  Assert(false, ExcNotImplemented());
+  switch (this->kind)
+    {
+      case ReferenceCells::Vertex:
+        return VTKCellType::VTK_VERTEX;
+      case ReferenceCells::Line:
+        return VTKCellType::VTK_LAGRANGE_CURVE;
+      case ReferenceCells::Triangle:
+        return VTKCellType::VTK_LAGRANGE_TRIANGLE;
+      case ReferenceCells::Quadrilateral:
+        return VTKCellType::VTK_LAGRANGE_QUADRILATERAL;
+      case ReferenceCells::Tetrahedron:
+        return VTKCellType::VTK_LAGRANGE_TETRAHEDRON;
+      case ReferenceCells::Pyramid:
+        return VTKCellType::VTK_LAGRANGE_PYRAMID;
+      case ReferenceCells::Wedge:
+        return VTKCellType::VTK_LAGRANGE_WEDGE;
+      case ReferenceCells::Hexahedron:
+        return VTKCellType::VTK_LAGRANGE_HEXAHEDRON;
+      case ReferenceCells::Invalid:
+        return VTKCellType::VTK_INVALID;
+      default:
+        Assert(false, ExcNotImplemented());
+    }
 
   return VTKCellType::VTK_INVALID;
 }
@@ -666,42 +672,45 @@ ReferenceCell::vtk_vertex_to_deal_vertex(const unsigned int vertex_index) const
   //
   // For the ordering, see the VTK manual (for example at
   // http://www.princeton.edu/~efeibush/viscourse/vtk.pdf, page 9).
-  if (*this == ReferenceCells::Vertex)
-    return vertex_index;
-  else if (*this == ReferenceCells::Line)
-    return vertex_index;
-  else if (*this == ReferenceCells::Triangle)
-    return vertex_index;
-  else if (*this == ReferenceCells::Quadrilateral)
-    {
-      static constexpr std::array<unsigned int, 4> index_translation_table = {
-        {0, 1, 3, 2}};
-      return index_translation_table[vertex_index];
-    }
-  else if (*this == ReferenceCells::Tetrahedron)
-    return vertex_index;
-  else if (*this == ReferenceCells::Pyramid)
-    {
-      static constexpr std::array<unsigned int, 5> index_translation_table = {
-        {0, 1, 3, 2, 4}};
-      return index_translation_table[vertex_index];
-    }
-  else if (*this == ReferenceCells::Wedge)
-    return vertex_index;
-  else if (*this == ReferenceCells::Hexahedron)
-    {
-      static constexpr std::array<unsigned int, 8> index_translation_table = {
-        {0, 1, 3, 2, 4, 5, 7, 6}};
-      return index_translation_table[vertex_index];
-    }
-  else if (*this == ReferenceCells::Invalid)
-    {
-      Assert(false, ExcNotImplemented());
-      return numbers::invalid_unsigned_int;
+  switch (this->kind)
+    {
+      case ReferenceCells::Vertex:
+        return vertex_index;
+      case ReferenceCells::Line:
+        return vertex_index;
+      case ReferenceCells::Triangle:
+        return vertex_index;
+      case ReferenceCells::Quadrilateral:
+        {
+          static constexpr std::array<unsigned int, 4> index_translation_table =
+            {{0, 1, 3, 2}};
+          return index_translation_table[vertex_index];
+        }
+      case ReferenceCells::Tetrahedron:
+        return vertex_index;
+      case ReferenceCells::Pyramid:
+        {
+          static constexpr std::array<unsigned int, 5> index_translation_table =
+            {{0, 1, 3, 2, 4}};
+          return index_translation_table[vertex_index];
+        }
+      case ReferenceCells::Wedge:
+        return vertex_index;
+      case ReferenceCells::Hexahedron:
+        {
+          static constexpr std::array<unsigned int, 8> index_translation_table =
+            {{0, 1, 3, 2, 4, 5, 7, 6}};
+          return index_translation_table[vertex_index];
+        }
+      case ReferenceCells::Invalid:
+        {
+          Assert(false, ExcNotImplemented());
+          return numbers::invalid_unsigned_int;
+        }
+      default:
+        Assert(false, ExcNotImplemented());
     }
 
-  Assert(false, ExcNotImplemented());
-
   return numbers::invalid_unsigned_int;
 }
 
@@ -763,30 +772,29 @@ ReferenceCell::gmsh_element_type() const
     15 Point (1 node).
   */
 
-  if (*this == ReferenceCells::Vertex)
-    return 15;
-  else if (*this == ReferenceCells::Line)
-    return 1;
-  else if (*this == ReferenceCells::Triangle)
-    return 2;
-  else if (*this == ReferenceCells::Quadrilateral)
-    return 3;
-  else if (*this == ReferenceCells::Tetrahedron)
-    return 4;
-  else if (*this == ReferenceCells::Pyramid)
-    return 7;
-  else if (*this == ReferenceCells::Wedge)
-    return 6;
-  else if (*this == ReferenceCells::Hexahedron)
-    return 5;
-  else if (*this == ReferenceCells::Invalid)
-    {
-      Assert(false, ExcNotImplemented());
-      return numbers::invalid_unsigned_int;
+  switch (this->kind)
+    {
+      case ReferenceCells::Vertex:
+        return 15;
+      case ReferenceCells::Line:
+        return 1;
+      case ReferenceCells::Triangle:
+        return 2;
+      case ReferenceCells::Quadrilateral:
+        return 3;
+      case ReferenceCells::Tetrahedron:
+        return 4;
+      case ReferenceCells::Pyramid:
+        return 7;
+      case ReferenceCells::Wedge:
+        return 6;
+      case ReferenceCells::Hexahedron:
+        return 5;
+      case ReferenceCells::Invalid:
+      default:
+        Assert(false, ExcNotImplemented());
     }
 
-  Assert(false, ExcNotImplemented());
-
   return numbers::invalid_unsigned_int;
 }
 

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.