|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 00010 00011 #include <stk_mesh/fixtures/RingFixture.hpp> 00012 00013 #include <stk_mesh/base/MetaData.hpp> 00014 #include <stk_mesh/base/BulkData.hpp> 00015 #include <stk_mesh/base/GetEntities.hpp> 00016 00017 #include <unit_tests/UnitTestModificationEndWrapper.hpp> 00018 00019 using stk_classic::mesh::fem::FEMMetaData; 00020 using stk_classic::mesh::MetaData; 00021 using stk_classic::mesh::BulkData; 00022 using stk_classic::mesh::Selector; 00023 using stk_classic::mesh::Entity; 00024 using stk_classic::mesh::EntityProc; 00025 using stk_classic::mesh::fixtures::RingFixture; 00026 00027 namespace { 00028 00029 const stk_classic::mesh::EntityRank NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK; 00030 00031 STKUNIT_UNIT_TEST( UnitTestBoxFixture, verifyRingFixture ) 00032 { 00033 // A unit test to verify the correctness of the RingFixture fixture. 00034 00035 stk_classic::ParallelMachine pm = MPI_COMM_WORLD; 00036 MPI_Barrier( pm ); 00037 00038 // Create the ring fixture we'll be testing 00039 00040 RingFixture fixture(pm); 00041 FEMMetaData& meta = fixture.m_meta_data; 00042 BulkData& bulk = fixture.m_bulk_data; 00043 00044 const stk_classic::mesh::EntityRank element_rank = meta.element_rank(); 00045 00046 meta.commit(); 00047 00048 const unsigned p_rank = bulk.parallel_rank(); 00049 const unsigned p_size = bulk.parallel_size(); 00050 const unsigned nPerProc = fixture.m_num_edge_per_proc ; 00051 const unsigned id_total = nPerProc * p_size ; 00052 const unsigned id_begin = nPerProc * p_rank ; 00053 const unsigned id_end = nPerProc * ( p_rank + 1 ); 00054 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 ); 00055 const unsigned nLocalEdge = nPerProc ; 00056 const unsigned n_extra = 1 < p_size ? 2 : 0 ; 00057 00058 bulk.modification_begin(); 00059 fixture.generate_mesh(); 00060 00061 Selector select_owned( meta.locally_owned_part() ); 00062 Selector select_used = meta.locally_owned_part() | 00063 meta.globally_shared_part(); 00064 Selector select_all( meta.universal_part() ); 00065 00066 std::vector<unsigned> local_count; 00067 stk_classic::mesh::count_entities( select_used , bulk , local_count ); 00068 STKUNIT_ASSERT_EQUAL( local_count[NODE_RANK] , nLocalNode ); 00069 STKUNIT_ASSERT_EQUAL( local_count[element_rank] , nLocalEdge ); 00070 00071 std::vector<Entity*> all_nodes; 00072 get_entities( bulk, NODE_RANK, all_nodes); 00073 00074 unsigned num_selected_nodes = 00075 count_selected_entities( select_used, bulk.buckets(NODE_RANK) ); 00076 STKUNIT_ASSERT_EQUAL( num_selected_nodes , local_count[NODE_RANK] ); 00077 00078 std::vector<Entity*> universal_nodes; 00079 get_selected_entities(select_all, bulk.buckets(NODE_RANK), 00080 universal_nodes ); 00081 STKUNIT_ASSERT_EQUAL( universal_nodes.size() , all_nodes.size() ); 00082 00083 STKUNIT_ASSERT(bulk.modification_end()); 00084 00085 // Verify declarations and sharing two end nodes: 00086 00087 stk_classic::mesh::count_entities( select_used , bulk , local_count ); 00088 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode ); 00089 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge ); 00090 00091 if ( 1 < p_size ) { 00092 const unsigned n0 = id_end < id_total ? id_begin : 0 ; 00093 const unsigned n1 = id_end < id_total ? id_end : id_begin ; 00094 00095 Entity * const node0 = bulk.get_entity( NODE_RANK , fixture.m_node_ids[n0] ); 00096 Entity * const node1 = bulk.get_entity( NODE_RANK , fixture.m_node_ids[n1] ); 00097 00098 STKUNIT_ASSERT( node0 != NULL ); 00099 STKUNIT_ASSERT( node1 != NULL ); 00100 00101 STKUNIT_ASSERT_EQUAL( node0->sharing().size() , size_t(1) ); 00102 STKUNIT_ASSERT_EQUAL( node1->sharing().size() , size_t(1) ); 00103 } 00104 00105 // Test no-op first: 00106 00107 std::vector<EntityProc> change ; 00108 00109 STKUNIT_ASSERT( bulk.modification_begin() ); 00110 bulk.change_entity_owner( change ); 00111 STKUNIT_ASSERT( bulk.modification_end()); 00112 00113 stk_classic::mesh::count_entities( select_used , bulk , local_count ); 00114 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode ); 00115 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge ); 00116 00117 stk_classic::mesh::count_entities( select_all , bulk , local_count ); 00118 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode + n_extra ); 00119 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge + n_extra ); 00120 00121 bulk.modification_begin(); 00122 fixture.fixup_node_ownership(); 00123 STKUNIT_ASSERT(bulk.modification_end()); 00124 00125 // Make sure that edge->owner_rank() == edge->node[1]->owner_rank() 00126 if ( 1 < p_size ) { 00127 stk_classic::mesh::count_entities( select_all , bulk , local_count ); 00128 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode + n_extra ); 00129 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge + n_extra ); 00130 00131 stk_classic::mesh::count_entities( select_used , bulk , local_count ); 00132 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode ); 00133 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge ); 00134 00135 stk_classic::mesh::count_entities( select_owned , bulk , local_count ); 00136 STKUNIT_ASSERT_EQUAL( local_count[0] , nPerProc ); 00137 STKUNIT_ASSERT_EQUAL( local_count[1] , nPerProc ); 00138 } 00139 } 00140 00141 } 00142 00143 namespace stk_classic { 00144 namespace unit_test { 00145 00146 void test_shift_ring( RingFixture& ring, bool generate_aura=true ) 00147 { 00148 FEMMetaData& meta = ring.m_meta_data; 00149 BulkData& bulk = ring.m_bulk_data; 00150 00151 const unsigned p_rank = bulk.parallel_rank(); 00152 const unsigned p_size = bulk.parallel_size(); 00153 const unsigned nPerProc = ring.m_num_edge_per_proc ; 00154 const unsigned id_total = nPerProc * p_size ; 00155 const unsigned id_begin = nPerProc * p_rank ; 00156 const unsigned id_end = nPerProc * ( p_rank + 1 ); 00157 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 ); 00158 const unsigned nLocalEdge = nPerProc ; 00159 00160 const unsigned p_send = ( p_rank + 1 ) % p_size ; 00161 const unsigned id_send = id_end - 2 ; 00162 const unsigned id_recv = ( id_begin + id_total - 2 ) % id_total ; 00163 00164 Selector select_used = meta.locally_owned_part() | 00165 meta.globally_shared_part(); 00166 00167 std::vector<unsigned> local_count ; 00168 std::vector<EntityProc> change ; 00169 00170 Entity * send_edge_1 = bulk.get_entity( 1 , ring.m_edge_ids[ id_send ] ); 00171 Entity * send_edge_2 = bulk.get_entity( 1 , ring.m_edge_ids[ id_send + 1 ] ); 00172 Entity * send_node_1 = send_edge_1->relations()[1].entity(); 00173 Entity * send_node_2 = send_edge_2->relations()[1].entity(); 00174 Entity * recv_edge_1 = bulk.get_entity( 1 , ring.m_edge_ids[ id_recv ] ); 00175 Entity * recv_edge_2 = bulk.get_entity( 1 , ring.m_edge_ids[ id_recv + 1 ] ); 00176 00177 STKUNIT_ASSERT( NULL != send_edge_1 && p_rank == send_edge_1->owner_rank() ); 00178 STKUNIT_ASSERT( NULL != send_edge_2 && p_rank == send_edge_2->owner_rank() ); 00179 STKUNIT_ASSERT( NULL == recv_edge_1 || p_rank != recv_edge_1->owner_rank() ); 00180 STKUNIT_ASSERT( NULL == recv_edge_2 || p_rank != recv_edge_2->owner_rank() ); 00181 00182 if ( p_rank == send_node_1->owner_rank() ) { 00183 EntityProc entry( send_node_1 , p_send ); 00184 change.push_back( entry ); 00185 } 00186 if ( p_rank == send_node_2->owner_rank() ) { 00187 EntityProc entry( send_node_2 , p_send ); 00188 change.push_back( entry ); 00189 } 00190 { 00191 EntityProc entry( send_edge_1 , p_send ); 00192 change.push_back( entry ); 00193 } 00194 { 00195 EntityProc entry( send_edge_2 , p_send ); 00196 change.push_back( entry ); 00197 } 00198 00199 send_edge_1 = NULL ; 00200 send_edge_2 = NULL ; 00201 send_node_1 = NULL ; 00202 send_node_2 = NULL ; 00203 recv_edge_1 = NULL ; 00204 recv_edge_2 = NULL ; 00205 00206 STKUNIT_ASSERT( bulk.modification_begin() ); 00207 bulk.change_entity_owner( change ); 00208 STKUNIT_ASSERT( stk_classic::unit_test::modification_end_wrapper( bulk , generate_aura ) ); 00209 00210 send_edge_1 = bulk.get_entity( 1 , ring.m_edge_ids[ id_send ] ); 00211 send_edge_2 = bulk.get_entity( 1 , ring.m_edge_ids[ id_send + 1 ] ); 00212 recv_edge_1 = bulk.get_entity( 1 , ring.m_edge_ids[ id_recv ] ); 00213 recv_edge_2 = bulk.get_entity( 1 , ring.m_edge_ids[ id_recv + 1 ] ); 00214 00215 STKUNIT_ASSERT( NULL == send_edge_1 || p_rank != send_edge_1->owner_rank() ); 00216 STKUNIT_ASSERT( NULL == send_edge_2 || p_rank != send_edge_2->owner_rank() ); 00217 STKUNIT_ASSERT( NULL != recv_edge_1 && p_rank == recv_edge_1->owner_rank() ); 00218 STKUNIT_ASSERT( NULL != recv_edge_2 && p_rank == recv_edge_2->owner_rank() ); 00219 00220 stk_classic::mesh::count_entities( select_used , bulk , local_count ); 00221 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode ); 00222 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge ); 00223 00224 unsigned count_shared = 0 ; 00225 for ( std::vector<Entity*>::const_iterator 00226 i = bulk.entity_comm().begin() ; 00227 i != bulk.entity_comm().end() ; ++i ) { 00228 if ( in_shared( **i ) ) { ++count_shared ; } 00229 } 00230 STKUNIT_ASSERT_EQUAL( count_shared , 2u ); 00231 00232 { 00233 Entity * const node_recv = bulk.get_entity( NODE_RANK , ring.m_node_ids[id_recv] ); 00234 Entity * const node_send = bulk.get_entity( NODE_RANK , ring.m_node_ids[id_send] ); 00235 00236 STKUNIT_ASSERT_EQUAL( node_recv->sharing().size() , 1u ); 00237 STKUNIT_ASSERT_EQUAL( node_send->sharing().size() , 1u ); 00238 } 00239 } 00240 00241 } 00242 }