Sierra Toolkit Version of the Day
GetBuckets.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 
00011 #include <algorithm>
00012 #include <stk_mesh/base/Types.hpp>
00013 #include <stk_mesh/base/GetBuckets.hpp>
00014 #include <stk_mesh/base/BulkData.hpp>
00015 #include <stk_mesh/base/MetaData.hpp>
00016 #include <stk_mesh/base/Bucket.hpp>
00017 #include <stk_mesh/base/Part.hpp>
00018 
00019 //----------------------------------------------------------------------
00020 
00021 namespace stk {
00022 namespace mesh {
00023 
00024 //----------------------------------------------------------------------
00025 
00026 void get_buckets( const Selector & selector ,
00027                   const std::vector< Bucket * > & input ,
00028                         std::vector< Bucket * > & output )
00029 {
00030   output.clear();
00031   for ( std::vector< Bucket * >::const_iterator
00032         i = input.begin() ; i != input.end() ; ++i ) {
00033     Bucket * const b = *i ;
00034     if ( selector( *b ) ) { output.push_back( b ); }
00035   }
00036 }
00037 
00038 AllSelectedBucketsRange get_buckets( const Selector & selector, const BulkData& mesh )
00039 {
00040   AllBucketsRange all_buckets = mesh.get_bucket_range();
00041   return get_selected_bucket_range(all_buckets, selector);
00042 }
00043 
00044 AllBucketsRange get_buckets( const BulkData& mesh )
00045 {
00046   return mesh.get_bucket_range();
00047 }
00048 
00049 AllBucketsRange get_buckets( EntityRank entity_rank, const BulkData& mesh )
00050 {
00051   return mesh.get_bucket_range(entity_rank);
00052 }
00053 
00054 AllSelectedBucketsRange get_buckets( const Selector & selector, const AllBucketsRange& range)
00055 {
00056   return get_selected_bucket_range(range, selector);
00057 }
00058 
00059 void copy_ids( std::vector<unsigned> & v , const PartVector & p )
00060 {
00061   {
00062     const size_t n = p.size();
00063     v.resize( n );
00064     for ( size_t k = 0 ; k < n ; ++k ) {
00065       v[k] = p[k]->mesh_meta_data_ordinal();
00066     }
00067   }
00068 
00069   {
00070     std::vector<unsigned>::iterator i = v.begin() , j = v.end();
00071     std::sort( i , j );
00072     i = std::unique( i , j );
00073     v.erase( i , j );
00074   }
00075 }
00076 
00077 void get_involved_parts(
00078     const PartVector & union_parts,
00079     const Bucket & candidate,
00080     PartVector & involved_parts
00081     )
00082 {
00083   involved_parts.clear();
00084   if (union_parts.size() == 0) {
00085     return;
00086   }
00087 
00088   // Used to convert part ordinals to part pointers:
00089   MetaData & meta_data = MetaData::get( * union_parts[0]);
00090   const PartVector & all_parts = meta_data.get_parts();
00091 
00092   const std::pair<const unsigned *,const unsigned *>
00093     bucket_part_begin_end_iterators = candidate.superset_part_ordinals(); // sorted and unique
00094 
00095   std::vector<unsigned> union_parts_ids;
00096   copy_ids( union_parts_ids , union_parts ); // sorted and unique
00097   std::vector<unsigned>::const_iterator union_part_id_it = union_parts_ids.begin();
00098   const unsigned * bucket_part_id_it = bucket_part_begin_end_iterators.first ;
00099 
00100   while ( union_part_id_it != union_parts_ids.end() &&
00101           bucket_part_id_it != bucket_part_begin_end_iterators.second )
00102   {
00103     if      ( *union_part_id_it  < *bucket_part_id_it ) {
00104       ++union_part_id_it ;
00105     }
00106     else if ( *bucket_part_id_it < *union_part_id_it )  {
00107       ++bucket_part_id_it ;
00108     }
00109     else {
00110       // Find every match:
00111       Part * const part = all_parts[ *union_part_id_it ];
00112       involved_parts.push_back( part );
00113       ++union_part_id_it;
00114       ++bucket_part_id_it;
00115     }
00116   }
00117 
00118 }
00119 
00120 //----------------------------------------------------------------------
00121 
00122 } // namespace mesh
00123 } // namespace stk
00124 
00125 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends