14 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 16 #include <stk_util/parallel/Parallel.hpp> 18 #include <stk_mesh/base/BulkData.hpp> 19 #include <stk_mesh/base/GetEntities.hpp> 20 #include <stk_mesh/base/EntityComm.hpp> 21 #include <stk_mesh/base/Comm.hpp> 23 #include <stk_mesh/fixtures/BoxFixture.hpp> 24 #include <stk_mesh/fixtures/RingFixture.hpp> 26 #include <unit_tests/UnitTestModificationEndWrapper.hpp> 27 #include <unit_tests/UnitTestRingFixture.hpp> 35 using stk_classic::mesh::BaseEntityRank;
39 using stk_classic::mesh::EntityId;
41 using stk_classic::mesh::EntityVector;
42 using stk_classic::mesh::EntityRank;
48 const EntityRank NODE_RANK = FEMMetaData::NODE_RANK;
50 void donate_one_element(
BulkData & mesh ,
bool aura )
54 Selector select_owned( MetaData::get(mesh).locally_owned_part() );
56 std::vector<unsigned> before_count ;
57 std::vector<unsigned> after_count ;
64 std::vector<EntityProc> change ;
70 for ( std::vector<Entity*>::const_iterator
73 if ( in_shared( **i ) && (**i).entity_rank() == BaseEntityRank ) {
79 STKUNIT_ASSERT( node != NULL );
81 for ( PairIterRelation rel = node->
relations( 3 );
82 ! rel.empty() && elem == NULL ; ++rel ) {
84 if ( elem->
owner_rank() != p_rank ) { elem = NULL ; }
87 STKUNIT_ASSERT( elem != NULL );
89 unsigned donated_nodes = 0 ;
95 entry.second = node->
sharing()[0].proc ;
96 change.push_back( entry );
97 for ( PairIterRelation
98 rel = elem->
relations(0) ; ! rel.empty() ; ++rel ) {
99 if ( rel->entity()->owner_rank() == p_rank ) {
100 entry.first = rel->entity();
101 change.push_back( entry );
109 STKUNIT_ASSERT( stk_classic::unit_test::modification_end_wrapper( mesh , aura ) );
114 STKUNIT_ASSERT_EQUAL( before_count[3] - 1 , after_count[3] );
115 STKUNIT_ASSERT_EQUAL( before_count[0] - donated_nodes, after_count[0] );
119 void donate_all_shared_nodes(
BulkData & mesh ,
bool aura )
123 const Selector select_used = MetaData::get(mesh).locally_owned_part() |
124 MetaData::get(mesh).globally_shared_part() ;
126 std::vector<unsigned> before_count ;
127 std::vector<unsigned> after_count ;
133 const std::vector<Entity*> & entity_comm = mesh.
entity_comm();
135 STKUNIT_ASSERT( ! entity_comm.empty() );
137 std::vector<EntityProc> change ;
139 for ( std::vector<Entity*>::const_iterator
140 i = entity_comm.begin() ;
141 i != entity_comm.end() &&
142 (**i).entity_rank() == BaseEntityRank ; ++i ) {
143 Entity *
const node = *i ;
146 if ( node->
owner_rank() == p_rank && ! ec.empty() ) {
147 change.push_back(
EntityProc( node , ec->proc ) );
153 STKUNIT_ASSERT( stk_classic::unit_test::modification_end_wrapper( mesh , aura ) );
157 STKUNIT_ASSERT( 3 <= after_count.size() );
158 STKUNIT_ASSERT_EQUAL( before_count[0] , after_count[0] );
159 STKUNIT_ASSERT_EQUAL( before_count[1] , after_count[1] );
160 STKUNIT_ASSERT_EQUAL( before_count[2] , after_count[2] );
161 STKUNIT_ASSERT_EQUAL( before_count[3] , after_count[3] );
166 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testBulkData)
173 std::vector<std::string> entity_names(10);
174 for (
size_t i = 0 ; i < 10 ; ++i ) {
175 std::ostringstream name ;
176 name <<
"EntityRank" << i ;
177 entity_names[i] = name.str();
186 for (
size_t i = 0 ; i < 4 ; ++i ) {
187 STKUNIT_ASSERT( bulk.modification_begin() );
188 STKUNIT_ASSERT_EQUAL( i , bulk.synchronized_count() );
189 STKUNIT_ASSERT( bulk.modification_end() );
192 std::vector<Part*> no_parts ;
196 const unsigned id = bulk.parallel_rank() + 1 ;
198 STKUNIT_ASSERT( bulk.modification_begin() );
199 for (
size_t i = 0 ; i < 10 ; ++i ) {
200 e[i] = & bulk.declare_entity( i ,
id , no_parts );
202 STKUNIT_ASSERT( bulk.modification_end() );
204 for (
size_t i = 0 ; i < 10 ; ++i ) {
205 STKUNIT_ASSERT( e[i] == bulk.get_entity( i ,
id ) );
208 STKUNIT_ASSERT( bulk.modification_begin() );
209 STKUNIT_ASSERT_THROW( bulk.declare_entity( 11 ,
id , no_parts ),
211 STKUNIT_ASSERT( bulk.modification_end() );
214 STKUNIT_ASSERT_THROW( bulk.declare_entity( 0 ,
id + 1 , no_parts ),
221 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeOwner_nodes)
226 enum { nPerProc = 10 };
229 const unsigned id_total = nPerProc * p_size ;
230 const unsigned id_begin = nPerProc * p_rank ;
231 const unsigned id_end = nPerProc * ( p_rank + 1 );
233 const int spatial_dimension = 3;
234 MetaData meta( stk_classic::mesh::fem::entity_rank_names(spatial_dimension) );
240 bulk.modification_begin();
244 std::vector<EntityId> ids( id_total );
246 for (
unsigned i = 0 ; i < id_total ; ++i ) {
252 for (
unsigned i = id_begin ; i < id_end ; ++i ) {
253 bulk.declare_entity( 0 , ids[i] , no_parts );
256 STKUNIT_ASSERT( bulk.modification_end() );
260 for (
unsigned i = 0 ; i < id_total ; ++i ) {
261 Entity * e = bulk.get_entity( 0 , ids[ i ] );
262 if ( id_begin <= i && i < id_end ) {
263 STKUNIT_ASSERT( NULL != e );
266 STKUNIT_ASSERT( NULL == e );
272 std::vector<EntityProc> change ;
274 STKUNIT_ASSERT( bulk.modification_begin() );
275 bulk.change_entity_owner( change );
276 STKUNIT_ASSERT( bulk.modification_end() );
278 for (
unsigned i = 0 ; i < id_total ; ++i ) {
279 Entity * e = bulk.get_entity( 0 , ids[ i ] );
280 if ( id_begin <= i && i < id_end ) {
281 STKUNIT_ASSERT( NULL != e );
284 STKUNIT_ASSERT( NULL == e );
294 const unsigned p_give = ( p_rank + 1 ) % p_size ;
295 const unsigned id_give = id_end - 2 ;
296 const unsigned id_get = ( id_begin + id_total - 2 ) % id_total ;
298 STKUNIT_ASSERT( NULL != bulk.get_entity( 0 , ids[id_give] ) );
299 STKUNIT_ASSERT( NULL != bulk.get_entity( 0 , ids[id_give+1] ) );
300 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[id_get] ) );
301 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[id_get+1] ) );
304 change[0].first = bulk.get_entity( 0 , ids[id_give] );
305 change[0].second = p_give ;
306 change[1].first = bulk.get_entity( 0 , ids[id_give+1] );
307 change[1].second = p_give ;
309 STKUNIT_ASSERT( bulk.modification_begin() );
310 bulk.change_entity_owner( change );
311 STKUNIT_ASSERT( bulk.modification_end() );
313 STKUNIT_ASSERT( NULL != bulk.get_entity( 0 , ids[id_get] ) );
314 STKUNIT_ASSERT( NULL != bulk.get_entity( 0 , ids[id_get+1] ) );
318 Entity *
const e0 = bulk.get_entity( 0 , ids[id_give] );
319 Entity *
const e1 = bulk.get_entity( 0 , ids[id_give+1] );
324 STKUNIT_ASSERT( bulk.modification_begin() );
325 STKUNIT_ASSERT( bulk.modification_end() );
327 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[id_give] ) );
328 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[id_give+1] ) );
335 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testCreateMore)
340 enum { nPerProc = 10 };
347 const unsigned id_total = nPerProc * p_size ;
348 const unsigned id_begin = nPerProc * p_rank ;
349 const unsigned id_end = nPerProc * ( p_rank + 1 );
351 const int spatial_dimension = 3;
352 MetaData meta( stk_classic::mesh::fem::entity_rank_names(spatial_dimension) );
360 bulk.modification_begin();
364 std::vector<EntityId> ids( id_total );
366 for (
unsigned i = 0 ; i < id_total ; ++i ) { ids[i] = i + 1; }
370 for (
unsigned i = id_begin ; i < id_end ; ++i ) {
371 bulk.declare_entity( 0 , ids[i] , no_parts );
374 STKUNIT_ASSERT( bulk.modification_end() );
378 const unsigned id_get = ( id_begin + id_total - 2 ) % id_total ;
380 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[id_get] ) );
381 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[id_get+1] ) );
383 STKUNIT_ASSERT( bulk.modification_begin() );
390 Entity & e0 = bulk.declare_entity( 0 , ids[ id_get ] , no_parts );
391 Entity & e1 = bulk.declare_entity( 0 , ids[ id_get + 1 ] , no_parts );
393 Entity & eU = bulk.declare_entity( 1 , 1 , no_parts );
395 bulk.declare_relation( eU , e0 , 0 );
396 bulk.declare_relation( eU , e1 , 1 );
399 bulk.modification_end();
402 Entity * e0 = bulk.get_entity( 0 , ids[id_get] );
403 Entity * e1 = bulk.get_entity( 0 , ids[id_get+1] );
404 STKUNIT_ASSERT( NULL != e0 );
405 STKUNIT_ASSERT( NULL != e1 );
412 bulk.modification_begin();
415 bulk.declare_entity( 0 , ids[ id_get ] , no_parts );
416 bulk.declare_entity( 0 , ids[ id_get + 1 ] , no_parts );
419 STKUNIT_ASSERT_THROW( bulk.modification_end() , std::runtime_error );
426 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeOwner_ring)
431 enum { nPerProc = 10 };
434 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 );
435 const unsigned nLocalEdge = nPerProc ;
437 std::vector<unsigned> local_count ;
443 BulkData & bulk = ring_mesh.m_bulk_data;
444 ring_mesh.m_meta_data.commit();
447 ring_mesh.generate_mesh( );
448 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(bulk, aura));
451 ring_mesh.fixup_node_ownership( );
452 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(bulk, aura));
454 const Selector select_used = ring_mesh.m_meta_data.locally_owned_part() |
455 ring_mesh.m_meta_data.globally_shared_part() ;
456 const Selector select_all = ring_mesh.m_meta_data.universal_part() ;
458 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
459 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
460 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
462 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
463 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
464 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
469 stk_classic::unit_test::test_shift_ring( ring_mesh,
false );
471 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
472 STKUNIT_ASSERT( local_count[0] == nLocalNode );
473 STKUNIT_ASSERT( local_count[1] == nLocalEdge );
475 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
476 STKUNIT_ASSERT( local_count[0] == nLocalNode );
477 STKUNIT_ASSERT( local_count[1] == nLocalEdge );
485 BulkData& bulk = ring_mesh.m_bulk_data;
486 ring_mesh.m_meta_data.commit();
489 ring_mesh.generate_mesh( );
493 ring_mesh.fixup_node_ownership( );
496 const Selector select_owned( ring_mesh.m_meta_data.locally_owned_part() );
497 const Selector select_used = ring_mesh.m_meta_data.locally_owned_part() |
498 ring_mesh.m_meta_data.globally_shared_part() ;
499 const Selector select_all( ring_mesh.m_meta_data.universal_part() );
501 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
502 STKUNIT_ASSERT_EQUAL( local_count[0] , nLocalNode );
503 STKUNIT_ASSERT_EQUAL( local_count[1] , nLocalEdge );
505 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
506 const unsigned n_extra = 1 < p_size ? 2 : 0 ;
507 STKUNIT_ASSERT( local_count[0] == nLocalNode + n_extra );
508 STKUNIT_ASSERT( local_count[1] == nLocalEdge + n_extra );
511 stk_classic::unit_test::test_shift_ring( ring_mesh,
false );
513 count_entities( select_owned , ring_mesh.m_bulk_data , local_count );
514 STKUNIT_ASSERT( local_count[0] == nPerProc );
515 STKUNIT_ASSERT( local_count[1] == nPerProc );
517 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
518 STKUNIT_ASSERT( local_count[0] == nLocalNode );
519 STKUNIT_ASSERT( local_count[1] == nLocalEdge );
522 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
523 STKUNIT_ASSERT_EQUAL( nLocalEdge , local_count[1] );
524 STKUNIT_ASSERT_EQUAL( nLocalNode , local_count[0] );
531 BulkData& bulk = ring_mesh.m_bulk_data;
532 ring_mesh.m_meta_data.commit();
535 ring_mesh.generate_mesh( );
539 ring_mesh.fixup_node_ownership( );
542 const Selector select_owned( ring_mesh.m_meta_data.locally_owned_part() );
543 const Selector select_used = ring_mesh.m_meta_data.locally_owned_part() |
544 ring_mesh.m_meta_data.globally_shared_part() ;
545 const Selector select_all( ring_mesh.m_meta_data.universal_part() );
547 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
548 STKUNIT_ASSERT( local_count[0] == nLocalNode );
549 STKUNIT_ASSERT( local_count[1] == nLocalEdge );
551 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
552 const unsigned n_extra = 1 < p_size ? 2 : 0 ;
553 STKUNIT_ASSERT( local_count[0] == nLocalNode + n_extra );
554 STKUNIT_ASSERT( local_count[1] == nLocalEdge + n_extra );
557 stk_classic::unit_test::test_shift_ring( ring_mesh,
true );
559 count_entities( select_owned , ring_mesh.m_bulk_data , local_count );
560 STKUNIT_ASSERT( local_count[0] == nPerProc );
561 STKUNIT_ASSERT( local_count[1] == nPerProc );
563 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
564 STKUNIT_ASSERT( local_count[0] == nLocalNode );
565 STKUNIT_ASSERT( local_count[1] == nLocalEdge );
568 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
569 STKUNIT_ASSERT( local_count[0] == nLocalNode + n_extra );
570 STKUNIT_ASSERT( local_count[1] == nLocalEdge + n_extra );
577 BulkData& bulk = ring_mesh.m_bulk_data;
578 ring_mesh.m_meta_data.commit();
581 ring_mesh.generate_mesh( );
585 ring_mesh.fixup_node_ownership( );
588 std::vector<EntityProc> change ;
593 change[0].first = ring_mesh.m_bulk_data.get_entity( 0 , ring_mesh.m_node_ids[1] );
594 change[0].second = p_size ;
596 for ( std::vector<Entity*>::const_iterator
597 ec = ring_mesh.m_bulk_data.entity_comm().begin() ;
598 ec != ring_mesh.m_bulk_data.entity_comm().end() ; ++ec ) {
599 if ( in_receive_ghost( **ec ) ) {
600 change[1].first = *ec ;
604 change[1].second = p_rank ;
606 change[2].first = ring_mesh.m_bulk_data.get_entity( 0 , ring_mesh.m_node_ids[1] );
607 change[2].second = ( p_rank + 1 ) % p_size ;
608 change[3].first = change[2].first ;
609 change[3].second = ( p_rank + 2 ) % p_size ;
612 STKUNIT_ASSERT( ring_mesh.m_bulk_data.modification_begin() );
614 STKUNIT_ASSERT_THROW( ring_mesh.m_bulk_data.change_entity_owner( change ),
615 std::runtime_error );
622 BulkData& bulk = ring_mesh.m_bulk_data;
623 ring_mesh.m_meta_data.commit();
626 ring_mesh.generate_mesh( );
630 ring_mesh.fixup_node_ownership( );
633 const Selector select_owned( ring_mesh.m_meta_data.locally_owned_part() );
634 const Selector select_used = ring_mesh.m_meta_data.locally_owned_part() |
635 ring_mesh.m_meta_data.globally_shared_part() ;
636 const Selector select_all( ring_mesh.m_meta_data.universal_part() );
638 std::vector<EntityProc> change ;
640 if ( p_rank + 1 == p_size ) {
642 entry.first = ring_mesh.m_bulk_data.get_entity( 0 , ring_mesh.m_node_ids[0] );
644 STKUNIT_ASSERT_EQUAL( p_rank , entry.first->owner_rank() );
645 change.push_back( entry );
648 STKUNIT_ASSERT( ring_mesh.m_bulk_data.modification_begin() );
649 ring_mesh.m_bulk_data.change_entity_owner( change );
650 STKUNIT_ASSERT( stk_classic::unit_test::modification_end_wrapper( ring_mesh.m_bulk_data ,
false ) );
652 count_entities( select_owned , ring_mesh.m_bulk_data , local_count );
653 const unsigned n_node = p_rank == 0 ? nPerProc + 1 : (
654 p_rank + 1 == p_size ? nPerProc - 1 :
657 STKUNIT_ASSERT_EQUAL( n_node , local_count[0] );
658 STKUNIT_ASSERT_EQUAL( (
unsigned) nPerProc , local_count[1] );
660 count_entities( select_used , ring_mesh.m_bulk_data , local_count );
661 STKUNIT_ASSERT_EQUAL( nLocalNode , local_count[0] );
662 STKUNIT_ASSERT_EQUAL( nLocalEdge , local_count[1] );
665 count_entities( select_all , ring_mesh.m_bulk_data , local_count );
666 const unsigned n_extra = p_rank + 1 == p_size || p_rank == 0 ? 1 : 2 ;
667 STKUNIT_ASSERT_EQUAL( nLocalNode + n_extra , local_count[0] );
668 STKUNIT_ASSERT_EQUAL( nLocalEdge + n_extra , local_count[1] );
676 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeOwner_box)
681 const int root_box[3][2] = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } };
685 const int spatial_dimension = 3;
686 MetaData meta( stk_classic::mesh::fem::entity_rank_names(spatial_dimension) );
694 fixture.fem_meta().commit();
695 BulkData & bulk = fixture.bulk_data();
696 int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } };
699 fixture.generate_boxes( root_box, local_box );
700 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(bulk, aura));
703 donate_one_element( bulk , aura );
710 fixture.fem_meta().commit();
711 BulkData & bulk = fixture.bulk_data();
712 int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } };
715 fixture.generate_boxes( root_box, local_box );
716 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(bulk, aura));
718 donate_all_shared_nodes( bulk , aura );
724 fixture.fem_meta().commit();
725 BulkData & bulk = fixture.bulk_data();
726 int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } };
729 fixture.generate_boxes( root_box, local_box );
730 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(bulk, aura));
732 donate_one_element( bulk ,
false );
738 BulkData & bulk = fixture.bulk_data();
741 int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } };
744 fixture.generate_boxes( root_box, local_box );
747 std::vector<unsigned> used_count ;
748 std::vector<unsigned> all_count ;
758 STKUNIT_ASSERT( used_count[0] < all_count[0] );
759 STKUNIT_ASSERT( used_count[3] < all_count[3] );
761 donate_all_shared_nodes( bulk ,
false );
766 STKUNIT_ASSERT_EQUAL( used_count[0] , all_count[0] );
767 STKUNIT_ASSERT_EQUAL( used_count[3] , all_count[3] );
771 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testModifyPropagation)
782 const unsigned nPerProc = 2;
786 if (p_size > 1)
return;
791 ring_mesh.m_meta_data.declare_part(
"special_node_part", stk_classic::mesh::BaseEntityRank );
792 ring_mesh.m_meta_data.commit();
793 BulkData& bulk = ring_mesh.m_bulk_data;
796 ring_mesh.generate_mesh( );
800 ring_mesh.fixup_node_ownership( );
805 const stk_classic::mesh::EntityRank element_rank = ring_mesh.m_meta_data.element_rank();
810 PairIterRelation node_relations = edge.
relations( stk_classic::mesh::BaseEntityRank );
811 STKUNIT_ASSERT( !node_relations.empty() );
813 STKUNIT_ASSERT_EQUAL( node.entity_rank(), (unsigned) stk_classic::mesh::BaseEntityRank );
816 ring_mesh.m_bulk_data.modification_begin();
818 parts.push_back( &special_part );
819 ring_mesh.m_bulk_data.change_entity_parts( node, parts );
822 STKUNIT_ASSERT_EQUAL ( node.log_query(), stk_classic::mesh::EntityLogModified );
823 STKUNIT_ASSERT_EQUAL ( edge.
log_query(), stk_classic::mesh::EntityLogModified );
825 STKUNIT_ASSERT ( ring_mesh.m_bulk_data.modification_end() );
828 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeEntityOwnerFromSelfToSelf)
844 const unsigned spatial_dim = 2;
847 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
860 const unsigned nodes_per_elem = 4, nodes_per_side = 2;
867 const EntityRank elem_rank = meta_data.element_rank();
873 const unsigned starting_node_id = p_rank * nodes_per_side + 1;
874 for (
unsigned id = starting_node_id;
id < starting_node_id + nodes_per_elem; ++id) {
882 for (EntityVector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr, ++rel_id) {
891 std::vector<EntityProc> change ;
898 change.push_back( entry );
902 change.push_back( entry );
906 Entity* shared_node = nodes[p_rank == 0 ? nodes_per_side : 0];
907 EntityId expected_id = 3;
908 Part& shared_part = meta_data.globally_shared_part();
910 STKUNIT_ASSERT_EQUAL(shared_node->
identifier(), expected_id);
913 change.push_back( entry );
922 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeEntityOwnerOfShared)
940 const unsigned spatial_dim = 2;
943 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
946 const EntityRank edge_rank = meta_data.edge_rank();
947 const EntityRank elem_rank = meta_data.element_rank();
957 const unsigned nodes_per_elem = 4, nodes_per_side = 2;
958 EntityKey elem_key_chg_own(elem_rank, p_size - 1 );
959 EntityKey edge_key_chg_own(edge_rank, 1 );
970 if (p_rank == p_size - 2) {
971 STKUNIT_ASSERT(elem_key_chg_own == elem.
key());
976 const unsigned starting_node_id = p_rank * nodes_per_side + 1;
977 for (
unsigned id = starting_node_id;
id < starting_node_id + nodes_per_elem; ++id) {
985 for (EntityVector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr, ++rel_id) {
991 if (p_rank >= p_size - 2) {
995 STKUNIT_ASSERT(edge.
key() == edge_key_chg_own);
1001 unsigned start_idx = p_rank == p_size - 1 ? 0 : nodes_per_side;
1002 unsigned end_idx = start_idx + nodes_per_side;
1004 for (
unsigned idx = start_idx ;
1005 start_idx < end_idx;
1006 ++start_idx, ++rel_id) {
1020 STKUNIT_ASSERT(changing_elem != NULL);
1021 STKUNIT_ASSERT(changing_edge != NULL);
1024 Part& owned = meta_data.locally_owned_part();
1025 Part& shared = meta_data.globally_shared_part();
1026 STKUNIT_ASSERT(!(changing_elem->
bucket().
member(owned) ||
1028 STKUNIT_ASSERT(!(changing_edge->
bucket().
member(owned) ||
1033 STKUNIT_ASSERT(changing_elem == NULL);
1034 STKUNIT_ASSERT(changing_edge == NULL);
1040 std::vector<EntityProc> change ;
1041 if (p_rank >= p_size - 2) {
1046 if (p_rank == p_size - 2) {
1048 change.push_back(eproc);
1051 for (PairIterRelation i = changing_elem->
relations() ; !i.empty() ; ++i) {
1052 if (i->entity()->owner_rank() == p_rank) {
1054 change.push_back(eproc);
1068 STKUNIT_ASSERT(changing_elem != NULL);
1069 STKUNIT_ASSERT(changing_edge != NULL);
1072 Part& owned = meta_data.locally_owned_part();
1073 STKUNIT_ASSERT( changing_elem->
bucket().
member(owned) );
1074 STKUNIT_ASSERT( changing_edge->
bucket().
member(owned) );
1078 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testFamilyTreeGhosting)
1097 const unsigned spatial_dim = 2;
1099 std::vector<std::string> entity_rank_names = stk_classic::mesh::fem::entity_rank_names(spatial_dim);
1100 entity_rank_names.push_back(
"FAMILY_TREE");
1102 FEMMetaData meta_data(spatial_dim, entity_rank_names);
1104 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
1108 Part& owned = meta_data.locally_owned_part();
1109 Part& shared = meta_data.globally_shared_part();
1118 const unsigned nodes_per_elem = 4, nodes_per_side = 2;
1119 const EntityRank family_tree_rank = meta_data.element_rank() + 1;
1120 const EntityId my_family_tree_id = p_rank+1;
1126 const EntityRank elem_rank = meta_data.element_rank();
1132 const unsigned starting_node_id = p_rank * nodes_per_side + 1;
1133 for (
unsigned id = starting_node_id;
id < starting_node_id + nodes_per_elem; ++id) {
1140 unsigned rel_id = 0;
1141 for (EntityVector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr, ++rel_id) {
1150 unsigned downward_ordinal = 0;
1160 std::vector<EntityId> family_tree_ghost_ids;
1162 family_tree_ghost_ids.push_back(my_family_tree_id - 1);
1164 if (p_rank < p_size - 1) {
1165 family_tree_ghost_ids.push_back(my_family_tree_id + 1);
1169 Entity *my_family_tree = mesh.
get_entity(family_tree_rank, my_family_tree_id);
1170 STKUNIT_ASSERT(my_family_tree);
1171 STKUNIT_ASSERT( (p_rank) == my_family_tree->
owner_rank());
1174 for (std::vector<EntityId>::const_iterator
1175 itr = family_tree_ghost_ids.begin(); itr != family_tree_ghost_ids.end(); ++itr) {
1176 EntityId expected_ghosted_family_tree_id = *itr;
1178 Entity *expected_ghosted_family_tree = mesh.
get_entity(family_tree_rank, expected_ghosted_family_tree_id);
1179 STKUNIT_ASSERT(expected_ghosted_family_tree);
1180 STKUNIT_ASSERT(expected_ghosted_family_tree_id - 1 == expected_ghosted_family_tree->
owner_rank());
1183 STKUNIT_ASSERT(!bucket.member(owned) && !bucket.member(shared));
1187 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, test_other_ghosting)
1200 const unsigned spatial_dim = 2;
1202 std::vector<std::string> entity_rank_names = stk_classic::mesh::fem::entity_rank_names(spatial_dim);
1205 FEMMetaData meta_data(spatial_dim, entity_rank_names);
1207 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
1211 if (p_size != 3)
return;
1223 const unsigned nodes_per_elem = 4, nodes_per_side = 2;
1229 const EntityRank elem_rank = meta_data.element_rank();
1235 const unsigned starting_node_id = p_rank * nodes_per_side + 1;
1236 for (
unsigned id = starting_node_id;
id < starting_node_id + nodes_per_elem; ++id) {
1240 std::cout <<
"P[" << p_rank <<
"] node id= " <<
id << std::endl;
1244 unsigned rel_id = 0;
1245 for (EntityVector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr, ++rel_id) {
1249 if (1 && p_rank == 2)
1266 std::cout <<
"P[" << p_rank <<
"] node " << node <<
" own= " << node->
owner_rank() << std::endl;
1269 PairIterRelation rels = node->
relations();
1270 for (
unsigned i = 0; i < rels.size(); i++)
1272 std::cout <<
"P[" << p_rank <<
"] rel = " << rels[i].entity()->owner_rank() << std::endl;
1290 if (1 || p_rank == 2)
1297 PairIterRelation rels = node->
relations();
1298 for (
unsigned i = 0; i < rels.size(); i++)
1300 std::cout <<
"P[" << p_rank <<
"] node " << node <<
" own= " << node->
owner_rank() <<
" rel = " << rels[i].entity()->owner_rank() << std::endl;
1313 std::vector<EntityId> family_tree_ghost_ids;
1315 family_tree_ghost_ids.push_back(my_family_tree_id - 1);
1317 if (p_rank < p_size - 1) {
1318 family_tree_ghost_ids.push_back(my_family_tree_id + 1);
1322 Entity *my_family_tree = mesh.
get_entity(family_tree_rank, my_family_tree_id);
1323 STKUNIT_ASSERT(my_family_tree);
1324 STKUNIT_ASSERT( (p_rank) == my_family_tree->
owner_rank());
1327 for (std::vector<EntityId>::const_iterator
1328 itr = family_tree_ghost_ids.begin(); itr != family_tree_ghost_ids.end(); ++itr) {
1329 EntityId expected_ghosted_family_tree_id = *itr;
1331 Entity *expected_ghosted_family_tree = mesh.
get_entity(family_tree_rank, expected_ghosted_family_tree_id);
1332 STKUNIT_ASSERT(expected_ghosted_family_tree);
1333 STKUNIT_ASSERT(expected_ghosted_family_tree_id - 1 == expected_ghosted_family_tree->
owner_rank());
1336 STKUNIT_ASSERT(!bucket.member(owned) && !bucket.member(shared));
1341 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeEntityPartsOfShared)
1359 const unsigned spatial_dim = 2;
1361 const EntityRank node_rank = meta_data.node_rank();
1362 const EntityRank elem_rank = meta_data.element_rank();
1367 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
1380 const unsigned nodes_per_elem = 4, nodes_per_side = 2;
1381 EntityKey node_key_to_move(node_rank, 3 );
1393 const unsigned starting_node_id = p_rank * nodes_per_side + 1;
1394 for (
unsigned id = starting_node_id;
id < starting_node_id + nodes_per_elem; ++id) {
1401 unsigned rel_id = 0;
1402 for (EntityVector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr, ++rel_id) {
1416 STKUNIT_EXPECT_FALSE(changing_node.
sharing().empty());
1420 STKUNIT_EXPECT_FALSE(changing_node.
bucket().
member(extra_node_part));
1433 STKUNIT_EXPECT_TRUE(changing_node.
bucket().
member(extra_node_part));
1444 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, test_final_modification_end)
1448 const unsigned spatial_dim = 2;
1452 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
1455 mesh.final_modification_end();
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.
bool has_superset(const Bucket &bucket, const unsigned &ordinal)
Is this bucket a subset of the given part by partID.
PairIterEntityComm sharing() const
Parallel processes which share this entity.
const std::vector< Entity * > & entity_comm() const
All entities with communication information.
Bucket & bucket() const
The bucket which holds this mesh entity's field data.
This is a class for selecting buckets based on a set of meshparts and set logic.
const EntityKey & key() const
The globally unique key ( entity type + identifier ) of this entity.
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...
std::pair< Entity *, unsigned > EntityProc
Pairing of an entity with a processor rank.
EntityModificationLog log_query() const
Query the current state of the entity log.
An application-defined subset of a problem domain.
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
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...
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.
unsigned parallel_machine_size(ParallelMachine parallel_machine)
Member function parallel_machine_size ...
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.
size_t capacity() const
Capacity of this bucket.
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.
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
A container for the field data of a homogeneous collection of entities.
bool destroy_entity(Entity *&entity)
Request the destruction an entity on the local process.
bool member(const Part &) const
Bucket is a subset of the given part.
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.