Sierra Toolkit  Version of the Day
GetEntities.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 
13 #include <stdexcept>
14 #include <iostream>
15 #include <sstream>
16 #include <algorithm>
17 
18 #include <stk_mesh/base/GetEntities.hpp>
19 
20 namespace stk_classic {
21 namespace mesh {
22 
23 //----------------------------------------------------------------------
24 
25 void get_entities( const BulkData & mesh , EntityRank entity_rank ,
26  std::vector< Entity*> & entities )
27 {
28  const std::vector<Bucket*> & ks = mesh.buckets( entity_rank );
29  entities.clear();
30 
31  size_t count = 0;
32 
33  const std::vector<Bucket*>::const_iterator ie = ks.end();
34  std::vector<Bucket*>::const_iterator ik = ks.begin();
35 
36  for ( ; ik != ie ; ++ik ) { count += (*ik)->size(); }
37 
38  entities.reserve(count);
39 
40  ik = ks.begin();
41 
42  for ( ; ik != ie ; ++ik ) {
43  const Bucket & k = **ik ;
44  size_t n = k.size();
45  for(size_t i = 0; i < n; ++i) {
46  entities.push_back(&k[i]);
47  }
48  }
49 
50  std::sort(entities.begin(), entities.end(), EntityLess());
51 }
52 
53 BucketVectorEntityIteratorRange get_entities( EntityRank entity_rank, const BulkData& mesh )
54 {
55  const std::vector<Bucket*>& buckets = mesh.buckets(entity_rank);
56  return get_entity_range(buckets);
57 }
58 
60  const Selector & selector ,
61  const std::vector< Bucket * > & input_buckets )
62 {
63  size_t count = 0;
64 
65  const std::vector<Bucket*>::const_iterator ie = input_buckets.end();
66  std::vector<Bucket*>::const_iterator ik = input_buckets.begin();
67 
68  for ( ; ik != ie ; ++ik ) {
69  const Bucket & k = ** ik ;
70  if ( selector( k ) ) { count += k.size(); }
71  }
72 
73  return count ;
74 }
75 
76 
77 void get_selected_entities( const Selector & selector ,
78  const std::vector< Bucket * > & input_buckets ,
79  std::vector< Entity * > & entities )
80 {
81  size_t count = count_selected_entities(selector,input_buckets);
82 
83  entities.resize(count);
84 
85  const std::vector<Bucket*>::const_iterator ie = input_buckets.end();
86  std::vector<Bucket*>::const_iterator ik = input_buckets.begin();
87 
88  for ( size_t j = 0 ; ik != ie ; ++ik ) {
89  const Bucket & k = ** ik ;
90  if ( selector( k ) ) {
91  const size_t n = k.size();
92  for ( size_t i = 0; i < n; ++i, ++j ) {
93  entities[j] = &k[i] ;
94  }
95  }
96  }
97 
98  std::sort(entities.begin(), entities.end(), EntityLess());
99 }
100 
101 #if 0
102 //this code is broken
103 // \TODO fix
104 SelectedBucketRangeEntityIteratorRange get_selected_entities( const Selector & selector,
105  const AllBucketsRange& bucket_range )
106 {
107  return get_selected_bucket_entity_range(bucket_range, selector);
108 }
109 #endif
110 
111 //----------------------------------------------------------------------
112 
114  const Selector & selector ,
115  const BulkData & mesh ,
116  std::vector< EntityRank > & count )
117 {
118  const size_t nranks = MetaData::get(mesh).entity_rank_count();
119 
120  count.resize( nranks );
121 
122  for ( size_t i = 0 ; i < nranks ; ++i ) {
123  count[i] = 0 ;
124 
125  const std::vector<Bucket*> & ks = mesh.buckets( i );
126 
127  std::vector<Bucket*>::const_iterator ik ;
128 
129  for ( ik = ks.begin() ; ik != ks.end() ; ++ik ) {
130  if ( selector(**ik) ) {
131  count[i] += (*ik)->size();
132  }
133  }
134  }
135 }
136 
137 //----------------------------------------------------------------------
138 
139 } // namespace mesh
140 } // namespace stk_classic
141 
Comparison operator for entities compares the entities&#39; keys.
Definition: Entity.hpp:478
unsigned count_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets)
Count entities in selected buckets (selected by the given selector instance), and sorted by ID...
Definition: GetEntities.cpp:59
This is a class for selecting buckets based on a set of meshparts and set logic.
Definition: Selector.hpp:112
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
Definition: BulkData.hpp:195
void get_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets, std::vector< Entity * > &entities)
Get entities in selected buckets (selected by the given selector instance), and sorted by ID...
Definition: GetEntities.cpp:77
size_t size() const
Number of entities associated with this bucket.
Definition: Bucket.hpp:119
void get_entities(const BulkData &mesh, EntityRank entity_rank, std::vector< Entity *> &entities)
Get all entities of the specified type, sorted by ID.
Definition: GetEntities.cpp:25
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
Sierra Toolkit.
void count_entities(const Selector &selector, const BulkData &mesh, std::vector< EntityRank > &count)
Local count selected entities of each type.
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).