9 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 11 #include <stk_mesh/fixtures/RingFixture.hpp> 13 #include <stk_mesh/base/MetaData.hpp> 14 #include <stk_mesh/base/BulkData.hpp> 15 #include <stk_mesh/base/GetEntities.hpp> 17 #include <unit_tests/UnitTestModificationEndWrapper.hpp> 29 const stk_classic::mesh::EntityRank NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
31 STKUNIT_UNIT_TEST( UnitTestBoxFixture, verifyRingFixture )
42 BulkData& bulk = fixture.m_bulk_data;
44 const stk_classic::mesh::EntityRank element_rank = meta.
element_rank();
50 const unsigned nPerProc = fixture.m_num_edge_per_proc ;
51 const unsigned id_total = nPerProc * p_size ;
52 const unsigned id_begin = nPerProc * p_rank ;
53 const unsigned id_end = nPerProc * ( p_rank + 1 );
54 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 );
55 const unsigned nLocalEdge = nPerProc ;
56 const unsigned n_extra = 1 < p_size ? 2 : 0 ;
59 fixture.generate_mesh();
66 std::vector<unsigned> local_count;
68 STKUNIT_ASSERT_EQUAL( local_count[NODE_RANK] , nLocalNode );
69 STKUNIT_ASSERT_EQUAL( local_count[element_rank] , nLocalEdge );
71 std::vector<Entity*> all_nodes;
74 unsigned num_selected_nodes =
76 STKUNIT_ASSERT_EQUAL( num_selected_nodes , local_count[NODE_RANK] );
78 std::vector<Entity*> universal_nodes;
81 STKUNIT_ASSERT_EQUAL( universal_nodes.size() , all_nodes.size() );
88 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
89 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
92 const unsigned n0 = id_end < id_total ? id_begin : 0 ;
93 const unsigned n1 = id_end < id_total ? id_end : id_begin ;
95 Entity *
const node0 = bulk.
get_entity( NODE_RANK , fixture.m_node_ids[n0] );
96 Entity *
const node1 = bulk.
get_entity( NODE_RANK , fixture.m_node_ids[n1] );
98 STKUNIT_ASSERT( node0 != NULL );
99 STKUNIT_ASSERT( node1 != NULL );
101 STKUNIT_ASSERT_EQUAL( node0->
sharing().size() , size_t(1) );
102 STKUNIT_ASSERT_EQUAL( node1->
sharing().size() , size_t(1) );
107 std::vector<EntityProc> change ;
114 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
115 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
118 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode + n_extra );
119 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge + n_extra );
122 fixture.fixup_node_ownership();
128 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode + n_extra );
129 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge + n_extra );
132 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
133 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
136 STKUNIT_ASSERT_EQUAL( local_count[0] , nPerProc );
137 STKUNIT_ASSERT_EQUAL( local_count[1] , nPerProc );
144 namespace unit_test {
146 void test_shift_ring(
RingFixture& ring,
bool generate_aura=
true )
153 const unsigned nPerProc = ring.m_num_edge_per_proc ;
154 const unsigned id_total = nPerProc * p_size ;
155 const unsigned id_begin = nPerProc * p_rank ;
156 const unsigned id_end = nPerProc * ( p_rank + 1 );
157 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 );
158 const unsigned nLocalEdge = nPerProc ;
160 const unsigned p_send = ( p_rank + 1 ) % p_size ;
161 const unsigned id_send = id_end - 2 ;
162 const unsigned id_recv = ( id_begin + id_total - 2 ) % id_total ;
167 std::vector<unsigned> local_count ;
168 std::vector<EntityProc> change ;
171 Entity * send_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_send + 1 ] );
175 Entity * recv_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_recv + 1 ] );
177 STKUNIT_ASSERT( NULL != send_edge_1 && p_rank == send_edge_1->
owner_rank() );
178 STKUNIT_ASSERT( NULL != send_edge_2 && p_rank == send_edge_2->
owner_rank() );
179 STKUNIT_ASSERT( NULL == recv_edge_1 || p_rank != recv_edge_1->
owner_rank() );
180 STKUNIT_ASSERT( NULL == recv_edge_2 || p_rank != recv_edge_2->
owner_rank() );
184 change.push_back( entry );
188 change.push_back( entry );
192 change.push_back( entry );
196 change.push_back( entry );
208 STKUNIT_ASSERT( stk_classic::unit_test::modification_end_wrapper( bulk , generate_aura ) );
210 send_edge_1 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_send ] );
211 send_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_send + 1 ] );
212 recv_edge_1 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_recv ] );
213 recv_edge_2 = bulk.
get_entity( 1 , ring.m_edge_ids[ id_recv + 1 ] );
215 STKUNIT_ASSERT( NULL == send_edge_1 || p_rank != send_edge_1->
owner_rank() );
216 STKUNIT_ASSERT( NULL == send_edge_2 || p_rank != send_edge_2->
owner_rank() );
217 STKUNIT_ASSERT( NULL != recv_edge_1 && p_rank == recv_edge_1->
owner_rank() );
218 STKUNIT_ASSERT( NULL != recv_edge_2 && p_rank == recv_edge_2->
owner_rank() );
221 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
222 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
224 unsigned count_shared = 0 ;
225 for ( std::vector<Entity*>::const_iterator
228 if ( in_shared( **i ) ) { ++count_shared ; }
230 STKUNIT_ASSERT_EQUAL( count_shared , 2u );
233 Entity *
const node_recv = bulk.
get_entity( NODE_RANK , ring.m_node_ids[id_recv] );
234 Entity *
const node_send = bulk.
get_entity( NODE_RANK , ring.m_node_ids[id_send] );
236 STKUNIT_ASSERT_EQUAL( node_recv->
sharing().size() , 1u );
237 STKUNIT_ASSERT_EQUAL( node_send->
sharing().size() , 1u );
PairIterEntityComm sharing() const
Parallel processes which share this entity.
const std::vector< Entity * > & entity_comm() const
All entities with communication information.
unsigned count_selected_entities(const Selector &selector, const std::vector< Bucket * > &input_buckets)
Count entities in selected buckets (selected by the given selector instance), and sorted by ID...
This is a class for selecting buckets based on a set of meshparts and set logic.
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
Entity * get_entity(EntityRank entity_rank, EntityId entity_id) const
Get entity with a given key.
std::pair< Entity *, unsigned > EntityProc
Pairing of an entity with a processor rank.
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...
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.
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
void get_entities(const BulkData &mesh, EntityRank entity_rank, std::vector< Entity *> &entities)
Get all entities of the specified type, sorted by ID.
Manager for an integrated collection of entities, entity relations, and buckets of field data...
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
void count_entities(const Selector &selector, const BulkData &mesh, std::vector< EntityRank > &count)
Local count selected entities of each type.
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's local processor.
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.