|
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_mesh/baseImpl/BucketImpl.hpp> 00019 00020 #include <stk_mesh/base/Types.hpp> 00021 #include <stk_mesh/base/Field.hpp> 00022 #include <stk_mesh/base/Part.hpp> 00023 #include <stk_mesh/base/Entity.hpp> 00024 00025 //---------------------------------------------------------------------- 00026 00027 namespace stk { 00028 namespace mesh { 00029 00030 namespace impl { 00031 class BucketRepository; 00032 } // namespace impl 00033 00034 00042 std::ostream & operator << ( std::ostream & , const Bucket & ); 00043 00045 std::ostream & 00046 print( std::ostream & , const std::string & indent , const Bucket & ); 00047 00048 // The part count and parts are equal 00049 bool bucket_part_equal( const unsigned * lhs , const unsigned * rhs ); 00050 00051 //---------------------------------------------------------------------- 00055 bool has_superset( const Bucket & , const Part & p ); 00056 00060 bool has_superset( const Bucket & , const unsigned & ordinal ); 00061 00065 bool has_superset( const Bucket & , const PartVector & ); 00066 00067 //---------------------------------------------------------------------- 00072 class BucketIterator : std::iterator<std::random_access_iterator_tag,Entity > { 00073 private: 00074 const Bucket * m_bucket_ptr; 00075 size_t m_current_entity; 00076 00077 inline Entity & entity( const size_t ) const ; 00078 00079 void throw_error(const char *err) const; 00080 00081 template< class field_type > 00082 friend 00083 typename FieldTraits< field_type >::data_type * 00084 field_data( const field_type & f , const BucketIterator &i ); 00085 00086 template< class field_type > friend struct BucketArray ; 00087 00088 public: 00089 00094 template< typename intType > 00095 BucketIterator(const Bucket * const bucket_ptr, intType offset) { 00096 m_bucket_ptr = bucket_ptr; 00097 m_current_entity = offset; 00098 } 00099 00101 BucketIterator() { 00102 m_bucket_ptr = NULL; 00103 m_current_entity = 0; 00104 } 00105 00107 BucketIterator(const BucketIterator &i) { 00108 m_bucket_ptr = i.m_bucket_ptr; 00109 m_current_entity = i.m_current_entity; 00110 } 00111 00113 BucketIterator & operator=(const BucketIterator &i) { 00114 m_bucket_ptr = i.m_bucket_ptr; 00115 m_current_entity = i.m_current_entity; 00116 return *this; 00117 } 00118 00122 inline Entity & operator*() const { return entity(0); } 00123 00127 inline Entity * operator->() const { return & entity(0); } 00128 00130 inline BucketIterator & operator++() { 00131 ++m_current_entity; 00132 return *this; 00133 } 00134 00136 inline BucketIterator & operator--() { 00137 --m_current_entity; 00138 return *this; 00139 } 00140 00142 inline BucketIterator operator++(int) { 00143 BucketIterator temp = *this; 00144 ++m_current_entity; 00145 return temp; 00146 } 00147 00149 inline BucketIterator operator--(int) { 00150 BucketIterator temp = *this; 00151 --m_current_entity; 00152 return temp; 00153 } 00154 00156 inline bool operator<(const BucketIterator &i) const { 00157 if (m_bucket_ptr != i.m_bucket_ptr) 00158 throw_error("operator < given iterator from different bucket"); 00159 return (m_current_entity < i.m_current_entity); 00160 } 00161 00163 inline bool operator<=(const BucketIterator &i) const { 00164 if (m_bucket_ptr != i.m_bucket_ptr) 00165 throw_error("operator <= given iterator from different bucket"); 00166 return (m_current_entity <= i.m_current_entity); 00167 } 00168 00170 inline bool operator>(const BucketIterator &i) const { 00171 if (m_bucket_ptr != i.m_bucket_ptr) 00172 throw_error("operator > given iterator from different bucket"); 00173 return (m_current_entity > i.m_current_entity); 00174 } 00175 00177 inline bool operator>=(const BucketIterator &i) const { 00178 if (m_bucket_ptr != i.m_bucket_ptr) 00179 throw_error("operator >= given iterator from different bucket"); 00180 return (m_current_entity >= i.m_current_entity); 00181 } 00182 00184 inline bool operator==(const BucketIterator &i) const { 00185 if (m_bucket_ptr != i.m_bucket_ptr) 00186 throw_error("operator == given iterator from different bucket"); 00187 return (m_current_entity == i.m_current_entity); 00188 } 00189 00191 inline bool operator!=(const BucketIterator &i) const { 00192 if (m_bucket_ptr != i.m_bucket_ptr) 00193 throw_error("operator != given iterator from different bucket"); 00194 return (m_current_entity != i.m_current_entity); 00195 } 00196 00197 inline BucketIterator & operator+=(int n) { 00198 m_current_entity += n; 00199 return *this; 00200 } 00201 00202 inline BucketIterator & operator-=(int n) { 00203 m_current_entity -= n; 00204 return *this; 00205 } 00206 00207 inline BucketIterator operator+(int n) const { 00208 return BucketIterator(m_bucket_ptr, m_current_entity + n); 00209 } 00210 00211 inline BucketIterator operator-(int n) const { 00212 return BucketIterator(m_bucket_ptr, m_current_entity - n); 00213 } 00214 00216 inline ptrdiff_t operator-(const BucketIterator &i) const { 00217 if (m_bucket_ptr != i.m_bucket_ptr) 00218 throw_error("operator - given iterator from different bucket"); 00219 return static_cast<ptrdiff_t>(m_current_entity - i.m_current_entity); 00220 } 00221 00222 template< typename intType > 00223 inline Entity & operator[]( const intType & n ) const { return entity(n); } 00224 00225 }; // class BucketIterator 00226 00227 //---------------------------------------------------------------------- 00235 class Bucket { 00236 private: 00237 friend class impl::BucketRepository ; 00238 friend class impl::BucketImpl ; 00239 00240 impl::BucketImpl m_bucketImpl ; 00241 00242 public: 00243 00244 //-------------------------------- 00245 // Container-like types and methods: 00246 00247 typedef BucketIterator iterator ; 00248 00250 inline iterator begin() const { return iterator(this,0); } 00251 00253 inline iterator end() const { return iterator(this,size()); } 00254 00256 size_t size() const { return m_bucketImpl.size() ; } 00257 00259 size_t capacity() const { return m_bucketImpl.capacity() ; } 00260 00262 Entity & operator[] ( size_t i ) const { return m_bucketImpl[i] ; } 00263 00265 unsigned field_data_size(const FieldBase & field) const 00266 { return m_bucketImpl.field_data_size(field); } 00267 00269 const FieldBase::Restriction::size_type * field_data_stride( const FieldBase & field ) const 00270 { return m_bucketImpl.field_data_stride(field); } 00271 00273 unsigned char * field_data_location( const FieldBase & field, const Entity & entity ) const 00274 { return m_bucketImpl.field_data_location(field,entity); } 00275 00277 unsigned char * field_data_location( const FieldBase & field ) const 00278 { return m_bucketImpl.field_data_location(field); } 00279 00281 template< class field_type > 00282 typename FieldTraits< field_type >::data_type * 00283 field_data( const field_type & field , const Entity & entity ) const 00284 { return m_bucketImpl.field_data(field,entity.bucket_ordinal()); } 00285 00286 //-------------------------------- 00290 BulkData & mesh() const { return m_bucketImpl.mesh(); } 00291 00293 unsigned entity_rank() const { return m_bucketImpl.entity_rank(); } 00294 00296 void supersets( PartVector & ) const ; 00297 00298 //-------------------------------- 00300 bool member( const Part & ) const ; 00301 00303 bool member_all( const std::vector<Part*> & ) const ; 00304 00306 bool member_any( const std::vector<Part*> & ) const ; 00307 00308 //-------------------------------- 00310 std::pair<const unsigned *, const unsigned *> 00311 superset_part_ordinals() const { return m_bucketImpl.superset_part_ordinals() ; } 00312 00315 bool equivalent( const Bucket& b ) const { 00316 return m_bucketImpl.equivalent(b.m_bucketImpl); 00317 } 00318 00319 #ifndef DOXYGEN_COMPILE 00320 const unsigned * key() const { return m_bucketImpl.key() ; } 00321 #endif /* DOXYGEN_COMPILE */ 00322 00324 unsigned allocation_size() const { return m_bucketImpl.allocation_size() ; } 00325 00326 private: 00327 00328 ~Bucket(); 00329 Bucket(); 00330 Bucket( const Bucket & ); 00331 Bucket & operator = ( const Bucket & ); 00332 00333 Bucket( BulkData & arg_mesh , 00334 unsigned arg_entity_rank , 00335 const unsigned * arg_key , 00336 size_t arg_alloc_size , 00337 size_t arg_capacity , 00338 impl::BucketImpl::DataMap * arg_field_map , 00339 Entity ** arg_entity_array ); 00340 00341 }; 00342 00343 00344 00345 struct BucketLess { 00346 bool operator()( const Bucket * lhs_bucket , const unsigned * rhs ) const ; 00347 bool operator()( const unsigned * lhs , const Bucket * rhs_bucket ) const ; 00348 }; 00349 00350 00351 inline 00352 std::vector<Bucket*>::iterator 00353 lower_bound( std::vector<Bucket*> & v , const unsigned * key ) 00354 { return std::lower_bound( v.begin() , v.end() , key , BucketLess() ); } 00355 00356 00357 00360 } // namespace mesh 00361 } // namespace stk 00362 00363 //---------------------------------------------------------------------- 00364 //---------------------------------------------------------------------- 00365 00366 namespace stk { 00367 namespace mesh { 00368 00369 inline Entity & BucketIterator::entity( const size_t i ) const 00370 { 00371 //if ( ! m_bucket_ptr ) { throw_error("is NULL"); } 00372 return (*m_bucket_ptr)[ m_current_entity + i ] ; 00373 } 00374 00375 } 00376 } 00377 00378 #endif 00379