From 724a5f62937f6cacfd0e4951093c56b6f1c17974 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 13 Oct 2021 17:26:29 -0600 Subject: [PATCH] Implement ReferenceCell::vertex(). --- include/deal.II/grid/reference_cell.h | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index 20f02a614d..025abf9e67 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -234,6 +235,17 @@ public: std_cxx20::ranges::iota_view 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 + Point + 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 +Point +ReferenceCell::vertex(const unsigned int v) const +{ + AssertDimension(dim, get_dimension()); + AssertIndexRange(v, n_vertices()); + + if (*this == ReferenceCells::get_hypercube()) + { + return GeometryInfo::unit_cell_vertex(v); + } + else if ((dim == 2) && (*this == ReferenceCells::Triangle)) + { + static const Point vertices[3] = { + Point(), // the origin + Point::unit_vector(0), // unit point along x-axis + Point::unit_vector(1) // unit point along y-axis + }; + return vertices[v]; + } + else if ((dim == 3) && (*this == ReferenceCells::Tetrahedron)) + { + static const Point vertices[4] = {Point{0.0, 0.0, 0.0}, + Point{1.0, 0.0, 0.0}, + Point{0.0, 1.0, 0.0}, + Point{0.0, 0.0, 1.0}}; + return vertices[v]; + } + else if ((dim == 3) && (*this == ReferenceCells::Pyramid)) + { + static const Point vertices[5] = {Point{-1.0, -1.0, 0.0}, + Point{+1.0, -1.0, 0.0}, + Point{-1.0, +1.0, 0.0}, + Point{+1.0, +1.0, 0.0}, + Point{+0.0, +0.0, 1.0}}; + return vertices[v]; + } + else if ((dim == 3) && (*this == ReferenceCells::Wedge)) + { + static const Point vertices[6] = {Point{1.0, 0.0, 0.0}, + Point{0.0, 1.0, 0.0}, + Point{0.0, 0.0, 0.0}, + Point{1.0, 0.0, 1.0}, + Point{0.0, 1.0, 1.0}, + Point{0.0, 0.0, 1.0}}; + return vertices[v]; + } + else + { + Assert(false, ExcNotImplemented()); + return Point(); + } +} + + inline unsigned int ReferenceCell::n_faces() const { -- 2.39.5