Skip to content

Commit

Permalink
Add Elem::n_vertices_per_side()
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Nov 8, 2022
1 parent bb0d86d commit 954baa6
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/geom/cell_hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Hex : public Cell
*/
virtual unsigned int n_vertices() const override final { return 8; }

/**
* \returns 4. Every side has four vertices.
*/
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
{ libmesh_assert_less(s, this->n_sides()); return 4; }

/**
* \returns 12. All hexahedra have 12 edges.
*/
Expand Down
6 changes: 6 additions & 0 deletions include/geom/cell_inf_hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class InfHex : public InfCell
*/
virtual unsigned int n_vertices() const override final { return 8; }

/**
* \returns 4. Every side has four vertices.
*/
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
{ libmesh_assert_less(s, this->n_sides()); return 4; }

/**
* \returns \p true if the specified (local) node number is a
* "mid-edge" node on an infinite element edge.
Expand Down
3 changes: 3 additions & 0 deletions include/geom/cell_inf_prism.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class InfPrism : public InfCell
*/
virtual unsigned int n_vertices() const override final { return 6; }

virtual unsigned int n_vertices_on_side(const unsigned short s) const override final
{ libmesh_assert_less(s, this->n_sides()); return 4 - (s == 0 || s == 4); }

/**
* \returns 6. All infinite prisms have 6 edges,
* 3 lying in the base, and 3 perpendicular to the base.
Expand Down
3 changes: 3 additions & 0 deletions include/geom/cell_prism.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Prism : public Cell
*/
virtual unsigned int n_vertices() const override final { return 6; }

virtual unsigned int n_vertices_on_side(const unsigned short s) const override final
{ libmesh_assert_less(s, this->n_sides()); return 4 - (s == 0 || s == 4); }

/**
* \returns 9. All prisms have 9 edges.
*/
Expand Down
3 changes: 3 additions & 0 deletions include/geom/cell_pyramid.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Pyramid : public Cell
*/
virtual unsigned int n_vertices() const override { return 5; }

virtual unsigned int n_vertices_on_side(const unsigned short s) const override final
{ libmesh_assert_less(s, this->n_sides()); return 4 - (s != 4); }

/**
* \returns 8. All pyramids have 8 edges.
*/
Expand Down
6 changes: 6 additions & 0 deletions include/geom/cell_tet.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class Tet : public Cell
*/
virtual unsigned int n_vertices() const override final { return 4; }

/**
* \returns 3. Every side has three vertices.
*/
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
{ libmesh_assert_less(s, this->n_sides()); return 3; }

/**
* \returns 6. All tetrahedra have 6 edges.
*/
Expand Down
6 changes: 6 additions & 0 deletions include/geom/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class Edge : public Elem
*/
virtual unsigned int n_vertices() const override final { return 2; }

/**
* \returns 1. Every side has one vertex.
*/
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
{ libmesh_assert_less(s, this->n_sides()); return 1; }

/**
* \returns 0. All 1D elements have no edges.
*/
Expand Down
18 changes: 18 additions & 0 deletions include/geom/elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,12 @@ class Elem : public ReferenceCountedObject<Elem>,
*/
IntRange<unsigned short> side_index_range () const;

/**
* \returns An integer range from 0 up to (but not including)
* the number of vertices this element has.
*/
IntRange<unsigned short> vertex_index_range () const;

/**
* \returns The number of neighbors the element that has been derived
* from this class has.
Expand All @@ -659,6 +665,11 @@ class Elem : public ReferenceCountedObject<Elem>,
*/
virtual unsigned int n_vertices () const = 0;

/**
* \returns The number of verticies on the side with index \p s.
*/
virtual unsigned int n_vertices_on_side (const unsigned short s) const = 0;

/**
* \returns The number of edges the element that has been derived
* from this class has.
Expand Down Expand Up @@ -2427,6 +2438,13 @@ Elem::side_index_range() const



inline
IntRange<unsigned short>
Elem::vertex_index_range() const
{
return {0, cast_int<unsigned short>(this->n_vertices())};
}


inline
std::unique_ptr<const Elem> Elem::side_ptr (unsigned int i) const
Expand Down
6 changes: 6 additions & 0 deletions include/geom/face.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class Face : public Elem
*/
virtual unsigned int n_faces() const override final { return 0; }

/**
* \returns 2. Every side has two vertices.
*/
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
{ libmesh_assert_less(s, this->n_sides()); return 2; }

/**
* build_side and build_edge are identical for faces.
*/
Expand Down
6 changes: 6 additions & 0 deletions include/geom/face_inf_quad.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class InfQuad : public Elem
*/
virtual unsigned int n_vertices() const override final { return 4; }

/**
* \returns 2. Every side has two vertices.
*/
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
{ libmesh_assert_less(s, this->n_sides()); return 2; }

/**
* \returns 3. All infinite quads have 1 edge in the
* base, and 2 perpendicular to the base.
Expand Down
6 changes: 6 additions & 0 deletions include/geom/node_elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class NodeElem : public Elem
*/
virtual unsigned int n_vertices() const override { return 1; }

/**
* The \p Elem::n_vertices_on_side makes no sense for nodes.
*/
virtual unsigned int n_vertices_on_side(const unsigned short) const override
{ libmesh_not_implemented(); return 0; }

/**
* \returns 0.
*/
Expand Down
3 changes: 3 additions & 0 deletions include/geom/remote_elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class RemoteElem : public Elem,
virtual unsigned int n_vertices () const override
{ libmesh_not_implemented(); return 0; }

virtual unsigned int n_vertices_on_side(const unsigned short) const override
{ libmesh_not_implemented(); return 0; }

virtual unsigned int n_edges () const override
{ libmesh_not_implemented(); return 0; }

Expand Down
16 changes: 16 additions & 0 deletions tests/geom/elem_test.C
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,21 @@ public:
CPPUNIT_ASSERT_EQUAL(elem->build_side_ptr(s)->type(), elem->side_type(s));
}

void test_n_vertices_on_side()
{
LOG_UNIT_TEST;

for (const auto & elem : _mesh->active_local_element_ptr_range())
for (const auto s : elem->side_index_range())
{
unsigned int n_vertices_on_side = 0;
for (const auto v : elem->vertex_index_range())
if (elem->is_node_on_side(v, s))
++n_vertices_on_side;
CPPUNIT_ASSERT_EQUAL(n_vertices_on_side, elem->n_vertices_on_side(s));
}
};

void test_elem_side_builder()
{
LOG_UNIT_TEST;
Expand Down Expand Up @@ -331,6 +346,7 @@ public:
CPPUNIT_TEST( test_contains_point_node ); \
CPPUNIT_TEST( test_center_node_on_side ); \
CPPUNIT_TEST( test_side_type ); \
CPPUNIT_TEST( test_n_vertices_on_side ); \
CPPUNIT_TEST( test_elem_side_builder );

#define INSTANTIATE_ELEMTEST(elemtype) \
Expand Down

0 comments on commit 954baa6

Please sign in to comment.