| 1 |
#include <gtest/gtest.h> |
| 2 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 3 |
#include "stk_mesh/base/GetEntities.hpp" |
| 4 |
#include <stk_mesh/base/MeshDiagnostics.hpp> |
| 5 |
#include <stk_util/parallel/ParallelReduceBool.hpp> |
| 6 |
|
| 7 |
namespace |
| 8 |
{ |
| 9 |
|
| 10 |
class MeshCheckerOwnedOrphans : public stk::unit_test_util::MeshFixture |
| 11 |
{ |
| 12 |
protected: |
| 13 |
MeshCheckerOwnedOrphans() |
| 14 |
{ |
| 15 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
void fill_mesh_with_orphaned_owned_sides(stk::mesh::BulkData& bulkData) |
| 20 |
{ |
| 21 |
bulkData.modification_begin(); |
| 22 |
if(bulkData.parallel_rank()==1) |
| 23 |
{ |
| 24 |
stk::mesh::EntityVector nodes(4); |
| 25 |
for(stk::mesh::EntityId id=1;id<=4;++id) |
| 26 |
nodes[id-1] = bulkData.declare_node(id); |
| 27 |
|
| 28 |
stk::mesh::Entity face = bulkData.declare_solo_side(1, {&bulkData.mesh_meta_data().get_topology_root_part(stk::topology::QUADRILATERAL_4)}); |
| 29 |
for(size_t i=0;i<nodes.size();++i) |
| 30 |
bulkData.declare_relation(face, nodes[i], i); |
| 31 |
} |
| 32 |
bulkData.modification_end(); |
| 33 |
} |
| 34 |
|
| 35 |
TEST_F(MeshCheckerOwnedOrphans, check_mesh_without_orphaned_owned_sides) |
| 36 |
{ |
| 37 |
if(stk::parallel_machine_size(get_comm())==2) |
| 38 |
{ |
| 39 |
std::vector<stk::mesh::Entity> orphanedOwnedSides = stk::mesh::get_orphaned_owned_sides(get_bulk()); |
| 40 |
EXPECT_TRUE(orphanedOwnedSides.empty()); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
TEST_F(MeshCheckerOwnedOrphans, check_mesh_with_orphaned_owned_sides) |
| 45 |
{ |
| 46 |
if(stk::parallel_machine_size(get_comm())==2) |
| 47 |
{ |
| 48 |
std::vector<std::vector<stk::mesh::EntityKey> > badSidesPerProc = { |
| 49 |
{}, |
| 50 |
{stk::mesh::EntityKey(stk::topology::FACE_RANK, 1)} |
| 51 |
}; |
| 52 |
|
| 53 |
fill_mesh_with_orphaned_owned_sides(get_bulk()); |
| 54 |
std::vector<stk::mesh::Entity> orphanedOwnedSides = stk::mesh::get_orphaned_owned_sides(get_bulk()); |
| 55 |
std::vector<stk::mesh::EntityKey> orphanedOwnedSidesKeys; |
| 56 |
for(stk::mesh::Entity entity : orphanedOwnedSides) |
| 57 |
orphanedOwnedSidesKeys.push_back(get_bulk().entity_key(entity)); |
| 58 |
|
| 59 |
EXPECT_EQ(badSidesPerProc[get_bulk().parallel_rank()].size(), orphanedOwnedSides.size()); |
| 60 |
EXPECT_EQ(badSidesPerProc[get_bulk().parallel_rank()], orphanedOwnedSidesKeys); |
| 61 |
EXPECT_FALSE(stk::is_true_on_all_procs(get_bulk().parallel(), orphanedOwnedSides.empty())); |
| 62 |
const std::vector<std::string> & orphanedOwnedMessages = get_messages_for_orphaned_owned_sides(get_bulk(), orphanedOwnedSides); |
| 63 |
for (const std::string & errorMessage : orphanedOwnedMessages) { |
| 64 |
std::cerr << errorMessage; |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
class MeshCheckerWithElements : public stk::unit_test_util::MeshFixture |
| 70 |
{ |
| 71 |
protected: |
| 72 |
void delete_element5_on_proc0() |
| 73 |
{ |
| 74 |
get_bulk().modification_begin(); |
| 75 |
if(get_bulk().parallel_rank()==0) |
| 76 |
{ |
| 77 |
stk::mesh::EntityId elementId = 5; |
| 78 |
stk::mesh::Entity element = get_bulk().get_entity(stk::topology::ELEM_RANK, elementId); |
| 79 |
get_bulk().destroy_entity(element); |
| 80 |
} |
| 81 |
get_bulk().modification_end(); |
| 82 |
} |
| 83 |
|
| 84 |
void make_an_orphaned_face_on_proc0() |
| 85 |
{ |
| 86 |
get_bulk().modification_begin(); |
| 87 |
if(get_bulk().parallel_rank()==0) |
| 88 |
{ |
| 89 |
stk::mesh::EntityIdVector ids{18, 19, 22, 23}; |
| 90 |
stk::mesh::Entity face = get_bulk().declare_solo_side(1, {&get_bulk().mesh_meta_data().get_topology_root_part(stk::topology::QUADRILATERAL_4)}); |
| 91 |
for(size_t i=0;i<ids.size();++i) |
| 92 |
{ |
| 93 |
stk::mesh::Entity node = get_bulk().get_entity(stk::topology::NODE_RANK, ids[i]); |
| 94 |
get_bulk().declare_relation(face, node, i); |
| 95 |
} |
| 96 |
} |
| 97 |
get_bulk().modification_end(); |
| 98 |
} |
| 99 |
|
| 100 |
void test_if_orphaned_faces_are_found() |
| 101 |
{ |
| 102 |
std::vector<std::vector<stk::mesh::EntityKey> > badSidesPerProc = { |
| 103 |
{stk::mesh::EntityKey(stk::topology::FACE_RANK, 1)}, |
| 104 |
{}, |
| 105 |
}; |
| 106 |
|
| 107 |
std::vector<stk::mesh::Entity> orphanedOwnedSides = get_orphaned_owned_sides(get_bulk()); |
| 108 |
std::vector<stk::mesh::EntityKey> orphanedOwnedSidesKeys; |
| 109 |
for(stk::mesh::Entity entity : orphanedOwnedSides) |
| 110 |
orphanedOwnedSidesKeys.push_back(get_bulk().entity_key(entity)); |
| 111 |
EXPECT_EQ(badSidesPerProc[get_bulk().parallel_rank()], orphanedOwnedSidesKeys); |
| 112 |
} |
| 113 |
}; |
| 114 |
|
| 115 |
TEST_F(MeshCheckerWithElements, withoutAura) |
| 116 |
{ |
| 117 |
if(stk::parallel_machine_size(get_comm())==2) |
| 118 |
{ |
| 119 |
setup_mesh("generated:3x1x4", stk::mesh::BulkData::NO_AUTO_AURA); |
| 120 |
delete_element5_on_proc0(); |
| 121 |
make_an_orphaned_face_on_proc0(); |
| 122 |
test_if_orphaned_faces_are_found(); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
TEST_F(MeshCheckerWithElements, withAura) |
| 127 |
{ |
| 128 |
if(stk::parallel_machine_size(get_comm())==2) |
| 129 |
{ |
| 130 |
setup_mesh("generated:3x1x4", stk::mesh::BulkData::AUTO_AURA); |
| 131 |
delete_element5_on_proc0(); |
| 132 |
make_an_orphaned_face_on_proc0(); |
| 133 |
test_if_orphaned_faces_are_found(); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
} |