Sierra Toolkit  Version of the Day
BucketImpl.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 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_BucketImpl_hpp
10 #define stk_mesh_BucketImpl_hpp
11 
12 //----------------------------------------------------------------------
13 
14 #include <stk_mesh/base/Types.hpp>
15 #include <stk_mesh/base/Field.hpp>
16 #include <stk_mesh/base/Entity.hpp>
17 
18 #include <boost/pool/pool_alloc.hpp>
19 //----------------------------------------------------------------------
20 
21 namespace stk_classic {
22 namespace mesh {
23 namespace impl {
24 
25 class BucketImpl {
26  public:
27 
28  struct DataMap {
29  typedef FieldBase::Restriction::size_type size_type ;
30  const size_type * m_stride ;
31  size_type m_base ;
32  size_type m_size ;
33  };
34 
35  BucketImpl( BulkData & arg_mesh ,
36  EntityRank arg_entity_rank,
37  const std::vector<unsigned> & arg_key,
38  size_t arg_capacity
39  );
40 
41  //
42  // External interface:
43  //
44  BulkData & mesh() const { return m_mesh ; }
45  unsigned entity_rank() const { return m_entity_rank ; }
46  const unsigned * key() const { return &m_key[0] ; }
47  const std::vector<unsigned> & key_vector() const { return m_key; }
48 
49  std::pair<const unsigned *, const unsigned *>
50  superset_part_ordinals() const
51  {
52  return std::pair<const unsigned *, const unsigned *>
53  ( key() + 1 , key() + key()[0] );
54  }
55  unsigned allocation_size() const { return 0 ; }
56  size_t capacity() const { return m_capacity ; }
57  size_t size() const { return m_size ; }
58  Entity & operator[] ( size_t i ) const { return *(m_entities[i]) ; }
59  unsigned field_data_size(const FieldBase & field) const
60  {
61  return m_field_map[ field.mesh_meta_data_ordinal() ].m_size;
62  }
63  const FieldBase::Restriction::size_type * field_data_stride( const FieldBase & field ) const
64  {
65  return m_field_map[ field.mesh_meta_data_ordinal() ].m_stride;
66  }
67  unsigned char * field_data_location( const FieldBase & field, const Entity & entity ) const
68  {
69  return field_data_location_impl( field.mesh_meta_data_ordinal(), entity.bucket_ordinal() );
70  }
71 
75  unsigned char * fast_field_data_location( const FieldBase & field, unsigned ordinal ) const
76  {
77  return fast_field_data_location_impl( field.mesh_meta_data_ordinal(), ordinal );
78  }
79  unsigned char * field_data_location( const FieldBase & field, unsigned ordinal ) const
80  {
81  return field_data_location_impl( field.mesh_meta_data_ordinal(), ordinal );
82  }
83  unsigned char * field_data_location( const FieldBase & field ) const
84  {
85  unsigned int zero_ordinal = 0;
86  return field_data_location_impl( field.mesh_meta_data_ordinal(), zero_ordinal );
87  }
88 
89  //
90  // Internal interface:
91  //
92  void increment_size() { ++m_size ; }
93  void decrement_size() { --m_size ; }
94  void replace_entity(unsigned entity_ordinal, Entity * entity ) { m_entities[entity_ordinal] = entity ; }
95  void update_state();
96 
97  template< class field_type >
98  typename FieldTraits< field_type >::data_type *
99  field_data( const field_type & f , const unsigned & entity_ordinal ) const
100  {
101  typedef typename FieldTraits< field_type >::data_type * data_p ;
102  return reinterpret_cast<data_p>(field_data_location_impl(f.mesh_meta_data_ordinal(),entity_ordinal));
103  }
104 
105  // BucketKey key = ( part-count , { part-ordinals } , counter )
106  // key[ key[0] ] == counter
107  unsigned bucket_counter() const { return m_key[ m_key[0] ]; }
108 
109  Bucket * last_bucket_in_family() const;
110  Bucket * first_bucket_in_family() const;
111  void set_last_bucket_in_family( Bucket * last_bucket );
112  void set_first_bucket_in_family( Bucket * first_bucket );
113  DataMap * get_field_map();
114  void initialize_fields( unsigned i_dst );
115  void replace_fields( unsigned i_dst , Bucket & k_src , unsigned i_src );
116  void set_bucket_family_pointer( Bucket * bucket ) { m_bucket = bucket; }
117  const Bucket * get_bucket_family_pointer() const { return m_bucket; }
118 
119  bool equivalent( const BucketImpl& other_bucket ) const {
120  return first_bucket_in_family() == other_bucket.first_bucket_in_family();
121  }
122 
123  Entity*const* begin() const { return &m_entities[0]; }
124  Entity*const* end() const { return &m_entities[0] + m_size; }
125 
126  ~BucketImpl() { delete [] m_field_data; }
127 
128  private:
129  BucketImpl();
130 
131  BulkData & m_mesh ; // Where this bucket resides
132  const EntityRank m_entity_rank ; // Type of entities for this bucket
133  std::vector<unsigned> m_key ;
134  const size_t m_capacity ; // Capacity for entities
135  size_t m_size ; // Number of entities
136  Bucket * m_bucket ; // Pointer to head of bucket family, but head points to tail
137  std::vector<DataMap> m_field_map ; // Field value data map, shared
138  std::vector<Entity*> m_entities ; // Array of entity pointers,
139  // beginning of field value memory.
140  unsigned char* m_field_data;
141  unsigned char* m_field_data_end;
142 
143  unsigned char * field_data_location_impl( const unsigned & field_ordinal, const unsigned & entity_ordinal ) const
144  {
145  const DataMap & data_map = m_field_map[ field_ordinal ];
146  unsigned char * ptr = NULL;
147  if ( data_map.m_size ) {
148  ptr = const_cast<unsigned char*>(m_field_data) + data_map.m_base + data_map.m_size * entity_ordinal;
149  ThrowAssert(ptr < m_field_data_end);
150  }
151  return ptr ;
152  }
153  unsigned char * fast_field_data_location_impl( const unsigned & field_ordinal, const unsigned & entity_ordinal ) const
154  {
155  const DataMap & data_map = m_field_map[ field_ordinal ];
156  ThrowAssertMsg(data_map.m_size>0,"Field doesn't exist on bucket.");
157  return const_cast<unsigned char*>(m_field_data) + data_map.m_base + data_map.m_size * entity_ordinal;
158  }
159  Bucket * last_bucket_in_family_impl() const;
160 };
161 
162 
163 
164 } // namespace impl
165 } // namespace mesh
166 } // namespace stk_classic
167 
168 
169 #endif // stk_mesh_BucketImpl_hpp
170 
unsigned field_data_size(const FieldBase &f, const Bucket &k)
Size, in bytes, of the field data for each entity.
Definition: FieldData.hpp:99
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
Definition: FieldData.hpp:116
Sierra Toolkit.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).