|
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 00013 #include <stdexcept> 00014 #include <iostream> 00015 #include <sstream> 00016 #include <algorithm> 00017 00018 #include <stk_mesh/base/GetEntities.hpp> 00019 00020 namespace stk_classic { 00021 namespace mesh { 00022 00023 //---------------------------------------------------------------------- 00024 00025 void get_entities( const BulkData & mesh , EntityRank entity_rank , 00026 std::vector< Entity*> & entities ) 00027 { 00028 const std::vector<Bucket*> & ks = mesh.buckets( entity_rank ); 00029 entities.clear(); 00030 00031 size_t count = 0; 00032 00033 const std::vector<Bucket*>::const_iterator ie = ks.end(); 00034 std::vector<Bucket*>::const_iterator ik = ks.begin(); 00035 00036 for ( ; ik != ie ; ++ik ) { count += (*ik)->size(); } 00037 00038 entities.reserve(count); 00039 00040 ik = ks.begin(); 00041 00042 for ( ; ik != ie ; ++ik ) { 00043 const Bucket & k = **ik ; 00044 size_t n = k.size(); 00045 for(size_t i = 0; i < n; ++i) { 00046 entities.push_back(&k[i]); 00047 } 00048 } 00049 00050 std::sort(entities.begin(), entities.end(), EntityLess()); 00051 } 00052 00053 BucketVectorEntityIteratorRange get_entities( EntityRank entity_rank, const BulkData& mesh ) 00054 { 00055 const std::vector<Bucket*>& buckets = mesh.buckets(entity_rank); 00056 return get_entity_range(buckets); 00057 } 00058 00059 unsigned count_selected_entities( 00060 const Selector & selector , 00061 const std::vector< Bucket * > & input_buckets ) 00062 { 00063 size_t count = 0; 00064 00065 const std::vector<Bucket*>::const_iterator ie = input_buckets.end(); 00066 std::vector<Bucket*>::const_iterator ik = input_buckets.begin(); 00067 00068 for ( ; ik != ie ; ++ik ) { 00069 const Bucket & k = ** ik ; 00070 if ( selector( k ) ) { count += k.size(); } 00071 } 00072 00073 return count ; 00074 } 00075 00076 00077 void get_selected_entities( const Selector & selector , 00078 const std::vector< Bucket * > & input_buckets , 00079 std::vector< Entity * > & entities ) 00080 { 00081 size_t count = count_selected_entities(selector,input_buckets); 00082 00083 entities.resize(count); 00084 00085 const std::vector<Bucket*>::const_iterator ie = input_buckets.end(); 00086 std::vector<Bucket*>::const_iterator ik = input_buckets.begin(); 00087 00088 for ( size_t j = 0 ; ik != ie ; ++ik ) { 00089 const Bucket & k = ** ik ; 00090 if ( selector( k ) ) { 00091 const size_t n = k.size(); 00092 for ( size_t i = 0; i < n; ++i, ++j ) { 00093 entities[j] = &k[i] ; 00094 } 00095 } 00096 } 00097 00098 std::sort(entities.begin(), entities.end(), EntityLess()); 00099 } 00100 00101 #if 0 00102 //this code is broken 00103 // \TODO fix 00104 SelectedBucketRangeEntityIteratorRange get_selected_entities( const Selector & selector, 00105 const AllBucketsRange& bucket_range ) 00106 { 00107 return get_selected_bucket_entity_range(bucket_range, selector); 00108 } 00109 #endif 00110 00111 //---------------------------------------------------------------------- 00112 00113 void count_entities( 00114 const Selector & selector , 00115 const BulkData & mesh , 00116 std::vector< EntityRank > & count ) 00117 { 00118 const size_t nranks = MetaData::get(mesh).entity_rank_count(); 00119 00120 count.resize( nranks ); 00121 00122 for ( size_t i = 0 ; i < nranks ; ++i ) { 00123 count[i] = 0 ; 00124 00125 const std::vector<Bucket*> & ks = mesh.buckets( i ); 00126 00127 std::vector<Bucket*>::const_iterator ik ; 00128 00129 for ( ik = ks.begin() ; ik != ks.end() ; ++ik ) { 00130 if ( selector(**ik) ) { 00131 count[i] += (*ik)->size(); 00132 } 00133 } 00134 } 00135 } 00136 00137 //---------------------------------------------------------------------- 00138 00139 } // namespace mesh 00140 } // namespace stk_classic 00141