Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestCreateEdges.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 "Setup2Block2HexMesh.hpp" // for setup2Block2HexMesh
36 #include "mpi.h" // for MPI_COMM_WORLD, etc
37 #include "stk_mesh/base/Bucket.hpp" // for Bucket
38 #include "stk_mesh/base/Entity.hpp" // for Entity
39 #include "stk_mesh/base/FEMHelpers.hpp" // for declare_element
40 #include "stk_mesh/base/Part.hpp" // for Part
41 #include "stk_mesh/base/Selector.hpp" // for operator!, Selector
42 #include "stk_mesh/base/Types.hpp" // for BucketVector, EntityId, etc
43 #include "stk_topology/topology.hpp" // for topology, etc
44 #include "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp" // for HexFixture
45 #include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture
46 #include "stk_unit_test_utils/BuildMesh.hpp"
47 #include "stk_util/parallel/Parallel.hpp" // for parallel_machine_size, etc
48 #include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc
49 #include <stddef.h> // for size_t
50 #include <stk_mesh/base/BulkData.hpp> // for BulkData
51 #include <stk_mesh/base/Comm.hpp> // for comm_mesh_counts
52 #include <stk_mesh/base/CreateEdges.hpp> // for create_edges
53 #include <stk_mesh/base/CreateFaces.hpp> // for create_faces
54 #include <stk_mesh/base/GetEntities.hpp> // for count_selected_entities
55 #include <stk_mesh/base/MetaData.hpp> // for MetaData
56 #include <stk_unit_test_utils/BulkDataTester.hpp>
57 #include <stk_unit_test_utils/StkMeshFromGeneratedMesh.hpp>
58 #include <stk_unit_test_utils/BuildMesh.hpp>
59 #include <string> // for string
60 #include <vector> // for vector, vector<>::iterator
61
62 using stk::mesh::MetaData;
63 using stk::unit_test_util::build_mesh;
64
65 TEST ( UnitTestCreateEdges, Quad_2x1 )
66 {
67 stk::mesh::fixtures::QuadFixture fixture( MPI_COMM_WORLD, 2, 1);
68
69 fixture.m_meta.commit();
70 fixture.generate_mesh();
71
72 {
73 std::vector<size_t> counts ;
74 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
75
76 EXPECT_EQ( counts[0] , 6u ); // nodes
77 EXPECT_EQ( counts[1] , 0u ); // edges
78 EXPECT_EQ( counts[2] , 0u ); // faces
79 EXPECT_EQ( counts[3] , 2u ); // elements
80 }
81
82 stk::mesh::create_edges(fixture.m_bulk_data);
83
84 {
85 std::vector<size_t> counts ;
86 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
87
88 EXPECT_EQ( counts[0] , 6u ); // nodes
89 EXPECT_EQ( counts[1] , 7u ); // edges
90 EXPECT_EQ( counts[2] , 0u ); // faces
91 EXPECT_EQ( counts[3] , 2u ); // elements
92 }
93 }
94
95 TEST ( UnitTestCreateEdges, Quad9_2x1 )
96 {
97 stk::mesh::fixtures::Quad9Fixture fixture( MPI_COMM_WORLD, 2, 1);
98
99 fixture.m_meta.commit();
100 fixture.generate_mesh();
101
102 {
103 std::vector<size_t> counts ;
104 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
105
106 EXPECT_EQ( counts[0] ,15u ); // nodes
107 EXPECT_EQ( counts[1] , 0u ); // edges
108 EXPECT_EQ( counts[2] , 0u ); // faces
109 EXPECT_EQ( counts[3] , 2u ); // elements
110 }
111
112 stk::mesh::create_edges(fixture.m_bulk_data);
113
114 {
115 std::vector<size_t> counts ;
116 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
117
118 EXPECT_EQ( counts[0] ,15u ); // nodes
119 EXPECT_EQ( counts[1] , 7u ); // edges
120 EXPECT_EQ( counts[2] , 0u ); // faces
121 EXPECT_EQ( counts[3] , 2u ); // elements
122 }
123 }
124
125 TEST ( UnitTestCreateEdges, Quad_3x1 )
126 {
127 stk::mesh::fixtures::QuadFixture fixture( MPI_COMM_WORLD, 3, 1);
128
129 fixture.m_meta.commit();
130 fixture.generate_mesh();
131
132 {
133 std::vector<size_t> counts ;
134 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
135
136 EXPECT_EQ( counts[0] , 8u ); // nodes
137 EXPECT_EQ( counts[1] , 0u ); // edges
138 EXPECT_EQ( counts[2] , 0u ); // faces
139 EXPECT_EQ( counts[3] , 3u ); // elements
140 }
141
142 stk::mesh::create_edges(fixture.m_bulk_data);
143
144 {
145 std::vector<size_t> counts ;
146 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
147
148 EXPECT_EQ( counts[0] , 8u ); // nodes
149 EXPECT_EQ( counts[1] , 10u ); // edges
150 EXPECT_EQ( counts[2] , 0u ); // faces
151 EXPECT_EQ( counts[3] , 3u ); // elements
152 }
153 }
154
155
156 TEST ( UnitTestCreateEdges, Quad9_3x1 )
157 {
158 stk::mesh::fixtures::Quad9Fixture fixture( MPI_COMM_WORLD, 3, 1);
159
160 fixture.m_meta.commit();
161 fixture.generate_mesh();
162
163 {
164 std::vector<size_t> counts ;
165 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
166
167 EXPECT_EQ( counts[0] ,21u ); // nodes
168 EXPECT_EQ( counts[1] , 0u ); // edges
169 EXPECT_EQ( counts[2] , 0u ); // faces
170 EXPECT_EQ( counts[3] , 3u ); // elements
171 }
172
173 stk::mesh::create_edges(fixture.m_bulk_data);
174
175 {
176 std::vector<size_t> counts ;
177 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
178
179 EXPECT_EQ( counts[0] , 21u ); // nodes
180 EXPECT_EQ( counts[1] , 10u ); // edges
181 EXPECT_EQ( counts[2] , 0u ); // faces
182 EXPECT_EQ( counts[3] , 3u ); // elements
183 }
184 }
185
186 TEST ( UnitTestCreateEdges, Hex_2x1x1 )
187 {
188 stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, 2, 1, 1);
189
190 fixture.m_meta.commit();
191 fixture.generate_mesh();
192
193 {
194 std::vector<size_t> counts ;
195 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
196
197 EXPECT_EQ( counts[0] , 12u ); // nodes
198 EXPECT_EQ( counts[1] , 0u ); // edges
199 EXPECT_EQ( counts[2] , 0u ); // faces
200 EXPECT_EQ( counts[3] , 2u ); // elements
201 }
202
203 stk::mesh::create_edges(fixture.m_bulk_data);
204
205 {
206 std::vector<size_t> counts ;
207 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
208
209 EXPECT_EQ( counts[0] , 12u ); // nodes
210 EXPECT_EQ( counts[1] , 20u ); // edges
211 EXPECT_EQ( counts[2] , 0u ); // faces
212 EXPECT_EQ( counts[3] , 2u ); // elements
213 }
214 }
215
216 TEST( UnitTestCreateEdges , Hex_3x1x1 )
217 {
218 stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, 3, 1, 1);
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( counts[0] , 16u ); // nodes
228 EXPECT_EQ( counts[1] , 0u ); // edges
229 EXPECT_EQ( counts[2] , 0u ); // faces
230 EXPECT_EQ( counts[3] , 3u ); // elements
231 }
232
233 stk::mesh::create_edges(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( counts[0] , 16u );
240 EXPECT_EQ( counts[1] , 28u );
241 EXPECT_EQ( counts[2] , 0u );
242 EXPECT_EQ( counts[3] , 3u );
243 }
244 }
245
246 TEST( UnitTestCreateEdges , testCreateEdges3x3x3 )
247 {
248 const stk::mesh::EntityRank elem_rank = stk::topology::ELEMENT_RANK;
249 const stk::mesh::EntityRank face_rank = stk::topology::FACE_RANK;
250 const stk::mesh::EntityRank edge_rank = stk::topology::EDGE_RANK;
251 const stk::mesh::EntityRank node_rank = stk::topology::NODE_RANK;
252
253 const size_t NX = 3;
254 const size_t NY = 3;
255 const size_t NZ = 3;
256
257 stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, NX, NY, NZ);
258
259 fixture.m_meta.commit();
260 fixture.generate_mesh();
261
262 {
263 std::vector<size_t> counts ;
264 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
265
266 EXPECT_EQ( counts[node_rank] , 64u ); // nodes
267 EXPECT_EQ( counts[edge_rank] , 0u ); // edges
268 EXPECT_EQ( counts[face_rank] , 0u ); // faces
269 EXPECT_EQ( counts[elem_rank] , 27u ); // elements
270 }
271
272 stk::mesh::create_edges(fixture.m_bulk_data);
273
274 {
275 std::vector<size_t> counts ;
276 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
277
278 EXPECT_EQ( 64u, counts[node_rank] ); // nodes
279 EXPECT_EQ( 144u, counts[edge_rank] ); // edges
280 EXPECT_EQ( 0u, counts[face_rank] ); // faces
281 EXPECT_EQ( 27u, counts[elem_rank] ); // elements
282 }
283
284 stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank);
285 for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin();
286 b_itr != elem_buckets.end();
287 ++b_itr
288 )
289 {
290 stk::mesh::Bucket & b = **b_itr;
291 for ( size_t i = 0; i< b.size(); ++i) {
292 EXPECT_EQ( 0u, b.num_faces(i) );
293 EXPECT_EQ( 12u, b.num_edges(i) );
294 EXPECT_EQ( 8u, b.num_nodes(i) );
295 }
296 }
297
298 stk::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank);
299 for ( stk::mesh::BucketVector::iterator b_itr = face_buckets.begin();
300 b_itr != face_buckets.end();
301 ++b_itr
302 )
303 {
304 stk::mesh::Bucket & b = **b_itr;
305 for ( size_t i = 0; i< b.size(); ++i) {
306 EXPECT_EQ( 4u, b.num_edges(i) );
307 EXPECT_EQ( 4u, b.num_nodes(i) );
308 }
309 }
310
311 stk::mesh::BucketVector edge_buckets = fixture.m_bulk_data.buckets(edge_rank);
312 for ( stk::mesh::BucketVector::iterator b_itr = edge_buckets.begin();
313 b_itr != edge_buckets.end();
314 ++b_itr
315 )
316 {
317 stk::mesh::Bucket & b = **b_itr;
318 for ( unsigned edge_ordinal = 0; edge_ordinal< b.size(); ++edge_ordinal) {
319 EXPECT_EQ( 2u, b.num_nodes(edge_ordinal) );
320 }
321 }
322 }
323
324 TEST( UnitTestCreateEdges , TwoBlockTwoHexTwoProc )
325 {
326 stk::ParallelMachine communicator = MPI_COMM_WORLD;
327 int numProcs = stk::parallel_machine_size(communicator);
328 if (numProcs > 2) {
329 return;
330 }
331
332 const unsigned spatialDim = 3;
333 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator);
334 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
335 stk::mesh::BulkData& bulk = *bulkPtr;
336
337 setup2Block2HexMesh(bulk);
338
339 stk::mesh::create_edges(bulk, *meta.get_part("block_1"));
340
341 unsigned num_elems = stk::mesh::count_selected_entities(meta.universal_part(), bulk.buckets(stk::topology::ELEM_RANK));
342 unsigned num_edges = stk::mesh::count_selected_entities(meta.universal_part(), bulk.buckets(stk::topology::EDGE_RANK));
343 unsigned expected_num_elems = 2;//1 owned, 1 ghost on each proc
344 unsigned expected_num_edges = 12;//edges only on the block_1 elem
345 EXPECT_EQ(expected_num_elems, num_elems);
346 EXPECT_EQ(expected_num_edges, num_edges);
347 }
348
349 TEST( UnitTestCreateEdges , testCreateEdges3x3 )
350 {
351 const stk::mesh::EntityRank elem_rank = stk::topology::ELEMENT_RANK;
352 const stk::mesh::EntityRank edge_rank = stk::topology::EDGE_RANK;
353 const stk::mesh::EntityRank node_rank = stk::topology::NODE_RANK;
354
355 const size_t NX = 3;
356 const size_t NY = 3;
357
358 stk::mesh::fixtures::QuadFixture fixture(MPI_COMM_WORLD, NX, NY);
359
360 fixture.m_meta.commit();
361 fixture.generate_mesh();
362
363 {
364 std::vector<size_t> counts ;
365 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
366
367 EXPECT_EQ( counts[node_rank] , 16u ); // nodes
368 EXPECT_EQ( counts[edge_rank] , 0u ); // edges
369 EXPECT_EQ( counts[elem_rank] , 9u ); // elements
370 }
371
372 stk::mesh::create_edges(fixture.m_bulk_data);
373
374 {
375 std::vector<size_t> counts ;
376 stk::mesh::comm_mesh_counts( fixture.m_bulk_data , counts);
377
378 EXPECT_EQ( 16u, counts[node_rank] ); // nodes
379 EXPECT_EQ( 24u, counts[edge_rank] ); // edges
380 EXPECT_EQ( 9u, counts[elem_rank] ); // elements
381 }
382
383 stk::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank);
384 for ( stk::mesh::BucketVector::iterator b_itr = elem_buckets.begin();
385 b_itr != elem_buckets.end();
386 ++b_itr
387 )
388 {
389 stk::mesh::Bucket & b = **b_itr;
390 for ( size_t i = 0; i< b.size(); ++i) {
391 unsigned elem_ordinal = i;
392 EXPECT_EQ( 4u, b.num_edges(elem_ordinal) );
393 EXPECT_EQ( 4u, b.num_nodes(elem_ordinal) );
394 }
395 }
396
397 stk::mesh::BucketVector edge_buckets = fixture.m_bulk_data.buckets(edge_rank);
398 for ( stk::mesh::BucketVector::iterator b_itr = edge_buckets.begin();
399 b_itr != edge_buckets.end();
400 ++b_itr
401 )
402 {
403 stk::mesh::Bucket & b = **b_itr;
404 for ( size_t i = 0; i< b.size(); ++i) {
405 unsigned edge_ordinal = i;
406 EXPECT_EQ( 2u, b.num_nodes(edge_ordinal) );
407 }
408 }
409 }
410
411 TEST( UnitTestCreateEdges , hex1x1x4 )
412 {
413 stk::ParallelMachine communicator = MPI_COMM_WORLD;
414 int procCount = stk::parallel_machine_size(communicator);
415
416 if(procCount == 2)
417 {
418 const std::string generatedMeshSpec = "generated:1x1x4|sideset:xXyYzZ|nodeset:xXyYzZ";
419 stk::unit_test_util::StkMeshCreator stkMesh(generatedMeshSpec, communicator);
420
421 stk::mesh::BulkData &stkMeshBulkData = *stkMesh.getBulkData();
422
423 const stk::mesh::BucketVector &buckets = stkMeshBulkData.buckets(stk::topology::EDGE_RANK);
424
425 EXPECT_EQ(0u, buckets.size());
426
427 stk::mesh::create_edges(stkMeshBulkData);
428
429 EXPECT_NE(0u, buckets.size());
430
431 stkMeshBulkData.modification_begin();
432 stkMeshBulkData.modification_end();
433 }
434 }
435
436 TEST( UnitTestCreateEdges, hybrid_HexPyrTet )
437 {
438 // ID.proc
439 //
440 // 3.0------------7.0-----------11.1
441 // /| /| /|
442 // / | / | / |
443 // / | / | / |
444 // 4.0------------8.0-----------12.1 |
445 // | | | | | | <-- (Undrawable transition pyramid between node (5,6,7,8,9)
446 // | | 1.0 | | | | and 4 tets contained in volume on the right)
447 // | | | | | |
448 // | 2.0---------|--6.0---------|-10.1
449 // | / | / | /
450 // | / | / | /
451 // |/ |/ |/
452 // 1.0------------5.0------------9.1
453
454 stk::ParallelMachine pm = MPI_COMM_WORLD;
455 int p_size = stk::parallel_machine_size(pm);
456
457 if(p_size != 2)
458 {
459 return;
460 }
461
462 const unsigned spatialDim = 3;
463 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
464 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
465 stk::mesh::BulkData& mesh = *bulkPtr;
466 const int p_rank = mesh.parallel_rank();
467
468 stk::mesh::Part * hexPart = &meta.declare_part_with_topology("hex_part", stk::topology::HEX_8);
469 stk::mesh::Part * pyrPart = &meta.declare_part_with_topology("pyr_part", stk::topology::PYRAMID_5);
470 stk::mesh::Part * tetPart = &meta.declare_part_with_topology("tet_part", stk::topology::TET_4);
471 meta.commit();
472
473 const size_t numHex = 1;
474 stk::mesh::EntityIdVector hexNodeIDs[] {
475 { 1, 2, 3, 4, 5, 6, 7, 8 }
476 };
477 stk::mesh::EntityId hexElemIDs[] = { 1 };
478
479 const size_t numPyr = 1;
480 stk::mesh::EntityIdVector pyrNodeIDs[] {
481 { 5, 6, 7, 8, 9 }
482 };
483 stk::mesh::EntityId pyrElemIDs[] = { 2 };
484
485 const size_t numTet = 4;
486 stk::mesh::EntityIdVector tetNodeIDs[] {
487 { 7, 8, 9, 12 },
488 { 6, 9, 10, 7 },
489 { 7, 9, 10, 12 },
490 { 7, 12, 10, 11 }
491 };
492 stk::mesh::EntityId tetElemIDs[] = { 3, 4, 5, 6 };
493
494 // list of triplets: (owner-proc, shared-nodeID, sharing-proc)
495 int shared_nodeIDs_and_procs[][3] =
496 {
497 { 0, 5, 1 }, // proc 0
498 { 0, 6, 1 },
499 { 0, 7, 1 },
500 { 0, 8, 1 },
501 { 1, 5, 0 }, // proc 1
502 { 1, 6, 0 },
503 { 1, 7, 0 },
504 { 1, 8, 0 }
505 };
506 int numSharedNodeTriples = 8;
507
508 mesh.modification_begin();
509
510 if (p_rank == 0) {
511 for (size_t i = 0; i < numHex; ++i) {
512 stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]);
513 }
514 }
515 else {
516 for (size_t i = 0; i < numPyr; ++i) {
517 stk::mesh::declare_element(mesh, *pyrPart, pyrElemIDs[i], pyrNodeIDs[i]);
518 }
519 for (size_t i = 0; i < numTet; ++i) {
520 stk::mesh::declare_element(mesh, *tetPart, tetElemIDs[i], tetNodeIDs[i]);
521 }
522 }
523
524 for (int nodeIdx = 0; nodeIdx < numSharedNodeTriples; ++nodeIdx) {
525 if (p_rank == shared_nodeIDs_and_procs[nodeIdx][0]) {
526 stk::mesh::EntityId nodeID = shared_nodeIDs_and_procs[nodeIdx][1];
527 int sharingProc = shared_nodeIDs_and_procs[nodeIdx][2];
528 stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, nodeID);
529 mesh.add_node_sharing(node, sharingProc);
530 }
531 }
532
533 mesh.modification_end();
534
535 stk::mesh::create_edges(mesh, *meta.get_part("pyr_part"));
536
537 {
538 std::vector<size_t> counts;
539 stk::mesh::comm_mesh_counts(mesh, counts);
540
541 EXPECT_EQ( counts[stk::topology::NODE_RANK], 12u ); // nodes
542 EXPECT_EQ( counts[stk::topology::EDGE_RANK], 8u ); // edges
543 EXPECT_EQ( counts[stk::topology::ELEM_RANK], 6u ); // elements
544 }
545 }
546
547 TEST ( UnitTestCreateEdges, Hex_2x1x1_select_out_a_face )
548 {
549 stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, 2, 1, 1);
550
551 stk::mesh::Part & facePart = fixture.m_meta.declare_part_with_topology("face_part_to_exclude", stk::topology::QUADRILATERAL_4, true);
552 stk::mesh::PartVector facePartVector(1, &facePart);
553 fixture.m_meta.commit();
554 fixture.generate_mesh();
555 stk::mesh::BulkData & mesh = fixture.m_bulk_data;
556 {
557 std::vector<size_t> counts ;
558 stk::mesh::comm_mesh_counts(mesh , counts);
559
560 EXPECT_EQ( counts[stk::topology::NODE_RANK] , 12u );
561 EXPECT_EQ( counts[stk::topology::EDGE_RANK] , 0u );
562 EXPECT_EQ( counts[stk::topology::FACE_RANK] , 0u );
563 EXPECT_EQ( counts[stk::topology::ELEM_RANK] , 2u );
564 }
565 stk::mesh::create_faces(mesh);
566 const stk::mesh::BucketVector & buckets = mesh.buckets(stk::topology::FACE_RANK);
567 mesh.modification_begin();
568 for (unsigned bucketCount = 0 ; bucketCount < buckets.size() ; ++bucketCount) {
569 stk::mesh::Bucket & bucket = *buckets[bucketCount];
570 for (unsigned count = 0; count < bucket.size(); ++count) {
571 stk::mesh::Entity face = bucket[count];
572 if (mesh.bucket(face).owned()) {
573 mesh.change_entity_parts(face, facePartVector);
574 }
575 }
576 }
577 mesh.modification_end();
578
579 stk::mesh::Selector selectOutFaces(!facePart);
580
581 stk::mesh::create_edges(mesh, selectOutFaces);
582
583 {
584 std::vector<size_t> counts ;
585 stk::mesh::comm_mesh_counts( mesh, counts);
586
587 EXPECT_EQ( counts[stk::topology::NODE_RANK] , 12u );
588 EXPECT_EQ( counts[stk::topology::EDGE_RANK] , 20u );
589 EXPECT_EQ( counts[stk::topology::FACE_RANK] , 11u );
590 EXPECT_EQ( counts[stk::topology::ELEM_RANK] , 2u );
591 }
592 }
593
594 TEST( UnitTestCreateEdges, particle )
595 {
596 stk::ParallelMachine pm = MPI_COMM_WORLD;
597 int p_size = stk::parallel_machine_size(pm);
598
599 if (p_size != 1) {
600 return;
601 }
602
603 const unsigned spatialDim = 3;
604 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
605 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
606 stk::mesh::BulkData& mesh = *bulkPtr;
607
608 stk::mesh::Part * particlePart = &meta.declare_part_with_topology("particle_part", stk::topology::PARTICLE);
609 meta.commit();
610
611 stk::mesh::EntityIdVector particleNodeIDs { 1 };
612 stk::mesh::EntityId particleElemID( 1 );
613
614 mesh.modification_begin();
615 stk::mesh::declare_element(mesh, *particlePart, particleElemID, particleNodeIDs);
616 mesh.modification_end();
617
618 stk::mesh::create_edges(mesh);
619
620 std::vector<size_t> counts;
621 stk::mesh::comm_mesh_counts(mesh, counts);
622
623 EXPECT_EQ( 1u, counts[stk::topology::NODE_RANK] );
624 EXPECT_EQ( 0u, counts[stk::topology::EDGE_RANK] ); // Shouldn't create any; particles don't have edges
625 EXPECT_EQ( 0u, counts[stk::topology::FACE_RANK] );
626 EXPECT_EQ( 1u, counts[stk::topology::ELEM_RANK] );
627 }
628