12 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
14 #include <stk_util/parallel/Parallel.hpp>
16 #include <stk_mesh/base/BulkData.hpp>
17 #include <stk_mesh/base/GetEntities.hpp>
18 #include <stk_mesh/base/Comm.hpp>
20 #include <stk_mesh/fixtures/RingFixture.hpp>
22 #include <unit_tests/UnitTestModificationEndWrapper.hpp>
35 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeParts)
50 const unsigned spatial_dimension = 10;
51 std::vector<std::string> entity_names(spatial_dimension+1);
52 for (
size_t i = 0 ; i <= spatial_dimension ; ++i ) {
53 std::ostringstream name ;
54 name <<
"EntityRank_" << i ;
55 entity_names[i] = name.str();
60 FEMMetaData meta( spatial_dimension, entity_names );
61 BulkData bulk( FEMMetaData::get_meta_data(meta) , pm , 100 );
63 Part & part_univ = meta.universal_part();
64 Part & part_owns = meta.locally_owned_part();
65 Part & part_shared = meta.globally_shared_part();
67 Part & part_A_0 = meta.declare_part(std::string(
"A_0"), 0 );
68 Part & part_A_1 = meta.declare_part(std::string(
"A_1"), 1 );
69 Part & part_A_2 = meta.declare_part(std::string(
"A_2"), 2 );
70 Part & part_A_3 = meta.declare_part(std::string(
"A_3"), 3 );
72 Part & part_B_0 = meta.declare_part(std::string(
"B_0"), 0 );
73 Part & part_B_2 = meta.declare_part(std::string(
"B_2"), 2 );
76 bulk.modification_begin();
86 Entity& closure_entity = bulk.declare_entity(4 ,
91 Entity& entity_0_1 = bulk.declare_entity(0 , 1 , tmp);
92 bulk.declare_relation( closure_entity , entity_0_1 , 0 );
95 Entity& entity_1_1 = bulk.declare_entity(1 , 1 , tmp);
96 bulk.declare_relation( closure_entity , entity_1_1 , 1 );
99 Entity& entity_2_1 = bulk.declare_entity(2 , 1 , tmp);
100 bulk.declare_relation( closure_entity , entity_2_1 , 2 );
102 tmp[0] = & part_A_3 ;
103 Entity& entity_3_1 = bulk.declare_entity(3 , 1 , tmp);
104 bulk.declare_relation( closure_entity , entity_3_1 , 3 );
110 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
111 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
112 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
116 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
117 STKUNIT_ASSERT( entity_1_1.
bucket().
member(part_univ) );
118 STKUNIT_ASSERT( entity_1_1.
bucket().
member(part_owns) );
122 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
123 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_univ) );
124 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_owns) );
128 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
129 STKUNIT_ASSERT( entity_3_1.
bucket().
member(part_univ) );
130 STKUNIT_ASSERT( entity_3_1.
bucket().
member(part_owns) );
136 tmp[0] = & part_A_0 ;
137 bulk.change_entity_parts( entity_0_1 , tmp );
139 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
140 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
141 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
148 tmp[0] = & part_B_0 ;
149 bulk.change_entity_parts( entity_0_1 , tmp );
151 STKUNIT_ASSERT_EQUAL(
size_t(4) , tmp.size() );
152 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
153 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
161 tmp[0] = & part_B_0 ;
162 bulk.change_entity_parts( entity_0_1 ,
PartVector() , tmp );
164 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
165 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
166 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
174 stk::mesh::RelationIdentifier test_rel_id = 0;
176 bulk.declare_relation( entity_1_1 , entity_0_1 , test_rel_id );
178 STKUNIT_ASSERT_EQUAL(
size_t(4) , tmp.size() );
179 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
180 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
189 bulk.destroy_relation( entity_1_1 , entity_0_1, test_rel_id );
191 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
192 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
193 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
200 tmp[0] = & part_B_2 ;
201 bulk.change_entity_parts( entity_2_1 , tmp );
203 STKUNIT_ASSERT_EQUAL(
size_t(4) , tmp.size() );
204 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_univ) );
205 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_owns) );
216 bulk.declare_relation( entity_2_1 , entity_0_1 , test_rel_id );
218 STKUNIT_ASSERT_EQUAL(
size_t(5) , tmp.size() );
219 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
220 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
230 bulk.destroy_relation( entity_2_1 , entity_0_1, test_rel_id );
232 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
233 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
234 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
238 bulk.modification_end();
245 bool parallel = p_size > 1;
253 STKUNIT_ASSERT_EQUAL(
size_t(parallel ? 4 : 3) , tmp.size() );
254 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
255 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
257 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_shared) );
261 STKUNIT_ASSERT( parallel );
262 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
263 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
264 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_shared) );
270 STKUNIT_ASSERT_EQUAL(
size_t(parallel ? 5 : 4) , tmp.size() );
271 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_univ) );
272 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_owns) );
274 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_shared) );
279 STKUNIT_ASSERT_EQUAL(
size_t(4) , tmp.size() );
280 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_univ) );
281 STKUNIT_ASSERT( entity_2_1.
bucket().
member(part_shared) );
288 STKUNIT_ASSERT_EQUAL(
size_t(p_size - 1) , entity_0_1.
sharing().size() );
289 STKUNIT_ASSERT_EQUAL(
size_t(p_size - 1) , entity_1_1.
sharing().size() );
290 STKUNIT_ASSERT_EQUAL(
size_t(p_size - 1) , entity_2_1.
sharing().size() );
291 STKUNIT_ASSERT_EQUAL(
size_t(p_size - 1) , entity_3_1.
sharing().size() );
294 bulk.modification_begin();
298 int ok_to_modify = entity_0_1.
owner_rank() == p_rank ;
302 tmp[0] = & part_B_0 ;
303 bulk.change_entity_parts( entity_0_1 , tmp );
304 STKUNIT_ASSERT( ok_to_modify );
306 catch(
const std::exception & x ) {
307 STKUNIT_ASSERT( ! ok_to_modify );
315 STKUNIT_ASSERT_EQUAL(
size_t(parallel ? 5 : 4) , tmp.size() );
316 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
317 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
319 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_shared) );
324 STKUNIT_ASSERT_EQUAL(
size_t(3) , tmp.size() );
325 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
326 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_shared) );
330 bulk.modification_end();
337 STKUNIT_ASSERT_EQUAL(
size_t(parallel ? 5 : 4) , tmp.size() );
338 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
339 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_owns) );
341 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_shared) );
346 STKUNIT_ASSERT_EQUAL(
size_t(4) , tmp.size() );
347 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_univ) );
348 STKUNIT_ASSERT( entity_0_1.
bucket().
member(part_shared) );
357 STKUNIT_UNIT_TEST(UnitTestingOfBulkData, testChangeParts_ringmesh)
367 const unsigned nPerProc = 10;
370 const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 );
371 const unsigned nLocalEdge = nPerProc ;
376 ring_mesh.m_meta_data.commit();
377 BulkData& bulk = ring_mesh.m_bulk_data;
380 ring_mesh.generate_mesh( );
381 STKUNIT_ASSERT(stk::unit_test::modification_end_wrapper(bulk,
385 ring_mesh.fixup_node_ownership();
386 STKUNIT_ASSERT(stk::unit_test::modification_end_wrapper(bulk,
389 Part & part_owns = ring_mesh.m_meta_data.locally_owned_part();
390 Part & part_univ = ring_mesh.m_meta_data.universal_part();
394 for (
unsigned i = 0 ; i < nLocalEdge ; ++i ) {
395 const unsigned n = i + nPerProc * p_rank ;
397 ring_mesh.m_edge_ids[n] );
398 STKUNIT_ASSERT( edge != NULL );
401 STKUNIT_ASSERT( edge->
bucket().
member( * ring_mesh.m_edge_parts[ n % ring_mesh.m_edge_parts.size() ] ) );
407 for (
unsigned i = 0 ; i < nLocalNode ; ++i ) {
408 const unsigned n = ( i + nPerProc * p_rank ) % ring_mesh.m_node_ids.size();
409 const unsigned e0 = n ;
410 const unsigned e1 = ( n + ring_mesh.m_edge_ids.size() - 1 ) % ring_mesh.m_edge_ids.size();
411 const unsigned ns = ring_mesh.m_edge_parts.size();
412 const unsigned n0 = e0 % ns ;
413 const unsigned n1 = e1 % ns ;
414 Part *
const epart_0 = ring_mesh.m_edge_parts[ n0 < n1 ? n0 : n1 ];
415 Part *
const epart_1 = ring_mesh.m_edge_parts[ n0 < n1 ? n1 : n0 ];
418 STKUNIT_ASSERT( node != NULL );
438 for (
unsigned i = 0 ; i < nLocalEdge ; ++i ) {
439 const unsigned n = i + nPerProc * p_rank ;
441 PartVector add(1); add[0] = & ring_mesh.m_edge_part_extra ;
442 PartVector rem(1); rem[0] = ring_mesh.m_edge_parts[ n % ring_mesh.m_edge_parts.size() ];
448 STKUNIT_ASSERT( edge->
bucket().
member(ring_mesh.m_edge_part_extra ) );
456 for (
unsigned i = 0 ; i < nLocalNode ; ++i ) {
457 const unsigned n = ( i + nPerProc * p_rank ) % ring_mesh.m_node_ids.size();
458 const unsigned e0 = n ;
459 const unsigned e1 = ( n + ring_mesh.m_edge_ids.size() - 1 ) % ring_mesh.m_edge_ids.size();
460 const unsigned ns = ring_mesh.m_edge_parts.size();
461 const unsigned n0 = e0 % ns ;
462 const unsigned n1 = e1 % ns ;
463 Part * ep_0 = e0 < nLocalEdge ? & ring_mesh.m_edge_part_extra : ring_mesh.m_edge_parts[n0] ;
464 Part * ep_1 = e1 < nLocalEdge ? & ring_mesh.m_edge_part_extra : ring_mesh.m_edge_parts[n1] ;
470 STKUNIT_ASSERT( node != NULL );
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...
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.
bool member(const Part &) const
Bucket is a subset of the given part.
unsigned mesh_meta_data_ordinal() const
Internally generated ordinal of this part that is unique within the owning meta data manager...
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 ...
void supersets(PartVector &) const
This bucket is a subset of these parts.
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...
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.