Skip to content

Commit 954baa6

Browse files
committed
Add Elem::n_vertices_per_side()
1 parent bb0d86d commit 954baa6

13 files changed

+88
-0
lines changed

include/geom/cell_hex.h

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class Hex : public Cell
7777
*/
7878
virtual unsigned int n_vertices() const override final { return 8; }
7979

80+
/**
81+
* \returns 4. Every side has four vertices.
82+
*/
83+
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
84+
{ libmesh_assert_less(s, this->n_sides()); return 4; }
85+
8086
/**
8187
* \returns 12. All hexahedra have 12 edges.
8288
*/

include/geom/cell_inf_hex.h

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ class InfHex : public InfCell
9090
*/
9191
virtual unsigned int n_vertices() const override final { return 8; }
9292

93+
/**
94+
* \returns 4. Every side has four vertices.
95+
*/
96+
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
97+
{ libmesh_assert_less(s, this->n_sides()); return 4; }
98+
9399
/**
94100
* \returns \p true if the specified (local) node number is a
95101
* "mid-edge" node on an infinite element edge.

include/geom/cell_inf_prism.h

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class InfPrism : public InfCell
8686
*/
8787
virtual unsigned int n_vertices() const override final { return 6; }
8888

89+
virtual unsigned int n_vertices_on_side(const unsigned short s) const override final
90+
{ libmesh_assert_less(s, this->n_sides()); return 4 - (s == 0 || s == 4); }
91+
8992
/**
9093
* \returns 6. All infinite prisms have 6 edges,
9194
* 3 lying in the base, and 3 perpendicular to the base.

include/geom/cell_prism.h

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class Prism : public Cell
8383
*/
8484
virtual unsigned int n_vertices() const override final { return 6; }
8585

86+
virtual unsigned int n_vertices_on_side(const unsigned short s) const override final
87+
{ libmesh_assert_less(s, this->n_sides()); return 4 - (s == 0 || s == 4); }
88+
8689
/**
8790
* \returns 9. All prisms have 9 edges.
8891
*/

include/geom/cell_pyramid.h

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class Pyramid : public Cell
8787
*/
8888
virtual unsigned int n_vertices() const override { return 5; }
8989

90+
virtual unsigned int n_vertices_on_side(const unsigned short s) const override final
91+
{ libmesh_assert_less(s, this->n_sides()); return 4 - (s != 4); }
92+
9093
/**
9194
* \returns 8. All pyramids have 8 edges.
9295
*/

include/geom/cell_tet.h

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class Tet : public Cell
7878
*/
7979
virtual unsigned int n_vertices() const override final { return 4; }
8080

81+
/**
82+
* \returns 3. Every side has three vertices.
83+
*/
84+
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
85+
{ libmesh_assert_less(s, this->n_sides()); return 3; }
86+
8187
/**
8288
* \returns 6. All tetrahedra have 6 edges.
8389
*/

include/geom/edge.h

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class Edge : public Elem
7878
*/
7979
virtual unsigned int n_vertices() const override final { return 2; }
8080

81+
/**
82+
* \returns 1. Every side has one vertex.
83+
*/
84+
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
85+
{ libmesh_assert_less(s, this->n_sides()); return 1; }
86+
8187
/**
8288
* \returns 0. All 1D elements have no edges.
8389
*/

include/geom/elem.h

+18
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ class Elem : public ReferenceCountedObject<Elem>,
641641
*/
642642
IntRange<unsigned short> side_index_range () const;
643643

644+
/**
645+
* \returns An integer range from 0 up to (but not including)
646+
* the number of vertices this element has.
647+
*/
648+
IntRange<unsigned short> vertex_index_range () const;
649+
644650
/**
645651
* \returns The number of neighbors the element that has been derived
646652
* from this class has.
@@ -659,6 +665,11 @@ class Elem : public ReferenceCountedObject<Elem>,
659665
*/
660666
virtual unsigned int n_vertices () const = 0;
661667

668+
/**
669+
* \returns The number of verticies on the side with index \p s.
670+
*/
671+
virtual unsigned int n_vertices_on_side (const unsigned short s) const = 0;
672+
662673
/**
663674
* \returns The number of edges the element that has been derived
664675
* from this class has.
@@ -2427,6 +2438,13 @@ Elem::side_index_range() const
24272438

24282439

24292440

2441+
inline
2442+
IntRange<unsigned short>
2443+
Elem::vertex_index_range() const
2444+
{
2445+
return {0, cast_int<unsigned short>(this->n_vertices())};
2446+
}
2447+
24302448

24312449
inline
24322450
std::unique_ptr<const Elem> Elem::side_ptr (unsigned int i) const

include/geom/face.h

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class Face : public Elem
6666
*/
6767
virtual unsigned int n_faces() const override final { return 0; }
6868

69+
/**
70+
* \returns 2. Every side has two vertices.
71+
*/
72+
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
73+
{ libmesh_assert_less(s, this->n_sides()); return 2; }
74+
6975
/**
7076
* build_side and build_edge are identical for faces.
7177
*/

include/geom/face_inf_quad.h

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class InfQuad : public Elem
106106
*/
107107
virtual unsigned int n_vertices() const override final { return 4; }
108108

109+
/**
110+
* \returns 2. Every side has two vertices.
111+
*/
112+
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
113+
{ libmesh_assert_less(s, this->n_sides()); return 2; }
114+
109115
/**
110116
* \returns 3. All infinite quads have 1 edge in the
111117
* base, and 2 perpendicular to the base.

include/geom/node_elem.h

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ class NodeElem : public Elem
8787
*/
8888
virtual unsigned int n_vertices() const override { return 1; }
8989

90+
/**
91+
* The \p Elem::n_vertices_on_side makes no sense for nodes.
92+
*/
93+
virtual unsigned int n_vertices_on_side(const unsigned short) const override
94+
{ libmesh_not_implemented(); return 0; }
95+
9096
/**
9197
* \returns 0.
9298
*/

include/geom/remote_elem.h

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ class RemoteElem : public Elem,
125125
virtual unsigned int n_vertices () const override
126126
{ libmesh_not_implemented(); return 0; }
127127

128+
virtual unsigned int n_vertices_on_side(const unsigned short) const override
129+
{ libmesh_not_implemented(); return 0; }
130+
128131
virtual unsigned int n_edges () const override
129132
{ libmesh_not_implemented(); return 0; }
130133

tests/geom/elem_test.C

+16
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ public:
301301
CPPUNIT_ASSERT_EQUAL(elem->build_side_ptr(s)->type(), elem->side_type(s));
302302
}
303303

304+
void test_n_vertices_on_side()
305+
{
306+
LOG_UNIT_TEST;
307+
308+
for (const auto & elem : _mesh->active_local_element_ptr_range())
309+
for (const auto s : elem->side_index_range())
310+
{
311+
unsigned int n_vertices_on_side = 0;
312+
for (const auto v : elem->vertex_index_range())
313+
if (elem->is_node_on_side(v, s))
314+
++n_vertices_on_side;
315+
CPPUNIT_ASSERT_EQUAL(n_vertices_on_side, elem->n_vertices_on_side(s));
316+
}
317+
};
318+
304319
void test_elem_side_builder()
305320
{
306321
LOG_UNIT_TEST;
@@ -331,6 +346,7 @@ public:
331346
CPPUNIT_TEST( test_contains_point_node ); \
332347
CPPUNIT_TEST( test_center_node_on_side ); \
333348
CPPUNIT_TEST( test_side_type ); \
349+
CPPUNIT_TEST( test_n_vertices_on_side ); \
334350
CPPUNIT_TEST( test_elem_side_builder );
335351

336352
#define INSTANTIATE_ELEMTEST(elemtype) \

0 commit comments

Comments
 (0)