| 1 |
#include <stk_mesh/base/GetEntities.hpp> |
| 2 |
#include <stk_unit_test_utils/unittestMeshUtils.hpp> |
| 3 |
#include <stk_mesh/base/Comm.hpp> |
| 4 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 5 |
#include <stk_unit_test_utils/BulkDataTester.hpp> |
| 6 |
#include "../FaceCreatorFixture.hpp" |
| 7 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> |
| 8 |
#include <stk_mesh/base/MeshDiagnostics.hpp> |
| 9 |
#include <stk_util/parallel/ParallelReduceBool.hpp> |
| 10 |
namespace |
| 11 |
{ |
| 12 |
|
| 13 |
class UnitTestRuleThreeViolation : public stk::unit_test_util::MeshFixture |
| 14 |
{ |
| 15 |
protected: |
| 16 |
stk::mesh::EntityVector get_shared_nodes_of_element(stk::mesh::Entity elem) |
| 17 |
{ |
| 18 |
stk::mesh::EntityVector sharedNodes; |
| 19 |
|
| 20 |
const stk::mesh::Entity *nodes = get_bulk().begin_nodes(elem); |
| 21 |
unsigned numNodes = get_bulk().num_nodes(elem); |
| 22 |
for(unsigned i = 0; i<numNodes; ++i) |
| 23 |
{ |
| 24 |
if(get_bulk().bucket(nodes[i]).shared()) |
| 25 |
sharedNodes.push_back(nodes[i]); |
| 26 |
} |
| 27 |
|
| 28 |
return sharedNodes; |
| 29 |
} |
| 30 |
|
| 31 |
stk::mesh::EntityVector get_shared_nodes_of_element5_on_p1() |
| 32 |
{ |
| 33 |
stk::mesh::EntityVector sharedNodes; |
| 34 |
|
| 35 |
if(get_proc_rank() == 1) |
| 36 |
{ |
| 37 |
stk::mesh::Entity elem5 = get_bulk().get_entity(stk::topology::ELEM_RANK, 5u); |
| 38 |
sharedNodes = get_shared_nodes_of_element(elem5); |
| 39 |
} |
| 40 |
return sharedNodes; |
| 41 |
} |
| 42 |
|
| 43 |
void delete_element1_on_p0() |
| 44 |
{ |
| 45 |
if(get_proc_rank() == 0) |
| 46 |
{ |
| 47 |
stk::mesh::Entity elem1 = get_bulk().get_entity(stk::topology::ELEM_RANK, 1u); |
| 48 |
|
| 49 |
bool isDestroyed = get_bulk().destroy_entity(elem1); |
| 50 |
EXPECT_TRUE(isDestroyed); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
stk::mesh::EntityVector delete_element2_on_p0_and_get_shared_nodes() |
| 55 |
{ |
| 56 |
stk::mesh::EntityVector sharedNodes; |
| 57 |
if(get_proc_rank() == 0) |
| 58 |
{ |
| 59 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2u); |
| 60 |
sharedNodes = get_shared_nodes_of_element(elem2); |
| 61 |
|
| 62 |
bool isDestroyed = get_bulk().destroy_entity(elem2); |
| 63 |
EXPECT_TRUE(isDestroyed); |
| 64 |
} |
| 65 |
|
| 66 |
return sharedNodes; |
| 67 |
} |
| 68 |
|
| 69 |
int get_proc_rank() |
| 70 |
{ |
| 71 |
return get_bulk().parallel_rank(); |
| 72 |
} |
| 73 |
|
| 74 |
void create_orphaned_side_on_p0() |
| 75 |
{ |
| 76 |
if (get_proc_rank() == 0) |
| 77 |
{ |
| 78 |
stk::topology quad4Topology = stk::topology::QUAD_4; |
| 79 |
stk::mesh::Part &quad4Part = get_meta().get_topology_root_part(quad4Topology); |
| 80 |
std::vector<stk::mesh::Entity> nodes(quad4Topology.num_nodes()); |
| 81 |
for(unsigned i=0; i<quad4Topology.num_nodes(); ++i) { |
| 82 |
stk::mesh::EntityId nodeId = i+1; |
| 83 |
nodes[i] = get_bulk().get_entity(stk::topology::NODE_RANK, nodeId); |
| 84 |
} |
| 85 |
stk::mesh::Entity face1 = get_bulk().declare_solo_side(1, {&quad4Part}); |
| 86 |
stk::mesh::Permutation perm = static_cast<stk::mesh::Permutation>(0); |
| 87 |
for(unsigned i=0; i<quad4Topology.num_nodes(); ++i) { |
| 88 |
get_bulk().declare_relation(face1, nodes[i], i, perm); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
void create_face_with_shared_nodes(const stk::mesh::EntityVector &sharedNodes) |
| 94 |
{ |
| 95 |
get_bulk().modification_begin(); |
| 96 |
|
| 97 |
stk::mesh::Part &quad4Part = get_meta().get_topology_root_part(stk::topology::QUAD_4); |
| 98 |
|
| 99 |
if (get_proc_rank() == 0) { |
| 100 |
stk::mesh::Entity face = get_bulk().declare_solo_side({&quad4Part}); |
| 101 |
stk::mesh::Permutation perm = static_cast<stk::mesh::Permutation> (0); |
| 102 |
for(unsigned i = 0; i<sharedNodes.size(); ++i) |
| 103 |
get_bulk().declare_relation(face, sharedNodes[i], i, perm); |
| 104 |
} |
| 105 |
else if (get_proc_rank() == 1) { |
| 106 |
stk::mesh::Entity elem5 = get_bulk().get_entity(stk::topology::ELEM_RANK, 5u); |
| 107 |
get_bulk().declare_element_side(elem5, 4, stk::mesh::ConstPartVector{&quad4Part}); |
| 108 |
} |
| 109 |
|
| 110 |
get_bulk().modification_end(); |
| 111 |
} |
| 112 |
|
| 113 |
void run(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 114 |
{ |
| 115 |
setup_mesh("generated:3x1x2", auraOption); |
| 116 |
|
| 117 |
get_bulk().modification_begin(); |
| 118 |
stk::mesh::EntityVector sharedNodes = delete_element2_on_p0_and_get_shared_nodes(); |
| 119 |
get_bulk().modification_end(); |
| 120 |
|
| 121 |
if(get_proc_rank() == 1) |
| 122 |
sharedNodes = get_shared_nodes_of_element5_on_p1(); |
| 123 |
|
| 124 |
create_face_with_shared_nodes(sharedNodes); |
| 125 |
std::vector<stk::mesh::Entity> orphanedSides = stk::mesh::get_orphaned_sides_with_attached_element_on_different_proc(get_bulk()); |
| 126 |
|
| 127 |
bool faceLeftBehind = !orphanedSides.empty(); |
| 128 |
bool faceLeftBehindOnAnyProc = stk::is_true_on_any_proc(get_bulk().parallel(), faceLeftBehind); |
| 129 |
ASSERT_TRUE(faceLeftBehindOnAnyProc); |
| 130 |
} |
| 131 |
|
| 132 |
void runTrueOrphanedSide(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 133 |
{ |
| 134 |
setup_mesh("generated:1x1x2", auraOption); |
| 135 |
|
| 136 |
get_bulk().modification_begin(); |
| 137 |
delete_element1_on_p0(); |
| 138 |
get_bulk().modification_end(); |
| 139 |
|
| 140 |
get_bulk().modification_begin(); |
| 141 |
create_orphaned_side_on_p0(); |
| 142 |
get_bulk().modification_end(); |
| 143 |
|
| 144 |
std::vector<stk::mesh::Entity> orphanedSides = stk::mesh::get_orphaned_sides_with_attached_element_on_different_proc(get_bulk()); |
| 145 |
|
| 146 |
bool faceLeftBehind = !orphanedSides.empty(); |
| 147 |
bool faceLeftBehindOnAnyProc = stk::is_true_on_any_proc(get_bulk().parallel(), faceLeftBehind); |
| 148 |
ASSERT_FALSE(faceLeftBehindOnAnyProc); |
| 149 |
} |
| 150 |
}; |
| 151 |
|
| 152 |
/////////////////////////////////////////////////////////////////// |
| 153 |
|
| 154 |
TEST_F(UnitTestRuleThreeViolation, keyholeWithAura) |
| 155 |
{ |
| 156 |
if(stk::parallel_machine_size(get_comm())==2) |
| 157 |
run(stk::mesh::BulkData::AUTO_AURA); |
| 158 |
} |
| 159 |
|
| 160 |
TEST_F(UnitTestRuleThreeViolation, keyholeWithoutAura) |
| 161 |
{ |
| 162 |
if(stk::parallel_machine_size(get_comm())==2) |
| 163 |
run(stk::mesh::BulkData::NO_AUTO_AURA); |
| 164 |
} |
| 165 |
|
| 166 |
TEST_F(UnitTestRuleThreeViolation, trueOrphanedSideWithAura) |
| 167 |
{ |
| 168 |
if(stk::parallel_machine_size(get_comm())==2) |
| 169 |
runTrueOrphanedSide(stk::mesh::BulkData::AUTO_AURA); |
| 170 |
} |
| 171 |
|
| 172 |
TEST_F(UnitTestRuleThreeViolation, trueOrphanedSideWithoutAura) |
| 173 |
{ |
| 174 |
if(stk::parallel_machine_size(get_comm())==2) |
| 175 |
runTrueOrphanedSide(stk::mesh::BulkData::NO_AUTO_AURA); |
| 176 |
} |
| 177 |
|
| 178 |
} |