|
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 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 #include <stk_mesh/base/BulkData.hpp> 00025 #include <stk_mesh/base/GetEntities.hpp> 00026 #include <stk_mesh/base/Field.hpp> 00027 #include <stk_mesh/base/FieldData.hpp> 00028 #include <stk_mesh/base/Comm.hpp> 00029 #include <stk_mesh/fem/EntityRanks.hpp> 00030 #include <stk_mesh/base/GetBuckets.hpp> 00031 00032 #include <unit_tests/UnitTestMesh.hpp> 00033 00034 00039 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyBulkOnCreate) 00040 { 00041 stk::mesh::MetaData meta ( stk::unit_test::get_entity_rank_names ( 3 ) ); 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::unit_test::UnitTestMesh fixture; 00081 stk::mesh::BulkData &bulk = fixture.nonconst_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::unit_test::UnitTestMesh fixture; 00142 stk::mesh::BulkData &bulk = fixture.nonconst_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::unit_test::UnitTestMesh fixture; 00203 fixture.generate_boxes (); 00204 stk::mesh::BulkData &bulk = fixture.nonconst_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::unit_test::UnitTestMesh fixture; 00242 stk::mesh::BulkData &bulk = fixture.nonconst_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 00315 stk::unit_test::UnitTestMesh fixture; 00316 fixture.generate_boxes(); 00317 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00318 bulk.modification_end(); // Comes out of fixture in MODIFIABLE 00319 00320 stk::mesh::Part &new_part = fixture.get_test_part(); 00321 stk::mesh::PartVector add_part,blank_part; 00322 add_part.push_back ( &new_part ); 00323 00324 // This test need only run in serial 00325 if ( fixture.comm_size() > 1 ) return; 00326 00327 00328 // Here are two modifications. The first adds an edge to the mesh, 00329 // the second changes the state of a node 00330 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00331 bulk.modification_begin(); 00332 bulk.declare_entity ( 1 , 10001 , blank_part ); 00333 bulk.modification_end(); 00334 00335 bulk.modification_begin(); 00336 stk::mesh::Entity &n = *(*bulk.buckets(0).begin())->begin(); 00337 bulk.change_entity_parts ( n , add_part ); 00338 bulk.modification_end(); 00339 00340 00341 // Verify both changes are logged 00342 STKUNIT_ASSERT ( bulk.get_transaction_log().get_modified_buckets(0).size() == 1 ); 00343 STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(1).size() == 1 ); 00344 00345 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00346 // Verify the log is cleared 00347 STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(0).size() == 0 ); 00348 STKUNIT_ASSERT ( bulk.get_transaction_log().get_inserted_buckets(1).size() == 0 ); 00349 00350 00351 // Cannot end a transaction while the mesh is modifiable 00352 // Even though the transaction can span modifications, it cannot be 00353 // reset in the middle of a modification 00354 bulk.modification_begin(); 00355 STKUNIT_ASSERT_THROW ( bulk.reset_transaction () , std::runtime_error ); 00356 bulk.modification_end(); 00357 00358 } 00359 00360 00365 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalInsert) 00366 { 00367 stk::unit_test::UnitTestMesh fixture; 00368 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00369 bulk.modification_end(); // Comes out of fixture in MODIFIABLE 00370 00371 stk::mesh::Part &new_part = fixture.get_test_part(); 00372 stk::mesh::PartVector add_part,blank_part; 00373 const stk::mesh::Transaction &log = bulk.get_transaction_log(); 00374 add_part.push_back ( &new_part ); 00375 00376 // This test need only run in serial 00377 if ( fixture.comm_size() > 1 ) return; 00378 00379 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00380 bulk.modification_begin(); 00381 // Add 4 entities to the mesh 00382 stk::mesh::Entity *entities[4]; 00383 entities[0] = &bulk.declare_entity ( 0 , 123456789 , blank_part ); 00384 entities[1] = &bulk.declare_entity ( 1 , 123456789 , blank_part ); 00385 entities[2] = &bulk.declare_entity ( 2 , 123456789 , blank_part ); 00386 entities[3] = &bulk.declare_entity ( 3 , 123456789 , blank_part ); 00387 00388 // Modify one entity to ensure modification does not appear in log 00389 bulk.change_entity_parts ( *entities[1] , add_part ); 00390 00391 // Delete one entity to ensure the entity disappears from log 00392 bulk.destroy_entity ( entities[3] ); 00393 bulk.modification_end(); 00394 00395 // The first three entities should exist in the insert buckets in 00396 // the transaction log 00397 for ( unsigned i = 0 ; i != 3 ; i++ ) 00398 { 00399 // Make sure there is only one bucket 00400 STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(i).size() , 1u ); 00401 // Make sure the entity is the only thing in the bucket 00402 STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(i)[0]->size() , 1u ); 00403 00404 stk::mesh::Entity &new_entity = *((*log.get_inserted_buckets(i).begin())->begin()); 00405 // Make sure we find the right entity 00406 STKUNIT_ASSERT_EQUAL ( &new_entity , entities[i] ); 00407 // Verify nothing happend to modified and deleted 00408 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(i).size() , 0u ); 00409 STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(i).size() , 0u ); 00410 } 00411 00412 // Verify entities[3] disappeared from the log 00413 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(3).size() , 0u ); 00414 STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(3).size() , 0u ); 00415 STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(3).size() , 0u ); 00416 } 00417 00418 00419 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalModify) 00420 { 00421 stk::unit_test::UnitTestMesh fixture; 00422 fixture.generate_boxes(); 00423 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00424 bulk.modification_end(); // Comes out of fixture in MODIFIABLE 00425 00426 stk::mesh::Part &new_part = fixture.get_test_part(); 00427 stk::mesh::PartVector add_part,blank_part; 00428 const stk::mesh::Transaction &log = bulk.get_transaction_log(); 00429 add_part.push_back ( &new_part ); 00430 00431 // This test need only run in serial 00432 if ( fixture.comm_size() > 1 ) return; 00433 00434 // Modify the state of a node and entity in the mesh 00435 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00436 bulk.modification_begin(); 00437 stk::mesh::Entity *entities[2]; 00438 entities[0] = &*bulk.buckets(0)[0]->begin(); 00439 entities[1] = &*bulk.buckets(3)[0]->begin(); 00440 bulk.change_entity_parts ( *entities[0] , add_part ); 00441 bulk.change_entity_parts ( *entities[1] , add_part ); 00442 bulk.modification_end(); 00443 00444 for ( unsigned i = 0 ; i != 2 ; i++ ) 00445 { 00446 unsigned enttype = i*3; 00447 // Make sure there is only one bucket 00448 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(enttype).size() , 1u ); 00449 // Make sure the entity is the only thing in the bucket 00450 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(enttype)[0]->size() , 1u ); 00451 stk::mesh::Entity &mod_entity = *log.get_modified_buckets(enttype)[0]->begin(); 00452 // Make sure we find the right entity 00453 STKUNIT_ASSERT_EQUAL ( &mod_entity , entities[i] ); 00454 // Verify nothing happend to modified and deleted 00455 STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(enttype).size() , 0u ); 00456 STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(enttype).size() , 0u ); 00457 00458 // Verify the transaction recorded the modification accurately 00459 // 1) Make sure the new part is not part of the previous parts 00460 // 2) Make sure the previous parts are in the new parts 00461 STKUNIT_ASSERT ( mod_entity.transaction_bucket() != 0 ); 00462 STKUNIT_ASSERT ( !mod_entity.transaction_bucket()->member ( new_part ) ); 00463 stk::mesh::PartVector modified_bucket_parts; 00464 mod_entity.transaction_bucket()->supersets ( modified_bucket_parts ); 00465 STKUNIT_ASSERT ( mod_entity.bucket().member_all ( modified_bucket_parts )); 00466 } 00467 } 00468 00469 00470 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalAddRelation) 00471 { 00472 stk::unit_test::UnitTestMesh fixture; 00473 fixture.generate_boxes(); 00474 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00475 bulk.modification_end(); // Comes out of fixture in MODIFIABLE 00476 00477 stk::mesh::Part &new_part = fixture.get_test_part(); 00478 stk::mesh::PartVector add_part,blank_part; 00479 const stk::mesh::Transaction &log = bulk.get_transaction_log(); 00480 add_part.push_back ( &new_part ); 00481 00482 // This test need only run in serial 00483 if ( fixture.comm_size() > 1 ) return; 00484 00485 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00486 bulk.modification_begin(); 00487 stk::mesh::Entity &new_node = bulk.declare_entity ( 0 , 123456789 , blank_part ); 00488 stk::mesh::Entity &existing_cell = *bulk.buckets(3)[0]->begin(); 00489 bulk.declare_relation ( existing_cell, new_node , 10 ); 00490 bulk.modification_end(); 00491 00492 // Verify that no nodes were modified, only inserted. 00493 STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(0).size() , 1u ); 00494 STKUNIT_ASSERT_EQUAL ( log.get_inserted_buckets(0)[0]->size() , 1u ); 00495 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(0).size() , 0u ); 00496 STKUNIT_ASSERT_EQUAL ( &*log.get_inserted_buckets(0)[0]->begin() , &new_node ); 00497 00498 // Verify that the element is modified 00499 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(3).size() , 1u ); 00500 STKUNIT_ASSERT_EQUAL ( log.get_modified_buckets(3)[0]->size() , 1u ); 00501 STKUNIT_ASSERT_EQUAL ( &*log.get_modified_buckets(3)[0]->begin() , &existing_cell ); 00502 00503 // Make sure the parts have not changed for the existing cell 00504 stk::mesh::PartVector old_parts , new_parts; 00505 STKUNIT_ASSERT ( existing_cell.transaction_bucket() != 0 ); 00506 existing_cell.transaction_bucket()->supersets ( old_parts ); 00507 STKUNIT_ASSERT ( existing_cell.bucket().member_all ( old_parts ) ); 00508 existing_cell.bucket().supersets ( new_parts ); 00509 STKUNIT_ASSERT ( existing_cell.transaction_bucket()->member_all ( new_parts ) ); 00510 00511 } 00512 00513 00514 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyIncrementalDelete) 00515 { 00516 stk::unit_test::UnitTestMesh fixture; 00517 fixture.generate_boxes(); 00518 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00519 bulk.modification_end(); // Comes out of fixture in MODIFIABLE 00520 00521 stk::mesh::Part &new_part = fixture.get_test_part(); 00522 stk::mesh::PartVector add_part,old_parts; 00523 const stk::mesh::Transaction &log = bulk.get_transaction_log(); 00524 add_part.push_back ( &new_part ); 00525 00526 // This test need only run in serial 00527 if ( fixture.comm_size() > 1 ) return; 00528 00529 // destroy does not delete. element will not be deleted until next 00530 // transaction reset 00531 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00532 bulk.modification_begin(); 00533 stk::mesh::Entity *deleted_cell = &*bulk.buckets(3)[0]->begin(); 00534 00535 // Record the old parts for testing later 00536 deleted_cell->bucket().supersets ( old_parts ); 00537 stk::mesh::EntityId deleted_cell_id = deleted_cell->identifier(); 00538 bulk.destroy_entity ( deleted_cell ); 00539 bulk.modification_end(); 00540 00541 // Verify that the element is deleted 00542 STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(3).size() , 1u ); 00543 STKUNIT_ASSERT_EQUAL ( log.get_deleted_buckets(3)[0]->size() , 1u ); 00544 STKUNIT_ASSERT_EQUAL ( (*log.get_deleted_buckets(3)[0]->begin()).identifier() , deleted_cell_id ); 00545 00546 // Check for the old parts 00547 deleted_cell = &*log.get_deleted_buckets(3)[0]->begin(); 00548 STKUNIT_ASSERT ( deleted_cell->transaction_bucket() != 0 ); 00549 STKUNIT_ASSERT ( deleted_cell->transaction_bucket()->member_all ( old_parts ) ); 00550 stk::mesh::PartVector old_in_trans; 00551 deleted_cell->transaction_bucket()->supersets ( old_in_trans ); 00552 STKUNIT_ASSERT_EQUAL ( old_in_trans.size() , old_parts.size() ); 00553 } 00554 00555 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyParallelChangeOwnership) 00556 { 00557 stk::unit_test::UnitTestMesh fixture; 00558 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00559 bulk.modification_end(); // Comes out of fixture in MODIFIABLE 00560 00561 stk::mesh::Part &new_part = fixture.get_test_part(); 00562 stk::mesh::PartVector add_part,blank_part; 00563 // const stk::mesh::Transaction &log = bulk.get_transaction_log(); 00564 add_part.push_back ( &new_part ); 00565 00566 // This test needs four processes to work 00567 if ( fixture.comm_size() < 4 ) return; 00568 00569 bulk.modification_begin (); 00570 stk::mesh::Entity *entity = 0; 00571 bulk.declare_entity ( 0 , fixture.comm_rank()+1 , blank_part ); 00572 if ( fixture.comm_rank() < 3 ) 00573 entity = &bulk.declare_entity ( 0 , 1234 , blank_part ); 00574 bulk.modification_end(); 00575 00576 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00577 std::vector <stk::mesh::EntityProc> change_owner; 00578 if ( entity ) 00579 if ( fixture.comm_rank() == entity->owner_rank() ) 00580 { 00581 int other_rank = fixture.comm_rank()==0?1:0; 00582 change_owner.push_back ( std::make_pair ( entity , other_rank ) ); 00583 } 00584 bulk.modification_begin(); 00585 bulk.change_entity_owner ( change_owner ); 00586 bulk.modification_end(); 00587 00588 /********* This needs to be fixed: we need to know what correct 00589 * behavior should be 00590 if ( entity ) 00591 { 00592 if ( fixture.comm_rank() < 3 ) 00593 { 00594 STKUNIT_ASSERT ( entity->transaction_bucket()->transaction_state() == stk::mesh::Transaction::MODIFIED ); 00595 } 00596 } 00597 ******************/ 00598 } 00599 00600 STKUNIT_UNIT_TEST(UnitTestTransaction, verifyParallelResolutionModify) 00601 { 00602 stk::unit_test::UnitTestMesh fixture; 00603 stk::mesh::BulkData &bulk = fixture.nonconst_bulk_data(); 00604 bulk.modification_end(); 00605 00606 stk::mesh::Part &new_part = fixture.get_test_part(); 00607 const stk::mesh::MetaData &meta = fixture.meta_data(); 00608 const stk::mesh::Transaction &log = bulk.get_transaction_log(); 00609 stk::mesh::PartVector add_part,old_parts; 00610 add_part.push_back ( &new_part ); 00611 00612 // This test need only run in parallel 00613 if ( fixture.comm_size() == 1 ) return; 00614 fixture.generate_boxes (); 00615 00616 00617 // Find a node to alter, preferable one that is shared 00618 const std::vector<stk::mesh::EntityProc> &shared_entities = bulk.shared_entities(); 00619 stk::mesh::Entity *node_to_modify = 0; 00620 for ( unsigned i = 0 ; i != shared_entities.size() ;i++ ) 00621 { 00622 if ( shared_entities[i].first->entity_rank() == 0 ) 00623 if ( shared_entities[i].first->bucket().member ( meta.locally_owned_part () ) ) 00624 { 00625 node_to_modify = shared_entities[i].first; 00626 break; 00627 } 00628 } 00629 00630 // Once found, tell all processes which one. If not found, tell 00631 // them that as well 00632 int *found_node_list = new int [ bulk.parallel_size() ]; 00633 stk::mesh::EntityId *found_node_id_list = new stk::mesh::EntityId [ bulk.parallel_size() ]; 00634 00635 #ifdef STK_HAS_MPI 00636 stk::mesh::EntityId node_id = node_to_modify ? node_to_modify->identifier() : 0; 00637 int found_a_node = node_to_modify ? 1 : 0; 00638 00639 MPI_Allgather ( &found_a_node , 1 , MPI_INT , found_node_list , 1 , MPI_INT , bulk.parallel() ); 00640 MPI_Allgather ( &node_id , 1 , MPI_INT , found_node_id_list , 1 , MPI_INT , bulk.parallel() ); 00641 #endif 00642 00643 // Modify the node 00644 bulk.reset_transaction ( stk::mesh::Transaction::INCREMENTAL ); 00645 bulk.modification_begin (); 00646 if ( node_to_modify ) 00647 bulk.change_entity_parts ( *node_to_modify , add_part ); 00648 bulk.modification_end (); 00649 00650 // Verify parallel consistent modification 00651 // First, loop over everythin in the modified buckets 00652 std::vector<stk::mesh::Bucket *>::const_iterator cur_modified_node_bucket = log.get_modified_buckets(0).begin(); 00653 while ( cur_modified_node_bucket != log.get_modified_buckets(0).end() ) 00654 { 00655 stk::mesh::BucketIterator cur_modified_node = (*cur_modified_node_bucket)->begin(); 00656 while ( cur_modified_node != (*cur_modified_node_bucket)->begin() ) 00657 { 00658 // For everything located in the buckets, verify it was changed 00659 // by another process 00660 bool valid_change = false; 00661 for ( unsigned i = 0 ; i != bulk.parallel_size() ; i++ ) 00662 if ( found_node_list[i] == 1 ) 00663 if ( cur_modified_node->identifier() == found_node_id_list[i] ) 00664 valid_change = true; 00665 STKUNIT_ASSERT ( valid_change ); 00666 ++cur_modified_node; 00667 } 00668 ++cur_modified_node_bucket; 00669 } 00670 00671 delete [] found_node_list; 00672 delete [] found_node_id_list; 00673 } 00674 00675 #endif 00676