|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010, 2011 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #ifndef stk_mesh_BucketImpl_hpp 00010 #define stk_mesh_BucketImpl_hpp 00011 00012 //---------------------------------------------------------------------- 00013 00014 #include <stk_mesh/base/Types.hpp> 00015 #include <stk_mesh/base/Field.hpp> 00016 #include <stk_mesh/base/Entity.hpp> 00017 00018 #include <boost/pool/pool_alloc.hpp> 00019 //---------------------------------------------------------------------- 00020 00021 namespace stk_classic { 00022 namespace mesh { 00023 namespace impl { 00024 00025 class BucketImpl { 00026 public: 00027 00028 struct DataMap { 00029 typedef FieldBase::Restriction::size_type size_type ; 00030 const size_type * m_stride ; 00031 size_type m_base ; 00032 size_type m_size ; 00033 }; 00034 00035 BucketImpl( BulkData & arg_mesh , 00036 EntityRank arg_entity_rank, 00037 const std::vector<unsigned> & arg_key, 00038 size_t arg_capacity 00039 ); 00040 00041 // 00042 // External interface: 00043 // 00044 BulkData & mesh() const { return m_mesh ; } 00045 unsigned entity_rank() const { return m_entity_rank ; } 00046 const unsigned * key() const { return &m_key[0] ; } 00047 const std::vector<unsigned> & key_vector() const { return m_key; } 00048 00049 std::pair<const unsigned *, const unsigned *> 00050 superset_part_ordinals() const 00051 { 00052 return std::pair<const unsigned *, const unsigned *> 00053 ( key() + 1 , key() + key()[0] ); 00054 } 00055 unsigned allocation_size() const { return 0 ; } 00056 size_t capacity() const { return m_capacity ; } 00057 size_t size() const { return m_size ; } 00058 Entity & operator[] ( size_t i ) const { return *(m_entities[i]) ; } 00059 unsigned field_data_size(const FieldBase & field) const 00060 { 00061 return m_field_map[ field.mesh_meta_data_ordinal() ].m_size; 00062 } 00063 const FieldBase::Restriction::size_type * field_data_stride( const FieldBase & field ) const 00064 { 00065 return m_field_map[ field.mesh_meta_data_ordinal() ].m_stride; 00066 } 00067 unsigned char * field_data_location( const FieldBase & field, const Entity & entity ) const 00068 { 00069 return field_data_location_impl( field.mesh_meta_data_ordinal(), entity.bucket_ordinal() ); 00070 } 00071 00075 unsigned char * fast_field_data_location( const FieldBase & field, unsigned ordinal ) const 00076 { 00077 return fast_field_data_location_impl( field.mesh_meta_data_ordinal(), ordinal ); 00078 } 00079 unsigned char * field_data_location( const FieldBase & field, unsigned ordinal ) const 00080 { 00081 return field_data_location_impl( field.mesh_meta_data_ordinal(), ordinal ); 00082 } 00083 unsigned char * field_data_location( const FieldBase & field ) const 00084 { 00085 unsigned int zero_ordinal = 0; 00086 return field_data_location_impl( field.mesh_meta_data_ordinal(), zero_ordinal ); 00087 } 00088 00089 // 00090 // Internal interface: 00091 // 00092 void increment_size() { ++m_size ; } 00093 void decrement_size() { --m_size ; } 00094 void replace_entity(unsigned entity_ordinal, Entity * entity ) { m_entities[entity_ordinal] = entity ; } 00095 void update_state(); 00096 00097 template< class field_type > 00098 typename FieldTraits< field_type >::data_type * 00099 field_data( const field_type & f , const unsigned & entity_ordinal ) const 00100 { 00101 typedef typename FieldTraits< field_type >::data_type * data_p ; 00102 return reinterpret_cast<data_p>(field_data_location_impl(f.mesh_meta_data_ordinal(),entity_ordinal)); 00103 } 00104 00105 // BucketKey key = ( part-count , { part-ordinals } , counter ) 00106 // key[ key[0] ] == counter 00107 unsigned bucket_counter() const { return m_key[ m_key[0] ]; } 00108 00109 Bucket * last_bucket_in_family() const; 00110 Bucket * first_bucket_in_family() const; 00111 void set_last_bucket_in_family( Bucket * last_bucket ); 00112 void set_first_bucket_in_family( Bucket * first_bucket ); 00113 DataMap * get_field_map(); 00114 void initialize_fields( unsigned i_dst ); 00115 void replace_fields( unsigned i_dst , Bucket & k_src , unsigned i_src ); 00116 void set_bucket_family_pointer( Bucket * bucket ) { m_bucket = bucket; } 00117 const Bucket * get_bucket_family_pointer() const { return m_bucket; } 00118 00119 bool equivalent( const BucketImpl& other_bucket ) const { 00120 return first_bucket_in_family() == other_bucket.first_bucket_in_family(); 00121 } 00122 00123 Entity*const* begin() const { return &m_entities[0]; } 00124 Entity*const* end() const { return &m_entities[0] + m_size; } 00125 00126 ~BucketImpl() { delete [] m_field_data; } 00127 00128 private: 00129 BucketImpl(); 00130 00131 BulkData & m_mesh ; // Where this bucket resides 00132 const EntityRank m_entity_rank ; // Type of entities for this bucket 00133 std::vector<unsigned> m_key ; 00134 const size_t m_capacity ; // Capacity for entities 00135 size_t m_size ; // Number of entities 00136 Bucket * m_bucket ; // Pointer to head of bucket family, but head points to tail 00137 std::vector<DataMap> m_field_map ; // Field value data map, shared 00138 std::vector<Entity*> m_entities ; // Array of entity pointers, 00139 // beginning of field value memory. 00140 unsigned char* m_field_data; 00141 unsigned char* m_field_data_end; 00142 00143 unsigned char * field_data_location_impl( const unsigned & field_ordinal, const unsigned & entity_ordinal ) const 00144 { 00145 typedef unsigned char * byte_p ; 00146 const DataMap & data_map = m_field_map[ field_ordinal ]; 00147 unsigned char * ptr = NULL; 00148 if ( data_map.m_size ) { 00149 ptr = const_cast<unsigned char*>(m_field_data) + data_map.m_base + data_map.m_size * entity_ordinal; 00150 ThrowAssert(ptr < m_field_data_end); 00151 } 00152 return ptr ; 00153 } 00154 unsigned char * fast_field_data_location_impl( const unsigned & field_ordinal, const unsigned & entity_ordinal ) const 00155 { 00156 typedef unsigned char * byte_p ; 00157 const DataMap & data_map = m_field_map[ field_ordinal ]; 00158 ThrowAssertMsg(data_map.m_size>0,"Field doesn't exist on bucket."); 00159 return const_cast<unsigned char*>(m_field_data) + data_map.m_base + data_map.m_size * entity_ordinal; 00160 } 00161 Bucket * last_bucket_in_family_impl() const; 00162 }; 00163 00164 00165 00166 } // namespace impl 00167 } // namespace mesh 00168 } // namespace stk_classic 00169 00170 00171 #endif // stk_mesh_BucketImpl_hpp 00172