Sierra Toolkit  Version of the Day
GetBuckets.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 //----------------------------------------------------------------------
10 
11 #include <algorithm>
12 #include <stk_mesh/base/Types.hpp>
13 #include <stk_mesh/base/GetBuckets.hpp>
14 #include <stk_mesh/base/BulkData.hpp>
15 #include <stk_mesh/base/MetaData.hpp>
16 #include <stk_mesh/base/Bucket.hpp>
17 #include <stk_mesh/base/Part.hpp>
18 
19 //----------------------------------------------------------------------
20 
21 namespace stk_classic {
22 namespace mesh {
23 
24 //----------------------------------------------------------------------
25 
26 AllSelectedBucketsRange get_buckets( const Selector & selector, const BulkData& mesh )
27 {
28  AllBucketsRange all_buckets = mesh.get_bucket_range();
29  return get_selected_bucket_range(all_buckets, selector);
30 }
31 
32 AllBucketsRange get_buckets( const BulkData& mesh )
33 {
34  return mesh.get_bucket_range();
35 }
36 
37 AllBucketsRange get_buckets( EntityRank entity_rank, const BulkData& mesh )
38 {
39  return mesh.get_bucket_range(entity_rank);
40 }
41 
42 AllSelectedBucketsRange get_buckets( const Selector & selector, const AllBucketsRange& range)
43 {
44  return get_selected_bucket_range(range, selector);
45 }
46 
47 void copy_ids( std::vector<unsigned> & v , const PartVector & p )
48 {
49  {
50  const size_t n = p.size();
51  v.resize( n );
52  for ( size_t k = 0 ; k < n ; ++k ) {
53  v[k] = p[k]->mesh_meta_data_ordinal();
54  }
55  }
56 
57  {
58  std::vector<unsigned>::iterator i = v.begin() , j = v.end();
59  std::sort( i , j );
60  i = std::unique( i , j );
61  v.erase( i , j );
62  }
63 }
64 
65 void get_involved_parts(
66  const PartVector & union_parts,
67  const Bucket & candidate,
68  PartVector & involved_parts
69  )
70 {
71  involved_parts.clear();
72  if (union_parts.size() == 0) {
73  return;
74  }
75 
76  // Used to convert part ordinals to part pointers:
77  MetaData & meta_data = MetaData::get( * union_parts[0]);
78  const PartVector & all_parts = meta_data.get_parts();
79 
80  const std::pair<const unsigned *,const unsigned *>
81  bucket_part_begin_end_iterators = candidate.superset_part_ordinals(); // sorted and unique
82 
83  std::vector<unsigned> union_parts_ids;
84  copy_ids( union_parts_ids , union_parts ); // sorted and unique
85  std::vector<unsigned>::const_iterator union_part_id_it = union_parts_ids.begin();
86  const unsigned * bucket_part_id_it = bucket_part_begin_end_iterators.first ;
87 
88  while ( union_part_id_it != union_parts_ids.end() &&
89  bucket_part_id_it != bucket_part_begin_end_iterators.second )
90  {
91  if ( *union_part_id_it < *bucket_part_id_it ) {
92  ++union_part_id_it ;
93  }
94  else if ( *bucket_part_id_it < *union_part_id_it ) {
95  ++bucket_part_id_it ;
96  }
97  else {
98  // Find every match:
99  Part * const part = all_parts[ *union_part_id_it ];
100  involved_parts.push_back( part );
101  ++union_part_id_it;
102  ++bucket_part_id_it;
103  }
104  }
105 
106 }
107 
108 //----------------------------------------------------------------------
109 
110 } // namespace mesh
111 } // namespace stk_classic
112 
113 
This is a class for selecting buckets based on a set of meshparts and set logic.
Definition: Selector.hpp:112
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
Sierra Toolkit.
AllSelectedBucketsRange get_buckets(const Selector &selector, const BulkData &mesh)
Definition: GetBuckets.cpp:26
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).