Skip to content

Commit 956b42c

Browse files
committed
Add Elem::n_nodes_on_edge
1 parent f684515 commit 956b42c

26 files changed

+158
-0
lines changed

include/geom/cell_hex20.h

+6
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ class Hex20 final : public Hex
249249
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
250250
{ return this->_n_nodes_on_side_constant<Hex20>(s); }
251251

252+
/**
253+
* \returns 3. Every edge has two nodes.
254+
*/
255+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
256+
{ return this->_n_nodes_on_edge_constant<Hex20>(e); }
257+
252258
protected:
253259

254260
/**

include/geom/cell_hex27.h

+6
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ class Hex27 final : public Hex
267267
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
268268
{ return this->_n_nodes_on_side_constant<Hex27>(s); }
269269

270+
/**
271+
* \returns 3. Every edge has three nodes.
272+
*/
273+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
274+
{ return this->_n_nodes_on_edge_constant<Hex27>(e); }
275+
270276
protected:
271277

272278

include/geom/cell_hex8.h

+6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ class Hex8 final : public Hex
224224
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
225225
{ return this->_n_nodes_on_side_constant<Hex8>(s); }
226226

227+
/**
228+
* \returns 2. Every edge has two nodes.
229+
*/
230+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
231+
{ return this->_n_nodes_on_edge_constant<Hex8>(e); }
232+
227233
protected:
228234

229235
/**

include/geom/cell_inf_hex16.h

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ class InfHex16 final : public InfHex
244244
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
245245
{ return this->_n_nodes_on_side<InfHex16, 2>(s); }
246246

247+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
248+
{ return this->_n_nodes_on_edge_constant<InfHex16>(e) - ((e < 4) ? 0 : 1); }
249+
247250
protected:
248251

249252
/**

include/geom/cell_inf_hex18.h

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ class InfHex18 final : public InfHex
259259
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
260260
{ return this->_n_nodes_on_side<InfHex18, 3>(s); }
261261

262+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
263+
{ return this->_n_nodes_on_edge_constant<InfHex18>(e) - ((e < 4) ? 0 : 1); }
264+
262265
protected:
263266

264267
/**

include/geom/cell_inf_hex8.h

+6
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ class InfHex8 final : public InfHex
197197
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
198198
{ return this->_n_nodes_on_side_constant<InfHex8>(s); }
199199

200+
/**
201+
* \returns 2. Every edge has two nodes.
202+
*/
203+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
204+
{ return this->_n_nodes_on_edge_constant<InfHex8>(e); }
205+
200206
protected:
201207

202208
/**

include/geom/cell_inf_prism12.h

+3
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ class InfPrism12 final : public InfPrism
235235
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
236236
{ return this->_n_nodes_on_side_constant<InfPrism12>(s); }
237237

238+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
239+
{ return this->_n_nodes_on_edge_constant<InfPrism12>(e) - ((e < 3) ? 0 : 1); }
240+
238241
protected:
239242

240243
/**

include/geom/cell_inf_prism6.h

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ class InfPrism6 final : public InfPrism
193193
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
194194
{ return this->_n_nodes_on_side_constant<InfPrism6>(s) - ((s == 0) ? 1 : 0); }
195195

196+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
197+
{ return this->_n_nodes_on_edge_constant<InfPrism6>(e); }
198+
196199
protected:
197200

198201
/**

include/geom/cell_prism15.h

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ class Prism15 final : public Prism
251251
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
252252
{ return _n_nodes_on_side<Prism15, 2>(s); }
253253

254+
/**
255+
* \returns 3. Every edge has three nodes.
256+
*/
257+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
258+
{ return this->_n_nodes_on_edge_constant<Prism15>(e); }
259+
254260
protected:
255261

256262
/**

include/geom/cell_prism18.h

+6
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ class Prism18 final : public Prism
269269
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
270270
{ return _n_nodes_on_side<Prism18, 3>(s); }
271271

272+
/**
273+
* \returns 3. Every edge has three nodes.
274+
*/
275+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
276+
{ return this->_n_nodes_on_edge_constant<Prism18>(e); }
277+
272278
protected:
273279

274280
/**

include/geom/cell_prism20.h

+6
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ class Prism20 final : public Prism
268268
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
269269
{ return _n_nodes_on_side<Prism20, 2>(s); }
270270

271+
/**
272+
* \returns 3. Every edge has three nodes.
273+
*/
274+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
275+
{ return this->_n_nodes_on_edge_constant<Prism20>(e); }
276+
271277
protected:
272278

273279
/**

include/geom/cell_prism21.h

+6
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ class Prism21 final : public Prism
271271
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
272272
{ return _n_nodes_on_side<Prism21, 2>(s); }
273273

274+
/**
275+
* \returns 3. Every edge has three nodes.
276+
*/
277+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
278+
{ return this->_n_nodes_on_edge_constant<Prism21>(e); }
279+
274280
protected:
275281

276282
/**

include/geom/cell_prism6.h

+6
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ class Prism6 final : public Prism
211211
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
212212
{ return _n_nodes_on_side<Prism6, 1>(s); }
213213

214+
/**
215+
* \returns 2. Every edge has two nodes.
216+
*/
217+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
218+
{ return this->_n_nodes_on_edge_constant<Prism6>(e); }
219+
214220
protected:
215221

216222
/**

include/geom/cell_pyramid13.h

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ class Pyramid13 final : public Pyramid
239239
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
240240
{ return _n_nodes_on_side<Pyramid13, 2>(s); }
241241

242+
/**
243+
* \returns 3. Every edge has three nodes.
244+
*/
245+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
246+
{ return this->_n_nodes_on_edge_constant<Pyramid13>(e); }
247+
242248
protected:
243249

244250
/**

include/geom/cell_pyramid14.h

+6
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ class Pyramid14 final : public Pyramid
260260
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
261261
{ return _n_nodes_on_side<Pyramid14, 3>(s); }
262262

263+
/**
264+
* \returns 3. Every edge has three nodes.
265+
*/
266+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
267+
{ return this->_n_nodes_on_edge_constant<Pyramid14>(e); }
268+
263269
protected:
264270

265271
/**

include/geom/cell_pyramid5.h

+6
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ class Pyramid5 final : public Pyramid
204204
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
205205
{ return _n_nodes_on_side<Pyramid5, 1>(s); }
206206

207+
/**
208+
* \returns 2. Every edge has two nodes.
209+
*/
210+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
211+
{ return this->_n_nodes_on_edge_constant<Pyramid5>(e); }
212+
207213
protected:
208214

209215
/**

include/geom/cell_tet10.h

+6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ class Tet10 final : public Tet
250250
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
251251
{ return this->_n_nodes_on_side_constant<Tet10>(s); }
252252

253+
/**
254+
* \returns 3. Every edge has three nodes.
255+
*/
256+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
257+
{ return this->_n_nodes_on_edge_constant<Tet10>(e); }
258+
253259
protected:
254260

255261
/**

include/geom/cell_tet14.h

+6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ class Tet14 final : public Tet
250250
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
251251
{ return this->_n_nodes_on_side_constant<Tet14>(s); }
252252

253+
/**
254+
* \returns 3. Every edge has three nodes.
255+
*/
256+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
257+
{ return this->_n_nodes_on_edge_constant<Tet14>(e); }
258+
253259
#ifdef LIBMESH_ENABLE_AMR
254260
virtual
255261
const std::vector<std::pair<unsigned char, unsigned char>> &

include/geom/cell_tet4.h

+6
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ class Tet4 final : public Tet
257257
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
258258
{ return this->_n_nodes_on_side_constant<Tet4>(s); }
259259

260+
/**
261+
* \returns 2. Every edge has two nodes.
262+
*/
263+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
264+
{ return this->_n_nodes_on_edge_constant<Tet4>(e); }
265+
260266
protected:
261267

262268
/**

include/geom/edge.h

+6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ class Edge : public Elem
237237
virtual unsigned int n_nodes_on_side(const unsigned short libmesh_dbg_var(s)) const override final
238238
{ libmesh_assert_less(s, 2); return 1; }
239239

240+
/**
241+
* The \p Elem::n_nodes_on_edge() member makes no sense for edges.
242+
*/
243+
virtual unsigned int n_nodes_on_edge(const unsigned short) const override final
244+
{ libmesh_not_implemented(); return 0; }
245+
240246
protected:
241247

242248
/**

include/geom/elem.h

+19
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ class Elem : public ReferenceCountedObject<Elem>,
677677
*/
678678
virtual unsigned int n_edges () const = 0;
679679

680+
/**
681+
* \returns The number of nodes on the edge with index \p e.
682+
*/
683+
virtual unsigned int n_nodes_on_edge (const unsigned short) const = 0;
684+
680685
/**
681686
* \returns An integer range from 0 up to (but not including)
682687
* the number of edges this element has.
@@ -2023,6 +2028,20 @@ class Elem : public ReferenceCountedObject<Elem>,
20232028
return ElemClass::nodes_per_side;
20242029
}
20252030

2031+
/**
2032+
* Helper for overriding n_nodes_per_edge in derived classes.
2033+
*
2034+
* Performs bound checking on \p s and returns nodes_per_edge
2035+
* for the given class for all edges.
2036+
*/
2037+
template <class ElemClass>
2038+
unsigned int _n_nodes_on_edge_constant(const unsigned short libmesh_dbg_var(s)) const
2039+
{
2040+
static_assert(std::is_base_of<Elem, ElemClass>::value, "Not an Elem");
2041+
libmesh_assert_less(s, this->n_edges());
2042+
return ElemClass::nodes_per_edge;
2043+
}
2044+
20262045
/**
20272046
* Helper for overriding nodes_on_side in derived classes.
20282047
*/

include/geom/face.h

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class Face : public Elem
7272
virtual unsigned int n_vertices_on_side(const unsigned short libmesh_dbg_var(s)) const override final
7373
{ libmesh_assert_less(s, this->n_sides()); return 2; }
7474

75+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
76+
{ return this->n_nodes_on_side(e); }
77+
7578
/**
7679
* build_side and build_edge are identical for faces.
7780
*/

include/geom/face_inf_quad.h

+3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ class InfQuad : public Elem
239239

240240
virtual void orient(BoundaryInfo *) override final;
241241

242+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
243+
{ return this->n_nodes_on_side(e); }
244+
242245
protected:
243246

244247
/**

include/geom/node_elem.h

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class NodeElem : public Elem
8383
virtual unsigned int n_nodes_on_side(const unsigned short) const override
8484
{ libmesh_not_implemented(); return 0; }
8585

86+
/**
87+
* The \p Elem::n_nodes_on_edge makes no sense for nodes.
88+
*/
89+
virtual unsigned int n_nodes_on_edge(const unsigned short) const override
90+
{ libmesh_not_implemented(); return 0; }
91+
8692
/**
8793
* The \p Elem::nodes_on_side_ptr makes no sense for nodes.
8894
*/

include/geom/remote_elem.h

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class RemoteElem : public Elem,
122122
virtual unsigned int n_nodes_on_side (const unsigned short) const override
123123
{ libmesh_not_implemented(); return 0; }
124124

125+
virtual unsigned int n_nodes_on_edge (const unsigned short) const override
126+
{ libmesh_not_implemented(); return 0; }
127+
125128
virtual unsigned int n_sides () const override
126129
{ libmesh_not_implemented(); return 0; }
127130

tests/geom/elem_test.C

+16
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,21 @@ public:
503503
}
504504
};
505505

506+
void test_n_nodes_on_edge()
507+
{
508+
LOG_UNIT_TEST;
509+
510+
for (const auto & elem : _mesh->active_local_element_ptr_range())
511+
for (const auto e : elem->edge_index_range())
512+
{
513+
unsigned int n_nodes_on_edge = 0;
514+
for (const auto n : elem->node_index_range())
515+
if (elem->is_node_on_edge(n, e))
516+
++n_nodes_on_edge;
517+
CPPUNIT_ASSERT_EQUAL(n_nodes_on_edge, elem->n_nodes_on_edge(e));
518+
}
519+
};
520+
506521
void test_n_vertices_on_side()
507522
{
508523
LOG_UNIT_TEST;
@@ -566,6 +581,7 @@ public:
566581
CPPUNIT_TEST( test_center_node_on_side ); \
567582
CPPUNIT_TEST( test_side_type ); \
568583
CPPUNIT_TEST( test_n_nodes_on_side ); \
584+
CPPUNIT_TEST( test_n_nodes_on_edge ); \
569585
CPPUNIT_TEST( test_n_vertices_on_side ); \
570586
CPPUNIT_TEST( test_nodes_on_side_ptr ); \
571587
CPPUNIT_TEST( test_elem_side_builder );

0 commit comments

Comments
 (0)