13 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 15 #include <stk_util/parallel/Parallel.hpp> 17 #include <stk_mesh/base/BulkData.hpp> 18 #include <stk_mesh/base/GetEntities.hpp> 19 #include <stk_mesh/base/Field.hpp> 20 #include <stk_mesh/base/FieldData.hpp> 21 #include <stk_mesh/base/Comm.hpp> 22 #include <stk_mesh/base/EntityComm.hpp> 23 #include <stk_mesh/base/Ghosting.hpp> 25 #include <stk_mesh/fem/FEMMetaData.hpp> 27 #include <stk_mesh/fixtures/BoxFixture.hpp> 28 #include <stk_mesh/fixtures/RingFixture.hpp> 30 #include <unit_tests/UnitTestModificationEndWrapper.hpp> 32 #include <Shards_BasicTopologies.hpp> 35 using stk_classic::mesh::EntityRank;
36 using stk_classic::mesh::EntityVector;
40 using stk_classic::mesh::EntityId;
49 const EntityRank NODE_RANK = FEMMetaData::NODE_RANK;
51 STKUNIT_UNIT_TEST(UnitTestingOfRelation, testRelation)
57 MPI_Barrier ( MPI_COMM_WORLD );
62 std::vector<std::string> entity_names(10);
63 for (
size_t i = 0 ; i < 10 ; ++i ) {
64 std::ostringstream name ;
65 name <<
"EntityRank" << i ;
66 entity_names[i] = name.str();
69 unsigned max_bucket_size = 4;
71 BoxFixture fixture1(pm , max_bucket_size, entity_names),
72 fixture2(pm , max_bucket_size, entity_names);
76 const int spatial_dimension = 3;
79 BulkData& bulk = fixture1.bulk_data();
80 BulkData& bulk2 = fixture2.bulk_data();
106 const int root_box[3][2] = { { 0,4 } , { 0,5 } , { 0,6 } };
107 int local_box1[3][2] = { { 0,0 } , { 0,0 } , { 0,0 } };
108 int local_box2[3][2] = { { 0,0 } , { 0,0 } , { 0,0 } };
112 fixture1.generate_boxes(root_box, local_box1);
119 std::vector<unsigned> procs ;
120 STKUNIT_ASSERT(!nodes.empty());
121 stk_classic::mesh::comm_procs( gg, *nodes.front() , procs );
132 fixture2.generate_boxes(root_box, local_box2);
147 std::vector<Part *> parts;
148 parts.push_back ( &universal );
149 parts.push_back ( &owned );
151 stk_classic::mesh::EntityId new_id = bulk.
parallel_rank() + 1;
157 STKUNIT_ASSERT_THROW ( bulk.
declare_relation ( node , cell , 0 ) , std::runtime_error );
158 STKUNIT_ASSERT_THROW ( bulk.
declare_relation ( cell , node2 , 0 ) , std::runtime_error );
159 STKUNIT_ASSERT_THROW ( bulk.
declare_relation ( cell2 , node , 0 ) , std::runtime_error );
162 STKUNIT_ASSERT_THROW ( bulk.
declare_relation ( edge , nodeb , 1 ) , std::runtime_error );
171 enum { nPerProc = 10 };
175 const unsigned nLocalEdge = nPerProc ;
180 Selector select_owned( meta3.locally_owned_part() );
181 Selector select_used = meta3.locally_owned_part() ;
182 Selector select_all( meta3.universal_part() );
186 std::vector<unsigned> local_count ;
190 bool aura_flag =
false;
192 mesh2.m_meta_data.commit();
194 mesh2.m_bulk_data.modification_begin();
195 mesh2.generate_mesh( );
196 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(mesh2.m_bulk_data,
198 mesh2.m_bulk_data.modification_begin();
199 mesh2.fixup_node_ownership( );
200 STKUNIT_ASSERT(stk_classic::unit_test::modification_end_wrapper(mesh2.m_bulk_data,
206 Entity * edgenew = mesh2.m_bulk_data.get_entity( 1 , mesh2.m_edge_ids[ nLocalEdge * p_rank ] );
208 mesh2.m_bulk_data.modification_begin();
209 for (
unsigned p = 0 ; p < p_size ; ++p )
if ( p != p_rank ) {
210 STKUNIT_ASSERT_EQUAL( in_shared( *edgenew , p ),
false );
211 STKUNIT_ASSERT_EQUAL( in_send_ghost( *edgenew , p ),
false );
214 Entity * edgenew2 = mesh2.m_bulk_data.get_entity( 1 , mesh2.m_edge_ids[ nLocalEdge * p_rank ] );
215 STKUNIT_ASSERT_EQUAL( in_send_ghost( *edgenew2 , p_rank+100 ),
false );
217 Entity * node3 = mesh2.m_bulk_data.get_entity( 0 , mesh2.m_node_ids[ nLocalEdge * p_rank ] );
218 STKUNIT_ASSERT_EQUAL( in_shared( *node3 , p_rank+100 ),
false );
225 mesh3.m_meta_data.commit();
227 mesh3.m_bulk_data.modification_begin();
228 mesh3.generate_mesh();
229 STKUNIT_ASSERT(mesh3.m_bulk_data.modification_end());
231 mesh3.m_bulk_data.modification_begin();
232 mesh3.fixup_node_ownership();
233 STKUNIT_ASSERT(mesh3.m_bulk_data.modification_end());
235 const unsigned nNotOwned = nPerProc * p_rank ;
238 Entity * node3 = mesh3.m_bulk_data.get_entity( 0 , mesh3.m_node_ids[ nNotOwned ] );
239 Entity * node4 = mesh3.m_bulk_data.get_entity( 0 , mesh3.m_node_ids[ nNotOwned ] );
245 mesh3.m_bulk_data.modification_begin();
247 for (
unsigned p = 0 ; p < p_size ; ++p )
if ( p != p_rank ) {
250 STKUNIT_ASSERT_EQUAL( in_send_ghost( *node3 , p ),
false );
254 Entity * node5 = mesh3.m_bulk_data.get_entity( 0 , mesh3.m_node_ids[ nLocalEdge * p_rank ] );
259 STKUNIT_ASSERT_EQUAL( in_shared( *node5 , p_rank+100 ),
false );
260 STKUNIT_ASSERT_EQUAL( in_send_ghost( *node4 , p_rank+100 ),
false );
267 STKUNIT_UNIT_TEST(UnitTestingOfRelation, testDegenerateRelation)
279 MPI_Barrier( MPI_COMM_WORLD );
282 const unsigned spatial_dim = 2;
285 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
286 unsigned p_rank = mesh.parallel_rank();
289 mesh.modification_begin();
295 const EntityRank
entity_rank = meta_data.element_rank();
299 Entity & node = mesh.declare_entity(NODE_RANK, p_rank+1 , empty_parts);
302 const unsigned nodes_per_elem = 4;
303 for (
unsigned i = 0; i < nodes_per_elem; ++i) {
304 mesh.declare_relation( elem, node, i );
308 STKUNIT_ASSERT_EQUAL( nodes_per_elem, elem.
relations().size() );
312 for (
unsigned i = 0; i < nodes_per_elem; ++i) {
313 mesh.destroy_relation( elem, node, i );
314 STKUNIT_ASSERT_EQUAL( nodes_per_elem - (i+1), elem.
relations().size() );
317 mesh.modification_end();
320 STKUNIT_UNIT_TEST(UnitTestingOfRelation, testRelationAttribute)
328 const unsigned spatial_dim = 2;
331 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
332 unsigned p_rank = mesh.parallel_rank();
335 mesh.modification_begin();
341 const EntityRank
entity_rank = meta_data.element_rank();
345 Entity & node = mesh.declare_entity(NODE_RANK, p_rank+1 , empty_parts);
347 mesh.declare_relation( elem, node, 0 );
350 my_relation.set_attribute(6u);
352 STKUNIT_ASSERT_EQUAL( my_relation.attribute(), 6u);
354 mesh.modification_end();
357 STKUNIT_UNIT_TEST(UnitTestingOfRelation, testDoubleDeclareOfRelation)
377 MPI_Barrier( MPI_COMM_WORLD );
380 const unsigned spatial_dim = 2;
383 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);
384 unsigned p_rank = mesh.parallel_rank();
385 unsigned p_size = mesh.parallel_size();
393 mesh.modification_begin();
398 const unsigned nodes_per_elem = 4, nodes_per_side = 2;
405 const EntityRank
entity_rank = meta_data.element_rank();
410 const unsigned starting_node_id = p_rank * nodes_per_side + 1;
411 for (
unsigned id = starting_node_id;
id < starting_node_id + nodes_per_elem; ++id) {
412 nodes.push_back(&mesh.declare_entity(NODE_RANK,
id, empty_parts));
417 for (EntityVector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr, ++rel_id) {
418 mesh.declare_relation( elem, **itr, rel_id );
422 const EntityRank edge_rank = meta_data.side_rank();
423 Entity & edge = mesh.declare_entity(edge_rank, 1 , empty_parts);
427 mesh.declare_relation( *elem_ptr, *edge_ptr, 0 );
430 mesh.modification_end();
432 mesh.modification_begin();
437 const unsigned starting_node_idx = (1 - p_rank) * nodes_per_side;
438 for (
unsigned node_idx = starting_node_idx;
439 node_idx < starting_node_idx + nodes_per_side;
440 ++node_idx, ++rel_id) {
441 mesh.declare_relation( *edge_ptr, *nodes[node_idx], rel_id );
445 mesh.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.
Ghosting & create_ghosting(const std::string &name)
Asymmetric parallel relations for owner-to-ghosted mesh entities.
Data for ghosting mesh entities.
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.
field_type & put_field(field_type &field, EntityRank entity_rank, const Part &part, const void *init_value=NULL)
Declare a field to exist for a given entity type and Part.
An application-defined subset of a problem domain.
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
void destroy_all_ghosting()
Empty every single Ghosting. Same result, but more efficient than, calling change_ghosting to remove ...
bool modification_end()
Parallel synchronization of modifications and transition to the guaranteed parallel consistent state...
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.
A relation between two mesh entities with a relation identifier and kind .
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...
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.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).