Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestAura.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include <gtest/gtest.h> // for AssertHelper, EXPECT_TRUE, etc
36 #include <stk_unit_test_utils/MeshFixture.hpp>
37 #include <stk_mesh/base/BulkData.hpp> // for BulkData
38 #include <stk_mesh/base/GetEntities.hpp>
39 #include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp>
40 #include <stk_mesh/baseImpl/AuraGhosting.hpp>
41 #include <stk_mesh/base/DestroyElements.hpp>
42 #include <stk_mesh/base/ForEachEntity.hpp>
43 #include <stk_mesh/base/FEMHelpers.hpp> // for declare_element
44 #include <stk_mesh/base/GetEntities.hpp>
45 #include "mpi.h" // for MPI_COMM_WORLD, etc
46 #include "stk_mesh/base/Bucket.hpp" // for Bucket
47 #include "stk_mesh/base/Entity.hpp" // for Entity
48 #include "stk_mesh/base/MetaData.hpp" // for MetaData
49 #include "stk_mesh/base/Types.hpp" // for PartVector, EntityId, etc
50 #include "stk_mesh/base/Comm.hpp"
51 #include "stk_topology/topology.hpp" // for topology, etc
52 #include "stk_io/FillMesh.hpp"
53 #include "stk_mesh/base/MeshBuilder.hpp"
54 #include "stk_unit_test_utils/BuildMesh.hpp"
55 #include "UnitTestTextMeshFixture.hpp"
56 #include "TestElemElemGraphUtils.hpp"
57
58 namespace stk { namespace mesh { class Part; } }
59
60
61 namespace stk
62 {
63 namespace mesh
64 {
65 class FieldBase;
66 }
67 }
68
69 namespace
70 {
71 using stk::unit_test_util::build_mesh;
72 constexpr stk::mesh::EntityState Unchanged = stk::mesh::EntityState::Unchanged;
73 constexpr stk::mesh::EntityState Created = stk::mesh::EntityState::Created;
74 constexpr stk::mesh::EntityState Modified = stk::mesh::EntityState::Modified;
75 constexpr stk::mesh::EntityState Deleted = stk::mesh::EntityState::Deleted;
76
77 void delete_elem2_on_p1(stk::mesh::BulkData& bulk)
78 {
79 bulk.modification_begin();
80
81 if (bulk.parallel_rank() == 1) {
82 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, 2);
83 EXPECT_TRUE(bulk.is_valid(elem2));
84 bool successfullyDestroyed = bulk.destroy_entity(elem2);
85 EXPECT_TRUE(successfullyDestroyed);
86 }
87
88 bulk.modification_end();
89 }
90
91 void expect_nodes_1_to_4_in_aura_on_p1(const stk::mesh::BulkData& bulk)
92 {
93 if (bulk.parallel_rank() == 1) {
94 for(stk::mesh::EntityId id : {1, 2, 3, 4}) {
95 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, id);
96 EXPECT_TRUE(bulk.is_valid(node) && bulk.bucket(node).in_aura());
97 }
98 }
99 }
100
101 void expect_nodes_1_to_8_no_longer_valid_on_p1(const stk::mesh::BulkData& bulk)
102 {
103 if (bulk.parallel_rank() == 1) {
104 for(stk::mesh::EntityId id : {1, 2, 3, 4, 5, 6, 7, 8}) {
105 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, id);
106 EXPECT_FALSE(bulk.is_valid(node));
107 }
108 }
109 }
110
111 TEST(BulkDataTest, cleanupAura_nominal)
112 {
113 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
114
115 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(MPI_COMM_WORLD, stk::mesh::BulkData::AUTO_AURA);
116 stk::mesh::BulkData& bulk = *bulkPtr;
117 stk::io::fill_mesh("generated:1x1x2|sideset:Z", bulk);
118
119 bulk.modification_begin();
120 stk::mesh::impl::AuraGhosting auraGhosting;
121 EXPECT_NO_THROW(auraGhosting.remove_aura(bulk));
122 bulk.modification_end();
123 }
124
125 TEST(BulkDataTest, cleanupAura_deletedFaceOnOtherProc)
126 {
127 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
128
129 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(MPI_COMM_WORLD, stk::mesh::BulkData::AUTO_AURA);
130 stk::mesh::BulkData& bulk = *bulkPtr;
131 stk::io::fill_mesh("generated:1x1x2|sideset:Z", bulk);
132
133 bulk.modification_begin();
134 if (bulk.parallel_rank() == 0) {
135 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, 2);
136 EXPECT_TRUE(bulk.is_valid(elem2));
137 EXPECT_TRUE(bulk.bucket(elem2).in_aura());
138 ASSERT_EQ(1u, bulk.num_connectivity(elem2, stk::topology::FACE_RANK));
139 stk::mesh::Entity face = bulk.begin(elem2, stk::topology::FACE_RANK)[0];
140 EXPECT_TRUE(bulk.bucket(face).in_aura());
141 }
142
143 if (bulk.parallel_rank() == 1) {
144 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, 2);
145 EXPECT_TRUE(bulk.is_valid(elem2));
146 ASSERT_EQ(1u, bulk.num_connectivity(elem2, stk::topology::FACE_RANK));
147 stk::mesh::Entity face = bulk.begin(elem2, stk::topology::FACE_RANK)[0];
148 stk::mesh::ConnectivityOrdinal faceOrd = bulk.begin_ordinals(elem2, stk::topology::FACE_RANK)[0];
149 EXPECT_TRUE(bulk.bucket(face).owned());
150 bulk.destroy_relation(elem2, face, faceOrd);
151 EXPECT_TRUE(bulk.destroy_entity(face));
152 }
153
154 stk::mesh::impl::AuraGhosting auraGhosting;
155 EXPECT_NO_THROW(auraGhosting.remove_aura(bulk));
156 bulk.modification_end();
157 }
158
159 TEST(BulkDataTest, destroyDependentGhostsConnectedToDeletedShared)
160 {
161 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
162
163 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(MPI_COMM_WORLD, stk::mesh::BulkData::AUTO_AURA);
164 stk::mesh::BulkData& bulk = *bulkPtr;
165 stk::io::fill_mesh("generated:1x1x2", bulk);
166
167 expect_nodes_1_to_4_in_aura_on_p1(bulk);
168 delete_elem2_on_p1(bulk);
169 expect_nodes_1_to_8_no_longer_valid_on_p1(bulk);
170 }
171
172 stk::mesh::Part& setupDavidNobleTestCaseTkt12837(stk::mesh::BulkData& bulk)
173 {
174 //
175 // 5____1 1 1____3
176 // | / /|\ \ |
177 // |E3/ / | \ \E1|
178 // | / /E4|E2\ \ |
179 // |/ /___|___\ \|
180 // 6 6 4 2 2
181 //
182 // P2 P1 P0
183 //
184
185 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
186
187 stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::TRIANGLE_3_2D);
188 stk::mesh::Part& nonConformalPart = meta.declare_part("noconform", stk::topology::ELEMENT_RANK);
189
190 meta.commit();
191
192 bulk.modification_begin();
193
194 stk::mesh::EntityIdVector elem1_nodes {1, 2, 3}; // 1
195 stk::mesh::EntityIdVector elem2_nodes {1, 4, 2}; // 2
196 stk::mesh::EntityIdVector elem3_nodes {6, 1, 5}; // 3
197 stk::mesh::EntityIdVector elem4_nodes {6, 4, 1}; // 4
198
199 stk::mesh::EntityId elemId1 = 1; // p0
200 stk::mesh::EntityId elemId2 = 2; // p1
201 stk::mesh::EntityId elemId3 = 3; // p2
202 stk::mesh::EntityId elemId4 = 4; // p1
203
204 if(bulk.parallel_size()==1 || bulk.parallel_rank() == 0)
205 {
206 stk::mesh::declare_element(bulk, block_1, elemId1, elem1_nodes);
207 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
208 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
209 if (bulk.parallel_size() == 3) {
210 bulk.add_node_sharing(node1, 1);
211 bulk.add_node_sharing(node1, 2);
212 bulk.add_node_sharing(node2, 1);
213 }
214 }
215 if(bulk.parallel_size()==1 || bulk.parallel_rank() == 1)
216 {
217 stk::mesh::declare_element(bulk, block_1, elemId2, elem2_nodes);
218 stk::mesh::declare_element(bulk, block_1, elemId4, elem4_nodes);
219
220 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
221 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
222 stk::mesh::Entity node6 = bulk.get_entity(stk::topology::NODE_RANK, 6);
223 if (bulk.parallel_size() == 3) {
224 bulk.add_node_sharing(node1, 2);
225 bulk.add_node_sharing(node6, 2);
226
227 bulk.add_node_sharing(node1, 0);
228 bulk.add_node_sharing(node2, 0);
229 }
230 }
231 if(bulk.parallel_size()==1 || bulk.parallel_rank() == 2)
232 {
233 stk::mesh::declare_element(bulk, block_1, elemId3, elem3_nodes);
234 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
235 stk::mesh::Entity node6 = bulk.get_entity(stk::topology::NODE_RANK, 6);
236 if (bulk.parallel_size() == 3) {
237 bulk.add_node_sharing(node1, 0);
238 bulk.add_node_sharing(node1, 1);
239 bulk.add_node_sharing(node6, 1);
240 }
241 }
242
243 bulk.modification_end();
244
245 return nonConformalPart;
246 }
247
248 stk::mesh::Part& setupDavidNobleTestCaseTkt14337(stk::mesh::BulkData& bulk)
249 {
250 //
251 // 5____1 1 1____3
252 // /| / /|\ \ |
253 // / |E3/ / | \ \E1|
254 // /E5| / /E4|E2\ \ |
255 // /___|/ /___|___\ \|
256 // 7 6 6 4 2 2
257 //
258 // P2 P1 P0
259 //
260
261 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
262
263 stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::TRIANGLE_3_2D);
264 stk::mesh::Part& nonConformalPart = meta.declare_part("noconform", stk::topology::ELEMENT_RANK);
265 stk::mesh::Part& edgePart = meta.declare_part("edge_part", stk::topology::EDGE_RANK);
266 stk::mesh::PartVector edgeParts = {&edgePart};
267
268 meta.commit();
269
270 bulk.modification_begin();
271
272 stk::mesh::EntityIdVector elem1_nodes {1, 2, 3}; // 1
273 stk::mesh::EntityIdVector elem2_nodes {1, 4, 2}; // 2
274 stk::mesh::EntityIdVector elem3_nodes {6, 1, 5}; // 3
275 stk::mesh::EntityIdVector elem4_nodes {6, 4, 1}; // 4
276 stk::mesh::EntityIdVector elem5_nodes {7, 6, 5}; // 5
277
278 stk::mesh::EntityId elemId1 = 1; // p0
279 stk::mesh::EntityId elemId2 = 2; // p1
280 stk::mesh::EntityId elemId3 = 3; // p2
281 stk::mesh::EntityId elemId4 = 4; // p1
282 stk::mesh::EntityId elemId5 = 5; // p2
283
284 if(bulk.parallel_rank() == 0)
285 {
286 stk::mesh::declare_element(bulk, block_1, elemId1, elem1_nodes);
287 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
288 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
289 bulk.add_node_sharing(node1, 1);
290 bulk.add_node_sharing(node1, 2);
291 bulk.add_node_sharing(node2, 1);
292 }
293 else if(bulk.parallel_rank() == 1)
294 {
295 stk::mesh::declare_element(bulk, block_1, elemId2, elem2_nodes);
296 stk::mesh::declare_element(bulk, block_1, elemId4, elem4_nodes);
297
298 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
299 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
300 stk::mesh::Entity node6 = bulk.get_entity(stk::topology::NODE_RANK, 6);
301 bulk.add_node_sharing(node1, 2);
302 bulk.add_node_sharing(node6, 2);
303
304 bulk.add_node_sharing(node1, 0);
305 bulk.add_node_sharing(node2, 0);
306 }
307 else
308 {
309 stk::mesh::declare_element(bulk, block_1, elemId3, elem3_nodes);
310 stk::mesh::declare_element(bulk, block_1, elemId5, elem5_nodes);
311 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
312 stk::mesh::Entity node6 = bulk.get_entity(stk::topology::NODE_RANK, 6);
313 bulk.add_node_sharing(node1, 0);
314 bulk.add_node_sharing(node1, 1);
315 bulk.add_node_sharing(node6, 1);
316 }
317
318 bulk.modification_end();
319
320 bulk.initialize_face_adjacent_element_graph();
321
322 bulk.modification_begin();
323
324 if (bulk.parallel_rank() == 1) {
325 stk::mesh::Entity elem4 = bulk.get_entity(stk::topology::ELEM_RANK, 4);
326 bulk.declare_element_side(elem4, 0, edgeParts);
327 bulk.declare_element_side(elem4, 2, edgeParts);
328 }
329 else if (bulk.parallel_rank() == 2) {
330 stk::mesh::Entity elem3 = bulk.get_entity(stk::topology::ELEM_RANK, 3);
331 bulk.declare_element_side(elem3, 0, edgeParts);
332 bulk.declare_element_side(elem3, 2, edgeParts);
333 }
334
335 bulk.modification_end();
336
337 bulk.modification_begin();
338 stk::mesh::Ghosting& ghosting = bulk.create_ghosting("myCustomGhosting");
339 stk::mesh::EntityProcVec elemToGhost;
340 const int destProc = 0;
341 if (bulk.parallel_rank() == 1) {
342 elemToGhost.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::ELEM_RANK, 4), destProc));
343 }
344 if (bulk.parallel_rank() == 2) {
345 elemToGhost.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::ELEM_RANK, 3), destProc));
346 }
347
348 bulk.change_ghosting(ghosting, elemToGhost);
349 bulk.modification_end();
350
351 return nonConformalPart;
352 }
353
354 bool isEntityInPart(stk::mesh::BulkData &bulk, stk::mesh::EntityRank rank, stk::mesh::EntityId id, const stk::mesh::Part &part)
355 {
356 stk::mesh::Entity entity = bulk.get_entity(rank, id);
357 return bulk.bucket(entity).member(part);
358 }
359
360 void put_elements_in_part(stk::mesh::BulkData& bulk,
361 const stk::mesh::EntityIdVector& elemIds,
362 stk::mesh::Part& part)
363 {
364 stk::mesh::PartVector addParts = {&part};
365 stk::mesh::PartVector rmParts;
366 bulk.modification_begin();
367
368 for(stk::mesh::EntityId elemId : elemIds) {
369 stk::mesh::Entity elem = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
370 if (bulk.is_valid(elem) && bulk.parallel_rank() == bulk.parallel_owner_rank(elem)) {
371 bulk.change_entity_parts(elem, addParts, rmParts);
372 }
373 }
374
375 bulk.modification_end();
376 }
377
378 void test_node6_shared_and_aura(const stk::mesh::BulkData& bulk)
379 {
380 stk::mesh::Entity node6 = bulk.get_entity(stk::topology::NODE_RANK, 6);
381 if(bulk.parallel_rank() == 0) {
382 EXPECT_TRUE(bulk.bucket(node6).in_aura());
383 }
384 else if(bulk.parallel_rank() == 1) {
385 EXPECT_TRUE(bulk.bucket(node6).owned());
386 EXPECT_TRUE(bulk.bucket(node6).shared());
387 }
388 else {
389 EXPECT_TRUE(!bulk.bucket(node6).owned());
390 EXPECT_TRUE(bulk.bucket(node6).shared());
391 }
392 }
393
394 TEST(BulkDataTest, removeElemPartWithNodeSharedWithOneProcAndAuraToAnotherProc)
395 {
396 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); }
397
398 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(2, MPI_COMM_WORLD);
399 stk::mesh::BulkData& bulk = *bulkPtr;
400
401 stk::mesh::Part& nonConformalPart = setupDavidNobleTestCaseTkt12837(bulk);
402
403 {
404 put_elements_in_part(bulk, {3}, nonConformalPart);
405
406 EXPECT_TRUE(isEntityInPart(bulk, stk::topology::NODE_RANK, 6, nonConformalPart));
407 }
408
409 {
410 bulk.modification_begin();
411 if(bulk.parallel_rank() == 2)
412 {
413 stk::mesh::PartVector add_parts;
414 stk::mesh::PartVector rm_parts;
415 rm_parts.push_back(&nonConformalPart);
416 stk::mesh::Entity element_3 = bulk.get_entity(stk::topology::ELEMENT_RANK, 3);
417 bulk.change_entity_parts(element_3, add_parts, rm_parts);
418 }
419
420 EXPECT_TRUE(isEntityInPart(bulk, stk::topology::NODE_RANK, 6, nonConformalPart));
421
422 bulk.modification_end();
423
424 EXPECT_FALSE(isEntityInPart(bulk, stk::topology::NODE_RANK, 6, nonConformalPart));
425
426 test_node6_shared_and_aura(bulk);
427 }
428 }
429
430 TEST(BulkDataTest, disconnectReconnectElem_AddNewSharedSide_checkGraph)
431 {
432 const int numProcs = stk::parallel_machine_size(MPI_COMM_WORLD);
433 if (numProcs != 1 && numProcs != 3) { GTEST_SKIP(); }
434
435 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(2, MPI_COMM_WORLD);
436 stk::mesh::BulkData& bulk = *bulkPtr;
437
438 setupDavidNobleTestCaseTkt12837(bulk);
439 bulk.initialize_face_adjacent_element_graph();
440
441 stk::mesh::Entity elem1 = bulk.get_entity(stk::topology::ELEMENT_RANK, 1);
442 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEMENT_RANK, 2);
443 stk::mesh::Entity elem4 = bulk.get_entity(stk::topology::ELEMENT_RANK, 4);
444 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
445
446 if (bulk.parallel_size()==1 || bulk.parallel_rank() == 1) {
447 stk::unit_test::verify_graph_edge_between_elems(bulk, elem2, elem4);
448 }
449
450 {
451 std::ostringstream os;
452 os<<"P"<<bulk.parallel_rank()<<" beginning mesh-mod"<<std::endl;
453 std::cerr<<os.str();
454 }
455 bulk.modification_begin();
456
457 if(bulk.parallel_size()==1 || bulk.parallel_rank() == 0)
458 {
459 stk::mesh::ConnectivityOrdinal nodeOrd = 0;
460 bulk.destroy_relation(elem1, node1, nodeOrd);
461 bulk.declare_relation(elem1, node1, nodeOrd);
462 unsigned sideOrd = 0;
463 bulk.declare_element_side<stk::mesh::ConstPartVector>(elem1, sideOrd);
464 }
465
466 if(bulk.parallel_size()==1 || bulk.parallel_rank() == 1)
467 {
468 stk::mesh::ConnectivityOrdinal nodeOrd = 0;
469 bulk.destroy_relation(elem2, node1, nodeOrd);
470 bulk.declare_relation(elem2, node1, nodeOrd);
471 unsigned sideOrd = 0;
472 bulk.declare_element_side<stk::mesh::ConstPartVector>(elem2, sideOrd);
473 }
474
475 {
476 stk::parallel_machine_barrier(bulk.parallel());
477 std::ostringstream os;
478 os<<"P"<<bulk.parallel_rank()<<" calling mod-end"<<std::endl;
479 std::cerr<<os.str();
480 stk::parallel_machine_barrier(bulk.parallel());
481 }
482 bulk.modification_end();
483
484 if (bulk.parallel_size()==1 || bulk.parallel_rank() == 1) {
485 stk::unit_test::verify_graph_edge_between_elems(bulk, elem2, elem4);
486 }
487 }
488
489 TEST(BulkDataTest, removeEdgeFromPartWithNodeSharedWithOneProcAndGhostedToAnotherProc)
490 {
491 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); }
492
493 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(2, MPI_COMM_WORLD, stk::mesh::BulkData::NO_AUTO_AURA);
494 stk::mesh::BulkData& bulk = *bulkPtr;
495
496 stk::mesh::Part& nonConformalPart = setupDavidNobleTestCaseTkt14337(bulk);
497 stk::mesh::PartVector edgeParts = {bulk.mesh_meta_data().get_part("edge_part")};
498 EXPECT_TRUE(!edgeParts.empty());
499 EXPECT_TRUE(edgeParts[0] != nullptr);
500
501 {
502 put_elements_in_part(bulk, {3,4}, nonConformalPart);
503
504 EXPECT_TRUE(isEntityInPart(bulk, stk::topology::NODE_RANK, 6, *edgeParts[0]));
505 }
506
507 {
508 bulk.modification_begin();
509 if(bulk.parallel_rank() == 1)
510 {
511 stk::mesh::PartVector add_parts;
512 stk::mesh::Entity edge31 = bulk.get_entity(stk::topology::EDGE_RANK, 31);
513 stk::mesh::Entity edge41 = bulk.get_entity(stk::topology::EDGE_RANK, 41);
514 ASSERT_TRUE(bulk.is_valid(edge31));
515 ASSERT_TRUE(bulk.is_valid(edge41));
516 stk::mesh::Entity elem4 = bulk.get_entity(stk::topology::ELEM_RANK, 4);
517 bulk.destroy_relation(elem4, edge31, 2);
518 bulk.destroy_entity(edge31);
519 bulk.change_entity_parts(edge41, add_parts, edgeParts);
520 }
521 if(bulk.parallel_rank() == 2)
522 {
523 stk::mesh::Entity edge31 = bulk.get_entity(stk::topology::EDGE_RANK, 31);
524 ASSERT_TRUE(bulk.is_valid(edge31));
525 stk::mesh::Entity elem3 = bulk.get_entity(stk::topology::ELEM_RANK, 3);
526 bulk.destroy_relation(elem3, edge31, 0);
527 bulk.destroy_entity(edge31);
528 stk::mesh::PartVector empty_parts;
529 bulk.declare_element_side(elem3, 0, empty_parts);
530 }
531
532 EXPECT_TRUE(isEntityInPart(bulk, stk::topology::NODE_RANK, 6, *edgeParts[0]));
533
534 stk::mesh::EntityProcVec addGhost;
535 if (bulk.parallel_rank() == 2) {
536 addGhost.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::EDGE_RANK, 31), 0));
537 }
538 bulk.change_ghosting(*bulk.ghostings()[2], addGhost);
539
540 EXPECT_TRUE(isEntityInPart(bulk, stk::topology::NODE_RANK, 6, *edgeParts[0]));
541 }
542 }
543
544 void disconnect_elem1_on_proc0(stk::mesh::BulkData& bulk)
545 {
546 bulk.modification_begin();
547
548 if (bulk.parallel_rank() == 0) {
549 stk::mesh::EntityId elemId = 1;
550 stk::mesh::Entity elem1 = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
551
552 const unsigned numSharedNodes = 4;
553 stk::mesh::EntityId sharedNodeIds[] = {5, 6, 8, 7};
554 stk::mesh::ConnectivityOrdinal nodeOrds[] = {4, 5, 6, 7};
555 stk::mesh::EntityId newNodeIds[] = {13, 14, 16, 15};
556
557 for(unsigned n=0; n<numSharedNodes; ++n) {
558 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, sharedNodeIds[n]);
559 bulk.destroy_relation(elem1, node, nodeOrds[n]);
560 stk::mesh::Entity newNode = bulk.declare_node(newNodeIds[n]);
561 bulk.declare_relation(elem1, newNode, nodeOrds[n]);
562 }
563 }
564 bulk.modification_end();
565 }
566
567 void partially_disconnect_elem1_on_proc0(stk::mesh::BulkData& bulk)
568 {
569 bulk.modification_begin();
570
571 if (bulk.parallel_rank() == 0) {
572 stk::mesh::EntityId elemId = 2;
573 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
574 bulk.destroy_entity(elem2);
575
576 elemId = 1;
577 stk::mesh::Entity elem1 = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
578
579 const unsigned numSharedNodesToDisconnect = 2;
580 stk::mesh::EntityId sharedNodeIds[] = {5, 6};
581 stk::mesh::ConnectivityOrdinal nodeOrds[] = {4, 5};
582 stk::mesh::EntityId newNodeIds[] = {13, 14};
583
584 for(unsigned n=0; n<numSharedNodesToDisconnect; ++n) {
585 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, sharedNodeIds[n]);
586 bulk.destroy_relation(elem1, node, nodeOrds[n]);
587 bulk.destroy_entity(node);
588 stk::mesh::Entity newNode = bulk.declare_node(newNodeIds[n]);
589 bulk.declare_relation(elem1, newNode, nodeOrds[n]);
590 }
591 }
592 bulk.modification_end();
593 }
594
595 void disconnect_elem2_on_proc1(stk::mesh::BulkData& bulk)
596 {
597 bulk.modification_begin();
598
599 if (bulk.parallel_rank() == 1) {
600 stk::mesh::EntityId elemId = 2;
601 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
602
603 const unsigned numSharedNodes = 4;
604 stk::mesh::EntityId sharedNodeIds[] = {5, 6, 8, 7};
605 stk::mesh::ConnectivityOrdinal nodeOrds[] = {0, 1, 2, 3};
606 stk::mesh::EntityId newNodeIds[] = {13, 14, 16, 15};
607
608 for(unsigned n=0; n<numSharedNodes; ++n) {
609 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, sharedNodeIds[n]);
610 bulk.destroy_relation(elem2, node, nodeOrds[n]);
611 stk::mesh::Entity newNode = bulk.declare_node(newNodeIds[n]);
612 bulk.declare_relation(elem2, newNode, nodeOrds[n]);
613 }
614 }
615 bulk.modification_end();
616 }
617
618 void partially_disconnect_elem2_on_proc1(stk::mesh::BulkData& bulk)
619 {
620 bulk.modification_begin();
621
622 if (bulk.parallel_rank() == 0) {
623 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, 2);
624 bulk.destroy_entity(elem2);
625 }
626
627 if (bulk.parallel_rank() == 1) {
628 stk::mesh::Entity elem1 = bulk.get_entity(stk::topology::ELEM_RANK, 1);
629 bulk.destroy_entity(elem1);
630
631 stk::mesh::EntityId elemId = 2;
632 stk::mesh::Entity elem2 = bulk.get_entity(stk::topology::ELEM_RANK, elemId);
633
634 const unsigned numSharedNodesToDisconnect = 2;
635 stk::mesh::EntityId sharedNodeIds[] = {5, 6};
636 stk::mesh::ConnectivityOrdinal nodeOrds[] = {0, 1};
637 stk::mesh::EntityId newNodeIds[] = {13, 14};
638
639 for(unsigned n=0; n<numSharedNodesToDisconnect; ++n) {
640 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, sharedNodeIds[n]);
641 bulk.destroy_relation(elem2, node, nodeOrds[n]);
642 stk::mesh::Entity newNode = bulk.declare_node(newNodeIds[n]);
643 bulk.declare_relation(elem2, newNode, nodeOrds[n]);
644 }
645 }
646 bulk.modification_end();
647 }
648
649 void check_node_states_for_elem(const stk::mesh::BulkData& mesh,
650 stk::mesh::EntityId elemId,
651 stk::mesh::EntityState expectedNodeStates[])
652 {
653 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEM_RANK, elemId);
654 ASSERT_TRUE(mesh.is_valid(elem));
655 const unsigned numNodes = mesh.num_nodes(elem);
656 const stk::mesh::Entity* nodes = mesh.begin_nodes(elem);
657 for(unsigned n=0; n<numNodes; ++n) {
658 EXPECT_EQ(expectedNodeStates[n], mesh.state(nodes[n]))
659 <<"state="<<mesh.state(nodes[n])
660 <<" for node "<<mesh.identifier(nodes[n])
661 <<" of elem "<<mesh.identifier(elem)
662 <<" on proc "<<mesh.parallel_rank()
663 <<" expectedNodeState="<<expectedNodeStates[n];
664 }
665 }
666
667 void check_elem_state(const stk::mesh::BulkData& mesh,
668 stk::mesh::EntityId elemId,
669 stk::mesh::EntityState expectedState)
670 {
671 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEM_RANK, elemId);
672 const bool expectValid = expectedState != Deleted;
673 if (expectValid) {
674 ASSERT_TRUE(mesh.is_valid(elem))<<"elem "<<elemId;
675 }
676 EXPECT_EQ(expectedState, mesh.state(elem))
677 <<"state="<<mesh.state(elem)
678 <<" for elem "<<elemId
679 <<" on proc "<<mesh.parallel_rank()
680 <<" expectedState="<<expectedState;
681 }
682
683 void confirm_entities_not_valid(const stk::mesh::BulkData& mesh,
684 stk::mesh::EntityRank rank,
685 const stk::mesh::EntityIdVector& ids)
686 {
687 for(stk::mesh::EntityId id : ids) {
688 stk::mesh::Entity entity = mesh.get_entity(rank, id);
689 EXPECT_FALSE(mesh.is_valid(entity))<<" entity "<<mesh.entity_key(entity)
690 <<" is valid, expected NOT valid.";
691 }
692 }
693
694 void test_aura_disconnect_elem_from_shared_owned_nodes(stk::mesh::BulkData& mesh)
695 {
696 disconnect_elem1_on_proc0(mesh);
697
698 int thisProc = stk::parallel_machine_rank(mesh.parallel());
699 stk::mesh::EntityId auraElemId = 2;
700 if (thisProc == 1) {
701 auraElemId = 1;
702 }
703 if (thisProc == 0) {
704 check_elem_state(mesh, auraElemId, Modified);
705
706 stk::mesh::EntityState expectedAuraElemNodeStates[] = {
707 Modified, Modified, Modified, Modified,
708 Unchanged, Unchanged, Unchanged, Unchanged
709 };
710 check_node_states_for_elem(mesh, auraElemId, expectedAuraElemNodeStates);
711
712 stk::mesh::EntityId ownedElemId = 1;
713 stk::mesh::Entity ownedElem = mesh.get_entity(stk::topology::ELEM_RANK, ownedElemId);
714 EXPECT_EQ(Modified, mesh.state(ownedElem));
715 stk::mesh::EntityState expectedNodeStates[] = {
716 Unchanged, Unchanged, Unchanged, Unchanged,
717 Created, Created, Created, Created
718 };
719 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
720 }
721 else {
722 confirm_entities_not_valid(mesh, stk::topology::ELEM_RANK,
723 stk::mesh::EntityIdVector{auraElemId});
724 confirm_entities_not_valid(mesh, stk::topology::NODE_RANK,
725 stk::mesh::EntityIdVector{1, 2, 3, 4});
726
727 stk::mesh::EntityId ownedElemId = 2;
728 stk::mesh::EntityState expectedNodeStates[] = {
729 Modified, Modified, Modified, Modified,
730 Unchanged, Unchanged, Unchanged, Unchanged
731 };
732 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
733 }
734 }
735
736 void test_aura_partially_disconnect_elem_from_shared_owned_nodes(stk::mesh::BulkData& mesh)
737 {
738 partially_disconnect_elem1_on_proc0(mesh);
739
740 int thisProc = stk::parallel_machine_rank(mesh.parallel());
741 stk::mesh::EntityId auraElemId = 2;
742 if (thisProc == 1) {
743 auraElemId = 1;
744 }
745 if (thisProc == 0) {
746 check_elem_state(mesh, auraElemId, Created);
747
748 stk::mesh::EntityState expectedAuraElemNodeStates[] = {
749 Created, Created, Modified, Modified,
750 Modified, Modified, Modified, Modified
751 };
752 check_node_states_for_elem(mesh, auraElemId, expectedAuraElemNodeStates);
753
754 stk::mesh::EntityId ownedElemId = 1;
755 stk::mesh::Entity ownedElem = mesh.get_entity(stk::topology::ELEM_RANK, ownedElemId);
756 EXPECT_EQ(Modified, mesh.state(ownedElem));
757 stk::mesh::EntityState expectedNodeStates[] = {
758 Unchanged, Unchanged, Unchanged, Unchanged,
759 Created, Created, Modified, Modified
760 };
761 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
762 }
763 else {
764 check_elem_state(mesh, auraElemId, Created);
765 stk::mesh::EntityState expectedAuraElemNodeStates[] = {
766 Modified, Modified, Modified, Modified,
767 Created, Created, Modified, Modified
768 };
769 check_node_states_for_elem(mesh, auraElemId, expectedAuraElemNodeStates);
770
771 stk::mesh::EntityId ownedElemId = 2;
772 stk::mesh::EntityState expectedNodeStates[] = {
773 Modified, Modified, Modified, Modified,
774 Modified, Modified, Modified, Modified
775 };
776 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
777 }
778 }
779
780 void test_aura_disconnect_elem_from_shared_not_owned_nodes(stk::mesh::BulkData& mesh)
781 {
782 disconnect_elem2_on_proc1(mesh);
783
784 int thisProc = stk::parallel_machine_rank(mesh.parallel());
785 stk::mesh::EntityId auraElemId = 2;
786 if (thisProc == 1) {
787 auraElemId = 1;
788 }
789 if (thisProc == 0) {
790 check_elem_state(mesh, auraElemId, Deleted);
791 confirm_entities_not_valid(mesh, stk::topology::NODE_RANK,
792 stk::mesh::EntityIdVector{9, 10, 11, 12});
793
794 stk::mesh::EntityId ownedElemId = 1;
795 stk::mesh::Entity ownedElem = mesh.get_entity(stk::topology::ELEM_RANK, ownedElemId);
796 EXPECT_EQ(Modified, mesh.state(ownedElem));
797 stk::mesh::EntityState expectedNodeStates[] = {
798 Unchanged, Unchanged, Unchanged, Unchanged,
799 Modified, Modified, Modified, Modified
800 };
801 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
802 }
803 else {
804 confirm_entities_not_valid(mesh, stk::topology::ELEM_RANK,
805 stk::mesh::EntityIdVector{auraElemId});
806 confirm_entities_not_valid(mesh, stk::topology::NODE_RANK,
807 stk::mesh::EntityIdVector{1, 2, 3, 4});
808
809 stk::mesh::EntityId ownedElemId = 2;
810 stk::mesh::EntityState expectedNodeStates[] = {
811 Created, Created, Created, Created,
812 Unchanged, Unchanged, Unchanged, Unchanged
813 };
814 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
815 }
816 }
817
818 void test_aura_partially_disconnect_elem_from_shared_not_owned_nodes(stk::mesh::BulkData& mesh)
819 {
820 partially_disconnect_elem2_on_proc1(mesh);
821
822 int thisProc = stk::parallel_machine_rank(mesh.parallel());
823 stk::mesh::EntityId auraElemId = 2;
824 if (thisProc == 1) {
825 auraElemId = 1;
826 }
827 if (thisProc == 0) {
828 check_elem_state(mesh, auraElemId, Created);
829
830 stk::mesh::EntityId ownedElemId = 1;
831 stk::mesh::Entity ownedElem = mesh.get_entity(stk::topology::ELEM_RANK, ownedElemId);
832 EXPECT_EQ(Modified, mesh.state(ownedElem));
833 stk::mesh::EntityState expectedNodeStates[] = {
834 Modified, Modified, Modified, Modified,
835 Modified, Modified, Modified, Modified
836 };
837 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
838 }
839 else {
840 check_elem_state(mesh, auraElemId, Created);
841
842 stk::mesh::EntityId ownedElemId = 2;
843 stk::mesh::EntityState expectedNodeStates[] = {
844 Created, Created, Modified, Modified,
845 Modified, Modified, Modified, Modified
846 };
847 check_node_states_for_elem(mesh, ownedElemId, expectedNodeStates);
848 }
849 }
850
851 class Aura2Hex2Proc : public stk::unit_test_util::MeshFixture
852 {
853 public:
854 Aura2Hex2Proc()
855 {
856 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) {
857 setup_mesh("generated:1x1x2", stk::mesh::BulkData::AUTO_AURA);
858 // 3----------7----------11
859 // /| /| /|
860 // / | / | / |
861 // / | / | / |
862 // 2----------6----------10 |
863 // | 4------|---8------|---12
864 // | / | / | /
865 // | / E1 | / E2 | /
866 // |/ |/ |/
867 // 1----------5----------9
868 // P0 P1
869 // Nodes 5,6,7,8 are shared
870 //
871 }
872 }
873 };
874
875 TEST_F(Aura2Hex2Proc, disconnectElemFromSharedOwnedNodes)
876 {
877 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
878 test_aura_disconnect_elem_from_shared_owned_nodes(get_bulk());
879 stk::unit_test::verify_no_graph_edges(get_bulk());
880 }
881
882 TEST_F(Aura2Hex2Proc, partiallyDisconnectElemFromSharedOwnedNodes)
883 {
884 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
885 test_aura_partially_disconnect_elem_from_shared_owned_nodes(get_bulk());
886 stk::unit_test::verify_no_graph_edges(get_bulk());
887 }
888
889 TEST_F(Aura2Hex2Proc, disconnectElemFromSharedNotOwnedNodes)
890 {
891 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
892 test_aura_disconnect_elem_from_shared_not_owned_nodes(get_bulk());
893 stk::unit_test::verify_no_graph_edges(get_bulk());
894 }
895
896 TEST_F(Aura2Hex2Proc, partiallyDisconnectElemFromSharedNotOwnedNodes)
897 {
898 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
899 test_aura_partially_disconnect_elem_from_shared_not_owned_nodes(get_bulk());
900 stk::unit_test::verify_no_graph_edges(get_bulk());
901 }
902
903 void expect_recv_aura(const stk::mesh::BulkData& bulk,
904 stk::mesh::EntityRank rank,
905 const stk::mesh::EntityIdVector& ids)
906 {
907 stk::mesh::Selector select = bulk.mesh_meta_data().aura_part();
908 stk::mesh::EntityVector entities;
909 stk::mesh::get_selected_entities(select, bulk.buckets(rank), entities);
910
911 EXPECT_EQ(ids.size(), entities.size());
912
913 for(stk::mesh::EntityId id : ids) {
914 stk::mesh::Entity entity = bulk.get_entity(rank, id);
915 EXPECT_TRUE(bulk.is_valid(entity));
916 EXPECT_FALSE(bulk.parallel_owner_rank(entity) == bulk.parallel_rank());
917 EXPECT_TRUE(std::binary_search(entities.begin(), entities.end(),
918 entity, stk::mesh::EntityLess(bulk)))
919 <<"P"<<bulk.parallel_rank()<<" expected to find "
920 <<bulk.entity_key(entity)<<" in recv-aura but didn't. "
921 <<"owned="<<bulk.bucket(entity).owned()
922 <<", shared="<<bulk.bucket(entity).shared()<<std::endl;
923 }
924 }
925
926 void test_aura_move_elem1_from_proc0_to_proc1(stk::mesh::BulkData& mesh)
927 {
928 const std::string generatedMeshSpec = "generated:1x1x4";
929 stk::io::fill_mesh(generatedMeshSpec, mesh);
930
931 //Initial mesh:
932 // 3----------7----------11----------15-----------19
933 // /| /| /| /| /|
934 // / | / | / | / | / |
935 // / | / | / | / | / |
936 // 2----------6----------10-----------14----------18 |
937 // | 4------|---8------|---12-------|--16-------|---20
938 // | / | / | / | / | /
939 // | / E1 | / E2 | / E3 | / E4 | /
940 // |/ |/ |/ |/ |/
941 // 1----------5----------9------------13----------17
942 // P0 P0 P1 P1
943 // Nodes 9,10,11,12 are shared
944 // Elem 3 is aura-ghost on P0 and elem 2 is aura-ghost on P1
945 // Nodes 13-16 are aura-ghosts on P0, nodes 5-8 are aura-ghosts on P1
946 //
947 int thisProc = stk::parallel_machine_rank(MPI_COMM_WORLD);
948 {
949 stk::mesh::EntityIdVector elemIds[] = {{3}, {2}};
950 stk::mesh::EntityIdVector nodeIds[] = {{13,14,15,16}, {5,6,7,8}};
951 expect_recv_aura(mesh, stk::topology::ELEM_RANK, elemIds[thisProc]);
952 expect_recv_aura(mesh, stk::topology::NODE_RANK, nodeIds[thisProc]);
953 }
954
955 //---------------------------------------
956 stk::mesh::EntityProcVec elemToMove;
957 if (thisProc == 0) {
958 stk::mesh::Entity elem1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
959 elemToMove.push_back(stk::mesh::EntityProc(elem1, 1));
960 }
961
962 mesh.change_entity_owner(elemToMove);
963
964 //After change-entity-owner moves elem 1 to P1:
965 // 3----------7----------11----------15-----------19
966 // /| /| /| /| /|
967 // / | / | / | / | / |
968 // / | / | / | / | / |
969 // 2----------6----------10-----------14----------18 |
970 // | 4------|---8------|---12-------|--16-------|---20
971 // | / | / | / | / | /
972 // | / E1 | / E2 | / E3 | / E4 | /
973 // |/ |/ |/ |/ |/
974 // 1----------5----------9------------13----------17
975 // P1 P0 P1 P1
976 // Nodes 1-12 are shared
977 // Elem 2 is aura-ghost on P1 and elems 1 and 3 are aura-ghosts on P0
978 // Nodes 13-16 are aura-ghosts on P0. No nodes are aura-ghosts on P1.
979 //
980 {
981 stk::mesh::EntityIdVector elemIds[] = {{1, 3}, {2}};
982 stk::mesh::EntityIdVector nodeIds[] = {{13,14,15,16}, {}};
983 expect_recv_aura(mesh, stk::topology::ELEM_RANK, elemIds[thisProc]);
984 expect_recv_aura(mesh, stk::topology::NODE_RANK, nodeIds[thisProc]);
985 }
986 }
987
988 TEST(BulkData, aura_moveElem1FromProc0ToProc1)
989 {
990 if (stk::parallel_machine_size(MPI_COMM_WORLD)==2) {
991 std::shared_ptr<stk::mesh::BulkData> bulkPtr = stk::mesh::MeshBuilder(MPI_COMM_WORLD)
992 .set_aura_option(stk::mesh::BulkData::AUTO_AURA)
993 .create();
994 test_aura_move_elem1_from_proc0_to_proc1(*bulkPtr);
995 }
996 }
997
998 TEST(BulkData, aura_moveElem1FromProc0ToProc1_NoUpwardConnectivity)
999 {
1000 if (stk::parallel_machine_size(MPI_COMM_WORLD)==2) {
1001 std::shared_ptr<stk::mesh::BulkData> bulkPtr = stk::mesh::MeshBuilder(MPI_COMM_WORLD)
1002 .set_aura_option(stk::mesh::BulkData::AUTO_AURA)
1003 .set_upward_connectivity(false)
1004 .create();
1005 test_aura_move_elem1_from_proc0_to_proc1(*bulkPtr);
1006 }
1007 }
1008
1009 class BulkDataAura : public stk::unit_test_util::MeshFixture
1010 {
1011 public:
1012 void verify_no_aura()
1013 {
1014 verify_aura(false, 0, 0);
1015 }
1016
1017 void verify_aura(bool expectAuraOptionIsOn,
1018 unsigned expectedNumAuraNodes,
1019 unsigned expectedNumAuraElems)
1020 {
1021 EXPECT_EQ(expectAuraOptionIsOn, get_bulk().is_automatic_aura_on());
1022
1023 stk::mesh::Selector selectAura = get_meta().aura_part();
1024 unsigned numAuraNodes = stk::mesh::count_selected_entities(selectAura, get_bulk().buckets(stk::topology::NODE_RANK));
1025 unsigned numAuraElements = stk::mesh::count_selected_entities(selectAura, get_bulk().buckets(stk::topology::ELEM_RANK));
1026 EXPECT_EQ(expectedNumAuraNodes, numAuraNodes);
1027 EXPECT_EQ(expectedNumAuraElems, numAuraElements);
1028 }
1029 };
1030
1031 TEST_F(BulkDataAura, turnAuraOnAfterConstruction)
1032 {
1033 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) {
1034 return;
1035 }
1036
1037 setup_mesh("generated:2x2x2", stk::mesh::BulkData::NO_AUTO_AURA);
1038
1039 verify_no_aura();
1040
1041 bool applyImmediately = true;
1042 get_bulk().set_automatic_aura_option(stk::mesh::BulkData::AUTO_AURA, applyImmediately);
1043
1044 bool expectAuraOptionIsOn = true;
1045 unsigned expectedNumAuraNodes = 9;
1046 unsigned expectedNumAuraElements = 4;
1047 verify_aura(expectAuraOptionIsOn, expectedNumAuraNodes, expectedNumAuraElements);
1048 }
1049
1050 TEST_F(BulkDataAura, turnAuraOnAfterConstruction_applyAtNextModEnd)
1051 {
1052 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) {
1053 return;
1054 }
1055
1056 setup_mesh("generated:2x2x2", stk::mesh::BulkData::NO_AUTO_AURA);
1057
1058 verify_no_aura();
1059
1060 bool applyImmediately = false;
1061 get_bulk().set_automatic_aura_option(stk::mesh::BulkData::AUTO_AURA, applyImmediately);
1062
1063 bool expectAuraOptionIsOn = true;
1064 unsigned expectedNumAuraNodes = 0;
1065 unsigned expectedNumAuraElements = 0;
1066 verify_aura(expectAuraOptionIsOn, expectedNumAuraNodes, expectedNumAuraElements);
1067
1068 get_bulk().modification_begin();
1069 get_bulk().modification_end();
1070
1071 expectedNumAuraNodes = 9;
1072 expectedNumAuraElements = 4;
1073 verify_aura(expectAuraOptionIsOn, expectedNumAuraNodes, expectedNumAuraElements);
1074 }
1075
1076 TEST_F(BulkDataAura, turnAuraOffAfterConstruction)
1077 {
1078 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) {
1079 return;
1080 }
1081
1082 setup_mesh("generated:2x2x2", stk::mesh::BulkData::AUTO_AURA);
1083
1084 bool expectAuraOptionIsOn = true;
1085 unsigned expectedNumAuraNodes = 9;
1086 unsigned expectedNumAuraElements = 4;
1087 verify_aura(expectAuraOptionIsOn, expectedNumAuraNodes, expectedNumAuraElements);
1088
1089 bool applyImmediately = true;
1090 get_bulk().set_automatic_aura_option(stk::mesh::BulkData::NO_AUTO_AURA, applyImmediately);
1091
1092 verify_no_aura();
1093 }
1094
1095 TEST_F(BulkDataAura, turnAuraOffAfterConstruction_applyAtNextModEnd)
1096 {
1097 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) {
1098 return;
1099 }
1100
1101 setup_mesh("generated:2x2x2", stk::mesh::BulkData::AUTO_AURA);
1102
1103 bool expectAuraOptionIsOn = true;
1104 unsigned expectedNumAuraNodes = 9;
1105 unsigned expectedNumAuraElements = 4;
1106 verify_aura(expectAuraOptionIsOn, expectedNumAuraNodes, expectedNumAuraElements);
1107
1108 bool applyImmediately = false;
1109 get_bulk().set_automatic_aura_option(stk::mesh::BulkData::NO_AUTO_AURA, applyImmediately);
1110
1111 expectAuraOptionIsOn = false;
1112 expectedNumAuraNodes = 9;
1113 expectedNumAuraElements = 4;
1114 verify_aura(expectAuraOptionIsOn, expectedNumAuraNodes, expectedNumAuraElements);
1115
1116 get_bulk().modification_begin();
1117 get_bulk().modification_end();
1118
1119 verify_no_aura();
1120 }
1121
1122 class AuraSharedSideMods : public TestTextMeshAura
1123 {
1124 public:
1125 void verify_num_faces(size_t goldCount)
1126 {
1127 EXPECT_EQ(goldCount, stk::mesh::count_entities(get_bulk(), stk::topology::FACE_RANK, get_meta().universal_part()));
1128 }
1129
1130 void delete_elem2()
1131 {
1132 get_bulk().modification_begin();
1133 stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2);
1134 if (get_bulk().is_valid(elem2) && get_bulk().parallel_owner_rank(elem2) == get_bulk().parallel_rank()) {
1135 get_bulk().destroy_entity(elem2);
1136 }
1137 get_bulk().modification_end();
1138 }
1139
1140 void verify_face_owned_on_P0_aura_on_P1(stk::mesh::EntityId faceId)
1141 {
1142 stk::mesh::Entity face = get_bulk().get_entity(stk::topology::FACE_RANK, faceId);
1143 EXPECT_TRUE(get_bulk().is_valid(face));
1144 if (get_bulk().parallel_rank() == 0) {
1145 EXPECT_TRUE(get_bulk().parallel_owner_rank(face) == get_bulk().parallel_rank());
1146 }
1147 else {
1148 EXPECT_TRUE(get_bulk().bucket(face).in_aura());
1149 }
1150 }
1151
1152 void verify_nodes_shared(const std::vector<stk::mesh::EntityId>& nodeIds)
1153 {
1154 for(stk::mesh::EntityId nodeId : nodeIds) {
1155 stk::mesh::Entity node = get_bulk().get_entity(stk::topology::NODE_RANK, nodeId);
1156 EXPECT_TRUE(get_bulk().is_valid(node));
1157 EXPECT_TRUE(get_bulk().bucket(node).shared());
1158 }
1159 }
1160
1161 void verify_nodes_owned_on_P0_aura_on_P1(const std::vector<stk::mesh::EntityId>& nodeIds)
1162 {
1163 const int thisProc = get_bulk().parallel_rank();
1164 for(stk::mesh::EntityId nodeId : nodeIds) {
1165 stk::mesh::Entity node = get_bulk().get_entity(stk::topology::NODE_RANK, nodeId);
1166 EXPECT_TRUE(get_bulk().is_valid(node));
1167 if (thisProc == 0) {
1168 EXPECT_TRUE(get_bulk().bucket(node).owned());
1169 EXPECT_FALSE(get_bulk().bucket(node).in_aura());
1170 }
1171 else {
1172 ASSERT_EQ(1, thisProc);
1173 EXPECT_FALSE(get_bulk().bucket(node).owned());
1174 EXPECT_TRUE(get_bulk().bucket(node).in_aura());
1175 }
1176 }
1177 }
1178
1179 void recreate_elem2_on_P1()
1180 {
1181 get_bulk().modification_begin();
1182 stk::mesh::Entity elem2;
1183 if (get_bulk().parallel_rank() == 1) {
1184 stk::mesh::Part& hexPart = get_meta().get_topology_root_part(stk::topology::HEX_8);
1185 stk::mesh::PartVector parts = {&hexPart};
1186 elem2 = stk::mesh::declare_element(get_bulk(), parts, 2, {5, 6, 7, 8, 9, 10, 11, 12});
1187 }
1188 get_bulk().modification_end();
1189 }
1190
1191 void declare_side_on_elem2()
1192 {
1193 get_bulk().modification_begin();
1194 if (get_bulk().parallel_rank() == 1) {
1195 stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2);
1196 EXPECT_TRUE(get_bulk().is_valid(elem2));
1197 const unsigned sideOrdinal = 4;
1198 get_bulk().declare_element_side<stk::mesh::PartVector>(elem2, sideOrdinal);
1199 }
1200 get_bulk().modification_end();
1201 }
1202
1203 void declare_relation_on_elem2()
1204 {
1205 get_bulk().modification_begin();
1206 if (get_bulk().parallel_rank() == 1) {
1207 stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2);
1208 EXPECT_TRUE(get_bulk().is_valid(elem2));
1209 stk::mesh::Entity face16 = get_bulk().get_entity(stk::topology::FACE_RANK, 16);
1210 const unsigned sideOrdinal = 4;
1211 get_bulk().declare_relation(elem2, face16, sideOrdinal);
1212 }
1213 get_bulk().modification_end();
1214 }
1215 };
1216
1217 TEST_F(AuraSharedSideMods, sharedFace)
1218 {
1219 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1220
1221 std::string meshDesc = "1, 2, HEX_8,5,6,7,8,9,10,11,12\n"
1222 "1, 3, HEX_8,5,13,14,15,16,17,18,19\n"
1223 "0, 1, HEX_8,1,2,3,4,5,6,7,8|sideset:data=1,6";
1224 setup_text_mesh(meshDesc);
1225 verify_num_elements(3);
1226 verify_num_faces(1);
1227 }
1228
1229 TEST_F(AuraSharedSideMods, sharedFaceDeleteElemRecreateElem_declareSide)
1230 {
1231 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1232
1233 std::string meshDesc = "1, 2, HEX_8,5,6,7,8,9,10,11,12\n"
1234 "1, 3, HEX_8,5,13,14,15,16,17,18,19\n"
1235 "0, 1, HEX_8,1,2,3,4,5,6,7,8|sideset:data=1,6";
1236 setup_text_mesh(meshDesc);
1237 verify_num_elements(3);
1238 verify_num_faces(1);
1239
1240 delete_elem2();
1241 verify_num_elements(2);
1242 stk::mesh::EntityId faceId = 16;
1243 verify_face_owned_on_P0_aura_on_P1(faceId);
1244 verify_nodes_shared({5});
1245 verify_nodes_owned_on_P0_aura_on_P1({6, 7, 8});
1246
1247 recreate_elem2_on_P1();
1248 declare_side_on_elem2();
1249 verify_num_faces(1);
1250 verify_nodes_shared({5, 6, 7, 8});
1251 }
1252
1253 TEST_F(AuraSharedSideMods, sharedFaceDeleteElemRecreateElem_declareRelation)
1254 {
1255 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1256
1257 std::string meshDesc = "1, 2, HEX_8,5,6,7,8,9,10,11,12\n"
1258 "1, 3, HEX_8,5,13,14,15,16,17,18,19\n"
1259 "0, 1, HEX_8,1,2,3,4,5,6,7,8|sideset:data=1,6";
1260 setup_text_mesh(meshDesc);
1261 verify_num_elements(3);
1262 verify_num_faces(1);
1263
1264 delete_elem2();
1265 verify_num_elements(2);
1266 stk::mesh::EntityId faceId = 16;
1267 verify_face_owned_on_P0_aura_on_P1(faceId);
1268 verify_nodes_shared({5});
1269 verify_nodes_owned_on_P0_aura_on_P1({6, 7, 8});
1270
1271 recreate_elem2_on_P1();
1272 declare_relation_on_elem2();
1273 verify_num_faces(1);
1274 verify_nodes_shared({5, 6, 7, 8});
1275 }
1276
1277 class AuraTetSide : public TestTextMeshAura
1278 {
1279 public:
1280 void delete_side_on_p0_check_marking()
1281 {
1282 get_bulk().modification_begin();
1283
1284 stk::mesh::Entity elem2577 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2577);
1285 stk::mesh::Entity elem2579 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2579);
1286 stk::mesh::Entity face25772 = get_bulk().get_entity(stk::topology::FACE_RANK, 25772);
1287 EXPECT_TRUE(get_bulk().is_valid(elem2577));
1288 EXPECT_TRUE(get_bulk().is_valid(elem2579));
1289 EXPECT_TRUE(get_bulk().is_valid(face25772));
1290
1291 if (get_bulk().parallel_rank() == 0) {
1292 stk::mesh::ConnectivityOrdinal ord = 1;
1293 EXPECT_TRUE(get_bulk().destroy_relation(elem2577, face25772, ord));
1294 EXPECT_TRUE(get_bulk().destroy_relation(elem2579, face25772, ord));
1295 EXPECT_TRUE(get_bulk().destroy_entity(face25772));
1296
1297 stk::mesh::Entity elem2587 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2587);
1298 stk::mesh::Entity node484 = get_bulk().get_entity(stk::topology::NODE_RANK, 484);
1299 stk::mesh::Entity node494 = get_bulk().get_entity(stk::topology::NODE_RANK, 494);
1300 EXPECT_TRUE(get_bulk().state(elem2587) == stk::mesh::Modified);
1301 EXPECT_TRUE(get_bulk().state(node484) == stk::mesh::Unchanged);
1302 EXPECT_TRUE(get_bulk().state(node494) == stk::mesh::Unchanged);
1303 }
1304
1305 get_bulk().modification_end();
1306 }
1307
1308 void delete_elems_on_p0_check_aura_nodes_deleted()
1309 {
1310 stk::mesh::Entity elem2577 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2577);
1311 stk::mesh::Entity elem2579 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2579);
1312 EXPECT_TRUE(get_bulk().is_valid(elem2577));
1313 EXPECT_TRUE(get_bulk().is_valid(elem2579));
1314
1315 get_bulk().modification_begin();
1316
1317 if (get_bulk().parallel_rank() == 0) {
1318 EXPECT_TRUE(get_bulk().destroy_entity(elem2577));
1319 EXPECT_TRUE(get_bulk().destroy_entity(elem2579));
1320 }
1321
1322 get_bulk().modification_end();
1323
1324 if (get_bulk().parallel_rank() == 1) {
1325 elem2577 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2577);
1326 elem2579 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2579);
1327 EXPECT_FALSE(get_bulk().is_valid(elem2577));
1328 EXPECT_FALSE(get_bulk().is_valid(elem2579));
1329
1330 stk::mesh::Entity node452 = get_bulk().get_entity(stk::topology::NODE_RANK, 452);
1331 stk::mesh::Entity node464 = get_bulk().get_entity(stk::topology::NODE_RANK, 464);
1332 stk::mesh::Entity node474 = get_bulk().get_entity(stk::topology::NODE_RANK, 474);
1333 EXPECT_FALSE(get_bulk().is_valid(node452));
1334 EXPECT_FALSE(get_bulk().is_valid(node464));
1335 EXPECT_FALSE(get_bulk().is_valid(node474));
1336 }
1337 }
1338
1339 void delete_elem_on_p1_check_aura_nodes_deleted()
1340 {
1341 stk::mesh::Entity elem2601 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2601);
1342 EXPECT_TRUE(get_bulk().is_valid(elem2601));
1343
1344 get_bulk().modification_begin();
1345
1346 if (get_bulk().parallel_rank() == 1) {
1347 EXPECT_TRUE(get_bulk().destroy_entity(elem2601));
1348 }
1349
1350 get_bulk().modification_end();
1351
1352 if (get_bulk().parallel_rank() == 1) {
1353 elem2601 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2601);
1354 EXPECT_FALSE(get_bulk().is_valid(elem2601));
1355
1356 stk::mesh::Entity node452 = get_bulk().get_entity(stk::topology::NODE_RANK, 452);
1357 stk::mesh::Entity node464 = get_bulk().get_entity(stk::topology::NODE_RANK, 464);
1358 stk::mesh::Entity node474 = get_bulk().get_entity(stk::topology::NODE_RANK, 474);
1359 EXPECT_FALSE(get_bulk().is_valid(node452));
1360 EXPECT_FALSE(get_bulk().is_valid(node464));
1361 EXPECT_FALSE(get_bulk().is_valid(node474));
1362 }
1363 }
1364
1365 void print_face_nodes()
1366 {
1367 stk::mesh::Entity face25872 = get_bulk().get_entity(stk::topology::FACE_RANK, 25872);
1368 EXPECT_TRUE(get_bulk().is_valid(face25872));
1369 const unsigned numNodes = get_bulk().num_nodes(face25872);
1370 EXPECT_EQ(3u, numNodes);
1371 const stk::mesh::Entity* nodes = get_bulk().begin_nodes(face25872);
1372 std::cerr<<" face 25872 nodes: ";
1373 for(unsigned i=0; i<numNodes; ++i) {
1374 std::cerr<<get_bulk().identifier(nodes[i])<<" ";
1375 }
1376 std::cerr<<std::endl;
1377 }
1378
1379 void delete_aura_elem_on_p1_check_aura_nodes_deleted()
1380 {
1381 stk::mesh::Entity elem2587 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2587);
1382 stk::mesh::Entity elem2601 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2601);
1383 EXPECT_TRUE(get_bulk().is_valid(elem2587));
1384 EXPECT_TRUE(get_bulk().is_valid(elem2601));
1385
1386 get_bulk().modification_begin();
1387
1388 if (get_bulk().parallel_rank() == 0) {
1389 stk::mesh::Entity elem2599 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2599);
1390 EXPECT_TRUE(get_bulk().destroy_entity(elem2599));
1391 }
1392 else {
1393 EXPECT_TRUE(get_bulk().destroy_entity(elem2601));
1394 }
1395
1396 get_bulk().modification_end();
1397
1398 if (get_bulk().parallel_rank() == 1) {
1399 elem2587 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2587);
1400 EXPECT_FALSE(get_bulk().is_valid(elem2587));
1401
1402 stk::mesh::Entity node484 = get_bulk().get_entity(stk::topology::NODE_RANK, 484);
1403 stk::mesh::Entity node494 = get_bulk().get_entity(stk::topology::NODE_RANK, 494);
1404 EXPECT_FALSE(get_bulk().is_valid(node484));
1405 EXPECT_FALSE(get_bulk().is_valid(node494));
1406 }
1407 }
1408
1409 };
1410
1411 TEST_F(AuraTetSide, removeAuraSideOnOwner_checkMarking)
1412 {
1413 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1414
1415 std::string meshDesc = "0, 2579, TET_4, 91,452,474,464\n"
1416 "0, 2577, TET_4, 50,452,464,474\n"
1417 "0, 2587, TET_4, 50,452,484,494\n"
1418 "1, 2601, TET_4, 91, 50, 60, 70|sideset:data=2577,2";
1419 setup_text_mesh(meshDesc);
1420
1421 delete_side_on_p0_check_marking();
1422 }
1423
1424 TEST_F(AuraTetSide, removeAuraElemsOnNonOwner_checkMarking)
1425 {
1426 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1427
1428 std::string meshDesc = "0, 2587, TET_4, 50,452,484,494\n"
1429 "0, 2599, TET_4, 50,497,498,499\n"
1430 "1, 2601, TET_4, 91, 50, 60, 70|sideset:data=2587,2";
1431 setup_text_mesh(meshDesc);
1432
1433 delete_aura_elem_on_p1_check_aura_nodes_deleted();
1434 }
1435
1436 TEST_F(AuraTetSide, printFaceNodes_serial)
1437 {
1438 if (get_parallel_size() != 1) { GTEST_SKIP(); }
1439
1440 std::string meshDesc = "0, 2587, TET_4, 50,452,484,494\n"
1441 "0, 2599, TET_4, 50,497,498,499\n"
1442 "0, 2601, TET_4, 91, 50, 60, 70|sideset:data=2587,2";
1443 setup_text_mesh(meshDesc);
1444
1445 print_face_nodes();
1446 }
1447
1448 TEST_F(AuraTetSide, removeElemsOnP0_auraNodesDeletedOnP1)
1449 {
1450 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1451
1452 std::string meshDesc = "0, 2579, TET_4, 91,452,474,464\n"
1453 "0, 2577, TET_4, 50,452,464,474\n"
1454 "1, 2601, TET_4, 91, 50, 60, 70";
1455 setup_text_mesh(meshDesc);
1456
1457 delete_elems_on_p0_check_aura_nodes_deleted();
1458 }
1459
1460 TEST_F(AuraTetSide, removeElemOnP1_auraNodesDeletedOnP1)
1461 {
1462 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1463
1464 std::string meshDesc = "0, 2579, TET_4, 91,452,474,464\n"
1465 "0, 2577, TET_4, 50,452,464,474\n"
1466 "1, 2601, TET_4, 91, 50, 60, 70";
1467 setup_text_mesh(meshDesc);
1468
1469 delete_elem_on_p1_check_aura_nodes_deleted();
1470 }
1471
1472 TEST_F(AuraTetSide, removeAuraElemOnP2_auraNodesDeletedOnP1)
1473 {
1474 if (get_parallel_size() != 2) { GTEST_SKIP(); }
1475
1476 std::string meshDesc = "0, 2579, TET_4, 91,452,474,464\n"
1477 "0, 2577, TET_4, 50,452,464,474\n"
1478 "1, 2601, TET_4, 91, 50, 60, 70";
1479 setup_text_mesh(meshDesc);
1480
1481 delete_elem_on_p1_check_aura_nodes_deleted();
1482 }
1483
1484 class AuraTetGhosting : public TestTextMeshAura
1485 {
1486 public:
1487
1488 void make_node110_owned_by_p1()
1489 {
1490 stk::mesh::EntityProcVec nodeToMove;
1491 {
1492 stk::mesh::Entity node110 = get_bulk().get_entity(stk::topology::NODE_RANK,110);
1493 if (get_bulk().parallel_rank() == 0) {
1494 EXPECT_TRUE(get_bulk().bucket(node110).owned());
1495 int destProc = 1;
1496 nodeToMove.push_back(stk::mesh::EntityProc(node110, destProc));
1497 }
1498 }
1499
1500 get_bulk().change_entity_owner(nodeToMove);
1501
1502 {
1503 stk::mesh::Entity node110 = get_bulk().get_entity(stk::topology::NODE_RANK,110);
1504 if (get_bulk().parallel_rank() == 1) {
1505 EXPECT_TRUE(get_bulk().bucket(node110).owned());
1506 }
1507 }
1508 }
1509
1510 void destroy_elems(const std::vector<std::pair<int,stk::mesh::EntityId>>& procElemIds)
1511 {
1512 stk::mesh::EntityVector elemsToDestroy;
1513 for(const std::pair<int,stk::mesh::EntityId>& procElemId : procElemIds) {
1514 if (procElemId.first == get_bulk().parallel_rank()) {
1515 stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, procElemId.second);
1516 ASSERT_TRUE(get_bulk().is_valid(elem));
1517 elemsToDestroy.push_back(elem);
1518 }
1519 }
1520
1521 get_bulk().modification_begin();
1522 stk::mesh::destroy_elements_no_mod_cycle(get_bulk(), elemsToDestroy, get_meta().universal_part());
1523 get_bulk().modification_end();
1524 }
1525
1526 void custom_ghost(stk::mesh::EntityRank rank, stk::mesh::EntityId entityId, const std::vector<int>& destProcs)
1527 {
1528 get_bulk().modification_begin();
1529
1530 stk::mesh::Ghosting& customGhosting = get_bulk().create_ghosting("myCustomGhosting");
1531
1532 stk::mesh::Entity entity = get_bulk().get_entity(rank, entityId);
1533 stk::mesh::EntityProcVec entityToGhost;
1534 if (get_bulk().is_valid(entity) && get_bulk().parallel_owner_rank(entity)==get_bulk().parallel_rank()) {
1535 for(int destProc : destProcs) {
1536 entityToGhost.push_back(stk::mesh::EntityProc(entity, destProc));
1537 }
1538 }
1539
1540 get_bulk().change_ghosting(customGhosting, entityToGhost);
1541
1542 get_bulk().modification_end();
1543 }
1544 };
1545
1546 TEST_F(AuraTetGhosting, destroy_elems)
1547 {
1548 if (get_parallel_size() != 8) { GTEST_SKIP(); }
1549
1550 std::string meshDesc = "0, 1049, TET_4, 101,140,138,137\n"
1551 "0, 1050, TET_4, 140,110,139,136\n"
1552 "0, 1051, TET_4, 138,139,108,135\n"
1553 "0, 1052, TET_4, 137,136,135,107\n"
1554 "0, 1053, TET_4, 138,137,140,136\n"
1555 "0, 1054, TET_4, 138,135,137,136\n"
1556 "0, 1055, TET_4, 138,139,135,136\n"
1557 "0, 1056, TET_4, 138,140,139,136\n"
1558 "1, 2000, TET_4, 200,110,162,201\n"
1559 "2, 1065, TET_4, 147,108,103,109\n"
1560 "2, 1066, TET_4, 105,147,103,109\n"
1561 "3, 1108, TET_4, 134,106,133,104\n"
1562 "3, 1109, TET_4, 132,133,105,104\n"
1563 "3, 1110, TET_4, 132,134,133,104\n"
1564 "3, 1111, TET_4, 107,134,132,104\n"
1565 "4, 1081, TET_4, 134,136,107,135\n"
1566 "4, 1145, TET_4, 135,107,136,134\n"
1567 "4, 1146, TET_4, 139,136,110,162\n"
1568 "4, 1148, TET_4, 136,135,134,159\n"
1569 "4, 1149, TET_4, 136,139,135,159\n"
1570 "4, 1150, TET_4, 136,162,139,159\n"
1571 "4, 1151, TET_4, 136,134,162,159\n"
1572 "5, 1089, TET_4, 108,147,135,159\n"
1573 "5, 1090, TET_4, 147,105,132,133\n"
1574 "5, 1091, TET_4, 135,132,107,134\n"
1575 "5, 1092, TET_4, 159,133,134,106\n"
1576 "5, 1093, TET_4, 132,147,133,159\n"
1577 "5, 1094, TET_4, 132,135,147,159\n"
1578 "5, 1095, TET_4, 132,134,135,159\n"
1579 "5, 1096, TET_4, 132,133,134,159\n"
1580 "6, 1160, TET_4, 159,133,160,147\n"
1581 "6, 1161, TET_4, 159,160,133,106\n"
1582 "6, 1162, TET_4, 109,159,160,147\n"
1583 "6, 1163, TET_4, 109,159,147,108\n"
1584 "6, 1164, TET_4, 105,160,133,147\n"
1585 "6, 1165, TET_4, 105,160,147,109\n"
1586 "7, 2001, TET_4, 202,162,110,203|sideset:data=1151,4,1146,2,1052,1,1050,1,1081,4,1053,2\n";
1587
1588 setup_text_mesh(meshDesc);
1589
1590 destroy_elems({ {0, 1049},
1591 {0, 1050},
1592 {0, 1051},
1593 {0, 1052},
1594 {0, 1053},
1595 {0, 1054},
1596 {0, 1055},
1597 {0, 1056},
1598 {2, 1065},
1599 {2, 1066},
1600 {3, 1108},
1601 {3, 1109},
1602 {3, 1110},
1603 {3, 1111},
1604 {5, 1089},
1605 {5, 1090},
1606 {5, 1091},
1607 {5, 1092},
1608 {5, 1093},
1609 {5, 1094},
1610 {5, 1095},
1611 {5, 1096},
1612 {6, 1160},
1613 {6, 1161},
1614 {6, 1162},
1615 {6, 1163},
1616 {6, 1164},
1617 {6, 1165} });
1618 }
1619
1620 TEST_F(AuraTetGhosting, destroy_elems_custom_ghosting)
1621 {
1622 if (get_parallel_size() != 8) { GTEST_SKIP(); }
1623
1624 std::string meshDesc = "0, 1049, TET_4, 101,140,138,137\n"
1625 "0, 1050, TET_4, 140,110,139,136\n"
1626 "0, 1051, TET_4, 138,139,108,135\n"
1627 "0, 1052, TET_4, 137,136,135,107\n"
1628 "0, 1053, TET_4, 138,137,140,136\n"
1629 "0, 1054, TET_4, 138,135,137,136\n"
1630 "0, 1055, TET_4, 138,139,135,136\n"
1631 "0, 1056, TET_4, 138,140,139,136\n"
1632 "1, 2000, TET_4, 200,110,162,201\n"
1633 "2, 1065, TET_4, 147,108,103,109\n"
1634 "2, 1066, TET_4, 105,147,103,109\n"
1635 "3, 1108, TET_4, 134,106,133,104\n"
1636 "3, 1109, TET_4, 132,133,105,104\n"
1637 "3, 1110, TET_4, 132,134,133,104\n"
1638 "3, 1111, TET_4, 107,134,132,104\n"
1639 "4, 1081, TET_4, 134,136,107,135\n"
1640 "4, 1145, TET_4, 135,107,136,134\n"
1641 "4, 1146, TET_4, 139,136,110,162\n"
1642 "4, 1148, TET_4, 136,135,134,159\n"
1643 "4, 1149, TET_4, 136,139,135,159\n"
1644 "4, 1150, TET_4, 136,162,139,159\n"
1645 "4, 1151, TET_4, 136,134,162,159\n"
1646 "5, 1089, TET_4, 108,147,135,159\n"
1647 "5, 1090, TET_4, 147,105,132,133\n"
1648 "5, 1091, TET_4, 135,132,107,134\n"
1649 "5, 1092, TET_4, 159,133,134,106\n"
1650 "5, 1093, TET_4, 132,147,133,159\n"
1651 "5, 1094, TET_4, 132,135,147,159\n"
1652 "5, 1095, TET_4, 132,134,135,159\n"
1653 "5, 1096, TET_4, 132,133,134,159\n"
1654 "6, 1160, TET_4, 159,133,160,147\n"
1655 "6, 1161, TET_4, 159,160,133,106\n"
1656 "6, 1162, TET_4, 109,159,160,147\n"
1657 "6, 1163, TET_4, 109,159,147,108\n"
1658 "6, 1164, TET_4, 105,160,133,147\n"
1659 "6, 1165, TET_4, 105,160,147,109\n"
1660 "7, 2001, TET_4, 202,162,110,203|sideset:data=1151,4,1146,2,1052,1,1050,1,1081,4,1053,2\n";
1661
1662 setup_text_mesh(meshDesc);
1663
1664 //This mesh setup provides coverage for some dark corners of BulkData::modification_end.
1665 //Specifically, node 110 is both aura-ghosted and custom-ghosted from proc 0 to procs 4 and 7,
1666 //and it is both shared with, and custom-ghosted to proc 1.
1667 //Similarly, node 135 is shared by procs 0 and 4 and 5, as well as being custom-ghosted
1668 //from proc 0 to procs 4 and 5.
1669 //This test is a success if no exception is thrown from BulkData::modification_end.
1670
1671 custom_ghost(stk::topology::NODE_RANK, 110, {1, 4, 7});
1672 custom_ghost(stk::topology::NODE_RANK, 135, {4, 5});
1673
1674 destroy_elems({ {0, 1050},
1675 {4, 1081},
1676 {4, 1145},
1677 {4, 1146},
1678 {4, 1148},
1679 {4, 1149},
1680 {1, 2000} });
1681 }
1682
1683 TEST_F(AuraTetGhosting, destroy_elems_sharing_and_aura_ghosting)
1684 {
1685 if (get_parallel_size() != 4) { GTEST_SKIP(); }
1686
1687 std::string meshDesc = "0, 1049, TET_4, 101,140,138,137\n"
1688 "0, 1050, TET_4, 140,110,139,136\n"
1689 "0, 1051, TET_4, 138,139,108,135\n"
1690 "0, 1052, TET_4, 137,136,135,107\n"
1691 "1, 2000, TET_4, 200,110,162,201\n"
1692 "1, 2001, TET_4, 200,110,165,202\n"
1693 "1, 2002, TET_4, 200,203,204,202\n"
1694 "2, 1065, TET_4, 200,108,103,104\n"
1695 "2, 1066, TET_4, 200,101,105,106\n"
1696 "3, 1085, TET_4, 136,189,183,156\n"
1697 "3, 1086, TET_4, 136,157,153,186|sideset:data=1050,1,1085,1,1086,2\n";
1698
1699 //This mesh setup provides coverage for some dark corners of BulkData::modification_end.
1700 //Specifically, we make node 110 shared by procs 0 and 1, and aura-ghosting to proc 2 and 3.
1701 //Additionally, we move the ownership of node 110 to proc 1, while the face that it is
1702 //attached to (face 10501, i.e., the face on side 1 of element 1050) remains owned by proc 0.
1703 //This test is a success if no exception is thrown from BulkData::modification_end.
1704
1705 setup_text_mesh(meshDesc);
1706
1707 make_node110_owned_by_p1();
1708
1709 destroy_elems({ {2, 1065} });
1710 }
1711
1712 TEST_F(AuraTetGhosting, destroy_elems_sharing_and_aura_and_custom_ghosting)
1713 {
1714 if (get_parallel_size() != 4) { GTEST_SKIP(); }
1715
1716 std::string meshDesc = "0, 1049, TET_4, 101,140,138,137\n"
1717 "0, 1050, TET_4, 140,110,139,136\n"
1718 "0, 1051, TET_4, 138,139,108,135\n"
1719 "0, 1052, TET_4, 137,136,135,107\n"
1720 "1, 2000, TET_4, 200,110,162,201\n"
1721 "1, 2001, TET_4, 200,110,165,202\n"
1722 "1, 2002, TET_4, 200,203,204,202\n"
1723 "2, 1065, TET_4, 200,108,103,104\n"
1724 "2, 1066, TET_4, 200,101,105,106\n"
1725 "3, 1085, TET_4, 136,189,183,156\n"
1726 "3, 1086, TET_4, 136,157,153,186|sideset:data=1050,1,1085,1,1086,2\n";
1727
1728 //This mesh setup provides coverage for some dark corners of BulkData::modification_end.
1729 //Specifically, we make node 110 shared by procs 0 and 1, and aura-ghosting to proc 2 and 3.
1730 //Additionally, we move the ownership of node 110 to proc 1, while the face that it is
1731 //attached to (face 10501, i.e., the face on side 1 of element 1050) remains owned by proc 0.
1732 //Finally, we also custom-ghost elems 1050 and 1051 to procs 2 and 3, as well as node 110 to procs 2 and 3.
1733 //This test is a success if no exception is thrown from BulkData::modification_end.
1734
1735 setup_text_mesh(meshDesc);
1736
1737 make_node110_owned_by_p1();
1738
1739 custom_ghost(stk::topology::ELEM_RANK, 1050, {2, 3});
1740 custom_ghost(stk::topology::ELEM_RANK, 1051, {2, 3});
1741 custom_ghost(stk::topology::NODE_RANK, 110, {2, 3});
1742
1743 destroy_elems({ {2, 1065} });
1744 }
1745
1746 } // empty namespace
1747