]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement ReferenceCell::vertex().
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 13 Oct 2021 23:26:29 +0000 (17:26 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 14 Oct 2021 13:53:38 +0000 (07:53 -0600)
include/deal.II/grid/reference_cell.h

index 20f02a614d515bde8de28e5ba6c4bbf820007666..025abf9e67889f8f1a3d494925c1604927625a34 100644 (file)
@@ -21,6 +21,7 @@
 #include <deal.II/base/array_view.h>
 #include <deal.II/base/geometry_info.h>
 #include <deal.II/base/ndarray.h>
+#include <deal.II/base/point.h>
 #include <deal.II/base/tensor.h>
 #include <deal.II/base/utilities.h>
 
@@ -234,6 +235,17 @@ public:
   std_cxx20::ranges::iota_view<unsigned int, unsigned int>
   vertex_indices() const;
 
+  /**
+   * Return the location of the `v`th vertex of the reference
+   * cell that corresponds to the current object.
+   *
+   * Because the ReferenceCell class does not have a `dim` argument,
+   * it has to be explicitly specified in the call to this function.
+   */
+  template <int dim>
+  Point<dim>
+  vertex(const unsigned int v) const;
+
   /**
    * Return the number of lines that make up the reference
    * cell in question. A line is an "edge" (a one-dimensional
@@ -850,6 +862,61 @@ ReferenceCell::n_lines() const
 
 
 
+template <int dim>
+Point<dim>
+ReferenceCell::vertex(const unsigned int v) const
+{
+  AssertDimension(dim, get_dimension());
+  AssertIndexRange(v, n_vertices());
+
+  if (*this == ReferenceCells::get_hypercube<dim>())
+    {
+      return GeometryInfo<dim>::unit_cell_vertex(v);
+    }
+  else if ((dim == 2) && (*this == ReferenceCells::Triangle))
+    {
+      static const Point<dim> vertices[3] = {
+        Point<dim>(),               // the origin
+        Point<dim>::unit_vector(0), // unit point along x-axis
+        Point<dim>::unit_vector(1)  // unit point along y-axis
+      };
+      return vertices[v];
+    }
+  else if ((dim == 3) && (*this == ReferenceCells::Tetrahedron))
+    {
+      static const Point<dim> vertices[4] = {Point<dim>{0.0, 0.0, 0.0},
+                                             Point<dim>{1.0, 0.0, 0.0},
+                                             Point<dim>{0.0, 1.0, 0.0},
+                                             Point<dim>{0.0, 0.0, 1.0}};
+      return vertices[v];
+    }
+  else if ((dim == 3) && (*this == ReferenceCells::Pyramid))
+    {
+      static const Point<dim> vertices[5] = {Point<dim>{-1.0, -1.0, 0.0},
+                                             Point<dim>{+1.0, -1.0, 0.0},
+                                             Point<dim>{-1.0, +1.0, 0.0},
+                                             Point<dim>{+1.0, +1.0, 0.0},
+                                             Point<dim>{+0.0, +0.0, 1.0}};
+      return vertices[v];
+    }
+  else if ((dim == 3) && (*this == ReferenceCells::Wedge))
+    {
+      static const Point<dim> vertices[6] = {Point<dim>{1.0, 0.0, 0.0},
+                                             Point<dim>{0.0, 1.0, 0.0},
+                                             Point<dim>{0.0, 0.0, 0.0},
+                                             Point<dim>{1.0, 0.0, 1.0},
+                                             Point<dim>{0.0, 1.0, 1.0},
+                                             Point<dim>{0.0, 0.0, 1.0}};
+      return vertices[v];
+    }
+  else
+    {
+      Assert(false, ExcNotImplemented());
+      return Point<dim>();
+    }
+}
+
+
 inline unsigned int
 ReferenceCell::n_faces() const
 {

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.