Skip to content

Commit 718c60a

Browse files
committed
Add Elem::n_nodes_on_edge
1 parent 3c13146 commit 718c60a

26 files changed

+158
-0
lines changed

include/geom/cell_hex20.h

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

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

252258
/**

include/geom/cell_hex27.h

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

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

270276

include/geom/cell_hex8.h

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

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

227233
/**

include/geom/cell_inf_hex16.h

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

245+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
246+
{ return this->_n_nodes_on_edge_constant<InfHex16>(e) - ((e < 4) ? 0 : 1); }
247+
245248
protected:
246249

247250
/**

include/geom/cell_inf_hex18.h

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

260+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
261+
{ return this->_n_nodes_on_edge_constant<InfHex18>(e) - ((e < 4) ? 0 : 1); }
262+
260263
protected:
261264

262265
/**

include/geom/cell_inf_hex8.h

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

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

200206
/**

include/geom/cell_inf_prism12.h

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

236+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
237+
{ return this->_n_nodes_on_edge_constant<InfPrism12>(e) - ((e < 3) ? 0 : 1); }
238+
236239
protected:
237240

238241
/**

include/geom/cell_inf_prism6.h

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

194+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
195+
{ return this->_n_nodes_on_edge_constant<InfPrism6>(e); }
196+
194197
protected:
195198

196199
/**

include/geom/cell_prism15.h

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

252+
/**
253+
* \returns 3. Every edge has three 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<Prism15>(e); }
257+
252258
protected:
253259

254260
/**

include/geom/cell_prism18.h

+6
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ class Prism18 final : public Prism
267267
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
268268
{ return _n_nodes_on_side<Prism18, 3>(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<Prism18>(e); }
275+
270276
protected:
271277

272278
/**

include/geom/cell_prism20.h

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

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

271277
/**

include/geom/cell_prism21.h

+6
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ class Prism21 final : public Prism
269269
virtual unsigned int n_nodes_on_side(const unsigned short s) const override final
270270
{ return _n_nodes_on_side<Prism21, 2>(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<Prism21>(e); }
277+
272278
protected:
273279

274280
/**

include/geom/cell_prism6.h

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

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

214220
/**

include/geom/cell_pyramid13.h

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

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

242248
/**

include/geom/cell_pyramid14.h

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

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

263269
/**

include/geom/cell_pyramid5.h

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

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

207213
/**

include/geom/cell_tet10.h

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

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

253259
/**

include/geom/cell_tet14.h

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

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

include/geom/cell_tet4.h

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

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

260266
/**

include/geom/edge.h

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

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

240246
/**

include/geom/elem.h

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

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

1993+
/**
1994+
* Helper for overriding n_nodes_per_edge in derived classes.
1995+
*
1996+
* Performs bound checking on \p s and returns nodes_per_edge
1997+
* for the given class for all edges.
1998+
*/
1999+
template <class ElemClass>
2000+
unsigned int _n_nodes_on_edge_constant(const unsigned short libmesh_dbg_var(s)) const
2001+
{
2002+
static_assert(std::is_base_of<Elem, ElemClass>::value, "Not an Elem");
2003+
libmesh_assert_less(s, this->n_edges());
2004+
return ElemClass::nodes_per_edge;
2005+
}
2006+
19882007
/**
19892008
* Helper for overriding nodes_on_side in derived classes.
19902009
*/

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
@@ -237,6 +237,9 @@ class InfQuad : public Elem
237237

238238
virtual void permute(unsigned int) override final { libmesh_error(); }
239239

240+
virtual unsigned int n_nodes_on_edge(const unsigned short e) const override final
241+
{ return this->n_nodes_on_side(e); }
242+
240243
protected:
241244

242245
/**

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
@@ -316,6 +316,21 @@ public:
316316
}
317317
};
318318

319+
void test_n_nodes_on_edge()
320+
{
321+
LOG_UNIT_TEST;
322+
323+
for (const auto & elem : _mesh->active_local_element_ptr_range())
324+
for (const auto e : elem->edge_index_range())
325+
{
326+
unsigned int n_nodes_on_edge = 0;
327+
for (const auto n : elem->node_index_range())
328+
if (elem->is_node_on_edge(n, e))
329+
++n_nodes_on_edge;
330+
CPPUNIT_ASSERT_EQUAL(n_nodes_on_edge, elem->n_nodes_on_edge(e));
331+
}
332+
};
333+
319334
void test_n_vertices_on_side()
320335
{
321336
LOG_UNIT_TEST;
@@ -376,6 +391,7 @@ public:
376391
CPPUNIT_TEST( test_center_node_on_side ); \
377392
CPPUNIT_TEST( test_side_type ); \
378393
CPPUNIT_TEST( test_n_nodes_on_side ); \
394+
CPPUNIT_TEST( test_n_nodes_on_edge ); \
379395
CPPUNIT_TEST( test_n_vertices_on_side ); \
380396
CPPUNIT_TEST( test_nodes_on_side_ptr ); \
381397
CPPUNIT_TEST( test_elem_side_builder );

0 commit comments

Comments
 (0)