Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestElemGraphCoincidentElements.cpp

raw
1 #include "gtest/gtest.h"
2 #include "mpi.h"
3 #include <stk_mesh/base/BulkData.hpp>
4 #include <stk_mesh/base/FEMHelpers.hpp>
5 #include <stk_mesh/base/GetEntities.hpp>
6 #include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp>
7 #include <stk_mesh/baseImpl/elementGraph/ElemElemGraphUpdater.hpp>
8 #include <stk_unit_test_utils/MeshFixture.hpp>
9 #include <stk_unit_test_utils/BuildMesh.hpp>
10 #include <stk_mesh/base/SkinBoundary.hpp>
11
12 namespace
13 {
14 using stk::unit_test_util::build_mesh;
15
16 void setup_node_sharing(stk::mesh::BulkData &mesh, const std::vector< std::vector<unsigned> > & shared_nodeIDs_and_procs )
17 {
18 const unsigned p_rank = mesh.parallel_rank();
19
20 for (size_t nodeIdx = 0, end = shared_nodeIDs_and_procs.size(); nodeIdx < end; ++nodeIdx) {
21 if (p_rank == shared_nodeIDs_and_procs[nodeIdx][0]) {
22 stk::mesh::EntityId nodeID = shared_nodeIDs_and_procs[nodeIdx][1];
23 int sharingProc = shared_nodeIDs_and_procs[nodeIdx][2];
24 stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, nodeID);
25 mesh.add_node_sharing(node, sharingProc);
26 }
27 }
28 }
29
30 void expect_correct_connected_element_via_side(stk::mesh::ElemElemGraph& elemElemGraph, stk::mesh::Entity elem, int k, stk::mesh::Entity otherElem, int viaSide)
31 {
32 stk::mesh::impl::ElementViaSidePair elem_via_side = elemElemGraph.get_connected_element_and_via_side(elem, k);
33 EXPECT_EQ(viaSide, elem_via_side.side);
34 EXPECT_EQ(otherElem, elem_via_side.element);
35 }
36
37 void expect_correct_connected_coincident_element_via_side(stk::mesh::ElemElemGraph& elemElemGraph, stk::mesh::Entity elem, stk::mesh::Entity otherElem, int viaSide)
38 {
39 stk::mesh::impl::LocalId localElemId = elemElemGraph.get_local_element_id(elem, true);
40 stk::mesh::impl::LocalId localOtherElemId = elemElemGraph.get_local_element_id(otherElem, true);
41 std::vector<stk::mesh::impl::LocalId> elements = elemElemGraph.get_coincident_elements_on_side(localElemId, viaSide);
42
43 EXPECT_EQ(1u, elements.size());
44 EXPECT_EQ(localOtherElemId, elements[0]);
45 }
46
47 class HexShellShell : public stk::unit_test_util::MeshFixture
48 {
49 protected:
50 HexShellShell()
51 {
52 setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA);
53 }
54
55 void setup_hex_shell_shell_on_procs(std::vector<int> owningProcs)
56 {
57 stk::mesh::Part* hexPart = &get_meta().declare_part_with_topology("hex_part", stk::topology::HEX_8);
58 stk::mesh::Part* shellPart = &get_meta().declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
59 stk::mesh::PartVector parts = {hexPart, shellPart, shellPart};
60 declare_elements_on_procs_and_setup_node_sharing(owningProcs, parts);
61 }
62
63 private:
64 void declare_elements_on_procs_and_setup_node_sharing(const std::vector<int>& owningProcs, const stk::mesh::PartVector& parts)
65 {
66 get_bulk().modification_begin();
67 declare_elements_on_procs(owningProcs, parts);
68 if(get_bulk().parallel_size()==2)
69 {
70 setup_node_sharing(get_bulk(), shared_nodeIDs_and_procs2);
71 }
72 if(get_bulk().parallel_size()==3)
73 {
74 setup_node_sharing(get_bulk(), shared_nodeIDs_and_procs3);
75 }
76 get_bulk().modification_end();
77 }
78
79 void declare_elements_on_procs(const std::vector<int>& owningProcs, const stk::mesh::PartVector& parts)
80 {
81 for(size_t i = 0; i < nodeIDsPerElement.size(); ++i)
82 if(owningProcs[i] == stk::parallel_machine_rank(get_comm()))
83 stk::mesh::declare_element(get_bulk(), *parts[i], elemIDs[i], nodeIDsPerElement[i]);
84 }
85
86 std::vector<stk::mesh::EntityIdVector> nodeIDsPerElement { {1, 2, 3, 4, 5, 6, 7, 8}, {5, 6, 7, 8}, {5, 6, 7, 8}};
87 stk::mesh::EntityIdVector elemIDs = {1, 2, 3};
88 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
89 std::vector<std::vector<unsigned> > shared_nodeIDs_and_procs2 = {
90 {0, 5, 1}, {0, 6, 1}, {0, 7, 1}, {0, 8, 1}, // proc 0
91 {1, 5, 0}, {1, 6, 0}, {1, 7, 0}, {1, 8, 0}}; // proc 1
92 std::vector<std::vector<unsigned> > shared_nodeIDs_and_procs3 = {
93 {0, 5, 1}, {0, 6, 1}, {0, 7, 1}, {0, 8, 1}, // proc 0
94 {0, 5, 2}, {0, 6, 2}, {0, 7, 2}, {0, 8, 2}, // proc 0
95 {1, 5, 0}, {1, 6, 0}, {1, 7, 0}, {1, 8, 0}, // proc 1
96 {1, 5, 2}, {1, 6, 2}, {1, 7, 2}, {1, 8, 2}, // proc 1
97 {2, 5, 0}, {2, 6, 0}, {2, 7, 0}, {2, 8, 0}, // proc 1
98 {2, 5, 1}, {2, 6, 1}, {2, 7, 1}, {2, 8, 1}}; // proc 1
99 };
100
101
102 TEST_F(HexShellShell, Hex0Shell1Shell1Parallel)
103 {
104 // ID.proc
105 //
106 // 3.0------------7.0
107 // /| /|
108 // / | / |
109 // / | / |
110 // 4.0------------8.0 |
111 // | | | |
112 // | | 1.0 |2.1|
113 // | | |3.1|
114 // | 2.0---------|--6.0
115 // | / | /
116 // | / | /
117 // |/ |/
118 // 1.0------------5.0
119 // ^
120 // |
121 // ---- Two stacked shells
122
123 if(stk::parallel_machine_size(get_comm()) != 2u)
124 {
125 GTEST_SKIP();
126 }
127
128 setup_hex_shell_shell_on_procs({0, 1, 1});
129
130 stk::mesh::ElemElemGraph elemElemGraph(get_bulk());
131
132 if(stk::parallel_machine_rank(get_comm()) == 0)
133 {
134 const stk::mesh::Entity hex1 = get_bulk().get_entity(stk::topology::ELEM_RANK, 1);
135 ASSERT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
136 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(hex1, 0).id);
137 EXPECT_EQ(5, elemElemGraph.get_connected_remote_id_and_via_side(hex1, 0).side);
138 EXPECT_EQ(3u, elemElemGraph.get_connected_remote_id_and_via_side(hex1, 1).id);
139 EXPECT_EQ(5, elemElemGraph.get_connected_remote_id_and_via_side(hex1, 1).side);
140 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
141 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
142 EXPECT_EQ(2u, elemElemGraph.num_edges());
143 EXPECT_EQ(2u, elemElemGraph.num_parallel_edges());
144 EXPECT_EQ(0u, elemElemGraph.num_coincident_edges());
145 }
146 else
147 {
148 const stk::mesh::Entity shell2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2);
149 ASSERT_EQ(1u, elemElemGraph.get_num_connected_elems(shell2));
150 EXPECT_EQ(1, elemElemGraph.get_connected_remote_id_and_via_side(shell2, 0).side);
151 EXPECT_EQ(1u, elemElemGraph.get_connected_remote_id_and_via_side(shell2, 0).id);
152 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell2, 0));
153
154 const stk::mesh::Entity shell3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3);
155 ASSERT_EQ(1u, elemElemGraph.get_num_connected_elems(shell3));
156 EXPECT_EQ(1, elemElemGraph.get_connected_remote_id_and_via_side(shell3, 0).side);
157 EXPECT_EQ(1u, elemElemGraph.get_connected_remote_id_and_via_side(shell3, 0).id);
158 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
159
160 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 2); //coincident shell edge
161 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 3); //coincident shell edge
162 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 4); //coincident shell edge
163 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 5); //coincident shell edge
164
165 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 2); //coincident shell edge
166 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 3); //coincident shell edge
167 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 4); //coincident shell edge
168 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 5); //coincident shell edge
169
170 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
171 }
172
173 }
174
175 void expect_id_ord_perm(stk::mesh::BulkData &bulk,
176 stk::mesh::Entity face,
177 unsigned elemOffset,
178 const stk::mesh::EntityId elemId,
179 const stk::mesh::ConnectivityOrdinal ord,
180 const stk::mesh::Permutation perm)
181 {
182 EXPECT_EQ(elemId, bulk.identifier(bulk.begin_elements(face)[elemOffset])) << "elemOffset=" << elemOffset;
183 EXPECT_EQ(ord, bulk.begin_element_ordinals(face)[elemOffset]) << "elemOffset=" << elemOffset;
184 EXPECT_EQ(perm, bulk.begin_element_permutations(face)[elemOffset]) << "elemOffset=" << elemOffset;
185 }
186
187 TEST_F(HexShellShell, SideConnections)
188 {
189 if(stk::parallel_machine_size(get_comm()) == 1u)
190 {
191 setup_hex_shell_shell_on_procs({0, 0, 0});
192
193 stk::mesh::ElemElemGraph elemElemGraph(get_bulk());
194 stk::mesh::SideConnector& sideConnector = elemElemGraph.get_side_connector();
195
196 get_bulk().modification_begin();
197 stk::mesh::Entity shell2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2);
198 int shellSide = 1;
199 stk::mesh::Entity face = get_bulk().declare_element_side(shell2, shellSide, stk::mesh::ConstPartVector{});
200 sideConnector.connect_side_to_all_elements(face, shell2, shellSide);
201 get_bulk().modification_end();
202
203 ASSERT_EQ(3u, get_bulk().num_elements(face));
204 expect_id_ord_perm(get_bulk(), face, 0, 2, stk::mesh::ConnectivityOrdinal(1), stk::mesh::Permutation(0));
205 expect_id_ord_perm(get_bulk(), face, 1, 3, stk::mesh::ConnectivityOrdinal(1), stk::mesh::Permutation(0));
206 expect_id_ord_perm(get_bulk(), face, 2, 1, stk::mesh::ConnectivityOrdinal(5), stk::mesh::Permutation(4));
207 }
208 }
209
210 TEST( ElementGraph, HexAddShellAddShellSerial )
211 {
212 // ID.proc
213 //
214 // 3.0------------7.0
215 // /| /|
216 // / | / |
217 // / | / |
218 // 4.0------------8.0 |
219 // | | | |
220 // | | 1.0 |2.0|
221 // | | |3.0|
222 // | 2.0---------|--6.0
223 // | / | /
224 // | / | /
225 // |/ |/
226 // 1.0------------5.0
227 // ^
228 // |
229 // ---- Two stacked shell elements
230
231 stk::ParallelMachine pm = MPI_COMM_WORLD;
232 int p_size = stk::parallel_machine_size(pm);
233
234 if(p_size > 1)
235 {
236 GTEST_SKIP();
237 }
238
239 const unsigned spatialDim = 3;
240 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
241 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
242 stk::mesh::BulkData& mesh = *bulkPtr;
243
244 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
245 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
246 meta.commit();
247
248 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
249 { 1, 2, 3, 4, 5, 6, 7, 8 }
250 };
251 stk::mesh::EntityId hexElemIDs[] = { 1 };
252
253 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
254 { 5, 6, 7, 8 },
255 { 5, 6, 7, 8 }
256 };
257 stk::mesh::EntityId shellElemIDs[] = { 2, 3 };
258
259 mesh.modification_begin();
260 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
261 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
262 }
263 mesh.modification_end();
264
265 stk::mesh::ElemElemGraph elemElemGraph(mesh);
266
267 mesh.modification_begin();
268 stk::mesh::EntityVector added_shells;
269 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
270 added_shells.push_back( stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]) );
271 }
272 mesh.modification_end();
273
274 elemElemGraph.add_elements(added_shells);
275
276 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
277 const stk::mesh::Entity shell2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
278 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
279
280 // Connectivity for Hex Element 1
281 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
282 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell2, 5);
283 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell3, 5);
284 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
285 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
286
287 // Connectivity for Shell Element 2
288 EXPECT_EQ(1u, elemElemGraph.get_num_connected_elems(shell2));
289 expect_correct_connected_element_via_side(elemElemGraph, shell2, 0, hex1, 1); //face
290 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 0); //coincident face
291 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 1); //coincident face
292 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 2); //coincident shell edge
293 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 3); //coincident shell edge
294 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 4); //coincident shell edge
295 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 5); //coincident shell edge
296 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell2, 0));
297
298 // Connectivity for Shell Element 3
299 EXPECT_EQ(1u, elemElemGraph.get_num_connected_elems(shell3));
300 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1); //face
301 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 0); //coincident face
302 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 1); //coincident face
303 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 2); //coincident shell edge
304 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 3); //coincident shell edge
305 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 4); //coincident shell edge
306 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 5); //coincident shell edge
307 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
308
309 EXPECT_EQ(0u, elemElemGraph.num_parallel_edges());
310 // EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
311
312 elemElemGraph.write_graph(std::cout);
313 }
314
315 TEST( ElementGraph, HexAddShellAddShellHexSerial )
316 {
317 // ID.proc
318 //
319 // 3.0------------7.0-----------11.0
320 // /| /| /|
321 // / | / | / |
322 // / | / | / |
323 // 4.0------------8.0-----------12.0 |
324 // | | | | | |
325 // | | 1.0 |3.0| 2.0 | |
326 // | | |4.0| | |
327 // | 2.0---------|--6.0---------|-10.0
328 // | / | / | /
329 // | / | / | /
330 // |/ |/ |/
331 // 1.0------------5.0------------9.0
332 // ^
333 // |
334 // ---- Added two stacked shell elements
335
336 stk::ParallelMachine pm = MPI_COMM_WORLD;
337 int p_size = stk::parallel_machine_size(pm);
338
339 if(p_size > 1)
340 {
341 GTEST_SKIP();
342 }
343
344 const unsigned spatialDim = 3;
345 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
346 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
347 stk::mesh::BulkData& mesh = *bulkPtr;
348
349 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
350 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
351 meta.commit();
352
353 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
354 { 1, 2, 3, 4, 5, 6, 7, 8 },
355 { 5, 6, 7, 8, 9, 10, 11, 12 }
356 };
357 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
358
359 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
360 { 5, 6, 7, 8 },
361 { 5, 6, 7, 8 }
362 };
363 stk::mesh::EntityId shellElemIDs[] = { 3, 4 };
364
365 mesh.modification_begin();
366 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
367 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
368 }
369 mesh.modification_end();
370
371 stk::mesh::ElemElemGraph elemElemGraph(mesh);
372
373 mesh.modification_begin();
374 stk::mesh::EntityVector added_shells;
375 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
376 added_shells.push_back( stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]) );
377 }
378 mesh.modification_end();
379
380 elemElemGraph.add_elements(added_shells);
381
382 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
383 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
384 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
385 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
386
387 // Connectivity for Hex Element 1
388 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
389 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell3, 5);
390 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell4, 5);
391 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
392 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
393
394 // Connectivity for Hex Element 2
395 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex2));
396 expect_correct_connected_element_via_side(elemElemGraph, hex2, 0, shell3, 4);
397 expect_correct_connected_element_via_side(elemElemGraph, hex2, 1, shell4, 4);
398 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 0));
399 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 1));
400
401 // Connectivity for Shell Element 3
402 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell3));
403 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1); //face
404 expect_correct_connected_element_via_side(elemElemGraph, shell3, 1, hex2, 0); //face
405 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 0); //coincident face
406 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 1); //coincident face
407 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
408 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
409 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
410 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
411 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
412 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 1));
413
414 // Connectivity for Shell Element 4
415 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell4));
416 expect_correct_connected_element_via_side(elemElemGraph, shell4, 0, hex1, 1); //face
417 expect_correct_connected_element_via_side(elemElemGraph, shell4, 1, hex2, 0); //face
418 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 0); //coincident face
419 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 1); //coincident face
420 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 2); //coincident shell edge
421 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 3); //coincident shell edge
422 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 4); //coincident shell edge
423 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 5); //coincident shell edge
424 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 0));
425 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 1));
426
427 EXPECT_EQ(0u, elemElemGraph.num_parallel_edges());
428 // EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
429 }
430
431 namespace {
432 class ElemElemGraphTester : public stk::mesh::ElemElemGraph
433 {
434 public:
435 ElemElemGraphTester(stk::mesh::BulkData& bulkData)
436 :ElemElemGraph(bulkData) {}
437 const stk::mesh::impl::SparseGraph& my_get_coincident_graph() {return m_coincidentGraph; }
438 };
439
440 class ShellMeshModification : public stk::unit_test_util::MeshFixture
441 {
442 protected:
443 ShellMeshModification()
444 {
445 }
446
447 ~ShellMeshModification()
448 {
449 delete elemElemGraph;
450 }
451
452 void initialize(stk::mesh::BulkData::AutomaticAuraOption auraOption)
453 {
454 setup_empty_mesh(auraOption);
455 shellPart = &get_meta().declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
456 }
457
458 void create_shell2_on_lowest_rank_proc_and_setup_node_sharing()
459 {
460 get_bulk().modification_begin();
461 declare_shell2_on_lowest_rank_proc();
462 if (get_bulk().parallel_size()>1)
463 share_nodes();
464 get_bulk().modification_end();
465 }
466
467 void create_shell3_on_highest_rank_proc()
468 {
469 get_bulk().modification_begin();
470 declare_shell3_on_highest_rank_proc();
471 get_bulk().modification_end();
472 }
473
474 void create_stacked_shells()
475 {
476 get_bulk().modification_begin();
477 declare_shell2_on_lowest_rank_proc();
478 declare_shell3_on_highest_rank_proc();
479 if (get_bulk().parallel_size()>1)
480 share_nodes();
481 get_bulk().modification_end();
482 }
483
484 void delete_shell2()
485 {
486 get_bulk().modification_begin();
487 destroy_shell2();
488 get_bulk().modification_end();
489 }
490
491 void create_elem_elem_graph()
492 {
493 elemElemGraph = new ElemElemGraphTester(get_bulk());
494 updater = std::make_shared<stk::mesh::ElemElemGraphUpdater>(get_bulk(), *elemElemGraph);
495 get_bulk().register_observer(updater);
496 coincident_graph = &elemElemGraph->my_get_coincident_graph();
497 }
498
499 void verify_graph_for_stacked_shells()
500 {
501 size_t expectedNumElementsThisProcessor = 2u;
502 size_t expectedNumCoincidentElementsThisProcessor = 2u;
503 size_t expectedNumParallelEdges = 0u;
504 if (get_bulk().parallel_size()>1) {
505 expectedNumElementsThisProcessor = 1u;
506 expectedNumCoincidentElementsThisProcessor = 1u;
507 expectedNumParallelEdges = 2u;
508 }
509 verify_graph_has_num_elements_and_num_graph_edges(expectedNumElementsThisProcessor, 0u);
510 verify_num_elements_and_num_edges_in_coincident_graph(2u,6u);
511 verify_num_local_and_parallel_edges(0u, expectedNumParallelEdges);
512 verify_num_elements_and_num_edges_in_coincident_graph(expectedNumCoincidentElementsThisProcessor,6u);
513 }
514
515 void verify_graph_for_single_shell3_on_highest_rank_proc()
516 {
517 size_t numElementsThisProcessor = 1u;
518 if (get_bulk().parallel_size()>1 && get_bulk().parallel_rank()==0)
519 numElementsThisProcessor = 0u;
520 const size_t numCoincidentElementsThisProcessor = 0u;
521 verify_graph_has_num_elements_and_num_graph_edges(numElementsThisProcessor, 0u);
522 verify_num_elements_and_num_edges_in_coincident_graph(0u,0u);
523 verify_num_local_and_parallel_edges(0u, 0u);
524 verify_num_elements_and_num_edges_in_coincident_graph(numCoincidentElementsThisProcessor,2u);
525 }
526
527 void test_create_stacked_shells_then_delete_one(stk::mesh::BulkData::AutomaticAuraOption auraOption)
528 {
529 initialize(auraOption);
530 create_stacked_shells();
531 create_elem_elem_graph();
532 // elemElemGraph->write_graph("-------------- Graph after creating stacked shells --------------\n");
533 verify_graph_for_stacked_shells();
534 delete_shell2();
535 // elemElemGraph->write_graph("-------------- Graph after deleting one shell --------------\n");
536 verify_graph_for_single_shell3_on_highest_rank_proc();
537 }
538
539 void test_create_shell_then_create_another_one(stk::mesh::BulkData::AutomaticAuraOption auraOption)
540 {
541 initialize(auraOption);
542 create_shell3_on_highest_rank_proc();
543 create_elem_elem_graph();
544 // elemElemGraph->write_graph("-------------- Graph after creating one shell --------------\n");
545 verify_graph_for_single_shell3_on_highest_rank_proc();
546 create_shell2_on_lowest_rank_proc_and_setup_node_sharing();
547 // elemElemGraph->write_graph("-------------- Graph after creating second (stacked) shell --------------\n");
548 verify_graph_for_stacked_shells();
549 }
550
551 void create_and_delete_shell_in_same_mod_cycle()
552 {
553 get_bulk().modification_begin();
554 declare_shell2_on_lowest_rank_proc();
555 destroy_shell2();
556 get_bulk().modification_end();
557 }
558
559 void verify_empty_graph()
560 {
561 verify_graph_has_num_elements_and_num_graph_edges(0u,0u);
562 verify_num_elements_and_num_edges_in_coincident_graph(0u,0u);
563 }
564
565 private:
566 void verify_local_and_parallel_edges_from_entity_to_remote_entity(stk::mesh::Entity entity, stk::mesh::EntityId remoteEntityId,
567 size_t numLocalEdges, size_t numParallelEdges)
568 {
569 if(get_bulk().is_valid(entity) && get_bulk().bucket(entity).owned())
570 {
571 EXPECT_EQ(numLocalEdges, elemElemGraph->get_num_connected_elems(entity));
572 }
573 }
574
575 void verify_num_local_and_parallel_edges(size_t numLocalEdges, size_t numParallelEdges)
576 {
577 verify_local_and_parallel_edges_from_entity_to_remote_entity(shell2, 3u, numLocalEdges, numParallelEdges);
578 verify_local_and_parallel_edges_from_entity_to_remote_entity(shell3, 2u, numLocalEdges, numParallelEdges);
579 }
580
581 void verify_num_elements_and_num_edges_in_coincident_graph(size_t numCoincidentElements, size_t numEdgesToCoincidentElements)
582 {
583 EXPECT_EQ(numCoincidentElements, coincident_graph->get_num_elements_in_graph());
584 for(const stk::mesh::impl::SparseGraph::value_type& map_iter : *coincident_graph)
585 {
586 const std::vector<stk::mesh::GraphEdge>& coincident_edges = map_iter.second;
587 EXPECT_EQ(numEdgesToCoincidentElements, coincident_edges.size());
588 }
589 }
590
591 void verify_graph_has_num_elements_and_num_graph_edges(size_t numElementsInGraph, size_t numEdgesInGraph)
592 {
593 EXPECT_EQ(numElementsInGraph, elemElemGraph->size());
594 EXPECT_EQ(numEdgesInGraph, elemElemGraph->num_edges());
595 }
596
597 void share_nodes()
598 {
599 int other_proc = get_bulk().parallel_rank() == 0 ? 1 : 0;
600 get_bulk().add_node_sharing(get_bulk().get_entity(stk::topology::NODE_RANK,shellNodeIDs[0][0]),other_proc);
601 get_bulk().add_node_sharing(get_bulk().get_entity(stk::topology::NODE_RANK,shellNodeIDs[0][1]),other_proc);
602 get_bulk().add_node_sharing(get_bulk().get_entity(stk::topology::NODE_RANK,shellNodeIDs[0][2]),other_proc);
603 get_bulk().add_node_sharing(get_bulk().get_entity(stk::topology::NODE_RANK,shellNodeIDs[0][3]),other_proc);
604 }
605
606 void declare_shell2_on_lowest_rank_proc()
607 {
608 if (get_bulk().parallel_size()==1 || get_bulk().parallel_rank()==0 )
609 shell2 = stk::mesh::declare_element(get_bulk(), *shellPart, shellElemIDs[0], shellNodeIDs[0]);
610 }
611
612 void declare_shell3_on_highest_rank_proc()
613 {
614 if (get_bulk().parallel_size()==1 || get_bulk().parallel_rank()==1 )
615 shell3 = stk::mesh::declare_element(get_bulk(), *shellPart, shellElemIDs[1], shellNodeIDs[1]);
616 }
617
618 void destroy_shell2()
619 {
620 if (get_bulk().parallel_size()==1 || get_bulk().parallel_rank()==0 )
621 get_bulk().destroy_entity(shell2);
622 }
623
624
625 private:
626 stk::mesh::Part* shellPart = nullptr;
627 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
628 { 5, 6, 7, 8 },
629 { 5, 6, 7, 8 }
630 };
631 stk::mesh::EntityId shellElemIDs[2] = { 2, 3 };
632 stk::mesh::Entity shell2;
633 stk::mesh::Entity shell3;
634 ElemElemGraphTester* elemElemGraph = nullptr;
635 std::shared_ptr<stk::mesh::ElemElemGraphUpdater> updater;
636 const stk::mesh::impl::SparseGraph* coincident_graph = nullptr;
637 };
638 } // namespace
639
640
641 TEST_F(ShellMeshModification, CreateStackedShellsThenTestDeleteOne)
642 {
643 if (stk::parallel_machine_size(get_comm()) == 1)
644 {
645 test_create_stacked_shells_then_delete_one(stk::mesh::BulkData::AUTO_AURA);
646 }
647 }
648
649 // disabled due to split coincident elements
650 TEST_F( ShellMeshModification, DISABLED_CreateShellThenTestCreateAnotherShellAutoAura)
651 {
652 if (stk::parallel_machine_size(get_comm()) <= 2)
653 {
654 test_create_shell_then_create_another_one(stk::mesh::BulkData::AUTO_AURA);
655 }
656 }
657
658 // disabled due to split coincident elements
659 TEST_F( ShellMeshModification, DISABLED_CreateShellThenTestCreateAnotherShellNoAura)
660 {
661 if (stk::parallel_machine_size(get_comm()) == 2)
662 {
663 test_create_shell_then_create_another_one(stk::mesh::BulkData::NO_AUTO_AURA);
664 }
665 }
666
667 TEST_F( ShellMeshModification, CreateAndDeleteShellInSameModCycle)
668 {
669 if (stk::parallel_machine_size(get_comm()) == 1)
670 {
671 initialize(stk::mesh::BulkData::NO_AUTO_AURA);
672 create_elem_elem_graph();
673 EXPECT_NO_THROW(create_and_delete_shell_in_same_mod_cycle());
674 verify_empty_graph();
675 }
676 }
677
678
679 TEST( ElementGraph, HexShellShellSerial )
680 {
681 // ID.proc
682 //
683 // 3.0------------7.0
684 // /| /|
685 // / | / |
686 // / | / |
687 // 4.0------------8.0 |
688 // | | | |
689 // | | 1.0 |2.0|
690 // | | |3.0|
691 // | 2.0---------|--6.0
692 // | / | /
693 // | / | /
694 // |/ |/
695 // 1.0------------5.0
696 // ^
697 // |
698 // ---- Two stacked shell elements
699
700 stk::ParallelMachine pm = MPI_COMM_WORLD;
701 int p_size = stk::parallel_machine_size(pm);
702
703 if(p_size > 1)
704 {
705 GTEST_SKIP();
706 }
707
708 const unsigned spatialDim = 3;
709 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
710 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
711 stk::mesh::BulkData& mesh = *bulkPtr;
712
713 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
714 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
715 meta.commit();
716
717 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
718 { 1, 2, 3, 4, 5, 6, 7, 8 }
719 };
720 stk::mesh::EntityId hexElemIDs[] = { 1 };
721
722 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
723 { 5, 6, 7, 8 },
724 { 5, 6, 7, 8 }
725 };
726 stk::mesh::EntityId shellElemIDs[] = { 2, 3 };
727
728 mesh.modification_begin();
729 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
730 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
731 }
732 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
733 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
734 }
735 mesh.modification_end();
736
737 stk::mesh::ElemElemGraph elemElemGraph(mesh);
738
739 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
740 const stk::mesh::Entity shell2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
741 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
742
743 // Connectivity for Hex Element 1
744 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
745 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell2, 5);
746 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell3, 5);
747 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
748 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
749
750 // Connectivity for Shell Element 2
751 EXPECT_EQ(1u, elemElemGraph.get_num_connected_elems(shell2));
752 expect_correct_connected_element_via_side(elemElemGraph, shell2, 0, hex1, 1); //face
753 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 0); //coincident face
754 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 1); //coincident face
755 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 2); //coincident shell edge
756 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 3); //coincident shell edge
757 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 4); //coincident shell edge
758 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell2, shell3, 5); //coincident shell edge
759 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell2, 0));
760
761 // Connectivity for Shell Element 3
762 EXPECT_EQ(1u, elemElemGraph.get_num_connected_elems(shell3));
763 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1); //face
764 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 0); //coincident face
765 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 1); //coincident face
766 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 2); //coincident shell edge
767 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 3); //coincident shell edge
768 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 4); //coincident shell edge
769 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell2, 5); //coincident shell edge
770 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
771
772 EXPECT_EQ(4u, elemElemGraph.num_edges());
773 EXPECT_EQ(0u, elemElemGraph.num_parallel_edges());
774 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
775 }
776
777 TEST( ElementGraph, HexShellShellHexSerial )
778 {
779 // ID.proc
780 //
781 // 3.0------------7.0-----------11.0
782 // /| /| /|
783 // / | / | / |
784 // / | / | / |
785 // 4.0------------8.0-----------12.0 |
786 // | | | | | |
787 // | | 1.0 |3.0| 2.0 | |
788 // | | |4.0| | |
789 // | 2.0---------|--6.0---------|-10.0
790 // | / | / | /
791 // | / | / | /
792 // |/ |/ |/
793 // 1.0------------5.0------------9.0
794 // ^
795 // |
796 // ---- Two stacked shell elements
797
798 stk::ParallelMachine pm = MPI_COMM_WORLD;
799 int p_size = stk::parallel_machine_size(pm);
800
801 if(p_size > 1)
802 {
803 GTEST_SKIP();
804 }
805
806 const unsigned spatialDim = 3;
807 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
808 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
809 stk::mesh::BulkData& mesh = *bulkPtr;
810
811 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
812 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
813 meta.commit();
814
815 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
816 { 1, 2, 3, 4, 5, 6, 7, 8 },
817 { 5, 6, 7, 8, 9, 10, 11, 12 }
818 };
819 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
820
821 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
822 { 5, 6, 7, 8 },
823 { 5, 6, 7, 8 }
824 };
825 stk::mesh::EntityId shellElemIDs[] = { 3, 4 };
826
827 mesh.modification_begin();
828 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
829 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
830 }
831 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
832 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
833 }
834 mesh.modification_end();
835
836 stk::mesh::ElemElemGraph elemElemGraph(mesh);
837
838 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
839 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
840 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
841 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
842
843 // Connectivity for Hex Element 1
844 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
845 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell3, 5);
846 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell4, 5);
847 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
848 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
849
850 // Connectivity for Hex Element 2
851 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex2));
852 expect_correct_connected_element_via_side(elemElemGraph, hex2, 0, shell3, 4);
853 expect_correct_connected_element_via_side(elemElemGraph, hex2, 1, shell4, 4);
854 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 0));
855 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 1));
856
857 // Connectivity for Shell Element 3
858 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell3));
859 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1); //face
860 expect_correct_connected_element_via_side(elemElemGraph, shell3, 1, hex2, 0); //face
861 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 0); //coincident face
862 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 1); //coincident face
863 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
864 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
865 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
866 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
867 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
868 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 1));
869
870 // Connectivity for Shell Element 4
871 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell4));
872 expect_correct_connected_element_via_side(elemElemGraph, shell4, 0, hex1, 1); //face
873 expect_correct_connected_element_via_side(elemElemGraph, shell4, 1, hex2, 0); //face
874 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 0); //coincident face
875 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 1); //coincident face
876 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 2); //coincident shell edge
877 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 3); //coincident shell edge
878 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 4); //coincident shell edge
879 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 5); //coincident shell edge
880 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 0));
881 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 1));
882
883 EXPECT_EQ(8u, elemElemGraph.num_edges());
884 EXPECT_EQ(0u, elemElemGraph.num_parallel_edges());
885 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
886 }
887
888 TEST( ElementGraph, HexShellReversedShellHexSerial )
889 {
890 // ID.proc
891 //
892 // 3.0------------7.0-----------11.0
893 // /| /| /|
894 // / | / | / |
895 // / | / | / |
896 // 4.0------------8.0-----------12.0 |
897 // | | | | | |
898 // | | 1.0 |3.0| 2.0 | |
899 // | | |4.0| | |
900 // | 2.0---------|--6.0---------|-10.0
901 // | / | / | /
902 // | / | / | /
903 // |/ |/ |/
904 // 1.0------------5.0------------9.0
905 // ^
906 // |
907 // ---- Two stacked shell elements
908
909 stk::ParallelMachine pm = MPI_COMM_WORLD;
910 int p_size = stk::parallel_machine_size(pm);
911
912 if(p_size > 1)
913 {
914 GTEST_SKIP();
915 }
916
917 const unsigned spatialDim = 3;
918 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
919 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
920 stk::mesh::BulkData& mesh = *bulkPtr;
921
922 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
923 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
924 meta.commit();
925
926 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
927 { 1, 2, 3, 4, 5, 6, 7, 8 },
928 { 5, 6, 7, 8, 9, 10, 11, 12 }
929 };
930 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
931
932 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
933 { 5, 6, 7, 8 },
934 { 5, 8, 7, 6 }
935 };
936 stk::mesh::EntityId shellElemIDs[] = { 3, 4 };
937
938 mesh.modification_begin();
939 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
940 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
941 }
942 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
943 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
944 }
945 mesh.modification_end();
946
947 stk::mesh::ElemElemGraph elemElemGraph(mesh);
948
949 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
950 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
951 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
952 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
953
954 // Connectivity for Hex Element 1
955 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
956 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell3, 5);
957 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell4, 5);
958 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
959 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
960
961 // Connectivity for Hex Element 2
962 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex2));
963 expect_correct_connected_element_via_side(elemElemGraph, hex2, 0, shell3, 4);
964 expect_correct_connected_element_via_side(elemElemGraph, hex2, 1, shell4, 4);
965 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 0));
966 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 1));
967
968 // Connectivity for Shell Element 3
969 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell3));
970 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1);
971 expect_correct_connected_element_via_side(elemElemGraph, shell3, 1, hex2, 0);
972 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
973 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 1));
974 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
975 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
976 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
977 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
978
979 // Connectivity for Shell Element 4
980 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell4));
981 expect_correct_connected_element_via_side(elemElemGraph, shell4, 0, hex1, 0);
982 expect_correct_connected_element_via_side(elemElemGraph, shell4, 1, hex2, 1);
983 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 0));
984 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 1));
985 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 2); //coincident shell edge
986 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 3); //coincident shell edge
987 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 4); //coincident shell edge
988 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 5); //coincident shell edge
989
990 EXPECT_EQ(8u, elemElemGraph.num_edges());
991 EXPECT_EQ(0u, elemElemGraph.num_parallel_edges());
992 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
993 }
994
995 TEST( ElementGraph, Hex0Shell0Shell0Hex1Parallel )
996 {
997 // ID.proc
998 //
999 // 3.0------------7.0-----------11.1
1000 // /| /| /|
1001 // / | / | / |
1002 // / | / | / |
1003 // 4.0------------8.0-----------12.1 |
1004 // | | | | | |
1005 // | | 1.0 |3.0| 2.1 | |
1006 // | | |4.0| | |
1007 // | 2.0---------|--6.0---------|-10.1
1008 // | / | / | /
1009 // | / | / | /
1010 // |/ |/ |/
1011 // 1.0------------5.0------------9.1
1012 // ^
1013 // |
1014 // ---- Two stacked shells
1015
1016 stk::ParallelMachine pm = MPI_COMM_WORLD;
1017 unsigned p_size = stk::parallel_machine_size(pm);
1018 unsigned p_rank = stk::parallel_machine_rank(pm);
1019
1020 if(p_size != 2u)
1021 {
1022 GTEST_SKIP();
1023 }
1024
1025 const unsigned spatialDim = 3;
1026 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
1027 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
1028 stk::mesh::BulkData& mesh = *bulkPtr;
1029
1030 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
1031 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
1032 meta.commit();
1033
1034 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
1035 { 1, 2, 3, 4, 5, 6, 7, 8 },
1036 { 5, 6, 7, 8, 9, 10, 11, 12 }
1037 };
1038 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
1039 stk::mesh::EntityId hexElemOwningProc[] = { 0, 1 };
1040
1041 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
1042 { 5, 6, 7, 8 },
1043 { 5, 6, 7, 8 }
1044 };
1045 stk::mesh::EntityId shellElemIDs[] = { 3, 4 };
1046 stk::mesh::EntityId shellElemOwningProc[] = { 0, 0 };
1047
1048 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
1049 std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs
1050 {
1051 { 0, 5, 1 }, // proc 0
1052 { 0, 6, 1 },
1053 { 0, 7, 1 },
1054 { 0, 8, 1 },
1055 { 1, 5, 0 }, // proc 1
1056 { 1, 6, 0 },
1057 { 1, 7, 0 },
1058 { 1, 8, 0 }
1059 };
1060
1061 mesh.modification_begin();
1062 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
1063 if (hexElemOwningProc[i] == p_rank) {
1064 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
1065 }
1066 }
1067 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
1068 if (shellElemOwningProc[i] == p_rank) {
1069 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
1070 }
1071 }
1072 setup_node_sharing(mesh, shared_nodeIDs_and_procs );
1073 mesh.modification_end();
1074
1075 stk::mesh::ElemElemGraph elemElemGraph(mesh);
1076
1077 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
1078 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
1079 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
1080 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
1081
1082 if (p_rank == 0) {
1083 // Connectivity for Hex Element 1
1084 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
1085 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell3, 5);
1086 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell4, 5);
1087 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
1088 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
1089
1090 // Connectivity for Shell Element 3
1091 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell3));
1092 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1); // face connection
1093 EXPECT_EQ(0, elemElemGraph.get_connected_remote_id_and_via_side(shell3, 1).side);
1094 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(shell3, 1).id);
1095 EXPECT_TRUE (elemElemGraph.is_connected_elem_locally_owned(shell3, 0)); // connection to hex1 through face
1096 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell3, 1)); // connection to hex2 through face
1097 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
1098 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
1099 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
1100 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
1101
1102 // Connectivity for Shell Element 4
1103 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell4));
1104 expect_correct_connected_element_via_side(elemElemGraph, shell4, 0, hex1, 1); // face connection
1105 EXPECT_EQ(0, elemElemGraph.get_connected_remote_id_and_via_side(shell4, 1).side);
1106 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(shell4, 1).id);
1107 EXPECT_TRUE (elemElemGraph.is_connected_elem_locally_owned(shell4, 0)); // connection to hex1 through face
1108 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell4, 1)); // connection to hex2 through face
1109
1110 EXPECT_EQ(6u, elemElemGraph.num_edges());
1111 EXPECT_EQ(2u, elemElemGraph.num_parallel_edges());
1112 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
1113 }
1114 else if (p_rank == 1) {
1115 // Connectivity for Hex Element 2
1116 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex2));
1117 EXPECT_EQ(4, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 0).side);
1118 EXPECT_EQ(4, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 1).side);
1119 EXPECT_EQ(3u, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 0).id);
1120 EXPECT_EQ(4u, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 1).id);
1121 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex2, 0));
1122 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex2, 1));
1123
1124 EXPECT_EQ(2u, elemElemGraph.num_edges());
1125 EXPECT_EQ(2u, elemElemGraph.num_parallel_edges());
1126 EXPECT_EQ(0u, elemElemGraph.num_coincident_edges());
1127 }
1128 }
1129
1130 TEST( ElementGraph, Hex0Shell0ReversedShell0Hex1Parallel )
1131 {
1132 // ID.proc
1133 //
1134 // 3.0------------7.0-----------11.1
1135 // /| /| /|
1136 // / | / | / |
1137 // / | / | / |
1138 // 4.0------------8.0-----------12.1 |
1139 // | | | | | |
1140 // | | 1.0 |3.0| 2.1 | |
1141 // | | |4.0| | |
1142 // | 2.0---------|--6.0---------|-10.1
1143 // | / | / | /
1144 // | / | / | /
1145 // |/ |/ |/
1146 // 1.0------------5.0------------9.1
1147 // ^
1148 // |
1149 // ---- Two stacked shells, opposite orientation
1150
1151 stk::ParallelMachine pm = MPI_COMM_WORLD;
1152 unsigned p_size = stk::parallel_machine_size(pm);
1153 unsigned p_rank = stk::parallel_machine_rank(pm);
1154
1155 if(p_size != 2u)
1156 {
1157 GTEST_SKIP();
1158 }
1159
1160 const unsigned spatialDim = 3;
1161 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
1162 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
1163 stk::mesh::BulkData& mesh = *bulkPtr;
1164
1165 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
1166 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
1167 meta.commit();
1168
1169 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
1170 { 1, 2, 3, 4, 5, 6, 7, 8 },
1171 { 5, 6, 7, 8, 9, 10, 11, 12 }
1172 };
1173 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
1174 stk::mesh::EntityId hexElemOwningProc[] = { 0, 1 };
1175
1176 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
1177 { 5, 6, 7, 8 },
1178 { 5, 8, 7, 6 }
1179 };
1180 stk::mesh::EntityId shellElemIDs[] = { 3, 4 };
1181 stk::mesh::EntityId shellElemOwningProc[] = { 0, 0 };
1182
1183 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
1184 std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs
1185 {
1186 { 0, 5, 1 }, // proc 0
1187 { 0, 6, 1 },
1188 { 0, 7, 1 },
1189 { 0, 8, 1 },
1190 { 1, 5, 0 }, // proc 1
1191 { 1, 6, 0 },
1192 { 1, 7, 0 },
1193 { 1, 8, 0 }
1194 };
1195
1196 mesh.modification_begin();
1197 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
1198 if (hexElemOwningProc[i] == p_rank) {
1199 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
1200 }
1201 }
1202 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
1203 if (shellElemOwningProc[i] == p_rank) {
1204 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
1205 }
1206 }
1207 setup_node_sharing(mesh, shared_nodeIDs_and_procs );
1208 mesh.modification_end();
1209
1210 stk::mesh::ElemElemGraph elemElemGraph(mesh);
1211
1212 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
1213 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
1214 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
1215 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
1216
1217 if (p_rank == 0) {
1218 // Connectivity for Hex Element 1
1219 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
1220 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, shell3, 5);
1221 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell4, 5);
1222 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
1223 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
1224
1225 // Connectivity for Shell Element 3
1226 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell3));
1227 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1);
1228 EXPECT_EQ(0, elemElemGraph.get_connected_remote_id_and_via_side(shell3, 1).side);
1229 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(shell3, 1).id);
1230 EXPECT_TRUE (elemElemGraph.is_connected_elem_locally_owned(shell3, 0)); // connection to hex1 through face
1231 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell3, 1)); // connection to hex2 through face
1232 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
1233 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
1234 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
1235 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
1236
1237 // Connectivity for Shell Element 4
1238 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell4));
1239 expect_correct_connected_element_via_side(elemElemGraph, shell4, 0, hex1, 0);
1240 EXPECT_EQ(1, elemElemGraph.get_connected_remote_id_and_via_side(shell4, 1).side);
1241 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(shell4, 1).id);
1242 EXPECT_TRUE (elemElemGraph.is_connected_elem_locally_owned(shell4, 0)); // connection to hex1 through face
1243 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell4, 1)); // connection to hex2 through face
1244 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 2); //coincident shell edge
1245 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 3); //coincident shell edge
1246 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 4); //coincident shell edge
1247 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 5); //coincident shell edge
1248
1249 EXPECT_EQ(6u, elemElemGraph.num_edges());
1250 EXPECT_EQ(2u, elemElemGraph.num_parallel_edges());
1251 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
1252 }
1253 else if (p_rank == 1) {
1254 // Connectivity for Hex Element 2
1255 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex2));
1256 EXPECT_EQ(3u, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 0).id);
1257 EXPECT_EQ(4, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 0).side);
1258 EXPECT_EQ(4u, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 1).id);
1259 EXPECT_EQ(4, elemElemGraph.get_connected_remote_id_and_via_side(hex2, 1).side);
1260 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex2, 0));
1261 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex2, 1));
1262 EXPECT_EQ(2u, elemElemGraph.num_edges());
1263 EXPECT_EQ(2u, elemElemGraph.num_parallel_edges());
1264 EXPECT_EQ(0u, elemElemGraph.num_coincident_edges());
1265 }
1266 }
1267
1268 TEST( ElementGraph, Hex1Shell0Shell0Hex1Parallel )
1269 {
1270 // ID.proc
1271 //
1272 // 3.0------------7.1-----------11.1
1273 // /| /| /|
1274 // / | / | / |
1275 // / | / | / |
1276 // 4.0------------8.1-----------12.1 |
1277 // | | | | | |
1278 // | | 1.1 |3.0| 2.1 | |
1279 // | | |4.0| | |
1280 // | 2.0---------|--6.1---------|-10.1
1281 // | / | / | /
1282 // | / | / | /
1283 // |/ |/ |/
1284 // 1.0------------5.1------------9.1
1285 // ^
1286 // |
1287 // ---- Two stacked shells
1288
1289 stk::ParallelMachine pm = MPI_COMM_WORLD;
1290 unsigned p_size = stk::parallel_machine_size(pm);
1291 unsigned p_rank = stk::parallel_machine_rank(pm);
1292
1293 if(p_size != 2u)
1294 {
1295 GTEST_SKIP();
1296 }
1297
1298 const unsigned spatialDim = 3;
1299 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
1300 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
1301 stk::mesh::BulkData& mesh = *bulkPtr;
1302
1303 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
1304 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
1305 meta.commit();
1306
1307 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
1308 { 1, 2, 3, 4, 5, 6, 7, 8 },
1309 { 5, 6, 7, 8, 9, 10, 11, 12 }
1310 };
1311 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
1312 stk::mesh::EntityId hexElemOwningProc[] = { 1, 1 };
1313
1314 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
1315 { 5, 6, 7, 8 },
1316 { 5, 6, 7, 8 }
1317 };
1318 stk::mesh::EntityId shellElemIDs[] = { 3, 4 };
1319 stk::mesh::EntityId shellElemOwningProc[] = { 0, 0 };
1320
1321 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
1322 std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs
1323 {
1324 { 0, 5, 1 }, // proc 0
1325 { 0, 6, 1 },
1326 { 0, 7, 1 },
1327 { 0, 8, 1 },
1328 { 1, 5, 0 }, // proc 1
1329 { 1, 6, 0 },
1330 { 1, 7, 0 },
1331 { 1, 8, 0 }
1332 };
1333
1334 mesh.modification_begin();
1335 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
1336 if (hexElemOwningProc[i] == p_rank) {
1337 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
1338 }
1339 }
1340 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
1341 if (shellElemOwningProc[i] == p_rank) {
1342 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
1343 }
1344 }
1345 setup_node_sharing(mesh, shared_nodeIDs_and_procs );
1346 mesh.modification_end();
1347
1348 stk::mesh::ElemElemGraph elemElemGraph(mesh);
1349
1350 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
1351 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
1352 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
1353 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
1354
1355 if (p_rank == 0) {
1356 // Connectivity for Shell Element 3
1357 size_t hex1Index = 0;
1358 size_t hex2Index = 1;
1359 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell3));
1360 EXPECT_EQ(0, elemElemGraph.get_connected_remote_id_and_via_side(shell3, hex2Index).side);
1361 EXPECT_EQ(1, elemElemGraph.get_connected_remote_id_and_via_side(shell3, hex1Index).side);
1362 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(shell3, hex2Index).id);
1363 EXPECT_EQ(1u, elemElemGraph.get_connected_remote_id_and_via_side(shell3, hex1Index).id);
1364 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell3, hex2Index));
1365 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell3, hex1Index));
1366 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
1367 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
1368 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
1369 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
1370
1371 // Connectivity for Shell Element 4
1372 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(shell4));
1373 EXPECT_EQ(0, elemElemGraph.get_connected_remote_id_and_via_side(shell4, hex2Index).side);
1374 EXPECT_EQ(1, elemElemGraph.get_connected_remote_id_and_via_side(shell4, hex1Index).side);
1375 EXPECT_EQ(2u, elemElemGraph.get_connected_remote_id_and_via_side(shell4, hex2Index).id);
1376 EXPECT_EQ(1u, elemElemGraph.get_connected_remote_id_and_via_side(shell4, hex1Index).id);
1377 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell4, hex2Index));
1378 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(shell4, hex1Index));
1379 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 2); //coincident shell edge
1380 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 3); //coincident shell edge
1381 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 4); //coincident shell edge
1382 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 5); //coincident shell edge
1383
1384 EXPECT_EQ(12u, elemElemGraph.num_coincident_edges());
1385 }
1386 else if (p_rank == 1) {
1387 size_t shell3Index = 0;
1388 size_t shell4Index = 1;
1389 // Connectivity for Hex Element 1
1390 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex1));
1391 EXPECT_EQ(5, elemElemGraph.get_connected_remote_id_and_via_side(hex1, shell3Index).side);
1392 EXPECT_EQ(5, elemElemGraph.get_connected_remote_id_and_via_side(hex1, shell4Index).side);
1393 EXPECT_EQ(3u, elemElemGraph.get_connected_remote_id_and_via_side(hex1, shell3Index).id);
1394 EXPECT_EQ(4u, elemElemGraph.get_connected_remote_id_and_via_side(hex1, shell4Index).id);
1395 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex1, shell3Index));
1396 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex1, shell4Index));
1397
1398 // Connectivity for Hex Element 2
1399 EXPECT_EQ(2u, elemElemGraph.get_num_connected_elems(hex2));
1400 EXPECT_EQ(4, elemElemGraph.get_connected_remote_id_and_via_side(hex2, shell3Index).side);
1401 EXPECT_EQ(4, elemElemGraph.get_connected_remote_id_and_via_side(hex2, shell4Index).side);
1402 EXPECT_EQ(3u, elemElemGraph.get_connected_remote_id_and_via_side(hex2, shell3Index).id);
1403 EXPECT_EQ(4u, elemElemGraph.get_connected_remote_id_and_via_side(hex2, shell4Index).id);
1404 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex2, shell3Index));
1405 EXPECT_FALSE(elemElemGraph.is_connected_elem_locally_owned(hex2, shell4Index));
1406
1407 EXPECT_EQ(0u, elemElemGraph.num_coincident_edges());
1408 }
1409
1410 EXPECT_EQ(4u, elemElemGraph.num_edges());
1411 EXPECT_EQ(4u, elemElemGraph.num_parallel_edges());
1412 }
1413
1414 TEST( ElementGraph, AdjacentHexStackedShellSerial )
1415 {
1416 // ID.proc
1417 //
1418 // 12.0-----------11.0
1419 // /| /|
1420 // / | / |
1421 // / | / |
1422 // 9.0-----------10.0 |
1423 // | | | |
1424 // | | 2.0 |5.0,6.0
1425 // | | | |
1426 // | 8.0---------|--7.0
1427 // | /| | /|
1428 // | / | | / |
1429 // |/ | |/ |
1430 // 5.0------------6.0 |
1431 // | | | |
1432 // | | 1.0 |3.0,4.0
1433 // | | | |
1434 // | 4.0---------|--3.0
1435 // | / | /
1436 // | / | /
1437 // |/ |/
1438 // 1.0------------2.0
1439 // ^
1440 // |
1441 // ---- Stacked shell elements
1442
1443 stk::ParallelMachine pm = MPI_COMM_WORLD;
1444 int p_size = stk::parallel_machine_size(pm);
1445
1446 if(p_size > 1)
1447 {
1448 GTEST_SKIP();
1449 }
1450
1451 const unsigned spatialDim = 3;
1452 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
1453 stk::mesh::BulkData& mesh = *bulkPtr;
1454 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
1455
1456 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
1457 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
1458 meta.commit();
1459
1460 std::vector<stk::mesh::EntityIdVector> hexNodeIDs {
1461 { 1, 2, 3, 4, 5, 6, 7, 8 },
1462 { 5, 6, 7, 8, 9, 10, 11, 12 }
1463 };
1464 stk::mesh::EntityId hexElemIDs[] = { 1, 2 };
1465
1466 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
1467 { 2, 3, 7, 6 },
1468 { 2, 3, 7, 6 },
1469 { 6, 7, 11, 10 },
1470 { 6, 7, 11, 10 },
1471 };
1472 stk::mesh::EntityId shellElemIDs[] = { 3, 4, 5, 6 };
1473
1474 mesh.modification_begin();
1475 for (size_t i = 0; i < hexNodeIDs.size(); ++i) {
1476 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
1477 }
1478 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
1479 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
1480 }
1481 mesh.modification_end();
1482
1483 stk::mesh::ElemElemGraph elemElemGraph(mesh);
1484
1485 const stk::mesh::Entity hex1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
1486 const stk::mesh::Entity hex2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
1487 const stk::mesh::Entity shell3 = mesh.get_entity(stk::topology::ELEM_RANK, 3);
1488 const stk::mesh::Entity shell4 = mesh.get_entity(stk::topology::ELEM_RANK, 4);
1489 const stk::mesh::Entity shell5 = mesh.get_entity(stk::topology::ELEM_RANK, 5);
1490 const stk::mesh::Entity shell6 = mesh.get_entity(stk::topology::ELEM_RANK, 6);
1491
1492 // Connectivity for Hex Element 1
1493 EXPECT_EQ(3u, elemElemGraph.get_num_connected_elems(hex1));
1494 expect_correct_connected_element_via_side(elemElemGraph, hex1, 0, hex2, 5);
1495 expect_correct_connected_element_via_side(elemElemGraph, hex1, 1, shell3, 1);
1496 expect_correct_connected_element_via_side(elemElemGraph, hex1, 2, shell4, 1);
1497 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 0));
1498 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 1));
1499 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex1, 2));
1500
1501 // Connectivity for Hex Element 2
1502 EXPECT_EQ(3u, elemElemGraph.get_num_connected_elems(hex2));
1503 expect_correct_connected_element_via_side(elemElemGraph, hex2, 0, hex1, 4);
1504 expect_correct_connected_element_via_side(elemElemGraph, hex2, 1, shell5, 1);
1505 expect_correct_connected_element_via_side(elemElemGraph, hex2, 2, shell6, 1);
1506 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 0));
1507 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 1));
1508 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(hex2, 2));
1509
1510 // Connectivity for Shell Element 3
1511 EXPECT_EQ(3u, elemElemGraph.get_num_connected_elems(shell3));
1512 expect_correct_connected_element_via_side(elemElemGraph, shell3, 0, hex1, 1);
1513 expect_correct_connected_element_via_side(elemElemGraph, shell3, 1, shell5, 4); // edge
1514 expect_correct_connected_element_via_side(elemElemGraph, shell3, 2, shell6, 4); // edge
1515 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 0));
1516 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 1)); // connected to shell5 through edge
1517 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell3, 2)); // connected to shell6 through edge
1518 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 0); //coincident shell face
1519 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 1); //coincident shell face
1520 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 2); //coincident shell edge
1521 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 3); //coincident shell edge
1522 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 4); //coincident shell edge
1523 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell3, shell4, 5); //coincident shell edge
1524
1525 // Connectivity for Shell Element 4
1526 EXPECT_EQ(3u, elemElemGraph.get_num_connected_elems(shell4));
1527 expect_correct_connected_element_via_side(elemElemGraph, shell4, 0, hex1, 1);
1528 expect_correct_connected_element_via_side(elemElemGraph, shell4, 1, shell5, 4); // edge
1529 expect_correct_connected_element_via_side(elemElemGraph, shell4, 2, shell6, 4); // edge
1530 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 0));
1531 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 1)); // connected to shell5 through edge
1532 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell4, 2)); // connected to shell6 through edge
1533 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 0); //coincident shell face
1534 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 1); //coincident shell face
1535 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 2); //coincident shell edge
1536 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 3); //coincident shell edge
1537 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 4); //coincident shell edge
1538 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell4, shell3, 5); //coincident shell edge
1539
1540 // Connectivity for Shell Element 5
1541 EXPECT_EQ(3u, elemElemGraph.get_num_connected_elems(shell5));
1542 expect_correct_connected_element_via_side(elemElemGraph, shell5, 0, hex2, 1);
1543 expect_correct_connected_element_via_side(elemElemGraph, shell5, 1, shell3, 2); // edge
1544 expect_correct_connected_element_via_side(elemElemGraph, shell5, 2, shell4, 2); // edge
1545 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell5, 0));
1546 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell5, 1)); // connected to shell3 through edge
1547 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell5, 2)); // connected to shell4 through edge
1548 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell5, shell6, 0); //coincident shell face
1549 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell5, shell6, 1); //coincident shell face
1550 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell5, shell6, 2); //coincident shell edge
1551 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell5, shell6, 3); //coincident shell edge
1552 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell5, shell6, 4); //coincident shell edge
1553 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell5, shell6, 5); //coincident shell edge
1554
1555 // Connectivity for Shell Element 6
1556 EXPECT_EQ(3u, elemElemGraph.get_num_connected_elems(shell6));
1557 expect_correct_connected_element_via_side(elemElemGraph, shell6, 0, hex2, 1);
1558 expect_correct_connected_element_via_side(elemElemGraph, shell6, 1, shell3, 2); // edge
1559 expect_correct_connected_element_via_side(elemElemGraph, shell6, 2, shell4, 2); // edge
1560 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell6, 0));
1561 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell6, 1)); // connected to shell3 through edge
1562 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell6, 2)); // connected to shell4 through edge
1563 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell6, shell5, 0); //coincident shell face
1564 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell6, shell5, 1); //coincident shell face
1565 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell6, shell5, 2); //coincident shell edge
1566 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell6, shell5, 3); //coincident shell edge
1567 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell6, shell5, 4); //coincident shell edge
1568 expect_correct_connected_coincident_element_via_side(elemElemGraph, shell6, shell5, 5); //coincident shell edge
1569
1570 EXPECT_EQ(18u, elemElemGraph.num_edges());
1571 EXPECT_EQ( 0u, elemElemGraph.num_parallel_edges());
1572 EXPECT_EQ(24u, elemElemGraph.num_coincident_edges());
1573 }
1574
1575 TEST( ElementGraph, BeamShellSerial )
1576 {
1577 // ID.proc
1578 //
1579 // 4.0------------3.0
1580 // | |
1581 // | |
1582 // | |
1583 // | |
1584 // | |
1585 // | |
1586 // | |
1587 // 1.0------------2.0
1588 // ^ ^
1589 // | |
1590 // | ---- Shell element
1591 // |
1592 // -----Beam element
1593
1594 stk::ParallelMachine pm = MPI_COMM_WORLD;
1595 int p_size = stk::parallel_machine_size(pm);
1596
1597 if(p_size > 1)
1598 {
1599 GTEST_SKIP();
1600 }
1601
1602 const unsigned spatialDim = 3;
1603 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
1604 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
1605 stk::mesh::BulkData& mesh = *bulkPtr;
1606
1607 stk::mesh::Part * beamPart = &meta.declare_part_with_topology("beam_part", stk::topology::BEAM_2);
1608 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
1609 meta.commit();
1610
1611 std::vector<stk::mesh::EntityIdVector> beamNodeIDs {
1612 { 1, 4 }
1613 };
1614 stk::mesh::EntityId beamElemIDs[] = { 1 };
1615
1616 std::vector<stk::mesh::EntityIdVector> shellNodeIDs {
1617 { 1, 2, 3, 4 }
1618 };
1619 stk::mesh::EntityId shellElemIDs[] = { 2 };
1620
1621 mesh.modification_begin();
1622 for (size_t i = 0; i < beamNodeIDs.size(); ++i) {
1623 stk::mesh::declare_element(mesh, *beamPart, beamElemIDs[i], beamNodeIDs[i]);
1624 }
1625 for (size_t i = 0; i < shellNodeIDs.size(); ++i) {
1626 stk::mesh::declare_element(mesh, *shellPart, shellElemIDs[i], shellNodeIDs[i]);
1627 }
1628 mesh.modification_end();
1629
1630 stk::mesh::ElemElemGraph elemElemGraph(mesh);
1631
1632 const stk::mesh::Entity beam1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
1633 const stk::mesh::Entity shell2 = mesh.get_entity(stk::topology::ELEM_RANK, 2);
1634
1635 // Connectivity for Beam Element 1
1636 EXPECT_EQ(1u, elemElemGraph.get_num_connected_elems(beam1));
1637 expect_correct_connected_element_via_side(elemElemGraph, beam1, 0, shell2, 0);
1638 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(beam1, 0));
1639
1640 // Connectivity for Shell Element 2
1641 EXPECT_EQ(1u, elemElemGraph.get_num_connected_elems(shell2));
1642 expect_correct_connected_element_via_side(elemElemGraph, shell2, 0, beam1, 5);
1643 EXPECT_TRUE(elemElemGraph.is_connected_elem_locally_owned(shell2, 0));
1644
1645 EXPECT_EQ(2u, elemElemGraph.num_edges());
1646 EXPECT_EQ(0u, elemElemGraph.num_parallel_edges());
1647 EXPECT_EQ(0u, elemElemGraph.num_coincident_edges());
1648 }
1649
1650 }