Sierra Toolkit  Version of the Day
Bucket.hpp
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 #ifndef stk_mesh_Bucket_hpp
10 #define stk_mesh_Bucket_hpp
11 
12 //----------------------------------------------------------------------
13 
14 #include <iosfwd>
15 #include <vector>
16 #include <algorithm>
17 
18 #include <stk_util/environment/ReportHandler.hpp>
19 
20 #include <stk_mesh/baseImpl/BucketImpl.hpp>
21 
22 #include <stk_mesh/base/Types.hpp>
23 #include <stk_mesh/base/Field.hpp>
24 #include <stk_mesh/base/Part.hpp>
25 #include <stk_mesh/base/Entity.hpp>
26 
27 #include <boost/iterator/transform_iterator.hpp>
28 #include <boost/iterator/indirect_iterator.hpp>
29 
30 //----------------------------------------------------------------------
31 
32 #ifdef SIERRA_MIGRATION
33 
34 namespace sierra {
35 namespace Fmwk {
36 
37 class MeshBulkData;
38 
39 }
40 }
41 
42 
43 #endif
44 
45 namespace stk_classic {
46 namespace mesh {
47 
48 namespace impl {
49 class BucketRepository;
50 } // namespace impl
51 
52 
60 std::ostream & operator << ( std::ostream & , const Bucket & );
61 
63 std::ostream &
64 print( std::ostream & , const std::string & indent , const Bucket & );
65 
66 // The part count and parts are equal
67 bool bucket_part_equal( const unsigned * lhs , const unsigned * rhs );
68 
69 //----------------------------------------------------------------------
73 bool has_superset( const Bucket & , const Part & p );
74 
78 bool has_superset( const Bucket & , const unsigned & ordinal );
79 
83 bool has_superset( const Bucket & , const PartVector & );
84 
85 
86 //----------------------------------------------------------------------
94 class Bucket {
95 private:
96  friend class impl::BucketRepository;
97  friend class impl::BucketImpl;
98 
99  impl::BucketImpl m_bucketImpl;
100 
101 #ifdef SIERRA_MIGRATION
102  const void* m_fmwk_mesh_bulk_data;
103 #endif
104 
105 public:
106 
107  //--------------------------------
108  // Container-like types and methods:
109 
110  typedef boost::indirect_iterator<Entity*const*> iterator ;
111 
113  inline iterator begin() const { return iterator(m_bucketImpl.begin()); }
114 
116  inline iterator end() const { return iterator(m_bucketImpl.end()); }
117 
119  size_t size() const { return m_bucketImpl.size() ; }
120 
122  size_t capacity() const { return m_bucketImpl.capacity() ; }
123 
125  Entity & operator[] ( size_t i ) const { return m_bucketImpl[i] ; }
126 
128  unsigned field_data_size(const FieldBase & field) const
129  { return m_bucketImpl.field_data_size(field); }
130 
132  const FieldBase::Restriction::size_type * field_data_stride( const FieldBase & field ) const
133  { return m_bucketImpl.field_data_stride(field); }
134 
136  unsigned char * field_data_location( const FieldBase & field, const Entity & entity ) const
137  { return m_bucketImpl.field_data_location(field,entity); }
138 
140  unsigned char * field_data_location( const FieldBase & field, unsigned ordinal ) const
141  { return m_bucketImpl.field_data_location(field, ordinal); }
142 
147  unsigned char * fast_field_data_location( const FieldBase & field, unsigned ordinal ) const
148  { return m_bucketImpl.fast_field_data_location(field, ordinal); }
149 
151  unsigned char * field_data_location( const FieldBase & field ) const
152  { return m_bucketImpl.field_data_location(field); }
153 
155  template< class field_type >
156  typename FieldTraits< field_type >::data_type *
157  field_data( const field_type & field , const Entity & entity ) const
158  { return m_bucketImpl.field_data(field,entity.bucket_ordinal()); }
159 
160  //--------------------------------
164  BulkData & mesh() const { return m_bucketImpl.mesh(); }
165 
167  unsigned entity_rank() const { return m_bucketImpl.entity_rank(); }
168 
170  void supersets( PartVector & ) const ;
171  void supersets( OrdinalVector & ) const ;
172 
173  //--------------------------------
175  bool member( const Part & ) const ;
176 
178  bool member_all( const PartVector & ) const ;
179  bool member_all( const OrdinalVector & ) const ;
180 
182  bool member_any( const PartVector & ) const ;
183  bool member_any( const OrdinalVector & ) const ;
184 
185  //--------------------------------
187  std::pair<const unsigned *, const unsigned *>
188  superset_part_ordinals() const { return m_bucketImpl.superset_part_ordinals() ; }
189 
192  bool equivalent( const Bucket& b ) const {
193  return m_bucketImpl.equivalent(b.m_bucketImpl);
194  }
195 
196 #ifndef DOXYGEN_COMPILE
197  const unsigned * key() const { return m_bucketImpl.key() ; }
198 #endif /* DOXYGEN_COMPILE */
199 
201  unsigned allocation_size() const { return m_bucketImpl.allocation_size() ; }
202 
204  bool assert_correct() const;
205 
206 #ifdef SIERRA_MIGRATION
207  typedef std::pair<iterator, iterator> EntityRange;
208 
209  bool is_empty() const { return size() == 0; }
210 
211  const sierra::Fmwk::MeshBulkData* get_bulk_data() const
212  {
213  return static_cast<const sierra::Fmwk::MeshBulkData*>(m_fmwk_mesh_bulk_data);
214  }
215 
216  template <class T>
217  void set_bulk_data(const T* bulk_ptr) { m_fmwk_mesh_bulk_data = bulk_ptr; }
218 #endif
219 
220 private:
224  BulkData & bulk_data() const { return m_bucketImpl.mesh(); }
225 
226  // Only reason to define this at all is to ensure it's private
227  ~Bucket() {}
228 
229  Bucket();
230  Bucket( const Bucket & );
231  Bucket & operator = ( const Bucket & );
232 
233  Bucket( BulkData & arg_mesh ,
234  EntityRank arg_entity_rank,
235  const std::vector<unsigned> & arg_key,
236  size_t arg_capacity
237  );
238 
239  friend class ::stk_classic::mesh::BulkData;
240 };
241 
242 
243 struct BucketLess {
244  bool operator()( const Bucket * lhs_bucket , const unsigned * rhs ) const ;
245  bool operator()( const unsigned * lhs , const Bucket * rhs_bucket ) const ;
246 };
247 
248 
249 inline
250 std::vector<Bucket*>::iterator
251 lower_bound( std::vector<Bucket*> & v , const unsigned * key )
252 { return std::lower_bound( v.begin() , v.end() , key , BucketLess() ); }
253 
254 inline
255 Bucket::Bucket( BulkData & arg_mesh ,
256  EntityRank arg_entity_rank,
257  const std::vector<unsigned> & arg_key,
258  size_t arg_capacity
259  )
260  : m_bucketImpl(arg_mesh,arg_entity_rank,arg_key,arg_capacity)
261 {}
262 
265 inline
266 bool Bucket::member_all( const OrdinalVector& parts ) const
267 {
268  const unsigned * const i_beg = key() + 1 ;
269  const unsigned * const i_end = key() + key()[0] ;
270 
271  const OrdinalVector::const_iterator ip_end = parts.end();
272  OrdinalVector::const_iterator ip = parts.begin() ;
273 
274  bool result_all = true ;
275 
276  for ( ; result_all && ip_end != ip ; ++ip ) {
277  const unsigned ord = *ip;
278  result_all = contains_ordinal(i_beg, i_end, ord);
279  }
280  return result_all ;
281 }
282 
283 struct To_Ptr : std::unary_function<Entity&, Entity*>
284 {
285  Entity* operator()(Entity& entity) const
286  {
287  return &entity;
288  }
289 };
290 
291 // Sometimes, we want a bucket-iterator to dereference to an Entity*
292 typedef boost::transform_iterator<To_Ptr, Bucket::iterator> BucketPtrIterator;
293 
294 typedef Bucket::iterator BucketIterator;
295 
296 } // namespace mesh
297 } // namespace stk_classic
298 
299 #endif
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
Definition: Bucket.cpp:259
BulkData & mesh() const
The bulk data manager that owns this bucket.
Definition: Bucket.hpp:164
Field base class with an anonymous data type and anonymous multi-dimension.
Definition: FieldBase.hpp:53
Definition: Env.cpp:53
bool has_superset(const Bucket &bucket, const unsigned &ordinal)
Is this bucket a subset of the given part by partID.
Definition: Bucket.cpp:127
bool assert_correct() const
A method to assist in unit testing - accesses private data as necessary.
Definition: Bucket.cpp:225
unsigned field_data_size(const FieldBase &field) const
Query the size of this field data specified by FieldBase.
Definition: Bucket.hpp:128
bool member_all(const PartVector &) const
Bucket is a subset of all of the given parts.
Definition: Bucket.cpp:71
bool member_any(const PartVector &) const
Bucket is a subset of any of the given parts.
Definition: Bucket.cpp:89
unsigned char * fast_field_data_location(const FieldBase &field, unsigned ordinal) const
Query the location of this field data specified by FieldBase and Entity-bucket-ordinal This method sh...
Definition: Bucket.hpp:147
const FieldBase::Restriction::size_type * field_data_stride(const FieldBase &field) const
Query the stride of this field data specified by FieldBase.
Definition: Bucket.hpp:132
std::pair< const unsigned *, const unsigned * > superset_part_ordinals() const
Definition: Bucket.hpp:188
An application-defined subset of a problem domain.
Definition: Part.hpp:49
size_t size() const
Number of entities associated with this bucket.
Definition: Bucket.hpp:119
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
Definition: Bucket.cpp:239
unsigned char * field_data_location(const FieldBase &field, const Entity &entity) const
Query the location of this field data specified by FieldBase and Entity.
Definition: Bucket.hpp:136
unsigned char * field_data_location(const FieldBase &field) const
Query the location of this field data specified by FieldBase.
Definition: Bucket.hpp:151
unsigned allocation_size() const
The allocation size, in bytes, of this bucket.
Definition: Bucket.hpp:201
Entity & operator[](size_t i) const
Query the i^th entity.
Definition: Bucket.hpp:125
iterator begin() const
Beginning of the bucket.
Definition: Bucket.hpp:113
iterator end() const
End of the bucket.
Definition: Bucket.hpp:116
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
unsigned char * field_data_location(const FieldBase &field, unsigned ordinal) const
Query the location of this field data specified by FieldBase and Entity-bucket-ordinal.
Definition: Bucket.hpp:140
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
Sierra Toolkit.
void supersets(PartVector &) const
This bucket is a subset of these parts.
Definition: Bucket.cpp:164
bool equivalent(const Bucket &b) const
Equivalent buckets have the same parts.
Definition: Bucket.hpp:192
size_t capacity() const
Capacity of this bucket.
Definition: Bucket.hpp:122
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94
FieldTraits< field_type >::data_type * field_data(const field_type &field, const Entity &entity) const
Query the location of this field data specified by FieldBase and Entity.
Definition: Bucket.hpp:157
bool member(const Part &) const
Bucket is a subset of the given part.
Definition: Bucket.cpp:60
unsigned entity_rank() const
Type of entities in this bucket.
Definition: Bucket.hpp:167