13 #include <stk_mesh/base/BulkData.hpp>
14 #include <stk_mesh/base/MetaData.hpp>
15 #include <stk_mesh/base/FieldData.hpp>
16 #include <stk_mesh/base/EntityComm.hpp>
18 namespace stk_classic {
23 bool in_shared(
const Entity & entity )
26 return ! ec.empty() && ec.front().ghost_id == 0 ;
29 bool in_shared(
const Entity & entity ,
unsigned proc )
32 ! ec.empty() && ec->ghost_id == 0 ; ++ec ) {
33 if ( proc == ec->proc ) {
40 bool in_receive_ghost(
const Entity & entity )
44 return ! ec.empty() && ec.front().ghost_id != 0 &&
45 ec.front().proc == entity.owner_rank();
48 bool in_receive_ghost(
const Ghosting & ghost ,
const Entity & entity )
50 return in_ghost( ghost , entity , entity.owner_rank() );
53 bool in_send_ghost(
const Entity & entity )
57 return ! ec.empty() && ec.back().ghost_id != 0 &&
58 ec.back().proc != entity.owner_rank();
61 bool in_send_ghost(
const Entity & entity ,
unsigned proc )
64 if ( ec->ghost_id != 0 &&
65 ec->proc != entity.owner_rank() &&
73 bool in_ghost(
const Ghosting & ghost ,
const Entity & entity ,
unsigned p )
76 EntityCommInfo tmp( ghost.ordinal() , p );
78 std::vector<EntityCommInfo>::const_iterator i =
79 std::lower_bound( entity.comm().begin() , entity.comm().end() , tmp );
81 return i != entity.comm().end() && tmp == *i ;
87 bool in_owned_closure(
const Entity & entity ,
unsigned proc )
93 bool result = entity.owner_rank() == proc ;
96 const unsigned erank = entity.entity_rank();
99 for ( PairIterRelation
100 rel = entity.relations(); ! result && ! rel.empty() ; ++rel ) {
101 result = erank < rel->entity_rank() &&
102 in_owned_closure( * rel->entity(), proc);
109 void comm_procs(
const Entity & entity , std::vector<unsigned> & procs )
113 procs.push_back( ec->proc );
115 std::sort( procs.begin() , procs.end() );
116 std::vector<unsigned>::iterator
117 i = std::unique( procs.begin() , procs.end() );
118 procs.erase( i , procs.end() );
121 void comm_procs(
const Ghosting & ghost ,
122 const Entity & entity , std::vector<unsigned> & procs )
126 if ( ec->ghost_id == ghost.ordinal() ) {
127 procs.push_back( ec->proc );
135 void pack_entity_info( CommBuffer & buf ,
const Entity & entity )
137 const EntityKey & key = entity.key();
138 const unsigned owner = entity.owner_rank();
139 const std::pair<const unsigned *, const unsigned *>
140 part_ordinals = entity.bucket().superset_part_ordinals();
141 const PairIterRelation relations = entity.relations();
143 const unsigned nparts = part_ordinals.second - part_ordinals.first ;
144 const unsigned nrel = relations.size();
146 buf.pack<EntityKey>( key );
147 buf.pack<
unsigned>( owner );
148 buf.pack<
unsigned>( nparts );
149 buf.pack<
unsigned>( part_ordinals.first , nparts );
150 buf.pack<
unsigned>( nrel );
152 for (
unsigned i = 0 ; i < nrel ; ++i ) {
153 buf.pack<EntityKey>( relations[i].entity()->key() );
154 buf.pack<
unsigned>( relations[i].identifier() );
155 buf.pack<
unsigned>( relations[i].attribute() );
159 void unpack_entity_info(
161 const BulkData & mesh ,
165 std::vector<Relation> & relations )
167 unsigned nparts = 0 ;
170 buf.unpack<EntityKey>( key );
171 buf.unpack<
unsigned>( owner );
172 buf.unpack<
unsigned>( nparts );
174 parts.resize( nparts );
176 for (
unsigned i = 0 ; i < nparts ; ++i ) {
177 unsigned part_ordinal = ~0u ;
178 buf.unpack<
unsigned>( part_ordinal );
179 parts[i] = & MetaData::get(mesh).get_part( part_ordinal );
185 relations.reserve( nrel );
187 for (
unsigned i = 0 ; i < nrel ; ++i ) {
189 unsigned rel_id = 0 ;
190 unsigned rel_attr = 0 ;
191 buf.unpack<EntityKey>( rel_key );
192 buf.unpack<
unsigned>( rel_id );
193 buf.unpack<
unsigned>( rel_attr );
194 Entity *
const entity =
196 if ( entity && EntityLogDeleted != entity->log_query() ) {
197 Relation rel( * entity, rel_id );
198 rel.set_attribute(rel_attr);
199 relations.push_back( rel );
207 void pack_field_values( CommBuffer & buf , Entity & entity )
209 const Bucket & bucket = entity.bucket();
210 const BulkData & mesh = BulkData::get(bucket);
211 const MetaData & mesh_meta_data = MetaData::get(mesh);
213 const std::vector< FieldBase * > & fields = mesh_meta_data.get_fields();
215 for ( std::vector< FieldBase * >::const_iterator
216 i = fields.begin() ; i != fields.end() ; ++i ) {
218 const FieldBase & f = **i ;
220 if ( f.data_traits().is_pod ) {
223 buf.pack<
unsigned>( size );
226 unsigned char *
const ptr =
227 reinterpret_cast<unsigned char *
>(
field_data( f , entity ) );
228 buf.pack<
unsigned char>( ptr , size );
234 bool unpack_field_values(
235 CommBuffer & buf , Entity & entity , std::ostream & error_msg )
237 const Bucket & bucket = entity.bucket();
238 const BulkData & mesh = BulkData::get(bucket);
239 const MetaData & mesh_meta_data = MetaData::get(mesh);
241 const std::vector< FieldBase * > & fields = mesh_meta_data.get_fields();
243 const std::vector< FieldBase * >::const_iterator i_end = fields.end();
244 const std::vector< FieldBase * >::const_iterator i_beg = fields.begin();
246 std::vector< FieldBase * >::const_iterator i ;
250 for ( i = i_beg ; i_end != i ; ) {
251 const FieldBase & f = **i ; ++i ;
253 if ( f.data_traits().is_pod ) {
256 unsigned recv_data_size = 0 ;
257 buf.unpack<
unsigned>( recv_data_size );
259 if ( size != recv_data_size ) {
262 print_entity_key( error_msg , mesh_meta_data , entity.key() );
264 error_msg <<
" " << f.name();
265 error_msg <<
" " << size ;
266 error_msg <<
" != " << recv_data_size ;
267 buf.skip<
unsigned char>( recv_data_size );
270 unsigned char * ptr =
271 reinterpret_cast<unsigned char *
>(
field_data( f , entity ) );
272 buf.unpack<
unsigned char>( ptr , size );
unsigned field_data_size(const FieldBase &f, const Bucket &k)
Size, in bytes, of the field data for each entity.
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
EntityId entity_id(const EntityKey &key)
Given an entity key, return the identifier for the entity.
std::vector< Part * > PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
PairIter< std::vector< EntityCommInfo >::const_iterator > PairIterEntityComm
Span of ( communication-subset-ordinal , process-rank ) pairs for the communication of an entity...
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).