Skip to content

Commit

Permalink
ReferenceCell: consolidate some tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
drwells committed Jan 22, 2023
1 parent 34a2faf commit 178a92f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 124 deletions.
199 changes: 75 additions & 124 deletions include/deal.II/grid/reference_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,37 @@ class ReferenceCell
*/
constexpr ReferenceCell(const std::uint8_t kind);

/**
* Table containing all vertex permutations for a line.
*/
static constexpr ndarray<unsigned int, 2, 2> line_vertex_permutations = {
{{{1, 0}}, {{0, 1}}}};


/**
* Table containing all vertex permutations for a triangle.
*/
static constexpr ndarray<unsigned int, 6, 3> triangle_vertex_permutations = {
{{{0, 2, 1}},
{{0, 1, 2}},
{{2, 1, 0}},
{{1, 2, 0}},
{{1, 0, 2}},
{{2, 0, 1}}}};

/**
* Table containing all vertex permutations for a quadrilateral.
*/
static constexpr ndarray<unsigned int, 8, 4>
quadrilateral_vertex_permutations = {{{{0, 2, 1, 3}},
{{0, 1, 2, 3}},
{{2, 3, 0, 1}},
{{2, 0, 3, 1}},
{{3, 1, 2, 0}},
{{3, 2, 1, 0}},
{{1, 0, 3, 2}},
{{1, 3, 0, 2}}}};

/**
* A kind of constructor -- not quite private because it can be
* called by anyone, but at least hidden in an internal namespace.
Expand Down Expand Up @@ -1865,80 +1896,23 @@ ReferenceCell::standard_to_real_face_vertex(
break;
case ReferenceCells::Triangle:
case ReferenceCells::Quadrilateral:
{
static constexpr ndarray<unsigned int, 2, 2> table = {
{{{1, 0}}, {{0, 1}}}};

return table[face_orientation][vertex];
}
return line_vertex_permutations[face_orientation][vertex];
case ReferenceCells::Tetrahedron:
{
static constexpr ndarray<unsigned int, 6, 3> table = {{{{0, 2, 1}},
{{0, 1, 2}},
{{2, 1, 0}},
{{1, 2, 0}},
{{1, 0, 2}},
{{2, 0, 1}}}};

return table[face_orientation][vertex];
}
return triangle_vertex_permutations[face_orientation][vertex];
case ReferenceCells::Pyramid:
{
if (face == 0) // The quadrilateral face
{
return GeometryInfo<3>::standard_to_real_face_vertex(
vertex,
Utilities::get_bit(face_orientation, 0),
Utilities::get_bit(face_orientation, 2),
Utilities::get_bit(face_orientation, 1));
}
else // One of the triangular faces
{
static const ndarray<unsigned int, 6, 3> table = {{{{0, 2, 1}},
{{0, 1, 2}},
{{2, 1, 0}},
{{1, 2, 0}},
{{1, 0, 2}},
{{2, 0, 1}}}};

return table[face_orientation][vertex];
}
}
// face 0 is a quadrilateral
if (face == 0)
return quadrilateral_vertex_permutations[face_orientation][vertex];
else
return triangle_vertex_permutations[face_orientation][vertex];
case ReferenceCells::Wedge:
{
if (face > 1) // One of the quadrilateral faces
{
return GeometryInfo<3>::standard_to_real_face_vertex(
vertex,
Utilities::get_bit(face_orientation, 0),
Utilities::get_bit(face_orientation, 2),
Utilities::get_bit(face_orientation, 1));
}
else // One of the triangular faces
{
static const ndarray<unsigned int, 6, 3> table = {{{{0, 2, 1}},
{{0, 1, 2}},
{{2, 1, 0}},
{{1, 2, 0}},
{{1, 0, 2}},
{{2, 0, 1}}}};

return table[face_orientation][vertex];
}
}
// faces 0 and 1 are triangles
if (face > 1)
return quadrilateral_vertex_permutations[face_orientation][vertex];
else
return triangle_vertex_permutations[face_orientation][vertex];
case ReferenceCells::Hexahedron:
{
static constexpr ndarray<unsigned int, 8, 4> table = {
{{{0, 2, 1, 3}},
{{0, 1, 2, 3}},
{{2, 3, 0, 1}},
{{2, 0, 3, 1}},
{{3, 1, 2, 0}},
{{3, 2, 1, 0}},
{{1, 0, 3, 2}},
{{1, 3, 0, 2}}}};
return table[face_orientation][vertex];
}
return quadrilateral_vertex_permutations[face_orientation][vertex];
default:
Assert(false, ExcNotImplemented());
}
Expand All @@ -1958,6 +1932,14 @@ ReferenceCell::standard_to_real_face_line(
AssertIndexRange(face, n_faces());
AssertIndexRange(line, face_reference_cell(face).n_lines());

static constexpr ndarray<unsigned int, 6, 3> triangle_table = {{{{2, 1, 0}},
{{0, 1, 2}},
{{1, 0, 2}},
{{1, 2, 0}},
{{0, 2, 1}},
{{2, 0, 1}}}};


switch (this->kind)
{
case ReferenceCells::Vertex:
Expand All @@ -1967,62 +1949,31 @@ ReferenceCell::standard_to_real_face_line(
Assert(false, ExcNotImplemented());
break;
case ReferenceCells::Tetrahedron:
{
static constexpr ndarray<unsigned int, 6, 3> table = {{{{2, 1, 0}},
{{0, 1, 2}},
{{1, 0, 2}},
{{1, 2, 0}},
{{0, 2, 1}},
{{2, 0, 1}}}};

return table[face_orientation][line];
}
return triangle_table[face_orientation][line];
case ReferenceCells::Pyramid:
{
if (face == 0) // The quadrilateral face
{
return GeometryInfo<3>::standard_to_real_face_line(
line,
Utilities::get_bit(face_orientation, 0),
Utilities::get_bit(face_orientation, 2),
Utilities::get_bit(face_orientation, 1));
}
else // One of the triangular faces
{
static constexpr ndarray<unsigned int, 6, 3> table = {
{{{2, 1, 0}},
{{0, 1, 2}},
{{1, 0, 2}},
{{1, 2, 0}},
{{0, 2, 1}},
{{2, 0, 1}}}};

return table[face_orientation][line];
}
}
if (face == 0) // The quadrilateral face
{
return GeometryInfo<3>::standard_to_real_face_line(
line,
Utilities::get_bit(face_orientation, 0),
Utilities::get_bit(face_orientation, 2),
Utilities::get_bit(face_orientation, 1));
}
else // One of the triangular faces
{
return triangle_table[face_orientation][line];
}
case ReferenceCells::Wedge:
{
if (face > 1) // One of the quadrilateral faces
{
return GeometryInfo<3>::standard_to_real_face_line(
line,
Utilities::get_bit(face_orientation, 0),
Utilities::get_bit(face_orientation, 2),
Utilities::get_bit(face_orientation, 1));
}
else // One of the triangular faces
{
static constexpr ndarray<unsigned int, 6, 3> table = {
{{{2, 1, 0}},
{{0, 1, 2}},
{{1, 0, 2}},
{{1, 2, 0}},
{{0, 2, 1}},
{{2, 0, 1}}}};

return table[face_orientation][line];
}
}
if (face > 1) // One of the quadrilateral faces
{
return GeometryInfo<3>::standard_to_real_face_line(
line,
Utilities::get_bit(face_orientation, 0),
Utilities::get_bit(face_orientation, 2),
Utilities::get_bit(face_orientation, 1));
}
else // One of the triangular faces
return triangle_table[face_orientation][line];
case ReferenceCells::Hexahedron:
{
static constexpr ndarray<unsigned int, 8, 4> table = {
Expand Down
7 changes: 7 additions & 0 deletions source/grid/reference_cell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ namespace

} // namespace

constexpr ndarray<unsigned int, 2, 2> ReferenceCell::line_vertex_permutations;

constexpr ndarray<unsigned int, 6, 3>
ReferenceCell::triangle_vertex_permutations;

constexpr ndarray<unsigned int, 8, 4>
ReferenceCell::quadrilateral_vertex_permutations;

std::string
ReferenceCell::to_string() const
Expand Down

0 comments on commit 178a92f

Please sign in to comment.