libMesh
edge_test.C
Go to the documentation of this file.
1 #include <libmesh/elem.h>
2 
3 #include <libmesh/cell_hex20.h>
4 #include <libmesh/cell_hex27.h>
5 #include <libmesh/cell_hex8.h>
6 #include <libmesh/cell_inf_hex16.h>
7 #include <libmesh/cell_inf_hex18.h>
8 #include <libmesh/cell_inf_hex8.h>
9 #include <libmesh/cell_inf_prism12.h>
10 #include <libmesh/cell_inf_prism6.h>
11 #include <libmesh/cell_prism15.h>
12 #include <libmesh/cell_prism18.h>
13 #include <libmesh/cell_prism20.h>
14 #include <libmesh/cell_prism21.h>
15 #include <libmesh/cell_prism6.h>
16 #include <libmesh/cell_pyramid13.h>
17 #include <libmesh/cell_pyramid14.h>
18 #include <libmesh/cell_pyramid5.h>
19 #include <libmesh/cell_tet10.h>
20 #include <libmesh/cell_tet14.h>
21 #include <libmesh/cell_tet4.h>
22 #include <libmesh/edge_edge2.h>
23 #include <libmesh/edge_edge3.h>
24 #include <libmesh/edge_edge4.h>
25 #include <libmesh/edge_inf_edge2.h>
26 #include <libmesh/face_inf_quad4.h>
27 #include <libmesh/face_inf_quad6.h>
28 #include <libmesh/face_quad4.h>
29 #include <libmesh/face_quad8.h>
30 #include <libmesh/face_quad9.h>
31 #include <libmesh/face_tri3.h>
32 #include <libmesh/face_tri6.h>
33 #include <libmesh/face_tri7.h>
34 
35 #include <vector>
36 
37 #include "libmesh_cppunit.h"
38 
39 #define EDGETEST \
40  CPPUNIT_TEST( testIsNodeOnEdge ); \
41  CPPUNIT_TEST( testNodesOnEdge ); \
42  CPPUNIT_TEST( testBuildEdgePtr ); \
43 
44 using namespace libMesh;
45 
46 
47 template <typename ElemClass, ElemType edge_type,
48  unsigned short indexbegin, unsigned short indexend>
49 class EdgeTest : public CppUnit::TestCase {
50 
51 private:
52  ElemClass elem;
53  std::vector<std::unique_ptr<Node>> nodes;
54 
55 protected:
56  std::string libmesh_suite_name;
57 
58 public:
59  void setUp() {
60  elem.set_id() = 0;
61 #ifdef LIBMESH_ENABLE_AMR
62  // Do tests with an Elem having a non-default p_level to ensure
63  // that edges which are built have a matching p_level. p-refinement
64  // is only available if LIBMESH_ENABLE_AMR is defined.
65  elem.set_p_level(1);
66 #endif
67  Point dummy;
68  for (auto i : elem.node_index_range())
69  {
70  nodes.push_back(std::make_unique<Node>(dummy, /*id=*/i));
71  elem.set_node(i, nodes[i].get());
72  }
73  }
74 
75  void tearDown() {}
76 
78  {
79  LOG_UNIT_TEST;
80 
81  for (auto e : make_range(indexbegin, indexend))
82  {
83  std::unique_ptr<Elem> edge = elem.build_edge_ptr(e);
84  for (auto n : elem.node_index_range())
85  {
86  const Node * node = elem.node_ptr(n);
87  bool found_node = false;
88  for (auto en : edge->node_index_range())
89  if (node == edge->node_ptr(en))
90  {
91  found_node = true;
92  break;
93  }
94 
95  if (elem.is_node_on_edge(n, e))
96  {
97  CPPUNIT_ASSERT(found_node);
98  }
99  else
100  {
101  CPPUNIT_ASSERT(!found_node);
102  }
103  }
104  }
105  }
106 
108  {
109  LOG_UNIT_TEST;
110 
111  for (auto e : make_range(indexbegin, indexend))
112  {
113  std::unique_ptr<Elem> edge = elem.build_edge_ptr(e);
114  std::vector<unsigned int> edge_nodes = elem.nodes_on_edge(e);
115 
116  CPPUNIT_ASSERT_EQUAL(edge_nodes.size(), std::size_t(edge->n_nodes()));
117 
118  for (auto en : edge->node_index_range())
119  {
120  const Node * node = edge->node_ptr(en);
121  bool found_node = false;
122  for (auto ei : edge_nodes)
123  if (node == elem.node_ptr(ei))
124  {
125  found_node = true;
126  break;
127  }
128  CPPUNIT_ASSERT(found_node);
129  }
130  }
131  }
132 
134  {
135  LOG_UNIT_TEST;
136 
137  for (auto e : make_range(indexbegin, indexend))
138  {
139  std::unique_ptr<Elem> edge = elem.build_edge_ptr(e);
140 
141  CPPUNIT_ASSERT(edge->type() == edge_type);
142  CPPUNIT_ASSERT(edge->subdomain_id() == elem.subdomain_id());
143 
144 #ifdef LIBMESH_ENABLE_AMR
145  // p-refinement is only available if LIBMESH_ENABLE_AMR is defined.
146  CPPUNIT_ASSERT(edge->p_level() == elem.p_level());
147 #endif
148  }
149  }
150 };
151 
152 
153 #define INSTANTIATE_EDGETEST(elemclass, edgetype, indexbegin, indexend) \
154  class EdgeTest_##elemclass##_##edgetype##_##indexbegin##_##indexend : \
155  public EdgeTest<elemclass, edgetype, indexbegin, indexend> { \
156  public: \
157  EdgeTest_##elemclass##_##edgetype##_##indexbegin##_##indexend() : \
158  EdgeTest<elemclass,edgetype,indexbegin,indexend>() { \
159  if (unitlog->summarized_logs_enabled()) \
160  this->libmesh_suite_name = "EdgeTest"; \
161  else \
162  this->libmesh_suite_name = "EdgeTest_" #elemclass"_" #edgetype "_" #indexbegin "_" #indexend; \
163  } \
164  CPPUNIT_TEST_SUITE( EdgeTest_##elemclass##_##edgetype##_##indexbegin##_##indexend ); \
165  EDGETEST \
166  CPPUNIT_TEST_SUITE_END(); \
167  }; \
168  \
169  CPPUNIT_TEST_SUITE_REGISTRATION( EdgeTest_##elemclass##_##edgetype##_##indexbegin##_##indexend );
170 
191 
192 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
207 #endif // LIBMESH_ENABLE_INFINITE_ELEMENTS
void testIsNodeOnEdge()
Definition: edge_test.C:77
The Prism20 is an element in 3D composed of 20 nodes.
Definition: cell_prism20.h:79
The Tri3 is an element in 2D composed of 3 nodes.
Definition: face_tri3.h:61
ElemType
Defines an enum for geometric element types.
The InfHex8 is an infinite element in 3D composed of 8 nodes.
Definition: cell_inf_hex8.h:55
A Node is like a Point, but with more information.
Definition: node.h:52
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:53
The Hex8 is an element in 3D composed of 8 nodes.
Definition: cell_hex8.h:55
The INFQUAD4 is an infinite element in 2D composed of 4 nodes.
The Prism6 is an element in 3D composed of 6 nodes.
Definition: cell_prism6.h:58
The Hex20 is an element in 3D composed of 20 nodes.
Definition: cell_hex20.h:70
void testNodesOnEdge()
Definition: edge_test.C:107
The QUAD8 is an element in 2D composed of 8 nodes.
Definition: face_quad8.h:51
void setUp()
Definition: edge_test.C:59
The libMesh namespace provides an interface to certain functionality in the library.
void testBuildEdgePtr()
Definition: edge_test.C:133
std::string libmesh_suite_name
Definition: edge_test.C:56
The Tet14 is an element in 3D composed of 14 nodes.
Definition: cell_tet14.h:70
The Tri6 is an element in 2D composed of 6 nodes.
Definition: face_tri6.h:61
std::vector< std::unique_ptr< Node > > nodes
Definition: edge_test.C:53
The InfPrism12 is an infinite element in 3D composed of 12 nodes.
The InfHex16 is an infinite element in 3D composed of 16 nodes.
The INFQUAD6 is an infinite element in 2D composed of 6 nodes.
The QUAD9 is an element in 2D composed of 9 nodes.
Definition: face_quad9.h:51
The Prism15 is an element in 3D composed of 15 nodes.
Definition: cell_prism15.h:75
INSTANTIATE_EDGETEST(Hex20, EDGE3, 0, 12)
ElemClass elem
Definition: edge_test.C:52
The Pyramid13 is an element in 3D composed of 13 nodes, designed to interface with a QUAD8 element ...
void tearDown()
Definition: edge_test.C:75
The Hex27 is an element in 3D composed of 27 nodes.
Definition: cell_hex27.h:70
The Tet10 is an element in 3D composed of 10 nodes.
Definition: cell_tet10.h:64
The Prism18 is an element in 3D composed of 18 nodes.
Definition: cell_prism18.h:75
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
The Prism21 is an element in 3D composed of 21 nodes.
Definition: cell_prism21.h:82
The Tet4 is an element in 3D composed of 4 nodes.
Definition: cell_tet4.h:59
The InfPrism6 is an infinite element in 3D composed of 6 nodes.
The Tri7 is an element in 2D composed of 7 nodes.
Definition: face_tri7.h:61
The Pyramid14 is an element in 3D composed of 14 nodes, designed to interface with a QUAD9 element ...
The Pyramid5 is an element in 3D composed of 5 nodes.
Definition: cell_pyramid5.h:57
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
The InfHex18 is an infinite element in 3D composed of 18 nodes.