|
Sierra Toolkit Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 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 //---------------------------------------------------------------------- 00019 00020 namespace stk { 00021 namespace mesh { 00022 namespace impl { 00023 00024 class BucketImpl { 00025 public: 00026 ~BucketImpl(); 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 unsigned arg_entity_rank , 00037 const unsigned * arg_key , 00038 size_t arg_alloc_size , 00039 size_t arg_capacity , 00040 DataMap * arg_field_map , 00041 Entity ** arg_entity_array ); 00042 00043 // 00044 // External interface: 00045 // 00046 BulkData & mesh() const { return m_mesh ; } 00047 unsigned entity_rank() const { return m_entity_rank ; } 00048 const unsigned * key() const { return m_key ; } 00049 std::pair<const unsigned *, const unsigned *> 00050 superset_part_ordinals() const 00051 { 00052 return std::pair<const unsigned *, const unsigned *> 00053 ( m_key + 1 , m_key + m_key[0] ); 00054 } 00055 unsigned allocation_size() const { return m_alloc_size ; } 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 unsigned char * field_data_location( const FieldBase & field ) const 00072 { 00073 unsigned int zero_ordinal = 0; 00074 return field_data_location_impl( field.mesh_meta_data_ordinal(), zero_ordinal ); 00075 } 00076 00077 // 00078 // Internal interface: 00079 // 00080 void increment_size() { ++m_size ; } 00081 void decrement_size() { --m_size ; } 00082 void replace_entity(unsigned entity_ordinal, Entity * entity ) { m_entities[entity_ordinal] = entity ; } 00083 void update_state(); 00084 00085 template< class field_type > 00086 typename FieldTraits< field_type >::data_type * 00087 field_data( const field_type & f , const unsigned & entity_ordinal ) const 00088 { 00089 typedef typename FieldTraits< field_type >::data_type * data_p ; 00090 return (data_p)(field_data_location_impl(f.mesh_meta_data_ordinal(),entity_ordinal)); 00091 } 00092 00093 // BucketKey key = ( part-count , { part-ordinals } , counter ) 00094 // key[ key[0] ] == counter 00095 unsigned bucket_counter() const { return m_key[ *m_key ]; } 00096 00097 Bucket * last_bucket_in_family(); 00098 Bucket * first_bucket_in_family(); 00099 void set_last_bucket_in_family( Bucket * last_bucket ); 00100 void set_first_bucket_in_family( Bucket * first_bucket ); 00101 DataMap * get_field_map(); 00102 void zero_fields( unsigned i_dst ); 00103 void replace_fields( unsigned i_dst , Bucket & k_src , unsigned i_src ); 00104 void set_bucket_family_pointer( Bucket * bucket ) { m_bucket = bucket; } 00105 const Bucket * get_bucket_family_pointer() const { return m_bucket; } 00106 bool equivalent( const BucketImpl& other_bucket ) const { 00107 return m_bucket == other_bucket.m_bucket; 00108 } 00109 00110 private: 00111 BucketImpl(); 00112 00113 BulkData & m_mesh ; // Where this bucket resides 00114 const unsigned m_entity_rank ; // Type of entities for this bucket 00115 const unsigned * const m_key ; // Unique key in the bulk data 00116 const size_t m_alloc_size ; // Allocation size of this bucket 00117 const size_t m_capacity ; // Capacity for entities 00118 size_t m_size ; // Number of entities 00119 Bucket * m_bucket ; // Pointer to head of bucket family, but head points to tail 00120 DataMap * const m_field_map ; // Field value data map, shared 00121 Entity ** const m_entities ; // Array of entity pointers, 00122 // begining of field value memory. 00123 00124 unsigned char * field_data_location_impl( const unsigned & field_ordinal, const unsigned & entity_ordinal ) const 00125 { 00126 typedef unsigned char * byte_p ; 00127 const DataMap & data_map = m_field_map[ field_ordinal ]; 00128 unsigned char * ptr = NULL; 00129 if ( data_map.m_size ) { 00130 ptr = ((byte_p)(m_entities) + data_map.m_base + data_map.m_size * entity_ordinal ); 00131 } 00132 return ptr ; 00133 } 00134 Bucket * last_bucket_in_family_impl(); 00135 }; 00136 00137 00138 00139 } // namespace impl 00140 } // namespace mesh 00141 } // namespace stk 00142 00143 00144 #endif // stk_mesh_BucketImpl_hpp 00145