| 1 |
#include "gtest/gtest.h" // for AssertHelper, EXPECT_EQ, etc |
| 2 |
#include <string> |
| 3 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 4 |
#include <stk_mesh/base/MetaData.hpp> |
| 5 |
#include <stk_mesh/base/Field.hpp> |
| 6 |
#include <stk_mesh/base/GetEntities.hpp> |
| 7 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 8 |
#include <stk_unit_test_utils/PerformanceTester.hpp> |
| 9 |
|
| 10 |
namespace |
| 11 |
{ |
| 12 |
|
| 13 |
class DestroyElementTopologyPerformanceTest : public stk::unit_test_util::MeshFixture |
| 14 |
{ |
| 15 |
protected: |
| 16 |
DestroyElementTopologyPerformanceTest() |
| 17 |
{ |
| 18 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 19 |
create_num_fields_of_rank(10, stk::topology::NODE_RANK); |
| 20 |
create_num_fields_of_rank(10, stk::topology::ELEM_RANK); |
| 21 |
stk::io::fill_mesh("generated:50x50x64", get_bulk()); |
| 22 |
} |
| 23 |
|
| 24 |
void expect_no_entities() |
| 25 |
{ |
| 26 |
EXPECT_EQ(0u, stk::mesh::count_selected_entities(get_meta().universal_part(), get_bulk().buckets(stk::topology::ELEM_RANK))); |
| 27 |
EXPECT_EQ(0u, stk::mesh::count_selected_entities(get_meta().universal_part(), get_bulk().buckets(stk::topology::NODE_RANK))); |
| 28 |
} |
| 29 |
private: |
| 30 |
void create_num_fields_of_rank(const unsigned numFields, stk::mesh::EntityRank rank) |
| 31 |
{ |
| 32 |
const std::string name = "field_" + std::to_string(rank) + "_"; |
| 33 |
for(unsigned i = 0; i < numFields; i++) |
| 34 |
create_vector_field_on_universal_part(rank, name + std::to_string(i)); |
| 35 |
} |
| 36 |
void create_vector_field_on_universal_part(stk::mesh::EntityRank rank, const std::string& name) |
| 37 |
{ |
| 38 |
auto& field = get_meta().declare_field<double>(rank, name, 3); |
| 39 |
stk::mesh::put_field_on_mesh(field, get_meta().universal_part(), nullptr); |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
class DestroyElementTopologyPerformance : public stk::unit_test_util::PerformanceTester |
| 45 |
{ |
| 46 |
public: |
| 47 |
DestroyElementTopologyPerformance(stk::mesh::BulkData &bulk) |
| 48 |
: stk::unit_test_util::PerformanceTester(bulk.parallel()), |
| 49 |
bulkData(bulk) |
| 50 |
{ } |
| 51 |
protected: |
| 52 |
virtual void run_algorithm_to_time() override { bulkData.destroy_elements_of_topology(stk::topology::HEX_8); } |
| 53 |
virtual size_t get_value_to_output_as_iteration_count() override { return 1; } |
| 54 |
private: |
| 55 |
stk::mesh::BulkData & bulkData; |
| 56 |
}; |
| 57 |
TEST_F(DestroyElementTopologyPerformanceTest, DestroyElementTopology) |
| 58 |
{ |
| 59 |
DestroyElementTopologyPerformance(get_bulk()).run_performance_test(); |
| 60 |
expect_no_entities(); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
class DestroyAllElementsIndividuallyPerformance : public stk::unit_test_util::PerformanceTester |
| 65 |
{ |
| 66 |
public: |
| 67 |
DestroyAllElementsIndividuallyPerformance(stk::mesh::BulkData &bulk) |
| 68 |
: stk::unit_test_util::PerformanceTester(bulk.parallel()), |
| 69 |
bulkData(bulk) |
| 70 |
{ } |
| 71 |
protected: |
| 72 |
virtual void run_algorithm_to_time() override |
| 73 |
{ |
| 74 |
bulkData.modification_begin(); |
| 75 |
for (stk::mesh::EntityRank rank : {stk::topology::ELEM_RANK, stk::topology::FACE_RANK, stk::topology::NODE_RANK}) |
| 76 |
destroy_entities_of_rank(rank); |
| 77 |
bulkData.modification_end(); |
| 78 |
} |
| 79 |
virtual size_t get_value_to_output_as_iteration_count() override { return 1; } |
| 80 |
private: |
| 81 |
void destroy_entities_of_rank(stk::mesh::EntityRank rank) |
| 82 |
{ |
| 83 |
stk::mesh::EntityVector entities; |
| 84 |
stk::mesh::get_entities(bulkData, rank, entities); |
| 85 |
for(stk::mesh::Entity elem : entities) |
| 86 |
bulkData.destroy_entity(elem); |
| 87 |
} |
| 88 |
stk::mesh::BulkData & bulkData; |
| 89 |
}; |
| 90 |
TEST_F(DestroyElementTopologyPerformanceTest, DestroyElementsIndividually) |
| 91 |
{ |
| 92 |
DestroyAllElementsIndividuallyPerformance(get_bulk()).run_performance_test(); |
| 93 |
expect_no_entities(); |
| 94 |
} |
| 95 |
|
| 96 |
} |