Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestBoxFixture.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 <stddef.h> // for size_t
36 #include <stk_mesh/base/BulkData.hpp> // for BulkData, etc
37 #include <stk_mesh/base/Entity.hpp> // for Entity
38 #include <stk_mesh/base/GetEntities.hpp> // for count_entities
39 #include <stk_mesh/base/MetaData.hpp> // for MetaData
40 #include <stk_mesh/base/Selector.hpp> // for Selector, operator|
41 #include <gtest/gtest.h>
42 #include <vector> // for vector, etc
43
44 #include "stk_mesh/base/Relation.hpp"
45 #include "stk_mesh/base/Types.hpp" // for EntityId, etc
46 #include "stk_topology/topology.hpp" // for topology, etc
47 #include "stk_unit_test_utils/stk_mesh_fixtures/BoxFixture.hpp" // for BoxFixture::BOX, etc
48 #include "stk_util/parallel/Parallel.hpp" // for ParallelMachine
49 #include "stk_util/util/PairIter.hpp" // for PairIter
50
51 using stk::mesh::MetaData;
52 using stk::mesh::BulkData;
53 using stk::mesh::Selector;
54 using stk::mesh::Entity;
55 using stk::mesh::EntityId;
56 using stk::mesh::EntityRank;
57 using stk::mesh::fixtures::BoxFixture;
58
59 namespace {
60
61 const EntityRank NODE_RANK = stk::topology::NODE_RANK;
62
63 class ExposePartition : public BoxFixture
64 {
65 public:
66 static void expose_box_partition( int ip , int up , int axis ,
67 const BOX box ,
68 BOX p_box[] )
69 {
70 box_partition(ip, up, axis, box, p_box);
71 }
72 };
73
74 }
75
76 TEST( UnitTestBoxFixture, verifyBoxFixture )
77 {
78 // A unit test to verify the correctness of the BoxFixture fixture.
79
80 stk::ParallelMachine pm = MPI_COMM_WORLD;
81 MPI_Barrier( pm );
82
83 // Create the box fixture we'll be testing
84
85 // box specifications
86 const BoxFixture::BOX root_box = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } };
87 BoxFixture::BOX local_box = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } };
88
89 BoxFixture fixture(pm);
90 MetaData& meta = fixture.fem_meta();
91 stk::unit_test_util::BulkDataTester& bulk = fixture.bulk_data();
92
93 const EntityRank element_rank = stk::topology::ELEMENT_RANK;
94
95 const int p_rank = bulk.parallel_rank();
96 const int p_size = bulk.parallel_size();
97
98 BoxFixture::BOX * const p_box = new BoxFixture::BOX[ p_size ];
99 ExposePartition::expose_box_partition( 0, p_size, 2, root_box, &p_box[0] );
100
101 meta.commit();
102
103 bulk.modification_begin();
104 fixture.generate_boxes( root_box, local_box );
105
106 const unsigned nx = local_box[0][1] - local_box[0][0] ;
107 const unsigned ny = local_box[1][1] - local_box[1][0] ;
108 const unsigned nz = local_box[2][1] - local_box[2][0] ;
109
110 const unsigned e_local = nx * ny * nz ;
111 const unsigned n_local = ( nx + 1 ) * ( ny + 1 ) * ( nz + 1 );
112
113 const unsigned ngx = root_box[0][1] - root_box[0][0] ;
114 const unsigned ngy = root_box[1][1] - root_box[1][0] ;
115
116 std::vector<size_t> local_count ;
117
118 // Verify that the correct entities are on this process
119
120 for ( int k = local_box[2][0] ; k < local_box[2][1] ; ++k ) {
121 for ( int j = local_box[1][0] ; j < local_box[1][1] ; ++j ) {
122 for ( int i = local_box[0][0] ; i < local_box[0][1] ; ++i ) {
123
124 const EntityId n0= 1 + (i+0) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
125 const EntityId n1= 1 + (i+1) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
126 const EntityId n2= 1 + (i+1) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
127 const EntityId n3= 1 + (i+0) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
128 const EntityId n4= 1 + (i+0) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
129 const EntityId n5= 1 + (i+1) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
130 const EntityId n6= 1 + (i+1) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
131 const EntityId n7= 1 + (i+0) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
132
133 const EntityId elem_id = 1 + i + j * ngx + k * ngx * ngy;
134
135 std::vector<Entity> nodes(8);
136 nodes[0] = bulk.get_entity( NODE_RANK, n0 );
137 nodes[1] = bulk.get_entity( NODE_RANK, n1 );
138 nodes[2] = bulk.get_entity( NODE_RANK, n2 );
139 nodes[3] = bulk.get_entity( NODE_RANK, n3 );
140 nodes[4] = bulk.get_entity( NODE_RANK, n4 );
141 nodes[5] = bulk.get_entity( NODE_RANK, n5 );
142 nodes[6] = bulk.get_entity( NODE_RANK, n6 );
143 nodes[7] = bulk.get_entity( NODE_RANK, n7 );
144
145 Entity elem = bulk.get_entity( element_rank, elem_id );
146
147 std::vector<Entity> elems ;
148 stk::mesh::get_entities_through_relations(bulk, nodes, element_rank, elems);
149 ASSERT_EQ( elems.size() , size_t(1) );
150 ASSERT_TRUE( elems[0] == elem );
151 }
152 }
153 }
154
155 Selector select_owned( meta.locally_owned_part() );
156 Selector select_used = select_owned |
157 meta.globally_shared_part();
158 Selector select_all( meta.universal_part() );
159
160 stk::mesh::count_entities( select_used , bulk , local_count );
161 ASSERT_EQ( e_local , local_count[3] );
162 ASSERT_EQ( 0u , local_count[2] );
163 ASSERT_EQ( 0u , local_count[1] );
164 ASSERT_EQ( n_local , local_count[0] );
165
166 ASSERT_TRUE(bulk.modification_end());
167
168 // Verify declarations and sharing
169
170 stk::mesh::count_entities( select_used , bulk , local_count );
171 ASSERT_EQ( local_count[3] , e_local );
172 ASSERT_EQ( local_count[2] , 0u );
173 ASSERT_EQ( local_count[1] , 0u );
174 ASSERT_EQ( local_count[0] , n_local );
175
176 for ( int k = local_box[2][0] ; k <= local_box[2][1] ; ++k ) {
177 for ( int j = local_box[1][0] ; j <= local_box[1][1] ; ++j ) {
178 for ( int i = local_box[0][0] ; i <= local_box[0][1] ; ++i ) {
179 EntityRank node_type = stk::topology::NODE_RANK;
180 EntityId node_id = 1 + i + j * (ngx+1) + k * (ngx+1) * (ngy+1);
181 Entity const node = bulk.get_entity( node_type , node_id );
182 ASSERT_TRUE( bulk.is_valid(node) );
183 // Shared if on a processor boundary.
184 const bool shared =
185 ( k == local_box[2][0] && k != root_box[2][0] ) ||
186 ( k == local_box[2][1] && k != root_box[2][1] ) ||
187 ( j == local_box[1][0] && j != root_box[1][0] ) ||
188 ( j == local_box[1][1] && j != root_box[1][1] ) ||
189 ( i == local_box[0][0] && i != root_box[0][0] ) ||
190 ( i == local_box[0][1] && i != root_box[0][1] );
191 if (bulk.parallel_size() > 1) {
192 std::vector<int> shared_procs;
193 bulk.comm_shared_procs(bulk.entity_key(node),shared_procs);
194 ASSERT_EQ( shared , ! shared_procs.empty() );
195 }
196 }
197 }
198 }
199
200 size_t count_shared_node_pairs = 0 ;
201 for ( int p = 0 ; p < p_size ; ++p ) if ( p != p_rank ) {
202 for ( int k = p_box[p][2][0] ; k <= p_box[p][2][1] ; ++k )
203 if ( local_box[2][0] <= k && k <= local_box[2][1] ) {
204
205 for ( int j = p_box[p][1][0] ; j <= p_box[p][1][1] ; ++j )
206 if ( local_box[1][0] <= j && j <= local_box[1][1] ) {
207
208 for ( int i = p_box[p][0][0] ; i <= p_box[p][0][1] ; ++i )
209 if ( local_box[0][0] <= i && i <= local_box[0][1] ) {
210
211 EntityRank node_type = stk::topology::NODE_RANK;
212 EntityId node_id = 1 + i + j * (ngx+1) + k * (ngx+1) * (ngy+1);
213 Entity const node = bulk.get_entity( node_type , node_id );
214 ASSERT_TRUE( bulk.is_valid(node) );
215 // Must be shared with 'p'
216 std::vector<int> shared_procs;
217 bulk.comm_shared_procs(bulk.entity_key(node),shared_procs);
218 std::vector<int>::const_iterator it=std::find(shared_procs.begin(),shared_procs.end(),p);
219 ASSERT_TRUE( it != shared_procs.end() );
220
221 ++count_shared_node_pairs ;
222 }
223 }
224 }
225 }
226
227 size_t count_shared_entities = 0 ;
228 for (stk::mesh::EntityCommListInfoVector::const_iterator
229 i = bulk.my_internal_comm_list().begin() ;
230 i != bulk.my_internal_comm_list().end() ;
231 ++i) {
232 std::vector<int> shared_procs;
233 bulk.comm_shared_procs(i->key,shared_procs);
234 count_shared_entities += shared_procs.size();
235 }
236 ASSERT_EQ( count_shared_entities , count_shared_node_pairs );
237
238 delete [] p_box;
239 }