Debian Codegraph @

packages/stk/stk_unit_tests/stk_tools/mesh_tools/UnitTestDisconnectBlocks.cpp

raw
1 #include "stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp"
2 #include "stk_unit_test_utils/getOption.h"
3 #include "DisconnectBlocksMeshConstruction.hpp"
4 #include "stk_util/parallel/ParallelReduce.hpp"
5 #include "stk_util/util/SortAndUnique.hpp"
6 #include <algorithm>
7 #include <fstream>
8 #include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc
9 #include <libgen.h>
10 #include <stk_io/FillMesh.hpp>
11 #include <stk_io/StkMeshIoBroker.hpp>
12 #include <stk_io/WriteMesh.hpp>
13 #include <stk_mesh/base/BulkData.hpp>
14 #include <stk_mesh/base/GetEntities.hpp>
15 #include <stk_mesh/base/MetaData.hpp> // for MetaData
16 #include <stk_mesh/base/SkinBoundary.hpp>
17 #include <stk_mesh/base/DumpMeshInfo.hpp>
18 #include <stk_tools/mesh_tools/DetectHingesImpl.hpp>
19 #include <stk_tools/mesh_tools/DisconnectBlocks.hpp>
20 #include <stk_tools/mesh_tools/DisconnectBlocksImpl.hpp>
21 #include <stk_tools/mesh_tools/DisconnectUtils.hpp>
22 #include <stk_unit_test_utils/MeshFixture.hpp>
23 #include <stk_unit_test_utils/TextMesh.hpp>
24 #include <stk_unit_test_utils/ConstructedMesh.hpp>
25 #include <stk_unit_test_utils/BuildMesh.hpp>
26 #include <stk_util/environment/WallTime.hpp>
27 #include <string>
28
29 using stk::unit_test_util::build_mesh;
30
31 class TestDisconnectBlocks2D : public stk::unit_test_util::MeshFixture
32 {
33 protected:
34 TestDisconnectBlocks2D() : stk::unit_test_util::MeshFixture(2)
35 {
36 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
37 }
38 };
39
40 TEST_F(TestDisconnectBlocks2D, disconnect_1block_1quad)
41 {
42 stk::mesh::PartVector blocks = setup_mesh_1block_1quad(get_bulk());
43
44 stk::tools::disconnect_all_blocks(get_bulk());
45
46 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
47 EXPECT_EQ(4u, get_num_total_nodes(get_bulk()));
48 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
49
50 output_mesh(get_bulk(), "disconnect_1block_1quad.g");
51 }
52
53 TEST_F(TestDisconnectBlocks2D, disconnect_user_block_1block_1quad_empty_part)
54 {
55 stk::mesh::Part & block2 = create_part(get_meta(), stk::topology::QUAD_4_2D, "block_2", 2);
56 stk::mesh::PartVector blocks = setup_mesh_1block_1quad(get_bulk());
57
58 stk::tools::BlockPairVector blocksToDisconnect;
59 blocksToDisconnect.emplace_back(blocks[0], &block2);
60
61 EXPECT_NO_THROW(stk::tools::disconnect_user_blocks(get_bulk(), blocksToDisconnect, stk::tools::SNIP_ALL_HINGES));
62 }
63
64 TEST_F(TestDisconnectBlocks2D, disconnect_2block_1quad)
65 {
66 stk::mesh::PartVector blocks = setup_mesh_2block_1quad(get_bulk());
67
68 stk::tools::disconnect_all_blocks(get_bulk());
69
70 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
71 EXPECT_EQ(4u, get_num_total_nodes(get_bulk()));
72 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
73
74 output_mesh(get_bulk(), "disconnect_2block_1quad.g");
75 }
76
77 TEST_F(TestDisconnectBlocks2D, disconnect_2block_2quad)
78 {
79 stk::mesh::PartVector blocks = setup_mesh_2block_2quad(get_bulk());
80
81 output_mesh(get_bulk(), "disconnect_2block_2quad_init.g");
82
83 stk::tools::disconnect_all_blocks(get_bulk());
84
85 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
86 EXPECT_EQ(8u, get_num_total_nodes(get_bulk()));
87 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
88
89 output_mesh(get_bulk(), "disconnect_2block_2quad.g");
90 }
91
92 TEST_F(TestDisconnectBlocks2D, disconnect_user_blocks_2block_2quad_in_reverse_block_order)
93 {
94 stk::mesh::PartVector blocks = setup_mesh_2block_2quad(get_bulk());
95 stk::tools::BlockPairVector blocksToDisconnect;
96 blocksToDisconnect.emplace_back(blocks[1], blocks[0]);
97
98 EXPECT_NO_THROW(stk::tools::disconnect_user_blocks(get_bulk(), blocksToDisconnect, stk::tools::SNIP_ALL_HINGES));
99 }
100
101 TEST_F(TestDisconnectBlocks2D, disconnect_2block_2quad_updateGraph)
102 {
103 stk::mesh::PartVector blocks = setup_mesh_2block_2quad(get_bulk());
104
105 get_bulk().initialize_face_adjacent_element_graph();
106 stk::tools::disconnect_all_blocks(get_bulk());
107
108 const stk::mesh::Entity elem1 = get_bulk().get_entity(stk::topology::ELEM_RANK, 1);
109 const stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2);
110 if (get_bulk().is_valid(elem1)) {
111 EXPECT_EQ(0u, get_bulk().get_face_adjacent_element_graph().get_num_connected_elems(elem1));
112 }
113 if (get_bulk().is_valid(elem2)) {
114 EXPECT_EQ(0u, get_bulk().get_face_adjacent_element_graph().get_num_connected_elems(elem2));
115 }
116
117 create_all_sides(get_bulk(), get_meta().locally_owned_part(), {&get_meta().get_topology_root_part(stk::topology::LINE_2)}, false);
118
119 unsigned localNumSides = stk::mesh::count_selected_entities(get_meta().locally_owned_part(), get_bulk().buckets(stk::topology::EDGE_RANK));
120 unsigned numSides = stk::get_global_sum(get_bulk().parallel(), localNumSides);
121 EXPECT_EQ(8u, numSides);
122 }
123
124 TEST_F(TestDisconnectBlocks2D, disconnect_2block_2quad_reversed)
125 {
126 stk::mesh::PartVector blocks = setup_mesh_2block_2quad_reversed(get_bulk());
127
128 output_mesh(get_bulk(), "disconnect_2block_2quad_reversed_init.g");
129
130 stk::tools::disconnect_all_blocks(get_bulk());
131
132 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
133 EXPECT_EQ(8u, get_num_total_nodes(get_bulk()));
134 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
135
136 output_mesh(get_bulk(), "disconnect_2block_2quad_reversed.g");
137 }
138
139 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_corner_decomp1)
140 {
141 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 1);
142
143 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp1_init.g");
144
145 stk::tools::disconnect_all_blocks(get_bulk());
146
147 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
148 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
149 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
150
151 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp1.g");
152 }
153
154 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_corner_decomp2)
155 {
156 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 2);
157
158 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp2_init.g");
159
160 stk::tools::disconnect_all_blocks(get_bulk());
161
162 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
163 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
164 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
165
166 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp2.g");
167 }
168
169 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_corner_decomp3)
170 {
171 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 3);
172
173 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp3_init.g");
174
175 stk::tools::disconnect_all_blocks(get_bulk());
176
177 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
178 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
179 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
180
181 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp3.g");
182 }
183
184 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_corner_decomp4)
185 {
186 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 4);
187
188 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp4_init.g");
189
190 stk::tools::disconnect_all_blocks(get_bulk());
191
192 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
193 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
194 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
195
196 output_mesh(get_bulk(), "disconnect_2block_4quad_corner_decomp4.g");
197 }
198
199 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_swappedCorner_decomp1)
200 {
201 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 1);
202
203 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp1_init.g");
204
205 stk::tools::disconnect_all_blocks(get_bulk());
206
207 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
208 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
209 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
210
211 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp1.g");
212 }
213
214 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_swappedCorner_decomp2)
215 {
216 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 2);
217
218 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp2_init.g");
219
220 stk::tools::disconnect_all_blocks(get_bulk());
221
222 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
223 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
224 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
225
226 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp2.g");
227 }
228
229 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_swappedCorner_decomp3)
230 {
231 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 3);
232
233 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp3_init.g");
234
235 stk::tools::disconnect_all_blocks(get_bulk());
236
237 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
238 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
239 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
240
241 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp3.g");
242 }
243
244 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_swappedCorner_decomp4)
245 {
246 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 4);
247
248 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp4_init.g");
249
250 stk::tools::disconnect_all_blocks(get_bulk());
251
252 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
253 EXPECT_EQ(12u, get_num_total_nodes(get_bulk()));
254 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
255
256 output_mesh(get_bulk(), "disconnect_2block_4quad_swappedCorner_decomp4.g");
257 }
258
259 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder1_decomp1)
260 {
261 test_mesh_3block_4quad(get_bulk(), 1, 1);
262 }
263
264 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder1_decomp2)
265 {
266 test_mesh_3block_4quad(get_bulk(), 1, 2);
267 }
268
269 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder1_decomp3)
270 {
271 test_mesh_3block_4quad(get_bulk(), 1, 3);
272 }
273
274 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder2_decomp1)
275 {
276 test_mesh_3block_4quad(get_bulk(), 2, 1);
277 }
278
279 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder2_decomp2)
280 {
281 test_mesh_3block_4quad(get_bulk(), 2, 2);
282 }
283
284 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder2_decomp3)
285 {
286 test_mesh_3block_4quad(get_bulk(), 2, 3);
287 }
288
289 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder3_decomp1)
290 {
291 test_mesh_3block_4quad(get_bulk(), 3, 1);
292 }
293
294 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder3_decomp2)
295 {
296 test_mesh_3block_4quad(get_bulk(), 3, 2);
297 }
298
299 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder3_decomp3)
300 {
301 test_mesh_3block_4quad(get_bulk(), 3, 3);
302 }
303
304 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder4_decomp1)
305 {
306 test_mesh_3block_4quad(get_bulk(), 4, 1);
307 }
308
309 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder4_decomp2)
310 {
311 test_mesh_3block_4quad(get_bulk(), 4, 2);
312 }
313
314 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder4_decomp3)
315 {
316 test_mesh_3block_4quad(get_bulk(), 4, 3);
317 }
318
319 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder5_decomp1)
320 {
321 test_mesh_3block_4quad(get_bulk(), 5, 1);
322 }
323
324 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder5_decomp2)
325 {
326 test_mesh_3block_4quad(get_bulk(), 5, 2);
327 }
328
329 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder5_decomp3)
330 {
331 test_mesh_3block_4quad(get_bulk(), 5, 3);
332 }
333
334 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder6_decomp1)
335 {
336 test_mesh_3block_4quad(get_bulk(), 6, 1);
337 }
338
339 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder6_decomp2)
340 {
341 test_mesh_3block_4quad(get_bulk(), 6, 2);
342 }
343
344 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_blockOrder6_decomp3)
345 {
346 test_mesh_3block_4quad(get_bulk(), 6, 3);
347 }
348
349 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_keepLowerRight_decomp1)
350 {
351 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 1);
352
353 output_mesh(get_bulk(), "disconnect_3block_4quad_keepLowerRight_decomp1_init.g");
354
355 stk::tools::disconnect_all_blocks(get_bulk());
356
357 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
358 EXPECT_EQ(14u, get_num_total_nodes(get_bulk()));
359 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
360
361 output_mesh(get_bulk(), "disconnect_3block_4quad_keepLowerRight_decomp1.g");
362 }
363
364 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_keepLowerRight_decomp2)
365 {
366 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 2);
367
368 output_mesh(get_bulk(), "disconnect_3block_4quad_keepLowerRight_decomp2_init.g");
369
370 stk::tools::disconnect_all_blocks(get_bulk());
371
372 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
373 EXPECT_EQ(14u, get_num_total_nodes(get_bulk()));
374 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
375
376 output_mesh(get_bulk(), "disconnect_3block_4quad_keepLowerRight_decomp2.g");
377 }
378
379 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_keepLowerRight_decomp3)
380 {
381 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 3);
382
383 output_mesh(get_bulk(), "disconnect_3block_4quad_keepLowerRight_decomp3_init.g");
384
385 stk::tools::disconnect_all_blocks(get_bulk());
386
387 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
388 EXPECT_EQ(14u, get_num_total_nodes(get_bulk()));
389 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
390
391 output_mesh(get_bulk(), "disconnect_3block_4quad_keepLowerRight_decomp3.g");
392 }
393
394 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_checkerboard_decomp1)
395 {
396 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_checkerboard(get_bulk(), 1);
397
398 output_mesh(get_bulk(), "disconnect_2block_4quad_checkerboard_decomp1_init.g");
399
400 stk::tools::disconnect_all_blocks(get_bulk());
401
402 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
403 EXPECT_EQ(14u, get_num_total_nodes(get_bulk()));
404 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
405
406 output_mesh(get_bulk(), "disconnect_2block_4quad_checkerboard_decomp1.g");
407 }
408
409 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_checkerboard_decomp2)
410 {
411 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_checkerboard(get_bulk(), 2);
412
413 output_mesh(get_bulk(), "disconnect_2block_4quad_checkerboard_decomp2_init.g");
414
415 stk::tools::disconnect_all_blocks(get_bulk());
416
417 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
418 EXPECT_EQ(14u, get_num_total_nodes(get_bulk()));
419 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
420
421 output_mesh(get_bulk(), "disconnect_2block_4quad_checkerboard_decomp2.g");
422 }
423
424 TEST_F(TestDisconnectBlocks2D, disconnect_2block_4quad_checkerboard_decomp3)
425 {
426 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_checkerboard(get_bulk(), 3);
427
428 output_mesh(get_bulk(), "disconnect_2block_4quad_checkerboard_decomp3_init.g");
429
430 stk::tools::disconnect_all_blocks(get_bulk());
431
432 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
433 EXPECT_EQ(14u, get_num_total_nodes(get_bulk()));
434 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
435
436 output_mesh(get_bulk(), "disconnect_2block_4quad_checkerboard_decomp3.g");
437 }
438
439 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_checkerboard_decomp1)
440 {
441 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_checkerboard(get_bulk(), 1);
442
443 output_mesh(get_bulk(), "disconnect_3block_4quad_checkerboard_decomp1_init.g");
444
445 stk::tools::disconnect_all_blocks(get_bulk());
446
447 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
448 EXPECT_EQ(15u, get_num_total_nodes(get_bulk()));
449 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
450
451 output_mesh(get_bulk(), "disconnect_3block_4quad_checkerboard_decomp1.g");
452 }
453
454 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_checkerboard_decomp2)
455 {
456 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_checkerboard(get_bulk(), 2);
457
458 output_mesh(get_bulk(), "disconnect_3block_4quad_checkerboard_decomp2_init.g");
459
460 stk::tools::disconnect_all_blocks(get_bulk());
461
462 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
463 EXPECT_EQ(15u, get_num_total_nodes(get_bulk()));
464 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
465
466 output_mesh(get_bulk(), "disconnect_3block_4quad_checkerboard_decomp2.g");
467 }
468
469 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_checkerboard_decomp3)
470 {
471 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_checkerboard(get_bulk(), 3);
472
473 output_mesh(get_bulk(), "disconnect_3block_4quad_checkerboard_decomp3_init.g");
474
475 stk::tools::disconnect_all_blocks(get_bulk());
476
477 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
478 EXPECT_EQ(15u, get_num_total_nodes(get_bulk()));
479 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
480
481 output_mesh(get_bulk(), "disconnect_3block_4quad_checkerboard_decomp3.g");
482 }
483
484 TEST_F(TestDisconnectBlocks2D, disconnect_2block_2quad_diagonal)
485 {
486 stk::mesh::PartVector blocks = setup_mesh_2block_2quad_diagonal(get_bulk());
487
488 output_mesh(get_bulk(), "disconnect_2block_2quad_diagonal_init.g");
489
490 stk::tools::disconnect_all_blocks(get_bulk());
491
492 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
493 EXPECT_EQ(8u, get_num_total_nodes(get_bulk()));
494 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
495
496 output_mesh(get_bulk(), "disconnect_2block_2quad_diagonal.g");
497 }
498
499 TEST_F(TestDisconnectBlocks2D, disconnect_3block_4quad_bowtie)
500 {
501 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
502 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_bowtie(get_bulk());
503
504 output_mesh(get_bulk(), "disconnect_3block_4quad_bowtie_init.g");
505
506 stk::tools::disconnect_all_blocks(get_bulk());
507
508 EXPECT_EQ( 0u, get_num_intersecting_nodes(get_bulk(), blocks));
509 EXPECT_EQ(15u, get_num_total_nodes(get_bulk()));
510 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
511
512 output_mesh(get_bulk(), "disconnect_3block_4quad_bowtie.g");
513 }
514 }
515
516 typedef TestDisconnectBlocks2D TestReconnectList2D;
517
518 void test_reconnect_list(const stk::mesh::BulkData& bulk, const BlockConnectionVector& disconnectList, const BlockConnectionVector& expectedReconnectList)
519 {
520 stk::tools::impl::PartPairLess comparator;
521 stk::tools::BlockPairVector reconnectList = get_local_reconnect_list(bulk, disconnectList);
522 EXPECT_EQ(reconnectList.size(), expectedReconnectList.size());
523
524 stk::tools::BlockPairVector convertedExpectedList = convert_connection_vector_to_pair_vector(bulk, expectedReconnectList);
525
526 for(stk::tools::BlockPair& reconnectPair : reconnectList) {
527 EXPECT_TRUE(std::binary_search(convertedExpectedList.begin(), convertedExpectedList.end(), reconnectPair, comparator))
528 << " did not find: " << reconnectPair.first->name() << " and " << reconnectPair.second->name() << std::endl;
529 }
530 }
531
532 TEST_F(TestReconnectList2D, reconnect_2block_2quad)
533 {
534 stk::mesh::BulkData& bulk = get_bulk();
535 setup_mesh_2block_2quad(bulk);
536 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2") };
537 BlockConnectionVector expectedReconnectList;
538
539 test_reconnect_list(bulk, blockPairsToDisconnect, expectedReconnectList);
540 }
541
542 TEST_F(TestReconnectList2D, reconnect_3block_4quad_permutation1)
543 {
544 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
545 stk::mesh::BulkData& bulk = get_bulk();
546 setup_mesh_3block_4quad(bulk, 1, 1);
547 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_3") };
548 BlockConnectionVector expectedReconnectList{ BlockConnection("block_1", "block_2"), BlockConnection("block_2", "block_3") };
549
550 test_reconnect_list(bulk, blockPairsToDisconnect, expectedReconnectList);
551 }
552
553 TEST_F(TestReconnectList2D, reconnect_3block_4quad_permutation2)
554 {
555 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
556 stk::mesh::BulkData& bulk = get_bulk();
557 setup_mesh_3block_4quad(bulk, 1, 1);
558 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2") };
559 BlockConnectionVector expectedReconnectList{ BlockConnection("block_1", "block_3"), BlockConnection("block_2", "block_3") };
560
561 test_reconnect_list(bulk, blockPairsToDisconnect, expectedReconnectList);
562 }
563
564 TEST_F(TestReconnectList2D, reconnect_3block_4quad_permutation3)
565 {
566 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
567 stk::mesh::BulkData& bulk = get_bulk();
568 setup_mesh_3block_4quad(bulk, 1, 1);
569 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_2","block_3") };
570 BlockConnectionVector expectedReconnectList{ BlockConnection("block_1", "block_2"), BlockConnection("block_1", "block_3") };
571
572 test_reconnect_list(bulk, blockPairsToDisconnect, expectedReconnectList);
573 }
574
575 TEST_F(TestReconnectList2D, reconnect_4block_4quad_permutation1)
576 {
577 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 4) { return; }
578 setup_mesh_4block_4quad(get_bulk(), 1);
579 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2") };
580 BlockConnectionVector expectedReconnectList{ BlockConnection("block_1", "block_3"), BlockConnection("block_2", "block_3"), BlockConnection("block_2", "block_4"), BlockConnection("block_1", "block_4"), BlockConnection("block_3", "block_4") };
581
582 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
583 }
584
585 TEST_F(TestReconnectList2D, reconnect_4block_4quad_permutation2)
586 {
587 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 4) { return; }
588 setup_mesh_4block_4quad(get_bulk(), 1);
589 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2"), BlockConnection("block_1","block_3") };
590 BlockConnectionVector expectedReconnectList{ BlockConnection("block_2", "block_3"), BlockConnection("block_2", "block_4"), BlockConnection("block_1", "block_4"), BlockConnection("block_3", "block_4") };
591
592 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
593 }
594
595 TEST_F(TestReconnectList2D, reconnect_4block_4quad_permutation3)
596 {
597 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 4) { return; }
598 setup_mesh_4block_4quad(get_bulk(), 1);
599 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2"), BlockConnection("block_3", "block_4") };
600 BlockConnectionVector expectedReconnectList{ BlockConnection("block_2", "block_3"), BlockConnection("block_2", "block_4"), BlockConnection("block_1", "block_4"), BlockConnection("block_1", "block_3") };
601
602 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
603 }
604
605 TEST_F(TestReconnectList2D, reconnect_4block_4quad_permutation4)
606 {
607 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 4) { return; }
608 setup_mesh_4block_4quad(get_bulk(), 1);
609 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2"), BlockConnection("block_2", "block_4"), BlockConnection("block_3", "block_4"), BlockConnection("block_1", "block_3") };
610 BlockConnectionVector expectedReconnectList{ BlockConnection("block_2", "block_3"), BlockConnection("block_1", "block_4") };
611
612 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
613 }
614
615 TEST_F(TestReconnectList2D, reconnect_9block_9quad_permutation1)
616 {
617 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
618 setup_mesh_9block_9quad(get_bulk());
619 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2"), BlockConnection("block_1", "block_4") };
620 BlockConnectionVector expectedReconnectList{ BlockConnection("block_1", "block_5"), BlockConnection("block_2", "block_4"), BlockConnection("block_2", "block_5"), BlockConnection("block_5", "block_4") };
621
622 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
623 }
624
625 TEST_F(TestReconnectList2D, reconnect_9block_9quad_permutation2)
626 {
627 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
628 setup_mesh_9block_9quad(get_bulk());
629 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_5","block_2"), BlockConnection("block_5", "block_4"), BlockConnection("block_5", "block_6"), BlockConnection("block_5", "block_8") };
630 BlockConnectionVector expectedReconnectList{ BlockConnection("block_1", "block_5"), BlockConnection("block_1", "block_2"), BlockConnection("block_1", "block_4"), BlockConnection("block_2", "block_4"),
631 BlockConnection("block_3", "block_5"), BlockConnection("block_2", "block_6"), BlockConnection("block_2", "block_3"), BlockConnection("block_3", "block_6"),
632 BlockConnection("block_5", "block_9"), BlockConnection("block_6", "block_8"), BlockConnection("block_8", "block_9"), BlockConnection("block_6", "block_9"),
633 BlockConnection("block_5", "block_7"), BlockConnection("block_4", "block_8"), BlockConnection("block_4", "block_7"), BlockConnection("block_7", "block_8"),
634 };
635
636 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
637 }
638
639
640 class TestDisconnectBlocks : public stk::unit_test_util::MeshFixture
641 {
642 protected:
643 TestDisconnectBlocks() : stk::unit_test_util::MeshFixture(3)
644 {
645 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
646 }
647 };
648
649 typedef TestDisconnectBlocks TestReconnectList;
650
651 TEST_F(TestReconnectList, reconnect_8block_8hex_permutation1)
652 {
653 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
654 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
655 BlockConnectionVector blockPairsToDisconnect { BlockConnection("block_1","block_2"), BlockConnection("block_2","block_4"), BlockConnection("block_2","block_6"),
656 BlockConnection("block_5","block_7"), BlockConnection("block_5","block_6"), BlockConnection("block_5","block_1"),
657 BlockConnection("block_8","block_6"), BlockConnection("block_8","block_4"), BlockConnection("block_8","block_7"),
658 BlockConnection("block_3","block_7"), BlockConnection("block_3","block_4"), BlockConnection("block_3","block_1")};
659 BlockConnectionVector expectedReconnectList { BlockConnection("block_2","block_3"), BlockConnection("block_2","block_5"), BlockConnection("block_2","block_8"), BlockConnection("block_2","block_7"),
660 BlockConnection("block_3","block_5"), BlockConnection("block_3","block_8"), BlockConnection("block_5","block_8"), BlockConnection("block_1","block_8"),
661 BlockConnection("block_1","block_4"), BlockConnection("block_1","block_6"), BlockConnection("block_1","block_7"), BlockConnection("block_3","block_6"),
662 BlockConnection("block_4","block_6"), BlockConnection("block_4","block_7"), BlockConnection("block_6","block_7"), BlockConnection("block_4","block_5")
663 };
664 test_reconnect_list(get_bulk(), blockPairsToDisconnect, expectedReconnectList);
665 }
666 }
667
668 TEST_F(TestDisconnectBlocks, disconnect_1block_1hex)
669 {
670 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
671 stk::mesh::PartVector blocks = setup_mesh_1block_1hex(get_bulk());
672
673 stk::tools::disconnect_all_blocks(get_bulk());
674
675 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
676 EXPECT_EQ(8u, get_num_total_nodes(get_bulk()));
677 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
678
679 output_mesh(get_bulk(), "disconnect_1block_1hex.g");
680 }
681 }
682
683 TEST_F(TestDisconnectBlocks, disconnect_2block_1hex)
684 {
685 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
686 stk::mesh::PartVector blocks = setup_mesh_2block_1hex(get_bulk());
687
688 stk::tools::disconnect_all_blocks(get_bulk());
689
690 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
691 EXPECT_EQ(8u, get_num_total_nodes(get_bulk()));
692 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
693
694 output_mesh(get_bulk(), "disconnect_2block_1hex.g");
695 }
696 }
697
698 TEST_F(TestDisconnectBlocks, disconnect_2block_2hex)
699 {
700 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
701 stk::mesh::PartVector blocks = setup_mesh_2block_2hex(get_bulk());
702
703 stk::tools::disconnect_all_blocks(get_bulk());
704
705 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
706 EXPECT_EQ(16u, get_num_total_nodes(get_bulk()));
707 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
708
709 output_mesh(get_bulk(), "disconnect_2block_2hex.g");
710 }
711 }
712
713 TEST_F(TestDisconnectBlocks, disconnect_2block_2hex_with_external_sides)
714 {
715 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
716 stk::mesh::PartVector blocks = setup_mesh_2block_2hex_with_external_sides(get_bulk());
717
718 EXPECT_EQ(12u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
719
720 stk::tools::disconnect_all_blocks(get_bulk());
721
722 EXPECT_EQ(16u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
723 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
724 EXPECT_EQ(16u,get_num_total_nodes(get_bulk()));
725 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
726
727 output_mesh(get_bulk(), "disconnect_2block_2hex_with_external_sides.g");
728 }
729 }
730
731 TEST_F(TestDisconnectBlocks, disconnect_8block_8hex_with_external_sides)
732 {
733 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
734 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_with_external_sides(get_bulk());
735
736 EXPECT_EQ(26u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
737
738 stk::tools::disconnect_all_blocks(get_bulk());
739
740 EXPECT_EQ(56u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
741 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
742 EXPECT_EQ(64u,get_num_total_nodes(get_bulk()));
743 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
744
745 output_mesh(get_bulk(), "disconnect_8block_8hex_with_external_sides.g");
746 }
747 }
748
749 TEST_F(TestDisconnectBlocks, disconnect_2block_2cubeOfTet)
750 {
751 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
752 stk::mesh::PartVector blocks = setup_mesh_2block_2cubeOfTet(get_bulk());
753
754 stk::tools::disconnect_all_blocks(get_bulk());
755
756 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
757 EXPECT_EQ(16u, get_num_total_nodes(get_bulk()));
758 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
759
760 output_mesh(get_bulk(), "disconnect_2block_2cubeOfTet.g");
761 }
762 }
763
764 TEST_F(TestDisconnectBlocks, disconnect_3block_4hex)
765 {
766 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
767 stk::mesh::PartVector blocks = setup_mesh_3block_4hex(get_bulk());
768
769 output_mesh(get_bulk(), "disconnect_3block_4hex_init.g");
770
771 stk::tools::disconnect_all_blocks(get_bulk());
772
773 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
774 EXPECT_EQ(28u, get_num_total_nodes(get_bulk()));
775 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
776
777 output_mesh(get_bulk(), "disconnect_3block_4hex.g");
778 }
779 }
780
781 TEST_F(TestDisconnectBlocks, disconnect_3block_4cubeOfTet)
782 {
783 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
784 stk::mesh::PartVector blocks = setup_mesh_3block_4cubeOfTet(get_bulk());
785
786 stk::tools::disconnect_all_blocks(get_bulk());
787
788 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
789 EXPECT_EQ(28u, get_num_total_nodes(get_bulk()));
790 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
791
792 output_mesh(get_bulk(), "disconnect_3block_4cubeOfTet.g");
793 }
794 }
795
796 TEST(DisconnectBlocks, input_mesh)
797 {
798 double startTime = stk::wall_time();
799
800 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_WORLD, stk::mesh::BulkData::NO_AUTO_AURA);
801 stk::mesh::BulkData& bulk = *bulkPtr;
802
803 std::string exodusFileName = stk::unit_test_util::get_option("-f", "");
804 if (exodusFileName.empty()) return;
805
806 stk::io::fill_mesh_with_auto_decomp(exodusFileName, bulk);
807
808 double meshReadTime = stk::wall_time();
809
810 stk::tools::disconnect_all_blocks(bulk);
811
812 double disconnectTime = stk::wall_time();
813
814 stk::mesh::PartVector allBlocksInMesh;
815 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
816 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
817 EXPECT_FALSE(check_orphaned_nodes(bulk));
818
819 output_mesh(bulk, "disconnected_" + exodusFileName);
820 double meshWriteTime = stk::wall_time();
821
822 if (bulk.parallel_rank() == 0) {
823 std::cout << " Mesh read time = " << (meshReadTime - startTime) << " s" << std::endl;
824 std::cout << "Disconnect time = " << (disconnectTime - meshReadTime) << " s" << std::endl;
825 std::cout << "Mesh write time = " << (meshWriteTime - disconnectTime) << " s" << std::endl;
826 }
827 }
828
829 typedef TestDisconnectBlocks2D TestReconnectBlocks2D;
830 typedef TestDisconnectBlocks TestReconnectBlocks;
831 typedef TestDisconnectBlocks2D TestDisconnectFullAlgorithm2D;
832 typedef TestDisconnectBlocks2D TestDisconnectFullAlgorithmPartial2D;
833 typedef TestDisconnectBlocks TestDisconnectFullAlgorithm;
834 typedef TestDisconnectBlocks TestDisconnectFullAlgorithmPartial;
835
836 void test_one_block_reconnect(stk::mesh::BulkData& bulk)
837 {
838 stk::mesh::PartVector allBlocksInMesh;
839 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
840 STK_ThrowRequire(allBlocksInMesh.size() == 1u);
841 stk::tools::impl::LinkInfo info;
842 info.preserveOrphans = true;
843
844 std::vector<stk::tools::BlockPair> blockPairs;
845
846 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
847 stk::tools::impl::disconnect_block_pairs(bulk, blockPairs, info);
848 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
849 stk::tools::impl::reconnect_block_pairs(bulk, blockPairs, info);
850 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
851
852 output_mesh(bulk);
853 }
854
855 void test_two_block_reconnect(stk::mesh::BulkData& bulk, const stk::mesh::PartVector& blocks,
856 const unsigned expectedCommonNodeCount)
857 {
858 STK_ThrowRequire(blocks.size() >= 2u);
859 stk::mesh::PartVector allBlocksInMesh;
860 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
861 stk::tools::impl::LinkInfo info;
862 info.preserveOrphans = true;
863
864 std::vector<stk::tools::BlockPair> blockPairs;
865
866 stk::tools::impl::insert_block_pair(blocks[0], blocks[1], blockPairs);
867
868 EXPECT_EQ(expectedCommonNodeCount, get_num_intersecting_nodes(bulk, allBlocksInMesh));
869 stk::tools::impl::disconnect_block_pairs(bulk, blockPairs, info);
870 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
871 stk::tools::impl::reconnect_block_pairs(bulk, blockPairs, info);
872 EXPECT_EQ(expectedCommonNodeCount, get_num_intersecting_nodes(bulk, allBlocksInMesh));
873
874 output_mesh(bulk);
875 }
876
877 TEST_F(TestReconnectBlocks2D, reconnect_1block_1quad)
878 {
879 stk::mesh::PartVector blocks = setup_mesh_1block_1quad(get_bulk());
880 test_one_block_reconnect(get_bulk());
881 }
882
883 TEST_F(TestReconnectBlocks2D, reconnect_2block_2quad)
884 {
885 stk::mesh::PartVector blocks = setup_mesh_2block_2quad(get_bulk());
886 test_two_block_reconnect(get_bulk(), blocks, 2u);
887 }
888
889 TEST_F(TestReconnectBlocks2D, reconnect_2block_2quad_diagonal)
890 {
891 stk::mesh::PartVector blocks = setup_mesh_2block_2quad_diagonal(get_bulk());
892 test_two_block_reconnect(get_bulk(), blocks, 1u);
893 }
894
895 TEST_F(TestReconnectBlocks2D, reconnect_2block_2quad_reversed)
896 {
897 stk::mesh::PartVector blocks = setup_mesh_2block_2quad_reversed(get_bulk());
898 test_two_block_reconnect(get_bulk(), blocks, 2u);
899 }
900
901 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_corner_decomp1)
902 {
903 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 1);
904 test_two_block_reconnect(get_bulk(), blocks, 3u);
905 }
906
907 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_corner_decomp2)
908 {
909 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 2);
910 test_two_block_reconnect(get_bulk(), blocks, 3u);
911 }
912
913 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_corner_decomp3)
914 {
915 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 3);
916 test_two_block_reconnect(get_bulk(), blocks, 3u);
917 }
918
919 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_corner_decomp4)
920 {
921 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_corner(get_bulk(), 4);
922 test_two_block_reconnect(get_bulk(), blocks, 3u);
923 }
924
925 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_swappedCorner_decomp1)
926 {
927 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 1);
928 test_two_block_reconnect(get_bulk(), blocks, 3u);
929 }
930
931 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_swappedCorner_decomp2)
932 {
933 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 2);
934 test_two_block_reconnect(get_bulk(), blocks, 3u);
935 }
936
937 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_swappedCorner_decomp3)
938 {
939 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 3);
940 test_two_block_reconnect(get_bulk(), blocks, 3u);
941 }
942
943 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_swappedCorner_decomp4)
944 {
945 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_swappedCorner(get_bulk(), 4);
946 test_two_block_reconnect(get_bulk(), blocks, 3u);
947 }
948
949 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_checkerboard_decomp1)
950 {
951 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_checkerboard(get_bulk(), 1);
952 test_two_block_reconnect(get_bulk(), blocks, 5u);
953 }
954
955 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_checkerboard_decomp2)
956 {
957 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_checkerboard(get_bulk(), 2);
958 test_two_block_reconnect(get_bulk(), blocks, 5u);
959 }
960
961 TEST_F(TestReconnectBlocks2D, reconnect_2block_4quad_checkerboard_decomp3)
962 {
963 stk::mesh::PartVector blocks = setup_mesh_2block_4quad_checkerboard(get_bulk(), 3);
964 test_two_block_reconnect(get_bulk(), blocks, 5u);
965 }
966
967 void test_reconnect_block_pairs(stk::mesh::BulkData& bulk, stk::mesh::PartVector& /*blocks*/,
968 const std::vector<BlockConnection>& reconnectPairs,
969 unsigned expectedGlobalInitialCommonNodes,
970 unsigned expectedGlobalConnectCommonNodes)
971 {
972 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
973 stk::mesh::PartVector allBlocksInMesh;
974 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
975 stk::tools::impl::LinkInfo info;
976 info.preserveOrphans = false;
977
978 std::vector<stk::tools::BlockPair> disconnectBlockPairs;
979 for(unsigned i = 0; i < allBlocksInMesh.size() - 1; i++) {
980 for(unsigned j = i+1; j < allBlocksInMesh.size(); j++) {
981 stk::tools::impl::insert_block_pair(allBlocksInMesh[i], allBlocksInMesh[j], disconnectBlockPairs);
982 }
983 }
984
985 std::vector<stk::tools::BlockPair> reconnectBlockPairs;
986
987 for(const BlockConnection& connectPair : reconnectPairs) {
988 STK_ThrowRequire(connectPair.block1 != connectPair.block2);
989
990 stk::mesh::Part* block1 = meta.get_part(connectPair.block1);
991 stk::mesh::Part* block2 = meta.get_part(connectPair.block2);
992
993 STK_ThrowRequire(block1 != nullptr && block2 != nullptr);
994
995 stk::tools::impl::insert_block_pair(block1, block2, reconnectBlockPairs);
996 }
997
998 EXPECT_EQ(expectedGlobalInitialCommonNodes, get_num_intersecting_nodes(bulk, allBlocksInMesh));
999 stk::tools::impl::disconnect_block_pairs(bulk, disconnectBlockPairs, info);
1000 output_mesh(bulk, "test.g");
1001 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1002 stk::tools::impl::reconnect_block_pairs(bulk, reconnectBlockPairs, info);
1003 EXPECT_EQ(expectedGlobalConnectCommonNodes, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1004
1005 stk::mesh::PartVector connectedBlockPair(2);
1006 for(const BlockConnection& connectPair : reconnectPairs) {
1007 stk::mesh::Part* block1 = meta.get_part(connectPair.block1);
1008 stk::mesh::Part* block2 = meta.get_part(connectPair.block2);
1009
1010 connectedBlockPair[0] = block1;
1011 connectedBlockPair[1] = block2;
1012
1013 EXPECT_EQ(connectPair.numExpectedIntersectingNodes, get_num_intersecting_nodes(bulk, connectedBlockPair)) << " first block: " << block1->name() << " second block: " << block2->name();
1014 }
1015 output_mesh(bulk);
1016 }
1017
1018 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder1_decomp1)
1019 {
1020 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 1);
1021 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",2)};
1022 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1023 }
1024
1025 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder1_decomp1_v2)
1026 {
1027 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 3);
1028 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_1",2), BlockConnection("block_2","block_3",2)};
1029 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1030 }
1031
1032 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder1_decomp2)
1033 {
1034 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 2);
1035 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",2)};
1036 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1037 }
1038
1039 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder1_decomp3)
1040 {
1041 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 3);
1042 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",2)};
1043 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1044 }
1045
1046 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder2_decomp1)
1047 {
1048 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 2, 1);
1049 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",2), BlockConnection("block_2","block_1",2)};
1050 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1051 }
1052
1053 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder2_decomp2)
1054 {
1055 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 2, 2);
1056 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",2), BlockConnection("block_2","block_1",2)};
1057 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1058 }
1059
1060 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder2_decomp2_v2)
1061 {
1062 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 2, 2);
1063 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",2)};
1064 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 2);
1065 }
1066
1067 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder2_decomp2_v3)
1068 {
1069 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 2, 2);
1070 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_1",2)};
1071 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 2);
1072 }
1073
1074 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder2_decomp3)
1075 {
1076 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 2, 3);
1077 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",2), BlockConnection("block_2","block_1",2)};
1078 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1079 }
1080
1081 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder3_decomp1)
1082 {
1083 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 3, 1);
1084 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_1",2), BlockConnection("block_3","block_2",2)};
1085 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1086 }
1087
1088 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder3_decomp2)
1089 {
1090 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 3, 2);
1091 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_1",2), BlockConnection("block_3","block_2",2)};
1092 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1093 }
1094
1095 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder3_decomp3)
1096 {
1097 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 3, 3);
1098 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_1",2), BlockConnection("block_3","block_2",2)};
1099 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1100 }
1101
1102 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder4_decomp1)
1103 {
1104 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 4, 1);
1105 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_2",2), BlockConnection("block_3","block_1",2)};
1106 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1107 }
1108
1109 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder4_decomp2)
1110 {
1111 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 4, 2);
1112 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_2",2), BlockConnection("block_3","block_1",2)};
1113 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1114 }
1115
1116 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder4_decomp3)
1117 {
1118 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 4, 3);
1119 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_2",2), BlockConnection("block_3","block_1",2)};
1120 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1121 }
1122
1123 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder5_decomp1)
1124 {
1125 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 5, 1);
1126 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_1",2), BlockConnection("block_2","block_3",2)};
1127 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1128 }
1129
1130 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder5_decomp2)
1131 {
1132 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 5, 2);
1133 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_1",2), BlockConnection("block_2","block_3",2)};
1134 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1135 }
1136
1137 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder5_decomp3)
1138 {
1139 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 5, 3);
1140 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_1",2), BlockConnection("block_2","block_3",2)};
1141 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1142 }
1143
1144 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder6_decomp1)
1145 {
1146 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 6, 1);
1147 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_3",2), BlockConnection("block_1","block_2",2)};
1148 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1149 }
1150
1151 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder6_decomp2)
1152 {
1153 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 6, 2);
1154 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_3",2), BlockConnection("block_1","block_2",2)};
1155 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1156 }
1157
1158 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_blockOrder6_decomp3)
1159 {
1160 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 6, 3);
1161 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_3",2), BlockConnection("block_1","block_2",2)};
1162 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1163 }
1164
1165 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_keepLowerRight_decomp1)
1166 {
1167 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 1);
1168 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",2)};
1169 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1170 }
1171
1172 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_keepLowerRight_decomp2)
1173 {
1174 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 2);
1175 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",2)};
1176 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1177 }
1178
1179 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_keepLowerRight_decomp3)
1180 {
1181 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 3);
1182 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",2)};
1183 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 4, 3);
1184 }
1185
1186 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_checkerboard_decomp1)
1187 {
1188 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_checkerboard(get_bulk(), 1);
1189 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",3), BlockConnection("block_1","block_3",3)};
1190 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 5);
1191 }
1192
1193 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_checkerboard_decomp2)
1194 {
1195 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_checkerboard(get_bulk(), 2);
1196 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",3), BlockConnection("block_1","block_3",3)};
1197 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 5);
1198 }
1199
1200 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_checkerboard_decomp3)
1201 {
1202 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_checkerboard(get_bulk(), 3);
1203 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",3), BlockConnection("block_1","block_3",3)};
1204 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 5);
1205 }
1206
1207 TEST_F(TestReconnectBlocks2D, reconnect_3block_4quad_bowtie)
1208 {
1209 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_bowtie(get_bulk());
1210 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",1), BlockConnection("block_1","block_3",1)};
1211 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 1, 1);
1212 }
1213
1214 TEST_F(TestReconnectBlocks2D, reconnect_4block_4quad_blockorder1)
1215 {
1216 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1217 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1218 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_4",2)};
1219 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 2);
1220 }
1221
1222 TEST_F(TestReconnectBlocks2D, reconnect_4block_4quad_blockorder1_v2)
1223 {
1224 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1225 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1226 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_4",2), BlockConnection("block_2","block_3",1)};
1227 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 2);
1228 }
1229
1230 TEST_F(TestReconnectBlocks2D, reconnect_4block_4quad_blockorder1_v3)
1231 {
1232 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1233 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1234 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_4",2), BlockConnection("block_3","block_4",2)};
1235 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 3);
1236 }
1237
1238 TEST_F(TestReconnectBlocks2D, reconnect_4block_4quad_blockorder1_v4)
1239 {
1240 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1241 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1242 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_2","block_3",1), BlockConnection("block_3","block_4",2)/*, BlockConnection("block_1","block_4",1)*/};
1243 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 3);
1244 }
1245
1246 TEST_F(TestReconnectBlocks2D, reconnect_4block_4quad_blockorder1_v5)
1247 {
1248 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1249 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1250 BlockConnectionVector reconnectPairs{BlockConnection("block_3","block_1",2), BlockConnection("block_1","block_2",2), BlockConnection("block_2","block_4",2)};
1251 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 4);
1252 }
1253
1254 TEST_F(TestReconnectBlocks2D, reconnect_4block_4quad_blockorder2)
1255 {
1256 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1257 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 2);
1258 output_mesh(get_bulk(), "initial.g");
1259 BlockConnectionVector reconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1","block_3",1)};
1260 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 5, 2);
1261 }
1262
1263 TEST_F(TestReconnectBlocks, reconnect_1block_1hex)
1264 {
1265 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
1266 stk::mesh::PartVector blocks = setup_mesh_1block_1hex(get_bulk());
1267 test_one_block_reconnect(get_bulk());
1268 }
1269 }
1270
1271 TEST_F(TestReconnectBlocks, reconnect_2block_1hex)
1272 {
1273 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
1274 stk::mesh::PartVector blocks = setup_mesh_2block_1hex(get_bulk());
1275 test_two_block_reconnect(get_bulk(), blocks, 0u);
1276 }
1277 }
1278
1279 TEST_F(TestReconnectBlocks, reconnect_2block_2hex)
1280 {
1281 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1282 stk::mesh::PartVector blocks = setup_mesh_2block_2hex(get_bulk());
1283 test_two_block_reconnect(get_bulk(), blocks, 4u);
1284 }
1285 }
1286
1287 TEST_F(TestReconnectBlocks, reconnect_2block_2cubeOfTet)
1288 {
1289 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1290 stk::mesh::PartVector blocks = setup_mesh_2block_2cubeOfTet(get_bulk());
1291 test_two_block_reconnect(get_bulk(), blocks, 4u);
1292 }
1293 }
1294
1295 TEST_F(TestReconnectBlocks, reconnect_3block_4hex)
1296 {
1297 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1298 stk::mesh::PartVector blocks = setup_mesh_3block_4hex(get_bulk());
1299 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",4), BlockConnection("block_2","block_1",4)};
1300 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 8, 6);
1301 }
1302 }
1303
1304 TEST_F(TestReconnectBlocks, reconnect_3block_4hex_v2)
1305 {
1306 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1307 stk::mesh::PartVector blocks = setup_mesh_3block_4hex(get_bulk());
1308 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",4)};
1309 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 8, 4);
1310 }
1311 }
1312
1313 TEST_F(TestReconnectBlocks, reconnect_3block_4hex_v3)
1314 {
1315 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1316 stk::mesh::PartVector blocks = setup_mesh_3block_4hex(get_bulk());
1317 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_1",4)};
1318 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 8, 4);
1319 }
1320 }
1321
1322 TEST_F(TestReconnectBlocks, reconnect_3block_4cubeOfTet)
1323 {
1324 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1325 stk::mesh::PartVector blocks = setup_mesh_3block_4cubeOfTet(get_bulk());
1326 BlockConnectionVector reconnectPairs{BlockConnection("block_2","block_3",4), BlockConnection("block_2","block_1",4)};
1327 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 8, 6);
1328 }
1329 }
1330
1331 TEST_F(TestReconnectBlocks, reconnect_4block_4hex)
1332 {
1333 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1334 stk::mesh::PartVector blocks = setup_mesh_4block_4hex(get_bulk());
1335 BlockConnectionVector reconnectPairs{ BlockConnection("block_2","block_1",4), BlockConnection("block_3","block_2",2) };
1336 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 10, 4);
1337 }
1338 }
1339
1340 TEST_F(TestReconnectBlocks, reconnect_4block_4hex_v2)
1341 {
1342 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1343 stk::mesh::PartVector blocks = setup_mesh_4block_4hex(get_bulk());
1344 BlockConnectionVector reconnectPairs{ BlockConnection("block_2","block_3",2), BlockConnection("block_1","block_4",2) };
1345 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 10, 4);
1346 }
1347 }
1348
1349 TEST_F(TestReconnectBlocks, reconnect_4block_4hex_v3)
1350 {
1351 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1352 stk::mesh::PartVector blocks = setup_mesh_4block_4hex(get_bulk());
1353 BlockConnectionVector reconnectPairs{ BlockConnection("block_1","block_2",4), BlockConnection("block_2","block_4",4), BlockConnection("block_4","block_3",4),
1354 BlockConnection("block_2","block_3",2), BlockConnection("block_1","block_4",2)};
1355 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 10, 8);
1356 }
1357 }
1358
1359 TEST_F(TestReconnectBlocks, reconnect_4block_4hex_vertical_stack)
1360 {
1361 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 4) {
1362 stk::mesh::PartVector blocks = setup_mesh_4block_4hex_vertical_stack(get_bulk());
1363 BlockConnectionVector reconnectPairs{ BlockConnection("block_1","block_2",4), BlockConnection("block_3","block_4",4) };
1364 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 12, 8);
1365 }
1366 }
1367
1368 TEST_F(TestReconnectBlocks, reconnect_4block_4hex_vertical_stack_v2)
1369 {
1370 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 4) {
1371 stk::mesh::PartVector blocks = setup_mesh_4block_4hex_vertical_stack(get_bulk());
1372 BlockConnectionVector reconnectPairs{ BlockConnection("block_2","block_3",4) };
1373 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 12, 4);
1374 }
1375 }
1376
1377 TEST_F(TestReconnectBlocks, reconnect_4block_8hex_cube)
1378 {
1379 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1380 stk::mesh::PartVector blocks = setup_mesh_4block_8hex_cube(get_bulk());
1381 BlockConnectionVector reconnectPairs{ BlockConnection("block_2","block_4",6) };
1382 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 15, 6);
1383 }
1384 }
1385
1386 TEST_F(TestReconnectBlocks, reconnect_4block_8hex_cube_v2)
1387 {
1388 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1389 stk::mesh::PartVector blocks = setup_mesh_4block_8hex_cube(get_bulk());
1390 BlockConnectionVector reconnectPairs{ BlockConnection("block_2","block_3",3) };
1391 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 15, 3);
1392 }
1393 }
1394
1395 TEST_F(TestReconnectBlocks, reconnect_4block_8hex_cube_v3)
1396 {
1397 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1398 stk::mesh::PartVector blocks = setup_mesh_4block_8hex_cube(get_bulk());
1399 BlockConnectionVector reconnectPairs{ BlockConnection("block_2","block_3",3), BlockConnection("block_3","block_4",6) };
1400 test_reconnect_block_pairs(get_bulk(), blocks, reconnectPairs, 15, 6);
1401 }
1402 }
1403
1404 TEST_F(TestReconnectBlocks, reconnect_2block_2hex_with_external_sides)
1405 {
1406 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1407 stk::mesh::PartVector blocks = setup_mesh_2block_2hex_with_external_sides(get_bulk());
1408
1409 EXPECT_EQ(12u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
1410
1411 stk::tools::impl::LinkInfo info;
1412 info.preserveOrphans = true;
1413
1414 stk::tools::disconnect_all_blocks(get_bulk(), info);
1415
1416 EXPECT_EQ(16u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
1417 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
1418 EXPECT_EQ(16u,get_num_total_nodes(get_bulk()));
1419 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
1420
1421 output_mesh(get_bulk(), "disconnect_2block_2hex_with_external_sides.g");
1422
1423 stk::tools::impl::reconnect_block_pairs(get_bulk(), {stk::tools::BlockPair(blocks[0], blocks[1])}, info);
1424
1425 EXPECT_EQ(12u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
1426 EXPECT_EQ(4u, get_num_intersecting_nodes(get_bulk(), blocks));
1427 EXPECT_EQ(12u,get_num_total_nodes(get_bulk()));
1428 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
1429
1430 output_mesh(get_bulk());
1431 }
1432 }
1433
1434 TEST_F(TestReconnectBlocks, reconnect_8block_8hex_with_external_sides)
1435 {
1436 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1437 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_with_external_sides(get_bulk());
1438
1439 EXPECT_EQ(26u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
1440
1441 stk::tools::impl::LinkInfo info;
1442 info.preserveOrphans = true;
1443
1444 stk::tools::disconnect_all_blocks(get_bulk(), info);
1445
1446 EXPECT_EQ(56u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
1447 EXPECT_EQ(0u, get_num_intersecting_nodes(get_bulk(), blocks));
1448 EXPECT_EQ(64u,get_num_total_nodes(get_bulk()));
1449 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
1450
1451 output_mesh(get_bulk(), "disconnect_8block_8hex_with_external_sides.g");
1452
1453 stk::tools::BlockPairVector blockPairs { stk::tools::impl::get_block_pair(blocks[0], blocks[1]),
1454 stk::tools::impl::get_block_pair(blocks[0], blocks[2]),
1455 stk::tools::impl::get_block_pair(blocks[0], blocks[3]),
1456 stk::tools::impl::get_block_pair(blocks[1], blocks[2]),
1457 stk::tools::impl::get_block_pair(blocks[1], blocks[3]),
1458 stk::tools::impl::get_block_pair(blocks[2], blocks[3])
1459 };
1460
1461 stk::tools::impl::reconnect_block_pairs(get_bulk(), blockPairs, info);
1462
1463 EXPECT_EQ(45u, get_num_surface_nodes(get_bulk(), {"surface_1"}));
1464 EXPECT_EQ(10u, get_num_intersecting_nodes(get_bulk(), blocks));
1465 EXPECT_EQ(50u,get_num_total_nodes(get_bulk()));
1466 EXPECT_FALSE(check_orphaned_nodes(get_bulk()));
1467
1468 output_mesh(get_bulk());
1469 }
1470 }
1471
1472 stk::tools::BlockPairVector convert_connection_vector_to_pair_vector(const stk::mesh::BulkData& bulk, BlockConnectionVector& disconnectConnVector)
1473 {
1474 stk::tools::BlockPairVector pairVector;
1475 const stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1476
1477 for(BlockConnection& connection : disconnectConnVector) {
1478 stk::mesh::Part* part1 = meta.get_part(connection.block1);
1479 stk::mesh::Part* part2 = meta.get_part(connection.block2);
1480
1481 pairVector.push_back(stk::tools::impl::get_block_pair(part1, part2));
1482 }
1483
1484 return pairVector;
1485 }
1486
1487 void test_populate_blocks_to_reconnect(stk::mesh::BulkData& bulk, const stk::tools::BlockPairVector& expectedReconnectBlockPairs, BlockConnectionVector& disconnectPairs)
1488 {
1489 stk::mesh::PartVector allBlocksInMesh;
1490 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
1491 stk::tools::BlockPairVector orderedBlockPairsInMesh;
1492 stk::tools::BlockPairVector blockPairsToReconnect;
1493 stk::tools::BlockPairVector blockPairsToDisconnect = convert_connection_vector_to_pair_vector(bulk, disconnectPairs);
1494
1495 stk::tools::impl::fill_ordered_block_pairs(allBlocksInMesh, orderedBlockPairsInMesh);
1496
1497 stk::tools::impl::populate_blocks_to_reconnect(bulk, orderedBlockPairsInMesh, blockPairsToDisconnect, blockPairsToReconnect);
1498 EXPECT_EQ(expectedReconnectBlockPairs.size(), blockPairsToReconnect.size());
1499
1500 for(const stk::tools::BlockPair& blockPair : expectedReconnectBlockPairs) {
1501 EXPECT_TRUE(std::binary_search(blockPairsToReconnect.begin(), blockPairsToReconnect.end(), blockPair, stk::tools::impl::PartPairLess()))
1502 << "first block name: " << blockPair.first->name() << " second block name: " << blockPair.second->name() << std::endl;
1503 }
1504 }
1505
1506 TEST_F(TestDisconnectBlocks2D, test_populate_blocks_to_reconnect_2block_2quad)
1507 {
1508 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1509 stk::mesh::BulkData& bulk = get_bulk();
1510 stk::mesh::PartVector blocks = setup_mesh_2block_2quad(bulk);
1511 BlockConnectionVector disconnectPairs{BlockConnection("block_1","block_2",2)};
1512 stk::tools::BlockPairVector expectedReconnectBlockPairs;
1513
1514 test_populate_blocks_to_reconnect(bulk, expectedReconnectBlockPairs, disconnectPairs);
1515 }
1516
1517 TEST_F(TestDisconnectBlocks2D, test_populate_blocks_to_reconnect_3block_4quad)
1518 {
1519 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1520 stk::mesh::BulkData& bulk = get_bulk();
1521 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1522 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(bulk, 1, 1);
1523
1524 stk::mesh::Part* block1 = meta.get_part("block_1");
1525 stk::mesh::Part* block2 = meta.get_part("block_2");
1526 stk::mesh::Part* block3 = meta.get_part("block_3");
1527
1528 stk::tools::BlockPairVector expectedReconnectBlockPairs;
1529 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block1, block3));
1530 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block2, block3));
1531
1532 BlockConnectionVector disconnectPairs{BlockConnection("block_1","block_2",2)};
1533
1534 test_populate_blocks_to_reconnect(bulk, expectedReconnectBlockPairs, disconnectPairs);
1535 }
1536
1537 TEST_F(TestDisconnectBlocks2D, test_populate_blocks_to_reconnect_3block_4quad_v2)
1538 {
1539 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1540 stk::mesh::BulkData& bulk = get_bulk();
1541 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1542 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(bulk, 1, 1);
1543 BlockConnectionVector disconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_1", "block_3", 2)};
1544
1545 stk::mesh::Part* block2 = meta.get_part("block_2");
1546 stk::mesh::Part* block3 = meta.get_part("block_3");
1547
1548 stk::tools::BlockPairVector expectedReconnectBlockPairs;
1549 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block2, block3));
1550
1551 test_populate_blocks_to_reconnect(bulk, expectedReconnectBlockPairs, disconnectPairs);
1552 }
1553
1554 TEST_F(TestDisconnectBlocks2D, test_populate_blocks_to_reconnect_4block_4quad)
1555 {
1556 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 3) { return; }
1557 stk::mesh::BulkData& bulk = get_bulk();
1558 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1559 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(bulk, 1);
1560
1561 stk::mesh::Part* block1 = meta.get_part("block_1");
1562 stk::mesh::Part* block2 = meta.get_part("block_2");
1563 stk::mesh::Part* block3 = meta.get_part("block_3");
1564 stk::mesh::Part* block4 = meta.get_part("block_4");
1565
1566 stk::tools::BlockPairVector expectedReconnectBlockPairs;
1567 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block1, block3));
1568 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block1, block4));
1569 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block2, block3));
1570 expectedReconnectBlockPairs.push_back(stk::tools::impl::get_block_pair(block3, block4));
1571
1572 BlockConnectionVector disconnectPairs{BlockConnection("block_1","block_2",2), BlockConnection("block_4","block_2",2)};
1573
1574 test_populate_blocks_to_reconnect(bulk, expectedReconnectBlockPairs, disconnectPairs);
1575 }
1576
1577 void print_block_pair_list(const stk::tools::BlockPairVector& blockPairs)
1578 {
1579 std::cout << "Block pairs to reconnect" << std::endl;
1580 for(const stk::tools::BlockPair& blockPair : blockPairs) {
1581 std::cout << "\t block pair: {" << blockPair.first->name() << "," << blockPair.second->name() <<"}" << std::endl;
1582 }
1583 std::cout << std::endl;
1584 }
1585
1586 void test_block_disconnect_full_algorithm_partial_disconnect(stk::mesh::BulkData& bulk,
1587 BlockConnectionVector& blockPairConnectionsToDisconnect,
1588 unsigned expectedGlobalInitialCommonNodes,
1589 unsigned expectedGlobalConnectCommonNodesAfterHingeSnip,
1590 unsigned expectedGlobalTotalNumberOfNodes)
1591 {
1592 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1593 stk::mesh::PartVector allBlocksInMesh;
1594 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
1595 stk::tools::impl::LinkInfo info;
1596 info.preserveOrphans = true;
1597
1598 stk::tools::BlockPairVector blockPairsToDisconnect = convert_connection_vector_to_pair_vector(bulk, blockPairConnectionsToDisconnect);
1599 stk::tools::BlockPairVector blockPairsToReconnect;
1600 blockPairsToReconnect = get_local_reconnect_list(bulk, blockPairConnectionsToDisconnect);
1601
1602 EXPECT_EQ(expectedGlobalInitialCommonNodes, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1603 stk::tools::impl::disconnect_block_pairs(bulk, blockPairsToDisconnect, info);
1604 output_mesh(bulk, "dis_seq_disconnected_mesh.g");
1605
1606 stk::mesh::PartVector connectedBlockPair(2);
1607 for(const stk::tools::BlockPair& connectPair : blockPairsToDisconnect) {
1608 connectedBlockPair[0] = connectPair.first;
1609 connectedBlockPair[1] = connectPair.second;
1610
1611 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, connectedBlockPair)) << " block1: " << connectedBlockPair[0]->name() << " block2: " << connectedBlockPair[1]->name();
1612 }
1613
1614 stk::tools::impl::reconnect_block_pairs(bulk, blockPairsToReconnect, info);
1615
1616 output_mesh(bulk, "dis_seq_reconnected_mesh.g");
1617
1618 stk::tools::impl::snip_all_hinges_between_blocks(bulk);
1619
1620 EXPECT_EQ(expectedGlobalConnectCommonNodesAfterHingeSnip, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1621 EXPECT_EQ(expectedGlobalTotalNumberOfNodes, get_num_total_nodes(bulk));
1622
1623 for(const BlockConnection& connectPair : blockPairConnectionsToDisconnect) {
1624 stk::mesh::Part* block1 = meta.get_part(connectPair.block1);
1625 stk::mesh::Part* block2 = meta.get_part(connectPair.block2);
1626
1627 connectedBlockPair[0] = block1;
1628 connectedBlockPair[1] = block2;
1629
1630 EXPECT_EQ(connectPair.numExpectedIntersectingNodes, get_num_intersecting_nodes(bulk, connectedBlockPair)) << " block1: " << block1->name() << " block2: " << block2->name();
1631 }
1632 output_mesh(bulk, "dis_seq_hinge_snipped_mesh.g");
1633 }
1634
1635 void test_block_disconnect_full_algorithm(stk::mesh::BulkData& bulk,
1636 BlockConnectionVector& blockPairConnectionsToDisconnect,
1637 unsigned expectedGlobalInitialCommonNodes,
1638 unsigned expectedGlobalConnectCommonNodesAfterHingeSnip,
1639 unsigned expectedGlobalTotalNumberOfNodes)
1640 {
1641 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1642 stk::mesh::PartVector allBlocksInMesh;
1643 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
1644 stk::tools::impl::LinkInfo info;
1645 info.preserveOrphans = true;
1646
1647 stk::tools::BlockPairVector orderedBlockPairsInMesh;
1648 stk::tools::impl::fill_ordered_block_pairs(allBlocksInMesh, orderedBlockPairsInMesh);
1649
1650 stk::tools::BlockPairVector blockPairsToDisconnect = convert_connection_vector_to_pair_vector(bulk, blockPairConnectionsToDisconnect);
1651 stk::tools::BlockPairVector blockPairsToReconnect;
1652 stk::tools::impl::populate_blocks_to_reconnect(bulk, orderedBlockPairsInMesh, blockPairsToDisconnect, blockPairsToReconnect);
1653
1654 EXPECT_EQ(expectedGlobalInitialCommonNodes, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1655 stk::tools::impl::disconnect_block_pairs(bulk, orderedBlockPairsInMesh, info);
1656 output_mesh(bulk, "dis_seq_disconnected_mesh.g");
1657 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1658 stk::tools::impl::reconnect_block_pairs(bulk, blockPairsToReconnect, info);
1659 // EXPECT_EQ(expectedGlobalConnectCommonNodesAfterReconnect, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1660
1661 output_mesh(bulk, "dis_seq_reconnected_mesh.g");
1662
1663 stk::tools::impl::snip_all_hinges_between_blocks(bulk);
1664
1665 EXPECT_EQ(expectedGlobalConnectCommonNodesAfterHingeSnip, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1666 EXPECT_EQ(expectedGlobalTotalNumberOfNodes, get_num_total_nodes(bulk));
1667
1668 stk::mesh::PartVector connectedBlockPair(2);
1669 for(const BlockConnection& connectPair : blockPairConnectionsToDisconnect) {
1670 stk::mesh::Part* block1 = meta.get_part(connectPair.block1);
1671 stk::mesh::Part* block2 = meta.get_part(connectPair.block2);
1672
1673 connectedBlockPair[0] = block1;
1674 connectedBlockPair[1] = block2;
1675
1676 EXPECT_EQ(connectPair.numExpectedIntersectingNodes, get_num_intersecting_nodes(bulk, connectedBlockPair)) << " block1: " << block1->name() << " block2: " << block2->name();
1677 }
1678 output_mesh(bulk, "dis_seq_hinge_snipped_mesh.g");
1679 }
1680
1681 void test_connection_pairs(stk::mesh::BulkData& bulk, stk::mesh::PartVector& allBlocksInMesh,
1682 BlockConnectionVector& blockPairConnectionsToDisconnect,
1683 unsigned expectedFinalCommonNodeCount)
1684 {
1685 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1686 stk::mesh::PartVector connectedBlockPair(2);
1687 for(const BlockConnection& connectPair : blockPairConnectionsToDisconnect) {
1688 stk::mesh::Part* block1 = meta.get_part(connectPair.block1);
1689 stk::mesh::Part* block2 = meta.get_part(connectPair.block2);
1690
1691 connectedBlockPair[0] = block1;
1692 connectedBlockPair[1] = block2;
1693
1694 EXPECT_EQ(connectPair.numExpectedIntersectingNodes, get_num_intersecting_nodes(bulk, connectedBlockPair)) << " block1: " << block1->name() << " block2: " << block2->name();
1695 }
1696
1697 output_mesh(bulk);
1698
1699 EXPECT_EQ(expectedFinalCommonNodeCount, get_num_intersecting_nodes(bulk, allBlocksInMesh));
1700 }
1701
1702 void test_user_block_disconnect(stk::mesh::BulkData& bulk,
1703 BlockConnectionVector& blockPairConnectionsToDisconnect,
1704 unsigned expectedFinalCommonNodeCount,
1705 stk::tools::SnipOption snipOption = stk::tools::PRESERVE_INITIAL_HINGES)
1706 {
1707 stk::mesh::PartVector allBlocksInMesh;
1708 stk::tools::impl::get_all_blocks_in_mesh(bulk, allBlocksInMesh);
1709 stk::tools::BlockPairVector blockPairsToDisconnect = convert_connection_vector_to_pair_vector(bulk, blockPairConnectionsToDisconnect);
1710
1711 stk::tools::disconnect_user_blocks(bulk, blockPairsToDisconnect, snipOption);
1712
1713 test_connection_pairs(bulk, allBlocksInMesh, blockPairConnectionsToDisconnect, expectedFinalCommonNodeCount);
1714 }
1715
1716 stk::tools::BlockNamePairVector convert_connection_vector_to_name_pair_vector(const stk::mesh::BulkData& /*bulk*/, const BlockConnectionVector& blockNamePairConnections)
1717 {
1718 stk::tools::BlockNamePairVector namePairVector;
1719
1720 for(const BlockConnection& connection : blockNamePairConnections) {
1721 namePairVector.push_back(std::make_pair(connection.block1, connection.block2));
1722 }
1723
1724 return namePairVector;
1725 }
1726
1727 TEST_F(TestDisconnectFullAlgorithm2D, disconnect_full_algorithm_2block_2quad)
1728 {
1729 stk::mesh::PartVector initialMesh = setup_mesh_2block_2quad(get_bulk());
1730 BlockConnectionVector blockPairsToDisconnect{BlockConnection("block_1","block_2",0)};
1731 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnect, 2u, 0u, 8u);
1732 }
1733
1734 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_2block_2quad)
1735 {
1736 stk::mesh::PartVector initialMesh = setup_mesh_2block_2quad(get_bulk());
1737 BlockConnectionVector blockPairsToDisconnect{BlockConnection("block_1","block_2",0)};
1738 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnect, 2u, 0u, 8u);
1739 }
1740
1741 TEST_F(TestDisconnectFullAlgorithm2D, disconnect_full_algorithm_3block_4quad_blockOrder1_decomp1)
1742 {
1743 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 1);
1744 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_1","block_3",0)};
1745 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 4u, 2u, 12u);
1746 }
1747
1748 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_3block_4quad_blockOrder1_decomp1)
1749 {
1750 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 1);
1751 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_1","block_3",0)};
1752 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 4u, 2u, 12u);
1753 }
1754
1755 TEST_F(TestDisconnectFullAlgorithm2D, disconnect_full_algorithm_3block_4quad_blockOrder1_decomp1_pacman)
1756 {
1757 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 1);
1758 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_2","block_3",1)};
1759 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 4u, 3u, 10u);
1760 }
1761
1762 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_3block_4quad_blockOrder1_decomp1_pacman)
1763 {
1764 stk::mesh::PartVector blocks = setup_mesh_3block_4quad(get_bulk(), 1, 1);
1765 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_2","block_3",1)};
1766 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 4u, 3u, 10u);
1767 }
1768
1769 TEST_F(TestDisconnectFullAlgorithm2D, disconnect_full_algorithm_4block_4quad_blockOrder1)
1770 {
1771 if(stk::parallel_machine_size(MPI_COMM_WORLD) <= 3) {
1772 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1773 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_2","block_4",0), BlockConnection("block_3","block_4",0)};
1774 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 5u, 3u, 12u);
1775 }
1776 }
1777
1778 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_4block_4quad_blockOrder1)
1779 {
1780 if(stk::parallel_machine_size(MPI_COMM_WORLD) <= 3) {
1781 stk::mesh::PartVector blocks = setup_mesh_4block_4quad(get_bulk(), 1);
1782 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_2","block_4",0), BlockConnection("block_3","block_4",0)};
1783 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 5u, 3u, 12u);
1784 }
1785 }
1786
1787 TEST_F(TestDisconnectFullAlgorithm2D, disconnect_full_algorithm_6block_6quad)
1788 {
1789 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
1790 setup_mesh_6block_6quad(get_bulk());
1791 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_2","block_5",1), BlockConnection("block_3","block_6",0),
1792 BlockConnection("block_2","block_6",0), BlockConnection("block_3","block_5",0) };
1793
1794 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnect, 8u, 8u, 14u);
1795 }
1796
1797 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_6block_6quad)
1798 {
1799 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
1800 setup_mesh_6block_6quad(get_bulk());
1801 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_2","block_5",1), BlockConnection("block_3","block_6",0),
1802 BlockConnection("block_2","block_6",0), BlockConnection("block_3","block_5",0) };
1803
1804 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnect, 8u, 8u, 14u);
1805 }
1806
1807 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_9block_9quad)
1808 {
1809 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
1810 setup_mesh_9block_9quad(get_bulk());
1811 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_1","block_2"), BlockConnection("block_1", "block_4") };
1812
1813 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnect, 12u, 10u, 19u);
1814 }
1815
1816 TEST_F(TestDisconnectFullAlgorithmPartial2D, disconnect_full_algorithm_9block_9quad_v2)
1817 {
1818 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
1819 setup_mesh_9block_9quad(get_bulk());
1820 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_2","block_3"), BlockConnection("block_5","block_6"),
1821 BlockConnection("block_3","block_5"), BlockConnection("block_2","block_6"), BlockConnection("block_9", "block_6")};
1822
1823 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnect, 12u, 11u, 20u);
1824 }
1825
1826 TEST_F(TestDisconnectFullAlgorithm2D, disconnect_full_algorithm_9block_9quad_v2)
1827 {
1828 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
1829 setup_mesh_9block_9quad(get_bulk());
1830 // BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_2","block_3"), BlockConnection("block_5", "block_6"), BlockConnection("block_9", "block_6")};
1831 BlockConnectionVector blockPairsToDisconnect{ BlockConnection("block_2","block_3"), BlockConnection("block_5","block_6"),
1832 BlockConnection("block_3","block_5"), BlockConnection("block_2","block_6"), BlockConnection("block_9", "block_6")};
1833
1834 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnect, 12u, 11u, 20u);
1835 }
1836
1837 TEST_F(TestDisconnectFullAlgorithm, disconnect_full_algorithm_4block_8hex)
1838 {
1839 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1840 stk::mesh::PartVector blocks = setup_mesh_4block_8hex_cube(get_bulk());
1841 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_2","block_4",0), BlockConnection("block_1","block_2",0)};
1842 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 15u, 9u, 36u);
1843 }
1844 }
1845
1846 TEST_F(TestDisconnectFullAlgorithmPartial, disconnect_full_algorithm_4block_8hex)
1847 {
1848 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1849 stk::mesh::PartVector blocks = setup_mesh_4block_8hex_cube(get_bulk());
1850 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_2","block_4",0), BlockConnection("block_1","block_2",0)};
1851 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 15u, 9u, 36u);
1852 }
1853 }
1854
1855 TEST_F(TestDisconnectFullAlgorithm, disconnect_full_algorithm_8block_8hex_lower_corner)
1856 {
1857 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1858 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1859 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0)};
1860 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 19u, 16u, 34u);
1861 }
1862 }
1863
1864 TEST_F(TestDisconnectFullAlgorithmPartial, disconnect_full_algorithm_8block_8hex_lower_corner)
1865 {
1866 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1867 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1868 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0)};
1869 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 19u, 16u, 34u);
1870 }
1871 }
1872
1873 TEST_F(TestDisconnectFullAlgorithm, disconnect_full_algorithm_8block_8hex_opposite_corners)
1874 {
1875 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1876 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1877 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0),
1878 BlockConnection("block_3","block_7",0), BlockConnection("block_7","block_8",0), BlockConnection("block_5","block_7",0)};
1879 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 19u, 13u, 41u);
1880 }
1881 }
1882
1883 TEST_F(TestDisconnectFullAlgorithmPartial, disconnect_full_algorithm_8block_8hex_opposite_corners)
1884 {
1885 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1886 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1887 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0),
1888 BlockConnection("block_3","block_7",0), BlockConnection("block_7","block_8",0), BlockConnection("block_5","block_7",0)};
1889 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 19u, 13u, 41u);
1890 }
1891 }
1892
1893 TEST_F(TestDisconnectFullAlgorithm, disconnect_full_algorithm_8block_8hex_opposite_corners2)
1894 {
1895 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1896 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1897 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0),
1898 BlockConnection("block_5","block_7",0), BlockConnection("block_5","block_6",0), BlockConnection("block_5","block_1",0),
1899 BlockConnection("block_8","block_6",0), BlockConnection("block_8","block_4",0), BlockConnection("block_8","block_7",0),
1900 BlockConnection("block_3","block_7",0), BlockConnection("block_3","block_4",0), BlockConnection("block_3","block_1",0)};
1901 test_block_disconnect_full_algorithm(get_bulk(), blockPairsToDisconnectPairs, 19u, 0u, 64u);
1902 }
1903 }
1904
1905 TEST_F(TestDisconnectFullAlgorithmPartial, disconnect_full_algorithm_8block_8hex_opposite_corners2)
1906 {
1907 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1908 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1909 BlockConnectionVector blockPairsToDisconnectPairs{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0),
1910 BlockConnection("block_5","block_7",0), BlockConnection("block_5","block_6",0), BlockConnection("block_5","block_1",0),
1911 BlockConnection("block_8","block_6",0), BlockConnection("block_8","block_4",0), BlockConnection("block_8","block_7",0),
1912 BlockConnection("block_3","block_7",0), BlockConnection("block_3","block_4",0), BlockConnection("block_3","block_1",0)};
1913 test_block_disconnect_full_algorithm_partial_disconnect(get_bulk(), blockPairsToDisconnectPairs, 19u, 0u, 64u);
1914 }
1915 }
1916
1917 std::string get_basename(const std::string& path)
1918 {
1919 return path.substr(path.find_last_of("/\\")+1);
1920 }
1921
1922 TEST(TestDisconnectInputFile, input_mesh)
1923 {
1924 double startTime = stk::wall_time();
1925
1926 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_WORLD);
1927 stk::mesh::BulkData& bulk = *bulkPtr;
1928
1929 std::string exodusFileName = stk::unit_test_util::get_option("-exoFile", "");
1930 if (exodusFileName.empty()) return;
1931
1932 std::string disconnectBlockFile = stk::unit_test_util::get_option("-blockFile", "");
1933 if (disconnectBlockFile.empty()) return;
1934
1935 stk::io::fill_mesh(exodusFileName, bulk);
1936
1937 std::ifstream infile(disconnectBlockFile);
1938
1939 std::string block1;
1940 std::string block2;
1941 stk::tools::BlockPairVector disconnectBlockVec;
1942
1943 while(infile >> block1 >> block2) {
1944 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
1945 stk::mesh::Part* block1Part = meta.get_part(block1);
1946 stk::mesh::Part* block2Part = meta.get_part(block2);
1947
1948 if(block1Part == nullptr || block2Part == nullptr) {
1949 if(bulk.parallel_rank() == 0) {
1950 if(block1Part == nullptr) {
1951 std::cout << "could not find block name: " << block1 << std::endl;
1952 }
1953 if(block2Part == nullptr) {
1954 std::cout << "could not find block name: " << block2 << std::endl;
1955 }
1956 }
1957
1958 continue;
1959 }
1960
1961 disconnectBlockVec.push_back(stk::tools::impl::get_block_pair(block1Part, block2Part));
1962 }
1963 infile.close();
1964
1965 double meshReadTime = stk::wall_time();
1966
1967 std::cout << "Starting disconnect block sequence" << std::endl;
1968 stk::tools::disconnect_user_blocks(bulk, disconnectBlockVec, stk::tools::PRESERVE_INITIAL_HINGES);
1969
1970 double disconnectTime = stk::wall_time();
1971
1972 std::string filename = get_basename(exodusFileName);
1973 output_mesh(bulk, "disconnected_" + filename);
1974 double meshWriteTime = stk::wall_time();
1975
1976 if (bulk.parallel_rank() == 0) {
1977 std::cout << "Mesh read time = " << (meshReadTime - startTime) << " s" << std::endl;
1978 std::cout << "Mesh write time = " << (meshWriteTime - disconnectTime) << " s" << std::endl;
1979 }
1980 }
1981
1982 typedef TestDisconnectFullAlgorithm TestDisconnectUserBlocks;
1983 typedef TestDisconnectFullAlgorithm2D TestDisconnectUserBlocks2D;
1984
1985 TEST_F(TestDisconnectUserBlocks, disconnect_user_blocks_8block_8hex_opposite_corners)
1986 {
1987 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1988 stk::mesh::PartVector blocks = setup_mesh_8block_8hex_cube(get_bulk());
1989
1990 BlockConnectionVector blockPairsToDisconnectVector{BlockConnection("block_1","block_2",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_6",0),
1991 BlockConnection("block_3","block_7",0), BlockConnection("block_7","block_8",0), BlockConnection("block_5","block_7",0)};
1992 test_user_block_disconnect(get_bulk(), blockPairsToDisconnectVector, 13u);
1993 }
1994 }
1995
1996 TEST_F(TestDisconnectUserBlocks, disconnect_user_blocks_preserve_snip_option_4block_4hex)
1997 {
1998 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
1999 stk::mesh::PartVector blocks = setup_mesh_4block_4hex(get_bulk());
2000
2001 BlockConnectionVector blockPairsToDisconnectVector{BlockConnection("block_2","block_1",0), BlockConnection("block_2","block_4",0), BlockConnection("block_2","block_3",0)};
2002 test_user_block_disconnect(get_bulk(), blockPairsToDisconnectVector, 6u, stk::tools::PRESERVE_INITIAL_HINGES);
2003 }
2004 }
2005
2006 TEST_F(TestDisconnectUserBlocks, disconnect_user_blocks_snip_all_hinges_snip_option_4block_4hex)
2007 {
2008 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2) {
2009 stk::mesh::PartVector blocks = setup_mesh_4block_4hex(get_bulk());
2010
2011 BlockConnectionVector blockPairsToDisconnectVector{BlockConnection("block_2","block_1",0), BlockConnection("block_2","block_4",0)};
2012 test_user_block_disconnect(get_bulk(), blockPairsToDisconnectVector, 6u, stk::tools::SNIP_ALL_HINGES);
2013 }
2014 }
2015
2016 TEST_F(TestDisconnectUserBlocks2D, disconnect_user_blocks_2block_3quad_1hinge)
2017 {
2018 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
2019 stk::mesh::PartVector blocks = setup_mesh_3block_3quad_1hinge_linear_stack(get_bulk());
2020
2021 BlockConnectionVector blockPairsToDisconnectVector{BlockConnection("block_1","block_3",0)};
2022 test_user_block_disconnect(get_bulk(), blockPairsToDisconnectVector, 3u, stk::tools::PRESERVE_INITIAL_HINGES);
2023 }
2024 }
2025
2026 TEST_F(TestDisconnectUserBlocks2D, disconnect_user_blocks_3blocks_4quad_3proc)
2027 {
2028 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) {
2029 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_keepLowerRight(get_bulk(), 1);
2030
2031 BlockConnectionVector blockPairsToDisconnectVector{BlockConnection("block_1","block_3",0), BlockConnection("block_2","block_3",0)};
2032 test_user_block_disconnect(get_bulk(), blockPairsToDisconnectVector, 2u, stk::tools::PRESERVE_INITIAL_HINGES);
2033 }
2034 }
2035
2036 TEST_F(TestDisconnectUserBlocks2D, disconnect_user_blocks_3blocks_4quad_custom_ordinal)
2037 {
2038 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { return; }
2039
2040 stk::mesh::PartVector blocks = setup_mesh_3block_4quad_reverse_ordinal(get_bulk());
2041
2042 BlockConnectionVector blockPairsToDisconnectVector{BlockConnection("vl","lateral",0), BlockConnection("radax","lateral",0)};
2043 test_user_block_disconnect(get_bulk(), blockPairsToDisconnectVector, 2u, stk::tools::PRESERVE_INITIAL_HINGES);
2044 }
2045
2046
2047 typedef TestDisconnectBlocks2D TestBlockPairCreation;
2048
2049 TEST_F(TestBlockPairCreation, test_block_pair_creation)
2050 {
2051 setup_mesh_3block_4quad(get_bulk(), 1, 1);
2052 stk::mesh::PartVector parts;
2053 stk::tools::BlockPairVector partPairs;
2054 parts.push_back(get_meta().get_part("block_1"));
2055 parts.push_back(get_meta().get_part("block_2"));
2056 parts.push_back(get_meta().get_part("block_3"));
2057 stk::tools::impl::fill_ordered_block_pairs(parts, partPairs);
2058
2059 EXPECT_EQ(3u, partPairs.size());
2060 EXPECT_EQ("block_1", partPairs[0].first->name());
2061 EXPECT_EQ("block_2", partPairs[0].second->name());
2062 EXPECT_EQ("block_1", partPairs[1].first->name());
2063 EXPECT_EQ("block_3", partPairs[1].second->name());
2064 EXPECT_EQ("block_2", partPairs[2].first->name());
2065 EXPECT_EQ("block_3", partPairs[2].second->name());
2066 }
2067
2068 void create_ngs_jtd_sub_mesh(stk::mesh::BulkData& bulk)
2069 {
2070 stk::unit_test_util::ConstructedMesh data(3);
2071
2072 data.set_x_coordinates({ 2.69902090331971, 2.66623140978201, 2.75874573101832, 2.69902090331971,
2073 2.69659806972163, 2.68053633989566, 2.66870203682596, 2.7137889539581,
2074 2.67272988291214, 2.65367227486113, 2.76694241182748, 2.72228375387999,
2075 2.68782101822595, 2.69659805697906, 2.71378890566682, 2.73602958156478});
2076
2077 data.set_y_coordinates({ -2.54798187240236, -2.625, -2.625, -2.54798187240236, -2.66,
2078 -2.67627405696173, -2.71269330410536, -2.625, -2.625, -2.66, -2.625,
2079 -2.625, -2.625, -2.625, -2.67580141240548, -2.63747011593858 });
2080
2081 data.set_z_coordinates({ -7.71929967118528, -7.76787460984145, -7.87919008575732,
2082 -7.82910729232061, -7.83153012591869, -7.73778423460932,
2083 -7.77420348175294, -7.81433924168221, -7.71000549971963,
2084 -7.72979606467204, -7.87099340494817, -7.80584444176032,
2085 -7.72193754541886, -7.83153013866126, -7.81433928997349, -7.84971773066203 });
2086
2087 data.set_node_ids( {953299, 953347, 1046307, 1086643, 1086883, 1543476, 1598788, 3021447,
2088 3121015, 3292103, 3357047, 3704977, 3705289, 3705425, 4715689, 5185015} );
2089
2090 data.set_elem_ids( {25203969, 26788853, 27186527, 29884816, 30162566, 30162567,
2091 30822787, 30824958, 30824959, 30824960, 30824961, 26778235, 26788861,
2092 29528157, 29886393, 24040308, 24040314, 24045937, 24467153, 24467347,
2093 24562607, 24562617, 29861241, 30822789} );
2094
2095 data.set_elem_distribution( {{30824959, 1}, {26788861, 1}, {29886393, 1}, {24045937, 1}, {24467153, 1},
2096 {24467347, 1}, {24562607, 1}, {24562617, 1}, {25203969, 1}, {26788853, 1},
2097 {29884816, 1}, {30824960, 1}, {30824961, 1}, {24040308, 1}, {24040314, 1},
2098 {30822787, 1}, {30824958, 1}, {26778235, 1}, {30822789, 1}, {30162567, 0},
2099 {27186527, 1}, {29861241, 1}, {29528157, 0}, {30162566, 0}} );
2100
2101 stk::unit_test_util::ConstructedElementBlock block1(stk::topology::TET_4, "block_1", 202, { {2, 8, 9, 10},
2102 {10, 8, 9, 6},
2103 {5, 15, 16, 8},
2104 {2, 8, 10, 5},
2105 {14, 16, 3, 8},
2106 {14, 16, 8, 5},
2107 {14, 5, 8, 2},
2108 {7, 5, 8, 15},
2109 {8, 5, 7, 10},
2110 {7, 8, 6, 15},
2111 {6, 8, 7, 10} });
2112 data.add_elem_block(block1);
2113
2114 stk::unit_test_util::ConstructedElementBlock block2(stk::topology::TET_4, "block_2", 223, { {15, 12, 8, 6},
2115 {8, 13, 9, 6},
2116 {12, 16, 15, 8},
2117 {8, 12, 13, 6} });
2118 data.add_elem_block(block2);
2119
2120 stk::unit_test_util::ConstructedElementBlock block3(stk::topology::TET_4, "block_3", 245, { {2, 8, 4, 1},
2121 {2, 8, 1, 9},
2122 {8, 11, 3, 4},
2123 {8, 12, 11, 4},
2124 {8, 13, 1, 9},
2125 {8, 12, 4, 1},
2126 {8, 12, 1, 13},
2127 {3, 4, 14, 8},
2128 {4, 14, 8, 2} });
2129 data.add_elem_block(block3);
2130
2131 data.create_mesh(bulk);
2132 }
2133
2134 TEST(TestNGSDisconnect, jtd_sub_mesh)
2135 {
2136 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_WORLD);
2137 stk::mesh::BulkData& bulk = *bulkPtr;
2138 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
2139 create_ngs_jtd_sub_mesh(bulk);
2140
2141 stk::mesh::Part* block1 = meta.get_part("block_1");
2142 stk::mesh::Part* block2 = meta.get_part("block_2");
2143 stk::mesh::Part* block3 = meta.get_part("block_3");
2144
2145 stk::tools::BlockPairVector disconnectPairs{{block1, block3}, {block2, block3}};
2146 EXPECT_NO_THROW(stk::tools::disconnect_user_blocks(bulk, disconnectPairs, stk::tools::PRESERVE_INITIAL_HINGES));
2147 }
2148
2149 void create_2_tet10s_in_2_blocks_sharing_6_nodes(stk::mesh::BulkData &bulk)
2150 {
2151 std::string meshDesc;
2152
2153 auto meshDescNp1
2154 {
2155 "0,1,TET_10,1,2,3,4,6,7,8, 9,10,11,block_1\n"
2156 "0,2,TET_10,3,2,1,5,7,6,8,12,13,14,block_2"
2157 };
2158
2159 auto meshDescNp2
2160 {
2161 "0,1,TET_10,1,2,3,4,6,7,8, 9,10,11,block_1\n"
2162 "1,2,TET_10,3,2,1,5,7,6,8,12,13,14,block_2"
2163 };
2164
2165 meshDesc = (bulk.parallel_size() == 2) ? meshDescNp2 : meshDescNp1;
2166
2167 const std::vector<double> coordinates
2168 {
2169 0, 0, 0,
2170 1, 0, 0,
2171 0, 1, 0,
2172 0, 0, 1,
2173 0, 0, -1,
2174 0.5, 0, 0,
2175 0.5, 0.5, 0,
2176 0, 0.5, 0,
2177 0, 0, 0.5,
2178 0.5, 0, 0.5,
2179 0, 0.5, 0.5,
2180 0, 0.5, -0.5,
2181 0.5, 0, -0.5,
2182 0, 0, -0.5,
2183 };
2184
2185 stk::unit_test_util::setup_text_mesh(bulk, stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coordinates));
2186 }
2187
2188 void create_4_hex8s_in_2_blocks_sharing_4_nodes(stk::mesh::BulkData &bulk)
2189 {
2190 stk::io::fill_mesh("generated:4x1x1", bulk);
2191 stk::mesh::Part* block1 = bulk.mesh_meta_data().get_part("block_1");
2192 stk::mesh::Part* block2 = &create_part(bulk.mesh_meta_data(), stk::topology::HEX_8, "block_2", 2);
2193
2194 stk::mesh::EntityVector elems;
2195 for(stk::mesh::EntityId elemId : std::vector<stk::mesh::EntityId>{2,3}) {
2196 stk::mesh::Entity elem = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
2197 if (bulk.is_valid(elem) && bulk.bucket(elem).owned()) {
2198 elems.push_back(elem);
2199 }
2200 }
2201
2202 bulk.batch_change_entity_parts(elems, stk::mesh::PartVector{block2}, stk::mesh::PartVector{block1});
2203 }
2204
2205 stk::mesh::Part & create_sideset_part(stk::mesh::MetaData &meta, const size_t sidesetId)
2206 {
2207 stk::mesh::Part &sidesetPart = meta.declare_part("Sideset"+std::to_string(sidesetId), meta.side_rank());
2208 meta.set_part_id(sidesetPart, sidesetId);
2209 stk::io::put_io_part_attribute(sidesetPart);
2210 return sidesetPart;
2211 }
2212
2213 stk::mesh::Part & create_sideset_part_with_topology(stk::mesh::MetaData &meta, const size_t sidesetId, stk::topology::topology_t topo)
2214 {
2215 stk::mesh::Part &sidesetPart = meta.declare_part_with_topology("Sideset"+std::to_string(sidesetId), topo);
2216 meta.set_part_id(sidesetPart, sidesetId);
2217 stk::io::put_io_part_attribute(sidesetPart);
2218 return sidesetPart;
2219 }
2220
2221 void expect_num_nodes_faces_elems(
2222 const stk::mesh::BulkData &bulk,
2223 const size_t goldNumNodes,
2224 const size_t goldNumFaces,
2225 const size_t goldNumElems)
2226 {
2227 const stk::mesh::Selector s(bulk.mesh_meta_data().universal_part());
2228 EXPECT_EQ(goldNumNodes, stk::mesh::count_selected_entities(s, bulk.buckets(stk::topology::NODE_RANK)));
2229 EXPECT_EQ(goldNumFaces, stk::mesh::count_selected_entities(s, bulk.buckets(stk::topology::FACE_RANK)));
2230 EXPECT_EQ(goldNumElems, stk::mesh::count_selected_entities(s, bulk.buckets(stk::topology::ELEM_RANK)));
2231 }
2232
2233 void expect_one_face_in_sideset_with_adjacent_blocks(
2234 const stk::mesh::BulkData &bulk,
2235 const stk::mesh::Part &sidesetPart,
2236 const stk::mesh::ConstPartVector &goldAdjacentElemBlockParts,
2237 const size_t goldNumAdjElems)
2238 {
2239 stk::mesh::EntityVector faces;
2240 stk::mesh::get_selected_entities(sidesetPart, bulk.buckets(stk::topology::FACE_RANK), faces);
2241 ASSERT_EQ(1u, faces.size()) << " for sideset " << sidesetPart.name();
2242
2243 const size_t numAdjElems = bulk.num_elements(faces[0]);
2244 ASSERT_EQ(goldNumAdjElems, numAdjElems) << " for sideset " << sidesetPart.name();
2245 const stk::mesh::Entity *elems = bulk.begin_elements(faces[0]);
2246 for(size_t i{0}; i<numAdjElems; i++)
2247 if (bulk.bucket(elems[i]).owned()) {
2248 EXPECT_TRUE(bulk.bucket(elems[i]).member(*goldAdjacentElemBlockParts[i])) << " for sideset " << sidesetPart.name();
2249 }
2250 }
2251
2252 class TestDisconnectWithSidesets : public stk::unit_test_util::MeshFixture
2253 {
2254 protected:
2255 TestDisconnectWithSidesets() : stk::unit_test_util::MeshFixture(3)
2256 {
2257 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
2258 }
2259 };
2260
2261 TEST_F(TestDisconnectWithSidesets, twoTetsSharingFaceWith2InternalSidesets_disconnect_2facesWith1SidesetEach)
2262 {
2263 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); }
2264
2265 auto& bulk = get_bulk();
2266 auto& meta = get_meta();
2267
2268 create_2_tet10s_in_2_blocks_sharing_6_nodes(bulk);
2269 stk::mesh::Part &elemPart1 = *meta.get_part("block_1");
2270 stk::mesh::Part &elemPart2 = *meta.get_part("block_2");
2271
2272 stk::mesh::Part &facePart1 = create_sideset_part_with_topology(meta, 1, stk::topology::TRI_6);
2273 stk::mesh::Part &facePart2 = create_sideset_part_with_topology(meta, 2, stk::topology::TRI_6);
2274 meta.set_surface_to_block_mapping(&facePart1, {&elemPart1});
2275 meta.set_surface_to_block_mapping(&facePart2, {&elemPart2});
2276 stk::mesh::create_interior_block_boundary_sides(bulk, meta.universal_part(), {&facePart1, &facePart2});
2277
2278 expect_num_nodes_faces_elems(bulk, 14, 1, 2);
2279 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1, &elemPart2}, 2);
2280 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart1, &elemPart2}, 2);
2281
2282 stk::tools::disconnect_all_blocks(bulk);
2283
2284 expect_num_nodes_faces_elems(bulk, 20, 2, 2);
2285 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1}, 1);
2286 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart2}, 1);
2287
2288 EXPECT_TRUE(verify_attached_faces(bulk));
2289 }
2290
2291 TEST_F(TestDisconnectWithSidesets, twoTetsSharingFaceWith3InternalSidesets_disconnect_blocksWith3Sidesets)
2292 {
2293 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); }
2294
2295 auto& bulk = get_bulk();
2296 auto& meta = get_meta();
2297
2298 create_2_tet10s_in_2_blocks_sharing_6_nodes(bulk);
2299 stk::mesh::Part &elemPart1 = *meta.get_part("block_1");
2300 stk::mesh::Part &elemPart2 = *meta.get_part("block_2");
2301
2302 stk::mesh::Part &facePart1 = create_sideset_part_with_topology(meta, 1, stk::topology::TRI_6);
2303 stk::mesh::Part &facePart2 = create_sideset_part_with_topology(meta, 2, stk::topology::TRI_6);
2304 stk::mesh::Part &facePart3 = create_sideset_part_with_topology(meta, 3, stk::topology::TRI_6);
2305 meta.set_surface_to_block_mapping(&facePart1, {&elemPart1});
2306 meta.set_surface_to_block_mapping(&facePart2, {&elemPart1});
2307 meta.set_surface_to_block_mapping(&facePart3, {&elemPart2});
2308 stk::mesh::create_interior_block_boundary_sides(bulk, meta.universal_part(), {&facePart1, &facePart2, &facePart3});
2309
2310 expect_num_nodes_faces_elems(bulk, 14, 1, 2);
2311 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1, &elemPart2}, 2);
2312 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart1, &elemPart2}, 2);
2313 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart3, {&elemPart1, &elemPart2}, 2);
2314
2315 stk::tools::disconnect_all_blocks(bulk);
2316
2317 expect_num_nodes_faces_elems(bulk, 20, 2, 2);
2318 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1}, 1);
2319 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart1}, 1);
2320 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart3, {&elemPart2}, 1);
2321
2322 EXPECT_TRUE(verify_attached_faces(bulk));
2323 }
2324
2325 TEST_F(TestDisconnectWithSidesets, twoTetsSharingFaceWith3InternalSidesets_disconnect_blocksWith3Sidesets_reverse)
2326 {
2327 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); }
2328
2329 auto& bulk = get_bulk();
2330 auto& meta = get_meta();
2331
2332 create_2_tet10s_in_2_blocks_sharing_6_nodes(bulk);
2333 stk::mesh::Part &elemPart1 = *meta.get_part("block_1");
2334 stk::mesh::Part &elemPart2 = *meta.get_part("block_2");
2335
2336 stk::mesh::Part &facePart1 = create_sideset_part_with_topology(meta, 1, stk::topology::TRI_6);
2337 stk::mesh::Part &facePart2 = create_sideset_part_with_topology(meta, 2, stk::topology::TRI_6);
2338 stk::mesh::Part &facePart3 = create_sideset_part_with_topology(meta, 3, stk::topology::TRI_6);
2339 meta.set_surface_to_block_mapping(&facePart1, {&elemPart1});
2340 meta.set_surface_to_block_mapping(&facePart2, {&elemPart2});
2341 meta.set_surface_to_block_mapping(&facePart3, {&elemPart2});
2342 stk::mesh::create_interior_block_boundary_sides(bulk, meta.universal_part(), {&facePart1, &facePart2, &facePart3});
2343
2344 expect_num_nodes_faces_elems(bulk, 14, 1, 2);
2345 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1, &elemPart2}, 2);
2346 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart1, &elemPart2}, 2);
2347 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart3, {&elemPart1, &elemPart2}, 2);
2348
2349 stk::tools::disconnect_all_blocks(bulk);
2350
2351 expect_num_nodes_faces_elems(bulk, 20, 2, 2);
2352 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1}, 1);
2353 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart2}, 1);
2354 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart3, {&elemPart2}, 1);
2355
2356 EXPECT_TRUE(verify_attached_faces(bulk));
2357 }
2358
2359 TEST_F(TestDisconnectWithSidesets, twoTetsSharingFaceWith2InternalSidesets_two_procs)
2360 {
2361 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
2362
2363 auto& bulk = get_bulk();
2364 auto& meta = get_meta();
2365 auto rank = stk::parallel_machine_rank(MPI_COMM_WORLD);
2366
2367 create_2_tet10s_in_2_blocks_sharing_6_nodes(bulk);
2368 stk::mesh::Part &elemPart1 = *meta.get_part("block_1");
2369 stk::mesh::Part &elemPart2 = *meta.get_part("block_2");
2370
2371 stk::mesh::Part &facePart1 = create_sideset_part_with_topology(meta, 1, stk::topology::TRI_6);
2372 stk::mesh::Part &facePart2 = create_sideset_part_with_topology(meta, 2, stk::topology::TRI_6);
2373 meta.set_surface_to_block_mapping(&facePart1, {&elemPart1});
2374 meta.set_surface_to_block_mapping(&facePart2, {&elemPart2});
2375 stk::mesh::create_interior_block_boundary_sides(bulk, meta.universal_part(), {&facePart1, &facePart2});
2376
2377 expect_num_nodes_faces_elems(bulk, 14, 1, 2);
2378 if (rank == 0)
2379 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1}, 2);
2380 if (rank == 1)
2381 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart2}, 2);
2382
2383 stk::tools::disconnect_all_blocks(bulk);
2384
2385 expect_num_nodes_faces_elems(bulk, 10, 1, 1);
2386 if (rank == 0)
2387 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart1, {&elemPart1}, 1);
2388 if (rank == 1)
2389 expect_one_face_in_sideset_with_adjacent_blocks(bulk, facePart2, {&elemPart2}, 1);
2390
2391 EXPECT_TRUE(verify_attached_faces(bulk));
2392 }
2393
2394 TEST_F(TestDisconnectWithSidesets, twoHexesInTwoBlocks_with_internalSidesets)
2395 {
2396 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2397
2398 auto& bulk = get_bulk();
2399
2400 auto blocks = setup_mesh_2block_2hex_with_internal_sides(bulk);
2401 auto block1 = blocks[0];
2402 auto block2 = blocks[1];
2403
2404 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}}, stk::tools::PRESERVE_INITIAL_HINGES);
2405
2406 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2407 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2408 EXPECT_EQ(16u, get_num_total_nodes(bulk));
2409 EXPECT_EQ(1u, get_num_total_sides(bulk));
2410 EXPECT_FALSE(check_orphaned_nodes(bulk));
2411 EXPECT_TRUE(verify_attached_faces(bulk));
2412 }
2413
2414 TEST_F(TestDisconnectWithSidesets, fourHexesInThreeBlocks_with_internalSidesets)
2415 {
2416 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2417
2418 auto& bulk = get_bulk();
2419 auto blocks = setup_mesh_3block_4hex_with_internal_sides(bulk);
2420
2421 auto block1 = blocks[0];
2422 auto block2 = blocks[1];
2423 auto block3 = blocks[2];
2424
2425 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2},
2426 stk::tools::BlockPair{block1, block3},
2427 stk::tools::BlockPair{block2, block3}}, stk::tools::PRESERVE_INITIAL_HINGES);
2428
2429 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2430 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block2, block3}));
2431 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2432 EXPECT_EQ(28u, get_num_total_nodes(bulk));
2433 EXPECT_EQ(3u, get_num_total_sides(bulk));
2434 EXPECT_FALSE(check_orphaned_nodes(bulk));
2435 EXPECT_TRUE(verify_attached_faces(bulk));
2436 }
2437
2438 TEST_F(TestDisconnectWithSidesets, twoTet4InTwoBlocks_with_internalSidesets)
2439 {
2440 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2441
2442 auto& bulk = get_bulk();
2443 auto blocks = setup_mesh_2block_2cubeOfTet_with_internal_sides(bulk);
2444 auto block1 = blocks[0];
2445 auto block2 = blocks[1];
2446
2447 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}}, stk::tools::PRESERVE_INITIAL_HINGES);
2448
2449 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2450 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2451 EXPECT_EQ(16u, get_num_total_nodes(bulk));
2452 EXPECT_EQ(2u, get_num_total_sides(bulk));
2453 EXPECT_FALSE(check_orphaned_nodes(bulk));
2454 EXPECT_TRUE(verify_attached_faces(bulk));
2455 }
2456
2457 TEST_F(TestDisconnectWithSidesets, threeTet4InFourBlocks_with_internalSidesets)
2458 {
2459 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2460
2461 auto& bulk = get_bulk();
2462 auto blocks = setup_mesh_3block_4cubeOfTet_with_internal_sides(bulk);
2463 auto block1 = blocks[0];
2464 auto block2 = blocks[1];
2465 auto block3 = blocks[2];
2466
2467 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2},
2468 stk::tools::BlockPair{block1, block3},
2469 stk::tools::BlockPair{block2, block3}}, stk::tools::PRESERVE_INITIAL_HINGES);
2470
2471 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2472 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block2, block3}));
2473 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2474 EXPECT_EQ(28u, get_num_total_nodes(bulk));
2475 EXPECT_EQ(6u, get_num_total_sides(bulk));
2476 EXPECT_FALSE(check_orphaned_nodes(bulk));
2477 EXPECT_TRUE(verify_attached_faces(bulk));
2478 }
2479
2480 TEST_F(TestDisconnectWithSidesets, twoHexesInTwoBlocks_with_internalAndExternalSidesets)
2481 {
2482 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2483
2484 auto& bulk = get_bulk();
2485
2486 auto blocks = setup_mesh_2block_2hex_with_internal_and_external_sides(bulk);
2487 auto block1 = blocks[0];
2488 auto block2 = blocks[1];
2489
2490 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}}, stk::tools::PRESERVE_INITIAL_HINGES);
2491
2492 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2493 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2494 EXPECT_EQ(16u, get_num_total_nodes(bulk));
2495 EXPECT_EQ(11u, get_num_total_sides(bulk));
2496 EXPECT_FALSE(check_orphaned_nodes(bulk));
2497 EXPECT_TRUE(verify_attached_faces(bulk));
2498 }
2499
2500 TEST_F(TestDisconnectWithSidesets, twoHexesInTwoBlocks_with_dualInternalAndExternalSidesets)
2501 {
2502 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2503
2504 auto& bulk = get_bulk();
2505
2506 auto blocks = setup_mesh_2block_2hex_with_dual_internal_and_external_sides(bulk);
2507 auto block1 = blocks[0];
2508 auto block2 = blocks[1];
2509
2510 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}}, stk::tools::PRESERVE_INITIAL_HINGES);
2511
2512 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2513 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2514 EXPECT_EQ(16u, get_num_total_nodes(bulk));
2515 EXPECT_EQ(12u, get_num_total_sides(bulk));
2516 EXPECT_FALSE(check_orphaned_nodes(bulk));
2517 EXPECT_TRUE(verify_attached_faces(bulk));
2518 }
2519
2520 TEST_F(TestDisconnectWithSidesets, twoHexesInTwoBlocks_with_internalSidesetAndEmptySidesets)
2521 {
2522 if (stk::parallel_machine_size(MPI_COMM_WORLD) > 2) { GTEST_SKIP(); }
2523
2524 auto& bulk = get_bulk();
2525
2526 stk::mesh::Part * surface2 = &create_part(bulk.mesh_meta_data(), stk::topology::QUAD_4, "surface_2", 2);
2527 stk::mesh::Part * surface3 = &create_part(bulk.mesh_meta_data(), stk::topology::QUAD_4, "surface_3", 3);
2528
2529 bool loadMeshFirst = true;
2530 auto blocks = setup_mesh_2block_2hex_with_internal_sides(bulk, loadMeshFirst);
2531 auto block1 = blocks[0];
2532 auto block2 = blocks[1];
2533
2534 create_sideset(bulk, "surface_2", {"block_1"});
2535 create_sideset(bulk, "surface_3", {"block_1"});
2536
2537 unsigned numFacesInSurface2 = stk::mesh::count_selected_entities(*surface2, get_bulk().buckets(stk::topology::FACE_RANK));
2538 unsigned numFacesInSurface3 = stk::mesh::count_selected_entities(*surface3, get_bulk().buckets(stk::topology::FACE_RANK));
2539 EXPECT_EQ(0u, numFacesInSurface2);
2540 EXPECT_EQ(0u, numFacesInSurface3);
2541
2542 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}}, stk::tools::PRESERVE_INITIAL_HINGES);
2543
2544 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2545 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2546 EXPECT_EQ(16u, get_num_total_nodes(bulk));
2547 EXPECT_EQ(1u, get_num_total_sides(bulk));
2548 EXPECT_FALSE(check_orphaned_nodes(bulk));
2549 EXPECT_TRUE(verify_attached_faces(bulk));
2550
2551 numFacesInSurface2 = stk::mesh::count_selected_entities(*surface2, get_bulk().buckets(stk::topology::FACE_RANK));
2552 numFacesInSurface3 = stk::mesh::count_selected_entities(*surface3, get_bulk().buckets(stk::topology::FACE_RANK));
2553
2554 EXPECT_EQ(0u, numFacesInSurface2);
2555 EXPECT_EQ(0u, numFacesInSurface3);
2556 }
2557
2558 TEST_F(TestDisconnectWithSidesets, ALRBC)
2559 {
2560 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); }
2561
2562 auto& bulk = get_bulk();
2563
2564 std::string meshDesc =
2565 "0,1,HEX_8, 1, 2, 3, 4, 5, 6, 7, 8,block_1\n"
2566 "1,2,HEX_8, 5, 6, 7, 8, 9,10,11,12,block_2\n"
2567 "2,3,HEX_8, 9,10,11,12,13,14,15,16,block_3\n"
2568 "|coordinates: 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, 0,0,2, 1,0,2, 1,1,2, 0,1,2, 0,0,3, 1,0,3, 1,1,3, 0,1,3"
2569 "|sideset:name=surface_1; data=1,6, 2,5";
2570
2571 stk::io::fill_mesh("textmesh:" + meshDesc, bulk);
2572
2573 auto block1 = bulk.mesh_meta_data().get_part("block_1");
2574 auto block2 = bulk.mesh_meta_data().get_part("block_2");
2575 auto block3 = bulk.mesh_meta_data().get_part("block_3");
2576
2577 auto surface1 = bulk.mesh_meta_data().get_part("surface_1");
2578
2579 unsigned numFacesInSurface1 = stk::mesh::count_selected_entities(*surface1, get_bulk().buckets(stk::topology::FACE_RANK));
2580 EXPECT_EQ(1u, numFacesInSurface1);
2581
2582 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}, stk::tools::BlockPair{block2, block3}}, stk::tools::PRESERVE_INITIAL_HINGES);
2583
2584 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2585 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block2, block3}));
2586 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2587 EXPECT_EQ(24u, get_num_total_nodes(bulk));
2588 EXPECT_EQ(2u, get_num_total_sides(bulk));
2589 EXPECT_FALSE(check_orphaned_nodes(bulk));
2590 EXPECT_TRUE(verify_attached_faces(bulk));
2591
2592 numFacesInSurface1 = stk::mesh::count_selected_entities(*surface1, get_bulk().buckets(stk::topology::FACE_RANK));
2593
2594 int myProc = bulk.parallel_rank();
2595 if(myProc == 0 || myProc == 1) {
2596 EXPECT_EQ(1u, numFacesInSurface1);
2597 } else {
2598 EXPECT_EQ(0u, numFacesInSurface1);
2599 }
2600 }
2601
2602 TEST_F(TestDisconnectWithSidesets, ALRB)
2603 {
2604 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
2605
2606 auto& bulk = get_bulk();
2607
2608 std::string meshDesc =
2609 "1,1,HEX_8, 1, 2, 3, 4, 5, 6, 7, 8,block_1\n"
2610 "0,2,HEX_8, 5, 6, 7, 8, 9,10,11,12,block_2\n"
2611 "|coordinates: 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, 0,0,2, 1,0,2, 1,1,2, 0,1,2"
2612 "|sideset:name=surface_1; data=1,6, 2,5";
2613
2614 stk::io::fill_mesh("textmesh:" + meshDesc, bulk);
2615
2616 auto block1 = bulk.mesh_meta_data().get_part("block_1");
2617 auto block2 = bulk.mesh_meta_data().get_part("block_2");
2618
2619 auto surface1 = bulk.mesh_meta_data().get_part("surface_1");
2620
2621 unsigned numFacesInSurface1 = stk::mesh::count_selected_entities(*surface1, get_bulk().buckets(stk::topology::FACE_RANK));
2622 EXPECT_EQ(1u, numFacesInSurface1);
2623
2624 stk::tools::disconnect_user_blocks(bulk, stk::tools::BlockPairVector{stk::tools::BlockPair{block1, block2}}, stk::tools::PRESERVE_INITIAL_HINGES);
2625
2626 EXPECT_EQ(0u, get_num_intersecting_nodes(bulk, {block1, block2}));
2627 EXPECT_EQ(0u, get_num_common_sides(bulk, {block1, block2}));
2628 EXPECT_EQ(16u, get_num_total_nodes(bulk));
2629 EXPECT_EQ(2u, get_num_total_sides(bulk));
2630 EXPECT_FALSE(check_orphaned_nodes(bulk));
2631 EXPECT_TRUE(verify_attached_faces(bulk));
2632
2633 numFacesInSurface1 = stk::mesh::count_selected_entities(*surface1, get_bulk().buckets(stk::topology::FACE_RANK));
2634
2635 EXPECT_EQ(1u, numFacesInSurface1);
2636 }
2637