Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestCheckUniqueGlobalIds.cpp

raw
1 #include <gtest/gtest.h>
2 #include <stk_unit_test_utils/MeshFixture.hpp>
3 #include "stk_util/parallel/DistributedIndex.hpp"
4 #include "stk_mesh/baseImpl/MeshImplUtils.hpp"
5 #include "stk_mesh/base/GetEntities.hpp"
6 #include "stk_mesh/base/FEMHelpers.hpp"
7 #include "stk_mesh/base/MeshDiagnostics.hpp"
8
9 namespace
10 {
11
12 class MeshChecker : public stk::unit_test_util::MeshFixture
13 {
14 public:
15 };
16
17 void test_non_unique_key_results(const stk::mesh::BulkData& bulkData, const std::vector<std::vector<stk::mesh::EntityKeyProc>>& gold_values)
18 {
19 std::vector<stk::mesh::EntityKeyProc> badKeyProcs = stk::mesh::get_non_unique_key_procs(bulkData);
20 EXPECT_EQ(gold_values[bulkData.parallel_rank()].size(), badKeyProcs.size());
21 EXPECT_EQ(gold_values[bulkData.parallel_rank()], badKeyProcs);
22 EXPECT_THROW(stk::mesh::throw_if_any_proc_has_false(bulkData.parallel(), badKeyProcs.empty()), std::logic_error);
23 }
24
25 void test_keys_are_unique(const stk::mesh::BulkData& bulkData)
26 {
27 std::vector<stk::mesh::EntityKeyProc> badKeyProcs = stk::mesh::get_non_unique_key_procs(bulkData);
28 EXPECT_TRUE(badKeyProcs.empty());
29 EXPECT_NO_THROW(stk::mesh::throw_if_any_proc_has_false(bulkData.parallel(), badKeyProcs.empty()));
30 }
31
32 TEST_F(MeshChecker, check_throw_on_non_unique_ids)
33 {
34 if(stk::parallel_machine_size(get_comm())==2)
35 {
36 std::vector<std::vector<stk::mesh::EntityKeyProc>> gold_values = {
37 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 1}},
38 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 0}},
39 };
40
41 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
42 get_bulk().modification_begin();
43 get_bulk().declare_node(1);
44 get_bulk().modification_end();
45
46 test_non_unique_key_results(get_bulk(), gold_values);
47 }
48 }
49
50 TEST_F(MeshChecker, check_no_throw_on_shared_nodes)
51 {
52 if(stk::parallel_machine_size(get_comm())==2)
53 {
54 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
55 get_bulk().modification_begin();
56 stk::mesh::Entity node1 = get_bulk().declare_node(1);
57 get_bulk().add_node_sharing(node1, 1-get_bulk().parallel_rank());
58 get_bulk().modification_end();
59
60 test_keys_are_unique(get_bulk());
61 }
62 }
63
64 TEST_F(MeshChecker, check_throw_on_partial_shared_nodes)
65 {
66 if(stk::parallel_machine_size(get_comm())==3)
67 {
68 std::vector<std::vector<stk::mesh::EntityKeyProc>> gold_values = {
69 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 2}},
70 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 2}},
71 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 0},
72 { stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 1}},
73 };
74
75 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
76 get_bulk().modification_begin();
77 stk::mesh::Entity node1 = get_bulk().declare_node(1);
78 if(get_bulk().parallel_rank()<2)
79 {
80 get_bulk().add_node_sharing(node1, 1-get_bulk().parallel_rank());
81 }
82 get_bulk().modification_end();
83
84 test_non_unique_key_results(get_bulk(), gold_values);
85 }
86 }
87
88 TEST_F(MeshChecker, check_throw_on_partial_shared_nodes_on_four_procs)
89 {
90 if(stk::parallel_machine_size(get_comm())==4)
91 {
92 std::vector<std::vector<stk::mesh::EntityKeyProc>> gold_values = {
93 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 2},
94 { stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 3}},
95 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 2},
96 { stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 3}},
97 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 0},
98 { stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 1}},
99 {{ stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 0},
100 { stk::mesh::EntityKey(stk::topology::NODE_RANK, 1), 1}},
101 };
102
103 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
104 get_bulk().modification_begin();
105 stk::mesh::Entity node1 = get_bulk().declare_node(1);
106 if(get_bulk().parallel_rank()<2)
107 {
108 get_bulk().add_node_sharing(node1, 1-get_bulk().parallel_rank());
109 }
110 else
111 {
112 const int other_proc = get_bulk().parallel_rank()==2 ? 3 : 2;
113 get_bulk().add_node_sharing(node1, other_proc);
114 }
115 get_bulk().modification_end();
116
117 test_non_unique_key_results(get_bulk(), gold_values);
118 }
119 }
120
121 TEST_F(MeshChecker, check_throw_on_non_unique_ids_for_elements)
122 {
123 if(stk::parallel_machine_size(get_comm())==2)
124 {
125 std::vector<std::vector<stk::mesh::EntityKeyProc>> gold_values = {
126 {{ stk::mesh::EntityKey(stk::topology::ELEM_RANK, 1), 1}},
127 {{ stk::mesh::EntityKey(stk::topology::ELEM_RANK, 1), 0}},
128 };
129
130 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
131 get_bulk().modification_begin();
132 stk::mesh::EntityId nodeId = static_cast<stk::mesh::EntityId>(get_bulk().parallel_rank()+1u);
133 stk::mesh::declare_element(get_bulk(),get_meta().get_topology_root_part(stk::topology::PARTICLE),1u,stk::mesh::EntityIdVector{nodeId});
134 get_bulk().modification_end();
135
136 test_non_unique_key_results(get_bulk(), gold_values);
137 }
138 }
139
140 }
141
142