Sierra Toolkit  Version of the Day
UnitTestCreateAdjacentEntities.cpp
1 
2 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
3 
4 #include <stk_util/parallel/Parallel.hpp>
5 
6 #include <stk_mesh/base/MetaData.hpp>
7 #include <stk_mesh/base/BulkData.hpp>
8 #include <stk_mesh/base/Entity.hpp>
9 #include <stk_mesh/base/GetEntities.hpp>
10 #include <stk_mesh/base/Selector.hpp>
11 #include <stk_mesh/base/GetBuckets.hpp>
12 #include <stk_mesh/base/Comm.hpp>
13 
14 #include <stk_mesh/fem/CreateAdjacentEntities.hpp>
15 #include <stk_mesh/fem/FEMHelpers.hpp>
16 
17 #include <stk_mesh/fixtures/HexFixture.hpp>
18 #include <stk_mesh/fixtures/QuadFixture.hpp>
19 
20 #include <stk_util/parallel/ParallelReduce.hpp>
21 
22 #include <Shards_BasicTopologies.hpp>
23 
24 #include <iomanip>
25 #include <algorithm>
26 #include <sstream>
27 
28 STKUNIT_UNIT_TEST( UnitTestStkMeshSkinning , testCreateAdjacentEntities3x1x1 )
29 {
30  const size_t NX = 3;
31  const size_t NY = 1;
32  const size_t NZ = 1;
33 
34  stk_classic::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, NX, NY, NZ);
35 
36  fixture.m_fem_meta.commit();
37  fixture.generate_mesh();
38 
39  {
40  std::vector<size_t> counts ;
41  stk_classic::mesh::fem::comm_mesh_counts( fixture.m_bulk_data , counts);
42 
43  STKUNIT_EXPECT_EQ( counts[0] , 16u ); // nodes
44  STKUNIT_EXPECT_EQ( counts[1] , 0u ); // edges
45  STKUNIT_EXPECT_EQ( counts[2] , 0u ); // faces
46  STKUNIT_EXPECT_EQ( counts[3] , 3u ); // elements
47  }
48 
49  stk_classic::mesh::PartVector empty_add_parts;
50 
51  stk_classic::mesh::create_adjacent_entities(fixture.m_bulk_data, empty_add_parts);
52 
53  {
54  std::vector<size_t> counts ;
55  stk_classic::mesh::fem::comm_mesh_counts( fixture.m_bulk_data , counts);
56 
57  STKUNIT_EXPECT_EQ( counts[0] , 16u );
58  STKUNIT_EXPECT_EQ( counts[1] , 28u );
59  STKUNIT_EXPECT_EQ( counts[2] , 16u );
60  STKUNIT_EXPECT_EQ( counts[3] , 3u );
61  }
62 }
63 
64 STKUNIT_UNIT_TEST( UnitTestStkMeshSkinning , testCreateAdjacentEntities3x3x3 )
65 {
66  const size_t elem_rank = 3;
67  const size_t face_rank = 2;
68  const size_t edge_rank = 1;
69  const size_t node_rank = 0;
70 
71  const size_t NX = 3;
72  const size_t NY = 3;
73  const size_t NZ = 3;
74 
75  stk_classic::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, NX, NY, NZ);
76 
77  fixture.m_fem_meta.commit();
78  fixture.generate_mesh();
79 
80  {
81  std::vector<size_t> counts ;
82  stk_classic::mesh::fem::comm_mesh_counts( fixture.m_bulk_data , counts);
83 
84  STKUNIT_EXPECT_EQ( counts[node_rank] , 64u ); // nodes
85  STKUNIT_EXPECT_EQ( counts[edge_rank] , 0u ); // edges
86  STKUNIT_EXPECT_EQ( counts[face_rank] , 0u ); // faces
87  STKUNIT_EXPECT_EQ( counts[elem_rank] , 27u ); // elements
88  }
89 
90  stk_classic::mesh::PartVector empty_add_parts;
91 
92  stk_classic::mesh::create_adjacent_entities(fixture.m_bulk_data, empty_add_parts);
93 
94  {
95  std::vector<size_t> counts ;
96  stk_classic::mesh::fem::comm_mesh_counts( fixture.m_bulk_data , counts);
97 
98  STKUNIT_EXPECT_EQ( 64u, counts[node_rank] ); // nodes
99  STKUNIT_EXPECT_EQ( 144u, counts[edge_rank] ); // edges
100  STKUNIT_EXPECT_EQ( 108u, counts[face_rank] ); // faces
101  STKUNIT_EXPECT_EQ( 27u, counts[elem_rank] ); // elements
102  }
103 
104  stk_classic::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank);
105  for ( stk_classic::mesh::BucketVector::iterator b_itr = elem_buckets.begin();
106  b_itr != elem_buckets.end();
107  ++b_itr
108  )
109  {
110  stk_classic::mesh::Bucket & b = **b_itr;
111  for ( size_t i = 0; i< b.size(); ++i) {
112  stk_classic::mesh::Entity & elem = b[i];
113 
114  STKUNIT_EXPECT_EQ( 6u, elem.relations(face_rank).size() );
115  STKUNIT_EXPECT_EQ( 12u, elem.relations(edge_rank).size() );
116  STKUNIT_EXPECT_EQ( 8u, elem.relations(node_rank).size() );
117 
118  }
119  }
120 
121  stk_classic::mesh::BucketVector face_buckets = fixture.m_bulk_data.buckets(face_rank);
122  for ( stk_classic::mesh::BucketVector::iterator b_itr = face_buckets.begin();
123  b_itr != face_buckets.end();
124  ++b_itr
125  )
126  {
127  stk_classic::mesh::Bucket & b = **b_itr;
128  for ( size_t i = 0; i< b.size(); ++i) {
129  stk_classic::mesh::Entity & face = b[i];
130  STKUNIT_EXPECT_EQ( 4u,face.relations(edge_rank).size());
131  STKUNIT_EXPECT_EQ( 4u, face.relations(node_rank).size() );
132  }
133  }
134 
135  stk_classic::mesh::BucketVector edge_buckets = fixture.m_bulk_data.buckets(edge_rank);
136  for ( stk_classic::mesh::BucketVector::iterator b_itr = edge_buckets.begin();
137  b_itr != edge_buckets.end();
138  ++b_itr
139  )
140  {
141  stk_classic::mesh::Bucket & b = **b_itr;
142  for ( size_t i = 0; i< b.size(); ++i) {
143  stk_classic::mesh::Entity & edge = b[i];
144  STKUNIT_EXPECT_EQ( 2u, edge.relations(node_rank).size() );
145  }
146  }
147 }
148 
149 STKUNIT_UNIT_TEST( UnitTestStkMeshSkinning , testCreateAdjacentEntities3x3 )
150 {
151  const size_t elem_rank = 2;
152  const size_t edge_rank = 1;
153  const size_t node_rank = 0;
154 
155  const size_t NX = 3;
156  const size_t NY = 3;
157 
158  stk_classic::mesh::fixtures::QuadFixture fixture(MPI_COMM_WORLD, NX, NY);
159 
160  fixture.m_fem_meta.commit();
161  fixture.generate_mesh();
162 
163  {
164  std::vector<size_t> counts ;
165  stk_classic::mesh::fem::comm_mesh_counts( fixture.m_bulk_data , counts);
166 
167  STKUNIT_EXPECT_EQ( counts[node_rank] , 16u ); // nodes
168  STKUNIT_EXPECT_EQ( counts[edge_rank] , 0u ); // edges
169  STKUNIT_EXPECT_EQ( counts[elem_rank] , 9u ); // elements
170  }
171 
172  stk_classic::mesh::PartVector empty_add_parts;
173 
174  stk_classic::mesh::create_adjacent_entities(fixture.m_bulk_data, empty_add_parts);
175 
176  {
177  std::vector<size_t> counts ;
178  stk_classic::mesh::fem::comm_mesh_counts( fixture.m_bulk_data , counts);
179 
180  STKUNIT_EXPECT_EQ( 16u, counts[node_rank] ); // nodes
181  STKUNIT_EXPECT_EQ( 24u, counts[edge_rank] ); // edges
182  STKUNIT_EXPECT_EQ( 9u, counts[elem_rank] ); // elements
183  }
184 
185  stk_classic::mesh::BucketVector elem_buckets = fixture.m_bulk_data.buckets(elem_rank);
186  for ( stk_classic::mesh::BucketVector::iterator b_itr = elem_buckets.begin();
187  b_itr != elem_buckets.end();
188  ++b_itr
189  )
190  {
191  stk_classic::mesh::Bucket & b = **b_itr;
192  for ( size_t i = 0; i< b.size(); ++i) {
193  stk_classic::mesh::Entity & elem = b[i];
194 
195  STKUNIT_EXPECT_EQ( 4u, elem.relations(edge_rank).size() );
196  STKUNIT_EXPECT_EQ( 4u, elem.relations(node_rank).size() );
197 
198  }
199  }
200 
201  stk_classic::mesh::BucketVector edge_buckets = fixture.m_bulk_data.buckets(edge_rank);
202  for ( stk_classic::mesh::BucketVector::iterator b_itr = edge_buckets.begin();
203  b_itr != edge_buckets.end();
204  ++b_itr
205  )
206  {
207  stk_classic::mesh::Bucket & b = **b_itr;
208  for ( size_t i = 0; i< b.size(); ++i) {
209  stk_classic::mesh::Entity & edge = b[i];
210  STKUNIT_EXPECT_EQ( 2u, edge.relations(node_rank).size() );
211  }
212  }
213 }
bool comm_mesh_counts(BulkData &M, std::vector< size_t > &counts, bool local_flag)
Global counts for a mesh&#39;s entities.
Definition: Comm.cpp:26
size_t size() const
Number of entities associated with this bucket.
Definition: Bucket.hpp:119
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
Definition: Entity.hpp:161
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94