|
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 { 00021 namespace mesh { 00022 00023 //---------------------------------------------------------------------- 00024 00025 void get_entities( const BulkData & mesh , EntityRank type , 00026 std::vector< Entity*> & entities ) 00027 { 00028 const std::vector<Bucket*> & ks = mesh.buckets( type ); 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 unsigned count_selected_entities( 00054 const Selector & selector , 00055 const std::vector< Bucket * > & input_buckets ) 00056 { 00057 size_t count = 0; 00058 00059 const std::vector<Bucket*>::const_iterator ie = input_buckets.end(); 00060 std::vector<Bucket*>::const_iterator ik = input_buckets.begin(); 00061 00062 for ( ; ik != ie ; ++ik ) { 00063 const Bucket & k = ** ik ; 00064 if ( selector( k ) ) { count += k.size(); } 00065 } 00066 00067 return count ; 00068 } 00069 00070 00071 void get_selected_entities( const Selector & selector , 00072 const std::vector< Bucket * > & input_buckets , 00073 std::vector< Entity * > & entities ) 00074 { 00075 size_t count = count_selected_entities(selector,input_buckets); 00076 00077 entities.resize(count); 00078 00079 const std::vector<Bucket*>::const_iterator ie = input_buckets.end(); 00080 std::vector<Bucket*>::const_iterator ik = input_buckets.begin(); 00081 00082 for ( size_t j = 0 ; ik != ie ; ++ik ) { 00083 const Bucket & k = ** ik ; 00084 if ( selector( k ) ) { 00085 const size_t n = k.size(); 00086 for ( size_t i = 0; i < n; ++i, ++j ) { 00087 entities[j] = &k[i] ; 00088 } 00089 } 00090 } 00091 00092 std::sort(entities.begin(), entities.end(), EntityLess()); 00093 } 00094 00095 00096 //---------------------------------------------------------------------- 00097 00098 void count_entities( 00099 const Selector & selector , 00100 const BulkData & mesh , 00101 std::vector< EntityRank > & count ) 00102 { 00103 const size_t ntype = mesh.mesh_meta_data().entity_rank_count(); 00104 00105 count.resize( ntype ); 00106 00107 for ( size_t i = 0 ; i < ntype ; ++i ) { 00108 count[i] = 0 ; 00109 00110 const std::vector<Bucket*> & ks = mesh.buckets( i ); 00111 00112 std::vector<Bucket*>::const_iterator ik ; 00113 00114 for ( ik = ks.begin() ; ik != ks.end() ; ++ik ) { 00115 if ( selector(**ik) ) { 00116 count[i] += (*ik)->size(); 00117 } 00118 } 00119 } 00120 } 00121 00122 //---------------------------------------------------------------------- 00123 00124 } // namespace mesh 00125 } // namespace stk 00126