9 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
11 #include <stk_mesh/fixtures/RingFixture.hpp>
13 #include <stk_mesh/base/MetaData.hpp>
14 #include <stk_mesh/base/BulkData.hpp>
15 #include <stk_mesh/base/GetEntities.hpp>
17 #include <unit_tests/UnitTestModificationEndWrapper.hpp>
29 const stk_classic::mesh::EntityRank NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
31 STKUNIT_UNIT_TEST( UnitTestBoxFixture, verifyRingFixture )
42 BulkData& bulk = fixture.m_bulk_data;
44 const stk_classic::mesh::EntityRank element_rank = meta.
element_rank();
50 const unsigned nPerProc = fixture.m_num_edge_per_proc ;
51 const unsigned id_total = nPerProc * p_size ;
52 const unsigned id_begin = nPerProc * p_rank ;
53 const unsigned id_end = nPerProc * ( p_rank + 1 );
54 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 );
55 const unsigned nLocalEdge = nPerProc ;
56 const unsigned n_extra = 1 < p_size ? 2 : 0 ;
59 fixture.generate_mesh();
66 std::vector<unsigned> local_count;
68 STKUNIT_ASSERT_EQUAL( local_count[NODE_RANK] , nLocalNode );
69 STKUNIT_ASSERT_EQUAL( local_count[element_rank] , nLocalEdge );
71 std::vector<Entity*> all_nodes;
74 unsigned num_selected_nodes =
76 STKUNIT_ASSERT_EQUAL( num_selected_nodes , local_count[NODE_RANK] );
78 std::vector<Entity*> universal_nodes;
81 STKUNIT_ASSERT_EQUAL( universal_nodes.size() , all_nodes.size() );
88 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
89 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
92 const unsigned n0 = id_end < id_total ? id_begin : 0 ;
93 const unsigned n1 = id_end < id_total ? id_end : id_begin ;
95 Entity *
const node0 = bulk.
get_entity( NODE_RANK , fixture.m_node_ids[n0] );
96 Entity *
const node1 = bulk.
get_entity( NODE_RANK , fixture.m_node_ids[n1] );
98 STKUNIT_ASSERT( node0 != NULL );
99 STKUNIT_ASSERT( node1 != NULL );
101 STKUNIT_ASSERT_EQUAL( node0->
sharing().size() , size_t(1) );
102 STKUNIT_ASSERT_EQUAL( node1->
sharing().size() , size_t(1) );
107 std::vector<EntityProc> change ;
114 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
115 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
118 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode + n_extra );
119 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge + n_extra );
122 fixture.fixup_node_ownership();
128 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode + n_extra );
129 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge + n_extra );
132 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
133 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
136 STKUNIT_ASSERT_EQUAL( local_count[0] , nPerProc );
137 STKUNIT_ASSERT_EQUAL( local_count[1] , nPerProc );
144 namespace unit_test {
146 void test_shift_ring(
RingFixture& ring,
bool generate_aura=
true )
153 const unsigned nPerProc = ring.m_num_edge_per_proc ;
154 const unsigned id_total = nPerProc * p_size ;
155 const unsigned id_begin = nPerProc * p_rank ;
156 const unsigned id_end = nPerProc * ( p_rank + 1 );
157 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 );
158 const unsigned nLocalEdge = nPerProc ;
160 const unsigned p_send = ( p_rank + 1 ) % p_size ;
161 const unsigned id_send = id_end - 2 ;
162 const unsigned id_recv = ( id_begin + id_total - 2 ) % id_total ;
167 std::vector<unsigned> local_count ;
168 std::vector<EntityProc> change ;
171 Entity * send_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_send + 1 ] );
175 Entity * recv_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_recv + 1 ] );
177 STKUNIT_ASSERT( NULL != send_edge_1 && p_rank == send_edge_1->
owner_rank() );
178 STKUNIT_ASSERT( NULL != send_edge_2 && p_rank == send_edge_2->
owner_rank() );
179 STKUNIT_ASSERT( NULL == recv_edge_1 || p_rank != recv_edge_1->
owner_rank() );
180 STKUNIT_ASSERT( NULL == recv_edge_2 || p_rank != recv_edge_2->
owner_rank() );
184 change.push_back( entry );
188 change.push_back( entry );
192 change.push_back( entry );
196 change.push_back( entry );
208 STKUNIT_ASSERT( stk_classic::unit_test::modification_end_wrapper( bulk , generate_aura ) );
210 send_edge_1 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_send ] );
211 send_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_send + 1 ] );
212 recv_edge_1 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_recv ] );
213 recv_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_recv + 1 ] );
215 STKUNIT_ASSERT( NULL == send_edge_1 || p_rank != send_edge_1->
owner_rank() );
216 STKUNIT_ASSERT( NULL == send_edge_2 || p_rank != send_edge_2->
owner_rank() );
217 STKUNIT_ASSERT( NULL != recv_edge_1 && p_rank == recv_edge_1->
owner_rank() );
218 STKUNIT_ASSERT( NULL != recv_edge_2 && p_rank == recv_edge_2->
owner_rank() );
221 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
222 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
224 unsigned count_shared = 0 ;
225 for ( std::vector<Entity*>::const_iterator
228 if ( in_shared( **i ) ) { ++count_shared ; }
230 STKUNIT_ASSERT_EQUAL( count_shared , 2u );
233 Entity *
const node_recv = bulk.
get_entity( NODE_RANK , ring.m_node_ids[id_recv] );
234 Entity *
const node_send = bulk.
get_entity( NODE_RANK , ring.m_node_ids[id_send] );
236 STKUNIT_ASSERT_EQUAL( node_recv->
sharing().size() , 1u );
237 STKUNIT_ASSERT_EQUAL( node_send->
sharing().size() , 1u );