9 #ifndef stk_mesh_BucketImpl_hpp 10 #define stk_mesh_BucketImpl_hpp 14 #include <stk_mesh/base/Types.hpp> 15 #include <stk_mesh/base/Field.hpp> 16 #include <stk_mesh/base/Entity.hpp> 18 #include <boost/pool/pool_alloc.hpp> 29 typedef FieldBase::Restriction::size_type size_type ;
30 const size_type * m_stride ;
35 BucketImpl( BulkData & arg_mesh ,
36 EntityRank arg_entity_rank,
37 const std::vector<unsigned> & arg_key,
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; }
49 std::pair<const unsigned *, const unsigned *>
50 superset_part_ordinals()
const 52 return std::pair<const unsigned *, const unsigned *>
53 ( key() + 1 , key() + key()[0] );
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]) ; }
61 return m_field_map[ field.mesh_meta_data_ordinal() ].m_size;
63 const FieldBase::Restriction::size_type * field_data_stride(
const FieldBase & field )
const 65 return m_field_map[ field.mesh_meta_data_ordinal() ].m_stride;
67 unsigned char * field_data_location(
const FieldBase & field,
const Entity & entity )
const 69 return field_data_location_impl( field.mesh_meta_data_ordinal(), entity.bucket_ordinal() );
75 unsigned char * fast_field_data_location(
const FieldBase & field,
unsigned ordinal )
const 77 return fast_field_data_location_impl( field.mesh_meta_data_ordinal(), ordinal );
79 unsigned char * field_data_location(
const FieldBase & field,
unsigned ordinal )
const 81 return field_data_location_impl( field.mesh_meta_data_ordinal(), ordinal );
83 unsigned char * field_data_location(
const FieldBase & field )
const 85 unsigned int zero_ordinal = 0;
86 return field_data_location_impl( field.mesh_meta_data_ordinal(), zero_ordinal );
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 ; }
97 template<
class field_type >
98 typename FieldTraits< field_type >::data_type *
99 field_data(
const field_type & f ,
const unsigned & entity_ordinal )
const 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));
107 unsigned bucket_counter()
const {
return m_key[ m_key[0] ]; }
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; }
119 bool equivalent(
const BucketImpl& other_bucket )
const {
120 return first_bucket_in_family() == other_bucket.first_bucket_in_family();
123 Entity*
const* begin()
const {
return &m_entities[0]; }
124 Entity*
const* end()
const {
return &m_entities[0] + m_size; }
126 ~BucketImpl() {
delete [] m_field_data; }
132 const EntityRank m_entity_rank ;
133 std::vector<unsigned> m_key ;
134 const size_t m_capacity ;
137 std::vector<DataMap> m_field_map ;
138 std::vector<Entity*> m_entities ;
140 unsigned char* m_field_data;
141 unsigned char* m_field_data_end;
143 unsigned char * field_data_location_impl(
const unsigned & field_ordinal,
const unsigned & entity_ordinal )
const 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);
153 unsigned char * fast_field_data_location_impl(
const unsigned & field_ordinal,
const unsigned & entity_ordinal )
const 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;
159 Bucket * last_bucket_in_family_impl()
const;
169 #endif // stk_mesh_BucketImpl_hpp unsigned field_data_size(const FieldBase &f, const Bucket &k)
Size, in bytes, of the field data for each entity.
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).