Entity.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_Entity_hpp
00010 #define stk_mesh_Entity_hpp
00011 
00012 #include <utility>
00013 #include <vector>
00014 
00015 #include <stk_util/util/NamedPair.hpp>
00016 #include <stk_util/util/PairIter.hpp>
00017 #include <stk_mesh/base/Types.hpp>
00018 #include <stk_mesh/base/Bucket.hpp>
00019 #include <stk_mesh/base/Relation.hpp>
00020 
00021 namespace stk {
00022 namespace mesh {
00023 
00028 //----------------------------------------------------------------------
00036 typedef PairIter< std::vector<Relation>::const_iterator > PairIterRelation ;
00037 
00038 //----------------------------------------------------------------------
00039 
00040 NAMED_PAIR( EntityCommInfo , unsigned , ghost_id , unsigned , proc )
00041 
00042 
00045 typedef PairIter< std::vector< EntityCommInfo >::const_iterator >
00046   PairIterEntityComm ;
00047 
00048 //----------------------------------------------------------------------
00057 class Entity {
00058 public:
00059 
00061   EntityType entity_rank() const { return stk::mesh::entity_rank( m_key ); }
00062 
00064   EntityType entity_type() const { return Entity::entity_rank(); }
00065 
00069   EntityId identifier() const { return stk::mesh::entity_id( m_key ); }
00070 
00074   const EntityKey & key() const { return m_key ; }
00075 
00077   const Bucket & bucket() const { return *m_bucket ; }
00078 
00080   unsigned bucket_ordinal() const { return m_bucket_ord ; }
00081 
00089   size_t synchronized_count() const { return m_sync_count ; }
00090 
00091   //------------------------------------
00095   PairIterRelation relations() const { return PairIterRelation( m_relation ); }
00096 
00100   PairIterRelation relations( unsigned type ) const ;
00101 
00102   //------------------------------------
00104   unsigned owner_rank() const { return m_owner_rank ; }
00105 
00107   PairIterEntityComm sharing() const ;
00108 
00110   PairIterEntityComm comm() const { return PairIterEntityComm( m_comm ); }
00111 
00113   PairIterEntityComm comm( const Ghosting & ) const ;
00114 
00115   //------------------------------------
00116 
00117 private:
00118 
00119   const EntityKey              m_key ;       
00120   std::vector<Relation>        m_relation ;  
00121   std::vector<EntityCommInfo>  m_comm ;      
00122   Bucket *                     m_bucket ;    
00123   unsigned              m_bucket_ord ;       
00124   unsigned              m_owner_rank ;       
00125   size_t                m_sync_count ;       
00126 
00127   ~Entity();
00128   explicit Entity( const EntityKey & arg_key );
00129 
00130   Entity(); 
00131   Entity( const Entity & ); 
00132   Entity & operator = ( const Entity & ); 
00133 
00134   bool insert( const EntityCommInfo & );
00135 
00136 #ifndef DOXYGEN_COMPILE
00137   friend class BulkData ;
00138 #endif /* DOXYGEN_COMPILE */
00139 };
00140 
00142 class EntityLess {
00143 public:
00144   ~EntityLess() {}
00145   EntityLess() {}
00146   EntityLess( const EntityLess & ) {}
00147   EntityLess & operator = ( const EntityLess & ) { return *this ; }
00148 
00150   bool operator()(const Entity& lhs, const Entity& rhs) const
00151   { return lhs.key() < rhs.key(); }
00152 
00153   bool operator()(const Entity& lhs, const EntityKey & rhs) const
00154   { return lhs.key() < rhs ; }
00155 
00157   bool operator()(const Entity* lhs, const Entity* rhs) const
00158   {
00159     const EntityKey lhs_key = lhs ? lhs->key() : EntityKey() ;
00160     const EntityKey rhs_key = rhs ? rhs->key() : EntityKey() ;
00161     return lhs_key < rhs_key ;
00162   }
00163 
00164   bool operator()(const Entity* lhs, const Entity& rhs) const
00165   {
00166     const EntityKey lhs_key = lhs ? lhs->key() : EntityKey();
00167     return lhs_key < rhs.key() ;
00168   }
00169 
00170   bool operator()(const Entity* lhs, const EntityKey & rhs) const
00171   {
00172     const EntityKey lhs_key = lhs ? lhs->key() : EntityKey() ;
00173     return lhs_key < rhs ;
00174   }
00175 
00176   bool operator()( const EntityProc & lhs, const EntityProc & rhs) const
00177   {
00178     const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
00179     const EntityKey rhs_key = rhs.first ? rhs.first->key() : EntityKey() ;
00180     return lhs_key != rhs_key ? lhs_key < rhs_key : lhs.second < rhs.second ;
00181   }
00182 
00183   bool operator()( const EntityProc & lhs, const Entity & rhs) const
00184   {
00185     const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
00186     return lhs_key < rhs.key();
00187   }
00188 
00189   bool operator()( const EntityProc & lhs, const Entity * rhs) const
00190   {
00191     const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
00192     const EntityKey rhs_key = rhs       ? rhs->key() : EntityKey() ;
00193     return lhs_key < rhs_key ;
00194   }
00195 
00196   bool operator()( const EntityProc & lhs, const EntityKey & rhs) const
00197   {
00198     const EntityKey lhs_key = lhs.first ? lhs.first->key() : EntityKey() ;
00199     return lhs_key < rhs ;
00200   }
00201 
00202 }; //class EntityLess
00203 
00204 class EntityEqual
00205 {
00206 public:
00207   bool operator()(const stk::mesh::Entity* lhs, const stk::mesh::Entity* rhs) const
00208   {
00209     const stk::mesh::EntityKey lhs_key = lhs ? lhs->key() : stk::mesh::EntityKey();
00210     const stk::mesh::EntityKey rhs_key = rhs ? rhs->key() : stk::mesh::EntityKey();
00211     return lhs_key == rhs_key;
00212   }
00213 
00214   bool operator()(const stk::mesh::Entity& lhs, const stk::mesh::Entity& rhs) const
00215   {
00216     const stk::mesh::EntityKey lhs_key = lhs.key();
00217     const stk::mesh::EntityKey rhs_key = rhs.key();
00218     return lhs_key == rhs_key;
00219   }
00220 };
00221 
00222 //----------------------------------------------------------------------
00223 
00226 } // namespace mesh
00227 } // namespace stk
00228 
00229 //----------------------------------------------------------------------
00230 //----------------------------------------------------------------------
00231 
00232 #endif /* stk_mesh_Entity_hpp */
00233 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7