16 #include <stk_util/environment/ReportHandler.hpp>
17 #include <stk_util/parallel/ParallelReduce.hpp>
19 #include <stk_mesh/base/BulkData.hpp>
20 #include <stk_mesh/base/MetaData.hpp>
21 #include <stk_mesh/base/GetEntities.hpp>
22 #include <stk_mesh/base/FieldData.hpp>
23 #include <stk_mesh/fem/FEMMetaData.hpp>
33 bool balance_comm_spec_domain(
Partition * partition,
34 mesh::EntityProcVec & rebal_spec )
36 bool rebalancingHasOccurred =
false;
48 return rebalancingHasOccurred;
59 void rebalance_dependent_entities(
const mesh::BulkData & bulk_data ,
61 const mesh::EntityRank & dep_rank,
62 mesh::EntityProcVec & entity_procs,
63 const stk::mesh::EntityRank rank)
67 const stk::mesh::EntityRank element_rank = (rank != stk::mesh::InvalidEntityRank) ? rank :
70 if (dep_rank == element_rank)
return;
72 std::map<mesh::EntityId, unsigned> elem_procs;
73 mesh::EntityVector owned_moving_elems;
74 mesh::EntityProcVec::iterator ep_iter = entity_procs.begin(),
75 ep_end = entity_procs.end();
76 for( ; ep_end != ep_iter; ++ep_iter ) {
77 if( element_rank == ep_iter->first->entity_rank() )
79 const mesh::EntityId elem_id = ep_iter->first->identifier();
80 elem_procs[elem_id] = ep_iter->second;
81 owned_moving_elems.push_back(ep_iter->first);
92 std::map<mesh::EntityId, unsigned> dep_entity_procs;
93 mesh::EntityVector::reverse_iterator r_iter = owned_moving_elems.rbegin(),
94 r_end = owned_moving_elems.rend();
95 for( ; r_end != r_iter; ++r_iter )
97 const mesh::EntityId elem_id = (*r_iter)->identifier();
98 mesh::EntityVector related_entities;
99 mesh::EntityVector elems(1);
102 for(
size_t j = 0; j < related_entities.size(); ++j ) {
103 dep_entity_procs[related_entities[j]->identifier()] = elem_procs[elem_id];
108 std::map<mesh::EntityId, unsigned>::const_iterator c_iter = dep_entity_procs.begin(),
109 c_end = dep_entity_procs.end();
110 for( ; c_end != c_iter; ++c_iter )
116 entity_procs.push_back(dep_proc);
124 const stk::mesh::EntityRank rank)
126 mesh::EntityProcVec cs_elem;
127 bool rebalancingHasOccurred = balance_comm_spec_domain( partition, cs_elem );
133 const stk::mesh::EntityRank node_rank = fem_meta.
node_rank();
134 const stk::mesh::EntityRank edge_rank = fem_meta.
edge_rank();
135 const stk::mesh::EntityRank face_rank = fem_meta.
face_rank();
136 const stk::mesh::EntityRank elem_rank = fem_meta.
element_rank();
137 const stk::mesh::EntityRank cons_rank = elem_rank+1;
140 rebalance_dependent_entities( bulk_data, partition, node_rank, cs_elem, rank );
141 if (stk::mesh::InvalidEntityRank != edge_rank && rank != edge_rank)
142 rebalance_dependent_entities( bulk_data, partition, edge_rank, cs_elem, rank );
143 if (stk::mesh::InvalidEntityRank != face_rank && rank != face_rank)
144 rebalance_dependent_entities( bulk_data, partition, face_rank, cs_elem, rank );
145 if (stk::mesh::InvalidEntityRank != elem_rank && rank != elem_rank)
146 rebalance_dependent_entities( bulk_data, partition, elem_rank, cs_elem, rank );
147 if (stk::mesh::InvalidEntityRank != cons_rank && rank != cons_rank)
148 rebalance_dependent_entities( bulk_data, partition, cons_rank, cs_elem, rank );
151 if ( rebalancingHasOccurred )
159 return rebalancingHasOccurred;
169 const stk::mesh::EntityRank rank)
172 const stk::mesh::EntityRank element_rank = (rank != stk::mesh::InvalidEntityRank) ? rank :
175 mesh::EntityVector rebal_elem_ptrs;
176 mesh::EntityVector entities;
179 bulk_data.
buckets(element_rank),
182 for (mesh::EntityVector::iterator iA = entities.begin() ; iA != entities.end() ; ++iA ) {
183 if(rebal_elem_weight_ref)
186 ThrowRequireMsg( NULL != w,
187 "Rebalance weight field is not defined on entities but should be defined on all entities.");
193 rebal_elem_ptrs.push_back( *iA );
196 (&partition)->set_mesh_info(
199 rebal_elem_weight_ref);
201 bool rebalancingHasOccurred = full_rebalance(bulk_data, &partition, rank);
203 return rebalancingHasOccurred;
Initialized with a list of mesh entities unique to each processor.
This is a class for selecting buckets based on a set of meshparts and set logic.
void get_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets, std::vector< Entity * > &entities)
Get entities in selected buckets (selected by the given selector instance), and sorted by ID...
Field with defined data type and multi-dimensions (if any)
virtual void determine_new_partition(bool &RebalancingNeeded)=0
determine New Partition.
virtual int get_new_partition(stk::mesh::EntityProcVec &new_partition)=0
Perform communication to create new partition.
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.
void change_entity_owner(const std::vector< EntityProc > &arg_change)
Give away ownership of entities to other parallel processes.
bool rebalance(mesh::BulkData &bulk_data, const mesh::Selector &selector, const VectorField *coord_ref, const ScalarField *elem_weight_ref, Partition &partition, const stk::mesh::EntityRank rank=stk::mesh::InvalidEntityRank)
Rebalance with a Partition object.
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
virtual bool partition_dependents_needed() const =0
Query whether element dependents need to be rebalanced outside this Partition.
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
virtual unsigned num_elems() const =0
Return the total number of mesh entities in all lists.
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
ParallelMachine parallel() const
Return the parallel communicator for this partition entity.
std::pair< Entity *, unsigned > EntityProc
Pairing of an entity with a processor rank.
Manager for an integrated collection of entities, entity relations, and buckets of field data...
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
void get_entities_through_relations(const std::vector< Entity * > &entities, std::vector< Entity * > &entities_related)
Query which mesh entities have a relation to all of the input mesh entities.
void all_reduce_sum(ParallelMachine comm, const double *local, double *global, unsigned count)
Parallel summation to all processors.
For partitioning of mesh entities over a processing grid.
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
Static functions for dynamic load balancing.
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.