Sierra Toolkit Version of the Day
GetEntities.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 
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 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 SelectedBucketRangeEntityIteratorRange get_selected_entities( const Selector & selector,
00102                                                               const AllBucketsRange& bucket_range )
00103 {
00104   return get_selected_bucket_entity_range(bucket_range, selector);
00105 }
00106 
00107 //----------------------------------------------------------------------
00108 
00109 void count_entities(
00110   const Selector & selector ,
00111   const BulkData & mesh ,
00112   std::vector< EntityRank > & count )
00113 {
00114   const size_t nranks = MetaData::get(mesh).entity_rank_count();
00115 
00116   count.resize( nranks );
00117 
00118   for ( size_t i = 0 ; i < nranks ; ++i ) {
00119     count[i] = 0 ;
00120 
00121     const std::vector<Bucket*> & ks = mesh.buckets( i );
00122 
00123     std::vector<Bucket*>::const_iterator ik ;
00124 
00125     for ( ik = ks.begin() ; ik != ks.end() ; ++ik ) {
00126       if ( selector(**ik) ) {
00127         count[i] += (*ik)->size();
00128       }
00129     }
00130   }
00131 }
00132 
00133 //----------------------------------------------------------------------
00134 
00135 } // namespace mesh
00136 } // namespace stk
00137 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends