Sierra Toolkit Version of the Day
EntityRepository.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_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 namespace stk {
00030 namespace mesh {
00031 namespace impl {
00032 
00033 class EntityRepository {
00034 
00035 #if STK_MESH_ENTITYREPOSITORY_MAP_TYPE_TR1
00036   struct stk_entity_rep_hash : public std::unary_function< EntityKey, std::size_t >
00037   {
00038     inline std::size_t
00039     operator()(const EntityKey& x) const
00040     {
00041       return (std::size_t)(x.raw_key());
00042     }
00043   };
00044 
00045   typedef std::tr1::unordered_map<EntityKey, Entity*, stk_entity_rep_hash, std::equal_to<EntityKey> > EntityMap;
00046 #else
00047   typedef std::map<EntityKey,Entity*> EntityMap;
00048 #endif
00049 
00050   public:
00051 
00052     typedef EntityMap::const_iterator iterator;
00053 
00054     EntityRepository() : m_entities() {}
00055     ~EntityRepository();
00056 
00057     Entity * get_entity( const EntityKey &key ) const;
00058 
00059     iterator begin() const { return m_entities.begin(); }
00060     iterator end() const { return m_entities.end(); }
00061 
00062     void clean_changes();
00063 
00064     // Return a pair: the relevant entity, and whether it had to be created
00065     // or not. If there was already an active entity, the second item in the
00066     // will be false; otherwise it will be true (even if the Entity was present
00067     // but marked as destroyed).
00068     std::pair<Entity*,bool>
00069       internal_create_entity( const EntityKey & key );
00070 
00074     void log_created_parallel_copy( Entity & e );
00075 
00082     inline void log_modified(Entity & e) const;
00083 
00084     inline void set_entity_owner_rank( Entity & e, unsigned owner_rank);
00085     inline void set_entity_sync_count( Entity & e, size_t count);
00086 
00087     inline void comm_clear( Entity & e) const;
00088     inline void comm_clear_ghosting( Entity & e) const;
00089 
00090     bool erase_ghosting( Entity & e, const Ghosting & ghosts) const;
00091     bool erase_comm_info( Entity & e, const EntityCommInfo & comm_info) const;
00092 
00093     bool insert_comm_info( Entity & e, const EntityCommInfo & comm_info) const;
00094 
00095     void change_entity_bucket( Bucket & b, Entity & e, unsigned ordinal);
00096     Bucket * get_entity_bucket ( Entity & e ) const;
00097     void destroy_later( Entity & e, Bucket* nil_bucket );
00098 
00099     bool destroy_relation( Entity & e_from,
00100                            Entity & e_to,
00101                            const RelationIdentifier local_id);
00102 
00103     void declare_relation( Entity & e_from,
00104                            Entity & e_to,
00105                            const RelationIdentifier local_id,
00106                            unsigned sync_count );
00107 
00108   private:
00109     void internal_expunge_entity( EntityMap::iterator i);
00110 
00111     EntityMap m_entities;
00112 
00113     //disabel copy constructor and assignment operator
00114     EntityRepository(const EntityRepository &);
00115     EntityRepository & operator =(const EntityRepository &);
00116 };
00117 
00118 /*---------------------------------------------------------------*/
00119 
00120 void EntityRepository::set_entity_sync_count( Entity & e, size_t count)
00121 {
00122   TraceIfWatching("stk::mesh::impl::EntityRepository::set_entity_sync_count", LOG_ENTITY, e.key());
00123 
00124   e.m_entityImpl.set_sync_count(count);
00125 }
00126 
00127 void EntityRepository::set_entity_owner_rank( Entity & e, unsigned owner_rank)
00128 {
00129   TraceIfWatching("stk::mesh::impl::EntityRepository::set_entity_owner_rank", LOG_ENTITY, e.key());
00130   DiagIfWatching(LOG_ENTITY, e.key(), "new owner: " << owner_rank);
00131 
00132   bool changed = e.m_entityImpl.set_owner_rank(owner_rank);
00133   if ( changed ) {
00134     e.m_entityImpl.log_modified_and_propagate();
00135   }
00136 }
00137 
00138 void EntityRepository::comm_clear( Entity & e) const
00139 {
00140   TraceIfWatching("stk::mesh::impl::EntityRepository::comm_clear", LOG_ENTITY, e.key());
00141 
00142   e.m_entityImpl.comm_clear();
00143 }
00144 
00145 void EntityRepository::comm_clear_ghosting( Entity & e) const
00146 {
00147   TraceIfWatching("stk::mesh::impl::EntityRepository::comm_clear_ghosting", LOG_ENTITY, e.key());
00148 
00149   e.m_entityImpl.comm_clear_ghosting();
00150 }
00151 
00152 void EntityRepository::log_modified( Entity & e ) const
00153 {
00154   TraceIfWatching("stk::mesh::impl::EntityRepository::log_modified", LOG_ENTITY, e.key());
00155 
00156   e.m_entityImpl.log_modified_and_propagate();
00157 }
00158 
00159 } // namespace impl
00160 } // namespace mesh
00161 } // namespace stk
00162 
00163 #endif // stk_mesh_baseImpl_EntityRepository_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends