|
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_baseImpl_EntityRepository_hpp 00010 #define stk_mesh_baseImpl_EntityRepository_hpp 00011 00012 #include <stk_mesh/base/Trace.hpp> 00013 00014 // We will use tr1 if we can (not on PGI or pathscale); otherwise, fall back to std map. 00015 #if defined(__PGI) || defined(__PATHSCALE__) 00016 #define STK_MESH_ENTITYREPOSITORY_MAP_TYPE_TR1 0 00017 #else 00018 #define STK_MESH_ENTITYREPOSITORY_MAP_TYPE_TR1 0 00019 #endif 00020 00021 #if STK_MESH_ENTITYREPOSITORY_MAP_TYPE_TR1 00022 #include <tr1/unordered_map> 00023 #else 00024 #include <map> 00025 #endif 00026 00027 #include <stk_mesh/base/Entity.hpp> 00028 00029 00030 #include <boost/pool/pool_alloc.hpp> 00031 00032 namespace stk_classic { 00033 namespace mesh { 00034 namespace impl { 00035 00036 class EntityRepository { 00037 00038 #if STK_MESH_ENTITYREPOSITORY_MAP_TYPE_TR1 00039 struct stk_entity_rep_hash : public std::unary_function< EntityKey, std::size_t > 00040 { 00041 inline std::size_t 00042 operator()(const EntityKey& x) const 00043 { 00044 return (std::size_t)(x.raw_key()); 00045 } 00046 }; 00047 00048 typedef std::tr1::unordered_map<EntityKey, Entity*, stk_entity_rep_hash, std::equal_to<EntityKey> > EntityMap; 00049 #else 00050 typedef std::map<EntityKey,Entity*> EntityMap; 00051 #endif 00052 00053 public: 00054 00055 typedef EntityMap::const_iterator iterator; 00056 00057 EntityRepository(bool use_pool) 00058 : m_entities(), m_use_pool(use_pool) {} 00059 00060 ~EntityRepository(); 00061 00062 Entity * get_entity( const EntityKey &key ) const; 00063 00064 iterator begin() const { return m_entities.begin(); } 00065 iterator end() const { return m_entities.end(); } 00066 00067 void clean_changes(); 00068 00069 // Return a pair: the relevant entity, and whether it had to be created 00070 // or not. If there was already an active entity, the second item in the 00071 // will be false; otherwise it will be true (even if the Entity was present 00072 // but marked as destroyed). 00073 std::pair<Entity*,bool> 00074 internal_create_entity( const EntityKey & key ); 00075 00079 void log_created_parallel_copy( Entity & e ); 00080 00087 inline void log_modified(Entity & e) const; 00088 00089 inline void set_entity_owner_rank( Entity & e, unsigned owner_rank); 00090 inline void set_entity_sync_count( Entity & e, size_t count); 00091 00092 inline void comm_clear( Entity & e) const; 00093 inline void comm_clear_ghosting( Entity & e) const; 00094 00095 bool erase_ghosting( Entity & e, const Ghosting & ghosts) const; 00096 bool erase_comm_info( Entity & e, const EntityCommInfo & comm_info) const; 00097 00098 bool insert_comm_info( Entity & e, const EntityCommInfo & comm_info) const; 00099 00100 void change_entity_bucket( Bucket & b, Entity & e, unsigned ordinal); 00101 Bucket * get_entity_bucket ( Entity & e ) const; 00102 void destroy_later( Entity & e, Bucket* nil_bucket ); 00103 00104 bool destroy_relation( Entity & e_from, 00105 Entity & e_to, 00106 const RelationIdentifier local_id); 00107 00108 void declare_relation( Entity & e_from, 00109 Entity & e_to, 00110 const RelationIdentifier local_id, 00111 unsigned sync_count ); 00112 00113 void update_entity_key(EntityKey key, Entity & entity); 00114 00115 private: 00116 void internal_expunge_entity( EntityMap::iterator i); 00117 00118 Entity* internal_allocate_entity(EntityKey entity_key); 00119 Entity* allocate_entity(bool use_pool); 00120 00121 EntityMap m_entities; 00122 bool m_use_pool; 00123 00124 //disable copy constructor and assignment operator 00125 EntityRepository(const EntityRepository &); 00126 EntityRepository & operator =(const EntityRepository &); 00127 }; 00128 00129 /*---------------------------------------------------------------*/ 00130 00131 void EntityRepository::set_entity_sync_count( Entity & e, size_t count) 00132 { 00133 TraceIfWatching("stk_classic::mesh::impl::EntityRepository::set_entity_sync_count", LOG_ENTITY, e.key()); 00134 00135 e.m_entityImpl.set_sync_count(count); 00136 } 00137 00138 void EntityRepository::set_entity_owner_rank( Entity & e, unsigned owner_rank) 00139 { 00140 TraceIfWatching("stk_classic::mesh::impl::EntityRepository::set_entity_owner_rank", LOG_ENTITY, e.key()); 00141 DiagIfWatching(LOG_ENTITY, e.key(), "new owner: " << owner_rank); 00142 00143 bool changed = e.m_entityImpl.set_owner_rank(owner_rank); 00144 if ( changed ) { 00145 e.m_entityImpl.log_modified_and_propagate(); 00146 } 00147 } 00148 00149 void EntityRepository::comm_clear( Entity & e) const 00150 { 00151 TraceIfWatching("stk_classic::mesh::impl::EntityRepository::comm_clear", LOG_ENTITY, e.key()); 00152 00153 e.m_entityImpl.comm_clear(); 00154 } 00155 00156 void EntityRepository::comm_clear_ghosting( Entity & e) const 00157 { 00158 TraceIfWatching("stk_classic::mesh::impl::EntityRepository::comm_clear_ghosting", LOG_ENTITY, e.key()); 00159 00160 e.m_entityImpl.comm_clear_ghosting(); 00161 } 00162 00163 void EntityRepository::log_modified( Entity & e ) const 00164 { 00165 TraceIfWatching("stk_classic::mesh::impl::EntityRepository::log_modified", LOG_ENTITY, e.key()); 00166 00167 e.m_entityImpl.log_modified_and_propagate(); 00168 } 00169 00170 } // namespace impl 00171 } // namespace mesh 00172 } // namespace stk_classic 00173 00174 #endif // stk_mesh_baseImpl_EntityRepository_hpp