Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestStkTextMesh.cpp

raw
1 #include <string>
2 #include <vector>
3
4 #include "gtest/gtest.h"
5 #include "mpi.h"
6
7 #include "UnitTestTextMeshFixture.hpp"
8
9 // STK specific versions of TextMesh
10 namespace
11 {
12 TEST_F(TestTextMeshAura, twoQuadShellWithCoordinates)
13 {
14 // 4-----5-----6
15 // | | |
16 // | 1 | 2 |
17 // | | |
18 // 1-----2-----3
19
20 if (get_parallel_size() != 2) return;
21 int rank = get_parallel_rank();
22
23 std::string meshDesc =
24 "0,1,SHELL_QUAD_4,1,2,5,4\n"
25 "1,2,SHELL_QUAD_4,2,3,6,5"
26 "|coordinates: 0,0,0, 1,0,0, 2,0,0, 0,1,0, 1,1,0, 2,1,0";
27 std::vector<double> goldCoordinates = {0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0};
28
29 setup_text_mesh(meshDesc);
30
31 verify_num_elements(2);
32 verify_single_element(1u, "SHELL_QUAD_4", EntityIdVector{1, 2, 5, 4});
33 verify_single_element(2u, "SHELL_QUAD_4", EntityIdVector{2, 3, 6, 5});
34 verify_coordinates(EntityIdVector{1, 2, 3, 4, 5, 6}, goldCoordinates);
35
36 if (rank == 0) verify_shared_nodes(EntityIdVector{2,5}, 1);
37 if (rank == 1) verify_shared_nodes(EntityIdVector{2,5}, 0);
38 }
39
40 TEST_F(TestTextMeshAura, sideBlockTopologyForConnectedHexes)
41 {
42 if (get_parallel_size() != 1) return;
43
44 std::string meshDesc =
45 "0,1,HEX_8,1, 2, 3, 4, 5, 6, 7, 8,block_1\n"
46 "0,2,HEX_8,5, 6, 7, 8, 9,10,11,12,block_2\n"
47 "|sideset:name=surface_1; data=1,1, 2,1; split=block";
48
49 setup_text_mesh(meshDesc);
50
51 verify_num_elements(2);
52
53 std::vector<std::string> sidesetSubsets;
54 std::string prefix("surface_");
55 sidesetSubsets.push_back(prefix + std::string("block_1") + "_" + get_topology_name("QUAD_4") + "_1");
56 sidesetSubsets.push_back(prefix + std::string("block_2") + "_" + get_topology_name("QUAD_4") + "_1");
57
58 verify_num_sidesets(1);
59 verify_single_sideset("surface_1", 1, sidesetSubsets, SideVector{{1, 1}, {2, 1}});
60
61 for (const std::string& subsetName : sidesetSubsets) {
62 stk::mesh::Part* subsetPart = get_meta().get_part(subsetName);
63 EXPECT_TRUE(nullptr != subsetPart);
64 EXPECT_EQ(stk::topology::QUAD_4, subsetPart->topology());
65 }
66 }
67
68 TEST_F(TestTextMeshAura, surfaceToBlockMapping_noSplit)
69 {
70 if (get_parallel_size() != 2) return;
71
72 std::string meshDesc =
73 "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1\n"
74 "1,2,HEX_8,2,9,10,3,6,11,12,7,block_2\n"
75 "|sideset:name=left_surf;data=1,4";
76
77 setup_text_mesh(meshDesc);
78
79 verify_num_elements(2);
80 verify_num_sidesets(1);
81
82 const stk::mesh::Part* block_1 = get_meta().get_part("block_1");
83
84 EXPECT_TRUE(nullptr != block_1);
85
86 {
87 std::string sidesetName("left_surf");
88
89 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
90 EXPECT_TRUE(nullptr != sidesetPart);
91 std::vector<const stk::mesh::Part*> goldParts{block_1};
92 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
93 }
94 }
95
96 TEST_F(TestTextMeshAura2d, surfaceToBlockMapping_splitByBlock)
97 {
98 if (get_parallel_size() != 1) return;
99
100 std::string meshDesc =
101 "0,1,TRI_3_2D,3,1,4,block_1\n"
102 "0,2,TRI_3_2D,1,2,4,block_1\n"
103 "0,3,TRI_3_2D,2,5,4,block_1\n"
104 "0,4,TRI_3_2D,5,7,4,block_2\n"
105 "0,5,TRI_3_2D,7,6,4,block_2\n"
106 "0,6,TRI_3_2D,6,3,4,block_2\n"
107 "|coordinates: 0,0,0.1,0,0,0.1,0.05,0.1,0.1,0.1,0,0.2,0.1,0.2"
108 "|dimension:2"
109 "|sideset:name=skinned_surf; skin=all; split=block"
110 "|sideset:name=internal_surf; data=1,3,3,2,4,3,6,2; split=block"
111 "|sideset:name=shared_surf; data=1,1,6,1; split=block"
112 "|sideset:name=owned_surf; data=5,1; split=block";
113
114 setup_text_mesh(meshDesc);
115
116 verify_num_elements(6);
117 verify_num_sidesets(4);
118
119 const stk::mesh::Part* block_1 = get_meta().get_part("block_1");
120 const stk::mesh::Part* block_2 = get_meta().get_part("block_2");
121
122 EXPECT_TRUE(nullptr != block_1);
123 EXPECT_TRUE(nullptr != block_2);
124
125 {
126 std::string sidesetName("skinned_surf");
127
128 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
129 EXPECT_TRUE(nullptr != sidesetPart);
130 std::vector<const stk::mesh::Part*> goldParts{block_1, block_2};
131 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
132 }
133
134 {
135 std::string sidesetName("skinned_surf_" + std::string("block_1") + "_" + get_topology_name("LINE_2"));
136
137 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
138 EXPECT_TRUE(nullptr != sidesetPart);
139 std::vector<const stk::mesh::Part*> goldParts{block_1};
140 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
141 }
142
143 {
144 std::string sidesetName("skinned_surf_" + std::string("block_2") + "_" + get_topology_name("LINE_2"));
145
146 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
147 EXPECT_TRUE(nullptr != sidesetPart);
148 std::vector<const stk::mesh::Part*> goldParts{block_2};
149 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
150 }
151
152 {
153 std::string sidesetName("internal_surf");
154
155 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
156 EXPECT_TRUE(nullptr != sidesetPart);
157 std::vector<const stk::mesh::Part*> goldParts{block_1, block_2};
158 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
159 }
160
161 {
162 std::string sidesetName("internal_surf_" + std::string("block_1") + "_" + get_topology_name("LINE_2"));
163
164 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
165 EXPECT_TRUE(nullptr != sidesetPart);
166 std::vector<const stk::mesh::Part*> goldParts{block_1};
167 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
168 }
169
170 {
171 std::string sidesetName("internal_surf_" + std::string("block_2") + "_" + get_topology_name("LINE_2"));
172
173 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
174 EXPECT_TRUE(nullptr != sidesetPart);
175 std::vector<const stk::mesh::Part*> goldParts{block_2};
176 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
177 }
178
179 {
180 std::string sidesetName("shared_surf");
181
182 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
183 EXPECT_TRUE(nullptr != sidesetPart);
184 std::vector<const stk::mesh::Part*> goldParts{block_1, block_2};
185 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
186 }
187
188 {
189 std::string sidesetName("shared_surf_" + std::string("block_1") + "_" + get_topology_name("LINE_2"));
190
191 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
192 EXPECT_TRUE(nullptr != sidesetPart);
193 std::vector<const stk::mesh::Part*> goldParts{block_1};
194 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
195 }
196
197 {
198 std::string sidesetName("shared_surf_" + std::string("block_2") + "_" + get_topology_name("LINE_2"));
199
200 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
201 EXPECT_TRUE(nullptr != sidesetPart);
202 std::vector<const stk::mesh::Part*> goldParts{block_2};
203 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
204 }
205
206 {
207 std::string sidesetName("owned_surf");
208
209 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
210 EXPECT_TRUE(nullptr != sidesetPart);
211 std::vector<const stk::mesh::Part*> goldParts{block_2};
212 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
213 }
214
215 {
216 std::string sidesetName("owned_surf_" + std::string("block_2") + "_" + get_topology_name("LINE_2"));
217
218 stk::mesh::Part* sidesetPart = get_meta().get_part(sidesetName);
219 EXPECT_TRUE(nullptr != sidesetPart);
220 std::vector<const stk::mesh::Part*> goldParts{block_2};
221 EXPECT_EQ(goldParts, get_meta().get_blocks_touching_surface(sidesetPart));
222 }
223 }
224
225 void test_get_mesh_spec(unsigned blockCountToDist, const std::vector<unsigned>& numProcs,
226 const std::vector<std::vector<unsigned>>& expectedDist)
227 {
228 EXPECT_EQ(numProcs.size(), expectedDist.size());
229
230 for(unsigned i = 0; i < numProcs.size(); i++) {
231 unsigned procCount = numProcs[i];
232 std::vector<unsigned> procs;
233 stk::unit_test_util::get_block_proc_distribution(blockCountToDist, procCount, procs);
234
235 EXPECT_EQ(expectedDist[i].size(), procs.size());
236 for(unsigned j = 0; j < procs.size(); j++) {
237 EXPECT_EQ(expectedDist[i][j], procs[j]) << "i,j: (" << i << ", " << j << ")";
238 }
239 }
240 }
241
242 TEST(GetMeshSpecTest, TestGetMeshSpecWithMultiProc)
243 {
244 unsigned blockCountToDist = 6;
245 std::vector<unsigned> numProcs = {1,2,4,6};
246 std::vector<std::vector<unsigned>> expectedDist = { {0,0,0,0,0,0},
247 {0,0,0,1,1,1},
248 {0,0,1,1,2,3},
249 {0,1,2,3,4,5} };
250 test_get_mesh_spec(blockCountToDist, numProcs, expectedDist);
251 }
252 }