|
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 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_classic { 00022 namespace mesh { 00023 00024 //---------------------------------------------------------------------- 00025 00026 AllSelectedBucketsRange get_buckets( const Selector & selector, const BulkData& mesh ) 00027 { 00028 AllBucketsRange all_buckets = mesh.get_bucket_range(); 00029 return get_selected_bucket_range(all_buckets, selector); 00030 } 00031 00032 AllBucketsRange get_buckets( const BulkData& mesh ) 00033 { 00034 return mesh.get_bucket_range(); 00035 } 00036 00037 AllBucketsRange get_buckets( EntityRank entity_rank, const BulkData& mesh ) 00038 { 00039 return mesh.get_bucket_range(entity_rank); 00040 } 00041 00042 AllSelectedBucketsRange get_buckets( const Selector & selector, const AllBucketsRange& range) 00043 { 00044 return get_selected_bucket_range(range, selector); 00045 } 00046 00047 void copy_ids( std::vector<unsigned> & v , const PartVector & p ) 00048 { 00049 { 00050 const size_t n = p.size(); 00051 v.resize( n ); 00052 for ( size_t k = 0 ; k < n ; ++k ) { 00053 v[k] = p[k]->mesh_meta_data_ordinal(); 00054 } 00055 } 00056 00057 { 00058 std::vector<unsigned>::iterator i = v.begin() , j = v.end(); 00059 std::sort( i , j ); 00060 i = std::unique( i , j ); 00061 v.erase( i , j ); 00062 } 00063 } 00064 00065 void get_involved_parts( 00066 const PartVector & union_parts, 00067 const Bucket & candidate, 00068 PartVector & involved_parts 00069 ) 00070 { 00071 involved_parts.clear(); 00072 if (union_parts.size() == 0) { 00073 return; 00074 } 00075 00076 // Used to convert part ordinals to part pointers: 00077 MetaData & meta_data = MetaData::get( * union_parts[0]); 00078 const PartVector & all_parts = meta_data.get_parts(); 00079 00080 const std::pair<const unsigned *,const unsigned *> 00081 bucket_part_begin_end_iterators = candidate.superset_part_ordinals(); // sorted and unique 00082 00083 std::vector<unsigned> union_parts_ids; 00084 copy_ids( union_parts_ids , union_parts ); // sorted and unique 00085 std::vector<unsigned>::const_iterator union_part_id_it = union_parts_ids.begin(); 00086 const unsigned * bucket_part_id_it = bucket_part_begin_end_iterators.first ; 00087 00088 while ( union_part_id_it != union_parts_ids.end() && 00089 bucket_part_id_it != bucket_part_begin_end_iterators.second ) 00090 { 00091 if ( *union_part_id_it < *bucket_part_id_it ) { 00092 ++union_part_id_it ; 00093 } 00094 else if ( *bucket_part_id_it < *union_part_id_it ) { 00095 ++bucket_part_id_it ; 00096 } 00097 else { 00098 // Find every match: 00099 Part * const part = all_parts[ *union_part_id_it ]; 00100 involved_parts.push_back( part ); 00101 ++union_part_id_it; 00102 ++bucket_part_id_it; 00103 } 00104 } 00105 00106 } 00107 00108 //---------------------------------------------------------------------- 00109 00110 } // namespace mesh 00111 } // namespace stk_classic 00112 00113