Sierra Toolkit Version of the Day
UnitTestBucket.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 <sstream>
00011 #include <stdexcept>
00012 
00013 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00014 
00015 #include <stk_util/parallel/Parallel.hpp>
00016 
00017 #include <stk_mesh/base/MetaData.hpp>
00018 #include <stk_mesh/base/BulkData.hpp>
00019 #include <stk_mesh/base/GetEntities.hpp>
00020 #include <stk_mesh/base/Field.hpp>
00021 #include <stk_mesh/base/FieldData.hpp>
00022 #include <stk_mesh/base/Comm.hpp>
00023 #include <stk_mesh/base/EntityComm.hpp>
00024 #include <stk_mesh/base/Part.hpp>
00025 #include <stk_mesh/base/Entity.hpp>
00026 #include <stk_mesh/base/GetBuckets.hpp>
00027 #include <stk_mesh/base/Bucket.hpp>
00028 #include <stk_mesh/base/BulkModification.hpp>
00029 
00030 #include <unit_tests/UnitTestBucket.hpp>
00031 #include <unit_tests/UnitTestMesh.hpp>
00032 
00033 #include <Shards_BasicTopologies.hpp>
00034 #include <stk_mesh/fem/TopologicalMetaData.hpp>
00035 
00036 #include <stk_mesh/base/Entity.hpp>
00037 #include <stk_mesh/base/Bucket.hpp>
00038 #include <stk_mesh/base/Transaction.hpp>
00039 #include <stk_mesh/baseImpl/BucketImpl.hpp>
00040 #include <stk_mesh/base/Ghosting.hpp>
00041 
00042 using stk::unit_test::UnitTestBucket;
00043 
00044 using stk::mesh::MetaData;
00045 using stk::mesh::BulkData;
00046 using stk::mesh::Part;
00047 using stk::mesh::PartVector;
00048 using stk::mesh::EntityRank;
00049 using stk::mesh::EntityId;
00050 using stk::mesh::PairIterEntityComm;
00051 using stk::mesh::Entity;
00052 using stk::mesh::Bucket;
00053 using stk::mesh::BucketIterator;
00054 using stk::mesh::Selector;
00055 using stk::mesh::Field;
00056 using stk::mesh::FieldBase;
00057 using stk::mesh::put_field;
00058 using stk::mesh::TopologicalMetaData;
00059 
00060 using stk::ParallelMachine;
00061 using std::cout;
00062 using std::endl;
00063 
00064 
00065 STKUNIT_UNIT_TEST(UnitTestingOfBucket, testUnit)
00066 {
00067   MPI_Barrier( MPI_COMM_WORLD );
00068   UnitTestBucket::testBucket ( MPI_COMM_WORLD );
00069   UnitTestBucket::test_get_involved_parts( MPI_COMM_WORLD );
00070   UnitTestBucket::testBucket2( MPI_COMM_WORLD );
00071   UnitTestBucket::test_EntityComm( MPI_COMM_WORLD );
00072 }
00073 
00074 //----------------------------------------------------------------------
00075 //----------------------------------------------------------------------
00076 
00077 
00078 
00079 // Unit test the Part functionality in isolation:
00080 
00081 void UnitTestBucket::testBucket( ParallelMachine pm )
00082 {
00083   typedef Field<double>  ScalarFieldType;
00084  // static const char method[] = "stk::mesh::UnitTestBucket" ;
00085 
00086  // Create a mesh for testing buckets
00087   cout << endl ;
00088 
00089   std::vector<std::string> entity_names(10);
00090   for ( size_t i = 0 ; i < 10 ; ++i ) {
00091     std::ostringstream name ;
00092     name << "EntityRank" << i ;
00093     entity_names[i] = name.str();
00094   }
00095 
00096   MetaData meta( entity_names );
00097   BulkData bulk( meta , pm , 4 );
00098   const int spatial_dimension = 3;
00099   TopologicalMetaData top(meta,spatial_dimension);
00100 
00101   ScalarFieldType & temperature =
00102        meta.declare_field < ScalarFieldType > ( "temperature" , 4 );
00103   ScalarFieldType & volume =
00104        meta.declare_field < ScalarFieldType > ( "volume" , 4 );
00105   Part  & universal     = meta.universal_part ();
00106   put_field ( temperature , top.node_rank , universal );
00107   put_field ( volume , top.element_rank , universal );
00108   meta.commit();
00109 
00110 
00111   const int root_box[3][2] = { { 0,4 } , { 0,5 } , { 0,6 } };
00112   int local_box[3][2] = { { 0,0 } , { 0,0 } , { 0,0 } };
00113 
00114   bulk.modification_begin();
00115   generate_boxes( bulk , false /* no aura */ , root_box , local_box );
00116   bulk.modification_end();
00117 
00118 
00119  //  First, test for streaming IO;
00120   {
00121     std::string gold1;
00122  // Parallel and Serial runs have different part intersections for the first
00123  // bucket
00124     if ( bulk.parallel_size() == 1 )
00125        gold1 = "Bucket( EntityRank0 : {UNIVERSAL} {OWNS} )";
00126     else
00127        gold1 = "Bucket( EntityRank0 : {UNIVERSAL} )";
00128     Bucket *b1 = bulk.buckets(0)[0];
00129     std::stringstream  out1_str;
00130     out1_str << (*b1);
00131     bool result = out1_str.str() == gold1;
00132     STKUNIT_ASSERT_EQUAL ( result , true );
00133 
00134  // Need to validate print against parallel gold string
00135     std::stringstream  gold2;
00136     gold2 << gold1 << "\n";
00137   }
00138 
00139  // Second, update state of bucket until circular cue is filled
00140   {
00141    /* Need to set some data in state, rotate look for it, rotate 3 more times
00142       and look for it again */
00143     for ( size_t i = 0 ; i != 10 ; ++i )
00144       bulk.update_field_data_states ();
00145   }
00146 
00147  // Third, checking field_data_valid (...)
00148   {
00149 
00150     const std::vector< FieldBase * > &field_bases = meta.get_fields();
00151     STKUNIT_ASSERT_THROW(field_data_valid ( *field_bases[0] , *bulk.buckets(3)[0] , 1 , "error" ) , std::runtime_error);
00152     STKUNIT_ASSERT_EQUAL(field_data_valid ( *field_bases[0] , *bulk.buckets(0)[0] , 1 , "no_error" ) , true);
00153     STKUNIT_ASSERT_THROW(field_data_valid ( *field_bases[0] , *bulk.buckets(3)[0] , 99 , "error" ) , std::runtime_error);
00154 
00155 
00156     MetaData meta2 ( entity_names );
00157     BulkData bulk2( meta2 , pm , 4 );
00158 
00159     ScalarFieldType & temperature2 =
00160        meta2.declare_field < ScalarFieldType > ( "temperature2" , 4 );
00161     ScalarFieldType & volume2 =
00162        meta2.declare_field < ScalarFieldType > ( "volume2" , 4 );
00163     Part  & universal2     = meta2.universal_part ();
00164     put_field ( temperature2 , top.node_rank , universal2 );
00165     put_field ( volume2 , top.element_rank, universal2 );
00166     meta2.commit();
00167 
00168     //Cover line containing messsage for wrong MetaData used
00169     const std::vector< FieldBase * > &field_bases2 = meta2.get_fields();
00170     STKUNIT_ASSERT_THROW(field_data_valid ( *field_bases2[0] , *bulk.buckets(0)[0] , 1 , "error" ) , std::runtime_error);
00171 
00172   }
00173 
00174  // Fourth, check has_superset (...) and membership functions
00175   {
00176     PartVector tmp(2) ;
00177     tmp[0] = & meta.universal_part();
00178     tmp[1] = & meta.locally_owned_part();
00179     STKUNIT_ASSERT_EQUAL ( has_superset ( *bulk.buckets(0)[0] , tmp ) , bulk.parallel_size() == 1 );
00180     STKUNIT_ASSERT ( bulk.buckets(0)[0]->member_any ( tmp ) );
00181     STKUNIT_ASSERT_EQUAL ( bulk.buckets(0)[0]->member_all ( tmp ) , bulk.parallel_size() == 1 );
00182     STKUNIT_ASSERT ( bulk.buckets(0)[0]->member ( **meta.get_parts().begin() ) );
00183   }
00184 
00185  // Fifth, check throw_field_data_array (...)
00186   {
00187     STKUNIT_ASSERT_THROW ( throw_field_data_array ( *meta.get_fields()[0] , 10 ) , std::runtime_error );
00188   }
00189 }
00190 
00191 
00192 //----------------------------------------------------------------------
00193 
00194 namespace {
00195 
00196 /* Recursively split a box into ( up - ip ) sub-boxes */
00197 
00198 typedef int BOX[3][2] ;
00199 
00200 void box_partition( int ip , int up , int axis ,
00201                     const BOX box ,
00202                     BOX p_box[] )
00203 {
00204   const int np = up - ip ;
00205   if ( 1 == np ) {
00206     p_box[ip][0][0] = box[0][0] ; p_box[ip][0][1] = box[0][1] ;
00207     p_box[ip][1][0] = box[1][0] ; p_box[ip][1][1] = box[1][1] ;
00208     p_box[ip][2][0] = box[2][0] ; p_box[ip][2][1] = box[2][1] ;
00209   }
00210   else {
00211     const int n = box[ axis ][1] - box[ axis ][0] ;
00212     const int np_low = np / 2 ;  /* Rounded down */
00213     const int np_upp = np - np_low ;
00214 
00215     const int n_upp = (int) (((double) n) * ( ((double)np_upp) / ((double)np)));
00216     const int n_low = n - n_upp ;
00217     const int next_axis = ( axis + 2 ) % 3 ;
00218 
00219     if ( np_low ) { /* P = [ip,ip+np_low) */
00220       BOX dbox ;
00221       dbox[0][0] = box[0][0] ; dbox[0][1] = box[0][1] ;
00222       dbox[1][0] = box[1][0] ; dbox[1][1] = box[1][1] ;
00223       dbox[2][0] = box[2][0] ; dbox[2][1] = box[2][1] ;
00224 
00225       dbox[ axis ][1] = dbox[ axis ][0] + n_low ;
00226 
00227       box_partition( ip, ip + np_low, next_axis,
00228                      (const int (*)[2]) dbox, p_box );
00229     }
00230 
00231     if ( np_upp ) { /* P = [ip+np_low,ip+np_low+np_upp) */
00232       BOX dbox ;
00233       dbox[0][0] = box[0][0] ; dbox[0][1] = box[0][1] ;
00234       dbox[1][0] = box[1][0] ; dbox[1][1] = box[1][1] ;
00235       dbox[2][0] = box[2][0] ; dbox[2][1] = box[2][1] ;
00236 
00237       ip += np_low ;
00238       dbox[ axis ][0] += n_low ;
00239       dbox[ axis ][1]  = dbox[ axis ][0] + n_upp ;
00240 
00241       box_partition( ip, ip + np_upp, next_axis,
00242                      (const int (*)[2]) dbox, p_box );
00243     }
00244   }
00245 }
00246 
00247 }
00248 
00249 void UnitTestBucket::generate_boxes(
00250   BulkData  & mesh ,
00251   const bool  generate_aura ,
00252   const int   root_box[][2] ,
00253         int   local_box[][2] )
00254 {
00255   const unsigned p_rank = mesh.parallel_rank();
00256   const unsigned p_size = mesh.parallel_size();
00257   const unsigned ngx = root_box[0][1] - root_box[0][0] ;
00258   const unsigned ngy = root_box[1][1] - root_box[1][0] ;
00259   const unsigned ngz = root_box[2][1] - root_box[2][0] ;
00260 /*
00261   const unsigned e_global = ngx * ngy * ngz ;
00262   const unsigned n_global = ( ngx + 1 ) * ( ngy + 1 ) * ( ngz + 1 );
00263 */
00264 
00265   if ( 0 == p_rank ) {
00266     std::cout << "Global box = " << ngx << " x " << ngy << " x " << ngz
00267               << endl ;
00268   }
00269 
00270   BOX * const p_box = new BOX[ p_size ];
00271 
00272   box_partition( 0 , p_size , 2 , root_box , & p_box[0] );
00273 
00274   local_box[0][0] = p_box[ p_rank ][0][0] ;
00275   local_box[0][1] = p_box[ p_rank ][0][1] ;
00276   local_box[1][0] = p_box[ p_rank ][1][0] ;
00277   local_box[1][1] = p_box[ p_rank ][1][1] ;
00278   local_box[2][0] = p_box[ p_rank ][2][0] ;
00279   local_box[2][1] = p_box[ p_rank ][2][1] ;
00280 
00281   const unsigned nx = local_box[0][1] - local_box[0][0] ;
00282   const unsigned ny = local_box[1][1] - local_box[1][0] ;
00283   const unsigned nz = local_box[2][1] - local_box[2][0] ;
00284 
00285   const unsigned e_local = nx * ny * nz ;
00286   const unsigned n_local = ( nx + 1 ) * ( ny + 1 ) * ( nz + 1 );
00287 
00288   // Create elements:
00289 
00290   std::vector<unsigned> local_count ;
00291 
00292   const PartVector no_parts ;
00293 
00294   for ( int k = local_box[2][0] ; k < local_box[2][1] ; ++k ) {
00295   for ( int j = local_box[1][0] ; j < local_box[1][1] ; ++j ) {
00296   for ( int i = local_box[0][0] ; i < local_box[0][1] ; ++i ) {
00297     const EntityId n0 = 1 + (i+0) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00298     const EntityId n1 = 1 + (i+1) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00299     const EntityId n2 = 1 + (i+1) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00300     const EntityId n3 = 1 + (i+0) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1);
00301     const EntityId n4 = 1 + (i+0) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00302     const EntityId n5 = 1 + (i+1) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00303     const EntityId n6 = 1 + (i+1) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00304     const EntityId n7 = 1 + (i+0) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1);
00305 
00306     const EntityId elem_id =  1 + i + j * ngx + k * ngx * ngy;
00307 
00308     Entity & node0 = mesh.declare_entity( 0 , n0 , no_parts );
00309     Entity & node1 = mesh.declare_entity( 0 , n1 , no_parts );
00310     Entity & node2 = mesh.declare_entity( 0 , n2 , no_parts );
00311     Entity & node3 = mesh.declare_entity( 0 , n3 , no_parts );
00312     Entity & node4 = mesh.declare_entity( 0 , n4 , no_parts );
00313     Entity & node5 = mesh.declare_entity( 0 , n5 , no_parts );
00314     Entity & node6 = mesh.declare_entity( 0 , n6 , no_parts );
00315     Entity & node7 = mesh.declare_entity( 0 , n7 , no_parts );
00316     Entity & elem  = mesh.declare_entity( 3 , elem_id , no_parts );
00317 
00318     mesh.declare_relation( elem , node0 , 0 );
00319     mesh.declare_relation( elem , node1 , 1 );
00320     mesh.declare_relation( elem , node2 , 2 );
00321     mesh.declare_relation( elem , node3 , 3 );
00322     mesh.declare_relation( elem , node4 , 4 );
00323     mesh.declare_relation( elem , node5 , 5 );
00324     mesh.declare_relation( elem , node6 , 6 );
00325     mesh.declare_relation( elem , node7 , 7 );
00326   }
00327   }
00328   }
00329 
00330   Selector select_owned( mesh.mesh_meta_data().locally_owned_part() );
00331   Selector select_used = select_owned | mesh.mesh_meta_data().globally_shared_part();
00332   Selector select_all(  mesh.mesh_meta_data().universal_part() );
00333 
00334   count_entities( select_used , mesh , local_count );
00335   STKUNIT_ASSERT_EQUAL( e_local , local_count[3] );
00336   STKUNIT_ASSERT_EQUAL( 0u , local_count[2] );
00337   STKUNIT_ASSERT_EQUAL( 0u , local_count[1] );
00338   STKUNIT_ASSERT_EQUAL( n_local , local_count[0] );
00339 
00340   // Set up sharing:
00341   mesh.modification_end();
00342 
00343   // Verify declarations and sharing
00344 
00345   count_entities( select_used , mesh , local_count );
00346   STKUNIT_ASSERT( local_count[3] == e_local );
00347   STKUNIT_ASSERT( local_count[2] == 0 );
00348   STKUNIT_ASSERT( local_count[1] == 0 );
00349   STKUNIT_ASSERT( local_count[0] == n_local );
00350 
00351   for ( int k = local_box[2][0] ; k <= local_box[2][1] ; ++k ) {
00352   for ( int j = local_box[1][0] ; j <= local_box[1][1] ; ++j ) {
00353   for ( int i = local_box[0][0] ; i <= local_box[0][1] ; ++i ) {
00354     EntityRank node_type = 0;
00355     EntityId node_id = 1 + i + j * (ngx+1) + k * (ngx+1) * (ngy+1);
00356     Entity * const node = mesh.get_entity( node_type , node_id );
00357     STKUNIT_ASSERT( node != NULL );
00358     // Shared if on a processor boundary.
00359     const bool shared =
00360       ( k == local_box[2][0] && k != root_box[2][0] ) ||
00361       ( k == local_box[2][1] && k != root_box[2][1] ) ||
00362       ( j == local_box[1][0] && j != root_box[1][0] ) ||
00363       ( j == local_box[1][1] && j != root_box[1][1] ) ||
00364       ( i == local_box[0][0] && i != root_box[0][0] ) ||
00365       ( i == local_box[0][1] && i != root_box[0][1] );
00366     if (mesh.parallel_size() > 1) {
00367       STKUNIT_ASSERT_EQUAL( shared , ! node->sharing().empty() );
00368     }
00369   }
00370   }
00371   }
00372 
00373   size_t count_shared_node_pairs = 0 ;
00374   for ( unsigned p = 0 ; p < p_size ; ++p ) if ( p != p_rank ) {
00375     for ( int k = p_box[p][2][0] ; k <= p_box[p][2][1] ; ++k )
00376     if ( local_box[2][0] <= k && k <= local_box[2][1] ) {
00377 
00378       for ( int j = p_box[p][1][0] ; j <= p_box[p][1][1] ; ++j )
00379       if ( local_box[1][0] <= j && j <= local_box[1][1] ) {
00380 
00381         for ( int i = p_box[p][0][0] ; i <= p_box[p][0][1] ; ++i )
00382         if ( local_box[0][0] <= i && i <= local_box[0][1] ) {
00383 
00384           EntityRank node_type = 0;
00385           EntityId node_id = 1 + i + j * (ngx+1) + k * (ngx+1) * (ngy+1);
00386           Entity * const node = mesh.get_entity( node_type , node_id );
00387           STKUNIT_ASSERT( node != NULL );
00388           // Must be shared with 'p'
00389           PairIterEntityComm iter = node->sharing();
00390           for ( ; ! iter.empty() && iter->proc != p ; ++iter );
00391           STKUNIT_ASSERT( ! iter.empty() );
00392 
00393 
00394           ++count_shared_node_pairs ;
00395         }
00396       }
00397     }
00398   }
00399 
00400   size_t count_shared_entities = 0 ;
00401   for ( std::vector<Entity*>::const_iterator
00402         i = mesh.entity_comm().begin() ; i != mesh.entity_comm().end() ; ++i ) {
00403     const PairIterEntityComm ec = (**i).sharing();
00404     count_shared_entities += ec.size();
00405   }
00406   STKUNIT_ASSERT_EQUAL( count_shared_entities , count_shared_node_pairs );
00407 
00408   delete[] p_box ;
00409 }
00410 
00411 
00412 void UnitTestBucket::test_get_involved_parts(ParallelMachine pm)
00413 {
00414 
00415   // Tests to cover get_involved_parts for GetBuckets.cpp - C.Brickley - 12 May 2010
00416 
00417   const int spatial_dimension = 3;
00418   MetaData meta ( TopologicalMetaData::entity_rank_names ( spatial_dimension ) );
00419   TopologicalMetaData top( meta, spatial_dimension );
00420 
00421   PartVector involved_parts(2) ;
00422   involved_parts[0] = & meta.universal_part();
00423   involved_parts[1] = & meta.locally_owned_part();
00424 
00425   Part & partLeft_1 = top.declare_part<shards::Tetrahedron<4> >( "block_left_1" );
00426 
00427   Part & partLeft_2 = top.declare_part<shards::Tetrahedron<4> >( "block_left_2" );
00428 
00429   meta.commit();
00430 
00431   PartVector union_parts;
00432   union_parts.push_back(&partLeft_1);
00433   union_parts.push_back(&partLeft_2);
00434 
00435   BulkData bulk( meta , pm , 100 );
00436   PartVector add_part4, no_part;
00437   add_part4.push_back ( &partLeft_1 );
00438 
00439   bulk.modification_begin();
00440   int  size , rank;
00441   rank = stk::parallel_machine_rank( pm );
00442   size = stk::parallel_machine_size( pm );
00443 
00444   for ( int id_base = 0 ; id_base < 99 ; ++id_base )
00445   {
00446     int new_id = size * id_base + rank + 1;
00447     bulk.declare_entity( 3 , new_id , add_part4 );
00448     bulk.declare_entity( top.node_rank , new_id , no_part );
00449   }
00450 
00451   bulk.modification_end();
00452 
00453   const std::vector<Bucket*> & buckets = bulk.buckets( top.element_rank );
00454 
00455   std::vector<Bucket*>::const_iterator k;
00456 
00457   k = buckets.begin();
00458 
00459   //test 1 covers aecond section of "if" statement in while loop
00460   get_involved_parts( union_parts, **k, involved_parts);
00461 
00462   //test 2 covers union_parts.size() = 0
00463   PartVector union_parts2(0) ;
00464   get_involved_parts( union_parts2, **k, involved_parts);
00465 
00466   //test 3 covers first section of "if" statement in while loop
00467   const std::vector<Bucket*> & buckets2 = bulk.buckets( top.node_rank );
00468   std::vector<Bucket*>::const_iterator k2;
00469 
00470   k2 = buckets2.begin();
00471   get_involved_parts( union_parts, **k2, involved_parts);
00472 
00473   // tests on throw_error and BucketIterator in bucket.cpp/hpp
00474 
00475   std::vector<std::string> entity_names(10);
00476   for ( size_t i = 0 ; i < 10 ; ++i ) {
00477     std::ostringstream name ;
00478     name << "EntityRank" << i ;
00479     entity_names[i] = name.str();
00480   }
00481   typedef Field<double>  ScalarFieldType;
00482 
00483   MetaData meta2 ( entity_names );
00484   BulkData bulk2( meta2 , pm , 4 );
00485 
00486   ScalarFieldType & temperature2 =
00487      meta2.declare_field < ScalarFieldType > ( "temperature2" , 4 );
00488   ScalarFieldType & volume2 =
00489      meta2.declare_field < ScalarFieldType > ( "volume2" , 4 );
00490   Part  & universal     = meta2.universal_part ();
00491   put_field ( temperature2 , top.node_rank , universal );
00492   put_field ( volume2 , top.element_rank , universal );
00493   meta2.commit();
00494 
00495   bulk2.modification_begin();
00496   bulk2.declare_entity( top.edge_rank, rank+1 , no_part );
00497   bulk2.modification_end();
00498 
00499   const std::vector<Bucket*> & buckets3 = bulk2.buckets( top.edge_rank );
00500 
00501   std::vector<Bucket*>::const_iterator k3;
00502 
00503   k3 = buckets3.begin();
00504 
00505   Bucket& b3 = **k3;
00506   BucketIterator bitr3 = b3.begin();
00507 
00508   Bucket& b2 = **k2;
00509   BucketIterator bitr2 = b2.begin();
00510 
00511   //tests operator != given iterator from different bucket - bucket.hpp
00512 
00513   {
00514     int ok = 0 ;
00515     try {
00516 
00517       if ( bitr2  !=  bitr3 ){
00518         // bitr3.throw_error("is NULL") ;
00519       }
00520 
00521     }
00522     catch( const std::exception & x ) {
00523       ok = 1 ;
00524       cout << "UnitTestBucket CORRECTLY caught error for : "
00525                 << x.what()
00526                 << endl ;
00527     }
00528 
00529     if ( ! ok ) {
00530       throw std::runtime_error("UnitTestBucket FAILED to catch error for throw_error");
00531     }
00532   }
00533 
00534   //tests operator - given iterator from different bucket - bucket.hpp
00535   {
00536     int ok = 0 ;
00537     try {
00538 
00539     const ptrdiff_t n = bitr2 - bitr3 ;
00540 
00541       if ( n  !=  0 ){
00542         // bitr3.throw_error("is NULL") ;
00543       }
00544     }
00545     catch( const std::exception & x ) {
00546       ok = 1 ;
00547       cout << "UnitTestBucket CORRECTLY caught error for : "
00548                 << x.what()
00549                 << endl ;
00550     }
00551 
00552     if ( ! ok ) {
00553       throw std::runtime_error("UnitTestBucket FAILED to catch error for iterator from a different bucket");
00554     }
00555   }
00556 
00557 }
00558 
00559 
00560 void UnitTestBucket::testBucket2(ParallelMachine pm)
00561 {
00562 
00563   // Tests to cover print, has_superset and BucketLess::operator() for Buckets.cpp - C.Brickley - 2nd June 2010
00564 
00565   const int spatial_dimension = 3;
00566   MetaData meta ( TopologicalMetaData::entity_rank_names ( spatial_dimension ) );
00567   TopologicalMetaData top( meta, spatial_dimension );
00568 
00569   PartVector involved_parts(2) ;
00570   involved_parts[0] = & meta.universal_part();
00571   involved_parts[1] = & meta.locally_owned_part();
00572 
00573   Part & partLeft_1 = meta.declare_part( "block_left_1", top.element_rank );
00574 
00575   Part & partLeft_3 = top.declare_part<shards::Tetrahedron<4> >( "block_left_3" );
00576 
00577   meta.commit();
00578 
00579   BulkData bulk( meta , pm , 100 );
00580   std::vector<Part *>  add_part4;
00581   add_part4.push_back ( &partLeft_1 );
00582 
00583   bulk.modification_begin();
00584   int  size , rank;
00585   rank = stk::parallel_machine_rank( pm );
00586   size = stk::parallel_machine_size( pm );
00587 
00588   for ( int id_base = 0 ; id_base < 99 ; ++id_base )
00589   {
00590     int new_id = size * id_base + rank;
00591     bulk.declare_entity( 3 , new_id+1 , add_part4 );
00592   }
00593 
00594   bulk.modification_end();
00595 
00596   const std::vector<Bucket*> & buckets2 = bulk.buckets( top.element_rank );
00597 
00598   std::vector<Bucket*>::const_iterator k2;
00599 
00600   k2 = buckets2.begin();
00601 
00602   Bucket& b2 = **k2;
00603   BucketIterator bitr2 = b2.begin();
00604 
00605   //define a new meta and bulkdata
00606   std::vector<std::string> entity_names(10);
00607 
00608   for ( size_t i = 0 ; i < 10 ; ++i ) {
00609     std::ostringstream name ;
00610     name << "EntityRank" << i ;
00611     entity_names[i] = name.str();
00612   }
00613 
00614   typedef Field<double>  ScalarFieldType;
00615 
00616   MetaData meta2 ( entity_names );
00617   BulkData bulk2( meta2 , pm , 4 );
00618 
00619   ScalarFieldType & temperature2 =
00620        meta2.declare_field < ScalarFieldType > ( "temperature2" , 4 );
00621   ScalarFieldType & volume2 =
00622        meta2.declare_field < ScalarFieldType > ( "volume2" , 4 );
00623   Part  & universal     = meta2.universal_part ();
00624   put_field ( temperature2 , top.node_rank , universal );
00625   put_field ( volume2 , top.element_rank , universal );
00626 
00627   typedef Field<double>  VectorFieldType;
00628   typedef Field<double>  ElementNodePointerFieldType;
00629 
00630   meta2.commit();
00631 
00632   //Test to cover print function in Bucket.cpp
00633   cout << endl << "Bucket test" << endl ;
00634   print(cout, "  ", b2);
00635 
00636   //Test to cover has_superset function in Bucket.cpp
00637   STKUNIT_ASSERT_EQUAL ( has_superset ( b2 , partLeft_3 ) , false );
00638 
00639   //Test on BucketLess::operator() in Bucket.cpp/hpp
00640 
00641   enum { KEY_TMP_BUFFER_SIZE = 64 };
00642 
00643   const unsigned max = ~(0u);
00644 
00645   unsigned key_tmp_buffer[ KEY_TMP_BUFFER_SIZE ];
00646 
00647   std::vector<unsigned> key_tmp_vector ;
00648 
00649   const unsigned key_size = 2 + 3 ;
00650 
00651   unsigned * const key =
00652     ( key_size <= KEY_TMP_BUFFER_SIZE )
00653     ? key_tmp_buffer
00654     : ( key_tmp_vector.resize( key_size ) , & key_tmp_vector[0] );
00655 
00656 
00657   key[ key[0] = 3 + 1 ] = max;
00658 
00659   {
00660     unsigned * const k = key + 1 ;
00661     for ( unsigned i = 0 ; i < 3 ; ++i ) { k[i] = 1 ; }
00662   }
00663 
00664   /*
00665   impl::BucketImpl::last_bucket_in_family( *k2 );
00666 
00667   const unsigned * t = key;
00668   const Bucket * u = last_bucket;
00669 
00670   BucketLess Buck;
00671 
00672   bool res = Buck(  &t[0], &u[0] );
00673 
00674   STKUNIT_EXPECT_EQUAL( res, false );
00675   */
00676 }
00677 
00678 void UnitTestBucket::test_EntityComm( ParallelMachine pm )
00679 {
00680   const int spatial_dimension = 3;
00681   MetaData meta ( TopologicalMetaData::entity_rank_names ( spatial_dimension ) );
00682   TopologicalMetaData top( meta, spatial_dimension );
00683 
00684   BulkData bulk ( meta , pm , 100 );
00685   std::vector<Part *>  add_part4;
00686 
00687   cout << endl << "Bucket test line 0.1" << endl ;
00688   Part & partLeft_1 = top.declare_part<shards::Tetrahedron<4> >( "block_left_1" );
00689   cout << endl << "Bucket test line 0.2" << endl;
00690   meta.commit();
00691 
00692   add_part4.push_back ( &partLeft_1 );
00693 
00694   int  size , rank;
00695   rank = stk::parallel_machine_rank( pm );
00696   size = stk::parallel_machine_size( pm );
00697   PartVector tmp(1);
00698 
00699   bulk.modification_begin();
00700   cout << endl << "Bucket test line 1" << endl ;
00701   //int id_base = 0;
00702   //int new_id = size * id_base + rank;
00703   //  for ( id_base = 0 ; id_base < 93 ; ++id_base )
00704   //  {
00705   //   int new_id = size * id_base + rank;
00706   //   bulk.declare_entity( 0 , new_id+1 , add_part4 );
00707   //  }
00708 
00709   bulk.modification_end();
00710 
00711   /*  cout << endl << "Bucket test line 3" << endl ;
00712   bool result = in_shared(elem);
00713   if( result) {
00714      STKUNIT_ASSERT_EQUAL( result , true );
00715   }
00716   cout << endl << "Bucket test line 4" << endl ;
00717 
00718   result = in_receive_ghost(elem);
00719   if( result) {
00720      STKUNIT_ASSERT_EQUAL( result , true );
00721   }
00722 
00723     for ( unsigned p = 0 ; p < p_size ; ++p ) if ( p != p_rank ) {
00724       cout << endl << "in relation h and p =" << p << endl ;
00725 
00726       STKUNIT_ASSERT_EQUAL( in_send_ghost( *elem , p ), false );
00727       cout << endl << "in relation ii =" << endl
00728    }
00729 
00730   cout << endl << "Bucket test line 5" << endl ;
00731   result = in_send_ghost(elem);
00732   if( result) {
00733      STKUNIT_ASSERT_EQUAL( result , true );
00734      }
00735 
00736   cout << endl << "Bucket test line 6" << endl ;
00737 
00738   unsigned proc = rank;
00739   unsigned procnew = rank+10;
00740 
00741   result = in_shared(elem, proc);
00742   if( result) {
00743      STKUNIT_ASSERT_EQUAL( result , true );
00744   }
00745   cout << endl << "Bucket test line 7" << endl ;  */
00746 }
00747 
00748 //----------------------------------------------------------------------
00749 //----------------------------------------------------------------------
00750 
00751 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends