Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/face_creation/skin_mesh/UnitTestSkinMeshCoincidentElements.cpp

raw
1 #include "mpi.h" // for MPI_Comm, etc
2 #include <stddef.h> // for size_t
3 #include <ostream> // for basic_ostream::operator<<
4 #include <stk_mesh/base/BulkData.hpp> // for BulkData, etc
5 #include <stk_mesh/base/SkinBoundary.hpp>
6 #include <stk_mesh/base/FEMHelpers.hpp> // for declare_element
7 #include <stk_mesh/base/GetEntities.hpp> // for get_selected_entities
8 #include <stk_unit_test_utils/MeshFixture.hpp> // for MeshTestFixture
9 #include <vector> // for vector
10 #include "gtest/gtest.h" // for TEST_F, ASSERT_EQ, etc
11 #include "stk_mesh/base/Entity.hpp" // for Entity
12 #include "stk_mesh/base/MetaData.hpp" // for MetaData
13 #include "stk_mesh/base/Selector.hpp" // for Selector
14 #include "stk_mesh/base/Types.hpp" // for EntityIdVector, etc
15 #include "stk_topology/topology.hpp" // for topology, etc
16 #include "stk_util/parallel/Parallel.hpp" // for parallel_machine_rank, etc
17 #include <stk_util/parallel/CommSparse.hpp>
18 #include <stk_mesh/base/SkinBoundary.hpp>
19
20 namespace stk { namespace mesh { class Part; } }
21
22 namespace
23 {
24
25 int get_other_proc(MPI_Comm comm)
26 {
27 return stk::parallel_machine_size(comm) - stk::parallel_machine_rank(comm) - 1;
28 }
29
30 class CoincidentElements: public stk::unit_test_util::MeshTestFixture
31 {
32 protected:
33 void make_coincident_element_mesh(unsigned numElemsToCreate, const stk::mesh::EntityIdVector &nodes, stk::mesh::Part &part)
34 {
35 get_bulk().modification_begin();
36 declare_coincident_elements_round_robin(numElemsToCreate, nodes, part);
37 make_nodes_shared(nodes);
38 get_bulk().modification_end();
39 }
40 void run_skin_mesh()
41 {
42 stk::mesh::create_exposed_block_boundary_sides(get_bulk(), get_meta().universal_part(), stk::mesh::PartVector());
43 }
44 void expect_faces_connected_to_num_elements_locally(const std::vector<unsigned> &goldNumConnectedElems)
45 {
46 stk::mesh::EntityVector faces = get_all_faces();
47 ASSERT_EQ(goldNumConnectedElems.size(), faces.size());
48 for(size_t i=0; i<faces.size(); i++)
49 EXPECT_EQ(goldNumConnectedElems[i], get_bulk().num_elements(faces[i])) << i;
50 }
51 stk::mesh::EntityVector get_all_faces()
52 {
53 stk::mesh::EntityVector faces;
54 stk::mesh::get_selected_entities(get_meta().universal_part(), get_bulk().buckets(stk::topology::FACE_RANK), faces);
55 return faces;
56 }
57 void make_nodes_shared(const stk::mesh::EntityIdVector &nodes)
58 {
59 if (get_bulk().parallel_size() > 1) {
60 for(const stk::mesh::EntityId nodeId : nodes) {
61 get_bulk().add_node_sharing(get_bulk().get_entity(stk::topology::NODE_RANK, nodeId), get_other_proc(get_comm()));
62 }
63 }
64 }
65 private:
66 bool is_element_created_on_this_proc(int elementIndex)
67 {
68 return (elementIndex % get_bulk().parallel_size() == get_bulk().parallel_rank());
69 }
70 void declare_coincident_elements_round_robin(unsigned numElemsToCreate, const stk::mesh::EntityIdVector &nodes, stk::mesh::Part &part)
71 {
72 for(unsigned i = 0; i < numElemsToCreate; i++)
73 if(is_element_created_on_this_proc(i))
74 stk::mesh::declare_element(get_bulk(), part, i+1, nodes);
75 }
76 };
77
78 class CoincidentQuad4Shells : public CoincidentElements
79 {
80 protected:
81 void skin_num_coincident_shells(unsigned numElemsToCreate, stk::mesh::BulkData::AutomaticAuraOption auraOption)
82 {
83 setup_empty_mesh(auraOption);
84 create_stacked_shells(numElemsToCreate);
85 run_skin_mesh();
86 }
87 void create_stacked_shells(unsigned numElemsToCreate)
88 {
89 stk::mesh::Part &shellPart = get_meta().get_topology_root_part(stk::topology::SHELL_QUADRILATERAL_4);
90 stk::mesh::EntityIdVector nodes = {1, 2, 3, 4};
91 make_coincident_element_mesh(numElemsToCreate, nodes, shellPart);
92 }
93 void expect_local_face_shared_to_other_proc(const std::vector<int> &goldSharedProcs, const stk::mesh::EntityIdVector &goldFaceIds)
94 {
95 stk::mesh::EntityVector faces = get_all_faces();
96 ASSERT_EQ(goldSharedProcs.size(), faces.size());
97 for(size_t i=0; i<faces.size(); i++)
98 expect_face_identifier_and_sharing_proc(faces[i], goldFaceIds[i], goldSharedProcs[i]);
99 }
100 void expect_face_identifier_and_sharing_proc(stk::mesh::Entity face, stk::mesh::EntityId goldFaceId, int goldSharedProc)
101 {
102 EXPECT_EQ(goldFaceId, get_bulk().identifier(face));
103 expect_sharing_proc(face, goldSharedProc);
104 }
105 void expect_sharing_proc(stk::mesh::Entity face, int goldSharedProc)
106 {
107 std::vector<int> procs;
108 get_bulk().comm_shared_procs(get_bulk().entity_key(face), procs);
109 ASSERT_EQ(1u, procs.size());
110 EXPECT_EQ(goldSharedProc, procs[0]);
111 }
112 };
113
114 class TwoCoincidentQuad4Shells : public CoincidentQuad4Shells
115 {
116 protected:
117 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
118 {
119 unsigned numElemsToCreate = 2;
120 skin_num_coincident_shells(numElemsToCreate, auraOption);
121 expect_faces_connected_to_num_elements_locally({numElemsToCreate, numElemsToCreate});
122 }
123 };
124 TEST_F(TwoCoincidentQuad4Shells, Skin)
125 {
126 run_test_on_num_procs(1, stk::mesh::BulkData::NO_AUTO_AURA);
127 }
128
129 class ThreeCoincidentQuad4Shells : public CoincidentQuad4Shells
130 {
131 protected:
132 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
133 {
134 unsigned numElemsToCreate = 3;
135 skin_num_coincident_shells(numElemsToCreate, auraOption);
136 expect_faces_connected_to_num_elements_locally({numElemsToCreate, numElemsToCreate});
137 }
138 };
139 TEST_F(ThreeCoincidentQuad4Shells, Skin)
140 {
141 run_test_on_num_procs(1, stk::mesh::BulkData::NO_AUTO_AURA);
142 }
143
144 class TwoCoincidentQuad4ShellsInParallel : public CoincidentQuad4Shells
145 {
146 protected:
147 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
148 {
149 skin_num_coincident_shells(2, auraOption);
150 expect_faces_connected_to_num_elements_locally({1, 1});
151 int otherProc = get_other_proc(get_comm());
152 expect_local_face_shared_to_other_proc({otherProc, otherProc}, {1, 2});
153 }
154 };
155 // disabled due to split coincident elements
156 TEST_F(TwoCoincidentQuad4ShellsInParallel, DISABLED_Skin)
157 {
158 run_test_on_num_procs(2, stk::mesh::BulkData::NO_AUTO_AURA);
159 }
160
161
162 class CoincidentHex8s : public CoincidentElements
163 {
164 protected:
165 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
166 {
167 setup_empty_mesh(auraOption);
168 create_two_coincident_hexes();
169 run_skin_mesh();
170 expect_faces_connected_to_num_elements_locally({2, 2, 2, 2, 2, 2});
171 }
172 void create_two_coincident_hexes()
173 {
174 block1 = &get_meta().declare_part_with_topology("block_1", stk::topology::HEX_8);
175 stk::mesh::EntityIdVector nodes = {1, 2, 3, 4, 5, 6, 7, 8};
176 declare_num_coincident_elements(2, nodes, *block1);
177 }
178 void declare_num_coincident_elements(unsigned numElemsToCreate, const stk::mesh::EntityIdVector &nodes, stk::mesh::Part &part)
179 {
180 get_bulk().modification_begin();
181 for(unsigned i = 0; i < numElemsToCreate; i++)
182 stk::mesh::declare_element(get_bulk(), part, i+1, nodes);
183 get_bulk().modification_end();
184 }
185 stk::mesh::Part *block1;
186 };
187 TEST_F(CoincidentHex8s, SkinMesh)
188 {
189 run_test_on_num_procs(1, stk::mesh::BulkData::NO_AUTO_AURA);
190 }
191
192 class CoincidentHex8sWithAdjacentHex : public CoincidentHex8s
193 {
194 protected:
195 void create_coincident_hex8s_with_adjacent_hex(stk::mesh::BulkData::AutomaticAuraOption auraOption)
196 {
197 setup_empty_mesh(auraOption);
198 block2 = &get_meta().declare_part_with_topology("block_2", stk::topology::HEX_8);
199 create_two_coincident_hexes();
200 create_adjacent_hex();
201 }
202 private:
203 void create_adjacent_hex()
204 {
205 stk::mesh::EntityIdVector nodes = {5, 6, 7, 8, 9, 10, 11, 12};
206 get_bulk().modification_begin();
207 stk::mesh::declare_element(get_bulk(), *block2, 3, nodes);
208 get_bulk().modification_end();
209 }
210 protected:
211 stk::mesh::Part *block2;
212 };
213
214 class CoincidentHex8sWithAdjacentHexSerial : public CoincidentHex8sWithAdjacentHex
215 {
216 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
217 {
218 create_coincident_hex8s_with_adjacent_hex(auraOption);
219 stk::mesh::create_exposed_block_boundary_sides(get_bulk(), get_meta().universal_part(), {});
220 expect_faces_connected_to_num_elements_locally({2, 2, 2, 2, 2, 1, 1, 1, 1, 1});
221 }
222 };
223 TEST_F(CoincidentHex8sWithAdjacentHexSerial, Skin)
224 {
225 run_test_on_num_procs(1, stk::mesh::BulkData::NO_AUTO_AURA);
226 }
227
228 class CoincidentHex8sWithAdjacentAirHex : public CoincidentHex8sWithAdjacentHex
229 {
230 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
231 {
232 create_coincident_hex8s_with_adjacent_hex(auraOption);
233 stk::mesh::Selector air = *block2;
234 stk::mesh::create_exposed_block_boundary_sides(get_bulk(), *block1, {}, air);
235
236 expect_faces_connected_to_num_elements_locally({2, 2, 2, 2, 2, 3});
237 }
238 };
239 TEST_F(CoincidentHex8sWithAdjacentAirHex, Skin)
240 {
241 run_test_on_num_procs(1, stk::mesh::BulkData::NO_AUTO_AURA);
242 }
243
244 class Hex8WithAdjacentCoincidentAirHex8s : public CoincidentHex8sWithAdjacentHex
245 {
246 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
247 {
248 create_coincident_hex8s_with_adjacent_hex(auraOption);
249
250 stk::mesh::Selector air = *block1;
251 stk::mesh::create_exposed_block_boundary_sides(get_bulk(), *block2, {}, air);
252 expect_faces_connected_to_num_elements_locally({3, 1, 1, 1, 1, 1});
253 }
254 };
255 TEST_F(Hex8WithAdjacentCoincidentAirHex8s, Skin)
256 {
257 run_test_on_num_procs(1, stk::mesh::BulkData::NO_AUTO_AURA);
258 }
259
260 class CoincidentHex8sWithAdjacentHexInParallel : public CoincidentHex8sWithAdjacentHex
261 {
262 protected:
263 void create_coincident_hex8s_with_adjacent_hex_on_2_procs(stk::mesh::BulkData::AutomaticAuraOption auraOption,
264 const stk::mesh::EntityIdVector &ids)
265 {
266 setup_empty_mesh(auraOption);
267 create_block_parts();
268 fill_mesh_with_coincident_hex8s_and_adjacent_hex_in_parallel(ids);
269 }
270 void fill_mesh_with_coincident_hex8s_and_adjacent_hex_in_parallel(const stk::mesh::EntityIdVector &ids)
271 {
272 get_bulk().modification_begin();
273 create_coincident_hexes_on_proc0_and_adjacent_hex_on_proc1(ids);
274 make_nodes_shared({5, 6, 7, 8});
275 get_bulk().modification_end();
276 }
277 void create_block_parts()
278 {
279 block1 = &get_meta().declare_part_with_topology("block_1", stk::topology::HEX_8);
280 block2 = &get_meta().declare_part_with_topology("block_2", stk::topology::HEX_8);
281 }
282 void create_coincident_hexes_on_proc0_and_adjacent_hex_on_proc1(const stk::mesh::EntityIdVector &ids)
283 {
284 if(get_bulk().parallel_rank() == 0)
285 create_coincident_hexes(ids[0], ids[1]);
286 else
287 stk::mesh::declare_element(get_bulk(), *block2, ids[2], {5, 6, 7, 8, 9, 10, 11, 12});
288 }
289 void create_coincident_hexes(stk::mesh::EntityId id1, stk::mesh::EntityId id2)
290 {
291 stk::mesh::EntityIdVector nodes = {1, 2, 3, 4, 5, 6, 7, 8};
292 stk::mesh::declare_element(get_bulk(), *block1, id1, nodes);
293 stk::mesh::declare_element(get_bulk(), *block1, id2, nodes);
294 }
295 void expect_faces_connected_to_num_elements_locally_per_proc(const std::vector<unsigned> &goldNumConnectedElemsProc0,
296 const std::vector<unsigned> &goldNumConnectedElemsProc1)
297 {
298 if(get_bulk().parallel_rank() == 0)
299 expect_faces_connected_to_num_elements_locally(goldNumConnectedElemsProc0);
300 else
301 expect_faces_connected_to_num_elements_locally(goldNumConnectedElemsProc1);
302 }
303 void skin_part_with_part2_as_air(stk::mesh::Selector partToSkin, stk::mesh::Selector partToConsiderAsAir)
304 {
305 stk::mesh::create_exposed_block_boundary_sides(get_bulk(), partToSkin, {}, partToConsiderAsAir);
306 }
307 stk::mesh::Part *block2;
308 };
309
310 class CoincidentHex8sWithAdjacentAirHexInParallel : public CoincidentHex8sWithAdjacentHexInParallel
311 {
312 protected:
313 void run_with_element_ids(stk::mesh::BulkData::AutomaticAuraOption auraOption, const stk::mesh::EntityIdVector &ids)
314 {
315 create_coincident_hex8s_with_adjacent_hex_on_2_procs(auraOption, ids);
316 skin_part_with_part2_as_air(*block1, *block2);
317 expect_faces_connected_to_num_elements_locally_per_proc( {2, 2, 2, 2, 2, 2}, {1});
318 }
319 };
320 TEST_F(CoincidentHex8sWithAdjacentAirHexInParallel, SkinHex1Hex2)
321 {
322 if(stk::parallel_machine_size(get_comm()) == 2)
323 run_with_element_ids(stk::mesh::BulkData::NO_AUTO_AURA, {1, 2, 3});
324 }
325 TEST_F(CoincidentHex8sWithAdjacentAirHexInParallel, SkinHex2Hex1)
326 {
327 if(stk::parallel_machine_size(get_comm()) == 2)
328 run_with_element_ids(stk::mesh::BulkData::NO_AUTO_AURA, {2, 1, 3});
329 }
330
331 class Hex8WithAdjacentCoincidentAirHex8sInParallel : public CoincidentHex8sWithAdjacentHexInParallel
332 {
333 virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption)
334 {
335 create_coincident_hex8s_with_adjacent_hex_on_2_procs(auraOption, {1, 2, 3});
336 skin_part_with_part2_as_air(*block2, *block1);
337 expect_faces_connected_to_num_elements_locally_per_proc({2}, {1, 1, 1, 1, 1, 1});
338 }
339 };
340 TEST_F(Hex8WithAdjacentCoincidentAirHex8sInParallel, Skin)
341 {
342 run_test_on_num_procs(2, stk::mesh::BulkData::NO_AUTO_AURA);
343 }
344
345 }