|
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_EntityComm_hpp 00010 #define stk_mesh_EntityComm_hpp 00011 00012 //---------------------------------------------------------------------- 00013 00014 #include <iosfwd> 00015 #include <vector> 00016 00017 #include <stk_util/parallel/ParallelComm.hpp> 00018 #include <stk_mesh/base/Types.hpp> 00019 #include <stk_mesh/base/Ghosting.hpp> 00020 00021 #include <boost/unordered_map.hpp> 00022 00023 //---------------------------------------------------------------------- 00024 00025 namespace stk_classic { 00026 namespace mesh { 00027 00028 class EntityComm 00029 { 00030 public: 00031 typedef boost::unordered_map<EntityKey, EntityCommInfoVector> map_type; 00032 00033 PairIterEntityComm sharing( const EntityKey & key ) const; 00034 PairIterEntityComm comm( const EntityKey & key ) const; 00035 PairIterEntityComm comm( const EntityKey & key, const Ghosting & sub ) const; 00036 00037 bool insert( const EntityKey & key, const EntityCommInfo & val ); 00038 bool erase( const EntityKey & key, const EntityCommInfo & val ); 00039 bool erase( const EntityKey & key, const Ghosting & ghost ); 00040 void comm_clear_ghosting(const EntityKey & key ); 00041 void comm_clear(const EntityKey & key ); 00042 void comm_swap(const EntityKey & key1, const EntityKey & key2); 00043 00044 private: 00045 map_type m_comm_map; 00046 }; 00047 00048 inline PairIterEntityComm EntityComm::sharing( const EntityKey & key ) const 00049 { 00050 map_type::const_iterator it = m_comm_map.find(key); 00051 if (it == m_comm_map.cend()) { 00052 return PairIterEntityComm(); 00053 } 00054 const EntityCommInfoVector & m_comm = it->second; 00055 00056 EntityCommInfoVector::const_iterator i = m_comm.begin(); 00057 EntityCommInfoVector::const_iterator e = m_comm.end(); 00058 00059 e = std::lower_bound( i , e , EntityCommInfo(1, // ghost id, 1->aura 00060 0 ) ); // proc 00061 00062 // Contains everything up the first aura comm (IE, only contains shared comms) 00063 return PairIterEntityComm( i , e ); 00064 } 00065 00066 inline PairIterEntityComm EntityComm::comm( const EntityKey & key ) const 00067 { 00068 map_type::const_iterator it = m_comm_map.find(key); 00069 if (it == m_comm_map.cend()) { 00070 return PairIterEntityComm(); 00071 } 00072 const EntityCommInfoVector & m_comm = it->second; 00073 return PairIterEntityComm(m_comm); 00074 } 00075 00076 inline PairIterEntityComm EntityComm::comm( const EntityKey & key, const Ghosting & sub ) const 00077 { 00078 map_type::const_iterator it = m_comm_map.find(key); 00079 if (it == m_comm_map.cend()) { 00080 return PairIterEntityComm(); 00081 } 00082 const EntityCommInfoVector & m_comm = it->second; 00083 00084 const EntityCommInfo s_begin( sub.ordinal() , 0 ); 00085 const EntityCommInfo s_end( sub.ordinal() + 1 , 0 ); 00086 00087 EntityCommInfoVector::const_iterator i = m_comm.begin(); 00088 EntityCommInfoVector::const_iterator e = m_comm.end(); 00089 00090 i = std::lower_bound( i , e , s_begin ); 00091 e = std::lower_bound( i , e , s_end ); 00092 00093 return PairIterEntityComm( i , e ); 00094 } 00095 00096 inline bool EntityComm::insert( const EntityKey & key, const EntityCommInfo & val ) 00097 { 00098 TraceIfWatching("stk_classic::mesh::EntityComm::insert", LOG_ENTITY, key()); 00099 EntityCommInfoVector & m_comm = m_comm_map[key]; 00100 00101 std::vector< EntityCommInfo >::iterator i = 00102 std::lower_bound( m_comm.begin() , m_comm.end() , val ); 00103 00104 const bool result = ((i == m_comm.end()) || (val != *i)); 00105 00106 if ( result ) { 00107 m_comm.insert( i , val ); 00108 } 00109 00110 return result ; 00111 } 00112 00113 inline bool EntityComm::erase( const EntityKey & key, const EntityCommInfo & val ) 00114 { 00115 TraceIfWatching("stk_classic::mesh::EntityComm::erase(comm)", LOG_ENTITY, key()); 00116 EntityCommInfoVector & m_comm = m_comm_map[key]; 00117 00118 std::vector< EntityCommInfo >::iterator i = 00119 std::lower_bound( m_comm.begin() , m_comm.end() , val ); 00120 00121 const bool result = ( (i != m_comm.end()) && (val == *i) ) ; 00122 00123 if ( result ) { 00124 m_comm.erase( i ); 00125 } 00126 00127 return result ; 00128 } 00129 00130 inline bool EntityComm::erase( const EntityKey & key, const Ghosting & ghost ) 00131 { 00132 TraceIfWatching("stk_classic::mesh::EntityComm::erase(ghost)", LOG_ENTITY, key()); 00133 EntityCommInfoVector & m_comm = m_comm_map[key]; 00134 00135 const EntityCommInfo s_begin( ghost.ordinal() , 0 ); 00136 const EntityCommInfo s_end( ghost.ordinal() + 1 , 0 ); 00137 00138 EntityCommInfoVector::iterator i = m_comm.begin(); 00139 EntityCommInfoVector::iterator e = m_comm.end(); 00140 00141 i = std::lower_bound( i , e , s_begin ); 00142 e = std::lower_bound( i , e , s_end ); 00143 00144 const bool result = i != e ; 00145 00146 if ( result ) { 00147 m_comm.erase( i , e ); 00148 } 00149 00150 return result ; 00151 } 00152 00153 inline void EntityComm::comm_clear_ghosting(const EntityKey & key) 00154 { 00155 TraceIfWatching("stk_classic::mesh::EntityComm::comm_clear_ghosting", LOG_ENTITY, key()); 00156 EntityCommInfoVector & m_comm = m_comm_map[key]; 00157 00158 std::vector< EntityCommInfo >::iterator j = m_comm.begin(); 00159 while ( j != m_comm.end() && j->ghost_id == 0 ) { ++j ; } 00160 m_comm.erase( j , m_comm.end() ); 00161 } 00162 00163 inline void EntityComm::comm_clear(const EntityKey & key) 00164 { 00165 TraceIfWatching("stk_classic::mesh::EntityComm::comm_clear", LOG_ENTITY, key()); 00166 EntityCommInfoVector& commvec = m_comm_map[key]; 00167 commvec.clear(); 00168 } 00169 00170 inline void EntityComm::comm_swap(const EntityKey & key1, const EntityKey & key2) 00171 { 00172 map_type::iterator it1 = m_comm_map.find(key1); 00173 map_type::iterator it2 = m_comm_map.find(key2); 00174 00175 if (it1 == m_comm_map.cend() && it2 == m_comm_map.cend()) { 00176 return; 00177 } 00178 00179 EntityCommInfoVector & comm1 = it1 == m_comm_map.cend() ? m_comm_map[key1] : it1->second; 00180 EntityCommInfoVector & comm2 = it2 == m_comm_map.cend() ? m_comm_map[key2] : it2->second; 00181 00182 comm1.swap(comm2); 00183 } 00184 00186 bool in_shared( const Entity & entity ); 00187 00189 bool in_shared( const Entity & entity , unsigned proc ); 00190 00192 bool in_receive_ghost( const Entity & entity ); 00193 00195 bool in_receive_ghost( const Ghosting & ghost , const Entity & entity ); 00196 00198 bool in_send_ghost( const Entity & entity ); 00199 00201 bool in_send_ghost( const Entity & entity , unsigned proc ); 00202 00204 bool in_ghost( const Ghosting & ghost , const Entity & entity , unsigned p ); 00205 00209 bool in_owned_closure( const Entity & entity , unsigned proc ); 00210 00212 void comm_procs( const Entity & entity , std::vector<unsigned> & procs ); 00213 00215 void comm_procs( const Ghosting & ghost , 00216 const Entity & entity , std::vector<unsigned> & procs ); 00217 00218 //---------------------------------------------------------------------- 00219 00220 void pack_entity_info( CommBuffer & buf , const Entity & entity ); 00221 00222 void unpack_entity_info( 00223 CommBuffer & buf, 00224 const BulkData & mesh , 00225 EntityKey & key , 00226 unsigned & owner , 00227 PartVector & parts , 00228 std::vector<Relation> & relations ); 00229 00231 void pack_field_values( CommBuffer & , Entity & ); 00232 00234 bool unpack_field_values( CommBuffer & , Entity & , std::ostream & error_msg ); 00235 00236 } // namespace mesh 00237 } // namespace stk_classic 00238 00239 #endif