|
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 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/fem/EntityRanks.hpp> 00019 #include <stk_mesh/fem/TopologyHelpers.hpp> 00020 #include <stk_mesh/fem/TopologicalMetaData.hpp> 00021 #include <Shards_BasicTopologies.hpp> 00022 #include <stk_mesh/baseImpl/PartRepository.hpp> 00023 #include <stk_mesh/baseImpl/EntityRepository.hpp> 00024 #include <stk_mesh/baseImpl/FieldBaseImpl.hpp> 00025 #include <unit_tests/UnitTestMesh.hpp> 00026 00027 namespace stk { 00028 namespace mesh { 00029 00030 class UnitTestMetaData { 00031 public: 00032 UnitTestMetaData() {} 00033 00034 void testEntityKey(); 00035 void testPart(); 00036 void testPartVector(); 00037 void testField(); 00038 void testFieldRestriction(); 00039 void testMetaData(); 00040 void testProperty(); 00041 void testEntityRepository(); 00042 }; 00043 00044 }//namespace mesh 00045 }//namespace stk 00046 00047 namespace { 00048 00049 STKUNIT_UNIT_TEST(UnitTestEntityKey, testUnit) 00050 { 00051 stk::mesh::UnitTestMetaData umeta; 00052 umeta.testEntityKey(); 00053 } 00054 00055 STKUNIT_UNIT_TEST(UnitTestPart, testUnit) 00056 { 00057 stk::mesh::UnitTestMetaData umeta; 00058 umeta.testPart(); 00059 } 00060 00061 STKUNIT_UNIT_TEST(UnitTestPartVector, testUnit) 00062 { 00063 stk::mesh::UnitTestMetaData umeta; 00064 umeta.testPartVector(); 00065 } 00066 00067 STKUNIT_UNIT_TEST(UnitTestField, testUnit) 00068 { 00069 stk::mesh::UnitTestMetaData umeta; 00070 umeta.testField(); 00071 } 00072 00073 STKUNIT_UNIT_TEST(UnitTestFieldRestriction, testUnit) 00074 { 00075 stk::mesh::UnitTestMetaData umeta; 00076 umeta.testFieldRestriction(); 00077 } 00078 00079 STKUNIT_UNIT_TEST(UnitTestMetaData, testUnit) 00080 { 00081 stk::mesh::UnitTestMetaData umeta; 00082 umeta.testMetaData(); 00083 } 00084 00085 STKUNIT_UNIT_TEST(UnitTestProperty, testUnit) 00086 { 00087 stk::mesh::UnitTestMetaData umeta; 00088 umeta.testProperty(); 00089 } 00090 00091 STKUNIT_UNIT_TEST(UnitTestEntityRepository, testUnit) 00092 { 00093 stk::mesh::UnitTestMetaData umeta; 00094 umeta.testEntityRepository(); 00095 } 00096 00097 }//namespace <anonymous> 00098 00099 //---------------------------------------------------------------------- 00100 00101 namespace stk { 00102 namespace mesh { 00103 void UnitTestMetaData::testEntityKey() 00104 { 00105 EntityKey 00106 key_bad_zero = EntityKey(), 00107 key_good_0_1 = EntityKey( 0 , 1 ), 00108 key_good_1_1 = EntityKey( 1 , 1 ), 00109 key_good_2_10 = EntityKey( 2 , 10 ); 00110 00111 // EntityId val = entity_id(key_good_2_10) ; 00112 00113 // EntityKey good_key_gone_bad; 00114 // entity_good_key_gone_bad.key = val ; 00115 00116 STKUNIT_ASSERT( ! entity_key_valid( key_bad_zero ) ); 00117 STKUNIT_ASSERT( entity_key_valid( key_good_0_1 ) ); 00118 STKUNIT_ASSERT( entity_key_valid( key_good_1_1 ) ); 00119 STKUNIT_ASSERT( entity_key_valid( key_good_2_10 ) ); 00120 00121 STKUNIT_ASSERT( 0 == entity_rank(key_good_0_1)); 00122 STKUNIT_ASSERT( 1 == entity_rank(key_good_1_1) ); 00123 STKUNIT_ASSERT( 2 == entity_rank(key_good_2_10) ); 00124 STKUNIT_ASSERT( 1 == entity_id(key_good_0_1) ); 00125 STKUNIT_ASSERT( 1 == entity_id(key_good_1_1) ); 00126 STKUNIT_ASSERT( 10 == entity_id(key_good_2_10) ); 00127 00128 EntityKey 00129 key_order_1_12 = EntityKey( 1 , 12 ), 00130 key_order_2_10 = EntityKey( 2 , 10 ); 00131 00132 STKUNIT_ASSERT( key_order_1_12 < key_order_2_10); 00133 STKUNIT_ASSERT( !(key_order_1_12 > key_order_2_10)); 00134 00135 // STKUNIT_ASSERT( ! entity_key_valid( good_key_gone_bad ) ); 00136 00137 // std::cout.unsetf( std::ios::dec); 00138 // std::cout.setf( std::ios::hex); 00139 // std::cout << "TEST entity_key_type " 00140 // << ", key_good_2_10 = " << key_good_2_10.key 00141 // << ", good_key_gone_bad = " << good_key_gone_bad.key 00142 // << std::endl ; 00143 // std::cout.unsetf( std::ios::hex); 00144 // std::cout.setf( std::ios::dec); 00145 00146 EntityKey key01(0,1), key_default; 00147 key01 = key_default; 00148 00149 STKUNIT_ASSERT_THROW( EntityKey( ~0u , 1 ) , std::runtime_error ); 00150 STKUNIT_ASSERT_THROW( EntityKey( 0 , ~stk::mesh::EntityKey::raw_key_type(0) ) , std::runtime_error ); 00151 } 00152 00153 //---------------------------------------------------------------------- 00154 // Unit test the Part functionality in isolation: 00155 00156 void UnitTestMetaData::testPart() 00157 { 00158 MetaData * const m = NULL ; 00159 00160 impl::PartRepository partRepo(m); 00161 00162 Part & universal = *partRepo.universal_part(); 00163 00164 STKUNIT_ASSERT( universal.supersets().empty() ); 00165 STKUNIT_ASSERT( 1u == universal.subsets().size() ); 00166 STKUNIT_ASSERT_EQUAL( universal.subsets()[0] , & universal ); 00167 00168 //-------------------------------------------------------------------- 00169 // Test multiple part creation 00170 00171 enum { NPARTS = 100 }; 00172 00173 Part * parts[ NPARTS ] ; 00174 00175 parts[0] = & universal ; 00176 00177 for ( int i = 1 ; i < NPARTS-1 ; ++i ) { 00178 std::ostringstream name ; 00179 name << "Part_" << i ; 00180 parts[i] = partRepo.declare_part( name.str() , 0 ); 00181 } 00182 parts[99] = partRepo.declare_part( "Part_99" , 1 ); 00183 00184 STKUNIT_ASSERT( universal.supersets().empty() ); 00185 STKUNIT_ASSERT( NPARTS == universal.subsets().size() ); 00186 STKUNIT_ASSERT_EQUAL( universal.subsets()[0] , & universal ); 00187 00188 for ( unsigned i = 1 ; i < NPARTS ; ++i ) { 00189 STKUNIT_ASSERT( parts[i]->subsets().empty() ); 00190 STKUNIT_ASSERT( parts[i]->intersection_of().empty() ); 00191 STKUNIT_ASSERT( parts[i]->mesh_meta_data_ordinal() == i ); 00192 STKUNIT_ASSERT( 1u == parts[i]->supersets().size() ); 00193 STKUNIT_ASSERT( & universal == parts[i]->supersets()[0] ); 00194 STKUNIT_ASSERT_EQUAL( parts[i] , universal.subsets()[i] ); 00195 STKUNIT_ASSERT_EQUAL( parts[i] , find( universal.subsets() , parts[i]->name() ) ); 00196 } 00197 00198 //-------------------------------------------------------------------- 00199 // Test multiple parts and transitive subset declarations: 00200 00201 partRepo.declare_subset( * parts[3], * parts[4] ); 00202 partRepo.declare_subset( * parts[4], * parts[5] ); 00203 00204 partRepo.declare_subset( * parts[1], * parts[2] ); 00205 // 1 and 2 pick up 4 and 5 via transitive relationship: 00206 partRepo.declare_subset( * parts[2], * parts[3] ); 00207 00208 STKUNIT_ASSERT( 4u == parts[1]->subsets().size() ); 00209 STKUNIT_ASSERT( 3u == parts[2]->subsets().size() ); 00210 STKUNIT_ASSERT( 2u == parts[3]->subsets().size() ); 00211 STKUNIT_ASSERT( 1u == parts[4]->subsets().size() ); 00212 STKUNIT_ASSERT( 0u == parts[5]->subsets().size() ); 00213 00214 STKUNIT_ASSERT( contain( parts[1]->subsets() , * parts[2] ) ); 00215 STKUNIT_ASSERT( contain( parts[1]->subsets() , * parts[3] ) ); 00216 STKUNIT_ASSERT( contain( parts[1]->subsets() , * parts[4] ) ); 00217 STKUNIT_ASSERT( contain( parts[1]->subsets() , * parts[5] ) ); 00218 00219 STKUNIT_ASSERT( contain( parts[5]->supersets() , * parts[1] ) ); 00220 STKUNIT_ASSERT( contain( parts[5]->supersets() , * parts[2] ) ); 00221 STKUNIT_ASSERT( contain( parts[5]->supersets() , * parts[3] ) ); 00222 STKUNIT_ASSERT( contain( parts[5]->supersets() , * parts[4] ) ); 00223 00224 //-------------------------------------------------------------------- 00225 // Test declaration of an intersection part 00226 00227 PartVector intersection ; 00228 intersection.push_back( parts[1] ); 00229 intersection.push_back( parts[2] ); 00230 intersection.push_back( parts[3] ); 00231 intersection.push_back( parts[4] ); // Smallest subset of 1..4 00232 00233 // Test filtering of trivial intersection 00234 00235 STKUNIT_ASSERT( parts[4] == partRepo.declare_part( intersection ) ); 00236 00237 // Test non-trivial intersection: 00238 00239 intersection.push_back( parts[6] ); 00240 intersection.push_back( parts[7] ); 00241 00242 Part & pint_4_6_7 = * partRepo.declare_part( intersection ); 00243 00244 STKUNIT_ASSERT( 3u == pint_4_6_7.intersection_of().size() ); 00245 STKUNIT_ASSERT( contain( pint_4_6_7.intersection_of() , * parts[4] ) ); 00246 STKUNIT_ASSERT( contain( pint_4_6_7.intersection_of() , * parts[6] ) ); 00247 STKUNIT_ASSERT( contain( pint_4_6_7.intersection_of() , * parts[7] ) ); 00248 00249 STKUNIT_ASSERT( 7u == pint_4_6_7.supersets().size() ); 00250 00251 // Test redeclaration of intersection, should give the same part back: 00252 00253 STKUNIT_ASSERT( pint_4_6_7 == * partRepo.declare_part( intersection ) ); 00254 00255 partRepo.declare_subset( pint_4_6_7, * parts[8] ); 00256 00257 //-------------------------------------------------------------------- 00258 // Test intersection-induced subset relationship 00259 00260 partRepo.declare_subset( * parts[7], * parts[10] ); 00261 STKUNIT_ASSERT( ! contain( pint_4_6_7.subsets() , * parts[10] ) ); 00262 00263 partRepo.declare_subset( * parts[6], * parts[10] ); 00264 STKUNIT_ASSERT( ! contain( pint_4_6_7.subsets() , * parts[10] ) ); 00265 00266 partRepo.declare_subset( * parts[3], * parts[10] ); 00267 STKUNIT_ASSERT( ! contain( pint_4_6_7.subsets() , * parts[10] ) ); 00268 00269 partRepo.declare_subset( * parts[4], * parts[10] ); 00270 STKUNIT_ASSERT( contain( pint_4_6_7.subsets() , * parts[10] ) ); 00271 00272 // Test intersection-induced subset relationship triggered from a subset 00273 00274 partRepo.declare_subset( * parts[7], * parts[11] ); 00275 STKUNIT_ASSERT( ! contain( pint_4_6_7.subsets() , * parts[11] ) ); 00276 00277 00278 partRepo.declare_subset( * parts[6], * parts[11] ); 00279 STKUNIT_ASSERT( ! contain( pint_4_6_7.subsets() , * parts[11] ) ); 00280 00281 partRepo.declare_subset( * parts[3], * parts[11] ); 00282 STKUNIT_ASSERT( ! contain( pint_4_6_7.subsets() , * parts[11] ) ); 00283 00284 partRepo.declare_subset( * parts[5], * parts[11] ); 00285 STKUNIT_ASSERT( contain( pint_4_6_7.subsets() , * parts[11] ) ); 00286 00287 std::cout << std::endl << "Part: test intersection generated" << std::endl ; 00288 print( std::cout , " " , pint_4_6_7 ); 00289 print( std::cout , " " , * parts[10] ); 00290 print( std::cout , " " , * parts[11] ); 00291 00292 std::cout << std::endl ; 00293 00294 //Test to cover assert_contain in PartRepository - Part is not a subset 00295 { 00296 const int spatial_dimension = 1; 00297 std::vector< std::string > dummy_names(spatial_dimension); 00298 dummy_names[0].assign("dummy"); 00299 00300 stk::mesh::MetaData meta( dummy_names ); 00301 00302 stk::mesh::Part &new_part4 = meta.declare_part ( "another part"); 00303 meta.commit(); 00304 00305 PartVector intersection2 ; 00306 intersection2.push_back( &new_part4 ); 00307 00308 impl::PartRepository partRepo2(m); 00309 STKUNIT_ASSERT_THROW( 00310 partRepo2.declare_part(intersection2), 00311 std::runtime_error 00312 ); 00313 } 00314 00315 //Test to cover assert_same_universe in PartRepository - Part is not in the same universe 00316 { 00317 int ok = 0 ; 00318 try { 00319 impl::PartRepository partRepo2(m); 00320 00321 PartVector intersection2 ; 00322 std::vector< std::string > dummy_names(1); 00323 dummy_names[0].assign("dummy"); 00324 00325 stk::mesh::MetaData meta2( dummy_names ); 00326 00327 stk::mesh::Part &new_part4 = meta2.declare_part ( "another part"); 00328 meta2.commit(); 00329 00330 intersection2.push_back( &new_part4 ); 00331 00332 PartVector::const_iterator i = intersection2.begin() ; 00333 Part * const p = *i ; 00334 partRepo2.declare_subset(*parts[5], *p); 00335 } 00336 catch( const std::exception & x ) { 00337 ok = 1 ; 00338 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 00339 << x.what() 00340 << std::endl ; 00341 } 00342 00343 if ( ! ok ) { 00344 throw std::runtime_error("UnitTestMetaData FAILED to catch error for assert_same_universe in PartRepository"); 00345 } 00346 } 00347 00348 //Test to cover assert_not_superset in PartRepository - parts[11] is not a superset of parts[7] 00349 { 00350 int ok = 0 ; 00351 try { 00352 partRepo.declare_subset(*parts[11], *parts[7] ); 00353 } 00354 catch( const std::exception & x ) { 00355 ok = 1 ; 00356 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 00357 << x.what() 00358 << std::endl ; 00359 } 00360 00361 if ( ! ok ) { 00362 throw std::runtime_error("UnitTestMetaData FAILED to catch error for assert_not_superset in PartRepository"); 00363 } 00364 } 00365 00366 //Test to cover assert_not_superset in PartRepository - parts[99] is not the same rank of parts[11] 00367 { 00368 int ok = 0 ; 00369 try { 00370 partRepo.declare_subset(*parts[11], *parts[99] ); 00371 } 00372 catch( const std::exception & x ) { 00373 ok = 1 ; 00374 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 00375 << x.what() 00376 << std::endl ; 00377 } 00378 00379 if ( ! ok ) { 00380 throw std::runtime_error("UnitTestMetaData FAILED to catch error for assert_rank_ordering in PartRepository"); 00381 } 00382 } 00383 00384 //Test to cover declare_part(arg_name, arg_rank) - Part_99 of rank 1 already exists.. 00385 { 00386 int ok = 0 ; 00387 try { 00388 partRepo.declare_part("Part_99", 0 ); 00389 } 00390 catch( const std::exception & x ) { 00391 ok = 1 ; 00392 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 00393 << x.what() 00394 << std::endl ; 00395 } 00396 00397 if ( ! ok ) { 00398 throw std::runtime_error("UnitTestMetaData FAILED to catch error for declare_part in PartRepository"); 00399 } 00400 } 00401 00402 //Test to cover declare_part(const PartVector & part_intersect) in PartRepository - failed from malicious abuse 00403 { 00404 int ok = 0 ; 00405 try { 00406 //create part with intersection 00407 00408 // Test declaration of an intersection part 00409 00410 impl::PartRepository partRepo2(m); 00411 00412 enum { NPARTS = 100 }; 00413 00414 Part * parts2[ NPARTS ] ; 00415 00416 parts2[0] = & universal ; 00417 00418 for ( int i = 1 ; i < NPARTS-1 ; ++i ) { 00419 std::ostringstream name ; 00420 name << "Part_" << i ; 00421 parts2[i] = partRepo2.declare_part( name.str() , 0 ); 00422 } 00423 00424 partRepo2.declare_subset( * parts2[3], * parts2[4] ); 00425 partRepo2.declare_subset( * parts2[4], * parts2[5] ); 00426 00427 partRepo2.declare_subset( * parts2[1], * parts2[2] ); 00428 // 1 and 2 pick up 4 and 5 via transitive relationship: 00429 partRepo2.declare_subset( * parts2[2], * parts2[3] ); 00430 00431 PartVector intersection2 ; 00432 intersection2.push_back( parts2[1] ); 00433 intersection2.push_back( parts2[2] ); 00434 intersection2.push_back( parts2[3] ); 00435 intersection2.push_back( parts2[4] ); // Smallest subset of 1..4 00436 intersection2.push_back( parts2[6] ); 00437 intersection2.push_back( parts2[7] ); 00438 00439 Part & partB = * partRepo2.declare_part("{Part_4^Part_6^Part_7}", 0); 00440 00441 std::cout << "UnitTestMetaData name of partB is " << partB.name() << std::endl ; 00442 00443 Part & pintersect_4_6_7 = * partRepo2.declare_part( intersection2 ); 00444 00445 std::cout << "UnitTestMetaData name of intersection part, pintersect_4_6_7 is " << pintersect_4_6_7.name() << std::endl ; 00446 } 00447 catch( const std::exception & x ) { 00448 ok = 1 ; 00449 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 00450 << x.what() 00451 << std::endl ; 00452 } 00453 00454 if ( ! ok ) { 00456 } 00457 } 00458 00459 //-------------------------------------------------------------------- 00460 // Test error trapping: 00461 00462 //bool generated_exception = false ; 00463 00464 // Can only declare parts on a universal part: 00465 00466 // generated_exception = false ; 00467 // try { parts[1]->declare_part( "error" , 0 ); } 00468 // catch( const std::exception & x ) { 00469 // std::cout << "Part: correctly caught " << x.what() << std::endl ; 00470 // generated_exception = true ; 00471 // } 00472 // STKUNIT_ASSERT( generated_exception ); 00473 00474 // Cannot be circular: 00475 00476 // generated_exception = false ; 00477 // try { parts[1]->declare_part( intersection ); } 00478 // catch( const std::exception & x ) { 00479 // std::cout << "Part: correctly caught " << x.what() << std::endl ; 00480 // generated_exception = true ; 00481 // } 00482 // STKUNIT_ASSERT( generated_exception ); 00483 00484 // Universal part cannot be a subset: 00485 00486 // generated_exception = false ; 00487 // try { parts[1]->declare_subset( universal ); } 00488 // catch( const std::exception & x ) { 00489 // std::cout << "Part: correctly caught " << x.what() << std::endl ; 00490 // generated_exception = true ; 00491 // } 00492 // STKUNIT_ASSERT( generated_exception ); 00493 00494 // Cannot have self-subset 00495 00496 // generated_exception = false ; 00497 // try { parts[1]->declare_subset( * parts[1] ); } 00498 // catch( const std::exception & x ) { 00499 // std::cout << "Part: correctly caught " << x.what() << std::endl ; 00500 // generated_exception = true ; 00501 // } 00502 // STKUNIT_ASSERT( generated_exception ); 00503 00504 // Cannot have circular-subset 00505 00506 // generated_exception = false ; 00507 // try { parts[5]->declare_subset( * parts[1] ); } 00508 // catch( const std::exception & x ) { 00509 // std::cout << "Part: correctly caught " << x.what() << std::endl ; 00510 // generated_exception = true ; 00511 // } 00512 // STKUNIT_ASSERT( generated_exception ); 00513 00514 // Part & part_rank_1 = universal.declare_part( std::string("PartRank1") , 1 ); 00515 // try { parts[1]->declare_subset( part_rank_1 ); } 00516 // catch( const std::exception & x ) { 00517 // std::cout << "Part: correctly caught " << x.what() << std::endl ; 00518 // generated_exception = true ; 00519 // } 00520 // STKUNIT_ASSERT( generated_exception ); 00521 00522 //-------------------------------------------------------------------- 00523 00524 return ; 00525 } 00526 00527 //---------------------------------------------------------------------- 00528 00529 void UnitTestMetaData::testPartVector() 00530 { 00531 std::vector< std::string > dummy_names(1); 00532 dummy_names[0].assign("dummy"); 00533 00534 stk::mesh::MetaData m( dummy_names ); 00535 00536 impl::PartRepository partRepo(&m); 00537 00538 Part * const pa = partRepo.declare_part( std::string("a") , 0 ); 00539 Part * const pb = partRepo.declare_part( std::string("b") , 0 ); 00540 Part * const pc = partRepo.declare_part( std::string("c") , 0 ); 00541 Part * const pd = partRepo.declare_part( std::string("d") , 0 ); 00542 Part * const pe = partRepo.declare_part( std::string("e") , 0 ); 00543 Part * const pf = partRepo.declare_part( std::string("f") , 0 ); 00544 00545 STKUNIT_ASSERT( ! intersect( *pa , *pb ) ); 00546 STKUNIT_ASSERT( ! intersect( *pb , *pc ) ); 00547 STKUNIT_ASSERT( ! intersect( *pc , *pd ) ); 00548 STKUNIT_ASSERT( ! intersect( *pd , *pe ) ); 00549 STKUNIT_ASSERT( ! intersect( *pe , *pf ) ); 00550 STKUNIT_ASSERT( ! intersect( *pf , *pa ) ); 00551 00552 PartVector vabc , vbcd , vdef , vresult ; 00553 00554 vabc.push_back( pa ); 00555 vabc.push_back( pb ); 00556 vabc.push_back( pc ); 00557 00558 vbcd.push_back( pb ); 00559 vbcd.push_back( pc ); 00560 vbcd.push_back( pd ); 00561 00562 vdef.push_back( pd ); 00563 vdef.push_back( pe ); 00564 vdef.push_back( pf ); 00565 00566 order( vabc ); 00567 order( vbcd ); 00568 order( vdef ); 00569 00570 vresult.clear(); 00571 STKUNIT_ASSERT_EQUAL( size_t(2) , intersect( vabc , vbcd ) ); 00572 size_t intersect_size = intersect( vabc , vbcd , vresult ); 00573 STKUNIT_ASSERT_EQUAL( size_t(2) , intersect_size ); 00574 STKUNIT_ASSERT_EQUAL( pb , vresult[0] ); 00575 STKUNIT_ASSERT_EQUAL( pc , vresult[1] ); 00576 00577 vresult.clear(); 00578 STKUNIT_ASSERT_EQUAL( size_t(1) , intersect( vdef , vbcd ) ); 00579 intersect_size = intersect( vdef , vbcd , vresult ); 00580 STKUNIT_ASSERT_EQUAL( size_t(1) , intersect_size ); 00581 STKUNIT_ASSERT_EQUAL( pd , vresult[0] ); 00582 00583 vresult.clear(); 00584 STKUNIT_ASSERT_EQUAL( size_t(0) , intersect( vdef , vabc ) ); 00585 intersect_size = intersect( vdef , vabc , vresult ); 00586 STKUNIT_ASSERT_EQUAL( size_t(0) , intersect_size ); 00587 STKUNIT_ASSERT_EQUAL( size_t(0) , vresult.size() ); 00588 00589 Part * const pabc = partRepo.declare_part( std::string("abc") , 0 ); 00590 Part * const pbcd = partRepo.declare_part( std::string("bcd") , 0 ); 00591 Part * const pdef = partRepo.declare_part( std::string("def") , 0 ); 00592 00593 partRepo.declare_subset( * pabc, *pa ); 00594 partRepo.declare_subset( * pabc, *pb ); 00595 partRepo.declare_subset( * pabc, *pc ); 00596 00597 partRepo.declare_subset( * pbcd, *pb ); 00598 partRepo.declare_subset( * pbcd, *pc ); 00599 partRepo.declare_subset( * pbcd, *pd ); 00600 00601 partRepo.declare_subset( * pdef, *pd ); 00602 partRepo.declare_subset( * pdef, *pe ); 00603 partRepo.declare_subset( * pdef, *pf ); 00604 00605 STKUNIT_ASSERT( intersect( *pabc , *pa ) ); 00606 STKUNIT_ASSERT( intersect( *pabc , *pb ) ); 00607 STKUNIT_ASSERT( intersect( *pabc , *pc ) ); 00608 STKUNIT_ASSERT( intersect( *pa , *pabc ) ); 00609 STKUNIT_ASSERT( intersect( *pb , *pabc ) ); 00610 STKUNIT_ASSERT( intersect( *pc , *pabc ) ); 00611 00612 STKUNIT_ASSERT( intersect( *pabc , *pbcd ) ); 00613 STKUNIT_ASSERT( ! intersect( *pabc , *pdef ) ); 00614 } 00615 00616 //---------------------------------------------------------------------- 00617 00618 namespace { 00619 00620 // Simple tags for testing field dimensions 00621 00622 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( ATAG ) 00623 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( BTAG ) 00624 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( CTAG ) 00625 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( DTAG ) 00626 00627 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( ATAG ) 00628 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( BTAG ) 00629 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( CTAG ) 00630 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( DTAG ) 00631 00632 } 00633 00634 void UnitTestMetaData::testField() 00635 { 00636 MetaData * const meta_null = NULL ; 00637 00638 // Declaration of a field allocates one field object 00639 // per state of the field. These fields are inserted 00640 // into a vector of fields of the base class. 00641 00642 impl::FieldRepository field_repo; 00643 const FieldVector & allocated_fields = field_repo.get_fields(); 00644 00645 //------------------------------ 00646 // Declare a double precision scalar field of one state. 00647 // Not an array; therefore, is rank zero. 00648 // Test the query methods for accuracy. 00649 FieldBase * const fA = 00650 field_repo.declare_field( std::string("A"), 00651 data_traits<double>() , 00652 0 /* # Ranks */ , 00653 NULL /* dimension tags */ , 00654 1 /* # States */ , 00655 meta_null ); 00656 00657 STKUNIT_ASSERT( allocated_fields.size() == 1 ); 00658 STKUNIT_ASSERT( fA != NULL ); 00659 STKUNIT_ASSERT( fA == allocated_fields[0] ); 00660 STKUNIT_ASSERT( fA->name() == std::string("A") ); 00661 STKUNIT_ASSERT( fA->type_is<double>() ); 00662 STKUNIT_ASSERT( fA->state() == StateNone ); 00663 STKUNIT_ASSERT( fA->rank() == 0 ); 00664 00665 //------------------------------ 00666 // Declare a field with an invalid suffix in its name. 00667 // Suffixes corresponding to "OLD" "N" "NM1" "NM2" "NM3" "NM4" 00668 // are not allowed as these are automatically appended to 00669 // the declared variable name for multistate fields. 00670 { 00671 FieldBase * tmp = NULL ; 00672 bool caught = false ; 00673 try { 00674 tmp = field_repo.declare_field( "A_OLD" , 00675 data_traits<double>() , 00676 0 /* # Ranks */ , 00677 NULL /* dimension tags */ , 00678 1 /* # States */ , 00679 meta_null ); 00680 } 00681 catch( const std::exception & x ) { 00682 std::cout << "Field: Correctly caught " << x.what() << std::endl ; 00683 caught = true ; 00684 } 00685 STKUNIT_ASSERT( caught ); 00686 STKUNIT_ASSERT( tmp == NULL ); 00687 STKUNIT_ASSERT( allocated_fields.size() == 1 ); 00688 } 00689 00690 //------------------------------ 00691 // Declare a double precision scalar field of two states. 00692 // Not an array; therefore, is rank zero. 00693 // Test that two fields: "B" and "B_OLD" were created. 00694 // Test the query methods for accuracy. 00695 00696 FieldBase * const fB = 00697 field_repo.declare_field( std::string("B"), 00698 data_traits<int>(), 00699 0 /* # Ranks */ , 00700 NULL /* dimension tags */ , 00701 2 /* # States */ , 00702 meta_null ); 00703 00704 STKUNIT_ASSERT( allocated_fields.size() == 3 ); 00705 STKUNIT_ASSERT( fB != NULL ); 00706 STKUNIT_ASSERT( fB == allocated_fields[1] ); 00707 STKUNIT_ASSERT( fB->name() == std::string("B") ); 00708 STKUNIT_ASSERT( fB->type_is<int>() ); 00709 STKUNIT_ASSERT( fB->state() == StateNew ); 00710 STKUNIT_ASSERT( fB->rank() == 0 ); 00711 00712 const FieldBase * const fB_old = allocated_fields[2] ; 00713 STKUNIT_ASSERT( fB_old->name() == std::string("B_OLD") ); 00714 STKUNIT_ASSERT( fB_old->type_is<int>() ); 00715 STKUNIT_ASSERT( fB_old->state() == StateOld ); 00716 STKUNIT_ASSERT( fB_old->rank() == 0 ); 00717 00718 //------------------------------ 00719 // Redeclare field must give back the previous field: 00720 00721 FieldBase * const fB_redundant = 00722 field_repo.declare_field( std::string("B"), 00723 data_traits<int>(), 00724 0 /* # Ranks */ , 00725 NULL /* dimension tags */ , 00726 2 /* # States */ , 00727 meta_null ); 00728 00729 STKUNIT_ASSERT( allocated_fields.size() == 3 ); 00730 STKUNIT_ASSERT( fB == fB_redundant ); 00731 00732 //------------------------------ 00733 // Declare a double precision array field of four states. 00734 // Test that four fields: were created. 00735 // Test the query methods for accuracy. 00736 00737 const shards::ArrayDimTag * dim_tags[] = 00738 { & ATAG::tag() , & BTAG::tag() , & CTAG::tag() , & DTAG::tag() }; 00739 00740 FieldBase * const fC = 00741 field_repo.declare_field( std::string("C"), 00742 data_traits<double>(), 00743 3 /* # Ranks */ , 00744 dim_tags /* dimension tags */ , 00745 4 /* # States */ , 00746 meta_null ); 00747 00748 STKUNIT_ASSERT( allocated_fields.size() == 7 ); 00749 STKUNIT_ASSERT( fC != NULL ); 00750 STKUNIT_ASSERT( fC == allocated_fields[3] ); 00751 STKUNIT_ASSERT( fC->name() == std::string("C") ); 00752 STKUNIT_ASSERT( fC->type_is<double>() ); 00753 STKUNIT_ASSERT( fC->state() == StateNew ); 00754 STKUNIT_ASSERT( fC->rank() == 3 ); 00755 00756 const FieldBase * const fC_n = allocated_fields[4] ; 00757 const FieldBase * const fC_nm1 = allocated_fields[5] ; 00758 const FieldBase * const fC_nm2 = allocated_fields[6] ; 00759 00760 STKUNIT_ASSERT( fC == fC->field_state( StateNP1 ) ); 00761 STKUNIT_ASSERT( fC_n == fC->field_state( StateN ) ); 00762 STKUNIT_ASSERT( fC_nm1 == fC->field_state( StateNM1 ) ); 00763 STKUNIT_ASSERT( fC_nm2 == fC->field_state( StateNM2 ) ); 00764 00765 STKUNIT_ASSERT( fC == fC_n->field_state( StateNP1 ) ); 00766 STKUNIT_ASSERT( fC_n == fC_n->field_state( StateN ) ); 00767 STKUNIT_ASSERT( fC_nm1 == fC_n->field_state( StateNM1 ) ); 00768 STKUNIT_ASSERT( fC_nm2 == fC_n->field_state( StateNM2 ) ); 00769 00770 STKUNIT_ASSERT( fC == fC_nm1->field_state( StateNP1 ) ); 00771 STKUNIT_ASSERT( fC_n == fC_nm1->field_state( StateN ) ); 00772 STKUNIT_ASSERT( fC_nm1 == fC_nm1->field_state( StateNM1 ) ); 00773 STKUNIT_ASSERT( fC_nm2 == fC_nm1->field_state( StateNM2 ) ); 00774 00775 STKUNIT_ASSERT( fC == fC_nm2->field_state( StateNP1 ) ); 00776 STKUNIT_ASSERT( fC_n == fC_nm2->field_state( StateN ) ); 00777 STKUNIT_ASSERT( fC_nm1 == fC_nm2->field_state( StateNM1 ) ); 00778 STKUNIT_ASSERT( fC_nm2 == fC_nm2->field_state( StateNM2 ) ); 00779 00780 STKUNIT_ASSERT( fC_n->name() == std::string("C_N") ); 00781 STKUNIT_ASSERT( fC_n->type_is<double>() ); 00782 STKUNIT_ASSERT( fC_n->state() == StateN ); 00783 STKUNIT_ASSERT( fC_n->rank() == 3 ); 00784 00785 STKUNIT_ASSERT( fC_nm1->name() == std::string("C_NM1") ); 00786 STKUNIT_ASSERT( fC_nm1->type_is<double>() ); 00787 STKUNIT_ASSERT( fC_nm1->state() == StateNM1 ); 00788 STKUNIT_ASSERT( fC_nm1->rank() == 3 ); 00789 00790 STKUNIT_ASSERT( fC_nm2->name() == std::string("C_NM2") ); 00791 STKUNIT_ASSERT( fC_nm2->type_is<double>() ); 00792 STKUNIT_ASSERT( fC_nm2->state() == StateNM2 ); 00793 STKUNIT_ASSERT( fC_nm2->rank() == 3 ); 00794 00795 //------------------------------ 00796 // Redeclare field must give back the previous field: 00797 //------------------------------ 00798 00799 for ( unsigned i = 0 ; i < allocated_fields.size() ; ++i ) { 00800 FieldBase * const f = allocated_fields[i] ; 00801 STKUNIT_ASSERT( f->mesh_meta_data_ordinal() == i ); 00802 } 00803 00804 std::cout << std::endl ; 00805 } 00806 00807 //---------------------------------------------------------------------- 00808 // Test field restrictions: the mapping of ( field , part ) -> dimensions 00809 00810 void UnitTestMetaData::testFieldRestriction() 00811 { 00812 const char method[] = "UnitTestMetaData::testFieldRestriction" ; 00813 00814 // Arrays for array dimension tags and dimension values 00815 const shards::ArrayDimTag * dim_tags[] = 00816 { & ATAG::tag() , & BTAG::tag() , & CTAG::tag() , & DTAG::tag() , 00817 & ATAG::tag() , & BTAG::tag() , & CTAG::tag() , & DTAG::tag() }; 00818 00819 unsigned stride[8] ; 00820 00821 stride[0] = 10 ; 00822 for ( unsigned i = 1 ; i < 8 ; ++i ) { 00823 stride[i] = ( i + 1 ) * stride[i-1] ; 00824 } 00825 00826 MetaData * const meta_null = NULL ; 00827 00828 impl::FieldRepository field_repo; 00829 const FieldVector & allocated_fields = field_repo.get_fields(); 00830 00831 //------------------------------ 00832 // Declare a rank two and one state: 00833 00834 FieldBase * const f2 = 00835 field_repo.declare_field( std::string("F2"), 00836 data_traits<int>(), 00837 2 /* # ranks */ , 00838 dim_tags /* dimension tags */ , 00839 1 /* # states */ , 00840 meta_null ); 00841 00842 //------------------------------ 00843 // Declare a rank three and two states: 00844 00845 FieldBase * const f3 = 00846 field_repo.declare_field( std::string("F3"), 00847 data_traits<int>(), 00848 3 /* # ranks */ , 00849 dim_tags /* dimension tags */ , 00850 2 /* # states */ , 00851 meta_null ); 00852 00853 FieldBase * const f3_old = f3->m_impl.field_state( StateOld ) ; 00854 00855 //------------------------------ 00856 // Test for correctness of vector of declared fields. 00857 STKUNIT_ASSERT( allocated_fields.size() == 3 ); 00858 STKUNIT_ASSERT( f2 == allocated_fields[0] ); 00859 STKUNIT_ASSERT( f3 == allocated_fields[1] ); 00860 00861 //------------------------------ 00862 // Test for correctness of field internal state access: 00863 00864 STKUNIT_ASSERT( f2 == f2->field_state( StateNone ) ); 00865 STKUNIT_ASSERT( NULL == f2->field_state( StateOld ) ); 00866 STKUNIT_ASSERT( f3 == f3->field_state( StateNew ) ); 00867 STKUNIT_ASSERT( f3_old == f3->field_state( StateOld ) ); 00868 STKUNIT_ASSERT( NULL == f3->field_state( StateNM1 ) ); 00869 STKUNIT_ASSERT( f3 == f3_old->field_state( StateNew ) ); 00870 STKUNIT_ASSERT( f3_old == f3_old->field_state( StateOld ) ); 00871 STKUNIT_ASSERT( NULL == f3_old->field_state( StateNM1 ) ); 00872 00873 STKUNIT_ASSERT( f2->rank() == 2 ); 00874 STKUNIT_ASSERT( f3->rank() == 3 ); 00875 STKUNIT_ASSERT( f3_old->rank() == 3 ); 00876 00877 //------------------------------ 00878 // Declare some parts for restrictions: 00879 00880 std::vector< std::string > dummy_names(1); 00881 dummy_names[0].assign("dummy"); 00882 00883 stk::mesh::MetaData m( dummy_names ); 00884 00885 impl::PartRepository partRepo( &m ); 00886 Part & universal = * partRepo.universal_part(); 00887 00888 Part & pA = * partRepo.declare_part( std::string("A") , 0 ); 00889 Part & pB = * partRepo.declare_part( std::string("B") , 0 ); 00890 Part & pC = * partRepo.declare_part( std::string("C") , 0 ); 00891 Part & pD = * partRepo.declare_part( std::string("D") , 0 ); 00892 00893 // Declare three restrictions: 00894 00895 f3->m_impl.insert_restriction( method , 0 , pA , stride ); 00896 f3->m_impl.insert_restriction( method , 1 , pB , stride + 1 ); 00897 f3->m_impl.insert_restriction( method , 2 , pC , stride + 2 ); 00898 00899 // Check for correctness of restrictions: 00900 00901 STKUNIT_ASSERT( f3->restrictions().size() == 3 ); 00902 STKUNIT_ASSERT( f3->restrictions()[0].key == 00903 EntityKey( 0 , pA.mesh_meta_data_ordinal() ) ); 00904 STKUNIT_ASSERT( f3->restrictions()[1].key == 00905 EntityKey( 1 , pB.mesh_meta_data_ordinal() ) ); 00906 STKUNIT_ASSERT( f3->restrictions()[2].key == 00907 EntityKey( 2 , pC.mesh_meta_data_ordinal() ) ); 00908 00909 f3->m_impl.insert_restriction( method , 0 , pB , stride + 1 ); 00910 00911 STKUNIT_ASSERT_EQUAL( f3->max_size( 0 ) , stride[3] ); 00912 00913 //------------------------------ 00914 // Check for error detection of bad stride: 00915 { 00916 bool caught = false ; 00917 try { 00918 unsigned bad_stride[4] = { 5 , 4 , 6 , 3 }; 00919 f3->m_impl.insert_restriction( method , 0 , pA , bad_stride ); 00920 } 00921 catch( const std::exception & x ) { 00922 caught = true ; 00923 std::cout << "Field: Correctly caught: " << x.what() << std::endl ; 00924 } 00925 STKUNIT_ASSERT( caught ); 00926 STKUNIT_ASSERT( f3->restrictions().size() == 4 ); 00927 } 00928 00929 // Check for error detection in re-declaring an incompatible 00930 // field restriction. 00931 { 00932 bool caught = false ; 00933 try { 00934 f3->m_impl.insert_restriction( method , 0 , pA , stride + 1 ); 00935 } 00936 catch( const std::exception & x ) { 00937 caught = true ; 00938 std::cout << "Field: Correctly caught: " << x.what() << std::endl ; 00939 } 00940 STKUNIT_ASSERT( caught ); 00941 STKUNIT_ASSERT( f3->restrictions().size() == 4 ); 00942 } 00943 00944 // Verify and clean out any redundant restructions: 00945 00946 f2->m_impl.verify_and_clean_restrictions( method , universal.subsets() ); 00947 f3->m_impl.verify_and_clean_restrictions( method , universal.subsets() ); 00948 00949 STKUNIT_ASSERT( f3->restrictions().size() == 4 ); 00950 00951 //------------------------------ 00952 // Introduce a redundant restriction, clean it, and 00953 // check that it was cleaned. 00954 00955 partRepo.declare_subset( pD, pA ); 00956 f2->m_impl.insert_restriction( method , 0 , pA , stride ); 00957 f2->m_impl.insert_restriction( method , 0 , pD , stride ); 00958 00959 STKUNIT_ASSERT( f2->restrictions().size() == 2 ); 00960 00961 f2->m_impl.verify_and_clean_restrictions( method , universal.subsets() ); 00962 00963 STKUNIT_ASSERT( f2->restrictions().size() == 1 ); 00964 00965 { 00966 const FieldBase::Restriction & rA = f2->restriction( 0 , pA ); 00967 const FieldBase::Restriction & rD = f2->restriction( 0 , pD ); 00968 STKUNIT_ASSERT( & rA == & rD ); 00969 STKUNIT_ASSERT( entity_id( rA.key ) == pD.mesh_meta_data_ordinal() ); 00970 } 00971 00972 //------------------------------ 00973 // Introduce a new restriction, then introduce a 00974 // subset-superset relationship that renders the new restriction 00975 // redundant and incompatible. 00976 // Check that the verify_and_clean_restrictions method detects 00977 // this error condition. 00978 { 00979 f2->m_impl.insert_restriction( method , 0 , pB , stride + 1 ); 00980 f2->m_impl.verify_and_clean_restrictions( method , universal.subsets() ); 00981 partRepo.declare_subset( pD, pB ); 00982 bool caught = false ; 00983 try { 00984 f2->m_impl.verify_and_clean_restrictions( method , universal.subsets() ); 00985 } 00986 catch( const std::exception & x ) { 00987 caught = true ; 00988 std::cout << "Field: Correctly caught: " << x.what() << std::endl ; 00989 } 00990 STKUNIT_ASSERT( caught ); 00991 } 00992 00993 //Test to cover print function in FieldBaseImpl.cpp 00994 { 00995 //Create a new field with MetaData m and two restrictions 00996 00997 FieldBase * const f4 = 00998 field_repo.declare_field( std::string("F4"), 00999 data_traits<int>(), 01000 3 /* # ranks */ , 01001 dim_tags /* dimension tags */ , 01002 2 /* # states */ , 01003 &m ); 01004 01005 partRepo.declare_subset( pD, pA ); 01006 partRepo.declare_subset( pC, pB ); 01007 01008 f4->m_impl.insert_restriction( method , 0 , pA , stride ); 01009 f4->m_impl.insert_restriction( method , 1 , pB , stride + 1 ); 01010 stk::mesh::impl::print(std::cout, "Field f4", *f4); 01011 } 01012 01013 //Coverage for error from print_restriction in FieldBaseImpl.cpp when there is no stride (!stride[i]) 01014 //Call print_restriction from insert_restriction 01015 { 01016 int ok = 0 ; 01017 try { 01018 unsigned arg_stride[2]; 01019 01020 arg_stride[0] = 1.0; 01021 arg_stride[1] = 0.1; 01022 01023 f2->m_impl.insert_restriction(method, 0, pA, arg_stride); 01024 01025 } 01026 catch( const std::exception & x ) { 01027 ok = 1 ; 01028 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 01029 << x.what() 01030 << std::endl ; 01031 } 01032 01033 if ( ! ok ) { 01034 throw std::runtime_error("UnitTestMetaData FAILED to catch error for iterator from print_restriction inFieldBaseImpl.cpp"); 01035 } 01036 } 01037 01038 std::cout << std::endl ; 01039 } 01040 01041 //---------------------------------------------------------------------- 01042 01043 void UnitTestMetaData::testProperty() 01044 { 01045 std::vector< std::string > dummy_names(1); 01046 dummy_names[0].assign("dummy"); 01047 01048 stk::mesh::MetaData meta_data( dummy_names ); 01049 stk::mesh::MetaData meta_data2( dummy_names ); 01050 01051 stk::mesh::Property<int> & pi = meta_data.declare_property<int>("my_i"); 01052 stk::mesh::Property<double> & pf = meta_data.declare_property<double>("my_d"); 01053 stk::mesh::Property<double> & px = meta_data.declare_property<double>("my_x"); 01054 stk::mesh::Property<double> & pa = meta_data.declare_property<double>("my_array",5); 01055 01056 STKUNIT_ASSERT( pi.type_is<int>() ); 01057 STKUNIT_ASSERT( pf.type_is<double>() ); 01058 STKUNIT_ASSERT( px.type_is<double>() ); 01059 STKUNIT_ASSERT( pa.type_is<double>() ); 01060 01061 STKUNIT_ASSERT( ! pi.type_is<double>() ); 01062 STKUNIT_ASSERT( ! pa.type_is<int>() ); 01063 01064 STKUNIT_ASSERT_EQUAL( pi.size() , 1u ); 01065 STKUNIT_ASSERT_EQUAL( pf.size() , 1u ); 01066 STKUNIT_ASSERT_EQUAL( px.size() , 1u ); 01067 STKUNIT_ASSERT_EQUAL( pa.size() , 5u ); 01068 01069 meta_data.put_property( pi , meta_data.locally_owned_part() ); 01070 01071 STKUNIT_ASSERT( stk::mesh::property_data( pi , meta_data.locally_owned_part() ) != NULL); 01072 STKUNIT_ASSERT( ! stk::mesh::property_data( px , meta_data.locally_owned_part() ) ); 01073 01074 stk::mesh::Property<int> * property(); 01075 01076 const stk::mesh::PropertyBase * p = NULL; 01077 property_data_throw( *p, meta_data.locally_owned_part()); 01078 01080 01081 const std::string& str = "my_i"; 01082 const std::string& str2 = "my_d"; 01083 01084 stk::mesh::Property<int> * const pProp = meta_data.get_property<int>( str ); 01085 STKUNIT_ASSERT( (*pProp).type_is<int>() ); 01086 01087 { 01088 int ok = 0 ; 01089 try { 01090 meta_data.get_property<double>( str ); 01091 } 01092 catch( const std::exception & x ) { 01093 ok = 1 ; 01094 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 01095 << x.what() 01096 << std::endl ; 01097 } 01098 01099 if ( ! ok ) { 01100 throw std::runtime_error("UnitTestMetaData FAILED to catch error for get_property"); 01101 } 01102 } 01103 01104 { 01105 int ok = 0 ; 01106 try { 01107 meta_data.get_property<int>( str2 ); 01108 } 01109 catch( const std::exception & x ) { 01110 ok = 1 ; 01111 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 01112 << x.what() 01113 << std::endl ; 01114 } 01115 01116 if ( ! ok ) { 01117 throw std::runtime_error("UnitTestMetaData FAILED to catch error for get_property"); 01118 } 01119 } 01120 01121 //Final coverage of MetaData.hpp - declare_property 01122 stk::mesh::Property<double> & pb = meta_data.declare_property<double>("my_array",0); 01123 STKUNIT_ASSERT( (pb).type_is<double>() ); 01124 01125 //More coverage of Property.hpp 01126 STKUNIT_ASSERT( stk::mesh::property_data( pi , meta_data2.locally_owned_part() )); 01127 } 01128 01129 } 01130 } 01131 01132 //---------------------------------------------------------------------- 01133 //---------------------------------------------------------------------- 01134 01135 namespace { 01136 int stencil_test_function( unsigned from_type , 01137 unsigned to_type , 01138 unsigned identifier ) 01139 { 01140 return 0; 01141 } 01142 01143 } 01144 01145 namespace stk { 01146 namespace mesh { 01147 01148 void UnitTestMetaData::testMetaData() 01149 { 01150 const int spatial_dimension = 3; 01151 const std::vector<std::string> & type_names = TopologicalMetaData::entity_rank_names(spatial_dimension); 01152 01153 MetaData metadata2( type_names ); 01154 MetaData metadata3( type_names ); 01155 MetaData metadata4( type_names ); 01156 01157 STKUNIT_ASSERT_THROW(metadata3.assert_committed("test throw"),std::logic_error); 01158 metadata3.commit(); 01159 STKUNIT_ASSERT_THROW(metadata3.assert_not_committed("test throw"),std::logic_error); 01160 STKUNIT_ASSERT_THROW(metadata3.assert_same_mesh_meta_data("test throw",metadata2),std::logic_error); 01161 std::string test_string = "this_part_does_not_exist"; 01162 STKUNIT_ASSERT_THROW(metadata3.get_part(test_string,"test_throw"),std::runtime_error); 01163 01164 //test declare part 01165 Part * const pa = & metadata4.declare_part( std::string("a") , 0 ); 01166 Part * const pb = & metadata4.declare_part( std::string("b") , 0 ); 01167 Part * const pc = & metadata4.declare_part( std::string("c") , 0 ); 01168 Part * const pd = & metadata4.declare_part( std::string("d") , 0 ); 01169 Part * const pe = & metadata4.declare_part( std::string("e") , 0 ); 01170 Part * const pf = & metadata4.declare_part( std::string("f") , 0 ); 01171 Part * const pg = & metadata4.declare_part( std::string("g") , 0 ); 01172 Part * const ph = & metadata4.declare_part( std::string("h") , 0 ); 01173 01174 metadata4.declare_part_relation(*pe,stencil_test_function,*pg); 01175 01176 PartVector part_vector; 01177 01178 part_vector.push_back(pa); 01179 part_vector.push_back(pb); 01180 part_vector.push_back(pc); 01181 part_vector.push_back(pd); 01182 01183 //Part * const intersection_part = & 01184 metadata4.declare_part(part_vector); 01185 01186 STKUNIT_ASSERT_THROW( metadata4.declare_part_subset(*pe,*pe), std::runtime_error); 01187 metadata4.declare_part_subset(*pd,*pf); 01188 01189 STKUNIT_ASSERT_THROW( metadata4.declare_part_relation(*pg,stencil_test_function,*ph), std::runtime_error); 01190 STKUNIT_ASSERT_THROW( metadata4.declare_part_relation(*pe,NULL,*pe), std::runtime_error); 01191 01192 { 01193 bool caught_throw = false; 01194 try { 01195 std::vector<std::string> empty_names; 01196 MetaData metadata5(empty_names); 01197 } 01198 catch(...) { 01199 caught_throw = true; 01200 } 01201 STKUNIT_ASSERT_EQUAL(caught_throw, true); 01202 } 01203 01204 int i = 2; 01205 01206 const std::string& i_name2 = metadata2.entity_rank_name( i ); 01207 01208 STKUNIT_ASSERT( i_name2 == type_names[i] ); 01209 01210 EntityRank one_rank_higher_than_defined = type_names.size(); 01211 STKUNIT_ASSERT_THROW( 01212 metadata2.entity_rank_name( one_rank_higher_than_defined ), 01213 std::runtime_error 01214 ); 01215 } 01216 01217 void UnitTestMetaData::testEntityRepository() 01218 { 01219 //Test Entity repository - covering EntityRepository.cpp/hpp 01220 01221 stk::mesh::MetaData meta ( stk::unit_test::get_entity_rank_names ( 3 ) ); 01222 stk::mesh::Part & part = meta.declare_part( "another part"); 01223 01224 meta.commit(); 01225 01226 stk::mesh::BulkData bulk ( meta , MPI_COMM_WORLD , 100 ); 01227 std::vector<stk::mesh::Part *> add_part; 01228 add_part.push_back ( &part ); 01229 01230 int size , rank; 01231 rank = stk::parallel_machine_rank( MPI_COMM_WORLD ); 01232 size = stk::parallel_machine_size( MPI_COMM_WORLD ); 01233 PartVector tmp(1); 01234 01235 bulk.modification_begin(); 01236 01237 int id_base = 0; 01238 for ( id_base = 0 ; id_base < 97 ; ++id_base ) 01239 { 01240 int new_id = size * id_base + rank; 01241 bulk.declare_entity( 0 , new_id+1 , add_part ); 01242 } 01243 01244 int new_id = size * (++id_base) + rank; 01245 stk::mesh::Entity & elem = bulk.declare_entity( 3 , new_id+1 , add_part ); 01246 01247 //new_id = size * (++id_base) + rank; 01248 // stk::mesh::Entity & elem2 = bulk.declare_entity( 3 , new_id+1 , add_part ); 01249 01250 stk::mesh::impl::EntityRepository e; 01251 01252 e.comm_clear( elem ); 01253 01254 e.comm_clear_ghosting( elem ); 01255 01256 const stk::mesh::Ghosting & ghost = bulk.shared_aura(); 01257 01258 bulk.modification_end(); 01259 01260 STKUNIT_ASSERT_FALSE(e.erase_ghosting(elem, ghost)); 01261 01262 const stk::mesh::EntityCommInfo comm_info( ghost.ordinal() , 0 ); 01263 01264 STKUNIT_ASSERT_FALSE(e.erase_comm_info(elem, comm_info)); 01265 01266 STKUNIT_ASSERT(e.insert_comm_info(elem, comm_info)); 01267 01268 //Checking internal_create_entity 01269 01270 e.internal_create_entity( stk::mesh::EntityKey( 3, 2 )); 01271 e.internal_create_entity( stk::mesh::EntityKey( 3, 5 )); 01272 e.internal_create_entity( stk::mesh::EntityKey( 3, 7 )); 01273 01274 //Checking get_entity with invalid key - no rank or id 01275 { 01276 int ok = 0 ; 01277 try { 01278 01279 stk::mesh::Entity * elem3 = e.get_entity(stk::mesh::EntityKey()); 01280 if(elem3){ 01281 // CAROL FIXME 01282 } 01283 01284 } 01285 catch( const std::exception & x ) { 01286 ok = 1 ; 01287 std::cout << "UnitTestMetaData CORRECTLY caught error for : " 01288 << x.what() 01289 << std::endl ; 01290 } 01291 if ( ! ok ) { 01292 throw std::runtime_error("UnitTestMetaData FAILED to catch error for get_entity - invalid key"); 01293 } 01294 } 01295 } 01296 01297 //---------------------------------------------------------------------- 01298 01299 } 01300 } 01301