|
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 #include <map> 00013 00014 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 00015 00016 #include <stk_util/parallel/Parallel.hpp> 00017 00018 #include <stk_mesh/base/Types.hpp> 00019 #include <stk_mesh/base/MetaData.hpp> 00020 #include <stk_mesh/base/Entity.hpp> 00021 #include <stk_mesh/base/EntityKey.hpp> 00022 #include <stk_mesh/base/Field.hpp> 00023 #include <stk_mesh/base/Bucket.hpp> 00024 #include <stk_mesh/base/BulkData.hpp> 00025 #include <stk_mesh/base/Ghosting.hpp> 00026 #include <stk_mesh/base/Field.hpp> 00027 00028 #include <stk_mesh/baseImpl/EntityRepository.hpp> 00029 00030 #include <stk_mesh/fem/FEMMetaData.hpp> 00031 00032 using stk_classic::ParallelMachine; 00033 using stk_classic::mesh::MetaData; 00034 using stk_classic::mesh::BulkData; 00035 using stk_classic::mesh::Part; 00036 using stk_classic::mesh::PartVector; 00037 using stk_classic::mesh::PartRelation; 00038 using stk_classic::mesh::EntityKey; 00039 using stk_classic::mesh::Entity; 00040 using stk_classic::mesh::Bucket; 00041 using stk_classic::mesh::impl::PartRepository; 00042 using stk_classic::mesh::impl::EntityRepository; 00043 00044 namespace { 00045 00046 //---------------------------------------------------------------------- 00047 00048 STKUNIT_UNIT_TEST(UnitTestEntity,testEntityKey) 00049 { 00050 EntityKey key_bad_zero = EntityKey(); 00051 EntityKey key_good_0_1 = EntityKey( 0 , 1 ); 00052 EntityKey key_good_1_1 = EntityKey( 1 , 1 ); 00053 EntityKey key_good_2_10 = EntityKey( 2 , 10); 00054 EntityKey key_order_1_12 = EntityKey( 1 , 12 ); 00055 EntityKey key_order_2_10 = EntityKey( 2 , 10 ); 00056 00057 STKUNIT_ASSERT( ! entity_key_valid( key_bad_zero ) ); 00058 STKUNIT_ASSERT( entity_key_valid( key_good_0_1 ) ); 00059 STKUNIT_ASSERT( entity_key_valid( key_good_1_1 ) ); 00060 STKUNIT_ASSERT( entity_key_valid( key_good_2_10 ) ); 00061 00062 STKUNIT_ASSERT( 0 == entity_rank( key_good_0_1)); 00063 STKUNIT_ASSERT( 1 == entity_rank( key_good_1_1) ); 00064 STKUNIT_ASSERT( 2 == entity_rank( key_good_2_10) ); 00065 STKUNIT_ASSERT( 1 == entity_id( key_good_0_1) ); 00066 STKUNIT_ASSERT( 1 == entity_id( key_good_1_1) ); 00067 STKUNIT_ASSERT( 10 == entity_id( key_good_2_10) ); 00068 00069 STKUNIT_ASSERT( key_order_1_12 < key_order_2_10); 00070 STKUNIT_ASSERT( !( key_order_1_12 > key_order_2_10)); 00071 00072 #ifndef NDEBUG 00073 STKUNIT_ASSERT_THROW( EntityKey( ~0u , 1 ) , std::logic_error ); 00074 STKUNIT_ASSERT_THROW( EntityKey( 0 , ~stk_classic::mesh::EntityKey::raw_key_type(0) ) , std::logic_error ); 00075 #endif // NDEBUG 00076 } 00077 00078 00079 STKUNIT_UNIT_TEST(UnitTestEntity,testEntityRepository) 00080 { 00081 //Test Entity repository - covering EntityRepository.cpp/hpp 00082 const int spatial_dimension = 3; 00083 MetaData meta(stk_classic::mesh::fem::entity_rank_names(spatial_dimension)); 00084 Part & part = meta.declare_part( "another part"); 00085 MPI_Barrier( MPI_COMM_WORLD ); 00086 ParallelMachine pm = MPI_COMM_WORLD; 00087 BulkData bulk( meta , pm, 200 ); 00088 const int rank = stk_classic::parallel_machine_rank( pm ); 00089 const int size = stk_classic::parallel_machine_size( pm ); 00090 std::vector<stk_classic::mesh::Part *> add_part; 00091 meta.commit(); 00092 00093 // Bail if not parallel. This test involves inducing errorneous conditions that 00094 // are only checked-for in parallel. 00095 if (size == 1) { 00096 return; 00097 } 00098 00099 add_part.push_back ( & part ); 00100 00101 bulk.modification_begin(); 00102 00103 int id_base = 0; 00104 for ( id_base = 0 ; id_base < 97 ; ++id_base ) 00105 { 00106 int new_id = size * id_base + rank; 00107 bulk.declare_entity( 0 , new_id+1 , add_part ); 00108 } 00109 00110 int new_id = size * (++id_base) + rank; 00111 stk_classic::mesh::Entity & elem = bulk.declare_entity( 3 , new_id+1 , add_part ); 00112 00113 bool use_memory_pool = false; 00114 stk_classic::mesh::impl::EntityRepository e(use_memory_pool); 00115 00116 e.comm_clear( elem ); 00117 00118 e.comm_clear_ghosting( elem ); 00119 00120 const stk_classic::mesh::Ghosting & ghost = bulk.shared_aura(); 00121 00122 STKUNIT_ASSERT_FALSE(e.erase_ghosting(elem, ghost)); 00123 00124 const stk_classic::mesh::EntityCommInfo comm_info( ghost.ordinal() , 0 ); 00125 00126 STKUNIT_ASSERT_FALSE(e.erase_comm_info(elem, comm_info)); 00127 00128 STKUNIT_ASSERT(e.insert_comm_info(elem, comm_info)); 00129 00130 //Coverage of verfify_parallel_attributes in BulkDataParallelVerify.cpp 00131 //for owned_closure = 1 AND recv_ghost = 1. 00132 //Also uses pack and unpack in DataTraits.cpp, DataTraitsClass.hpp and DataTraitsEnum.hpp 00133 STKUNIT_ASSERT_THROW(bulk.modification_end(), std::runtime_error); 00134 00135 bulk.modification_begin(); 00136 00137 00138 //Checking internal_create_entity 00139 00140 e.internal_create_entity( stk_classic::mesh::EntityKey( 3, 2 )); 00141 e.internal_create_entity( stk_classic::mesh::EntityKey( 3, 5 )); 00142 e.internal_create_entity( stk_classic::mesh::EntityKey( 3, 7 )); 00143 00144 //Checking get_entity with invalid key - no rank or id 00145 { 00146 STKUNIT_ASSERT_THROW( 00147 e.get_entity(stk_classic::mesh::EntityKey()), 00148 std::runtime_error 00149 ); 00150 } 00151 00152 // stk_classic::mesh::impl::EntityRepository::EntityMap eMap; 00153 stk_classic::mesh::Entity & elem2 = bulk.declare_entity( 3 , new_id+8 , add_part ); 00154 stk_classic::mesh::Entity & elem3 = bulk.declare_entity( 3 , new_id+9 , add_part ); 00155 stk_classic::mesh::Entity & elem4 = bulk.declare_entity( 3 , new_id+10 , add_part ); 00156 00157 e.internal_create_entity( stk_classic::mesh::EntityKey( 3, new_id+8 )); 00158 e.internal_create_entity( stk_classic::mesh::EntityKey( 3, new_id+9 )); 00159 e.internal_create_entity( stk_classic::mesh::EntityKey( 3, new_id+10 )); 00160 00161 typedef std::map<EntityKey,Entity*> EntityMap; 00162 EntityMap entity_map_array; 00163 00164 entity_map_array[stk_classic::mesh::EntityKey( 3, new_id+8 )] = &elem2; 00165 entity_map_array[stk_classic::mesh::EntityKey( 3, new_id+9 )] = &elem3; 00166 entity_map_array[stk_classic::mesh::EntityKey( 3, new_id+10 )] = &elem4; 00167 00168 //Coverage of destroy_later in EntityRepository.cpp 00169 Bucket *nil_bucket = bulk.buckets(3)[0]; 00170 e.destroy_later(elem2, nil_bucket); 00171 //Call a second time for more coverage 00172 STKUNIT_ASSERT_THROW(e.destroy_later(elem2, nil_bucket), std::runtime_error); 00173 00174 //Coverage of !comm_mesh_verify_parallel_consistency in BulkDataEndSync.cpp 00175 //in internal_modification_end function 00176 Bucket *nil_bucket2 = bulk.buckets(0)[0]; 00177 00178 STKUNIT_ASSERT ( nil_bucket2 != NULL); 00179 00180 e.destroy_later(elem3, nil_bucket2); 00181 00182 STKUNIT_ASSERT_THROW(bulk.modification_end(), std::runtime_error); 00183 00184 bulk.modification_begin(); 00185 00186 STKUNIT_ASSERT_THROW(e.destroy_later(elem2, nil_bucket), std::runtime_error); 00187 00188 STKUNIT_ASSERT_THROW(bulk.modification_end(), std::runtime_error); 00189 00190 bulk.modification_begin(); 00191 STKUNIT_ASSERT_THROW(bulk.modification_end(), std::runtime_error); 00192 } 00193 00194 //---------------------------------------------------------------------- 00195 }//namespace <anonymous> 00196