|
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 { 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 for ( std::vector< Bucket * >::const_iterator 00031 i = input.begin() ; i != input.end() ; ++i ) { 00032 Bucket * const b = *i ; 00033 if ( selector( *b ) ) { output.push_back( b ); } 00034 } 00035 } 00036 00037 00038 void copy_ids( std::vector<unsigned> & v , const PartVector & p ) 00039 { 00040 { 00041 const size_t n = p.size(); 00042 v.resize( n ); 00043 for ( size_t k = 0 ; k < n ; ++k ) { 00044 v[k] = p[k]->mesh_meta_data_ordinal(); 00045 } 00046 } 00047 00048 { 00049 std::vector<unsigned>::iterator i = v.begin() , j = v.end(); 00050 std::sort( i , j ); 00051 i = std::unique( i , j ); 00052 v.erase( i , j ); 00053 } 00054 } 00055 00056 void get_involved_parts( 00057 const PartVector & union_parts, 00058 const Bucket & candidate, 00059 PartVector & involved_parts 00060 ) 00061 { 00062 involved_parts.clear(); 00063 if (union_parts.size() == 0) { 00064 return; 00065 } 00066 00067 // Used to convert part ordinals to part pointers: 00068 const PartVector & all_parts = union_parts[0]->mesh_meta_data().get_parts(); 00069 00070 const std::pair<const unsigned *,const unsigned *> 00071 bucket_part_begin_end_iterators = candidate.superset_part_ordinals(); // sorted and unique 00072 00073 std::vector<unsigned> union_parts_ids; 00074 copy_ids( union_parts_ids , union_parts ); // sorted and unique 00075 std::vector<unsigned>::const_iterator union_part_id_it = union_parts_ids.begin(); 00076 const unsigned * bucket_part_id_it = bucket_part_begin_end_iterators.first ; 00077 00078 while ( union_part_id_it != union_parts_ids.end() && 00079 bucket_part_id_it != bucket_part_begin_end_iterators.second ) 00080 { 00081 if ( *union_part_id_it < *bucket_part_id_it ) { 00082 ++union_part_id_it ; 00083 } 00084 else if ( *bucket_part_id_it < *union_part_id_it ) { 00085 ++bucket_part_id_it ; 00086 } 00087 else { 00088 // Find every match: 00089 Part * const part = all_parts[ *union_part_id_it ]; 00090 involved_parts.push_back( part ); 00091 ++union_part_id_it; 00092 ++bucket_part_id_it; 00093 } 00094 } 00095 00096 } 00097 00098 //---------------------------------------------------------------------- 00099 00100 } // namespace mesh 00101 } // namespace stk 00102 00103