Sierra Toolkit Version of the Day
BucketRepository.hpp
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_BucketRepository_hpp
00010 #define stk_mesh_BucketRepository_hpp
00011 
00012 #include <stk_mesh/base/Types.hpp>
00013 #include <stk_mesh/base/Bucket.hpp>
00014 #include <stk_mesh/base/Iterators.hpp>
00015 
00016 namespace stk {
00017 namespace mesh {
00018 namespace impl {
00019 
00020 class EntityRepository;
00021 
00022 class BucketRepository {
00023 public:
00024   ~BucketRepository();
00025   BucketRepository(
00026       BulkData & mesh,
00027       unsigned bucket_capacity,
00028       unsigned entity_rank_count,
00029       EntityRepository & entity_repo
00030       );
00031 
00033   const std::vector<Bucket*> & buckets( EntityRank rank ) const
00034   {
00035     ThrowAssertMsg( rank < m_buckets.size(), "Invalid entity rank " << rank );
00036   
00037     return m_buckets[ rank ];
00038   }
00039 
00040   /*  Entity modification consequences:
00041    *  1) Change entity relation => update via part relation => change parts
00042    *  2) Change parts => update forward relations via part relation
00043    *                  => update via field relation
00044    */
00045   void remove_entity( Bucket * , unsigned );
00046 
00047   //------------------------------------
00051   unsigned bucket_capacity() const { return m_bucket_capacity; }
00052 
00053 
00054   //------------------------------------
00055 
00067   void update_field_data_states() const ;
00068 
00069   // Destroy the last empty bucket in a family:
00070   void destroy_bucket( const unsigned & entity_rank , Bucket * last );
00071   void destroy_bucket( Bucket * bucket );
00072   void declare_nil_bucket();
00073   Bucket * get_nil_bucket() const { return m_nil_bucket; }
00074   Bucket * declare_bucket(
00075       const unsigned entity_rank ,
00076       const unsigned part_count ,
00077       const unsigned part_ord[] ,
00078       const std::vector< FieldBase * > & field_set
00079       );
00080   void copy_fields( Bucket & k_dst , unsigned i_dst ,
00081                            Bucket & k_src , unsigned i_src )
00082   { k_dst.m_bucketImpl.replace_fields(i_dst,k_src,i_src); }
00083 
00084   void initialize_fields( Bucket & k_dst , unsigned i_dst );
00085 
00086   void internal_sort_bucket_entities();
00087 
00088   void optimize_buckets();
00089   void sort_and_optimize_buckets();
00090 
00091   void add_entity_to_bucket( Entity & entity, Bucket & bucket )
00092   {
00093     bucket.m_bucketImpl.replace_entity( bucket.size() , & entity ) ;
00094     bucket.m_bucketImpl.increment_size();
00095   }
00096 
00097   void internal_propagate_relocation( Entity & );
00098 
00099   AllBucketsRange get_bucket_range() const
00100   {
00101     return stk::mesh::get_bucket_range(m_buckets);
00102   }
00103 
00104   AllBucketsRange get_bucket_range(EntityRank entity_rank) const
00105   {
00106     std::vector< std::vector<Bucket*> >::const_iterator itr = m_buckets.begin() + entity_rank;
00107     return stk::mesh::get_bucket_range(m_buckets, itr);
00108   }
00109 
00110 private:
00111   BucketRepository();
00112 
00113   BulkData                            & m_mesh ; // Associated Bulk Data Aggregate
00114   unsigned                              m_bucket_capacity ; // Maximum number of entities per bucket
00115   std::vector< std::vector<Bucket*> >   m_buckets ; // Vector of bucket pointers by rank
00116   Bucket                              * m_nil_bucket ; // nil bucket
00117 
00118   EntityRepository                    & m_entity_repo ;
00119 };
00120 
00121 
00122 
00123 } // namespace impl
00124 } // namespace mesh
00125 } // namespace stk
00126 
00127 
00128 #endif // stk_mesh_BucketRepository_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines