Sierra Toolkit Version of the Day
UnitTestBoxFixture.cpp
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 
00010 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00011 
00012 #include <stk_mesh/fixtures/BoxFixture.hpp>
00013 
00014 #include <stk_mesh/base/MetaData.hpp>
00015 #include <stk_mesh/base/BulkData.hpp>
00016 #include <stk_mesh/base/Entity.hpp>
00017 #include <stk_mesh/base/Selector.hpp>
00018 #include <stk_mesh/base/GetEntities.hpp>
00019 
00020 using stk::mesh::fem::FEMMetaData;
00021 using stk::mesh::BulkData;
00022 using stk::mesh::Selector;
00023 using stk::mesh::Entity;
00024 using stk::mesh::EntityId;
00025 using stk::mesh::EntityRank;
00026 using stk::mesh::fixtures::BoxFixture;
00027 
00028 namespace {
00029 
00030 const EntityRank NODE_RANK = FEMMetaData::NODE_RANK;
00031 
00032 class ExposePartition : public BoxFixture
00033 {
00034  public:
00035   static void expose_box_partition( int ip , int up , int axis ,
00036                                     const BOX box ,
00037                                     BOX p_box[] )
00038   {
00039     box_partition(ip, up, axis, box, p_box);
00040   }
00041 };
00042 
00043 }
00044 
00045 STKUNIT_UNIT_TEST( UnitTestBoxFixture, verifyBoxFixture )
00046 {
00047   // A unit test to verify the correctness of the BoxFixture fixture.
00048 
00049   stk::ParallelMachine pm = MPI_COMM_WORLD;
00050   MPI_Barrier( pm );
00051 
00052   // Create the box fixture we'll be testing
00053 
00054   // box specifications
00055   const BoxFixture::BOX root_box = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } };
00056   BoxFixture::BOX local_box = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } };
00057 
00058   BoxFixture fixture(pm);
00059   FEMMetaData& meta = fixture.fem_meta();
00060   BulkData& bulk = fixture.bulk_data();
00061 
00062   const EntityRank element_rank = meta.element_rank();
00063 
00064   const unsigned p_rank = bulk.parallel_rank();
00065   const unsigned p_size = bulk.parallel_size();
00066 
00067   BoxFixture::BOX * const p_box = new BoxFixture::BOX[ p_size ];
00068   ExposePartition::expose_box_partition( 0, p_size, 2, root_box, &p_box[0] );
00069 
00070   meta.commit();
00071 
00072   bulk.modification_begin();
00073   fixture.generate_boxes( root_box, local_box );
00074 
00075   const unsigned nx = local_box[0][1] - local_box[0][0] ;
00076   const unsigned ny = local_box[1][1] - local_box[1][0] ;
00077   const unsigned nz = local_box[2][1] - local_box[2][0] ;
00078 
00079   const unsigned e_local = nx * ny * nz ;
00080   const unsigned n_local = ( nx + 1 ) * ( ny + 1 ) * ( nz + 1 );
00081 
00082   const unsigned ngx = root_box[0][1] - root_box[0][0] ;
00083   const unsigned ngy = root_box[1][1] - root_box[1][0] ;
00084 
00085   std::vector<unsigned> local_count ;
00086 
00087   // Verify that the correct entities are on this process
00088 
00089   for ( int k = local_box[2][0] ; k < local_box[2][1] ; ++k ) {
00090   for ( int j = local_box[1][0] ; j < local_box[1][1] ; ++j ) {
00091   for ( int i = local_box[0][0] ; i < local_box[0][1] ; ++i ) {
00092 
00093     const EntityId n0= 1 + (i+0) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00094     const EntityId n1= 1 + (i+1) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00095     const EntityId n2= 1 + (i+1) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00096     const EntityId n3= 1 + (i+0) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00097     const EntityId n4= 1 + (i+0) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00098     const EntityId n5= 1 + (i+1) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00099     const EntityId n6= 1 + (i+1) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00100     const EntityId n7= 1 + (i+0) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00101 
00102     const EntityId elem_id =  1 + i + j * ngx + k * ngx * ngy;
00103 
00104     std::vector<Entity*> nodes(8);
00105     nodes[0] = bulk.get_entity( NODE_RANK, n0 );
00106     nodes[1] = bulk.get_entity( NODE_RANK, n1 );
00107     nodes[2] = bulk.get_entity( NODE_RANK, n2 );
00108     nodes[3] = bulk.get_entity( NODE_RANK, n3 );
00109     nodes[4] = bulk.get_entity( NODE_RANK, n4 );
00110     nodes[5] = bulk.get_entity( NODE_RANK, n5 );
00111     nodes[6] = bulk.get_entity( NODE_RANK, n6 );
00112     nodes[7] = bulk.get_entity( NODE_RANK, n7 );
00113 
00114     Entity* elem = bulk.get_entity( element_rank, elem_id );
00115 
00116     std::vector<Entity*> elems ;
00117     stk::mesh::get_entities_through_relations( nodes , elems );
00118     STKUNIT_ASSERT_EQUAL( elems.size() , size_t(1) );
00119     STKUNIT_ASSERT_EQUAL( elems[0] , elem );
00120 
00121     stk::mesh::get_entities_through_relations(nodes, element_rank, elems);
00122     STKUNIT_ASSERT_EQUAL( elems.size() , size_t(1) );
00123     STKUNIT_ASSERT_EQUAL( elems[0] , elem );
00124 
00125   }
00126   }
00127   }
00128 
00129   Selector select_owned( meta.locally_owned_part() );
00130   Selector select_used = select_owned |
00131                          meta.globally_shared_part();
00132   Selector select_all( meta.universal_part() );
00133 
00134   stk::mesh::count_entities( select_used , bulk , local_count );
00135   STKUNIT_ASSERT_EQUAL( e_local , local_count[3] );
00136   STKUNIT_ASSERT_EQUAL( 0u , local_count[2] );
00137   STKUNIT_ASSERT_EQUAL( 0u , local_count[1] );
00138   STKUNIT_ASSERT_EQUAL( n_local , local_count[0] );
00139 
00140   STKUNIT_ASSERT(bulk.modification_end());
00141 
00142   // Verify declarations and sharing
00143 
00144   stk::mesh::count_entities( select_used , bulk , local_count );
00145   STKUNIT_ASSERT_EQUAL( local_count[3] , e_local );
00146   STKUNIT_ASSERT_EQUAL( local_count[2] , 0u );
00147   STKUNIT_ASSERT_EQUAL( local_count[1] , 0u );
00148   STKUNIT_ASSERT_EQUAL( local_count[0] , n_local );
00149 
00150   for ( int k = local_box[2][0] ; k <= local_box[2][1] ; ++k ) {
00151   for ( int j = local_box[1][0] ; j <= local_box[1][1] ; ++j ) {
00152   for ( int i = local_box[0][0] ; i <= local_box[0][1] ; ++i ) {
00153     EntityRank node_type = 0;
00154     EntityId node_id = 1 + i + j * (ngx+1) + k * (ngx+1) * (ngy+1);
00155     Entity * const node = bulk.get_entity( node_type , node_id );
00156     STKUNIT_ASSERT( node != NULL );
00157     // Shared if on a processor boundary.
00158     const bool shared =
00159       ( k == local_box[2][0] && k != root_box[2][0] ) ||
00160       ( k == local_box[2][1] && k != root_box[2][1] ) ||
00161       ( j == local_box[1][0] && j != root_box[1][0] ) ||
00162       ( j == local_box[1][1] && j != root_box[1][1] ) ||
00163       ( i == local_box[0][0] && i != root_box[0][0] ) ||
00164       ( i == local_box[0][1] && i != root_box[0][1] );
00165     if (bulk.parallel_size() > 1) {
00166       STKUNIT_ASSERT_EQUAL( shared , ! node->sharing().empty() );
00167     }
00168   }
00169   }
00170   }
00171 
00172   size_t count_shared_node_pairs = 0 ;
00173   for ( unsigned p = 0 ; p < p_size ; ++p ) if ( p != p_rank ) {
00174     for ( int k = p_box[p][2][0] ; k <= p_box[p][2][1] ; ++k )
00175       if ( local_box[2][0] <= k && k <= local_box[2][1] ) {
00176 
00177         for ( int j = p_box[p][1][0] ; j <= p_box[p][1][1] ; ++j )
00178           if ( local_box[1][0] <= j && j <= local_box[1][1] ) {
00179 
00180             for ( int i = p_box[p][0][0] ; i <= p_box[p][0][1] ; ++i )
00181               if ( local_box[0][0] <= i && i <= local_box[0][1] ) {
00182 
00183                 EntityRank node_type = 0;
00184                 EntityId node_id = 1 + i + j * (ngx+1) + k * (ngx+1) * (ngy+1);
00185                 Entity * const node = bulk.get_entity( node_type , node_id );
00186                 STKUNIT_ASSERT( node != NULL );
00187                 // Must be shared with 'p'
00188                 stk::mesh::PairIterEntityComm iter = node->sharing();
00189                 for ( ; ! iter.empty() && iter->proc != p ; ++iter );
00190                 STKUNIT_ASSERT( ! iter.empty() );
00191 
00192                 ++count_shared_node_pairs ;
00193               }
00194           }
00195       }
00196   }
00197 
00198   size_t count_shared_entities = 0 ;
00199   for (std::vector<Entity*>::const_iterator
00200        i = bulk.entity_comm().begin() ;
00201        i != bulk.entity_comm().end() ;
00202        ++i) {
00203     const stk::mesh::PairIterEntityComm ec = (**i).sharing();
00204     count_shared_entities += ec.size();
00205   }
00206   STKUNIT_ASSERT_EQUAL( count_shared_entities , count_shared_node_pairs );
00207 
00208   delete [] p_box;
00209 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines