Sierra Toolkit Version of the Day
UnitTestTransactionLog.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 
00016 #if 0
00017 
00018 #include <sstream>
00019 #include <stdexcept>
00020 
00021 #include <unit_tests/stk_utest_macros.hpp>
00022 
00023 #include <stk_util/parallel/Parallel.hpp>
00024 
00025 #include <stk_mesh/base/BulkData.hpp>
00026 #include <stk_mesh/base/GetEntities.hpp>
00027 #include <stk_mesh/base/Field.hpp>
00028 #include <stk_mesh/base/FieldData.hpp>
00029 #include <stk_mesh/base/Comm.hpp>
00030 #include <stk_mesh/base/GetBuckets.hpp>
00031 
00032 
00033 #include <stk_mesh/fixtures/BoxFixture.hpp>
00034 
00039 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyBulkOnCreate)
00040 {
00041   stk::mesh::MetaData meta ( stk::mesh::fem_entity_rank_names() );
00042   stk::mesh::Part  &new_part = meta.declare_part ( "another part" );
00043   meta.commit ();
00044 
00045   stk::ParallelMachine comm(MPI_COMM_WORLD);
00046   stk::mesh::BulkData bulk ( meta , comm , 100 );
00047   std::vector<stk::mesh::Part *>  add_part;
00048   add_part.push_back ( &new_part );
00049 
00050   int  size , rank;
00051   rank = stk::parallel_machine_rank( comm );
00052   size = stk::parallel_machine_size( comm );
00053 
00054   for ( int i = 0 ; i != 100 ; i++ )
00055   {
00056     int new_id = size*i+rank;
00057     bulk.declare_entity ( 0 , new_id+1 , add_part );
00058   }
00059   bulk.modification_end();
00060 
00061   // If something shows up in the insert incremental log, then
00062   // not in bulk state
00063   STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(0).size() == 0 );
00064   STKUNIT_ASSERT ( bulk.get_transaction_log().get_modified_buckets(0).size() == 0 );
00065   STKUNIT_ASSERT ( bulk.get_transaction_log().get_deleted_buckets(0).size() == 0 );
00066 
00067   // Verify that things are inserted in the bulk transaction
00068   stk::mesh::PartVector  inserted_parts;
00069   bulk.get_transaction_log().get_parts_with_inserted_entities ( inserted_parts );
00070   STKUNIT_ASSERT ( inserted_parts.size() > 0 );
00071 }
00072 
00078 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyBulkInsert)
00079 {
00080   stk::mesh::fixtures::BoxFixture fixture;
00081   stk::mesh::BulkData             &bulk = fixture.bulk_data();
00082   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00083 
00084   stk::mesh::Part                       &new_part = fixture.get_test_part ();
00085   stk::mesh::PartVector                  add_part;
00086   add_part.push_back ( &new_part );
00087 
00088   // This test need only run in serial
00089   if ( fixture.comm_size() > 1 ) return;
00090 
00091   bulk.reset_transaction ( stk::mesh::Transaction::BULK );
00092   bulk.modification_begin ();
00093   bulk.declare_entity ( 0 , fixture.comm_size()*1000 + fixture.comm_rank() , add_part );
00094   bulk.modification_end ();
00095 
00096   // Verify the entity did not go into the log explicitly
00097   STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(0).size() == 0 );
00098 
00099   // Check to see if the new_part is in the inserted parts;
00100   stk::mesh::PartVector                  inserted_parts;
00101   bool  found = false;
00102   bulk.get_transaction_log().get_parts_with_inserted_entities ( inserted_parts );
00103   for ( size_t i = 0 ; i != inserted_parts.size() ; i++ )
00104   {
00105     if ( inserted_parts[i] == &new_part )
00106       found = true;
00107   }
00108   STKUNIT_ASSERT ( found );
00109 
00110   // Verify there is nothing in the modified_parts set
00111   stk::mesh::PartVector  modified_parts;
00112   found = false;
00113   bulk.get_transaction_log().get_parts_with_modified_entities ( modified_parts );
00114   for ( size_t i = 0 ; i != modified_parts.size() ; i++ )
00115   {
00116     if ( modified_parts[i] == &new_part )
00117       found = true;
00118   }
00119   STKUNIT_ASSERT ( !found );
00120 
00121   // Verify there is nothing in the deleted_parts set
00122   stk::mesh::PartVector  deleted_parts;
00123   found = false;
00124   bulk.get_transaction_log().get_parts_with_deleted_entities ( deleted_parts );
00125   for ( size_t i = 0 ; i != deleted_parts.size() ; i++ )
00126   {
00127     if ( deleted_parts[i] == &new_part )
00128       found = true;
00129   }
00130   STKUNIT_ASSERT ( !found );
00131 }
00132 
00133 
00139 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyBulkModify)
00140 {
00141   stk::mesh::fixtures::BoxFixture fixture;
00142   stk::mesh::BulkData    &bulk = fixture.bulk_data();
00143   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00144 
00145   stk::mesh::Part        &new_part = fixture.get_test_part();
00146   stk::mesh::PartVector   add_part,blank_part;
00147   add_part.push_back ( &new_part );
00148 
00149   // This test need only run in serial
00150   if ( fixture.comm_size() > 1 ) return;
00151 
00152   bulk.reset_transaction ( stk::mesh::Transaction::BULK );
00153   bulk.modification_begin ();
00154   stk::mesh::Entity &new_entity = bulk.declare_entity ( 0 , fixture.comm_size()*1000 + fixture.comm_rank() , add_part );
00155   bulk.modification_end ();
00156 
00157   bulk.reset_transaction ( stk::mesh::Transaction::BULK );
00158   bulk.modification_begin ();
00159   bulk.change_entity_parts ( new_entity , blank_part , add_part );
00160   bulk.modification_end ();
00161 
00162   STKUNIT_ASSERT ( bulk.get_transaction_log().get_modified_buckets(0).size() == 0 );
00163 
00164   stk::mesh::PartVector  inserted_parts;
00165   bool  found = false;
00166   bulk.get_transaction_log().get_parts_with_inserted_entities ( inserted_parts );
00167   for ( size_t i = 0 ; i != inserted_parts.size() ; i++ )
00168   {
00169     if ( inserted_parts[i] == &new_part )
00170       found = true;
00171   }
00172   STKUNIT_ASSERT ( !found );
00173 
00174   stk::mesh::PartVector  modified_parts;
00175   found = false;
00176   bulk.get_transaction_log().get_parts_with_modified_entities ( modified_parts );
00177   for ( size_t i = 0 ; i != modified_parts.size() ; i++ )
00178   {
00179     if ( modified_parts[i] == &new_part )
00180       found = true;
00181   }
00182   STKUNIT_ASSERT ( found );
00183 
00184   stk::mesh::PartVector  deleted_parts;
00185   found = false;
00186   bulk.get_transaction_log().get_parts_with_deleted_entities ( deleted_parts );
00187   for ( size_t i = 0 ; i != deleted_parts.size() ; i++ )
00188   {
00189     if ( deleted_parts[i] == &new_part )
00190       found = true;
00191   }
00192   STKUNIT_ASSERT ( !found );
00193 }
00194 
00200 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyBulkAddRelation)
00201 {
00202   stk::mesh::fixtures::BoxFixture fixture;
00203   fixture.generate_boxes();
00204   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00205   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00206 
00207   stk::mesh::Part                       &new_part = fixture.get_test_part();
00208   stk::mesh::PartVector   add_part,blank_part, buffer_vec;
00209   const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00210   add_part.push_back ( &new_part );
00211 
00212   // This test need only run in serial
00213   if ( fixture.comm_size() > 1 ) return;
00214 
00215   bulk.reset_transaction ( stk::mesh::Transaction::BULK );
00216   bulk.modification_begin();
00217   stk::mesh::Entity  &new_node = bulk.declare_entity ( 0 , 123456789 , blank_part );
00218   stk::mesh::Entity  &existing_cell = *bulk.buckets(3)[0]->begin();
00219   bulk.declare_relation ( existing_cell, new_node , 10 );
00220   bulk.modification_end();
00221 
00222   // Verify that nodes were inserted.
00223   log.get_parts_with_inserted_entities ( buffer_vec );
00224   STKUNIT_ASSERT ( buffer_vec.size() > 0u );
00225 
00226   // Verify that the element is modified
00227   buffer_vec.clear();
00228   log.get_parts_with_modified_entities ( buffer_vec );
00229   STKUNIT_ASSERT ( buffer_vec.size() > 0u );
00230 
00231 }
00232 
00233 
00239 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyBulkDelete)
00240 {
00241   stk::mesh::fixtures::BoxFixture fixture;
00242   stk::mesh::BulkData             &bulk = fixture.bulk_data();
00243   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00244 
00245   stk::mesh::Part                       &new_part = fixture.get_test_part();
00246   stk::mesh::PartVector   add_part,blank_part;
00247   add_part.push_back ( &new_part );
00248 
00249 
00250   // This test need only run in serial
00251   if ( fixture.comm_size() > 1 ) return;
00252 
00253   bulk.reset_transaction ( stk::mesh::Transaction::BULK );
00254   bulk.modification_begin ();
00255   stk::mesh::Entity *new_entity = &bulk.declare_entity ( 0 , fixture.comm_size()*1000 + fixture.comm_rank() , add_part );
00256   bulk.modification_end ();
00257 
00258   bulk.reset_transaction ( stk::mesh::Transaction::BULK );
00259   bulk.modification_begin ();
00260   bulk.destroy_entity ( new_entity );
00261   bulk.modification_end ();
00262 
00263   STKUNIT_ASSERT ( bulk.get_transaction_log().get_deleted_buckets(0).size() == 0 );
00264 
00265   stk::mesh::PartVector                  inserted_parts;
00266   stk::mesh::PartVector                  modified_parts;
00267   stk::mesh::PartVector                  deleted_parts;
00268   bool  inserted_found = false;
00269   bulk.get_transaction_log().get_parts_with_inserted_entities ( inserted_parts );
00270   for ( size_t i = 0 ; i != deleted_parts.size() ; i++ )
00271   {
00272     if ( inserted_parts[i] == &new_part )
00273       inserted_found = true;
00274   }
00275   STKUNIT_ASSERT ( !inserted_found );
00276 
00277   bool modified_found = false;
00278   bulk.get_transaction_log().get_parts_with_modified_entities ( modified_parts );
00279   for ( size_t i = 0 ; i != deleted_parts.size() ; i++ )
00280   {
00281     if ( modified_parts[i] == &new_part )
00282       modified_found = true;
00283   }
00284   STKUNIT_ASSERT ( !modified_found );
00285 
00286   bool deleted_found = false;
00287   bulk.get_transaction_log().get_parts_with_deleted_entities ( deleted_parts );
00288   for ( size_t i = 0 ; i != deleted_parts.size() ; i++ )
00289   {
00290     if ( deleted_parts[i] == &new_part )
00291       deleted_found = true;
00292   }
00293   STKUNIT_ASSERT ( deleted_found );
00294 }
00295 
00301 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyTransactionSpanningModifications)
00302 {
00303   //  HCE 3/4/10:
00304   //  For transactions to span multiple modifications destroyed
00305   //  mesh entities would have to be retained across multiple
00306   //  transactions.  This creates a problem where the transaction
00307   //  has to take ownership of the mesh entities away from the
00308   //  creating bulk data.
00309   //  This capability needs to be re-thought.
00310 
00311   return ;
00312 
00313 
00314   stk::mesh::fixtures::BoxFixture fixture;
00315   fixture.generate_boxes();
00316   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00317   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00318 
00319   stk::mesh::Part                       &new_part = fixture.get_test_part();
00320   stk::mesh::PartVector   add_part,blank_part;
00321   add_part.push_back ( &new_part );
00322 
00323   // This test need only run in serial
00324   if ( fixture.comm_size() > 1 ) return;
00325 
00326 
00327   // Here are two modifications.  The first adds an edge to the mesh,
00328   // the second changes the state of a node
00329   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00330   bulk.modification_begin();
00331   bulk.declare_entity ( 1 , 10001 , blank_part );
00332   bulk.modification_end();
00333 
00334   bulk.modification_begin();
00335   stk::mesh::Entity &n = *(*bulk.buckets(0).begin())->begin();
00336   bulk.change_entity_parts ( n , add_part );
00337   bulk.modification_end();
00338 
00339 
00340   // Verify both changes are logged
00341   STKUNIT_ASSERT ( bulk.get_transaction_log().get_modified_buckets(0).size() == 1 );
00342   STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(1).size() == 1 );
00343 
00344   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00345   // Verify the log is cleared
00346   STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(0).size() == 0 );
00347   STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(1).size() == 0 );
00348 
00349 
00350   // Cannot end a transaction while the mesh is modifiable
00351   // Even though the transaction can span modifications, it cannot be
00352   // reset in the middle of a modification
00353   bulk.modification_begin();
00354   STKUNIT_ASSERT_THROW ( bulk.reset_transaction () , std::runtime_error );
00355   bulk.modification_end();
00356 
00357 }
00358 
00359 
00364 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalInsert)
00365 {
00366   stk::mesh::fixtures::BoxFixture fixture;
00367   stk::mesh::BulkData             &bulk = fixture.bulk_data();
00368   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00369 
00370   stk::mesh::Part                       &new_part = fixture.get_test_part();
00371   stk::mesh::PartVector   add_part,blank_part;
00372   const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00373   add_part.push_back ( &new_part );
00374 
00375   // This test need only run in serial
00376   if ( fixture.comm_size() > 1 ) return;
00377 
00378   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00379   bulk.modification_begin();
00380   // Add 4 entities to the mesh
00381   stk::mesh::Entity *entities[4];
00382   entities[0] = &bulk.declare_entity ( 0 , 123456789 , blank_part );
00383   entities[1] = &bulk.declare_entity ( 1 , 123456789 , blank_part );
00384   entities[2] = &bulk.declare_entity ( 2 , 123456789 , blank_part );
00385   entities[3] = &bulk.declare_entity ( 3 , 123456789 , blank_part );
00386 
00387   // Modify one entity to ensure modification does not appear in log
00388   bulk.change_entity_parts ( *entities[1] , add_part );
00389 
00390   // Delete one entity to ensure the entity disappears from log
00391   bulk.destroy_entity ( entities[3] );
00392   bulk.modification_end();
00393 
00394   // The first three entities should exist in the insert buckets in
00395   // the transaction log
00396   for ( unsigned i = 0 ; i != 3 ; i++ )
00397   {
00398     // Make sure there is only one bucket
00399     STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(i).size() , 1u );
00400     // Make sure the entity is the only thing in the bucket
00401     STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(i)[0]->size() , 1u );
00402 
00403     stk::mesh::Entity &new_entity = *((*log.get_inserted_buckets(i).begin())->begin());
00404     // Make sure we find the right entity
00405     STKUNIT_ASSERT_EQUAL ( &new_entity , entities[i] );
00406     // Verify nothing happend to modified and deleted
00407     STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(i).size() , 0u );
00408     STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(i).size() , 0u );
00409   }
00410 
00411   // Verify entities[3] disappeared from the log
00412   STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(3).size() , 0u );
00413   STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(3).size() , 0u );
00414   STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(3).size() , 0u );
00415 }
00416 
00417 
00418 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalModify)
00419 {
00420   stk::mesh::fixtures::BoxFixture fixture;
00421   fixture.generate_boxes();
00422   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00423   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00424 
00425   stk::mesh::Part                       &new_part = fixture.get_test_part();
00426   stk::mesh::PartVector   add_part,blank_part;
00427   const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00428   add_part.push_back ( &new_part );
00429 
00430   // This test need only run in serial
00431   if ( fixture.comm_size() > 1 ) return;
00432 
00433   // Modify the state of a node and entity in the mesh
00434   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00435   bulk.modification_begin();
00436   stk::mesh::Entity *entities[2];
00437   entities[0] = &*bulk.buckets(0)[0]->begin();
00438   entities[1] = &*bulk.buckets(3)[0]->begin();
00439   bulk.change_entity_parts ( *entities[0] , add_part );
00440   bulk.change_entity_parts ( *entities[1] , add_part );
00441   bulk.modification_end();
00442 
00443   for ( unsigned i = 0 ; i != 2 ; i++ )
00444   {
00445     unsigned enttype = i*3;
00446     // Make sure there is only one bucket
00447     STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(enttype).size() , 1u );
00448     // Make sure the entity is the only thing in the bucket
00449     STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(enttype)[0]->size() , 1u );
00450     stk::mesh::Entity &mod_entity = *log.get_modified_buckets(enttype)[0]->begin();
00451     // Make sure we find the right entity
00452     STKUNIT_ASSERT_EQUAL ( &mod_entity , entities[i] );
00453     // Verify nothing happend to modified and deleted
00454     STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(enttype).size() , 0u );
00455     STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(enttype).size() , 0u );
00456 
00457     // Verify the transaction recorded the modification accurately
00458     //  1)  Make sure the new part is not part of the previous parts
00459     //  2)  Make sure the previous parts are in the new parts
00460     STKUNIT_ASSERT ( mod_entity.transaction_bucket() != 0 );
00461     STKUNIT_ASSERT ( !mod_entity.transaction_bucket()->member ( new_part ) );
00462     stk::mesh::PartVector  modified_bucket_parts;
00463     mod_entity.transaction_bucket()->supersets ( modified_bucket_parts );
00464     STKUNIT_ASSERT ( mod_entity.bucket().member_all ( modified_bucket_parts ));
00465   }
00466 }
00467 
00468 
00469 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalAddRelation)
00470 {
00471   stk::mesh::fixtures::BoxFixture fixture;
00472   fixture.generate_boxes();
00473   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00474   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00475 
00476   stk::mesh::Part                       &new_part = fixture.get_test_part();
00477   stk::mesh::PartVector   add_part,blank_part;
00478   const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00479   add_part.push_back ( &new_part );
00480 
00481   // This test need only run in serial
00482   if ( fixture.comm_size() > 1 ) return;
00483 
00484   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00485   bulk.modification_begin();
00486   stk::mesh::Entity  &new_node = bulk.declare_entity ( 0 , 123456789 , blank_part );
00487   stk::mesh::Entity  &existing_cell = *bulk.buckets(3)[0]->begin();
00488   bulk.declare_relation ( existing_cell, new_node , 10 );
00489   bulk.modification_end();
00490 
00491   // Verify that no nodes were modified, only inserted.
00492   STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(0).size() , 1u );
00493   STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(0)[0]->size() , 1u );
00494   STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(0).size() , 0u );
00495   STKUNIT_ASSERT_EQUAL ( &*log.get_inserted_buckets(0)[0]->begin() , &new_node );
00496 
00497   // Verify that the element is modified
00498   STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(3).size() , 1u );
00499   STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(3)[0]->size() , 1u );
00500   STKUNIT_ASSERT_EQUAL ( &*log.get_modified_buckets(3)[0]->begin() , &existing_cell );
00501 
00502   // Make sure the parts have not changed for the existing cell
00503   stk::mesh::PartVector old_parts , new_parts;
00504   STKUNIT_ASSERT ( existing_cell.transaction_bucket() != 0 );
00505   existing_cell.transaction_bucket()->supersets ( old_parts );
00506   STKUNIT_ASSERT ( existing_cell.bucket().member_all ( old_parts ) );
00507   existing_cell.bucket().supersets ( new_parts );
00508   STKUNIT_ASSERT ( existing_cell.transaction_bucket()->member_all ( new_parts ) );
00509 
00510 }
00511 
00512 
00513 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalDelete)
00514 {
00515   stk::mesh::fixtures::BoxFixture fixture;
00516   fixture.generate_boxes();
00517   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00518   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00519 
00520   stk::mesh::Part                       &new_part = fixture.get_test_part();
00521   stk::mesh::PartVector   add_part,old_parts;
00522   const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00523   add_part.push_back ( &new_part );
00524 
00525   // This test need only run in serial
00526   if ( fixture.comm_size() > 1 ) return;
00527 
00528   // destroy does not delete.  element will not be deleted until next
00529   // transaction reset
00530   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00531   bulk.modification_begin();
00532   stk::mesh::Entity     *deleted_cell = &*bulk.buckets(3)[0]->begin();
00533 
00534   // Record the old parts for testing later
00535   deleted_cell->bucket().supersets ( old_parts );
00536   stk::mesh::EntityId  deleted_cell_id = deleted_cell->identifier();
00537   bulk.destroy_entity ( deleted_cell );
00538   bulk.modification_end();
00539 
00540   // Verify that the element is deleted
00541   STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(3).size() , 1u );
00542   STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(3)[0]->size() , 1u );
00543   STKUNIT_ASSERT_EQUAL ( (*log.get_deleted_buckets(3)[0]->begin()).identifier() , deleted_cell_id );
00544 
00545   // Check for the old parts
00546   deleted_cell = &*log.get_deleted_buckets(3)[0]->begin();
00547   STKUNIT_ASSERT ( deleted_cell->transaction_bucket() != 0 );
00548   STKUNIT_ASSERT ( deleted_cell->transaction_bucket()->member_all ( old_parts ) );
00549   stk::mesh::PartVector  old_in_trans;
00550   deleted_cell->transaction_bucket()->supersets ( old_in_trans );
00551   STKUNIT_ASSERT_EQUAL ( old_in_trans.size() , old_parts.size() );
00552 }
00553 
00554 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyParallelChangeOwnership)
00555 {
00556   stk::mesh::fixtures::BoxFixture fixture;
00557   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00558   bulk.modification_end();  // Comes out of fixture in MODIFIABLE
00559 
00560   stk::mesh::Part                       &new_part = fixture.get_test_part();
00561   stk::mesh::PartVector   add_part,blank_part;
00562 //  const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00563   add_part.push_back ( &new_part );
00564 
00565   // This test needs four processes to work
00566   if ( fixture.comm_size() < 4 ) return;
00567 
00568   bulk.modification_begin ();
00569   stk::mesh::Entity  *entity = 0;
00570   bulk.declare_entity ( 0 , fixture.comm_rank()+1 , blank_part );
00571   if ( fixture.comm_rank() < 3 )
00572     entity = &bulk.declare_entity ( 0 , 1234 , blank_part );
00573   bulk.modification_end();
00574 
00575   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00576   std::vector <stk::mesh::EntityProc> change_owner;
00577   if ( entity )
00578     if ( fixture.comm_rank() == entity->owner_rank() )
00579     {
00580       int other_rank = fixture.comm_rank()==0?1:0;
00581       change_owner.push_back ( std::make_pair ( entity , other_rank ) );
00582     }
00583   bulk.modification_begin();
00584   bulk.change_entity_owner ( change_owner );
00585   bulk.modification_end();
00586 
00587   /********* This needs to be fixed:  we need to know what correct
00588    * behavior should be
00589   if ( entity )
00590   {
00591     if ( fixture.comm_rank() < 3 )
00592     {
00593       STKUNIT_ASSERT ( entity->transaction_bucket()->transaction_state() == stk::mesh::Transaction::MODIFIED );
00594     }
00595   }
00596   ******************/
00597 }
00598 
00599 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyParallelResolutionModify)
00600 {
00601   stk::mesh::fixtures::BoxFixture fixture;
00602   stk::mesh::BulkData                   &bulk = fixture.bulk_data();
00603   bulk.modification_end();
00604 
00605   stk::mesh::Part                       &new_part = fixture.get_test_part();
00606   const stk::mesh::MetaData             &meta = fixture.meta_data();
00607   const stk::mesh::Transaction   &log = bulk.get_transaction_log();
00608   stk::mesh::PartVector   add_part,old_parts;
00609   add_part.push_back ( &new_part );
00610 
00611   // This test need only run in parallel
00612   if ( fixture.comm_size() == 1 ) return;
00613   fixture.generate_boxes ();
00614 
00615 
00616   // Find a node to alter, preferable one that is shared
00617   const std::vector<stk::mesh::EntityProc> &shared_entities = bulk.shared_entities();
00618   stk::mesh::Entity  *node_to_modify = 0;
00619   for ( unsigned i = 0 ; i != shared_entities.size() ;i++ )
00620   {
00621     if ( shared_entities[i].first->entity_rank() == 0 )
00622       if ( shared_entities[i].first->bucket().member ( meta.locally_owned_part () ) )
00623       {
00624         node_to_modify = shared_entities[i].first;
00625         break;
00626       }
00627   }
00628 
00629   // Once found, tell all processes which one.  If not found, tell
00630   // them that as well
00631   int       *found_node_list     = new int [ bulk.parallel_size() ];
00632   stk::mesh::EntityId  *found_node_id_list  = new stk::mesh::EntityId [ bulk.parallel_size() ];
00633 
00634 #ifdef STK_HAS_MPI
00635   stk::mesh::EntityId node_id = node_to_modify ? node_to_modify->identifier() : 0;
00636   int found_a_node = node_to_modify ? 1 : 0;
00637 
00638   MPI_Allgather ( &found_a_node , 1 , MPI_INT , found_node_list , 1 , MPI_INT , bulk.parallel() );
00639   MPI_Allgather ( &node_id , 1 , MPI_INT , found_node_id_list , 1 , MPI_INT , bulk.parallel() );
00640 #endif
00641 
00642   // Modify the node
00643   bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL );
00644   bulk.modification_begin ();
00645   if ( node_to_modify )
00646     bulk.change_entity_parts ( *node_to_modify , add_part );
00647   bulk.modification_end ();
00648 
00649   // Verify parallel consistent modification
00650   // First, loop over everythin in the modified buckets
00651   std::vector<stk::mesh::Bucket *>::const_iterator  cur_modified_node_bucket = log.get_modified_buckets(0).begin();
00652   while ( cur_modified_node_bucket != log.get_modified_buckets(0).end() )
00653   {
00654     stk::mesh::BucketIterator  cur_modified_node = (*cur_modified_node_bucket)->begin();
00655     while ( cur_modified_node != (*cur_modified_node_bucket)->begin() )
00656     {
00657       // For everything located in the buckets, verify it was changed
00658       // by another process
00659       bool valid_change = false;
00660       for ( unsigned i = 0 ; i != bulk.parallel_size() ; i++ )
00661         if ( found_node_list[i] == 1 )
00662           if ( cur_modified_node->identifier() == found_node_id_list[i] )
00663             valid_change = true;
00664       STKUNIT_ASSERT ( valid_change );
00665       ++cur_modified_node;
00666     }
00667     ++cur_modified_node_bucket;
00668   }
00669 
00670   delete [] found_node_list;
00671   delete [] found_node_id_list;
00672 }
00673 
00674 #endif
00675 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines