Sierra Toolkit Version of the Day
EntityImpl.hpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010, 2011 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_EntityImpl_hpp
00010 #define stk_mesh_EntityImpl_hpp
00011 
00012 #include <stk_util/util/PairIter.hpp>
00013 
00014 #include <stk_util/environment/ReportHandler.hpp>
00015 
00016 #include <stk_mesh/base/Types.hpp>
00017 #include <stk_mesh/base/Relation.hpp>
00018 #include <stk_mesh/base/Trace.hpp>
00019 
00020 #include <algorithm>
00021 
00022 namespace stk {
00023 namespace mesh {
00024 namespace impl {
00025 
00030 class EntityImpl {
00031 public:
00032 
00033   ~EntityImpl();
00034   EntityImpl( const EntityKey & arg_key );
00035 
00036   // Exposed in external interface:
00037   EntityRank entity_rank() const { return stk::mesh::entity_rank( m_key ); }
00038   EntityId identifier() const { return stk::mesh::entity_id( m_key ); }
00039   const EntityKey & key() const { return m_key ; }
00040   PairIterRelation relations() const { return PairIterRelation(m_relation); }
00041   PairIterRelation relations( unsigned rank ) const ;
00042   PairIterRelation node_relations( ) const
00043   {
00044     std::vector<Relation>::const_iterator i = m_relation.begin();
00045     std::vector<Relation>::const_iterator e = m_relation.end();
00046   
00047     const Relation::raw_relation_id_type hi = Relation::raw_relation_id(1, 0);
00048     e = std::lower_bound( i , e , hi , LessRelation() );
00049   
00050     return PairIterRelation( i , e );
00051   }
00052 
00053   PairIterEntityComm comm() const { return PairIterEntityComm( m_comm ); }
00054   PairIterEntityComm sharing() const ;
00055   PairIterEntityComm comm( const Ghosting & sub ) const ;
00056 
00057   Bucket & bucket() const
00058   {
00059     ThrowAssert(m_bucket); //don't want to return a reference to a null bucket
00060     return *m_bucket ;
00061   }
00062 
00063   Bucket* bucket_ptr() const
00064   {
00065     return m_bucket; // allow for NULL return value
00066   }
00067 
00068   bool is_bucket_valid() const { return m_bucket != NULL; }
00069   unsigned bucket_ordinal() const { return m_bucket_ord ; }
00070   unsigned owner_rank() const { return m_owner_rank ; }
00071   size_t synchronized_count() const { return m_sync_count ; }
00072 
00073   // The two relation methods below need to be called symmetically, ideally
00074   // through EntityRepository which will enforce the symmetry.
00075 
00076   bool destroy_relation( Entity & e_to, const RelationIdentifier local_id);
00077   bool declare_relation( Entity & e_to,
00078                          const RelationIdentifier local_id,
00079                          unsigned sync_count,
00080                          bool is_back_relation = false);
00081 
00082   // Communication info access:
00083   bool insert( const EntityCommInfo & );
00084   bool erase(  const EntityCommInfo & ); 
00085   bool erase(  const Ghosting & );       
00086   void comm_clear_ghosting(); 
00087   void comm_clear(); 
00088 
00089   void set_bucket_and_ordinal( Bucket * in_bucket, unsigned ordinal )
00090   {
00091     TraceIfWatching("stk::mesh::impl::EntityRepository::set_bucket_and_ordinal", LOG_ENTITY, key());
00092 
00093     m_bucket = in_bucket;
00094     m_bucket_ord = ordinal;
00095   }
00096 
00097   // return true if entity was actually modified
00098   bool set_owner_rank( unsigned in_owner_rank )
00099   {
00100     TraceIfWatching("stk::mesh::impl::EntityRepository::set_owner_rank", LOG_ENTITY, key());
00101 
00102     if ( in_owner_rank != m_owner_rank ) {
00103       m_owner_rank = in_owner_rank;
00104       return true;
00105     }
00106     return false;
00107   }
00108 
00109   void set_sync_count( size_t sync_count )
00110   {
00111     TraceIfWatching("stk::mesh::impl::EntityRepository::set_sync_count", LOG_ENTITY, key());
00112 
00113     m_sync_count = sync_count;
00114   }
00115 
00116   // Change log access:
00117   EntityModificationLog log_query() const { return m_mod_log ; }
00118 
00119   void log_clear()
00120   {
00121     TraceIfWatching("stk::mesh::impl::EntityRepository::log_clear", LOG_ENTITY, key());
00122 
00123     m_mod_log = EntityLogNoChange;
00124   }
00125 
00126   void log_deleted()
00127   {
00128     TraceIfWatching("stk::mesh::impl::EntityRepository::log_deleted", LOG_ENTITY, key());
00129 
00130     m_mod_log = EntityLogDeleted;
00131   }
00132 
00137   void log_resurrect();
00138 
00146   void log_modified_and_propagate();
00147 
00149   void log_created_parallel_copy();
00150 
00151   bool marked_for_destruction() const;
00152 
00153  private:
00154 
00155   const EntityKey         m_key ;        
00156   RelationVector          m_relation ;   
00157   EntityCommInfoVector    m_comm ;       
00158   Bucket                * m_bucket ;     
00159   unsigned                m_bucket_ord ; 
00160   unsigned                m_owner_rank ; 
00161   size_t                  m_sync_count ; 
00162   EntityModificationLog   m_mod_log ;
00163 
00164   EntityImpl();
00165   EntityImpl( const EntityImpl & ); 
00166   EntityImpl & operator = ( const EntityImpl & ); 
00167 };
00168 
00169 //----------------------------------------------------------------------
00170 
00173 } // namespace impl
00174 } // namespace mesh
00175 } // namespace stk
00176 
00177 //----------------------------------------------------------------------
00178 //----------------------------------------------------------------------
00179 
00180 #endif /* stk_mesh_EntityImpl_hpp */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends