9 #ifndef stk_mesh_BulkData_hpp 10 #define stk_mesh_BulkData_hpp 14 #include <stk_util/parallel/Parallel.hpp> 15 #include <stk_util/parallel/DistributedIndex.hpp> 17 #include <stk_mesh/base/Types.hpp> 18 #include <stk_mesh/base/Field.hpp> 19 #include <stk_mesh/base/MetaData.hpp> 20 #include <stk_mesh/base/Ghosting.hpp> 21 #include <stk_mesh/base/Selector.hpp> 22 #include <stk_mesh/base/Trace.hpp> 23 #include <stk_mesh/base/EntityComm.hpp> 25 #include <stk_mesh/baseImpl/EntityRepository.hpp> 26 #include <stk_mesh/baseImpl/BucketRepository.hpp> 52 void optimize_buckets_at_modification_end(
bool b) { m_optimize_buckets = b; }
58 enum BulkDataSyncState { MODIFIABLE = 1 , SYNCHRONIZED = 2 };
71 unsigned bucket_max_size = 1000 ,
72 bool use_memory_pool =
true );
132 bool final_modification_end()
134 optimize_buckets_at_modification_end(
true);
141 m_mesh_finalized =
true;
185 m_bucket_repository.copy_fields(
195 const std::vector<Bucket*> &
buckets( EntityRank rank )
const 196 {
return m_bucket_repository.buckets(rank); }
199 AllBucketsRange get_bucket_range()
const 201 return m_bucket_repository.get_bucket_range();
204 AllBucketsRange get_bucket_range( EntityRank rank )
const 206 return m_bucket_repository.get_bucket_range(rank);
218 return m_entity_repo.get_entity(key);
238 void change_entity_id( EntityId
id,
Entity & entity);
254 add_parts.begin(), add_parts.end(),
255 remove_parts.begin(), remove_parts.end());
262 template<
typename AddIterator,
typename RemoveIterator>
264 AddIterator begin_add_parts, AddIterator end_add_parts,
265 RemoveIterator begin_remove_parts, RemoveIterator end_remove_parts,
266 bool always_propagate_internal_changes=
true );
315 std::vector<Entity *>& requested_entities);
339 const RelationIdentifier local_id );
362 const RelationIdentifier local_id );
368 {
return m_entity_comm ; }
402 const std::vector<EntityProc> & add_send ,
403 const std::vector<Entity*> & remove_receive );
412 const std::vector<Ghosting*> &
ghostings()
const {
return m_ghosting ; }
421 bool entity_comm_insert(
const EntityKey & key,
const EntityCommInfo & val) {
return m_entity_comm_map.insert(key,val); }
422 bool entity_comm_erase(
const EntityKey & key,
const EntityCommInfo & val) {
return m_entity_comm_map.erase(key,val); }
423 bool entity_comm_erase(
const EntityKey & key,
const Ghosting & ghost) {
return m_entity_comm_map.erase(key,ghost); }
424 void entity_comm_clear_ghosting(
const EntityKey & key ) { m_entity_comm_map.comm_clear_ghosting(key); }
425 void entity_comm_clear(
const EntityKey & key) { m_entity_comm_map.comm_clear(key); }
426 void entity_comm_swap(
const EntityKey & key1,
const EntityKey & key2) { m_entity_comm_map.comm_swap(key1, key2); }
431 MetaData & meta_data()
const {
return m_mesh_meta_data ; }
433 #ifndef DOXYGEN_COMPILE 440 parallel::DistributedIndex m_entities_index ;
441 impl::EntityRepository m_entity_repo ;
442 impl::BucketRepository m_bucket_repository ;
443 std::vector<Entity*> m_entity_comm ;
444 std::vector<Ghosting*> m_ghosting ;
447 MetaData & m_mesh_meta_data ;
449 unsigned m_parallel_size ;
450 unsigned m_parallel_rank ;
451 size_t m_sync_count ;
452 BulkDataSyncState m_sync_state ;
453 bool m_meta_data_verified ;
454 bool m_optimize_buckets;
455 bool m_mesh_finalized;
456 EntityComm m_entity_comm_map;
462 unsigned determine_new_owner( Entity & )
const ;
469 void internal_change_entity_parts( Entity & ,
477 void internal_change_entity_parts( Entity & ,
478 const OrdinalVector & add_parts ,
479 const OrdinalVector & remove_parts,
480 bool always_propagate_internal_changes=
true);
482 void internal_propagate_part_changes( Entity & entity,
const PartVector & removed );
483 void internal_propagate_part_changes( Entity & entity,
const OrdinalVector & removed );
485 void internal_change_ghosting( Ghosting & ghosts,
486 const std::vector<EntityProc> & add_send ,
487 const std::vector<Entity*> & remove_receive );
489 bool internal_modification_end(
bool regenerate_aura );
490 void internal_resolve_shared_modify_delete();
491 void internal_resolve_shared_modify_delete_second_pass();
492 void internal_resolve_ghosted_modify_delete();
493 void internal_resolve_parallel_create();
494 void internal_resolve_shared_membership();
496 void internal_update_distributed_index( std::vector<Entity*> & shared_new );
503 void internal_regenerate_shared_aura();
505 void internal_basic_part_check(
const Part* part,
507 const unsigned undef_rank,
508 bool& intersection_ok,
510 bool& rank_ok)
const;
517 bool internal_quick_verify_change_part(
const Part* part,
519 const unsigned undef_rank)
const;
521 void internal_verify_change_parts(
const MetaData & meta ,
522 const Entity & entity ,
525 void internal_verify_change_parts(
const MetaData & meta ,
526 const Entity & entity ,
527 const OrdinalVector & parts )
const;
536 void require_ok_to_modify()
const ;
538 void require_entity_owner(
const Entity & entity,
unsigned owner)
const ;
540 void require_metadata_committed()
const;
542 void require_good_rank_and_id(EntityRank ent_rank, EntityId ent_id)
const;
544 void require_valid_relation(
const char action[] ,
546 const Entity & e_from ,
547 const Entity & e_to );
554 friend class UnitTestModificationEndWrapper;
555 friend class ::stk_classic::mesh::MetaData;
559 BulkData & BulkData::get(
const Bucket & bucket) {
560 return bucket.bulk_data();
563 BulkData & BulkData::get(
const Entity & entity) {
564 return BulkData::get(entity.bucket());
567 BulkData & BulkData::get(
const Ghosting & ghost) {
568 return ghost.bulk_data();
579 void set_field_relations( Entity & e_from ,
581 const unsigned ident );
584 void BulkData::internal_basic_part_check(
const Part* part,
586 const unsigned undef_rank,
587 bool& intersection_ok,
593 intersection_ok = part->intersection_of().empty();
594 rel_target_ok = ( part->relations().empty() ||
595 part != part->relations().begin()->m_target );
597 #ifdef SIERRA_MIGRATION 600 const unsigned part_rank = part->primary_entity_rank();
602 undef_rank == part_rank );
606 inline bool BulkData::internal_quick_verify_change_part(
const Part* part,
608 const unsigned undef_rank)
const 610 bool intersection_ok, rel_target_ok, rank_ok;
611 internal_basic_part_check(part,
entity_rank, undef_rank, intersection_ok, rel_target_ok, rank_ok);
612 return intersection_ok && rel_target_ok && rank_ok;
619 template<
typename AddIterator,
typename RemoveIterator>
621 AddIterator begin_add_parts, AddIterator end_add_parts,
622 RemoveIterator begin_remove_parts, RemoveIterator end_remove_parts,
623 bool always_propagate_internal_changes)
625 TraceIfWatching(
"stk_classic::mesh::BulkData::change_entity_parts", LOG_ENTITY, entity.key());
626 DiagIfWatching(LOG_ENTITY, entity.key(),
"entity state: " << entity);
630 require_ok_to_modify();
632 require_entity_owner( entity , m_parallel_rank );
634 const EntityRank
entity_rank = entity.entity_rank();
635 const EntityRank undef_rank = InvalidEntityRank;
643 const unsigned expected_min_num_supersets = 2;
645 OrdinalVector a_parts;
646 a_parts.reserve( std::distance(begin_add_parts, end_add_parts) * (expected_min_num_supersets + 1) );
647 for(AddIterator add_iter=begin_add_parts; add_iter!=end_add_parts; ++add_iter) {
648 a_parts.push_back((*add_iter)->mesh_meta_data_ordinal());
650 bool quick_verify_check =
true;
652 for ( AddIterator ia = begin_add_parts; ia != end_add_parts ; ++ia ) {
653 quick_verify_check = quick_verify_check &&
654 internal_quick_verify_change_part(*ia,
entity_rank, undef_rank);
655 const PartVector& supersets = (*ia)->supersets();
656 for(PartVector::const_iterator s_iter=supersets.begin(), s_end=supersets.end();
657 s_iter!=s_end; ++s_iter) {
658 a_parts.push_back((*s_iter)->mesh_meta_data_ordinal());
664 OrdinalVector::const_iterator a_parts_begin = a_parts.begin(),
665 a_parts_end = a_parts.end();
666 OrdinalVector r_parts ;
668 for ( RemoveIterator ir = begin_remove_parts; ir != end_remove_parts ; ++ir ) {
684 quick_verify_check = quick_verify_check &&
685 internal_quick_verify_change_part(*ir,
entity_rank, undef_rank);
687 if ( ! contains_ordinal( a_parts_begin, a_parts_end , (*ir)->mesh_meta_data_ordinal() ) ) {
688 r_parts.push_back( (*ir)->mesh_meta_data_ordinal() );
689 for ( PartVector::const_iterator cur_part = (*ir)->subsets().begin() ;
690 cur_part != (*ir)->subsets().end() ;
692 if ( entity.bucket().member ( **cur_part ) )
693 r_parts.push_back ( (*cur_part)->mesh_meta_data_ordinal() );
702 if ( ! quick_verify_check ) {
703 internal_verify_change_parts( m_mesh_meta_data , entity , a_parts );
704 internal_verify_change_parts( m_mesh_meta_data , entity , r_parts );
705 ThrowRequireMsg(
false,
"Expected throw from verify methods above.");
709 internal_verify_change_parts( m_mesh_meta_data , entity , a_parts );
710 internal_verify_change_parts( m_mesh_meta_data , entity , r_parts );
714 internal_change_entity_parts( entity , a_parts , r_parts , always_propagate_internal_changes );
725 #endif // stk_mesh_BulkData_hpp void declare_relation(Entity &e_from, Entity &e_to, const RelationIdentifier local_id)
Declare a relation and its converse between entities in the same mesh.
unsigned bucket_ordinal() const
The ordinal for this entity within its bucket.
PairIterEntityComm entity_comm(const EntityKey &key) const
Entity Comm functions that are now moved to BulkData These functions are only here for backwards comp...
Ghosting & create_ghosting(const std::string &name)
Asymmetric parallel relations for owner-to-ghosted mesh entities.
const std::vector< Entity * > & entity_comm() const
All entities with communication information.
Data for ghosting mesh entities.
bool destroy_relation(Entity &e_from, Entity &e_to, const RelationIdentifier local_id)
Remove all relations between two entities.
Bucket & bucket() const
The bucket which holds this mesh entity's field data.
void order(PartVector &v)
Order a collection of parts: invoke sort and then unique.
BulkData(MetaData &mesh_meta_data, ParallelMachine parallel, unsigned bucket_max_size=1000, bool use_memory_pool=true)
Construct mesh bulk data manager conformal to the given meta data manager and will distribute bulk da...
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
void change_ghosting(Ghosting &ghosts, const std::vector< EntityProc > &add_send, const std::vector< Entity *> &remove_receive)
Change the members of a ghosting list on the sending processor.
Ghosting & shared_aura() const
Query the shared-entity aura. Is likely to be stale if ownership or sharing has changed and the 'modi...
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
Integer type for the entity keys, which is an encoding of the entity type and entity identifier...
void copy_entity_fields(const Entity &src, Entity &dest)
Copy field data from src entity to Dest entity.
BulkDataSyncState synchronized_state() const
Bulk data has two states: guaranteed to be parallel synchronized or modification in progress and may ...
void change_entity_parts(Entity &entity, const PartVector &add_parts, const PartVector &remove_parts=PartVector())
Change the parallel-locally-owned entity's part membership by adding and/or removing parts...
void destroy_all_ghosting()
Empty every single Ghosting. Same result, but more efficient than, calling change_ghosting to remove ...
ParallelMachine parallel() const
The parallel machine.
Entity * get_entity(const EntityKey key) const
Get entity with a given key.
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
unsigned parallel_size() const
Size of the parallel machine.
bool modification_begin()
Begin a modification phase during which the mesh bulk data could become parallel inconsistent. This is a parallel synchronous call. The first time this method is called the mesh meta data is verified to be committed and parallel consistent. An exception is thrown if this verification fails.
size_t synchronized_count() const
Count of the number of times that the bulk data has been parallel synchronized. This count gets updat...
Manager for an integrated collection of entities, entity relations, and buckets of field data...
EntityId entity_id(const EntityKey &key)
Given an entity key, return the identifier for the entity.
const MetaData & mesh_meta_data() const
The meta data manager for this bulk data manager.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
void change_entity_owner(const std::vector< EntityProc > &arg_change)
Give away ownership of entities to other parallel processes.
const std::vector< Ghosting * > & ghostings() const
Query all ghostings.
unsigned parallel_rank() const
Rank of the parallel machine's local processor.
Entity & declare_entity(EntityRank ent_rank, EntityId ent_id, const PartVector &parts)
Create or retrieve a locally owned entity of a given rank and id.
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...
void generate_new_entities(const std::vector< size_t > &requests, std::vector< Entity *> &requested_entities)
Generate a set of entites with globally unique id's.
A container for the field data of a homogeneous collection of entities.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).
bool destroy_entity(Entity *&entity)
Request the destruction an entity on the local process.
void update_field_data_states() const
Rotate the field data of multistate fields.