Sierra Toolkit  Version of the Day
RingFixture.cpp
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 #include <stk_mesh/fixtures/RingFixture.hpp>
10 
11 #include <stk_util/parallel/Parallel.hpp>
12 
13 #include <stk_util/environment/ReportHandler.hpp>
14 
15 #include <stk_mesh/base/Types.hpp>
16 #include <stk_mesh/base/MetaData.hpp>
17 #include <stk_mesh/base/BulkData.hpp>
18 #include <stk_mesh/base/MetaData.hpp>
19 #include <stk_mesh/base/Entity.hpp>
20 #include <stk_mesh/base/EntityComm.hpp>
21 #include <stk_mesh/base/GetEntities.hpp>
22 
23 #include <Shards_BasicTopologies.hpp>
24 
25 namespace stk_classic {
26 namespace mesh {
27 namespace fixtures {
28 
35 RingFixture::RingFixture( stk_classic::ParallelMachine pm ,
36  unsigned num_edge_per_proc ,
37  bool use_edge_parts )
38  : m_spatial_dimension(1),
39  m_meta_data( m_spatial_dimension ),
40  m_bulk_data( fem::FEMMetaData::get_meta_data(m_meta_data), pm, 100 ),
41  m_edge_parts(),
42  m_edge_part_extra( m_meta_data.declare_part("edge_extra" , m_meta_data.element_rank() ) ),
43  m_num_edge_per_proc( num_edge_per_proc ),
44  m_node_ids(),
45  m_edge_ids()
46 {
47  if ( use_edge_parts ) {
48  m_edge_parts.resize( num_edge_per_proc );
49  for ( unsigned i = 0 ; i < num_edge_per_proc ; ++i ) {
50  std::ostringstream name ;
51  name << "EdgePart_" << i ;
52  m_edge_parts[i] = & m_meta_data.declare_part( name.str() , m_meta_data.element_rank() );
53  }
54  }
55 }
56 
58 {
59  const unsigned p_rank = m_bulk_data.parallel_rank();
60  const unsigned p_size = m_bulk_data.parallel_size();
61  const unsigned nPerProc = m_num_edge_per_proc ;
62  const unsigned id_total = nPerProc * p_size ;
63  const unsigned id_begin = nPerProc * p_rank ;
64  const unsigned id_end = nPerProc * ( p_rank + 1 );
65 
66  m_node_ids.resize( id_total );
67  m_edge_ids.resize( id_total );
68  std::vector<unsigned> local_count ;
69 
70  for ( unsigned i = 0 ; i < id_total ; ++i ) {
71  m_node_ids[i] = i + 1;
72  m_edge_ids[i] = i + 1;
73  }
74 
75  // Create a loop of edges:
76  {
77  const PartVector no_parts ;
78  PartVector add_parts ;
79 
80  if ( ! m_edge_parts.empty() ) { add_parts.resize(1); }
81 
82  for ( unsigned i = id_begin ; i < id_end ; ++i ) {
83  const unsigned n0 = i ;
84  const unsigned n1 = ( i + 1 ) % id_total ;
85  if ( ! m_edge_parts.empty() ) {
86  add_parts[0] = m_edge_parts[ i % m_edge_parts.size() ];
87  }
88  Entity & e_node_0 = m_bulk_data.declare_entity( 0 , m_node_ids[n0] , no_parts );
89  Entity & e_node_1 = m_bulk_data.declare_entity( 0 , m_node_ids[n1] , no_parts );
90  Entity & e_edge = m_bulk_data.declare_entity( 1 , m_edge_ids[i] , add_parts );
91  m_bulk_data.declare_relation( e_edge , e_node_0 , 0 );
92  m_bulk_data.declare_relation( e_edge , e_node_1 , 1 );
93  }
94  }
95 }
96 
98 {
99  const unsigned p_rank = m_bulk_data.parallel_rank();
100  const unsigned p_size = m_bulk_data.parallel_size();
101  const unsigned nPerProc = m_num_edge_per_proc ;
102  const unsigned id_begin = nPerProc * p_rank ;
103 
104  // Make sure that edge->owner_rank() == edge->node[1]->owner_rank()
105 
106  if ( 1 < p_size ) {
107  std::vector<EntityProc> change ;
108  Entity * const e_node_0 = m_bulk_data.get_entity( 0 , m_node_ids[id_begin] );
109  if ( p_rank == e_node_0->owner_rank() ) {
110  EntityProc entry ;
111  entry.first = e_node_0 ;
112  entry.second = ( p_rank + p_size - 1 ) % p_size ;
113  change.push_back( entry );
114  }
115  m_bulk_data.change_entity_owner( change );
116  }
117 }
118 
119 }
120 }
121 }
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.
EntityRank element_rank() const
Returns the element rank which is always equal to spatial dimension.
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
Definition: BulkData.hpp:211
std::pair< Entity *, unsigned > EntityProc
Pairing of an entity with a processor rank.
Definition: Types.hpp:111
Part & declare_part(const std::string &name, fem::CellTopology cell_topology)
Declare a part with a given cell topology.
unsigned parallel_size() const
Size of the parallel machine.
Definition: BulkData.hpp:82
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
Part & declare_part(FEMMetaData &meta_data, const std::string &name)
Declare a part with a given cell topology. This is just a convenient function that wraps FEMMetaData&#39;...
Definition: FEMHelpers.hpp:93
Sierra Toolkit.
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32
void change_entity_owner(const std::vector< EntityProc > &arg_change)
Give away ownership of entities to other parallel processes.
unsigned parallel_rank() const
Rank of the parallel machine&#39;s local processor.
Definition: BulkData.hpp:85
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.
Definition: BulkData.cpp:215
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.
Definition: Entity.hpp:175