Sierra Toolkit  Version of the Day
BucketRepository.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #ifndef stk_mesh_BucketRepository_hpp
10 #define stk_mesh_BucketRepository_hpp
11 
12 #include <stk_mesh/base/Types.hpp>
13 #include <stk_mesh/base/Bucket.hpp>
14 #include <stk_mesh/base/Iterators.hpp>
15 
16 namespace stk_classic {
17 namespace mesh {
18 namespace impl {
19 
20 class EntityRepository;
21 
22 class BucketRepository {
23 public:
24  ~BucketRepository();
25  BucketRepository(
26  BulkData & mesh,
27  unsigned bucket_capacity,
28  unsigned entity_rank_count,
29  EntityRepository & entity_repo
30  );
31 
33  const std::vector<Bucket*> & buckets( EntityRank rank ) const
34  {
35  ThrowAssertMsg( rank < m_buckets.size(), "Invalid entity rank " << rank );
36 
37  return m_buckets[ rank ];
38  }
39 
40  /* Entity modification consequences:
41  * 1) Change entity relation => update via part relation => change parts
42  * 2) Change parts => update forward relations via part relation
43  * => update via field relation
44  */
45  void remove_entity( Bucket * , unsigned );
46 
47  //------------------------------------
51  unsigned bucket_capacity() const { return m_bucket_capacity; }
52 
53 
54  //------------------------------------
55 
67  void update_field_data_states() const ;
68 
69  // Destroy the last empty bucket in a family:
70  void destroy_bucket( const unsigned & entity_rank , Bucket * last );
71  void destroy_bucket( Bucket * bucket );
72  void declare_nil_bucket();
73  Bucket * get_nil_bucket() const { return m_nil_bucket; }
74  Bucket * declare_bucket(
75  const unsigned entity_rank ,
76  const unsigned part_count ,
77  const unsigned part_ord[] ,
78  const std::vector< FieldBase * > & field_set
79  );
80  void copy_fields( Bucket & k_dst , unsigned i_dst ,
81  Bucket & k_src , unsigned i_src )
82  { k_dst.m_bucketImpl.replace_fields(i_dst,k_src,i_src); }
83 
84  void initialize_fields( Bucket & k_dst , unsigned i_dst );
85 
86  void internal_sort_bucket_entities();
87 
88  void optimize_buckets();
89  void sort_and_optimize_buckets();
90 
91  void add_entity_to_bucket( Entity & entity, Bucket & bucket )
92  {
93  bucket.m_bucketImpl.replace_entity( bucket.size() , & entity ) ;
94  bucket.m_bucketImpl.increment_size();
95  }
96 
97  void internal_propagate_relocation( Entity & );
98 
99  AllBucketsRange get_bucket_range() const
100  {
101  return stk_classic::mesh::get_bucket_range(m_buckets);
102  }
103 
104  AllBucketsRange get_bucket_range(EntityRank entity_rank) const
105  {
106  std::vector< std::vector<Bucket*> >::const_iterator itr = m_buckets.begin() + entity_rank;
107  return stk_classic::mesh::get_bucket_range(m_buckets, itr);
108  }
109 
110 private:
111  BucketRepository();
112 
113  BulkData & m_mesh ; // Associated Bulk Data Aggregate
114  unsigned m_bucket_capacity ; // Maximum number of entities per bucket
115  std::vector< std::vector<Bucket*> > m_buckets ; // Vector of bucket pointers by rank
116  Bucket * m_nil_bucket ; // nil bucket
117 
118  EntityRepository & m_entity_repo ;
119 };
120 
121 
122 
123 } // namespace impl
124 } // namespace mesh
125 } // namespace stk_classic
126 
127 
128 #endif // stk_mesh_BucketRepository_hpp
Sierra Toolkit.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).