Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestCreateFaces.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 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc
36 #include <stddef.h> // for size_t
37 #include <ostream> // for basic_ostream::operator<<
38 #include <stk_mesh/base/BulkData.hpp> // for BulkData, etc
39 #include <stk_mesh/base/Comm.hpp> // for comm_mesh_counts
40 #include <stk_mesh/base/CreateFaces.hpp> // for create_faces
41 #include <stk_mesh/base/MetaData.hpp> // for MetaData, put_field
42 #include <stk_util/parallel/Parallel.hpp> // for parallel_machine_size
43 #include <vector> // for vector, vector<>::iterator
44 #include "mpi.h" // for MPI_COMM_WORLD
45
46 #include "stk_mesh/base/Bucket.hpp" // for Bucket
47 #include "stk_mesh/base/Entity.hpp" // for Entity
48 #include "stk_mesh/base/Field.hpp" // for Field
49 #include "stk_mesh/base/Part.hpp" // for Part
50 #include "stk_mesh/base/Selector.hpp" // for Selector, operator&, etc
51 #include "stk_mesh/base/Types.hpp" // for BucketVector, EntityRank
52 #include "stk_topology/topology.hpp" // for topology, etc
53 #include "stk_unit_test_utils/stk_mesh_fixtures/GearsFixture.hpp" // for GearsFixture, etc
54 #include "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp" // for HexFixture
55 #include "stk_unit_test_utils/stk_mesh_fixtures/TetFixture.hpp" // for TetFixture
56 #include "stk_unit_test_utils/stk_mesh_fixtures/degenerate_mesh.hpp"
57 #include "stk_unit_test_utils/stk_mesh_fixtures/heterogeneous_mesh.hpp"
58 #include "stk_unit_test_utils/BuildMesh.hpp"
59
60 using stk::mesh::MetaData;
61 using stk::unit_test_util::build_mesh;
62
63 namespace {
64 const stk::mesh::EntityRank elem_rank = stk::topology::ELEMENT_RANK;
65 const stk::mesh::EntityRank face_rank = stk::topology::FACE_RANK;
66 const stk::mesh::EntityRank edge_rank = stk::topology::EDGE_RANK;
67 const stk::mesh::EntityRank node_rank = stk::topology::NODE_RANK;
68
69 const size_t nodes_per_hex = 8;
70 const size_t faces_per_hex = 6;
71 const size_t nodes_per_quad= 4;
72
73 const size_t nodes_per_tet = 4;
74 const size_t faces_per_tet = 4;
75 const size_t nodes_per_tri = 3;
76
77 size_t exp_hex_face_count(size_t nx, size_t ny, size_t nz)
78 {
79 size_t exp_face = 3 * nx * ny * nz;
80 exp_face += ny * nz + nz * nx + nx * ny;
81 return exp_face;
82 }
83
84 size_t exp_tet_face_count(size_t nx, size_t ny, size_t nz)
85 {
86 size_t exp_face = 12 * nx * ny * nz;
87 exp_face += 2* (ny * nz + nz * nx + nx * ny);
88 return exp_face;
89 }
90
91 size_t exp_node_count(size_t nx, size_t ny, size_t nz)
92 {
93 size_t exp_node = (nx+1) * (ny+1) * (nz+1);
94 return exp_node;
95 }
96
97 size_t exp_hex_count(size_t nx, size_t ny, size_t nz)
98 {
99 size_t exp_elem = nx * ny * nz;
100 return exp_elem;
101 }
102
103 size_t exp_tet_count(size_t nx, size_t ny, size_t nz)
104 {
105 size_t exp_elem = 6 * nx * ny * nz;
106 return exp_elem;
107 }
108
109
110 TEST ( UnitTestCreateFaces, Hex_2x1x1 )
111 {
112 const size_t NX = 2;
113 const size_t NY = 1;
114 const size_t NZ = 1;
115
116 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(MPI_COMM_WORLD);
117 stk::mesh::fixtures::HexFixture::fill_mesh(NX, NY, NZ, *bulkPtr);
118
119 {
120 std::vector<size_t> counts ;
121 stk::mesh::comm_mesh_counts( *bulkPtr , counts);
122
123 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
124 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
125 EXPECT_EQ( 0u, counts[face_rank] ); // faces
126 EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements
127 }
128
129 stk::mesh::create_faces(*bulkPtr);
130
131 {
132 std::vector<size_t> counts ;
133 stk::mesh::comm_mesh_counts( *bulkPtr , counts);
134
135 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
136 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
137 EXPECT_EQ( exp_hex_face_count(NX, NY, NZ), counts[face_rank] ); // faces
138 EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements
139 }
140
141 }
142
143 TEST ( UnitTestCreateFaces, Tet_2x1x1 )
144 {
145 const size_t NX = 2;
146 const size_t NY = 1;
147 const size_t NZ = 1;
148
149 stk::mesh::fixtures::TetFixture fixture( MPI_COMM_WORLD, NX, NY, NZ);
150
151 fixture.m_meta.commit();
152 fixture.generate_mesh();
153
154 {
155 std::vector<size_t> counts ;
156 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
157
158 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
159 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
160 EXPECT_EQ( 0u, counts[face_rank] ); // faces
161 EXPECT_EQ( exp_tet_count(NX, NY, NZ), counts[elem_rank] ); // elements
162 }
163
164 stk::mesh::create_faces(fixture.m_bulk_data);
165
166 {
167 std::vector<size_t> counts ;
168 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
169
170 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
171 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
172 EXPECT_EQ( exp_tet_face_count(NX, NY, NZ), counts[face_rank] ); // faces
173 EXPECT_EQ( exp_tet_count(NX, NY, NZ), counts[elem_rank] ); // elements
174 }
175
176 }
177
178 TEST( UnitTestCreateFaces , Hex_3x1x1 )
179 {
180 const size_t NX = 3;
181 const size_t NY = 1;
182 const size_t NZ = 1;
183
184 stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, NX, NY, NZ);
185
186 fixture.m_meta.commit();
187 fixture.generate_mesh();
188
189 {
190 std::vector<size_t> counts ;
191 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
192
193 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
194 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
195 EXPECT_EQ( 0u, counts[face_rank] ); // faces
196 EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements
197 }
198
199 stk::mesh::create_faces(fixture.m_bulk_data);
200
201 {
202 std::vector<size_t> counts ;
203 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
204
205 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
206 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
207 EXPECT_EQ( exp_hex_face_count(NX, NY, NZ), counts[face_rank] ); // faces
208 EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements
209 }
210 }
211
212 TEST( UnitTestCreateFaces , Tet_3x1x1 )
213 {
214 const size_t NX = 3;
215 const size_t NY = 1;
216 const size_t NZ = 1;
217
218 stk::mesh::fixtures::TetFixture fixture( MPI_COMM_WORLD, NX, NY, NZ);
219
220 fixture.m_meta.commit();
221 fixture.generate_mesh();
222
223 {
224 std::vector<size_t> counts ;
225 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
226
227 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
228 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
229 EXPECT_EQ( 0u, counts[face_rank] ); // faces
230 EXPECT_EQ( exp_tet_count(NX, NY, NZ), counts[elem_rank] ); // elements
231 }
232
233 stk::mesh::create_faces(fixture.m_bulk_data);
234
235 {
236 std::vector<size_t> counts ;
237 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
238
239 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
240 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
241 EXPECT_EQ( exp_tet_face_count(NX, NY, NZ), counts[face_rank] ); // faces
242 EXPECT_EQ( exp_tet_count(NX, NY, NZ), counts[elem_rank] ); // elements
243 }
244 }
245
246 TEST( UnitTestCreateFaces , testCreateFaces3x3x3 )
247 {
248 const size_t NX = 3;
249 const size_t NY = 3;
250 const size_t NZ = 3;
251
252 stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, NX, NY, NZ);
253
254 fixture.m_meta.commit();
255 fixture.generate_mesh();
256
257 {
258 std::vector<size_t> counts ;
259 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
260
261 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
262 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
263 EXPECT_EQ( 0u, counts[face_rank] ); // faces
264 EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements
265 }
266
267 stk::mesh::create_faces(fixture.m_bulk_data);
268
269 {
270 std::vector<size_t> counts ;
271 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
272
273 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
274 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
275 EXPECT_EQ( exp_hex_face_count(NX, NY, NZ), counts[face_rank] ); // faces
276 EXPECT_EQ( exp_hex_count(NX, NY, NZ), counts[elem_rank] ); // elements
277 }
278
279 stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank);
280 for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin();
281 b_itr != elem_buckets.end();
282 ++b_itr
283 )
284 {
285 stk::mesh::Bucket & b = **b_itr;
286 for ( size_t i = 0; i< b.size(); ++i) {
287 EXPECT_EQ( faces_per_hex, b.num_faces(i) );
288 EXPECT_EQ( 0u, b.num_edges(i) );
289 EXPECT_EQ( nodes_per_hex, b.num_nodes(i) );
290 }
291 }
292
293 stk::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank);
294 for ( stk::mesh::BucketVector::iterator b_itr = face_buckets.begin();
295 b_itr != face_buckets.end();
296 ++b_itr
297 )
298 {
299 stk::mesh::Bucket & b = **b_itr;
300 for ( size_t i = 0; i< b.size(); ++i) {
301 EXPECT_EQ( 0u, b.num_edges(i) );
302 EXPECT_EQ( nodes_per_quad, b.num_nodes(i) );
303 }
304 }
305
306 unsigned num_ghosted_faces = 0;
307
308 stk::mesh::Selector ghosted_part = fixture.m_meta.universal_part() &
309 !(fixture.m_meta.locally_owned_part() | fixture.m_meta.globally_shared_part());
310
311 stk::mesh::BucketVector ghosted_elem_buckets = fixture.m_bulk_data.get_buckets(elem_rank,ghosted_part);
312
313 for ( stk::mesh::BucketVector::iterator b_itr = ghosted_elem_buckets.begin();
314 b_itr != ghosted_elem_buckets.end();
315 ++b_itr
316 )
317 {
318 stk::mesh::Bucket & b = **b_itr;
319 for ( size_t i = 0; i< b.size(); ++i) {
320 const stk::mesh::Entity & elem = b[i];
321
322 const unsigned num_faces = fixture.m_bulk_data.num_faces(elem);
323 EXPECT_EQ(faces_per_hex, num_faces);
324
325 const stk::mesh::Entity * faces = fixture.m_bulk_data.begin_faces(elem);
326 unsigned elem_num_ghosted_faces = 0;
327 unsigned elem_num_shared_faces = 0;
328
329 const int my_proc_id = fixture.m_bulk_data.parallel_rank();
330
331 for (unsigned k = 0; k < num_faces; ++k)
332 {
333 const stk::mesh::Entity & face = faces[k];
334
335 const bool is_ghosted = fixture.m_bulk_data.in_receive_ghost(fixture.m_bulk_data.entity_key(face));
336 if (is_ghosted)
337 {
338 elem_num_ghosted_faces += 1;
339 const int face_owner = fixture.m_bulk_data.parallel_owner_rank(face);
340 EXPECT_NE(face_owner, my_proc_id);
341 }
342
343 const bool is_shared = fixture.m_bulk_data.in_shared(fixture.m_bulk_data.entity_key(face));
344 if (is_shared) elem_num_shared_faces += 1;
345
346 const bool is_ghosted_or_shared = is_ghosted || is_shared;
347 ASSERT_TRUE(is_ghosted_or_shared);
348
349 }
350
351 EXPECT_LE(1u, elem_num_ghosted_faces);
352 num_ghosted_faces += elem_num_ghosted_faces;
353
354 const unsigned shared_and_ghosted = elem_num_shared_faces + elem_num_ghosted_faces;
355 EXPECT_EQ(faces_per_hex, shared_and_ghosted);
356 }
357 }
358
359 if (fixture.m_bulk_data.parallel_size() > 1)
360 {
361 EXPECT_LE(1u, num_ghosted_faces);
362 }
363 }
364
365 TEST( UnitTestCreateFaces , testCreateTetFaces3x3x3 )
366 {
367 const size_t NX = 3;
368 const size_t NY = 3;
369 const size_t NZ = 3;
370
371 stk::mesh::fixtures::TetFixture fixture( MPI_COMM_WORLD, NX, NY, NZ);
372
373 fixture.m_meta.commit();
374 fixture.generate_mesh();
375
376 {
377 std::vector<size_t> counts ;
378 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
379
380 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
381 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
382 EXPECT_EQ( 0u, counts[face_rank] ); // faces
383 EXPECT_EQ( exp_tet_count(NX, NY, NZ), counts[elem_rank] ); // elements
384 }
385
386 stk::mesh::create_faces(fixture.m_bulk_data);
387
388 {
389 std::vector<size_t> counts ;
390 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
391
392 EXPECT_EQ( exp_node_count(NX, NY, NZ), counts[node_rank] ); // nodes
393 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
394 EXPECT_EQ( exp_tet_face_count(NX, NY, NZ), counts[face_rank] ); // faces
395 EXPECT_EQ( exp_tet_count(NX, NY, NZ), counts[elem_rank] ); // elements
396 }
397
398 stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank);
399 for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin();
400 b_itr != elem_buckets.end();
401 ++b_itr
402 )
403 {
404 stk::mesh::Bucket & b = **b_itr;
405 for ( size_t i = 0; i< b.size(); ++i) {
406 EXPECT_EQ( faces_per_tet, b.num_faces(i) );
407 EXPECT_EQ( 0u, b.num_edges(i) );
408 EXPECT_EQ( nodes_per_tet, b.num_nodes(i) );
409 }
410 }
411
412 stk::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank);
413 for ( stk::mesh::BucketVector::iterator b_itr = face_buckets.begin();
414 b_itr != face_buckets.end();
415 ++b_itr
416 )
417 {
418 stk::mesh::Bucket & b = **b_itr;
419 for ( size_t i = 0; i< b.size(); ++i) {
420 EXPECT_EQ( 0u, b.num_edges(i) );
421 EXPECT_EQ( nodes_per_tri, b.num_nodes(i) );
422 }
423 }
424
425 unsigned num_ghosted_faces = 0;
426
427 stk::mesh::Selector ghosted_part = fixture.m_meta.universal_part() &
428 !(fixture.m_meta.locally_owned_part() | fixture.m_meta.globally_shared_part());
429
430 stk::mesh::BucketVector ghosted_elem_buckets = fixture.m_bulk_data.get_buckets(elem_rank,ghosted_part);
431
432 for ( stk::mesh::BucketVector::iterator b_itr = ghosted_elem_buckets.begin();
433 b_itr != ghosted_elem_buckets.end();
434 ++b_itr
435 )
436 {
437 stk::mesh::Bucket & b = **b_itr;
438 for ( size_t i = 0; i< b.size(); ++i) {
439 const stk::mesh::Entity & elem = b[i];
440
441 const unsigned num_faces = fixture.m_bulk_data.num_faces(elem);
442 EXPECT_EQ(faces_per_tet, num_faces);
443
444 const stk::mesh::Entity * faces = fixture.m_bulk_data.begin_faces(elem);
445 unsigned elem_num_ghosted_faces = 0;
446 unsigned elem_num_shared_faces = 0;
447
448 const int my_proc_id = fixture.m_bulk_data.parallel_rank();
449
450 for (unsigned k = 0; k < num_faces; ++k)
451 {
452 const stk::mesh::Entity & face = faces[k];
453
454 const bool is_ghosted = fixture.m_bulk_data.in_receive_ghost(fixture.m_bulk_data.entity_key(face));
455 if (is_ghosted)
456 {
457 elem_num_ghosted_faces += 1;
458 const int face_owner = fixture.m_bulk_data.parallel_owner_rank(face);
459 EXPECT_NE(face_owner, my_proc_id);
460 }
461
462 const bool is_shared = fixture.m_bulk_data.in_shared(fixture.m_bulk_data.entity_key(face));
463 if (is_shared) elem_num_shared_faces += 1;
464
465 const bool is_ghosted_or_shared = is_ghosted || is_shared;
466 ASSERT_TRUE(is_ghosted_or_shared);
467
468 }
469
470 EXPECT_LE(1u, elem_num_ghosted_faces);
471 num_ghosted_faces += elem_num_ghosted_faces;
472
473 const unsigned shared_and_ghosted = elem_num_shared_faces + elem_num_ghosted_faces;
474 EXPECT_EQ(faces_per_tet, shared_and_ghosted);
475 }
476 }
477
478 if (fixture.m_bulk_data.parallel_size() > 1)
479 {
480 EXPECT_LE(1u, num_ghosted_faces);
481 }
482 }
483
484 TEST ( UnitTestCreateFaces, Gears )
485 {
486 stk::mesh::fixtures::GearsFixture fixture( MPI_COMM_WORLD, 1,
487 stk::mesh::fixtures::GearParams(0.1, 0.4, 1.0, -0.4, 0.4));
488
489 fixture.meta_data.commit();
490 fixture.generate_mesh();
491
492 {
493 std::vector<size_t> counts ;
494 stk::mesh::comm_mesh_counts( fixture.bulk_data , counts);
495
496 EXPECT_EQ( 4340u, counts[node_rank] ); // nodes
497 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
498 EXPECT_EQ( 0u, counts[face_rank] ); // faces
499 EXPECT_EQ( 3348u, counts[elem_rank] ); // elements
500 }
501
502 stk::mesh::create_faces(fixture.bulk_data);
503
504 {
505 std::vector<size_t> counts ;
506 stk::mesh::comm_mesh_counts( fixture.bulk_data , counts);
507
508 EXPECT_EQ( 4340u, counts[node_rank] ); // nodes
509 EXPECT_EQ( 0u , counts[edge_rank] ); // edges
510 EXPECT_EQ( 10974u, counts[face_rank] ); // faces
511 EXPECT_EQ( 3348u, counts[elem_rank] ); // elements
512 }
513
514 }
515
516 void heterogeneous_create_faces_test(stk::mesh::BulkData::AutomaticAuraOption autoAuraOption)
517 {
518 int numprocs = stk::parallel_machine_size(MPI_COMM_WORLD);
519 if (numprocs > 1)
520 return;
521
522 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_WORLD, autoAuraOption);
523 stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data();
524 stk::mesh::BulkData& bulk_data = *bulkPtr;
525 stk::mesh::fixtures::VectorFieldType & node_coord =
526 meta_data.declare_field<double>(stk::topology::NODE_RANK, "coordinates");
527 stk::mesh::put_field_on_mesh( node_coord , meta_data.universal_part() , 3, nullptr);
528
529 stk::mesh::fixtures::heterogeneous_mesh_meta_data( meta_data , node_coord );
530 meta_data.commit();
531
532 stk::mesh::fixtures::heterogeneous_mesh_bulk_data( bulk_data , node_coord );
533
534 /*
535 * Three hexes, three wedges, three tets, two pyramids,
536 * three quad shells, and three triangle shells.
537 *
538 * Z = 0 plane:
539 *
540 * Y
541 * ^ 9 10
542 * ! *-------*
543 * ! / \ / \
544 * ! / \ / \
545 * / \ / \
546 * *-------*-------*-------*
547 * 5| 6| 7| 8|
548 * | | | |
549 * | | | |
550 * *-------*-------*-------* ----> X
551 * 1 2 3 4
552 *
553 * Z = -1 plane:
554 *
555 * Y
556 * ^ 19 20
557 * ! *-------*
558 * ! / \ / \
559 * ! / \ / \
560 * / \ / \
561 * *-------*-------*-------*
562 * 15| 16| 17| 18|
563 * | | | |
564 * | | | |
565 * *-------*-------*-------* ----> X
566 * 11 12 13 14
567 *
568 *
569 * Last node (#21) at Z = -2, translated from node #16
570 */
571
572 /*
573 * Total elements = 21 = 3 + 3 + 3 + 2 + 3 + 3
574 * Total faces = 45 = 6 front + 6 back + 9 perimeter + 6 internal + 7 from tet + 5 from pyr + 6 from extra (2sided) shells
575 */
576 {
577 std::vector<size_t> counts ;
578 stk::mesh::comm_mesh_counts(bulk_data , counts);
579
580 EXPECT_EQ( 21u, counts[node_rank] ); // nodes
581 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
582 EXPECT_EQ( 0u, counts[face_rank] ); // faces
583 EXPECT_EQ( 17u, counts[elem_rank] ); // elements
584 }
585
586 stk::mesh::create_faces(bulk_data);
587
588 {
589 std::vector<size_t> counts ;
590 stk::mesh::comm_mesh_counts(bulk_data , counts);
591
592 EXPECT_EQ( 21u, counts[node_rank] ); // nodes
593 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
594 EXPECT_EQ( 45u, counts[face_rank] ); // faces
595 EXPECT_EQ( 17u, counts[elem_rank] ); // elements
596 }
597 }
598
599 TEST ( UnitTestCreateFaces, HeterogeneousWithAura )
600 {
601 heterogeneous_create_faces_test(stk::mesh::BulkData::AUTO_AURA );
602 }
603
604 TEST ( UnitTestCreateFaces, HeterogeneousNoAura )
605 {
606 heterogeneous_create_faces_test(stk::mesh::BulkData::NO_AUTO_AURA );
607 }
608
609 TEST ( UnitTestCreateFaces, Degenerate )
610 {
611 int numprocs = stk::parallel_machine_size(MPI_COMM_WORLD);
612 if (numprocs > 1)
613 return;
614
615 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_WORLD);
616 stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data();
617 stk::mesh::BulkData& bulk_data = *bulkPtr;
618 stk::mesh::fixtures::VectorFieldType & node_coord =
619 meta_data.declare_field<double>(stk::topology::NODE_RANK, "coordinates");
620 stk::mesh::put_field_on_mesh( node_coord , meta_data.universal_part() , 3, nullptr);
621
622 stk::mesh::fixtures::degenerate_mesh_meta_data( meta_data , node_coord );
623 meta_data.commit();
624
625 stk::mesh::fixtures::degenerate_mesh_bulk_data( bulk_data , node_coord );
626
627 /*
628 * Z = 0 plane:
629 *
630 * Y
631 * ^
632 * !
633 *
634 * 4* *5
635 * |\ /|
636 * | \ / |
637 * | \ / |
638 * *---*---* ----> X
639 * 1 2 3
640 *
641 * Z = -1 plane:
642 *
643 * Y
644 * ^
645 * !
646 *
647 * 9* *10
648 * |\ /|
649 * | \ / |
650 * | \ / |
651 * *---*---* ----> X
652 * 6 7 8
653 *
654 * Total elements = 2 hexes
655 * Total faces = 11 = 2 front + 2 back + 6 perimeter + 1 internal degenerate
656 */
657 {
658 std::vector<size_t> counts ;
659 stk::mesh::comm_mesh_counts(bulk_data , counts);
660
661 EXPECT_EQ(10u, counts[node_rank] ); // nodes
662 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
663 EXPECT_EQ( 0u, counts[face_rank] ); // faces
664 EXPECT_EQ( 2u, counts[elem_rank] ); // elements
665 }
666
667 stk::mesh::create_faces(bulk_data);
668
669 {
670 std::vector<size_t> counts ;
671 stk::mesh::comm_mesh_counts(bulk_data , counts);
672
673 EXPECT_EQ(10u, counts[node_rank] ); // nodes
674 EXPECT_EQ( 0u, counts[edge_rank] ); // edges
675 EXPECT_EQ(11u, counts[face_rank] ); // faces
676 EXPECT_EQ( 2u, counts[elem_rank] ); // elements
677 }
678 }
679
680 } //end empty namespace
681