19 #include <stk_util/util/string_case_compare.hpp> 20 #include <stk_util/parallel/ParallelComm.hpp> 21 #include <stk_util/parallel/ParallelReduce.hpp> 22 #include <stk_mesh/base/MetaData.hpp> 23 #include <stk_mesh/base/Comm.hpp> 25 #include <stk_mesh/base/BulkData.hpp> 28 #include <stk_mesh/baseImpl/FieldRepository.hpp> 33 MetaData & MetaData::get(
const BulkData & bulk_data) {
34 return bulk_data.meta_data();
37 MetaData & MetaData::get(
const Bucket & bucket) {
38 return MetaData::get(BulkData::get(bucket));
41 MetaData & MetaData::get(
const Entity & entity) {
42 return MetaData::get(BulkData::get(entity));
45 MetaData & MetaData::get(
const Ghosting & ghost) {
46 return MetaData::get(BulkData::get(ghost));
51 print_entity_id( std::ostream & os ,
const MetaData & meta_data ,
52 unsigned type , EntityId
id )
54 const std::string & name = meta_data.entity_rank_name( type );
55 return os << name <<
"[" <<
id <<
"]" ;
60 print_entity_key( std::ostream & os ,
const MetaData & meta_data ,
65 return print_entity_id( os , meta_data , type ,
id );
69 print_entity_key(
const MetaData & meta_data ,
const EntityKey & key )
71 std::ostringstream out;
72 print_entity_key(out, meta_data, key);
78 void MetaData::require_not_committed()
const 80 ThrowRequireMsg(!m_commit,
"mesh MetaData has been committed.");
83 void MetaData::require_committed()
const 85 ThrowRequireMsg(m_commit,
"mesh MetaData has not been committed.");
88 void MetaData::require_same_mesh_meta_data(
const MetaData & rhs )
const 90 ThrowRequireMsg(
this == &rhs,
"Different mesh_meta_data.");
93 void MetaData::require_valid_entity_rank( EntityRank rank )
const 96 "entity_rank " << rank <<
" >= " << m_entity_rank_names.size() );
99 void MetaData::require_not_relation_target(
const Part *
const part )
const 101 std::vector<PartRelation>::const_iterator i_end = part->relations().end();
102 std::vector<PartRelation>::const_iterator i = part->relations().begin();
103 for ( ; i != i_end ; ++i ) {
104 ThrowRequireMsg( part != i->m_target,
105 "Part[" << part->name() <<
"] is a PartRelation target");
115 m_universal_part( NULL ),
117 m_shares_part( NULL ),
119 m_field_relations( ),
121 m_entity_rank_names( entity_rank_names ),
122 m_spatial_dimension( 0 )
124 ThrowErrorMsgIf( entity_rank_names.empty(),
"entity ranks empty" );
128 m_universal_part = m_part_repo.universal_part();
129 m_owns_part = & declare_internal_part(
"OWNS");
130 m_shares_part = & declare_internal_part(
"SHARES");
137 m_universal_part( NULL ),
139 m_shares_part( NULL ),
141 m_field_relations( ),
143 m_entity_rank_names( ),
144 m_spatial_dimension( 0 )
148 m_universal_part = m_part_repo.universal_part();
149 m_owns_part = & declare_internal_part(
"OWNS");
150 m_shares_part = & declare_internal_part(
"SHARES");
157 ThrowErrorMsgIf( entity_rank_names.empty(),
"entity ranks empty" );
159 m_entity_rank_names = entity_rank_names;
162 const std::string& MetaData::entity_rank_name( EntityRank
entity_rank )
const 164 ThrowErrorMsgIf( entity_rank >= m_entity_rank_names.size(),
166 " out of range. Must be in range 0.." << m_entity_rank_names.size());
171 EntityRank MetaData::entity_rank(
const std::string &name )
const 173 EntityRank entity_rank = InvalidEntityRank;
175 for (
size_t i = 0; i < m_entity_rank_names.size(); ++i)
176 if (
equal_case(name, m_entity_rank_names[i])) {
186 const char * required_by )
const 188 const PartVector & all_parts = m_part_repo.get_all_parts();
190 Part *
const p =
find( all_parts , p_name );
192 ThrowErrorMsgIf( required_by && NULL == p,
193 "Failed to find part with name " << p_name <<
194 " for method " << required_by );
201 require_not_committed();
203 const EntityRank rank = InvalidEntityRank;
205 return *m_part_repo.declare_part( p_name, rank );
208 Part & MetaData::declare_internal_part(
const std::string & p_name )
210 std::string internal_name = convert_to_internal_name(p_name);
216 require_not_committed();
217 require_valid_entity_rank(rank);
219 return *m_part_repo.declare_part( p_name , rank );
222 Part & MetaData::declare_internal_part(
const std::string & p_name , EntityRank rank )
224 std::string internal_name = convert_to_internal_name(p_name);
230 require_not_committed();
232 for ( PartVector::const_iterator
233 i = part_intersect.begin() ; i != part_intersect.end() ; ++i ) {
234 require_not_relation_target(*i);
237 return *m_part_repo.declare_part( part_intersect );
242 static const char method[] =
"stk_classic::mesh::MetaData::declare_part_subset" ;
244 require_not_committed();
245 require_same_mesh_meta_data( MetaData::get(superset) );
246 require_same_mesh_meta_data( MetaData::get(subset) );
247 require_not_relation_target( &superset );
248 require_not_relation_target( &subset );
250 m_part_repo.declare_subset( superset, subset );
254 m_field_repo.verify_and_clean_restrictions(method, superset, subset, m_part_repo.get_all_parts());
262 require_not_committed();
263 require_not_relation_target( &root_part );
265 ThrowErrorMsgIf( !stencil,
"stencil function pointer cannot be NULL" );
267 ThrowErrorMsgIf( 0 != target_part.
subsets().size() ||
270 "target Part[" << target_part.
name() <<
271 "] cannot be a superset or subset" );
274 tmp.
m_root = & root_part ;
275 tmp.m_target = & target_part ;
276 tmp.m_function = stencil ;
278 m_part_repo.declare_part_relation( root_part, tmp, target_part );
285 const std::string & arg_name ,
286 const DataTraits & arg_traits ,
288 const shards::ArrayDimTag *
const * arg_dim_tags ,
289 unsigned arg_num_states )
291 require_not_committed();
293 return m_field_repo.declare_field(
305 EntityRank arg_entity_rank ,
306 const Part & arg_part ,
307 const unsigned * arg_stride ,
308 const void * arg_init_value )
310 static const char method[] =
311 "std::mesh::MetaData::declare_field_restriction" ;
314 require_same_mesh_meta_data( MetaData::get(arg_field) );
315 require_same_mesh_meta_data( MetaData::get(arg_part) );
317 m_field_repo.declare_field_restriction(
322 m_part_repo.get_all_parts(),
330 EntityRank arg_entity_rank ,
332 const unsigned * arg_stride ,
333 const void * arg_init_value )
335 static const char method[] =
336 "std::mesh::MetaData::declare_field_restriction" ;
339 require_same_mesh_meta_data( MetaData::get(arg_field) );
341 m_field_repo.declare_field_restriction(
346 m_part_repo.get_all_parts(),
353 void MetaData::internal_declare_field_relation(
359 tmp.
m_root = & pointer_field ;
363 m_field_relations.push_back( tmp );
370 require_not_committed();
380 std::vector<PropertyBase * >::iterator j = m_properties.begin();
382 for ( ; j != m_properties.end() ; ++j ) {
delete *j ; }
384 m_properties.clear();
397 void pack( CommBuffer & b ,
const PartVector & pset )
399 PartVector::const_iterator i , j ;
400 for ( i = pset.begin() ; i != pset.end() ; ++i ) {
401 const Part & p = **i ;
405 const size_t name_len = p.
name().size() + 1 ;
406 const char *
const name_ptr = p.
name().c_str();
410 b.pack<
unsigned>( ord );
413 b.pack<
unsigned>( name_len );
414 b.pack<
char>( name_ptr , name_len );
416 const unsigned subset_size =
static_cast<unsigned>(subsets.size());
417 b.pack<
unsigned>( subset_size );
418 for ( j = subsets.begin() ; j != subsets.end() ; ++j ) {
419 const Part & s = **j ;
420 const unsigned ord = s.mesh_meta_data_ordinal();
421 b.pack<
unsigned>( ord );
423 const unsigned intersect_size =
static_cast<unsigned>(
intersect.size());
424 b.pack<
unsigned>( intersect_size );
426 const Part & s = **j ;
427 const unsigned ord = s.mesh_meta_data_ordinal();
428 b.pack<
unsigned>( ord );
433 bool unpack_verify( CommBuffer & b ,
const PartVector & pset )
435 enum { MAX_TEXT_LEN = 4096 };
436 char b_text[ MAX_TEXT_LEN ];
440 PartVector::const_iterator i , j ;
441 for ( i = pset.begin() ; ok && i != pset.end() ; ++i ) {
442 const Part & p = **i ;
445 const unsigned name_len =
static_cast<unsigned>(p.name().size()) + 1 ;
446 const char *
const name_ptr = p.name().c_str();
449 b.unpack<
unsigned>( b_tmp );
450 ok = b_tmp == p.mesh_meta_data_ordinal();
454 b.unpack<
unsigned>( b_tmp );
455 ok = b_tmp == name_len ;
458 b.unpack<
char>( b_text , name_len );
459 ok = 0 == strcmp( name_ptr , b_text );
463 b.unpack<
unsigned>( b_tmp );
464 ok = b_tmp == subsets.size() ;
466 for ( j = subsets.begin() ; ok && j != subsets.end() ; ++j ) {
467 const Part & s = **j ;
468 b.unpack<
unsigned>( b_tmp );
469 ok = b_tmp == s.mesh_meta_data_ordinal();
473 b.unpack<
unsigned>( b_tmp );
477 const Part & s = **j ;
478 b.unpack<
unsigned>( b_tmp );
479 ok = b_tmp == s.mesh_meta_data_ordinal();
485 void pack( CommBuffer & ,
486 const std::vector< FieldBase * > & )
490 bool unpack_verify( CommBuffer & ,
491 const std::vector< FieldBase * > & )
505 const bool is_root = 0 == p_rank ;
507 CommBroadcast comm( pm , 0 );
510 pack( comm.send_buffer() , s.
get_parts() );
514 comm.allocate_buffer();
517 pack( comm.send_buffer() , s.
get_parts() );
525 ok[0] = unpack_verify( comm.recv_buffer() , s.
get_parts() );
526 ok[1] = unpack_verify( comm.recv_buffer() , s.
get_fields() );
528 all_reduce( pm , ReduceMin<2>( ok ) );
530 ThrowRequireMsg(ok[0],
"P" << p_rank <<
": FAILED for Parts");
531 ThrowRequireMsg(ok[1],
"P" << p_rank <<
": FAILED for Fields");
FieldBase * m_target
relation range part
void verify_parallel_consistency(const MetaData &s, ParallelMachine pm)
Verify that the meta data is identical on all processors.
Field base class with an anonymous data type and anonymous multi-dimension.
This is a class for selecting buckets based on a set of meshparts and set logic.
size_t intersect(const PartVector &v, const PartVector &p)
Query cardinality of intersection of two PartVectors.
Integer type for the entity keys, which is an encoding of the entity type and entity identifier...
An application-defined subset of a problem domain.
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
const PartVector & intersection_of() const
Parts for which this part is defined as the intersection.
FieldBase * m_root
relation domain part
const std::string & name() const
Application-defined text name of this part.
unsigned mesh_meta_data_ordinal() const
Internally generated ordinal of this part that is unique within the owning meta data manager...
Part * m_root
relation domain part
const PartVector & supersets() const
Parts that are supersets of this part.
EntityId entity_id(const EntityKey &key)
Given an entity key, return the identifier for the entity.
const PartVector & subsets() const
Parts that are subsets of this part.
A defined entity-relationship between parts. An internal class that should never need to be directly...
bool equal_case(const char *lhs, const char *rhs)
Case-insensitive equality compare.
int(* relation_stencil_ptr)(unsigned from_type, unsigned to_type, unsigned identifier)
A relation stencil maps entity relationships to ordinals.
relation_stencil_ptr m_function
relation stencil
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
A defined entity-relationship between a field of a pointer type and the field that it should point to...
Part * find(const PartVector &parts, const std::string &name)
Find a part by name in a collection of parts.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).