| 1 |
#include <gtest/gtest.h> |
| 2 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 3 |
#include <stk_mesh/base/SideIdPool.hpp> |
| 4 |
#include <stk_util/parallel/ParallelVectorConcat.hpp> |
| 5 |
#include <stk_util/util/SortAndUnique.hpp> |
| 6 |
|
| 7 |
class SideIdPoolTester : public stk::mesh::SideIdPool |
| 8 |
{ |
| 9 |
public: |
| 10 |
SideIdPoolTester(stk::mesh::BulkData &bulk) |
| 11 |
: SideIdPool(bulk) |
| 12 |
{ |
| 13 |
|
| 14 |
} |
| 15 |
|
| 16 |
const stk::mesh::EntityIdVector &my_get_all_ids() |
| 17 |
{ |
| 18 |
return get_all_ids(); |
| 19 |
} |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
class SideIdPoolInitialIdsTest : public stk::unit_test_util::MeshFixture |
| 24 |
{ |
| 25 |
protected: |
| 26 |
SideIdPoolInitialIdsTest() |
| 27 |
{ |
| 28 |
setup_mesh("generated:1x1x4", stk::mesh::BulkData::AUTO_AURA); |
| 29 |
sideIdPool = new SideIdPoolTester(get_bulk()); |
| 30 |
} |
| 31 |
|
| 32 |
virtual ~SideIdPoolInitialIdsTest() |
| 33 |
{ |
| 34 |
delete sideIdPool; |
| 35 |
} |
| 36 |
|
| 37 |
void generate_1000_ids_on_all_procs() |
| 38 |
{ |
| 39 |
sideIdPool->generate_initial_ids(numInitialIdsToRequestPerProc); |
| 40 |
const stk::mesh::EntityIdVector &idsThisProc = sideIdPool->my_get_all_ids(); |
| 41 |
stk::parallel_vector_concat(get_comm(), idsThisProc, ids); |
| 42 |
} |
| 43 |
|
| 44 |
void expect_ids_are_parallel_unique(const unsigned expectedParallelSize) |
| 45 |
{ |
| 46 |
size_t sizeBeforeSort = ids.size(); |
| 47 |
stk::util::sort_and_unique(ids); |
| 48 |
EXPECT_EQ(sizeBeforeSort, ids.size()); |
| 49 |
EXPECT_EQ(expectedParallelSize*get_bulk().parallel_size(), ids.size()); |
| 50 |
} |
| 51 |
|
| 52 |
const unsigned numInitialIdsToRequestPerProc = 1000; |
| 53 |
stk::mesh::EntityIdVector ids; |
| 54 |
SideIdPoolTester *sideIdPool; |
| 55 |
}; |
| 56 |
|
| 57 |
TEST_F(SideIdPoolInitialIdsTest, ids_are_unique) |
| 58 |
{ |
| 59 |
generate_1000_ids_on_all_procs(); |
| 60 |
expect_ids_are_parallel_unique(2*numInitialIdsToRequestPerProc); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
class SideIdPoolAdditionalIdTest : public SideIdPoolInitialIdsTest |
| 65 |
{ |
| 66 |
protected: |
| 67 |
void generate_5_additional_ids_on_all_procs() |
| 68 |
{ |
| 69 |
sideIdPool->generate_additional_ids_collective(numAdditionalIdsToRequestPerProc); |
| 70 |
const stk::mesh::EntityIdVector &idsThisProc = sideIdPool->my_get_all_ids(); |
| 71 |
stk::parallel_vector_concat(get_comm(), idsThisProc, ids); |
| 72 |
} |
| 73 |
|
| 74 |
void expect_5_additional_ids_are_parallel_unique() |
| 75 |
{ |
| 76 |
// when asking for 5 more, it will double the requested size if enough ids are not available |
| 77 |
expect_ids_are_parallel_unique(2*numInitialIdsToRequestPerProc); |
| 78 |
} |
| 79 |
|
| 80 |
const unsigned numAdditionalIdsToRequestPerProc = 5; |
| 81 |
}; |
| 82 |
TEST_F(SideIdPoolAdditionalIdTest, additional_ids_are_unique) |
| 83 |
{ |
| 84 |
generate_1000_ids_on_all_procs(); |
| 85 |
generate_5_additional_ids_on_all_procs(); |
| 86 |
expect_5_additional_ids_are_parallel_unique(); |
| 87 |
} |