Sierra Toolkit  Version of the Day
SetOwners.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #ifndef stk_mesh_SetOwners_hpp
10 #define stk_mesh_SetOwners_hpp
11 
12 #include <set>
13 #include <map>
14 
15 #include <stk_mesh/base/BulkData.hpp>
16 
17 namespace stk_classic {
18 namespace mesh {
19 
20 typedef std::less<unsigned> LowestRankSharingProcOwns;
21 typedef std::greater<unsigned> HighestRankSharingProcOwns;
22 
27 template<class OwnershipRule>
28 void set_owners(BulkData& mesh_bulk_data)
29 {
30  typedef std::set<unsigned,OwnershipRule> ProcSet ;
31 
32  const unsigned local_proc = mesh_bulk_data.parallel_rank();
33 
34  std::vector<EntityProc> entity_new_owners;
35 
36  const std::vector<Entity*>& entity_comm = mesh_bulk_data.entity_comm();
37 
38  for ( size_t i=0; i<entity_comm.size(); ++i) {
39  Entity * const entity = entity_comm[i] ;
40 
41  const PairIterEntityComm sharing = entity->sharing();
42 
43  if ( ! sharing.empty() && entity->owner_rank() == local_proc ) {
44  ProcSet proc_set ;
45 
46  proc_set.insert( local_proc );
47 
48  for ( size_t j = 0 ; j < sharing.size() ; ++j ) {
49  proc_set.insert( sharing[j].proc );
50  }
51 
52  const unsigned new_owner_proc = *proc_set.begin();
53 
54  entity_new_owners.push_back(std::make_pair( entity, new_owner_proc ) );
55  }
56  }
57 
58  mesh_bulk_data.modification_begin();
59 
60  mesh_bulk_data.change_entity_owner( entity_new_owners );
61 
62  mesh_bulk_data.modification_end();
63 }
64 
65 }//namespace mesh
66 }//namespace stk_classic
67 
68 #endif // stk_mesh_SetOwner_hpp
69 
PairIterEntityComm sharing() const
Parallel processes which share this entity.
Definition: Entity.hpp:178
Sierra Toolkit.
PairIter< std::vector< EntityCommInfo >::const_iterator > PairIterEntityComm
Span of ( communication-subset-ordinal , process-rank ) pairs for the communication of an entity...
Definition: Types.hpp:128
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.
Definition: Entity.hpp:175