13 #include <stk_mesh/base/Ghosting.hpp> 14 #include <stk_mesh/base/Bucket.hpp> 15 #include <stk_mesh/base/BulkData.hpp> 16 #include <stk_mesh/base/MetaData.hpp> 18 #include <stk_mesh/baseImpl/EntityImpl.hpp> 25 PairIterRelation EntityImpl::relations(
unsigned rank )
const 27 RelationVector::const_iterator i = m_relation.begin();
28 RelationVector::const_iterator e = m_relation.end();
33 i = std::lower_bound( i , e , lo_attr , LessRelation() );
37 e = std::lower_bound( i , e , hi_attr , LessRelation() );
39 return PairIterRelation( i , e );
45 inline bool is_degenerate_relation (
const Relation &r1 ,
const Relation &r2 )
47 return r1.raw_relation_id() == r2.raw_relation_id() && r1.entity() != r2.entity() ;
52 void EntityImpl::log_resurrect()
54 TraceIfWatching(
"stk_classic::mesh::impl::EntityImpl::log_resurrect", LOG_ENTITY, key());
56 ThrowErrorMsgIf( EntityLogDeleted != m_mod_log,
57 "Trying to resurrect non-deleted entity: " <<
58 print_entity_key( MetaData::get( bucket() ), key() ) );
60 m_mod_log = EntityLogModified;
64 void EntityImpl::log_modified_and_propagate()
66 TraceIfWatching(
"stk_classic::mesh::impl::EntityImpl::log_modified_and_propagate", LOG_ENTITY, key());
69 if (m_mod_log != EntityLogNoChange) {
74 m_mod_log = EntityLogModified;
78 for ( PairIterRelation irel = relations() ; irel.first != irel.second ; ) {
80 Entity & entity = *(irel.second->entity());
81 if ( rank_of_original_entity >= entity.entity_rank() ) {
84 else if ( entity.log_query() == EntityLogNoChange ) {
85 entity.m_entityImpl.log_modified_and_propagate();
91 void EntityImpl::compress_relation_capacity()
97 void EntityImpl::log_created_parallel_copy()
99 TraceIfWatching(
"stk_classic::mesh::impl::EntityImpl::log_created_parallel_copy", LOG_ENTITY, key());
101 if ( EntityLogCreated == m_mod_log ) {
102 m_mod_log = EntityLogModified ;
106 bool EntityImpl::destroy_relation( Entity& e_to,
const RelationIdentifier local_id )
108 TraceIfWatching(
"stk_classic::mesh::impl::EntityImpl::destroy_relation", LOG_ENTITY, key());
110 bool destroyed_relations =
false;
111 for ( RelationVector::iterator
112 i = m_relation.begin() ; i != m_relation.end() ; ++i ) {
113 if ( i->entity() == & e_to && i->identifier() == local_id ) {
114 i = m_relation.erase( i );
115 destroyed_relations =
true;
119 return destroyed_relations;
122 bool EntityImpl::declare_relation( Entity & e_to,
123 const RelationIdentifier local_id,
125 bool is_back_relation )
127 TraceIfWatching(
"stk_classic::mesh::impl::EntityImpl::declare_relation", LOG_ENTITY, key());
129 const MetaData & meta_data = MetaData::get( bucket() );
131 Relation new_relation( e_to , local_id );
132 #ifdef SIERRA_MIGRATION 133 new_relation.setRelationType( e_to.entity_rank() >
entity_rank() ? Relation::USED_BY : Relation::USES );
134 new_relation.setOrientation(0);
137 const RelationVector::iterator rel_end = m_relation.end();
138 RelationVector::iterator rel_begin = m_relation.begin();
139 RelationVector::iterator
lower;
141 lower = std::lower_bound( rel_begin , rel_end , new_relation , LessRelation() );
164 if ( !m_relation.empty() && !is_back_relation ) {
168 RelationVector::iterator start, end;
169 start = (
lower == rel_begin) ? rel_begin :
lower - 1;
170 end = (
lower == rel_end) ? rel_end :
lower + 1;
172 for (RelationVector::iterator itr = start; itr != end; ++itr) {
173 ThrowErrorMsgIf( is_degenerate_relation ( new_relation , *itr ),
174 "Could not declare relation from " <<
175 print_entity_key( meta_data, key() ) <<
" to " <<
176 print_entity_key( meta_data, e_to.key() ) <<
", with id " <<
177 local_id <<
". Relation already exists to " <<
178 print_entity_key( meta_data, itr->entity()->key() ));
182 bool not_already_exists = (rel_end ==
lower) ||
183 ( !is_back_relation && new_relation.raw_relation_id() !=
lower->raw_relation_id() ) ||
184 ( is_back_relation && new_relation != *
lower );
187 if (not_already_exists) {
188 lower = m_relation.insert(
lower , new_relation );
190 set_sync_count( sync_count );
199 void EntityImpl::set_key(EntityKey key)
204 void EntityImpl::update_key(EntityKey key)
208 std::sort(m_relation.begin(), m_relation.end(), LessRelation());
209 log_modified_and_propagate();
211 for ( RelationVector::iterator i = m_relation.begin(), e = m_relation.end();
216 EntityImpl & entity = i->entity()->m_entityImpl;
217 std::sort(entity.m_relation.begin(), entity.m_relation.end(), LessRelation());
218 entity.log_modified_and_propagate();
225 return BulkData::get(bucket()).entity_comm(m_key);
230 return BulkData::get(bucket()).entity_comm_sharing(m_key);
235 return BulkData::get(bucket()).entity_comm(m_key,sub);
240 return BulkData::get(bucket()).entity_comm_insert(m_key,val);
243 bool EntityImpl::erase(
const EntityCommInfo & val )
245 return BulkData::get(bucket()).entity_comm_erase(m_key,val);
248 bool EntityImpl::erase(
const Ghosting & ghost )
250 return BulkData::get(bucket()).entity_comm_erase(m_key,ghost);
253 void EntityImpl::comm_clear_ghosting()
255 return BulkData::get(bucket()).entity_comm_clear_ghosting(m_key);
258 void EntityImpl::comm_clear()
260 return BulkData::get(bucket()).entity_comm_clear(m_key);
String lower(const String &s)
Function lower returns a lower case version of the string.
raw_relation_id_type raw_relation_id() const
The encoded relation raw_relation_id.
PairIter< std::vector< EntityCommInfo >::const_iterator > PairIterEntityComm
Span of ( communication-subset-ordinal , process-rank ) pairs for the communication of an entity...
std::vector< Relation > RelationVector
Span of a sorted relations for a given domain entity.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).
bool insert(PartVector &v, Part &part)
Insert a part into a properly ordered collection of parts. Returns true if this is a new insertion...