Sierra Toolkit Version of the Day
BucketImpl.hpp
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 //----------------------------------------------------------------------
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() const;
00098   Bucket * first_bucket_in_family() const;
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 initialize_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 
00107   bool equivalent( const BucketImpl& other_bucket ) const {
00108     return first_bucket_in_family() == other_bucket.first_bucket_in_family();
00109   }
00110 
00111   private:
00112   BucketImpl();
00113 
00114   BulkData             & m_mesh ;        // Where this bucket resides
00115   const unsigned         m_entity_rank ; // Type of entities for this bucket
00116   const unsigned * const m_key ;         // Unique key in the bulk data
00117   const size_t           m_alloc_size ;  // Allocation size of this bucket
00118   const size_t           m_capacity ;    // Capacity for entities
00119   size_t                 m_size ;        // Number of entities
00120   Bucket               * m_bucket ;      // Pointer to head of bucket family, but head points to tail
00121   DataMap        * const m_field_map ;   // Field value data map, shared
00122   Entity        ** const m_entities ;    // Array of entity pointers,
00123                                          // beginning of field value memory.
00124 
00125   unsigned char * field_data_location_impl( const unsigned & field_ordinal, const unsigned & entity_ordinal ) const
00126   {
00127     typedef unsigned char * byte_p ;
00128     const DataMap & data_map = m_field_map[ field_ordinal ];
00129     unsigned char * ptr = NULL;
00130     if ( data_map.m_size ) {
00131       ptr = ((byte_p)(m_entities) + data_map.m_base + data_map.m_size * entity_ordinal );
00132     }
00133     return ptr ;
00134   }
00135   Bucket * last_bucket_in_family_impl() const;
00136 };
00137 
00138 
00139 
00140 } // namespace impl
00141 } // namespace mesh
00142 } // namespace stk
00143 
00144 
00145 #endif // stk_mesh_BucketImpl_hpp
00146 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends