inline void setupKeyholeMesh2D_case2(stk::mesh::BulkData& bulk) { // // proc 0 proc 1 // | // | block_2 block_3 // | // block_1 | 12---11 // | | 4 | // 4----3 | 3----6 6----10 // | 1 | | | 2 | // 1----2 | 2----5 5----9 // | | 3 | // | 7----8 // | // //nodes 5 and 6 are ghosts (aura) on proc 0, //and should be members of block_2 and block_3 on proc 0 //if edges are added, the edge between nodes 5 and 6 should //be a member of block_2 not block_3. // stk::mesh::MetaData& meta = bulk.mesh_meta_data(); stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::QUAD_4_2D); stk::mesh::Part& block_2 = meta.declare_part_with_topology("block_2", stk::topology::QUAD_4_2D); stk::mesh::Part& block_3 = meta.declare_part_with_topology("block_3", stk::topology::QUAD_4_2D); meta.commit(); bulk.modification_begin(); stk::mesh::EntityIdVector elem1_nodes {1, 2, 3, 4}; stk::mesh::EntityIdVector elem2_nodes {2, 5, 6, 3}; stk::mesh::EntityIdVector elem3_nodes {7, 8, 9, 5}; stk::mesh::EntityIdVector elem4_nodes {6, 10, 11, 12}; stk::mesh::EntityId elemId = 1; if (bulk.parallel_rank() == 0) { stk::mesh::declare_element(bulk, block_1, elemId, elem1_nodes); stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2); stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3); bulk.add_node_sharing(node2, 1); bulk.add_node_sharing(node3, 1); } else if (bulk.parallel_rank() == 1) { elemId = 2; stk::mesh::declare_element(bulk, block_2, elemId, elem2_nodes); elemId = 3; stk::mesh::declare_element(bulk, block_3, elemId, elem3_nodes); elemId = 4; stk::mesh::declare_element(bulk, block_3, elemId, elem4_nodes); stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2); stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3); bulk.add_node_sharing(node2, 0); bulk.add_node_sharing(node3, 0); } bulk.modification_end(); }
inline void setupKeyholeMesh2D_case1(stk::mesh::BulkData& bulk) { // // proc 0 proc 1 // | // | block_2 block_3 // | // block_1 | 10---9 9----12 // | | 3 | | 4 | // 4----3 | 3----8 8----11 // | 1 | | // 1----2 | 2----7 // | | 2 | // | 5----6 // | // //shared nodes 2 and 3 should be members of block_1 and block_2 on both procs //nodes 8 and 9 are ghosts on proc 0, and should be members of block_2 and block_3 // //if edges are added, the edge between nodes 2 and 3 should be a member of block_1 not block_2. // //also, the edge between nodes 8 and 9 should be a member of block_2 and block_3 on both procs. stk::mesh::MetaData& meta = bulk.mesh_meta_data(); stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::QUAD_4_2D); stk::mesh::Part& block_2 = meta.declare_part_with_topology("block_2", stk::topology::QUAD_4_2D); stk::mesh::Part& block_3 = meta.declare_part_with_topology("block_3", stk::topology::QUAD_4_2D); meta.commit(); bulk.modification_begin(); stk::mesh::EntityIdVector elem1_nodes {1, 2, 3, 4}; stk::mesh::EntityIdVector elem2_nodes {5, 6, 7, 2}; stk::mesh::EntityIdVector elem3_nodes {3, 8, 9, 10}; stk::mesh::EntityIdVector elem4_nodes {8, 11, 12, 9}; stk::mesh::EntityId elemId = 1; if (bulk.parallel_rank() == 0) { stk::mesh::declare_element(bulk, block_1, elemId, elem1_nodes); stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2); stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3); bulk.add_node_sharing(node2, 1); bulk.add_node_sharing(node3, 1); } else if (bulk.parallel_rank() == 1) { elemId = 2; stk::mesh::declare_element(bulk, block_2, elemId, elem2_nodes); elemId = 3; stk::mesh::declare_element(bulk, block_2, elemId, elem3_nodes); elemId = 4; stk::mesh::declare_element(bulk, block_3, elemId, elem4_nodes); stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2); stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3); bulk.add_node_sharing(node2, 0); bulk.add_node_sharing(node3, 0); } bulk.modification_end(); }
inline void setup2Block2HexMesh(stk::mesh::BulkData& bulk) { // // proc 0 proc 1 // | // block_1 | block_2 // | // 8----7 | 7----12 // / /| | / / | // 5----6 3 | 6----11 10 // | 1 |/ | | 2 | / // 1----2 | 2----9 // | // | // | // //shared nodes 2, 3, 6, 7 // if (bulk.parallel_size() > 2) { return; } stk::mesh::MetaData& meta = bulk.mesh_meta_data(); stk::topology hex = stk::topology::HEX_8; stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", hex); stk::mesh::Part& block_2 = meta.declare_part_with_topology("block_2", hex); meta.commit(); bulk.modification_begin(); stk::mesh::EntityIdVector elem1_nodes {1, 2, 3, 4, 5, 6, 7, 8}; stk::mesh::EntityIdVector elem2_nodes {2, 9, 10, 3, 6, 11, 12, 7}; stk::mesh::EntityId elemId = 1; if (bulk.parallel_rank() == 0) { stk::mesh::declare_element(bulk, block_1, elemId, elem1_nodes); } if (bulk.parallel_rank() == 1 || bulk.parallel_size() == 1) { elemId = 2; stk::mesh::declare_element(bulk, block_2, elemId, elem2_nodes); } if(bulk.parallel_rank() == 0 && bulk.parallel_size() == 2) { bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 2), 1); bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 3), 1); bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 6), 1); bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 7), 1); } if(bulk.parallel_rank() == 1 && bulk.parallel_size() == 2) { bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 2), 0); bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 3), 0); bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 6), 0); bulk.add_node_sharing(bulk.get_entity(stk::topology::NODE_RANK , 7), 0); } bulk.modification_end(); }
void fixup_ghosted_to_shared_nodes(stk::mesh::BulkData & bulk) { stk::mesh::EntityVector ghosted_nodes_that_are_now_shared; find_ghosted_nodes_that_need_to_be_shared(bulk, ghosted_nodes_that_are_now_shared); stk::CommSparse comm(bulk.parallel()); for (int phase=0;phase<2;++phase) { for (size_t i = 0; i < ghosted_nodes_that_are_now_shared.size(); ++i) { stk::mesh::Entity node = ghosted_nodes_that_are_now_shared[i]; int proc = bulk.parallel_owner_rank(node); comm.send_buffer(proc).pack<stk::mesh::EntityKey>(bulk.entity_key(node)); } if (phase == 0 ) { comm.allocate_buffers(); } else { comm.communicate(); } } stk::mesh::EntityVector sharedNodes; for (int process=0;process<bulk.parallel_size();++process) { while(comm.recv_buffer(process).remaining()) { stk::mesh::EntityKey key; comm.recv_buffer(process).unpack<stk::mesh::EntityKey>(key); stk::mesh::Entity entity = bulk.get_entity(key); if ( bulk.state(entity) != stk::mesh::Deleted && bulk.is_valid(entity) ) { bulk.add_node_sharing(entity, process); sharedNodes.push_back(entity); } } } ///////////////////////// stk::CommSparse commSecondStage(bulk.parallel()); for (int phase=0;phase<2;++phase) { for (size_t i=0;i<sharedNodes.size();++i) { std::vector<int> procs; stk::mesh::EntityKey key = bulk.entity_key(sharedNodes[i]); bulk.comm_shared_procs(key, procs); for (size_t j=0;j<procs.size();++j) { if ( procs[j] != bulk.parallel_rank() ) { commSecondStage.send_buffer(procs[j]).pack<int>(bulk.parallel_rank()).pack<stk::mesh::EntityKey>(key); for (size_t k=0;k<procs.size();++k) { commSecondStage.send_buffer(procs[j]).pack<int>(procs[k]).pack<stk::mesh::EntityKey>(key); } } } } if (phase == 0 ) { commSecondStage.allocate_buffers(); } else { commSecondStage.communicate(); } } for (int proc_that_sent_message=0;proc_that_sent_message<bulk.parallel_size();++proc_that_sent_message) { if ( proc_that_sent_message == bulk.parallel_rank() ) continue; while(commSecondStage.recv_buffer(proc_that_sent_message).remaining()) { stk::mesh::EntityKey key; int sharingProc; commSecondStage.recv_buffer(proc_that_sent_message).unpack<int>(sharingProc).unpack<stk::mesh::EntityKey>(key); if ( sharingProc != bulk.parallel_rank() ) { stk::mesh::Entity entity = bulk.get_entity(key); if ( bulk.state(entity) != stk::mesh::Deleted && bulk.is_valid(entity) && !bulk.in_shared(key, sharingProc) ) { bulk.add_node_sharing(entity, sharingProc); } } } } }
void make_small_hybrid_mesh(stk::mesh::MetaData &meta, stk::mesh::BulkData &mesh, bool user_attempt_no_induce = false, bool user_parts_force_no_induce = true) { stk::ParallelMachine pm = MPI_COMM_WORLD; int p_size = stk::parallel_machine_size(pm); if(p_size > 2) { return; } const unsigned p_rank = mesh.parallel_rank(); stk::mesh::Part * hexPart = &meta.get_topology_root_part(stk::topology::HEX_8); stk::mesh::Part * pyrPart = &meta.get_topology_root_part(stk::topology::PYRAMID_5); stk::mesh::Part * tetPart = &meta.get_topology_root_part(stk::topology::TET_4); if (user_attempt_no_induce) { hexPart = &meta.declare_part_with_topology("my_hex_part",stk::topology::HEX_8, user_parts_force_no_induce); pyrPart = &meta.declare_part_with_topology("my_pyr_part",stk::topology::PYRAMID_5, user_parts_force_no_induce); tetPart = &meta.declare_part_with_topology("my_tet_part",stk::topology::TET_4, user_parts_force_no_induce); EXPECT_EQ(user_parts_force_no_induce, hexPart->force_no_induce()); EXPECT_EQ(user_parts_force_no_induce, pyrPart->force_no_induce()); EXPECT_EQ(user_parts_force_no_induce, tetPart->force_no_induce()); } meta.commit(); const size_t numHex = 1; stk::mesh::EntityIdVector hexNodeIDs[] { { 1, 2, 3, 4, 5, 6, 7, 8 } }; stk::mesh::EntityId hexElemIDs[] = { 1 }; const size_t numPyr = 1; stk::mesh::EntityIdVector pyrNodeIDs[] { { 5, 6, 7, 8, 9 } }; stk::mesh::EntityId pyrElemIDs[] = { 2 }; const size_t numTet = 4; stk::mesh::EntityIdVector tetNodeIDs[] { { 7, 8, 9, 12 }, { 6, 9, 10, 7 }, { 7, 9, 10, 12 }, { 7, 12, 10, 11 } }; stk::mesh::EntityId tetElemIDs[] = { 3, 4, 5, 6 }; // list of triplets: (owner-proc, shared-nodeID, sharing-proc) std::vector< std::vector<unsigned> > shared_nodeIDs_and_procs { { 0, 5, 1 }, // proc 0 { 0, 6, 1 }, { 0, 7, 1 }, { 0, 8, 1 }, { 1, 5, 0 }, // proc 1 { 1, 6, 0 }, { 1, 7, 0 }, { 1, 8, 0 } }; mesh.modification_begin(); if (0 == p_rank) { for (size_t i = 0; i < numHex; ++i) { stk::mesh::declare_element(mesh, *hexPart, hexElemIDs[i], hexNodeIDs[i]); } } if ( (1 == p_rank) || (1 == p_size) ) { // setup the pyramids/tets for either np 2 or serial for (size_t i = 0; i < numPyr; ++i) { stk::mesh::declare_element(mesh, *pyrPart, pyrElemIDs[i], pyrNodeIDs[i]); } for (size_t i = 0; i < numTet; ++i) { stk::mesh::declare_element(mesh, *tetPart, tetElemIDs[i], tetNodeIDs[i]); } } if (p_size > 1) { for (size_t nodeIdx = 0, end = shared_nodeIDs_and_procs.size(); nodeIdx < end; ++nodeIdx) { if (p_rank == shared_nodeIDs_and_procs[nodeIdx][0]) { stk::mesh::EntityId nodeID = shared_nodeIDs_and_procs[nodeIdx][1]; int sharingProc = shared_nodeIDs_and_procs[nodeIdx][2]; stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, nodeID); mesh.add_node_sharing(node, sharingProc); } } } mesh.modification_end(); }