|
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_Bucket_hpp 00010 #define stk_mesh_Bucket_hpp 00011 00012 //---------------------------------------------------------------------- 00013 00014 #include <iosfwd> 00015 #include <vector> 00016 #include <algorithm> 00017 00018 #include <stk_util/environment/ReportHandler.hpp> 00019 00020 #include <stk_mesh/baseImpl/BucketImpl.hpp> 00021 00022 #include <stk_mesh/base/Types.hpp> 00023 #include <stk_mesh/base/Field.hpp> 00024 #include <stk_mesh/base/Part.hpp> 00025 #include <stk_mesh/base/Entity.hpp> 00026 00027 #include <boost/iterator/transform_iterator.hpp> 00028 #include <boost/iterator/indirect_iterator.hpp> 00029 00030 //---------------------------------------------------------------------- 00031 00032 #ifdef SIERRA_MIGRATION 00033 00034 namespace sierra { 00035 namespace Fmwk { 00036 00037 class MeshBulkData; 00038 00039 } 00040 } 00041 00042 00043 #endif 00044 00045 namespace stk_classic { 00046 namespace mesh { 00047 00048 namespace impl { 00049 class BucketRepository; 00050 } // namespace impl 00051 00052 00060 std::ostream & operator << ( std::ostream & , const Bucket & ); 00061 00063 std::ostream & 00064 print( std::ostream & , const std::string & indent , const Bucket & ); 00065 00066 // The part count and parts are equal 00067 bool bucket_part_equal( const unsigned * lhs , const unsigned * rhs ); 00068 00069 //---------------------------------------------------------------------- 00073 bool has_superset( const Bucket & , const Part & p ); 00074 00078 bool has_superset( const Bucket & , const unsigned & ordinal ); 00079 00083 bool has_superset( const Bucket & , const PartVector & ); 00084 00085 00086 //---------------------------------------------------------------------- 00094 class Bucket { 00095 private: 00096 friend class impl::BucketRepository; 00097 friend class impl::BucketImpl; 00098 00099 impl::BucketImpl m_bucketImpl; 00100 00101 #ifdef SIERRA_MIGRATION 00102 const void* m_fmwk_mesh_bulk_data; 00103 #endif 00104 00105 public: 00106 00107 //-------------------------------- 00108 // Container-like types and methods: 00109 00110 typedef boost::indirect_iterator<Entity*const*> iterator ; 00111 00113 inline iterator begin() const { return iterator(m_bucketImpl.begin()); } 00114 00116 inline iterator end() const { return iterator(m_bucketImpl.end()); } 00117 00119 size_t size() const { return m_bucketImpl.size() ; } 00120 00122 size_t capacity() const { return m_bucketImpl.capacity() ; } 00123 00125 Entity & operator[] ( size_t i ) const { return m_bucketImpl[i] ; } 00126 00128 unsigned field_data_size(const FieldBase & field) const 00129 { return m_bucketImpl.field_data_size(field); } 00130 00132 const FieldBase::Restriction::size_type * field_data_stride( const FieldBase & field ) const 00133 { return m_bucketImpl.field_data_stride(field); } 00134 00136 unsigned char * field_data_location( const FieldBase & field, const Entity & entity ) const 00137 { return m_bucketImpl.field_data_location(field,entity); } 00138 00140 unsigned char * field_data_location( const FieldBase & field, unsigned ordinal ) const 00141 { return m_bucketImpl.field_data_location(field, ordinal); } 00142 00147 unsigned char * fast_field_data_location( const FieldBase & field, unsigned ordinal ) const 00148 { return m_bucketImpl.fast_field_data_location(field, ordinal); } 00149 00151 unsigned char * field_data_location( const FieldBase & field ) const 00152 { return m_bucketImpl.field_data_location(field); } 00153 00155 template< class field_type > 00156 typename FieldTraits< field_type >::data_type * 00157 field_data( const field_type & field , const Entity & entity ) const 00158 { return m_bucketImpl.field_data(field,entity.bucket_ordinal()); } 00159 00160 //-------------------------------- 00164 BulkData & mesh() const { return m_bucketImpl.mesh(); } 00165 00167 unsigned entity_rank() const { return m_bucketImpl.entity_rank(); } 00168 00170 void supersets( PartVector & ) const ; 00171 void supersets( OrdinalVector & ) const ; 00172 00173 //-------------------------------- 00175 bool member( const Part & ) const ; 00176 00178 bool member_all( const PartVector & ) const ; 00179 bool member_all( const OrdinalVector & ) const ; 00180 00182 bool member_any( const PartVector & ) const ; 00183 bool member_any( const OrdinalVector & ) const ; 00184 00185 //-------------------------------- 00187 std::pair<const unsigned *, const unsigned *> 00188 superset_part_ordinals() const { return m_bucketImpl.superset_part_ordinals() ; } 00189 00192 bool equivalent( const Bucket& b ) const { 00193 return m_bucketImpl.equivalent(b.m_bucketImpl); 00194 } 00195 00196 #ifndef DOXYGEN_COMPILE 00197 const unsigned * key() const { return m_bucketImpl.key() ; } 00198 #endif /* DOXYGEN_COMPILE */ 00199 00201 unsigned allocation_size() const { return m_bucketImpl.allocation_size() ; } 00202 00204 bool assert_correct() const; 00205 00206 #ifdef SIERRA_MIGRATION 00207 typedef std::pair<iterator, iterator> EntityRange; 00208 00209 bool is_empty() const { return size() == 0; } 00210 00211 const sierra::Fmwk::MeshBulkData* get_bulk_data() const 00212 { 00213 return static_cast<const sierra::Fmwk::MeshBulkData*>(m_fmwk_mesh_bulk_data); 00214 } 00215 00216 template <class T> 00217 void set_bulk_data(const T* bulk_ptr) { m_fmwk_mesh_bulk_data = bulk_ptr; } 00218 #endif 00219 00220 private: 00224 BulkData & bulk_data() const { return m_bucketImpl.mesh(); } 00225 00226 // Only reason to define this at all is to ensure it's private 00227 ~Bucket() {} 00228 00229 Bucket(); 00230 Bucket( const Bucket & ); 00231 Bucket & operator = ( const Bucket & ); 00232 00233 Bucket( BulkData & arg_mesh , 00234 EntityRank arg_entity_rank, 00235 const std::vector<unsigned> & arg_key, 00236 size_t arg_capacity 00237 ); 00238 00239 friend class ::stk_classic::mesh::BulkData; 00240 }; 00241 00242 00243 struct BucketLess { 00244 bool operator()( const Bucket * lhs_bucket , const unsigned * rhs ) const ; 00245 bool operator()( const unsigned * lhs , const Bucket * rhs_bucket ) const ; 00246 }; 00247 00248 00249 inline 00250 std::vector<Bucket*>::iterator 00251 lower_bound( std::vector<Bucket*> & v , const unsigned * key ) 00252 { return std::lower_bound( v.begin() , v.end() , key , BucketLess() ); } 00253 00254 inline 00255 Bucket::Bucket( BulkData & arg_mesh , 00256 EntityRank arg_entity_rank, 00257 const std::vector<unsigned> & arg_key, 00258 size_t arg_capacity 00259 ) 00260 : m_bucketImpl(arg_mesh,arg_entity_rank,arg_key,arg_capacity) 00261 {} 00262 00265 inline 00266 bool Bucket::member_all( const OrdinalVector& parts ) const 00267 { 00268 const unsigned * const i_beg = key() + 1 ; 00269 const unsigned * const i_end = key() + key()[0] ; 00270 00271 const OrdinalVector::const_iterator ip_end = parts.end(); 00272 OrdinalVector::const_iterator ip = parts.begin() ; 00273 00274 bool result_all = true ; 00275 00276 for ( ; result_all && ip_end != ip ; ++ip ) { 00277 const unsigned ord = *ip; 00278 result_all = contains_ordinal(i_beg, i_end, ord); 00279 } 00280 return result_all ; 00281 } 00282 00283 struct To_Ptr : std::unary_function<Entity&, Entity*> 00284 { 00285 Entity* operator()(Entity& entity) const 00286 { 00287 return &entity; 00288 } 00289 }; 00290 00291 // Sometimes, we want a bucket-iterator to dereference to an Entity* 00292 typedef boost::transform_iterator<To_Ptr, Bucket::iterator> BucketPtrIterator; 00293 00294 typedef Bucket::iterator BucketIterator; 00295 00296 } // namespace mesh 00297 } // namespace stk_classic 00298 00299 #endif