libMesh
side_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_prism6.h>
14 #include <libmesh/cell_pyramid13.h>
15 #include <libmesh/cell_pyramid14.h>
16 #include <libmesh/cell_pyramid5.h>
17 #include <libmesh/cell_tet10.h>
18 #include <libmesh/cell_tet4.h>
19 #include <libmesh/edge_edge2.h>
20 #include <libmesh/edge_edge3.h>
21 #include <libmesh/edge_edge4.h>
22 #include <libmesh/edge_inf_edge2.h>
23 #include <libmesh/face_inf_quad4.h>
24 #include <libmesh/face_inf_quad6.h>
25 #include <libmesh/face_quad4.h>
26 #include <libmesh/face_quad8.h>
27 #include <libmesh/face_quad9.h>
28 #include <libmesh/face_tri3.h>
29 #include <libmesh/face_tri6.h>
30 
31 #include <vector>
32 
33 #include "libmesh_cppunit.h"
34 
35 #define SIDETEST \
36  CPPUNIT_TEST( testIsNodeOnSide ); \
37  CPPUNIT_TEST( testNodesOnSide ); \
38  CPPUNIT_TEST( testSidePtr ); \
39  CPPUNIT_TEST( testSidePtrFill ); \
40  CPPUNIT_TEST( testBuildSidePtr ); \
41  CPPUNIT_TEST( testBuildSidePtrFill ); \
42 
43 using namespace libMesh;
44 
45 
46 template <typename ElemClass, ElemType side_type,
47  unsigned short indexbegin, unsigned short indexend>
48 class SideTest : public CppUnit::TestCase {
49 
50 private:
51  ElemClass elem;
52  std::vector<std::unique_ptr<Node>> nodes;
53 
54 public:
55  void setUp() {
56  elem.set_id() = 0;
57  Point dummy;
58  for (auto i : elem.node_index_range())
59  {
60  nodes.push_back(libmesh_make_unique<Node>(dummy, /*id=*/i));
61  elem.set_node(i) = nodes[i].get();
62  }
63  }
64 
65  void tearDown() {}
66 
68  {
69  for (auto s : IntRange<unsigned short>(indexbegin, indexend))
70  {
71  std::unique_ptr<Elem> side = elem.build_side_ptr(s);
72  for (auto n : elem.node_index_range())
73  {
74  const Node * node = elem.node_ptr(n);
75  bool found_node = false;
76  for (auto sn : side->node_index_range())
77  if (node == side->node_ptr(sn))
78  {
79  found_node = true;
80  break;
81  }
82 
83  if (elem.is_node_on_side(n, s))
84  {
85  CPPUNIT_ASSERT(found_node);
86  }
87  else
88  {
89  CPPUNIT_ASSERT(!found_node);
90  }
91  }
92  }
93  }
94 
96  {
97  for (auto s : IntRange<unsigned short>(indexbegin, indexend))
98  {
99  std::unique_ptr<Elem> side = elem.build_side_ptr(s);
100  std::vector<unsigned int> side_nodes = elem.nodes_on_side(s);
101 
102  CPPUNIT_ASSERT_EQUAL(side_nodes.size(), std::size_t(side->n_nodes()));
103 
104  for (auto sn : side->node_index_range())
105  {
106  const Node * node = side->node_ptr(sn);
107  bool found_node = false;
108  for (auto si : side_nodes)
109  if (node == elem.node_ptr(si))
110  {
111  found_node = true;
112  break;
113  }
114  CPPUNIT_ASSERT(found_node);
115  }
116  }
117  }
118 
119  void testSidePtr()
120  {
121  for (auto s : IntRange<unsigned short>(indexbegin, indexend))
122  {
123  std::unique_ptr<Elem> side = elem.side_ptr(s);
124 
125  CPPUNIT_ASSERT(side->type() ==
127  }
128  }
129 
131  {
132  std::unique_ptr<Elem> side;
133 
134  for (auto s : IntRange<unsigned short>(indexbegin, indexend))
135  {
136  elem.side_ptr(side, s);
137 
138  CPPUNIT_ASSERT(side->type() ==
140  }
141  }
142 
144  {
145  for (auto s : IntRange<unsigned short>(indexbegin, indexend))
146  {
147  std::unique_ptr<Elem> side = elem.build_side_ptr(s);
148 
149  CPPUNIT_ASSERT(side->type() == side_type);
150  }
151  }
152 
154  {
155  std::unique_ptr<Elem> side;
156 
157  for (auto s : IntRange<unsigned short>(indexbegin, indexend))
158  {
159  elem.build_side_ptr(side, s);
160  std::unique_ptr<Elem> side_new = elem.build_side_ptr(s);
161 
162  CPPUNIT_ASSERT(side->type() == side_type);
163  CPPUNIT_ASSERT(*side == *side_new);
164  }
165  }
166 
167 };
168 
169 
170 #define INSTANTIATE_SIDETEST(elemclass, sidetype, indexbegin, indexend) \
171  class SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend : \
172  public SideTest<elemclass, sidetype, indexbegin, indexend> { \
173  public: \
174  CPPUNIT_TEST_SUITE( SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend ); \
175  SIDETEST \
176  CPPUNIT_TEST_SUITE_END(); \
177  }; \
178  \
179  CPPUNIT_TEST_SUITE_REGISTRATION( SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend );
180 
209 
210 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
226 #endif // LIBMESH_ENABLE_INFINITE_ELEMENTS
SideTest::testIsNodeOnSide
void testIsNodeOnSide()
Definition: side_test.C:67
SideTest::setUp
void setUp()
Definition: side_test.C:55
libMesh::Quad9
The QUAD9 is an element in 2D composed of 9 nodes.
Definition: face_quad9.h:51
SideTest::testBuildSidePtrFill
void testBuildSidePtrFill()
Definition: side_test.C:153
libMesh::Tri6
The Tri6 is an element in 2D composed of 6 nodes.
Definition: face_tri6.h:56
SideTest
Definition: side_test.C:48
libMesh::Prism18
The Prism18 is an element in 3D composed of 18 nodes.
Definition: cell_prism18.h:69
libMesh::Pyramid13
The Pyramid13 is an element in 3D composed of 13 nodes, designed to interface with a QUAD8 element on...
Definition: cell_pyramid13.h:68
libMesh::INFQUAD4
Definition: enum_elem_type.h:58
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::InfPrism6
The InfPrism6 is an infinite element in 3D composed of 6 nodes.
Definition: cell_inf_prism6.h:57
libMesh::InfHex18
The InfHex18 is an infinite element in 3D composed of 18 nodes.
Definition: cell_inf_hex18.h:70
libMesh::Hex20
The Hex20 is an element in 3D composed of 20 nodes.
Definition: cell_hex20.h:68
libMesh::Prism6
The Prism6 is an element in 3D composed of 6 nodes.
Definition: cell_prism6.h:52
libMesh::INFEDGE2
Definition: enum_elem_type.h:57
libMesh::InfQuad4
The INFQUAD4 is an infinite element in 2D composed of 4 nodes.
Definition: face_inf_quad4.h:52
libMesh::Pyramid14
The Pyramid14 is an element in 3D composed of 14 nodes, designed to interface with a QUAD9 element on...
Definition: cell_pyramid14.h:71
INSTANTIATE_SIDETEST
INSTANTIATE_SIDETEST(Hex20, QUAD8, 0, 6)
libMesh::IntRange
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition: int_range.h:53
SideTest::testBuildSidePtr
void testBuildSidePtr()
Definition: side_test.C:143
SideTest::testSidePtr
void testSidePtr()
Definition: side_test.C:119
SideTest::nodes
std::vector< std::unique_ptr< Node > > nodes
Definition: side_test.C:52
libMesh::Elem::first_order_equivalent_type
static ElemType first_order_equivalent_type(const ElemType et)
Definition: elem.C:2369
SideTest::tearDown
void tearDown()
Definition: side_test.C:65
libMesh::QUAD4
Definition: enum_elem_type.h:41
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::InfEdge2
The InfEdge2 is an infinite element in 1D composed of 2 nodes.
Definition: edge_inf_edge2.h:52
libMesh::TRI3
Definition: enum_elem_type.h:39
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::Pyramid5
The Pyramid5 is an element in 3D composed of 5 nodes.
Definition: cell_pyramid5.h:52
libMesh::Tet4
The Tet4 is an element in 3D composed of 4 nodes.
Definition: cell_tet4.h:53
libMesh::Edge3
The Edge3 is an element in 1D composed of 3 nodes.
Definition: edge_edge3.h:43
libMesh::Quad4
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:51
libMesh::InfPrism12
The InfPrism12 is an infinite element in 3D composed of 12 nodes.
Definition: cell_inf_prism12.h:61
SideTest::elem
ElemClass elem
Definition: side_test.C:51
libMesh::TRI6
Definition: enum_elem_type.h:40
libMesh::Hex8
The Hex8 is an element in 3D composed of 8 nodes.
Definition: cell_hex8.h:53
libMesh::Tet10
The Tet10 is an element in 3D composed of 10 nodes.
Definition: cell_tet10.h:60
libMesh::INFQUAD6
Definition: enum_elem_type.h:59
libMesh::Quad8
The QUAD8 is an element in 2D composed of 8 nodes.
Definition: face_quad8.h:51
libmesh_cppunit.h
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::Edge2
The Edge2 is an element in 1D composed of 2 nodes.
Definition: edge_edge2.h:43
libMesh::Tri3
The Tri3 is an element in 2D composed of 3 nodes.
Definition: face_tri3.h:56
SideTest::testSidePtrFill
void testSidePtrFill()
Definition: side_test.C:130
libMesh::Edge4
The Edge4 is an element in 1D composed of 4 nodes.
Definition: edge_edge4.h:44
libMesh::Hex27
The Hex27 is an element in 3D composed of 27 nodes.
Definition: cell_hex27.h:68
libMesh::InfHex8
The InfHex8 is an infinite element in 3D composed of 8 nodes.
Definition: cell_inf_hex8.h:55
libMesh::NODEELEM
Definition: enum_elem_type.h:66
SideTest::testNodesOnSide
void testNodesOnSide()
Definition: side_test.C:95
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::InfQuad6
The INFQUAD6 is an infinite element in 2D composed of 6 nodes.
Definition: face_inf_quad6.h:53
libMesh::Prism15
The Prism15 is an element in 3D composed of 15 nodes.
Definition: cell_prism15.h:69
libMesh::EDGE2
Definition: enum_elem_type.h:35
libMesh::QUAD8
Definition: enum_elem_type.h:42
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33
libMesh::InfHex16
The InfHex16 is an infinite element in 3D composed of 16 nodes.
Definition: cell_inf_hex16.h:70