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 <map>
00013 #include <stk_mesh/base/Entity.hpp>
00014 
00015 namespace stk {
00016 namespace mesh {
00017 namespace impl {
00018 
00019 class EntityRepository {
00020     typedef std::map<EntityKey,Entity*> EntityMap;
00021   public:
00022     typedef std::map<EntityKey,Entity*>::const_iterator iterator;
00023 
00024     EntityRepository() : m_entities() {}
00025     ~EntityRepository();
00026 
00027     Entity * get_entity( const EntityKey &key ) const;
00028 
00029     iterator begin() const { return m_entities.begin(); }
00030     iterator end() const { return m_entities.end(); }
00031 
00032     void clean_changes();
00033 
00034     // Return a pair: the relevant entity, and whether it had to be created
00035     // or not. If there was already an active entity, the second item in the
00036     // will be false; otherwise it will be true (even if the Entity was present
00037     // but marked as destroyed).
00038     std::pair<Entity*,bool>
00039       internal_create_entity( const EntityKey & key );
00040 
00044     void log_created_parallel_copy( Entity & e );
00045 
00046     inline void set_entity_owner_rank( Entity & e, unsigned owner_rank);
00047     inline void set_entity_sync_count( Entity & e, size_t count);
00048 
00049     inline void comm_clear( Entity & e) const;
00050     inline void comm_clear_ghosting( Entity & e) const;
00051 
00052     bool erase_ghosting( Entity & e, const Ghosting & ghosts) const;
00053     bool erase_comm_info( Entity & e, const EntityCommInfo & comm_info) const;
00054 
00055     bool insert_comm_info( Entity & e, const EntityCommInfo & comm_info) const;
00056 
00057     void change_entity_bucket( Bucket & b, Entity & e, unsigned ordinal);
00058     Bucket * get_entity_bucket ( Entity & e ) const;
00059     void destroy_later( Entity & e, Bucket* nil_bucket );
00060 
00061     void destroy_relation( Entity & e_from, Entity & e_to);
00062 
00063     void declare_relation( Entity & e_from,
00064                            Entity & e_to,
00065                            const unsigned local_id,
00066                            unsigned sync_count );
00067 
00068     // Based on our modification model, if an entity gets modified, then all
00069     // entities of higher rank that depend on this entity must also be marked
00070     // as modified. In other words, all entities that have modified_entity
00071     // in their closure must also be marked as modified. This is the ONLY
00072     // place in the code base that should call log_modified directly.
00073     void modify_and_propagate( Entity & modified_entity ) const;
00074 
00075   private:
00076     void internal_expunge_entity( EntityMap::iterator i);
00077 
00078     EntityMap                           m_entities ;
00079 
00080     //disabel copy constructor and assignment operator
00081     EntityRepository(const EntityRepository &);
00082     EntityRepository & operator =(const EntityRepository &);
00083 };
00084 
00085 /*---------------------------------------------------------------*/
00086 
00087 void EntityRepository::set_entity_sync_count( Entity & e, size_t count) {
00088   e.m_entityImpl.set_sync_count(count);
00089 }
00090 
00091 void EntityRepository::set_entity_owner_rank( Entity & e, unsigned owner_rank) {
00092   bool changed = e.m_entityImpl.set_owner_rank(owner_rank);
00093   if ( changed ) {
00094     modify_and_propagate( e );
00095   }
00096 }
00097 
00098 void EntityRepository::comm_clear( Entity & e) const {
00099   e.m_entityImpl.comm_clear();
00100 }
00101 
00102 void EntityRepository::comm_clear_ghosting( Entity & e) const {
00103   e.m_entityImpl.comm_clear_ghosting();
00104 }
00105 
00106 } // namespace impl
00107 } // namespace mesh
00108 } // namespace stk
00109 
00110 #endif // stk_mesh_baseImpl_EntityRepository_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends