Sierra Toolkit Version of the Day
UnitTestSelector.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #include <stdexcept>
00011 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00012 
00013 #include <stk_mesh/base/Selector.hpp>
00014 #include <stk_mesh/base/Bucket.hpp>
00015 #include <stk_mesh/base/Part.hpp>
00016 #include <stk_mesh/base/Types.hpp>
00017 #include <stk_mesh/base/GetBuckets.hpp>
00018 #include <stk_util/environment/WallTime.hpp>
00019 
00020 #include <stk_util/parallel/Parallel.hpp>
00021 
00022 #include <stk_mesh/fixtures/SelectorFixture.hpp>
00023 
00024 // Unit test the Selector in isolation
00025 
00026 namespace {
00027 
00028 using stk::mesh::fixtures::SelectorFixture ;
00029 
00030 void initialize(SelectorFixture& fixture)
00031 {
00032   fixture.m_meta_data.commit();
00033   fixture.m_bulk_data.modification_begin();
00034   fixture.generate_mesh();
00035   STKUNIT_ASSERT(fixture.m_bulk_data.modification_end());
00036 }
00037 
00073 STKUNIT_UNIT_TEST( UnitTestSelector, one_SelectorFixture )
00074 {
00075   {
00076     SelectorFixture fix;
00077     initialize(fix);
00078   }
00079   STKUNIT_EXPECT_TRUE(true);
00080 }
00081 
00082 
00086 STKUNIT_UNIT_TEST( UnitTestSelector, two_SelectorFixture )
00087 {
00088   {
00089     SelectorFixture fix;
00090     initialize(fix);
00091   }
00092   {
00093     SelectorFixture fix;
00094     initialize(fix);
00095   }
00096   STKUNIT_EXPECT_TRUE(true);
00097 }
00098 
00099 
00100 
00106 STKUNIT_UNIT_TEST( UnitTestSelector, A_12345 )
00107 {
00108   SelectorFixture fix;
00109   initialize(fix);
00110 
00111   stk::mesh::Selector selector( fix.m_partA );
00112   //std::cout << "Selector = " << selector << std::endl;
00113 
00114   {
00115     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket() ;
00116     bool result = selector(bucket);
00117     STKUNIT_EXPECT_TRUE(result);
00118   }
00119   {
00120     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00121     bool result = selector(bucket);
00122     STKUNIT_EXPECT_TRUE(result);
00123   }
00124   {
00125     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00126     bool result = selector(bucket);
00127     STKUNIT_EXPECT_FALSE(result);
00128   }
00129   {
00130     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00131     bool result = selector(bucket);
00132     STKUNIT_EXPECT_FALSE(result);
00133   }
00134   {
00135     const stk::mesh::Bucket & bucket = fix.m_entity5->bucket();
00136     bool result = selector(bucket);
00137     STKUNIT_EXPECT_FALSE(result);
00138   }
00139 }
00140 
00146 STKUNIT_UNIT_TEST( UnitTestSelector, Ac_12345 )
00147 {
00148   SelectorFixture fix;
00149   initialize(fix);
00150 
00151   stk::mesh::Selector selector = ! fix.m_partA ;
00152   //std::cout << "Selector = " << selector << std::endl;
00153 
00154   {
00155     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00156     bool result = selector(bucket);
00157     STKUNIT_EXPECT_FALSE(result);
00158   }
00159   {
00160     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00161     bool result = selector(bucket);
00162     STKUNIT_EXPECT_FALSE(result);
00163   }
00164   {
00165     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00166     bool result = selector(bucket);
00167     STKUNIT_EXPECT_TRUE(result);
00168   }
00169   {
00170     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00171     bool result = selector(bucket);
00172     STKUNIT_EXPECT_TRUE(result);
00173   }
00174   {
00175     const stk::mesh::Bucket & bucket = fix.m_entity5->bucket();
00176     bool result = selector(bucket);
00177     STKUNIT_EXPECT_TRUE(result);
00178   }
00179 
00180 }
00181 
00185 STKUNIT_UNIT_TEST( UnitTestSelector, D_5 )
00186 {
00187   SelectorFixture fix;
00188   initialize(fix);
00189 
00190   stk::mesh::Selector selector( fix.m_partD );
00191 
00192   const stk::mesh::Bucket & bucket = fix.m_entity5->bucket();
00193 
00194   bool result = selector(bucket);
00195   STKUNIT_EXPECT_FALSE(result);
00196 }
00197 
00201 STKUNIT_UNIT_TEST( UnitTestSelector, Ac_15 )
00202 {
00203   SelectorFixture fix;
00204   initialize(fix);
00205 
00206   stk::mesh::Part & partA = fix.m_partA ;
00207 
00208   stk::mesh::Selector selector(partA);
00209   selector.complement();
00210   //std::cout << "Selector = " << selector << std::endl;
00211 
00212   {
00213     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00214     bool result = selector(bucket);
00215     STKUNIT_EXPECT_FALSE(result);
00216   }
00217   {
00218     const stk::mesh::Bucket & bucket = fix.m_entity5->bucket();
00219     bool result = selector(bucket);
00220     STKUNIT_EXPECT_TRUE(result);
00221   }
00222 }
00223 
00228 STKUNIT_UNIT_TEST( UnitTestSelector, AiB_12 )
00229 {
00230   SelectorFixture fix ;
00231   initialize(fix);
00232 
00233   stk::mesh::Part & partA = fix.m_partA ;
00234   stk::mesh::Part & partB = fix.m_partB ;
00235 
00236   stk::mesh::Selector selector = partA & partB;
00237   //std::cout << "Selector = " << selector << std::endl;
00238 
00239   {
00240     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00241     bool result = selector(bucket);
00242     STKUNIT_EXPECT_FALSE(result);
00243   }
00244   {
00245     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00246     bool result = selector(bucket);
00247     STKUNIT_EXPECT_TRUE(result);
00248   }
00249 }
00250 
00251 
00255 STKUNIT_UNIT_TEST( UnitTestSelector, AuB_14 )
00256 {
00257   SelectorFixture fix ;
00258   initialize(fix);
00259 
00260   stk::mesh::Part & partA = fix.m_partA ;
00261   stk::mesh::Part & partB = fix.m_partB ;
00262 
00263   stk::mesh::Selector selector = partA | partB;
00264   //std::cout << "Selector = " << selector << std::endl;
00265 
00266   {
00267     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00268     bool result = selector(bucket);
00269     STKUNIT_EXPECT_TRUE(result);
00270   }
00271   {
00272     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00273     bool result = selector(bucket);
00274     STKUNIT_EXPECT_FALSE(result);
00275   }
00276 }
00277 
00278 
00282 STKUNIT_UNIT_TEST( UnitTestSelector, AiBc_12 )
00283 {
00284   SelectorFixture fix ;
00285   initialize(fix);
00286 
00287   stk::mesh::Part & partA = fix.m_partA ;
00288   stk::mesh::Part & partB = fix.m_partB ;
00289 
00290   stk::mesh::Selector selector = partA & !partB;
00291   //std::cout << "Selector = " << selector << std::endl;
00292 
00293   {
00294     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00295     bool result = selector(bucket);
00296     STKUNIT_EXPECT_TRUE(result);
00297   }
00298   {
00299     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00300     bool result = selector(bucket);
00301     STKUNIT_EXPECT_FALSE(result);
00302   }
00303 }
00304 
00305 
00309 STKUNIT_UNIT_TEST( UnitTestSelector, AuBc_13 )
00310 {
00311   SelectorFixture fix ;
00312   initialize(fix);
00313 
00314   stk::mesh::Part & partA = fix.m_partA ;
00315   stk::mesh::Part & partB = fix.m_partB ;
00316 
00317   stk::mesh::Selector selector = partA | !partB;
00318   //std::cout << "Selector = " << selector << std::endl;
00319 
00320   {
00321     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00322     bool result = selector(bucket);
00323     STKUNIT_EXPECT_TRUE(result);
00324   }
00325   {
00326     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00327     bool result = selector(bucket);
00328     STKUNIT_EXPECT_FALSE(result);
00329   }
00330 }
00331 
00332 
00333 // plus copy constructor
00338 STKUNIT_UNIT_TEST( UnitTestSelector, Ai_BuC_c_12 )
00339 {
00340   SelectorFixture fix ;
00341   initialize(fix);
00342 
00343   stk::mesh::Part & partA = fix.m_partA ;
00344   stk::mesh::Part & partB = fix.m_partB ;
00345   stk::mesh::Part & partC = fix.m_partC ;
00346 
00347   stk::mesh::Selector selector = partA & !(partB | partC);
00348   //std::cout << "Selector = " << selector << std::endl;
00349 
00350   {
00351     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00352     bool result = selector(bucket);
00353     STKUNIT_EXPECT_TRUE(result);
00354   }
00355   {
00356     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00357     bool result = selector(bucket);
00358     STKUNIT_EXPECT_FALSE(result);
00359   }
00360 
00361   stk::mesh::Selector newSelector(selector);
00362   // Should be the same:
00363   {
00364     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00365     bool result = newSelector(bucket);
00366     STKUNIT_EXPECT_TRUE(result);
00367   }
00368   {
00369     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00370     bool result = newSelector(bucket);
00371     STKUNIT_EXPECT_FALSE(result);
00372   }
00373 
00374 }
00375 
00376 
00380 STKUNIT_UNIT_TEST( UnitTestSelector, entityTest )
00381 {
00382   {
00383     SelectorFixture fix ;
00384     initialize(fix);
00385 
00386     stk::mesh::Part & partA = fix.m_partA ;
00387     stk::mesh::Part & partB = fix.m_partB ;
00388     stk::mesh::Selector selector = partA & !partB;
00389 
00390     const stk::mesh::Entity & pEntity = *fix.m_entity5;
00391     bool result = selector(pEntity);
00392     STKUNIT_EXPECT_FALSE(result);
00393   }
00394 
00395 }
00396 
00400 STKUNIT_UNIT_TEST( UnitTestSelector, defaultConstructor )
00401 {
00402   SelectorFixture fix ;
00403   initialize(fix);
00404 
00405   stk::mesh::Selector selector;
00406   //std::cout << "Selector = " << selector << std::endl;
00407 
00408   {
00409     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00410     bool result = selector(bucket);
00411     STKUNIT_EXPECT_FALSE(result);
00412   }
00413 }
00414 
00415 
00423 STKUNIT_UNIT_TEST( UnitTestSelector, flipComplement_AuB_c )
00424 {
00425   SelectorFixture fix ;
00426   initialize(fix);
00427 
00428   stk::mesh::Part & partA = fix.m_partA ;
00429   stk::mesh::Part & partB = fix.m_partB ;
00430   stk::mesh::Selector notOrSelector = partA | partB;
00431   //std::cout << "Or Selector = " << notOrSelector << std::endl;
00432   notOrSelector.complement();
00433   //std::cout << "Not Or Selector = " << notOrSelector << std::endl;
00434 
00435   {
00436     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00437     bool result = notOrSelector(bucket);
00438     STKUNIT_EXPECT_FALSE(result);
00439   }
00440   {
00441     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00442     bool result = notOrSelector(bucket);
00443     STKUNIT_EXPECT_FALSE(result);
00444   }
00445   {
00446     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00447     bool result = notOrSelector(bucket);
00448     STKUNIT_EXPECT_FALSE(result);
00449   }
00450   {
00451     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00452     bool result = notOrSelector(bucket);
00453     STKUNIT_EXPECT_TRUE(result);
00454   }
00455 
00456   stk::mesh::Selector notNotOrSelector = !notOrSelector;
00457   //std::cout << "Not Not Or Selector = " << notNotOrSelector << std::endl;
00458   {
00459     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00460     bool result = notNotOrSelector(bucket);
00461     STKUNIT_EXPECT_TRUE(result);
00462   }
00463   {
00464     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00465     bool result = notNotOrSelector(bucket);
00466     STKUNIT_EXPECT_TRUE(result);
00467   }
00468   {
00469     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00470     bool result = notNotOrSelector(bucket);
00471     STKUNIT_EXPECT_TRUE(result);
00472   }
00473   {
00474     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00475     bool result = notNotOrSelector(bucket);
00476     STKUNIT_EXPECT_FALSE(result);
00477   }
00478 }
00479 
00487 STKUNIT_UNIT_TEST( UnitTestSelector, flipComplement_AiB_c )
00488 {
00489   SelectorFixture fix ;
00490   initialize(fix);
00491 
00492   stk::mesh::Part & partA = fix.m_partA ;
00493   stk::mesh::Part & partB = fix.m_partB ;
00494   stk::mesh::Selector notAndSelector = partA & partB;
00495   //std::cout << "And Selector = " << notAndSelector << std::endl;
00496   notAndSelector.complement();
00497   //std::cout << "Not And Selector = " << notAndSelector << std::endl;
00498 
00499   {
00500     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00501     bool result = notAndSelector(bucket);
00502     STKUNIT_EXPECT_TRUE(result);
00503   }
00504   {
00505     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00506     bool result = notAndSelector(bucket);
00507     STKUNIT_EXPECT_FALSE(result);
00508   }
00509   {
00510     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00511     bool result = notAndSelector(bucket);
00512     STKUNIT_EXPECT_TRUE(result);
00513   }
00514   {
00515     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00516     bool result = notAndSelector(bucket);
00517     STKUNIT_EXPECT_TRUE(result);
00518   }
00519 
00520   stk::mesh::Selector notNotAndSelector = !notAndSelector;
00521   //std::cout << "Not Not And Selector = " << notNotAndSelector << std::endl;
00522   {
00523     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00524     bool result = notNotAndSelector(bucket);
00525     STKUNIT_EXPECT_FALSE(result);
00526   }
00527   {
00528     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00529     bool result = notNotAndSelector(bucket);
00530     STKUNIT_EXPECT_TRUE(result);
00531   }
00532   {
00533     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00534     bool result = notNotAndSelector(bucket);
00535     STKUNIT_EXPECT_FALSE(result);
00536   }
00537   {
00538     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00539     bool result = notNotAndSelector(bucket);
00540     STKUNIT_EXPECT_FALSE(result);
00541   }
00542 }
00543 
00550 STKUNIT_UNIT_TEST( UnitTestSelector, complementEmpty ) {
00551   SelectorFixture fix ;
00552   initialize(fix);
00553 
00554   stk::mesh::Selector selector;
00555   {
00556     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00557     bool result = selector(bucket);
00558     STKUNIT_EXPECT_FALSE(result);
00559   }
00560   selector.complement();
00561   {
00562     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00563     bool result = selector(bucket);
00564     STKUNIT_EXPECT_TRUE(result);
00565   }
00566 }
00567 
00568 
00573 STKUNIT_UNIT_TEST( UnitTestSelector, AuBuCuD )
00574 {
00575   SelectorFixture fix ;
00576   initialize(fix);
00577 
00578   stk::mesh::Part & partA = fix.m_partA ;
00579   stk::mesh::Part & partB = fix.m_partB ;
00580   stk::mesh::Part & partC = fix.m_partC ;
00581   stk::mesh::Part & partD = fix.m_partD ;
00582   stk::mesh::Selector selector = partA | partB | partC | partD;
00583   std::cout << "A|B|C|D = " << selector << std::endl;
00584   std::ostringstream msg;
00585   msg << selector;
00586   STKUNIT_EXPECT_EQUAL( "!(!PartA AND !PartB AND !PartC AND !PartD)" , msg.str() );
00587 }
00588 
00589 
00593 STKUNIT_UNIT_TEST( UnitTestSelector, AiBiC )
00594 {
00595   SelectorFixture fix ;
00596   initialize(fix);
00597 
00598   stk::mesh::Part & partA = fix.m_partA ;
00599   stk::mesh::Part & partB = fix.m_partB ;
00600   stk::mesh::Part & partC = fix.m_partC ;
00601   stk::mesh::Selector selector = partA & partB & partC;
00602   std::cout << "A&B&C = " << selector << std::endl;
00603   std::ostringstream msg;
00604   msg << selector;
00605   STKUNIT_EXPECT_TRUE( msg.str() == "PartA AND PartB AND PartC" );
00606 }
00607 
00608 
00612 STKUNIT_UNIT_TEST( UnitTestSelector, complicated )
00613 {
00614   SelectorFixture fix ;
00615   initialize(fix);
00616 
00617   stk::mesh::Part & partA = fix.m_partA ;
00618   stk::mesh::Part & partB = fix.m_partB ;
00619   stk::mesh::Part & partC = fix.m_partC ;
00620   stk::mesh::Part & partD = fix.m_partD ;
00621   stk::mesh::Selector selector =  partA | ( !((partA & partB) | partC)  & (!partD | partB));
00622   std::cout << "complicated selector = " << selector << std::endl;
00623   std::ostringstream msg;
00624   msg << selector;
00625   STKUNIT_EXPECT_EQUAL( "!(!PartA AND !((!(PartA AND PartB) AND !PartC) AND !(PartD AND !PartB)))" , msg.str() );
00626 }
00627 
00628 
00633 STKUNIT_UNIT_TEST( UnitTestSelector, selectIntersection )
00634 {
00635   SelectorFixture fix ;
00636   initialize(fix);
00637 
00638   stk::mesh::PartVector parts ;
00639   parts.push_back( & fix.m_partA );
00640   parts.push_back( & fix.m_partB );
00641   stk::mesh::Selector selector = selectIntersection(parts);
00642 
00643   {
00644     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00645     bool result = selector(bucket);
00646     STKUNIT_ASSERT_FALSE(result);
00647   }
00648   {
00649     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00650     bool result = selector(bucket);
00651     STKUNIT_ASSERT_TRUE(result);
00652   }
00653   {
00654     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00655     bool result = selector(bucket);
00656     STKUNIT_ASSERT_FALSE(result);
00657   }
00658   {
00659     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00660     bool result = selector(bucket);
00661     STKUNIT_ASSERT_FALSE(result);
00662   }
00663   {
00664     const stk::mesh::Bucket & bucket = fix.m_entity5->bucket();
00665     bool result = selector(bucket);
00666     STKUNIT_ASSERT_FALSE(result);
00667   }
00668 
00669   std::ostringstream msg;
00670   msg << selector;
00671   STKUNIT_EXPECT_TRUE( msg.str() == "PartA AND PartB");
00672 }
00673 
00674 
00679 STKUNIT_UNIT_TEST( UnitTestSelector, selectUnion )
00680 {
00681   SelectorFixture fix ;
00682   initialize(fix);
00683 
00684   stk::mesh::PartVector parts ;
00685   parts.push_back( & fix.m_partA );
00686   parts.push_back( & fix.m_partB );
00687   parts.push_back( & fix.m_partC );
00688   stk::mesh::Selector selector = selectUnion(parts);
00689 
00690   {
00691     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00692     bool result = selector(bucket);
00693     STKUNIT_ASSERT_TRUE(result);
00694   }
00695   {
00696     const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00697     bool result = selector(bucket);
00698     STKUNIT_ASSERT_TRUE(result);
00699   }
00700   {
00701     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00702     bool result = selector(bucket);
00703     STKUNIT_ASSERT_TRUE(result);
00704   }
00705   {
00706     const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00707     bool result = selector(bucket);
00708     STKUNIT_ASSERT_TRUE(result);
00709   }
00710   {
00711     const stk::mesh::Bucket & bucket = fix.m_entity5->bucket();
00712     bool result = selector(bucket);
00713     STKUNIT_ASSERT_FALSE(result);
00714   }
00715 
00716   std::ostringstream msg;
00717   msg << selector;
00718   std::cout << "msg.str() = " << msg.str() << std::endl;
00719   STKUNIT_EXPECT_EQUAL( "!(!PartA AND !PartB AND !PartC)", msg.str() );
00720 }
00721 
00722 // Intersection first then union
00723 // & before |
00729 //STKUNIT_UNIT_TEST( UnitTestSelector, orderOfOperations )
00730 //{
00731 //  SelectorFixture fix ;
00732 //  stk::mesh::Part & partA = fix.m_partA ;
00733 //  stk::mesh::Part & partB = fix.m_partB ;
00734 //  stk::mesh::Part & partC = fix.m_partC ;
00735 //  {
00736 //    stk::mesh::Selector selector = partA | partB & partC;
00737 //    //std::cout << "A|B&C selector = " << selector << std::endl;
00738 //    std::ostringstream msg;
00739 //    msg << selector;
00740 //    STKUNIT_EXPECT_EQUAL( "!(!PartA AND !(PartB AND PartC))", msg.str() );
00741 //    {
00742 //      const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00743 //      bool result = selector(bucket);
00744 //      STKUNIT_EXPECT_TRUE(result);
00745 //    }
00746 //    {
00747 //      const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00748 //      bool result = selector(bucket);
00749 //      STKUNIT_EXPECT_TRUE(result);
00750 //    }
00751 //    {
00752 //      const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00753 //      bool result = selector(bucket);
00754 //      STKUNIT_EXPECT_TRUE(result);
00755 //    }
00756 //    {
00757 //      const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00758 //      bool result = selector(bucket);
00759 //      STKUNIT_EXPECT_FALSE(result);
00760 //    }
00761 //  }
00762 //  {
00763 //    stk::mesh::Selector selector = partB & partC | partA;
00764 //    //std::cout << "B&C|A selector = " << selector << std::endl;
00765 //    std::ostringstream msg;
00766 //    msg << selector;
00767 //    STKUNIT_EXPECT_EQUAL( "!(!(PartB AND PartC) AND !PartA)", msg.str() );
00768 //    {
00769 //      const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00770 //      bool result = selector(bucket);
00771 //      STKUNIT_EXPECT_TRUE(result);
00772 //    }
00773 //    {
00774 //      const stk::mesh::Bucket & bucket = fix.m_entity2->bucket();
00775 //      bool result = selector(bucket);
00776 //      STKUNIT_EXPECT_TRUE(result);
00777 //    }
00778 //    {
00779 //      const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00780 //      bool result = selector(bucket);
00781 //      STKUNIT_EXPECT_TRUE(result);
00782 //    }
00783 //    {
00784 //      const stk::mesh::Bucket & bucket = fix.m_entity4->bucket();
00785 //      bool result = selector(bucket);
00786 //      STKUNIT_EXPECT_FALSE(result);
00787 //    }
00788 //  }
00789 //}
00790 
00791 
00796 STKUNIT_UNIT_TEST( UnitTestSelector, ZeroiuZero ) {
00797   SelectorFixture fix ;
00798   initialize(fix);
00799 
00800   stk::mesh::Selector selectNone;
00801   stk::mesh::Selector selectAll;
00802   selectAll.complement();
00803   {
00804     stk::mesh::Selector selector = selectNone & selectAll;
00805     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00806     bool result = selector(bucket);
00807     STKUNIT_EXPECT_FALSE(result);
00808   }
00809   {
00810     stk::mesh::Selector selector = selectNone | selectAll;
00811     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00812     bool result = selector(bucket);
00813     STKUNIT_EXPECT_TRUE(result);
00814   }
00815 
00816 }
00817 
00827 STKUNIT_UNIT_TEST( UnitTestSelector, ZeroiuA )
00828 {
00829   SelectorFixture fix ;
00830   initialize(fix);
00831 
00832   stk::mesh::Part & partA = fix.m_partA ;
00833   stk::mesh::Selector selectNone;
00834   stk::mesh::Selector selectAll;
00835   selectAll.complement();
00836   stk::mesh::Selector selectA = partA;
00837   stk::mesh::Selector selectNoneOrA = selectNone | selectA;
00838   stk::mesh::Selector selectAllAndA = selectAll & selectA;
00839   {
00840     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00841     bool result = selectNoneOrA(bucket);
00842     STKUNIT_EXPECT_TRUE(result);
00843   }
00844   {
00845     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00846     bool result = selectAllAndA(bucket);
00847     STKUNIT_EXPECT_TRUE(result);
00848   }
00849 }
00850 
00851 
00855 STKUNIT_UNIT_TEST( UnitTestSelector, copyConstructor )
00856 {
00857   SelectorFixture fix ;
00858   initialize(fix);
00859 
00860   stk::mesh::Part & partA = fix.m_partA ;
00861   stk::mesh::Part & partB = fix.m_partB ;
00862   stk::mesh::Part & partC = fix.m_partC ;
00863   stk::mesh::Selector selectA = (partA & partB) | partC;
00864   stk::mesh::Selector anotherSelectA(selectA);
00865   std::ostringstream descriptionA;
00866   descriptionA << selectA;
00867   std::ostringstream descriptionAnotherA;
00868   descriptionAnotherA << anotherSelectA;
00869   STKUNIT_EXPECT_EQUAL( descriptionA.str() == descriptionAnotherA.str(), true );
00870 }
00871 
00872 
00879 STKUNIT_UNIT_TEST( UnitTestSelector, AlliuAll )
00880 {
00881   stk::mesh::Selector selectAll;
00882   selectAll.complement();
00883 
00884   stk::mesh::Selector anotherSelectAll;
00885   anotherSelectAll.complement();
00886 
00887   {
00888     stk::mesh::Selector selectAllANDAll = selectAll & anotherSelectAll;
00889     std::ostringstream description;
00890     description << selectAllANDAll;
00891     STKUNIT_EXPECT_EQUAL( "!() AND !()", description.str() );
00892   }
00893   {
00894     stk::mesh::Selector selectAllORAll = selectAll | anotherSelectAll;
00895     std::ostringstream description;
00896     description << selectAllORAll;
00897     STKUNIT_EXPECT_EQUAL( "!(())", description.str() );
00898   }
00899 }
00900 
00904 STKUNIT_UNIT_TEST( UnitTestSelector, selectField )
00905 {
00906   SelectorFixture fix ;
00907   initialize(fix);
00908 
00909   stk::mesh::Selector selectA = stk::mesh::selectField(fix.m_fieldA);
00910   stk::mesh::Selector selectABC = stk::mesh::selectField(fix.m_fieldABC);
00911   {
00912     //entity1 is in partA, so entity1's bucket should be selected by selectA:
00913     const stk::mesh::Bucket & bucket = fix.m_entity1->bucket();
00914     bool result = selectA(bucket);
00915     STKUNIT_EXPECT_TRUE(result);
00916   }
00917   {
00918     //entity3 is not in partA, so entity3's bucket should not be selected by selectA:
00919     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00920     bool result = selectA(bucket);
00921     STKUNIT_EXPECT_FALSE(result);
00922   }
00923   {
00924     //entity3 is in partB, so entity3's bucket should be selected by selectABC:
00925     const stk::mesh::Bucket & bucket = fix.m_entity3->bucket();
00926     bool result = selectABC(bucket);
00927     STKUNIT_EXPECT_TRUE(result);
00928   }
00929 }
00930 
00934 STKUNIT_UNIT_TEST( UnitTestSelector, select_part )
00935 {
00936   SelectorFixture fix ;
00937   initialize(fix);
00938 
00939   stk::mesh::Part & partA = fix.m_partA ;
00940   stk::mesh::Part & partB = fix.m_partB ;
00941   stk::mesh::Part & partC = fix.m_partC ;
00942   stk::mesh::Part & partD = fix.m_partD ;
00943   stk::mesh::Selector selector =  partA | partB | (!partC) | partD;
00944   std::cout << "select_part selector = " << selector << std::endl;
00945   STKUNIT_EXPECT_TRUE(selector(partA));
00946   STKUNIT_EXPECT_TRUE(selector(partB));
00947   STKUNIT_EXPECT_FALSE(selector(partC));
00948   STKUNIT_EXPECT_TRUE(selector(partD));
00949 
00950   selector =  
00951     partA |  
00952     ( !( (partA & partB) | partC)  
00953       & 
00954       (!partD | partB)
00955       );
00956 
00957   STKUNIT_EXPECT_TRUE(selector(partA));
00958   STKUNIT_EXPECT_TRUE(selector(partB));
00959   STKUNIT_EXPECT_FALSE(selector(partC));
00960   STKUNIT_EXPECT_FALSE(selector(partD));
00961 
00962   selector = partC & (!partD);
00963   STKUNIT_EXPECT_FALSE(selector(partA));
00964   STKUNIT_EXPECT_FALSE(selector(partB));
00965   STKUNIT_EXPECT_TRUE(selector(partC));
00966   STKUNIT_EXPECT_FALSE(selector(partD));
00967 
00968 }
00969 
00973 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines