Sierra Toolkit Version of the Day
UnitTestPartRepository.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 
00012 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00013 
00014 #include <stk_mesh/baseImpl/PartRepository.hpp>
00015 
00016 #include <stk_mesh/base/MetaData.hpp>
00017 
00018 #include <stk_mesh/fem/FEMMetaData.hpp>
00019 #include <stk_mesh/fem/FEMHelpers.hpp>
00020 
00021 using stk::mesh::MetaData;
00022 using stk::mesh::BulkData;
00023 using stk::mesh::Part;
00024 using stk::mesh::impl::PartRepository;
00025 
00026 class UnitTestPartRepository
00027 {
00028 public:
00029   UnitTestPartRepository();
00030   ~UnitTestPartRepository() {}
00031 
00032    const int spatial_dimension;
00033    MetaData meta;
00034    stk::mesh::impl::PartRepository partRepo;
00035    stk::mesh::impl::PartRepository partRepo_1;
00036    stk::mesh::impl::PartRepository partRepo_2;
00037 
00038    stk::mesh::Part * universal_part;
00039    stk::mesh::Part * part_A;
00040    stk::mesh::Part * part_B;
00041    stk::mesh::Part * part_C;
00042    stk::mesh::Part * part_D;
00043    stk::mesh::Part * part_1_A;
00044    stk::mesh::Part * part_1_B;
00045    stk::mesh::Part * part_2_A;
00046    std::vector<stk::mesh::Part *> intersection;
00047    stk::mesh::PartRelation relation;
00048    const CellTopologyData * singleton;
00049 };
00050 
00051 UnitTestPartRepository::UnitTestPartRepository()
00052   : spatial_dimension(3)
00053   , meta( stk::mesh::fem::entity_rank_names(spatial_dimension) )
00054   , partRepo( &meta )
00055   , partRepo_1( &meta )
00056   , partRepo_2( &meta )
00057   , universal_part(      partRepo.universal_part()    )
00058   , part_A   (           partRepo.declare_part("A",0) )
00059   , part_B   (           partRepo.declare_part("B",0) )
00060   , part_C   (           partRepo.declare_part("C",0) )
00061   , part_D   (           partRepo.declare_part("D",1) )
00062   , part_1_A (           partRepo_1.declare_part("A",0) )
00063   , part_1_B (           partRepo_1.declare_part("B",0) )
00064   , part_2_A (           partRepo_2.declare_part("A",0) )
00065   , intersection ( )
00066   , relation ( )
00067   , singleton ( NULL )
00068 {
00069  meta.commit();
00070 }
00071 
00072 namespace {
00073 
00074 STKUNIT_UNIT_TEST( UnitTestPartRepository, construct )
00075 {
00076   UnitTestPartRepository upr;
00077   STKUNIT_EXPECT_TRUE( upr.universal_part != NULL );
00078 }
00079 
00080 STKUNIT_UNIT_TEST( UnitTestPartRepository, universal_in_subset )
00081 {
00082   UnitTestPartRepository upr;
00083   STKUNIT_ASSERT_THROW(
00084     upr.partRepo.declare_subset(*upr.part_A,*upr.universal_part),
00085     std::runtime_error
00086     );
00087 }
00088 
00089 STKUNIT_UNIT_TEST( UnitTestPartRepository, subset_equal_superset )
00090 {
00091   UnitTestPartRepository upr;
00092   STKUNIT_ASSERT_THROW(
00093     upr.partRepo.declare_subset(*upr.part_A,*upr.part_A),
00094     std::runtime_error
00095     );
00096 }
00097 
00098 STKUNIT_UNIT_TEST( UnitTestPartRepository, universal_in_intersection )
00099 {
00100   UnitTestPartRepository upr;
00101   upr.intersection.push_back(upr.universal_part);
00102   STKUNIT_ASSERT_THROW(
00103     upr.partRepo.declare_part(upr.intersection),
00104     std::runtime_error
00105     );
00106   upr.intersection.push_back(upr.part_A);
00107   STKUNIT_ASSERT_THROW(
00108     upr.partRepo.declare_part(upr.intersection),
00109     std::runtime_error
00110     );
00111 }
00112 
00113 STKUNIT_UNIT_TEST( UnitTestPartRepository, circular_subset )
00114 {
00115   UnitTestPartRepository upr;
00116   upr.partRepo.declare_subset(*upr.part_A,*upr.part_B);
00117   upr.partRepo.declare_subset(*upr.part_B,*upr.part_C);
00118   STKUNIT_ASSERT_THROW(
00119     upr.partRepo.declare_subset(*upr.part_C,*upr.part_A),
00120     std::runtime_error
00121     );
00122 }
00123 
00124 STKUNIT_UNIT_TEST( UnitTestPartRepository, inconsistent_rank_subset )
00125 {
00126   UnitTestPartRepository upr;
00127   // lower rank cannot contain higher rank:
00128   STKUNIT_ASSERT_THROW(
00129     upr.partRepo.declare_subset(*upr.part_A,*upr.part_D),
00130     std::runtime_error
00131     );
00132   // higher rank can contain lower rank:
00133   STKUNIT_ASSERT_NO_THROW(
00134     upr.partRepo.declare_subset(*upr.part_D,*upr.part_A)
00135     );
00136 }
00137 
00138 STKUNIT_UNIT_TEST( UnitTestPartRepository, two_part_repositories )
00139 {
00140   UnitTestPartRepository upr;
00141   // subset/superset parts must come from same part repository
00142   STKUNIT_ASSERT_THROW(
00143     upr.partRepo_1.declare_subset(*upr.part_1_A,*upr.part_2_A),
00144     std::runtime_error
00145     );
00146 
00147   // intersection contains parts from another part repository
00148   {
00149     upr.intersection.push_back(upr.part_1_A);
00150     upr.intersection.push_back(upr.part_1_B);
00151     STKUNIT_ASSERT_THROW(
00152         upr.partRepo_2.declare_part( upr.intersection ),
00153         std::runtime_error
00154         );
00155   }
00156   // intersection contains parts from multiple part repositories
00157   {
00158     upr.intersection.push_back(upr.part_1_A);
00159     upr.intersection.push_back(upr.part_2_A);
00160     STKUNIT_ASSERT_THROW(
00161         upr.partRepo_1.declare_part( upr.intersection ),
00162         std::runtime_error
00163         );
00164   }
00165 }
00166 
00167 STKUNIT_UNIT_TEST( UnitTestPartRepository, invalid_relation )
00168 {
00169   UnitTestPartRepository upr;
00170   upr.relation.m_root = upr.part_B;
00171   upr.relation.m_target = upr.part_A;
00172   STKUNIT_ASSERT_THROW(
00173       upr.partRepo.declare_part_relation( *upr.part_A, upr.relation, *upr.part_B ),
00174       std::runtime_error
00175       );
00176 }
00177 
00178 //Test covers declare_attribute_no_delete in PartRepository.hpp and PartImpl.hpp
00179 STKUNIT_UNIT_TEST( UnitTestPartRepository, declare_attribute_no_delete )
00180 {
00181   UnitTestPartRepository upr;
00182   upr.partRepo.declare_attribute_no_delete(*upr.part_A, upr.singleton);
00183 
00184 }
00185 
00186 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines