libMesh
Loading...
Searching...
No Matches
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_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 SIDETEST \
40 CPPUNIT_TEST( testIsNodeOnSide ); \
41 CPPUNIT_TEST( testNodesOnSide ); \
42 CPPUNIT_TEST( testSidePtr ); \
43 CPPUNIT_TEST( testSidePtrFill ); \
44 CPPUNIT_TEST( testBuildSidePtr ); \
45 CPPUNIT_TEST( testBuildSidePtrFill ); \
46
47using namespace libMesh;
48
49
50template <typename ElemClass, ElemType side_type,
51 unsigned short indexbegin, unsigned short indexend>
52class SideTest : public CppUnit::TestCase {
53
54private:
55 ElemClass elem;
56 std::vector<std::unique_ptr<Node>> nodes;
57
58protected:
59 std::string libmesh_suite_name;
60
61public:
62 void setUp() {
63 elem.set_id() = 0;
64#ifdef LIBMESH_ENABLE_AMR
65 // Do tests with an Elem having a non-default p_level to ensure
66 // that sides which are built have a matching p_level. p-refinement
67 // is only available if LIBMESH_ENABLE_AMR is defined.
68 elem.set_p_level(1);
69#endif
70 Point dummy;
71 for (auto i : elem.node_index_range())
72 {
73 nodes.push_back(std::make_unique<Node>(dummy, /*id=*/i));
74 elem.set_node(i, nodes[i].get());
75 }
76 }
77
78 void tearDown() {}
79
81 {
82 LOG_UNIT_TEST;
83
84 for (auto s : make_range(indexbegin, indexend))
85 {
86 std::unique_ptr<Elem> side = elem.build_side_ptr(s);
87 for (auto n : elem.node_index_range())
88 {
89 const Node * node = elem.node_ptr(n);
90 bool found_node = false;
91 for (auto sn : side->node_index_range())
92 if (node == side->node_ptr(sn))
93 {
94 found_node = true;
95 break;
96 }
97
98 if (elem.is_node_on_side(n, s))
99 {
100 CPPUNIT_ASSERT(found_node);
101 }
102 else
103 {
104 CPPUNIT_ASSERT(!found_node);
105 }
106 }
107 }
108 }
109
111 {
112 LOG_UNIT_TEST;
113
114 for (auto s : make_range(indexbegin, indexend))
115 {
116 std::unique_ptr<Elem> side = elem.build_side_ptr(s);
117 std::vector<unsigned int> side_nodes = elem.nodes_on_side(s);
118
119 CPPUNIT_ASSERT_EQUAL(side_nodes.size(), std::size_t(side->n_nodes()));
120
121 for (auto sn : side->node_index_range())
122 {
123 const Node * node = side->node_ptr(sn);
124 bool found_node = false;
125 for (auto si : side_nodes)
126 if (node == elem.node_ptr(si))
127 {
128 found_node = true;
129 break;
130 }
131 CPPUNIT_ASSERT(found_node);
132 }
133 }
134 }
135
137 {
138 LOG_UNIT_TEST;
139
140 for (auto s : make_range(indexbegin, indexend))
141 {
142 std::unique_ptr<Elem> side = elem.side_ptr(s);
143
144 CPPUNIT_ASSERT(side->type() ==
146 }
147 }
148
150 {
151 LOG_UNIT_TEST;
152
153 std::unique_ptr<Elem> side;
154
155 for (auto s : make_range(indexbegin, indexend))
156 {
157 elem.side_ptr(side, s);
158
159 CPPUNIT_ASSERT(side->type() ==
161 }
162 }
163
165 {
166 LOG_UNIT_TEST;
167
168 for (auto s : make_range(indexbegin, indexend))
169 {
170 std::unique_ptr<Elem> side = elem.build_side_ptr(s);
171
172 CPPUNIT_ASSERT(side->type() == side_type);
173 CPPUNIT_ASSERT(side->subdomain_id() == elem.subdomain_id());
174
175#ifdef LIBMESH_ENABLE_AMR
176 // p-refinement is only available if LIBMESH_ENABLE_AMR is defined.
177 CPPUNIT_ASSERT(side->p_level() == elem.p_level());
178#endif
179 }
180 }
181
183 {
184 LOG_UNIT_TEST;
185
186 std::unique_ptr<Elem> side;
187
188 for (auto s : make_range(indexbegin, indexend))
189 {
190 elem.build_side_ptr(side, s);
191 std::unique_ptr<Elem> side_new = elem.build_side_ptr(s);
192
193 CPPUNIT_ASSERT(side->type() == side_type);
194 CPPUNIT_ASSERT(*side == *side_new);
195 }
196 }
197
198};
199
200
201#define INSTANTIATE_SIDETEST(elemclass, sidetype, indexbegin, indexend) \
202 class SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend : \
203 public SideTest<elemclass, sidetype, indexbegin, indexend> { \
204 public: \
205 SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend() : \
206 SideTest<elemclass,sidetype,indexbegin,indexend>() { \
207 if (unitlog->summarized_logs_enabled()) \
208 this->libmesh_suite_name = "SideTest"; \
209 else \
210 this->libmesh_suite_name = "SideTest_" #elemclass"_" #sidetype "_" #indexbegin "_" #indexend; \
211 } \
212 CPPUNIT_TEST_SUITE( SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend ); \
213 SIDETEST \
214 CPPUNIT_TEST_SUITE_END(); \
215 }; \
216 \
217 CPPUNIT_TEST_SUITE_REGISTRATION( SideTest_##elemclass##_##sidetype##_##indexbegin##_##indexend );
218
255
256#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
272#endif // LIBMESH_ENABLE_INFINITE_ELEMENTS
void testBuildSidePtr()
Definition side_test.C:164
void testBuildSidePtrFill()
Definition side_test.C:182
void testNodesOnSide()
Definition side_test.C:110
void setUp()
Definition side_test.C:62
void testSidePtr()
Definition side_test.C:136
std::string libmesh_suite_name
Definition side_test.C:59
void testSidePtrFill()
Definition side_test.C:149
void tearDown()
Definition side_test.C:78
std::vector< std::unique_ptr< Node > > nodes
Definition side_test.C:56
void testIsNodeOnSide()
Definition side_test.C:80
ElemClass elem
Definition side_test.C:55
The Edge2 is an element in 1D composed of 2 nodes.
Definition edge_edge2.h:47
The Edge3 is an element in 1D composed of 3 nodes.
Definition edge_edge3.h:47
The Edge4 is an element in 1D composed of 4 nodes.
Definition edge_edge4.h:48
static ElemType first_order_equivalent_type(const ElemType et)
Definition elem.C:3099
The Hex20 is an element in 3D composed of 20 nodes.
Definition cell_hex20.h:71
The Hex27 is an element in 3D composed of 27 nodes.
Definition cell_hex27.h:71
The Hex8 is an element in 3D composed of 8 nodes.
Definition cell_hex8.h:56
The InfEdge2 is an infinite element in 1D composed of 2 nodes.
The InfHex16 is an infinite element in 3D composed of 16 nodes.
The InfHex18 is an infinite element in 3D composed of 18 nodes.
The InfHex8 is an infinite element in 3D composed of 8 nodes.
The InfPrism12 is an infinite element in 3D composed of 12 nodes.
The InfPrism6 is an infinite element in 3D composed of 6 nodes.
The INFQUAD4 is an infinite element in 2D composed of 4 nodes.
The INFQUAD6 is an infinite element in 2D composed of 6 nodes.
A Node is like a Point, but with more information.
Definition node.h:55
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The Prism15 is an element in 3D composed of 15 nodes.
The Prism18 is an element in 3D composed of 18 nodes.
The Prism20 is an element in 3D composed of 20 nodes.
The Prism21 is an element in 3D composed of 21 nodes.
The Prism6 is an element in 3D composed of 6 nodes.
Definition cell_prism6.h:59
The Pyramid13 is an element in 3D composed of 13 nodes, designed to interface with a QUAD8 element on...
The Pyramid14 is an element in 3D composed of 14 nodes, designed to interface with a QUAD9 element on...
The Pyramid5 is an element in 3D composed of 5 nodes.
The QUAD4 is an element in 2D composed of 4 nodes.
Definition face_quad4.h:54
The QUAD8 is an element in 2D composed of 8 nodes.
Definition face_quad8.h:52
The QUAD9 is an element in 2D composed of 9 nodes.
Definition face_quad9.h:52
The Tet10 is an element in 3D composed of 10 nodes.
Definition cell_tet10.h:65
The Tet14 is an element in 3D composed of 14 nodes.
Definition cell_tet14.h:71
The Tet4 is an element in 3D composed of 4 nodes.
Definition cell_tet4.h:60
The Tri3 is an element in 2D composed of 3 nodes.
Definition face_tri3.h:62
The Tri6 is an element in 2D composed of 6 nodes.
Definition face_tri6.h:62
The Tri7 is an element in 2D composed of 7 nodes.
Definition face_tri7.h:62
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
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:176
INSTANTIATE_SIDETEST(Hex20, QUAD8, 0, 6)