Debian Codegraph @

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

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its contributors
18 // may be used to endorse or promote products derived from this
19 // software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33
34 #include "stk_mesh/base/CreateEdges.hpp"
35 #include "stk_mesh/base/MetaData.hpp" // for MetaData
36 #include "stk_mesh/base/Part.hpp" // for Part
37 #include "stk_mesh/base/Selector.hpp" // for operator&
38 #include "stk_mesh/base/Types.hpp" // for PartVector, EntityRank
39 #include "stk_topology/topology.hpp" // for topology, etc
40 #include "stk_unit_test_utils/ioUtils.hpp"
41 #include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp"
42 #include "stk_unit_test_utils/stk_mesh_fixtures/TetFixture.hpp"
43 #include <stk_unit_test_utils/MeshFixture.hpp>
44 #include <stk_unit_test_utils/TextMesh.hpp>
45 #include "gtest/gtest.h" // for AssertHelper, EXPECT_EQ, etc
46 #include <algorithm>
47 #include <array>
48 #include <stddef.h> // for size_t
49 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
50 #include <stk_mesh/base/BulkData.hpp> // for BulkData
51 #include <stk_mesh/base/MeshBuilder.hpp>
52 #include <stk_mesh/base/Comm.hpp>
53 #include <stk_mesh/base/FEMHelpers.hpp> // for declare_element
54 #include <stk_mesh/base/GetEntities.hpp> // for count_selected_entities
55 #include <stk_mesh/base/SkinMesh.hpp> // for skin_mesh
56 #include <stk_mesh/baseImpl/MeshImplUtils.hpp>
57 #include <stk_util/parallel/ParallelReduce.hpp> // for all_reduce_sum
58
59 template <std::size_t SIZE>
60 bool check_if_one_owned_face_with_these_nodes_exists(const std::array <uint64_t, SIZE> &nodes, stk::mesh::BulkData &mesh)
61 {
62 stk::mesh::EntityVector face_vector;
63 unsigned numNodes = nodes.size();
64 stk::mesh::EntityVector node_vector(nodes.size());
65
66 for (unsigned i = 0; i < numNodes; ++i)
67 {
68 node_vector[i] = mesh.get_entity(stk::topology::NODE_RANK, nodes[i]);
69 }
70
71 stk::mesh::impl::find_entities_these_nodes_have_in_common(mesh,stk::topology::FACE_RANK,numNodes,&node_vector[0],face_vector);
72
73 // remove all non-locally owned entities
74 face_vector.erase(
75 std::remove_if(face_vector.begin(),
76 face_vector.end(),
77 [&](stk::mesh::Entity e){return !mesh.bucket(e).owned();}),
78 face_vector.end());
79
80 return face_vector.size() == 1;
81 }
82
83 void setup_node_sharing(stk::mesh::BulkData &mesh, const std::vector< std::vector<unsigned> > & shared_nodeIDs_and_procs )
84 {
85 const unsigned p_rank = mesh.parallel_rank();
86
87 for (size_t nodeIdx = 0, end = shared_nodeIDs_and_procs.size(); nodeIdx < end; ++nodeIdx) {
88 if (p_rank == shared_nodeIDs_and_procs[nodeIdx][0]) {
89 stk::mesh::EntityId nodeID = shared_nodeIDs_and_procs[nodeIdx][1];
90 int sharingProc = shared_nodeIDs_and_procs[nodeIdx][2];
91 stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, nodeID);
92 mesh.add_node_sharing(node, sharingProc);
93 }
94 }
95 }
96
97 std::shared_ptr<stk::mesh::BulkData> build_mesh(unsigned spatialDim,
98 stk::ParallelMachine comm,
99 stk::mesh::BulkData::AutomaticAuraOption auraOption)
100 {
101 stk::mesh::MeshBuilder builder(comm);
102 builder.set_spatial_dimension(spatialDim);
103 builder.set_aura_option(auraOption);
104 return builder.create();
105 }
106
107 void test_skin_mesh_with_hexes(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
108 {
109 // ID.proc
110 //
111 // 4.0------------8.0-----------12.1
112 // /| /| /|
113 // / | / | / |
114 // / | / | / |
115 // 3.0------------7.0-----------11.1 |
116 // | | | | | |
117 // | | 1.0 | | | |
118 // | | | | | |
119 // | 2.0---------|--6.0---------|-10.1
120 // | / | / | /
121 // | / | / | /
122 // |/ |/ |/
123 // 1.0------------5.0------------9.1
124
125 stk::ParallelMachine pm = MPI_COMM_WORLD;
126 int p_size = stk::parallel_machine_size(pm);
127 if(p_size > 2)
128 {
129 return;
130 }
131
132 const int spatialDim = 3;
133 std::shared_ptr<stk::mesh::BulkData> meshPtr = build_mesh(spatialDim, MPI_COMM_WORLD, autoAuraOption);
134 stk::mesh::BulkData& mesh = *meshPtr;
135 stk::mesh::MetaData& meta = mesh.mesh_meta_data();
136
137 stk::mesh::EntityRank side_rank = meta.side_rank();
138
139 stk::mesh::Part & skin_part = meta.declare_part("SkinPart", side_rank);
140 stk::mesh::Part & locally_owned = meta.locally_owned_part();
141
142 // node ordering for generated mesh is different than hand-crafted meshes for other unit tests below
143 stk::io::fill_mesh("generated:1x1x2", mesh);
144 const int p_rank = mesh.parallel_rank();
145
146 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
147 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
148
149 // skin the mesh
150 stk::mesh::PartVector add_parts(1,&skin_part);
151 stk::mesh::skin_mesh(mesh, add_parts);
152
153 stk::mesh::Selector skin = skin_part & locally_owned;
154 std::vector<size_t> counts(4);
155 counts[0] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::NODE_RANK));
156 counts[1] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::EDGE_RANK));
157 counts[2] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::FACE_RANK));
158 counts[3] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::ELEM_RANK));
159
160 // stk::io::StkMeshIoBroker stkio(pm);
161 // stkio.set_bulk_data(mesh);
162 // writeStkDebuggingFile(stkio, mesh, "hex1x1x2.exo");
163
164 if (p_rank == 0)
165 {
166 // check number of entities in skin part
167 EXPECT_EQ( p_size == 2 ? 8u : 12u, counts[stk::topology::NODE_RANK] ); // nodes
168 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
169 EXPECT_EQ( p_size == 2 ? 5u : 10u, counts[stk::topology::FACE_RANK] ); // face
170 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
171 // check boundary faces are created
172 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 2, 4, 3 }}, mesh));
173 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 5, 7, 3 }}, mesh));
174 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 3, 7, 8, 4 }}, mesh));
175 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 5, 6, 2 }}, mesh));
176 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 2, 6, 8, 4 }}, mesh));
177
178 if (p_size == 1)
179 {
180 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 11, 7 }}, mesh));
181 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 7, 11, 12, 8 }}, mesh));
182 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 9, 10, 12, 11 }}, mesh));
183 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 10, 6 }}, mesh));
184 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 6, 10, 12, 8 }}, mesh));
185 }
186 }
187 else if (p_rank == 1)
188 {
189 // check number of entities in skin part
190 EXPECT_EQ( 4u, counts[stk::topology::NODE_RANK] ); // nodes
191 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
192 EXPECT_EQ( 5u, counts[stk::topology::FACE_RANK] ); // face
193 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
194 // check boundary faces are created
195 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 11, 7 }}, mesh));
196 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 7, 11, 12, 8 }}, mesh));
197 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 9, 10, 12, 11 }}, mesh));
198 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 10, 6 }}, mesh));
199 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 6, 10, 12, 8 }}, mesh));
200 }
201 }
202
203 TEST( SkinMesh, SkinHexWithAura )
204 {
205 test_skin_mesh_with_hexes(stk::mesh::BulkData::AUTO_AURA);
206 }
207
208 TEST( SkinMesh, SkinHexWithoutAura )
209 {
210 test_skin_mesh_with_hexes(stk::mesh::BulkData::NO_AUTO_AURA);
211 }
212
213 void test_skin_mesh_with_tets(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
214 {
215 stk::ParallelMachine pm = MPI_COMM_WORLD;
216 int p_size = stk::parallel_machine_size(pm);
217 if(p_size > 2)
218 {
219 return;
220 }
221
222 const size_t NX = 1;
223 const size_t NY = 1;
224 const size_t NZ = 2;
225
226 // fixture generates six tets from NXxNYxNZ hex
227 stk::mesh::fixtures::TetFixture fixture( MPI_COMM_WORLD, NX, NY, NZ, autoAuraOption);
228
229 fixture.m_meta.commit();
230 fixture.generate_mesh();
231 const int p_rank = fixture.m_bulk_data.parallel_rank();
232
233 stk::mesh::EntityRank side_rank = fixture.m_meta.side_rank();
234
235 stk::mesh::Part & skin_part = fixture.m_meta.declare_part("SkinPart", side_rank);
236 stk::mesh::Part & locally_owned = fixture.m_meta.locally_owned_part();
237
238 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, fixture.m_bulk_data.buckets(stk::topology::NODE_RANK)) );
239 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, fixture.m_bulk_data.buckets(side_rank)) );
240
241 // skin the mesh
242 {
243 stk::mesh::PartVector add_parts(1,&skin_part);
244 stk::mesh::skin_mesh(fixture.m_bulk_data, add_parts);
245 }
246 stk::mesh::Selector skin = skin_part & locally_owned;
247 std::vector<size_t> counts(4);
248 counts[0] = stk::mesh::count_selected_entities( skin, fixture.m_bulk_data.buckets(stk::topology::NODE_RANK));
249 counts[1] = stk::mesh::count_selected_entities( skin, fixture.m_bulk_data.buckets(stk::topology::EDGE_RANK));
250 counts[2] = stk::mesh::count_selected_entities( skin, fixture.m_bulk_data.buckets(stk::topology::FACE_RANK));
251 counts[3] = stk::mesh::count_selected_entities( skin, fixture.m_bulk_data.buckets(stk::topology::ELEM_RANK));
252
253 if (0 == p_rank)
254 {
255 // check number of entities in skin part
256 EXPECT_EQ( 1 == p_size ? 12u : 8u, counts[stk::topology::NODE_RANK] ); // nodes
257 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
258 EXPECT_EQ( 1 == p_size ? 20u : 10u, counts[stk::topology::FACE_RANK] ); // face
259 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
260 // check boundary faces are created
261 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 3, 4, 8 }}, fixture.m_bulk_data));
262 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 3, 7, 8 }}, fixture.m_bulk_data));
263 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 5, 7 }}, fixture.m_bulk_data));
264 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 3, 7 }}, fixture.m_bulk_data));
265 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 5, 6 }}, fixture.m_bulk_data));
266 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 2, 6 }}, fixture.m_bulk_data));
267 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 3, 4 }}, fixture.m_bulk_data));
268 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 2, 4 }}, fixture.m_bulk_data));
269 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 2, 6, 8 }}, fixture.m_bulk_data));
270 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 2, 4, 8 }}, fixture.m_bulk_data));
271
272 if (1 == p_size) {
273 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 7, 12 }}, fixture.m_bulk_data));
274 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 7, 11 }}, fixture.m_bulk_data));
275 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 7, 11, 12 }}, fixture.m_bulk_data));
276 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 11, 9 }}, fixture.m_bulk_data));
277 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 11, 12 }}, fixture.m_bulk_data));
278 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 10, 12 }}, fixture.m_bulk_data));
279 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 10 }}, fixture.m_bulk_data));
280 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 6, 10 }}, fixture.m_bulk_data));
281 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 10, 12 }}, fixture.m_bulk_data));
282 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 8, 12 }}, fixture.m_bulk_data));
283 }
284 }
285 else if (1 == p_rank)
286 {
287 // check number of entities in skin part
288 EXPECT_EQ( 4u, counts[stk::topology::NODE_RANK] ); // nodes
289 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
290 EXPECT_EQ( 10u, counts[stk::topology::FACE_RANK] ); // face
291 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
292 // check boundary faces are created
293 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 7, 12 }}, fixture.m_bulk_data));
294 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 7, 11 }}, fixture.m_bulk_data));
295 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 7, 11, 12 }}, fixture.m_bulk_data));
296 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 11, 9 }}, fixture.m_bulk_data));
297 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 11, 12 }}, fixture.m_bulk_data));
298 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 10, 12 }}, fixture.m_bulk_data));
299 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 10 }}, fixture.m_bulk_data));
300 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 6, 10 }}, fixture.m_bulk_data));
301 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 10, 12 }}, fixture.m_bulk_data));
302 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 8, 12 }}, fixture.m_bulk_data));
303 }
304 }
305
306 TEST( SkinMesh, SkinTetWithAura )
307 {
308 test_skin_mesh_with_tets(stk::mesh::BulkData::AUTO_AURA);
309 }
310
311 TEST( SkinMesh, SkinTetWithoutAura )
312 {
313 test_skin_mesh_with_tets(stk::mesh::BulkData::NO_AUTO_AURA);
314 }
315
316 void test_skin_mesh_with_wedge(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption, bool addShells)
317 {
318 // ID.proc
319 //
320 // 3.0------------7.0-----------11.1
321 // /| /| /|
322 // / | / | / |
323 // / | / | / |
324 // 4.0------------8.0-----------12.1 |
325 // | | | | | | <-- (Undrawable transition pyramid between node (5,6,7,8,9)
326 // | | 1.0 | | | | and 4 tets contained in volume on the right)
327 // | | | | | |
328 // | 2.0---------|--6.0---------|-10.1
329 // | / | / | /
330 // | / | / | /
331 // |/ |/ |/
332 // 1.0------------5.0------------9.1
333
334 stk::ParallelMachine pm = MPI_COMM_WORLD;
335 int p_size = stk::parallel_machine_size(pm);
336
337 if(p_size > 2)
338 {
339 return;
340 }
341
342 const unsigned spatialDim = 3;
343 std::shared_ptr<stk::mesh::BulkData> meshPtr = build_mesh(spatialDim, pm, autoAuraOption);
344 stk::mesh::BulkData& mesh = *meshPtr;
345 stk::mesh::MetaData& meta = mesh.mesh_meta_data();
346 const int p_rank = mesh.parallel_rank();
347
348 stk::mesh::EntityRank side_rank = meta.side_rank();
349
350 stk::mesh::Part & skin_part = meta.declare_part("SkinPart", side_rank);
351 stk::mesh::Part & locally_owned = meta.locally_owned_part();
352
353 stk::mesh::Part * wedgePart = &meta.declare_part_with_topology("wedge_part", stk::topology::WEDGE_6);
354 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUADRILATERAL_4);
355 meta.commit();
356
357 const size_t numWedges = 4;
358 stk::mesh::EntityId elementIDsToProc[][2] =
359 {
360 { 1, 0 }, // proc 0
361 { 2, 0 }, // proc 0
362 { 3, 1 }, // proc 1
363 { 4, 1 } // proc 1
364 };
365
366 stk::mesh::EntityIdVector wedgeNodeIDs[] {
367 { 1, 5, 2, 4, 8, 3 },
368 { 2, 5, 6, 3, 8, 7 },
369 { 5, 9, 6, 8, 12, 7 },
370 { 6, 9, 10, 7, 12, 11 }
371 };
372
373 const size_t numShells = 1;
374 stk::mesh::EntityId shellIDsToProc[][2] =
375 {
376 { 5, 0 } // proc 0
377 };
378
379 stk::mesh::EntityIdVector shellNodeIDs[] {
380 { 1, 2, 3, 4 }
381 };
382
383 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
384 std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs
385 {
386 { 0, 5, 1 }, // proc 0
387 { 0, 6, 1 },
388 { 0, 7, 1 },
389 { 0, 8, 1 },
390 { 1, 5, 0 }, // proc 1
391 { 1, 6, 0 },
392 { 1, 7, 0 },
393 { 1, 8, 0 }
394 };
395
396 mesh.modification_begin();
397
398 for (size_t i = 0; i < numWedges; ++i) {
399 if ( (1 == p_size) || (elementIDsToProc[i][1] == static_cast<unsigned>(p_rank)) )
400 {
401 stk::mesh::declare_element(mesh, *wedgePart, elementIDsToProc[i][0], wedgeNodeIDs[i]);
402 }
403 }
404
405 if (addShells)
406 {
407 for (size_t i = 0; i < numShells; ++i) {
408 if ( (1 == p_size) || (shellIDsToProc[i][1] == static_cast<unsigned>(p_rank)) )
409 {
410 stk::mesh::declare_element(mesh, *shellPart, shellIDsToProc[i][0], shellNodeIDs[i]);
411 }
412 }
413 }
414
415 if (p_size > 1)
416 {
417 setup_node_sharing(mesh, shared_nodeIDs_and_procs );
418 }
419
420 mesh.modification_end();
421
422 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
423 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
424
425 stk::mesh::PartVector add_parts(1,&skin_part);
426 stk::mesh::skin_mesh(mesh, add_parts);
427
428 stk::mesh::Selector skin = skin_part & locally_owned;
429
430 std::vector<size_t> counts(4);
431 counts[0] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::NODE_RANK));
432 counts[1] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::EDGE_RANK));
433 counts[2] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::FACE_RANK));
434 counts[3] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::ELEM_RANK));
435
436 if (p_rank == 0)
437 {
438 // check number of entities
439 EXPECT_EQ( 1 == p_size ? 12u : 8u, counts[stk::topology::NODE_RANK] ); // nodes
440 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
441 EXPECT_EQ( 1 == p_size ? 14u : 7u, counts[stk::topology::FACE_RANK] ); // face
442 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
443 // check boundary faces are created
444 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 5, 8, 4 }}, mesh));
445 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 2, 3, 4 }}, mesh));
446 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 2, 6, 7, 3 }}, mesh));
447 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 2, 5 }}, mesh));
448 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 6, 2 }}, mesh));
449 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 4, 8, 3 }}, mesh));
450 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 7, 3 }}, mesh));
451
452 if (1 == p_size) {
453 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 12, 8 }}, mesh));
454 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 9, 10, 11, 12 }}, mesh));
455 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 6, 10, 11, 7 }}, mesh));
456 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 12, 7 }}, mesh));
457 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 11, 7, 12 }}, mesh));
458 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 6 }}, mesh));
459 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 6, 9 }}, mesh));
460 }
461 }
462 else if (p_rank == 1)
463 {
464 // check number of entities in skin part
465 EXPECT_EQ( 4u, counts[stk::topology::NODE_RANK] ); // nodes
466 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
467 EXPECT_EQ( 7u, counts[stk::topology::FACE_RANK] ); // face
468 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
469 // check boundary faces are created
470 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 12, 8 }}, mesh));
471 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 9, 10, 11, 12 }}, mesh));
472 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 6, 10, 11, 7 }}, mesh));
473 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 12, 7 }}, mesh));
474 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 11, 7, 12 }}, mesh));
475 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 6 }}, mesh));
476 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 6, 9 }}, mesh));
477 }
478 }
479
480 TEST( SkinMesh, SkinWedgeWithAura )
481 {
482 test_skin_mesh_with_wedge(stk::mesh::BulkData::AUTO_AURA, false);
483 }
484
485 TEST( SkinMesh, SkinWedgeWithoutAura )
486 {
487 test_skin_mesh_with_wedge(stk::mesh::BulkData::NO_AUTO_AURA, false);
488 }
489
490 TEST( SkinMesh, SkinWedgeWithAuraWithShell )
491 {
492 test_skin_mesh_with_wedge(stk::mesh::BulkData::AUTO_AURA, true);
493 }
494
495 TEST( SkinMesh, SkinWedgeWithoutAuraWithShell )
496 {
497 test_skin_mesh_with_wedge(stk::mesh::BulkData::NO_AUTO_AURA, true);
498 }
499
500 void test_skin_mesh_with_pyramid(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
501 {
502 // ID.proc
503 //
504 // 3.0------------7.0-----------11.1
505 // /| /| /|
506 // / | / | / |
507 // / | / | / |
508 // 4.0------------8.0-----------12.1 |
509 // | | | | | | <-- (Undrawable transition pyramid between node (5,6,7,8,9)
510 // | | 1.0 | | | | and 4 tets contained in volume on the right)
511 // | | | | | |
512 // | 2.0---------|--6.0---------|-10.1
513 // | / | / | /
514 // | / | / | /
515 // |/ |/ |/
516 // 1.0------------5.0------------9.1
517
518 stk::ParallelMachine pm = MPI_COMM_WORLD;
519 int p_size = stk::parallel_machine_size(pm);
520
521 if(p_size > 2)
522 {
523 return;
524 }
525
526 const unsigned spatialDim = 3;
527 std::shared_ptr<stk::mesh::BulkData> meshPtr = build_mesh(spatialDim, pm, autoAuraOption);
528 stk::mesh::BulkData& mesh = *meshPtr;
529 stk::mesh::MetaData& meta = mesh.mesh_meta_data();
530 const int p_rank = mesh.parallel_rank();
531
532 stk::mesh::EntityRank side_rank = meta.side_rank();
533
534 stk::mesh::Part & skin_part = meta.declare_part("SkinPart", side_rank);
535 stk::mesh::Part & locally_owned = meta.locally_owned_part();
536
537 stk::mesh::Part * pyramidPart = &meta.declare_part_with_topology("pyramid_part", stk::topology::PYRAMID_5);
538 meta.commit();
539
540 const size_t numPyramids = 6;
541 stk::mesh::EntityId elementIDsToProc[][2] =
542 {
543 { 1, 0 }, // proc 0
544 { 2, 0 }, // proc 0
545 { 3, 0 }, // proc 0
546 { 4, 1 }, // proc 1
547 { 5, 1 }, // proc 1
548 { 6, 1 } // proc 1
549 };
550
551 stk::mesh::EntityIdVector pyramidNodeIDs[] {
552 { 1, 4, 8, 5, 2 },
553 { 5, 8, 7, 6, 2 },
554 { 3, 7, 8, 4, 2 },
555 { 5, 8, 12, 9, 10 },
556 { 8, 7, 11, 12, 10 },
557 { 5, 6, 7, 8, 10 }
558 };
559
560 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
561 std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs
562 {
563 { 0, 5, 1 }, // proc 0
564 { 0, 6, 1 },
565 { 0, 7, 1 },
566 { 0, 8, 1 },
567 { 1, 5, 0 }, // proc 1
568 { 1, 6, 0 },
569 { 1, 7, 0 },
570 { 1, 8, 0 }
571 };
572
573 mesh.modification_begin();
574
575 for (size_t i = 0; i < numPyramids; ++i) {
576 if ( (1 == p_size) || (elementIDsToProc[i][1] == static_cast<unsigned>(p_rank)) )
577 {
578 stk::mesh::Entity element = stk::mesh::declare_element(mesh, *pyramidPart, elementIDsToProc[i][0], pyramidNodeIDs[i]);
579 ASSERT_TRUE(mesh.is_valid(element));
580 }
581 }
582
583 if (p_size > 1)
584 {
585 setup_node_sharing(mesh, shared_nodeIDs_and_procs );
586 }
587
588 mesh.modification_end();
589
590 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
591 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
592
593 stk::mesh::PartVector add_parts(1,&skin_part);
594 stk::mesh::skin_mesh(mesh, add_parts);
595
596 stk::mesh::Selector skin = skin_part & locally_owned;
597
598 std::vector<size_t> counts(4);
599 counts[0] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::NODE_RANK));
600 counts[1] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::EDGE_RANK));
601 counts[2] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::FACE_RANK));
602 counts[3] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::ELEM_RANK));
603
604 if (p_rank == 0)
605 {
606 // check number of entities
607 EXPECT_EQ( 1 == p_size ? 12u : 8u, counts[stk::topology::NODE_RANK] ); // nodes
608 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
609 EXPECT_EQ( 1 == p_size ? 16u : 8u, counts[stk::topology::FACE_RANK] ); // face
610 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
611 // check boundary faces are created
612 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 5, 8, 4 }}, mesh));
613 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 4, 8, 7, 3 }}, mesh));
614 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 2, 6, 7 }}, mesh));
615 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 2, 7, 3 }}, mesh));
616 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 2, 5 }}, mesh));
617 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 2, 5, 6 }}, mesh));
618 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 1, 2, 4 }}, mesh));
619 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 2, 3, 4 }}, mesh));
620
621 if (1 == p_size) {
622 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 12, 8 }}, mesh));
623 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 8, 12, 11, 7 }}, mesh));
624 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 10, 7 }}, mesh));
625 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 7, 11 }}, mesh));
626 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 10 }}, mesh));
627 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 10, 6 }}, mesh));
628 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 10, 12 }}, mesh));
629 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 11, 12 }}, mesh));
630 }
631 }
632 else if (p_rank == 1)
633 {
634 // check number of entities in skin part
635 EXPECT_EQ( 4u, counts[stk::topology::NODE_RANK] ); // nodes
636 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
637 EXPECT_EQ( 8u, counts[stk::topology::FACE_RANK] ); // face
638 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
639 // check boundary faces are created
640 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 5, 9, 12, 8 }}, mesh));
641 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 8, 12, 11, 7 }}, mesh));
642 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 10, 7 }}, mesh));
643 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 7, 11 }}, mesh));
644 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 10 }}, mesh));
645 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 10, 6 }}, mesh));
646 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 10, 12 }}, mesh));
647 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 11, 12 }}, mesh));
648 }
649 }
650
651 TEST( SkinMesh, SkinPyramidWithAura )
652 {
653 test_skin_mesh_with_pyramid(stk::mesh::BulkData::AUTO_AURA);
654 }
655
656 TEST( SkinMesh, SkinPyramidWithoutAura )
657 {
658 test_skin_mesh_with_pyramid(stk::mesh::BulkData::NO_AUTO_AURA);
659 }
660
661 void test_skin_hybrid_mesh(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
662 {
663 // ID.proc
664 //
665 // 3.0------------7.0-----------11.1
666 // /| /| /|
667 // / | / | / |
668 // / | / | / |
669 // 4.0------------8.0-----------12.1 |
670 // | | | | | | <-- (Undrawable transition pyramid between node (5,6,7,8,9)
671 // | | 1.0 | | | | and 4 tets contained in volume on the right)
672 // | | | | | |
673 // | 2.0---------|--6.0---------|-10.1
674 // | / | / | /
675 // | / | / | /
676 // |/ |/ |/
677 // 1.0------------5.0------------9.1
678
679 stk::ParallelMachine pm = MPI_COMM_WORLD;
680 int p_size = stk::parallel_machine_size(pm);
681
682 if(p_size > 2)
683 {
684 return;
685 }
686
687 const unsigned spatialDim = 3;
688 std::shared_ptr<stk::mesh::BulkData> meshPtr = build_mesh(spatialDim, pm, autoAuraOption);
689 stk::mesh::BulkData& mesh = *meshPtr;
690 stk::mesh::MetaData& meta = mesh.mesh_meta_data();
691 const int p_rank = mesh.parallel_rank();
692
693 stk::mesh::EntityRank side_rank = meta.side_rank();
694
695 stk::mesh::Part & skin_part = meta.declare_part("SkinPart", side_rank);
696 stk::mesh::Part & locally_owned = meta.locally_owned_part();
697
698 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
699 stk::mesh::Part * pyrPart = &meta.declare_part_with_topology("pyr_part", stk::topology::PYRAMID_5);
700 stk::mesh::Part * tetPart = &meta.declare_part_with_topology("tet_part", stk::topology::TET_4);
701 meta.commit();
702
703 const size_t numHex = 1;
704 stk::mesh::EntityIdVector hexNodeIDs[] {
705 { 1, 2, 3, 4, 5, 6, 7, 8 }
706 };
707 stk::mesh::EntityId hexElemIDs[] = { 1 };
708
709 const size_t numPyr = 1;
710 stk::mesh::EntityIdVector pyrNodeIDs[] {
711 { 5, 6, 7, 8, 9 }
712 };
713 stk::mesh::EntityId pyrElemIDs[] = { 2 };
714
715 const size_t numTet = 4;
716 stk::mesh::EntityIdVector tetNodeIDs[] {
717 { 7, 8, 9, 12 },
718 { 6, 9, 10, 7 },
719 { 7, 9, 10, 12 },
720 { 7, 12, 10, 11 }
721 };
722 stk::mesh::EntityId tetElemIDs[] = { 3, 4, 5, 6 };
723
724 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
725 std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs
726 {
727 { 0, 5, 1 }, // proc 0
728 { 0, 6, 1 },
729 { 0, 7, 1 },
730 { 0, 8, 1 },
731 { 1, 5, 0 }, // proc 1
732 { 1, 6, 0 },
733 { 1, 7, 0 },
734 { 1, 8, 0 }
735 };
736
737 mesh.modification_begin();
738
739 if (0 == p_rank) {
740 for (size_t i = 0; i < numHex; ++i) {
741 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
742 }
743 }
744 if ( (1 == p_rank) || (1 == p_size) ) { // setup the pyramids/tets for either np 2 or serial
745 for (size_t i = 0; i < numPyr; ++i) {
746 stk::mesh::declare_element(mesh, *pyrPart, pyrElemIDs[i], pyrNodeIDs[i]);
747 }
748 for (size_t i = 0; i < numTet; ++i) {
749 stk::mesh::declare_element(mesh, *tetPart, tetElemIDs[i], tetNodeIDs[i]);
750 }
751 }
752
753 if (p_size > 1)
754 {
755 setup_node_sharing(mesh, shared_nodeIDs_and_procs );
756 }
757
758 mesh.modification_end();
759
760 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
761 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
762
763 stk::mesh::PartVector add_parts(1,&skin_part);
764 stk::mesh::skin_mesh(mesh, add_parts);
765
766 stk::mesh::Selector skin = skin_part & locally_owned;
767
768 std::vector<size_t> counts(4);
769 counts[0] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::NODE_RANK));
770 counts[1] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::EDGE_RANK));
771 counts[2] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::FACE_RANK));
772 counts[3] = stk::mesh::count_selected_entities( skin, mesh.buckets(stk::topology::ELEM_RANK));
773
774 if (p_rank == 0)
775 {
776 // check number of entities
777 EXPECT_EQ( 1 == p_size ? 12u : 8u, counts[stk::topology::NODE_RANK] ); // nodes
778 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
779 EXPECT_EQ( 1 == p_size ? 15u : 5u, counts[stk::topology::FACE_RANK] ); // face
780 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
781 // check boundary faces are created
782 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 2, 3, 4 }}, mesh));
783 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 5, 8, 4 }}, mesh));
784 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 4, 8, 7, 3 }}, mesh));
785 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 1, 5, 6, 2 }}, mesh));
786 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 4 > {{ 2, 6, 7, 3 }}, mesh));
787
788 if (1 == p_size)
789 {
790 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 8 }}, mesh));
791 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 8, 12 }}, mesh));
792 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 7, 12 }}, mesh));
793 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 7, 12, 11 }}, mesh));
794 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 12, 10 }}, mesh));
795 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 12, 11 }}, mesh));
796 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 6 }}, mesh));
797 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 9, 10 }}, mesh));
798 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 10, 7 }}, mesh));
799 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 7, 10, 11 }}, mesh));
800 }
801 }
802 else if (p_rank == 1)
803 {
804 // check number of entities in skin part
805 EXPECT_EQ( 4u, counts[stk::topology::NODE_RANK] ); // nodes
806 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // edges
807 EXPECT_EQ( 10u, counts[stk::topology::FACE_RANK] ); // face
808 EXPECT_EQ( 0u, counts[stk::topology::ELEM_RANK] ); // elements
809 // check boundary faces are created
810 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 8 }}, mesh));
811 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 8, 12 }}, mesh));
812 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 8, 7, 12 }}, mesh));
813 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 7, 12, 11 }}, mesh));
814 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 9, 12, 10 }}, mesh));
815 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 10, 12, 11 }}, mesh));
816 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 5, 9, 6 }}, mesh));
817 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 9, 10 }}, mesh));
818 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 6, 10, 7 }}, mesh));
819 EXPECT_TRUE(check_if_one_owned_face_with_these_nodes_exists(std::array< uint64_t, 3 > {{ 7, 10, 11 }}, mesh));
820 }
821 }
822
823 TEST( SkinMesh, SkinHybridMeshWithAura )
824 {
825 test_skin_hybrid_mesh(stk::mesh::BulkData::AUTO_AURA);
826 }
827
828 TEST( SkinMesh, SkinHybridMeshWithoutAura )
829 {
830 test_skin_hybrid_mesh(stk::mesh::BulkData::NO_AUTO_AURA);
831 }
832
833 void move_element2_into_part(stk::mesh::BulkData& mesh, stk::mesh::EntityId element_id, stk::mesh::Part& part)
834 {
835 stk::mesh::EntityVector entities;
836 std::vector<stk::mesh::PartVector> add_parts_per_entity;
837 std::vector<stk::mesh::PartVector> remove_parts_per_entity;
838
839 stk::mesh::Entity element = mesh.get_entity(stk::topology::ELEM_RANK, element_id);
840 if ( mesh.is_valid(element) && mesh.bucket(element).owned() )
841 {
842 entities.push_back(element);
843 stk::mesh::PartVector add_parts;
844 stk::mesh::PartVector rm_parts;
845 add_parts.push_back(&part);
846 add_parts_per_entity.push_back(add_parts);
847 remove_parts_per_entity.push_back(rm_parts);
848 }
849
850 mesh.batch_change_entity_parts(entities, add_parts_per_entity, remove_parts_per_entity);
851 }
852
853 void test_2_hex_2_block(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
854 {
855 if (stk::parallel_machine_size(MPI_COMM_WORLD) <= 2)
856 {
857 const int spatialDim = 3;
858 std::shared_ptr<stk::mesh::BulkData> meshPtr = build_mesh(spatialDim, MPI_COMM_WORLD, autoAuraOption);
859 stk::mesh::BulkData& mesh = *meshPtr;
860 stk::mesh::MetaData& meta = mesh.mesh_meta_data();
861
862 stk::mesh::EntityRank side_rank = meta.side_rank();
863
864 stk::mesh::Part & skin_part = meta.declare_part("SkinPart", side_rank);
865 stk::mesh::Part & block_2 = meta.declare_part("block_2", stk::topology::FACE_RANK);
866
867 stk::io::fill_mesh("generated:1x1x2", mesh);
868
869 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
870 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
871
872 stk::mesh::EntityId element_id = 2;
873 move_element2_into_part(mesh, element_id, block_2);
874
875 stk::mesh::PartVector skin_parts;
876 skin_parts.push_back(&skin_part);
877
878 stk::mesh::skin_mesh(mesh, block_2, skin_parts);
879
880 stk::mesh::Entity element2 = mesh.get_entity(stk::topology::ELEM_RANK, element_id);
881
882 if (mesh.is_valid(element2))
883 {
884 unsigned num_faces = mesh.num_faces(element2);
885 EXPECT_EQ(5u, num_faces);
886 }
887
888 stk::mesh::Entity element1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
889
890 // with correct face connection behavior, shouldn't this be 1 for num_faces?
891 if (mesh.is_valid(element1))
892 {
893 unsigned num_faces = mesh.num_faces(element1);
894 EXPECT_EQ(0u, num_faces);
895 }
896 }
897 }
898
899 TEST( SkinMesh, test_2_hex_2_block_with_aura)
900 {
901 test_2_hex_2_block(stk::mesh::BulkData::AUTO_AURA);
902 }
903
904 TEST( SkinMesh, test_2_hex_2_block_without_aura)
905 {
906 test_2_hex_2_block(stk::mesh::BulkData::NO_AUTO_AURA);
907 }
908
909 void test_2_hex_2_block_with_second_selector(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
910 {
911 if (stk::parallel_machine_size(MPI_COMM_WORLD) < 2)
912 {
913 const int spatialDim = 3;
914 std::shared_ptr<stk::mesh::BulkData> meshPtr = build_mesh(spatialDim, MPI_COMM_WORLD, autoAuraOption);
915 stk::mesh::BulkData& mesh = *meshPtr;
916 stk::mesh::MetaData& meta = mesh.mesh_meta_data();
917
918 stk::mesh::EntityRank side_rank = meta.side_rank();
919
920 stk::mesh::Part & skin_part = meta.declare_part("SkinPart", side_rank);
921 stk::mesh::Part & block_2 = meta.declare_part("block_2", stk::topology::FACE_RANK);
922
923 stk::io::fill_mesh("generated:1x1x2", mesh);
924
925 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
926 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
927
928 stk::mesh::EntityId element_id = 2;
929 move_element2_into_part(mesh, element_id, block_2);
930
931 stk::mesh::PartVector skin_parts;
932 skin_parts.push_back(&skin_part);
933
934 stk::mesh::Selector block_1_becomes_air(!stk::mesh::Selector(*meta.get_part("block_1")));
935 stk::mesh::skin_mesh(mesh, block_2, skin_parts, &block_1_becomes_air);
936
937 stk::mesh::Entity element2 = mesh.get_entity(stk::topology::ELEM_RANK, element_id);
938
939 if (mesh.is_valid(element2))
940 {
941 unsigned num_faces = mesh.num_faces(element2);
942 EXPECT_EQ(6u, num_faces);
943 }
944
945 stk::mesh::Entity element1 = mesh.get_entity(stk::topology::ELEM_RANK, 1);
946
947 if (mesh.is_valid(element1))
948 {
949 unsigned num_faces = mesh.num_faces(element1);
950 EXPECT_EQ(0u, num_faces); // should be 1 once corrected
951 }
952 }
953 }
954
955 TEST( SkinMesh, test_2_hex_2_block_with_second_selector_with_aura)
956 {
957 test_2_hex_2_block_with_second_selector(stk::mesh::BulkData::AUTO_AURA);
958 }
959
960 TEST( SkinMesh, test_2_hex_2_block_with_second_selector_without_aura)
961 {
962 test_2_hex_2_block_with_second_selector(stk::mesh::BulkData::NO_AUTO_AURA);
963 }
964
965 void test_quad_2D_skin_with_aura_option (bool auraOn)
966 {
967 const unsigned X = 5, Y = 5;
968 stk::mesh::fixtures::QuadFixture fixture(MPI_COMM_WORLD, X, Y, auraOn);
969
970 stk::mesh::EntityRank side_rank = fixture.m_meta.side_rank();
971
972 stk::mesh::Part & skin_part = fixture.m_meta.declare_part("SkinPart", side_rank);
973 stk::mesh::Part & skin_part_2 = fixture.m_meta.declare_part("SkinPart_2", side_rank);
974 stk::mesh::Part & locally_owned = fixture.m_meta.locally_owned_part();
975
976 fixture.m_meta.commit();
977
978 fixture.generate_mesh();
979
980 stk::mesh::BulkData & mesh = fixture.m_bulk_data;
981
982 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(stk::topology::NODE_RANK)) );
983 ASSERT_EQ( 0u, stk::mesh::count_selected_entities( skin_part, mesh.buckets(side_rank)) );
984
985 stk::mesh::create_edges(mesh);
986
987 {
988 size_t local_counts[2] = {}, global_counts[2] = {};
989 local_counts[0] = stk::mesh::count_selected_entities( skin_part & locally_owned, mesh.buckets(stk::topology::NODE_RANK));
990 local_counts[1] = stk::mesh::count_selected_entities( skin_part & locally_owned, mesh.buckets(side_rank));
991
992 stk::all_reduce_sum( mesh.parallel(), local_counts, global_counts, 2);
993
994 EXPECT_EQ( 0u, global_counts[0] );
995 EXPECT_EQ( 0u, global_counts[1] );
996 }
997
998 // skin the mesh
999 {
1000 stk::mesh::PartVector add_parts(1,&skin_part);
1001 stk::mesh::skin_mesh(mesh, add_parts);
1002 }
1003
1004 {
1005 size_t local_counts[2] = {}, global_counts[2] = {};
1006 local_counts[0] = stk::mesh::count_selected_entities( skin_part & locally_owned, mesh.buckets(stk::topology::NODE_RANK));
1007 local_counts[1] = stk::mesh::count_selected_entities( skin_part & locally_owned, mesh.buckets(side_rank));
1008
1009 stk::all_reduce_sum( mesh.parallel(), local_counts, global_counts, 2);
1010
1011 EXPECT_EQ( 20u, global_counts[0] );
1012 EXPECT_EQ( 20u, global_counts[1] );
1013 }
1014
1015 // trying skinning the mesh again but put skin into part 2
1016 // skin the mesh
1017 {
1018 stk::mesh::PartVector add_parts(1,&skin_part_2);
1019 stk::mesh::skin_mesh(mesh, add_parts);
1020 }
1021
1022 {
1023 size_t local_counts[2] = {}, global_counts[2] = {};
1024 local_counts[0] = stk::mesh::count_selected_entities( skin_part_2 & locally_owned, mesh.buckets(stk::topology::NODE_RANK));
1025 local_counts[1] = stk::mesh::count_selected_entities( skin_part_2 & locally_owned, mesh.buckets(side_rank));
1026
1027 stk::all_reduce_sum( mesh.parallel(), local_counts, global_counts, 2);
1028
1029 EXPECT_EQ( 20u, global_counts[0] );
1030 EXPECT_EQ( 20u, global_counts[1] );
1031 }
1032 }
1033
1034 TEST( SkinMesh, SimpleQuad)
1035 {
1036 test_quad_2D_skin_with_aura_option(true);
1037 test_quad_2D_skin_with_aura_option(false);
1038 }
1039
1040 class TextSkinMesh : public stk::unit_test_util::MeshFixture
1041 {
1042 public:
1043 void setup_three_wedges_2p()
1044 {
1045 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
1046 STK_ThrowRequire(get_bulk().parallel_size() == 2);
1047
1048 const std::string meshDesc = "0,1,WEDGE_6,1,2,4,6,7,9\n"
1049 "0,2,WEDGE_6,4,2,5,9,7,10\n"
1050 "1,3,WEDGE_6,2,3,5,7,8,10";
1051
1052 std::vector<double> coordinates = {
1053 0,0,0, 1,0,0, 2,0,0, 0,1,0, 1,1,0,
1054 0,0,1, 1,0,1, 2,0,1, 0,1,1, 1,1,1,
1055 };
1056
1057 stk::unit_test_util::setup_text_mesh(
1058 get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coordinates));
1059 }
1060
1061 void setup_three_wedges_with_sideset_2p()
1062 {
1063 setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA);
1064 STK_ThrowRequire(get_bulk().parallel_size() == 2);
1065
1066 const std::string meshDesc = "0,1,WEDGE_6,1,2,4,6,7,9\n"
1067 "0,2,WEDGE_6,4,2,5,9,7,10\n"
1068 "1,3,WEDGE_6,2,3,5,7,8,10|sideset:name=surface_1; data=1,5, 2,5, 3,5";
1069
1070 std::vector<double> coordinates = {
1071 0,0,0, 1,0,0, 2,0,0, 0,1,0, 1,1,0,
1072 0,0,1, 1,0,1, 2,0,1, 0,1,1, 1,1,1,
1073 };
1074
1075 stk::unit_test_util::setup_text_mesh(
1076 get_bulk(), stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coordinates));
1077 }
1078 };
1079
1080 TEST_F(TextSkinMesh, wedgesWithAura)
1081 {
1082 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) return;
1083
1084 setup_three_wedges_2p();
1085
1086 stk::mesh::skin_mesh(get_bulk());
1087
1088 std::vector<size_t> globalCounts;
1089 stk::mesh::comm_mesh_counts(get_bulk(), globalCounts);
1090
1091 EXPECT_EQ(globalCounts[get_meta().side_rank()], 11u);
1092 }
1093
1094 TEST_F(TextSkinMesh, wedgesWithAuraAndSideset)
1095 {
1096 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) return;
1097
1098 setup_three_wedges_with_sideset_2p();
1099
1100 stk::mesh::skin_mesh(get_bulk());
1101
1102 std::vector<size_t> globalCounts;
1103 stk::mesh::comm_mesh_counts(get_bulk(), globalCounts);
1104
1105 EXPECT_EQ(globalCounts[get_meta().side_rank()], 11u);
1106 }
1107
1108