| 1 |
#include "gtest/gtest.h" |
| 2 |
#include "stk_mesh/baseImpl/DeletedEntityCache.hpp" |
| 3 |
#include "stk_unit_test_utils/MeshFixture.hpp" |
| 4 |
#include "stk_unit_test_utils/TextMesh.hpp" |
| 5 |
|
| 6 |
namespace { |
| 7 |
|
| 8 |
class DeletedEntityCacheTester : public stk::unit_test_util::MeshFixture |
| 9 |
{ |
| 10 |
protected: |
| 11 |
DeletedEntityCacheTester() : |
| 12 |
MeshFixture(3), |
| 13 |
cache() |
| 14 |
{ |
| 15 |
std::string meshDesc = |
| 16 |
"0,1,HEX_8,1,2,3,4,5,6,7,8\n\ |
| 17 |
0,2,HEX_8,2,9,10,3,6,11,12,7"; |
| 18 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 19 |
stk::unit_test_util::setup_text_mesh(get_bulk(), meshDesc); |
| 20 |
|
| 21 |
stk::mesh::BucketVector const& buckets = bulkData->get_buckets(stk::topology::NODE_RANK, metaData->universal_part()); |
| 22 |
for (auto& bucket : buckets) |
| 23 |
{ |
| 24 |
for (const stk::mesh::Entity& entity : *bucket) |
| 25 |
{ |
| 26 |
nodes.push_back(entity); |
| 27 |
max_local_offset = std::max(entity.local_offset(), max_local_offset); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
cache = std::make_shared<stk::mesh::impl::DeletedEntityCache>(*bulkData); |
| 32 |
} |
| 33 |
|
| 34 |
std::vector<stk::mesh::Entity::entity_value_type> get_ghost_entity_counts() |
| 35 |
{ |
| 36 |
auto& ghostReuseMap = cache->get_ghost_reuse_map(); |
| 37 |
std::vector<stk::mesh::Entity::entity_value_type> usedValuesCount(max_local_offset+1, 0); |
| 38 |
for (auto& keyOffsetPair : ghostReuseMap) |
| 39 |
{ |
| 40 |
usedValuesCount[keyOffsetPair.second] += 1; |
| 41 |
} |
| 42 |
|
| 43 |
return usedValuesCount; |
| 44 |
} |
| 45 |
|
| 46 |
std::shared_ptr<stk::mesh::impl::DeletedEntityCache> cache; |
| 47 |
std::vector<stk::mesh::Entity> nodes; |
| 48 |
stk::mesh::Entity::entity_value_type max_local_offset = 0; |
| 49 |
|
| 50 |
}; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
TEST_F(DeletedEntityCacheTester, mark_entity_as_deleted_nonghost) |
| 55 |
{ |
| 56 |
if (get_parallel_size() != 1) |
| 57 |
{ |
| 58 |
GTEST_SKIP(); |
| 59 |
} |
| 60 |
|
| 61 |
for (int i=0; i < 3; ++i) |
| 62 |
{ |
| 63 |
cache->mark_entity_as_deleted(nodes[i], false); |
| 64 |
} |
| 65 |
|
| 66 |
auto& ghost_reuse_map = cache->get_ghost_reuse_map(); |
| 67 |
EXPECT_EQ(ghost_reuse_map.size(), 0u); |
| 68 |
|
| 69 |
auto& deleted_entities = cache->get_deleted_entities_current_mod_cycle(); |
| 70 |
EXPECT_EQ(deleted_entities.size(), 3u); |
| 71 |
for (int i=0; i < 3; ++i) |
| 72 |
{ |
| 73 |
EXPECT_EQ(deleted_entities[i], nodes[i].local_offset()); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
TEST_F(DeletedEntityCacheTester, mark_entity_as_deleted_ghost) |
| 78 |
{ |
| 79 |
if (get_parallel_size() != 1) |
| 80 |
{ |
| 81 |
GTEST_SKIP(); |
| 82 |
} |
| 83 |
|
| 84 |
for (int i=0; i < 3; ++i) |
| 85 |
{ |
| 86 |
cache->mark_entity_as_deleted(nodes[i], true); |
| 87 |
} |
| 88 |
|
| 89 |
EXPECT_EQ(cache->get_deleted_entities_current_mod_cycle().size(), 0u); |
| 90 |
EXPECT_EQ(cache->get_ghost_reuse_map().size(), 3u); |
| 91 |
|
| 92 |
auto usedGhosts = get_ghost_entity_counts(); |
| 93 |
for (size_t i=0; i < nodes.size(); ++i) |
| 94 |
{ |
| 95 |
size_t expected_val = i < 3 ? 1 : 0; |
| 96 |
EXPECT_EQ(usedGhosts[nodes[i].local_offset()], expected_val); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
TEST_F(DeletedEntityCacheTester, get_entity_for_reuse_initial) |
| 101 |
{ |
| 102 |
if (get_parallel_size() != 1) |
| 103 |
{ |
| 104 |
GTEST_SKIP(); |
| 105 |
} |
| 106 |
|
| 107 |
EXPECT_EQ(cache->get_entity_for_reuse(), stk::mesh::Entity::InvalidEntity); |
| 108 |
} |
| 109 |
|
| 110 |
TEST_F(DeletedEntityCacheTester, update_deleted_entities_container) |
| 111 |
{ |
| 112 |
if (get_parallel_size() != 1) |
| 113 |
{ |
| 114 |
GTEST_SKIP(); |
| 115 |
} |
| 116 |
|
| 117 |
std::vector<stk::mesh::Entity::entity_value_type> destroyedEntities; |
| 118 |
for (int i=0; i < 5; ++i) |
| 119 |
{ |
| 120 |
bool isGhost = i < 3; |
| 121 |
cache->mark_entity_as_deleted(nodes[i], isGhost); |
| 122 |
destroyedEntities.push_back(nodes[i].local_offset()); |
| 123 |
} |
| 124 |
std::sort(destroyedEntities.begin(), destroyedEntities.end()); |
| 125 |
|
| 126 |
EXPECT_EQ(cache->get_entity_for_reuse(), stk::mesh::Entity::InvalidEntity); |
| 127 |
cache->update_deleted_entities_container(); |
| 128 |
|
| 129 |
std::vector<stk::mesh::Entity::entity_value_type> reusedEntities; |
| 130 |
for (int i=0; i < 5; ++i) |
| 131 |
{ |
| 132 |
reusedEntities.push_back(cache->get_entity_for_reuse()); |
| 133 |
} |
| 134 |
std::sort(reusedEntities.begin(), reusedEntities.end()); |
| 135 |
|
| 136 |
for (int i=0; i < 5; ++i) |
| 137 |
{ |
| 138 |
EXPECT_EQ(destroyedEntities[i], reusedEntities[i]); |
| 139 |
} |
| 140 |
|
| 141 |
for (int i=0; i < 10; ++i) |
| 142 |
{ |
| 143 |
EXPECT_EQ(cache->get_entity_for_reuse(), stk::mesh::Entity::InvalidEntity); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|