9 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 11 #include <stk_util/parallel/Parallel.hpp> 13 #include <stk_mesh/base/BulkData.hpp> 14 #include <stk_mesh/base/GetEntities.hpp> 15 #include <stk_mesh/base/Comm.hpp> 17 #include <stk_mesh/fixtures/RingFixture.hpp> 19 #include <unit_tests/UnitTestModificationEndWrapper.hpp> 27 using stk::mesh::EntityId;
33 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testDestroy_nodes)
38 enum { nPerProc = 10 };
41 const unsigned id_total = nPerProc * p_size ;
42 const unsigned id_begin = nPerProc * p_rank ;
43 const unsigned id_end = nPerProc * ( p_rank + 1 );
45 const int spatial_dimension = 3;
46 MetaData meta( stk::mesh::fem::entity_rank_names(spatial_dimension) );
56 std::vector<EntityId> ids( id_total );
58 for (
unsigned i = 0 ; i < id_total ; ++i ) {
64 STKUNIT_ASSERT( bulk.modification_begin() );
65 for (
unsigned i = id_begin ; i < id_end ; ++i ) {
66 bulk.declare_entity( 0 , ids[i] , no_parts );
68 STKUNIT_ASSERT( bulk.modification_end() );
72 for (
unsigned i = 0 ; i < id_total ; ++i ) {
73 Entity * e = bulk.get_entity( 0 , ids[ i ] );
74 if ( id_begin <= i && i < id_end ) {
75 STKUNIT_ASSERT( NULL != e );
79 STKUNIT_ASSERT( NULL == e );
85 for (
unsigned i = id_begin ; i < id_end ; ++i ) {
86 Entity * e = bulk.get_entity( 0 , ids[ i ] );
88 STKUNIT_ASSERT( NULL != e );
90 bulk.modification_begin();
91 STKUNIT_ASSERT( bulk.destroy_entity( e ) );
92 bulk.modification_end();
99 STKUNIT_ASSERT( NULL == bulk.get_entity( 0 , ids[ i - 1 ] ) );
102 e = bulk.get_entity( 0 , ids[ i ] );
103 STKUNIT_ASSERT( NULL != e );
104 STKUNIT_ASSERT( 0 == e->bucket().capacity() );
110 void assert_is_destroyed(
const Entity *
const entity )
112 STKUNIT_ASSERT( entity == NULL || entity->
bucket().
capacity() == 0 );
115 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testDestory_ring)
120 enum { nPerProc = 10 };
124 const unsigned nLocalEdge = nPerProc ;
126 const int spatial_dimension = 3;
127 MetaData meta( stk::mesh::fem::entity_rank_names(spatial_dimension) );
131 Selector select_owned( meta.locally_owned_part() );
132 Selector select_used = meta.locally_owned_part() | meta.globally_shared_part();
133 Selector select_all( meta.universal_part() );
137 std::vector<unsigned> local_count ;
141 const bool aura_flag = false ;
144 mesh.m_meta_data.commit();
148 mesh.generate_mesh( );
149 STKUNIT_ASSERT(stk::unit_test::modification_end_wrapper(bulk,
153 mesh.fixup_node_ownership();
154 STKUNIT_ASSERT(stk::unit_test::modification_end_wrapper(bulk,
159 Entity * edge = bulk.
get_entity( 1 , mesh.m_edge_ids[ nLocalEdge * p_rank ] );
163 const size_t node0_edges = node0->
relations().size();
164 const size_t node1_edges = node1->
relations().size();
166 STKUNIT_ASSERT( 1 <= node0_edges && node0_edges <= 2 );
167 STKUNIT_ASSERT( 1 <= node1_edges && node1_edges <= 2 );
169 STKUNIT_ASSERT( node0->
relations()[0].entity() == edge ||
170 node0->
relations()[1].entity() == edge );
172 STKUNIT_ASSERT( node1->
relations()[0].entity() == edge ||
173 node1->
relations()[1].entity() == edge );
179 STKUNIT_ASSERT(
true == result );
180 STKUNIT_ASSERT( NULL == edge );
185 STKUNIT_ASSERT( NULL == node0 );
189 STKUNIT_ASSERT( NULL == node1 );
191 STKUNIT_ASSERT( stk::unit_test::modification_end_wrapper(bulk, aura_flag) );
193 if ( NULL != node0 ) {
194 STKUNIT_ASSERT_EQUAL( node0_edges - 1 , node0->
relations().size() );
196 if ( NULL != node1 ) {
197 STKUNIT_ASSERT_EQUAL( node1_edges - 1 , node1->
relations().size() );
203 mesh.m_meta_data.commit();
207 mesh.generate_mesh( );
211 mesh.fixup_node_ownership();
214 const unsigned nNotOwned = nPerProc * p_rank ;
219 STKUNIT_ASSERT( node != NULL );
220 STKUNIT_ASSERT_NE( p_rank , node->
owner_rank() );
221 STKUNIT_ASSERT_EQUAL(
size_t(1) , node->
sharing().size() );
222 STKUNIT_ASSERT_EQUAL(
size_t(2) , node->
relations().size() );
224 EntityId node_edge_ids[2] ;
225 node_edge_ids[0] = node->
relations()[0].entity()->identifier();
226 node_edge_ids[1] = node->
relations()[1].entity()->identifier();
242 assert_is_destroyed( bulk.
get_entity(0, mesh.m_node_ids[nNotOwned] ) );
243 assert_is_destroyed( bulk.
get_entity(1, node_edge_ids[0] ) );
244 assert_is_destroyed( bulk.
get_entity(1, node_edge_ids[1] ) );
252 mesh.m_meta_data.commit();
256 mesh.generate_mesh( );
260 mesh.fixup_node_ownership();
264 const unsigned nOwned = ( nPerProc * ( p_rank + 1 ) ) % mesh.m_node_ids.size();
265 const unsigned nNotOwned = nPerProc * p_rank ;
268 Entity * node_not_owned = bulk.
get_entity( 0 , mesh.m_node_ids[ nNotOwned ] );
270 STKUNIT_ASSERT( node_owned != NULL );
271 STKUNIT_ASSERT( node_not_owned != NULL );
272 STKUNIT_ASSERT_NE( p_rank , node_not_owned->
owner_rank() );
273 STKUNIT_ASSERT_EQUAL( p_rank , node_owned->
owner_rank() );
274 STKUNIT_ASSERT_EQUAL(
size_t(1) , node_owned->
sharing().size() );
275 STKUNIT_ASSERT_EQUAL(
size_t(1) , node_not_owned->
sharing().size() );
276 STKUNIT_ASSERT_EQUAL(
size_t(2) , node_owned->
relations().size() );
278 EntityId node_edge_ids[2] ;
279 node_edge_ids[0] = node_owned->
relations()[0].entity()->identifier();
280 node_edge_ids[1] = node_owned->
relations()[1].entity()->identifier();
288 while ( node_owned->
relations().size() ) {
299 STKUNIT_ASSERT_EQUAL( p_rank , node_not_owned->
owner_rank() );
300 assert_is_destroyed( bulk.
get_entity(0, mesh.m_node_ids[ nOwned ] ) );
301 assert_is_destroyed( bulk.
get_entity(1, node_edge_ids[0] ) );
302 assert_is_destroyed( bulk.
get_entity(1, node_edge_ids[1] ) );
std::vector< Part * > PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
This is a class for selecting buckets based on a set of meshparts and set logic.
const std::vector< Entity * > & entity_comm() const
All entities with communication information.
size_t capacity() const
Capacity of this bucket.
unsigned owner_rank() const
Parallel processor rank of the processor which owns this entity.
unsigned parallel_machine_size(ParallelMachine parallel_machine)
Member function parallel_machine_size ...
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...
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
Bucket & bucket() const
The bucket which holds this mesh entity's field data.
PairIterEntityComm sharing() const
Parallel processes which share this entity.
An application-defined subset of a problem domain.
Manager for an integrated collection of entities, entity relations, and buckets of field data...
PairIterRelation relations() const
All Entity relations for which this entity is a member. The relations are ordered from lowest entity-...
bool destroy_entity(Entity *&entity)
Request the destruction an entity on the local process.
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.