// ======================================================================== void process_nodesets(Ioss::Region ®ion, stk::mesh::BulkData &bulk) { // Should only process nodes that have already been defined via the element // blocks connectivity lists. const Ioss::NodeSetContainer& node_sets = region.get_nodesets(); for(Ioss::NodeSetContainer::const_iterator it = node_sets.begin(); it != node_sets.end(); ++it) { Ioss::NodeSet *entity = *it; if (stk::io::include_entity(entity)) { const std::string & name = entity->name(); const stk::mesh::MetaData& meta = stk::mesh::MetaData::get(bulk); stk::mesh::Part* const part = meta.get_part(name); STKIORequire(part != NULL); stk::mesh::PartVector add_parts( 1 , part ); std::vector<int> node_ids ; int node_count = entity->get_field_data("ids", node_ids); std::vector<stk::mesh::Entity> nodes(node_count); for(int i=0; i<node_count; ++i) { nodes[i] = bulk.get_entity( stk::topology::NODE_RANK, node_ids[i] ); if (bulk.is_valid(nodes[i])) { bulk.declare_entity(stk::topology::NODE_RANK, node_ids[i], add_parts ); } } /** \todo REFACTOR Application would probably store this field * (and others) somewhere after the declaration instead of * looking it up each time it is needed. */ stk::mesh::Field<double> *df_field = meta.get_field<stk::mesh::Field<double> >(stk::topology::NODE_RANK, "distribution_factors"); if (df_field != NULL) { stk::io::field_data_from_ioss(bulk, df_field, nodes, entity, "distribution_factors"); } } } }
stk::mesh::Entity declare_element_to_sub_topology_with_nodes(stk::mesh::BulkData &mesh, stk::mesh::Entity elem, stk::mesh::EntityVector &sub_topology_nodes, stk::mesh::EntityId global_sub_topology_id, stk::mesh::EntityRank to_rank, stk::mesh::Part &part) { std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation = get_ordinal_and_permutation(mesh, elem, to_rank, sub_topology_nodes); if ((ordinalAndPermutation.first == stk::mesh::ConnectivityOrdinal::INVALID_CONNECTIVITY_ORDINAL) || (ordinalAndPermutation.second == stk::mesh::Permutation::INVALID_PERMUTATION)) { stk::mesh::Entity invalid; invalid = stk::mesh::Entity::InvalidEntity; return invalid; } stk::mesh::Entity side = mesh.declare_entity(to_rank, global_sub_topology_id, part); for (unsigned i=0;i<sub_topology_nodes.size();++i) { mesh.declare_relation(side, sub_topology_nodes[i], i); } mesh.declare_relation(elem, side, ordinalAndPermutation.first, ordinalAndPermutation.second); return side; }
void Gear::mesh( stk::mesh::BulkData & M ) { stk::mesh::EntityRank element_rank = stk::topology::ELEMENT_RANK; stk::mesh::EntityRank side_rank = m_mesh_meta_data.side_rank(); M.modification_begin(); m_mesh = & M ; const unsigned p_size = M.parallel_size(); const unsigned p_rank = M.parallel_rank(); std::vector<size_t> counts ; stk::mesh::comm_mesh_counts(M, counts); // max_id is no longer available from comm_mesh_stats. // If we assume uniform numbering from 1.., then max_id // should be equal to counts... const stk::mesh::EntityId node_id_base = counts[ stk::topology::NODE_RANK ] + 1 ; const stk::mesh::EntityId elem_id_base = counts[ element_rank ] + 1 ; const unsigned long elem_id_gear_max = m_angle_num * ( m_rad_num - 1 ) * ( m_z_num - 1 ); std::vector<stk::mesh::Part*> elem_parts ; std::vector<stk::mesh::Part*> face_parts ; std::vector<stk::mesh::Part*> node_parts ; { stk::mesh::Part * const p_gear = & m_gear ; stk::mesh::Part * const p_surf = & m_surf ; elem_parts.push_back( p_gear ); face_parts.push_back( p_surf ); } for ( unsigned ia = 0 ; ia < m_angle_num ; ++ia ) { for ( unsigned ir = 0 ; ir < m_rad_num - 1 ; ++ir ) { for ( unsigned iz = 0 ; iz < m_z_num - 1 ; ++iz ) { stk::mesh::EntityId elem_id_gear = identifier( m_z_num-1 , m_rad_num-1 , iz , ir , ia ); if ( ( ( elem_id_gear * p_size ) / elem_id_gear_max ) == p_rank ) { stk::mesh::EntityId elem_id = elem_id_base + elem_id_gear ; // Create the node and set the model_coordinates const size_t ia_1 = ( ia + 1 ) % m_angle_num ; const size_t ir_1 = ir + 1 ; const size_t iz_1 = iz + 1 ; stk::mesh::Entity node[8] ; node[0] = create_node( node_parts, node_id_base, iz , ir , ia_1 ); node[1] = create_node( node_parts, node_id_base, iz_1, ir , ia_1 ); node[2] = create_node( node_parts, node_id_base, iz_1, ir , ia ); node[3] = create_node( node_parts, node_id_base, iz , ir , ia ); node[4] = create_node( node_parts, node_id_base, iz , ir_1, ia_1 ); node[5] = create_node( node_parts, node_id_base, iz_1, ir_1, ia_1 ); node[6] = create_node( node_parts, node_id_base, iz_1, ir_1, ia ); node[7] = create_node( node_parts, node_id_base, iz , ir_1, ia ); #if 0 /* VERIFY_CENTROID */ // Centroid of the element for verification const double TWO_PI = 2.0 * acos( -1.0 ); const double angle = m_ang_inc * (0.5 + ia); const double z = m_center[2] + m_z_min + m_z_inc * (0.5 + iz); double c[3] = { 0 , 0 , 0 }; for ( size_t j = 0 ; j < 8 ; ++j ) { double * const coord_data = field_data( m_model_coord , *node[j] ); c[0] += coord_data[0] ; c[1] += coord_data[1] ; c[2] += coord_data[2] ; } c[0] /= 8 ; c[1] /= 8 ; c[2] /= 8 ; c[0] -= m_center[0] ; c[1] -= m_center[1] ; double val_a = atan2( c[1] , c[0] ); if ( val_a < 0 ) { val_a += TWO_PI ; } const double err_a = angle - val_a ; const double err_z = z - c[2] ; const double eps = 100 * std::numeric_limits<double>::epsilon(); if ( err_z < - eps || eps < err_z || err_a < - eps || eps < err_a ) { std::string msg ; msg.append("problem setup element centroid error" ); throw std::logic_error( msg ); } #endif stk::mesh::Entity elem = M.declare_entity( element_rank, elem_id, elem_parts ); for ( size_t j = 0 ; j < 8 ; ++j ) { M.declare_relation( elem , node[j] , static_cast<unsigned>(j) ); } } } } } // Array of faces on the surface { const size_t ir = m_rad_num - 1 ; for ( size_t ia = 0 ; ia < m_angle_num ; ++ia ) { for ( size_t iz = 0 ; iz < m_z_num - 1 ; ++iz ) { stk::mesh::EntityId elem_id_gear = identifier( m_z_num-1 , m_rad_num-1 , iz , ir-1 , ia ); if ( ( ( elem_id_gear * p_size ) / elem_id_gear_max ) == p_rank ) { stk::mesh::EntityId elem_id = elem_id_base + elem_id_gear ; unsigned face_ord = 5 ; stk::mesh::EntityId face_id = elem_id * 10 + face_ord + 1; stk::mesh::Entity node[4] ; const size_t ia_1 = ( ia + 1 ) % m_angle_num ; const size_t iz_1 = iz + 1 ; node[0] = create_node( node_parts, node_id_base, iz , ir , ia_1 ); node[1] = create_node( node_parts, node_id_base, iz_1, ir , ia_1 ); node[2] = create_node( node_parts, node_id_base, iz_1, ir , ia ); node[3] = create_node( node_parts, node_id_base, iz , ir , ia ); stk::mesh::Entity face = M.declare_entity( side_rank, face_id, face_parts ); for ( size_t j = 0 ; j < 4 ; ++j ) { M.declare_relation( face , node[j] , static_cast<unsigned>(j) ); } stk::mesh::Entity elem = M.get_entity(element_rank, elem_id); M.declare_relation( elem , face , face_ord ); } } } } M.modification_begin(); }
void verify_unbuildable_element(stk::mesh::BulkData &bulk, const stk::topology topo, const stk::mesh::EntityIdVector & elem_node_ids, const stk::mesh::EntityIdVector & side_ids, const std::vector < std::vector < unsigned > > &gold_side_node_ids, bool *sides_connectibility_check, const stk::mesh::EntityIdVector & edge_ids, const std::vector < std::vector < unsigned > > &gold_edge_node_ids, bool *edges_connectibility_check) { stk::mesh::EntityId element_id[1] = {1}; stk::mesh::MetaData &meta = bulk.mesh_meta_data(); stk::mesh::Part &elem_part = meta.declare_part_with_topology("elem_part", topo); meta.commit(); bulk.modification_begin(); stk::mesh::Entity elem = stk::mesh::declare_element(bulk, elem_part, element_id[0], elem_node_ids); stk::mesh::EntityVector side_nodes; uint num_sides = topo.num_sides(); stk::topology::rank_t sub_topo_rank = topo.side_rank(); for(uint i = 0; i < num_sides; ++i) { stk::topology sub_topo = topo.side_topology(i); side_nodes.clear(); stk::mesh::Entity side = bulk.declare_entity(sub_topo_rank, side_ids[i], meta.get_topology_root_part(sub_topo)); for (uint j = 0; j < sub_topo.num_nodes(); ++j) { stk::mesh::Entity side_node = bulk.get_entity(stk::topology::NODE_RANK, gold_side_node_ids[i][j]); side_nodes.push_back(side_node); bulk.declare_relation(side, side_node, j); } std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation = stk::mesh::get_ordinal_and_permutation(bulk, elem, sub_topo_rank, side_nodes); if (sides_connectibility_check[i]) { EXPECT_NE(ordinalAndPermutation.first, stk::mesh::ConnectivityOrdinal::INVALID_CONNECTIVITY_ORDINAL); EXPECT_NE(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION); } else { EXPECT_EQ(ordinalAndPermutation.first, stk::mesh::ConnectivityOrdinal::INVALID_CONNECTIVITY_ORDINAL); EXPECT_EQ(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION); } } if (edge_ids.empty()) { bulk.modification_end(); return; } stk::mesh::EntityVector edge_nodes; uint num_edges = topo.num_edges(); for(uint i = 0; i < num_edges; ++i) { edge_nodes.clear(); stk::mesh::Entity edge = bulk.declare_entity(stk::topology::EDGE_RANK, edge_ids[i], meta.get_topology_root_part(topo.edge_topology())); for (uint j = 0; j < topo.edge_topology().num_nodes(); ++j) { stk::mesh::Entity edge_node = bulk.get_entity(stk::topology::NODE_RANK, gold_edge_node_ids[i][j]); edge_nodes.push_back(edge_node); bulk.declare_relation(edge, edge_node, j); } std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation = stk::mesh::get_ordinal_and_permutation(bulk, elem, stk::topology::EDGE_RANK, edge_nodes); if (edges_connectibility_check[i]) { EXPECT_NE(ordinalAndPermutation.first, stk::mesh::ConnectivityOrdinal::INVALID_CONNECTIVITY_ORDINAL); EXPECT_NE(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION); } else { EXPECT_EQ(ordinalAndPermutation.first, stk::mesh::ConnectivityOrdinal::INVALID_CONNECTIVITY_ORDINAL); EXPECT_EQ(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION); } } bulk.modification_end(); }
void build_element_from_topology_verify_ordinals_and_permutations(stk::mesh::BulkData &bulk, const stk::topology topo, const stk::mesh::EntityIdVector & elem_node_ids, const stk::mesh::EntityIdVector & edge_ids, const std::vector < std::vector < unsigned > > &gold_side_node_ids, const unsigned * gold_side_permutations, const std::vector < std::vector < unsigned > > &gold_edge_node_ids, const unsigned * gold_edge_permutations) { stk::mesh::EntityId element_id[1] = {1}; stk::mesh::MetaData &meta = bulk.mesh_meta_data(); stk::mesh::Part &elem_part = meta.declare_part_with_topology("elem_part", topo); meta.commit(); bulk.modification_begin(); stk::mesh::Entity elem = stk::mesh::declare_element(bulk, elem_part, element_id[0], elem_node_ids); stk::mesh::EntityVector side_nodes; uint num_sides = topo.num_sides(); stk::topology::rank_t sub_topo_rank = topo.side_rank(); for(uint i = 0; i < num_sides; ++i) { stk::topology sub_topo = topo.side_topology(i); bulk.declare_element_side(elem, i, {&meta.get_topology_root_part(sub_topo)}); side_nodes.clear(); for (uint j = 0; j < sub_topo.num_nodes(); ++j) { stk::mesh::Entity side_node = bulk.get_entity(stk::topology::NODE_RANK, gold_side_node_ids[i][j]); side_nodes.push_back(side_node); } stk::mesh::OrdinalAndPermutation ordinalAndPermutation = stk::mesh::get_ordinal_and_permutation(bulk, elem, sub_topo_rank, side_nodes); EXPECT_EQ(ordinalAndPermutation.second, gold_side_permutations[i]) << topo; EXPECT_EQ(ordinalAndPermutation.first, i) << topo; } if (edge_ids.empty()) { bulk.modification_end(); return; } stk::mesh::EntityVector edge_nodes; uint num_edges = topo.num_edges(); for(uint i = 0; i < num_edges; ++i) { edge_nodes.clear(); stk::mesh::Entity edge = bulk.declare_entity(stk::topology::EDGE_RANK, edge_ids[i], meta.get_topology_root_part(topo.edge_topology())); for (uint j = 0; j < topo.edge_topology().num_nodes(); ++j) { stk::mesh::Entity edge_node = bulk.get_entity(stk::topology::NODE_RANK, gold_edge_node_ids[i][j]); edge_nodes.push_back(edge_node); bulk.declare_relation(edge, edge_node, j); } std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation = stk::mesh::get_ordinal_and_permutation(bulk, elem, stk::topology::EDGE_RANK, edge_nodes); EXPECT_EQ(ordinalAndPermutation.second, gold_edge_permutations[i]) << topo; EXPECT_EQ(ordinalAndPermutation.first, i) << topo; } bulk.modification_end(); }