void SculptMeshFactory::buildElements(stk_classic::ParallelMachine parallelMach,STK_Interface & mesh) const { struct MeshStorageStruct *mss = get_sculpt_mesh(); int num_blocks = mss->num_elem_blk; int *block_id = new int[num_blocks]; //char ** element_types = new std::string[num_blocks]; int *elements = new int[num_blocks]; int *nodes_per_element = new int[num_blocks]; int *element_attributes = new int[num_blocks]; int **elmt_node_linkage = new int*[num_blocks]; for(int b = 0; b < num_blocks; b++){ block_id[b] = mss->block_id[b]; // element_types[b] = mss->element_types[b]; elements[b] = mss->elements[b]; nodes_per_element[b] = mss->nodes_per_element[b]; element_attributes[b] = mss->element_attributes[b]; } int elm_start = 1; mesh.beginModification(); // build each block for(int ib=0;ib<num_blocks;ib++) { buildBlock(parallelMach,mesh, ib, block_id, elm_start, elements, nodes_per_element, element_attributes, elmt_node_linkage ); elm_start += elements[ib]; } mesh.endModification(); }
void LineMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const { mesh.beginModification(); // build each block for(int xBlock=0;xBlock<xBlocks_;xBlock++) { buildBlock(parallelMach,xBlock,mesh); } mesh.endModification(); }
void SculptMeshFactory::addNodeSets(STK_Interface & mesh) const { mesh.beginModification(); struct MeshStorageStruct *mss = get_sculpt_mesh(); int num_node_sets = mss->num_node_sets; if (num_node_sets) { int *node_set_id = new int[num_node_sets]; int *num_nodes_in_node_set = new int[num_node_sets]; int *num_df_in_node_set = new int[num_node_sets]; int **node_set_nodes = new int*[num_node_sets]; double **node_set_df = new double*[num_node_sets]; for(int ict = 0; ict < num_node_sets; ict ++){ node_set_id[ict] = mss->node_set_id[ict]; num_nodes_in_node_set[ict] = mss->num_nodes_in_node_set[ict]; num_df_in_node_set[ict] = mss->num_df_in_node_set[ict]; } for(int i = 0; i < num_node_sets; i++) { node_set_nodes[i] = new int[num_nodes_in_node_set[i]]; node_set_df[i] = NULL; if(num_nodes_in_node_set[i]) { for(int nct = 0; nct < num_nodes_in_node_set[i];nct ++){ node_set_nodes[i][nct] = mss->node_set_nodes[i][nct]; } } } for(int i = 0; i < num_node_sets; i++) { std::stringstream nodesetName; nodesetName << "Nodeset-" << mss->node_set_id[i]; stk_classic::mesh::Part * nodeset = mesh.getNodeset(nodesetName.str()); for( int j = 0; j < num_nodes_in_node_set[i]; j++ ) { int node_id = node_set_nodes[i][j]; Teuchos::RCP<stk_classic::mesh::BulkData> bulkData = mesh.getBulkData(); if(machRank_==0) { stk_classic::mesh::Entity * node = bulkData->get_entity(mesh.getNodeRank(),node_id); mesh.addEntityToNodeset(*node, nodeset); } } } } mesh.endModification(); }
void STK_ExodusReaderFactory::completeMeshConstruction(STK_Interface & mesh,stk::ParallelMachine parallelMach) const { PANZER_FUNC_TIME_MONITOR("panzer::STK_ExodusReaderFactory::completeMeshConstruction()"); using Teuchos::RCP; using Teuchos::rcp; if(not mesh.isInitialized()) mesh.initialize(parallelMach); // grab mesh data pointer to build the bulk data stk::mesh::MetaData & metaData = stk::mesh::fem::FEMMetaData::get_meta_data(*mesh.getMetaData()); stk::io::MeshData * meshData = const_cast<stk::io::MeshData *>(metaData.get_attribute<stk::io::MeshData>()); // if const_cast is wrong ... why does it feel so right? // I believe this is safe since we are basically hiding this object under the covers // until the mesh construction can be completed...below I cleanup the object myself. TEUCHOS_ASSERT(metaData.remove_attribute(meshData)); // remove the MeshData attribute RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData(); // build mesh bulk data mesh.beginModification(); stk::io::populate_bulk_data(*bulkData, *meshData); mesh.endModification(); // put in a negative index and (like python) the restart will be from the back // (-1 is the last time step) int restartIndex = restartIndex_; if(restartIndex<0) { std::pair<int,double> lastTimeStep = meshData->m_input_region->get_max_time(); restartIndex = 1+restartIndex+lastTimeStep.first; } // populate mesh fields with specific index stk::io::process_input_request(*meshData,*bulkData,restartIndex); mesh.buildSubcells(); mesh.buildLocalElementIDs(); if(restartIndex>0) // process_input_request is a no-op if restartIndex<=0 ... thus there would be no inital time mesh.setInitialStateTime(meshData->m_input_region->get_state_time(restartIndex)); else mesh.setInitialStateTime(0.0); // no initial time to speak, might as well use 0.0 // clean up mesh data object delete meshData; // calls Stk_MeshFactory::rebalance this->rebalance(mesh); }
void CubeTetMeshFactory::buildElements(stk_classic::ParallelMachine parallelMach,STK_Interface & mesh) const { mesh.beginModification(); // build each block for(int xBlock=0;xBlock<xBlocks_;xBlock++) { for(int yBlock=0;yBlock<yBlocks_;yBlock++) { for(int zBlock=0;zBlock<zBlocks_;zBlock++) { buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh); } } } mesh.endModification(); }
void MultiBlockMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const { mesh.beginModification(); if(machRank_==0) { buildBlock(parallelMach,0,0,mesh); } else if(machRank_==1) { buildBlock(parallelMach,0,1,mesh); } else TEUCHOS_ASSERT(false); mesh.endModification(); }
void CustomMeshFactory::addSideSets(STK_Interface &mesh) const { mesh.beginModification(); // get all part vectors stk_classic::mesh::Part *box[6]; box[0] = mesh.getSideset("front"); box[1] = mesh.getSideset("right"); box[2] = mesh.getSideset("back"); box[3] = mesh.getSideset("left"); box[4] = mesh.getSideset("bottom"); box[5] = mesh.getSideset("top"); stk_classic::mesh::Part *wall = mesh.getSideset("wall"); std::vector<stk_classic::mesh::Entity*> elements; mesh.getMyElements(elements); // loop over elements adding sides to sidesets for (std::vector<stk_classic::mesh::Entity*>::const_iterator itr=elements.begin();itr!=elements.end();++itr) { stk_classic::mesh::Entity *element = (*itr); stk_classic::mesh::PairIterRelation relations = element->relations(mesh.getSideRank()); // loop over side id checking element neighbors for (std::size_t i=0;i<relations.size();++i) { stk_classic::mesh::Entity *side = relations[i].entity(); stk_classic::mesh::PairIterRelation neighbors = side->relations(mesh.getElementRank()); const std::size_t numNeighbors = neighbors.size(); if (numNeighbors == 1) { if (side->owner_rank() == machRank_) mesh.addEntityToSideset(*side, box[i]); } else if (numNeighbors == 2) { std::string neig_block_id_0 = mesh.containingBlockId(neighbors[0].entity()); std::string neig_block_id_1 = mesh.containingBlockId(neighbors[1].entity()); if ((neig_block_id_0 != neig_block_id_1) && (side->owner_rank() == machRank_)) mesh.addEntityToSideset(*side, wall); } else { // runtime exception } } } mesh.endModification(); }
void LineMeshFactory::addSideSets(STK_Interface & mesh) const { mesh.beginModification(); std::size_t totalXElems = nXElems_*xBlocks_; // get all part vectors stk::mesh::Part * left = mesh.getSideset("left"); stk::mesh::Part * right = mesh.getSideset("right"); std::vector<stk::mesh::Entity*> localElmts; mesh.getMyElements(localElmts); // loop over elements adding edges to sidesets std::vector<stk::mesh::Entity*>::const_iterator itr; for(itr=localElmts.begin();itr!=localElmts.end();++itr) { stk::mesh::Entity * element = (*itr); stk::mesh::EntityId gid = element->identifier(); stk::mesh::PairIterRelation relations = element->relations(mesh.getSideRank()); std::size_t nx = gid-1; // vertical boundaries /////////////////////////////////////////// if(nx+1==totalXElems) { stk::mesh::Entity * edge = getRelationByID(1,relations)->entity(); // on the right if(edge->owner_rank()==machRank_) mesh.addEntityToSideset(*edge,right); } if(nx==0) { stk::mesh::Entity * edge = getRelationByID(0,relations)->entity(); // on the left if(edge->owner_rank()==machRank_) mesh.addEntityToSideset(*edge,left); } } mesh.endModification(); }
void CustomMeshFactory::buildElements(STK_Interface &mesh) const { mesh.beginModification(); const int dim = mesh.getDimension(); // build the nodes std::vector<double> coords(dim,0.0); for (int i=0;i<NumNodesPerProc_;++i) { for (int k=0;k<dim;++k) coords[k] = Coords_[i*dim+k]; mesh.addNode(Nodes_[i], coords); } // build the elements std::vector<std::string> block_ids; mesh.getElementBlockNames(block_ids); for (int i=0;i<NumElementsPerProc_;++i) { // get block by its name std::stringstream block_id; block_id << "eblock-" << BlockIDs_[i]; stk_classic::mesh::Part *block = mesh.getElementBlockPart(block_id.str()); // construct element and its nodal connectivity stk_classic::mesh::EntityId elt = i + OffsetToGlobalElementIDs_; std::vector<stk_classic::mesh::EntityId> elt2nodes(8); for (int k=0;k<8;++k) elt2nodes[k] = Element2Nodes_[i*8+k]; RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(elt,elt2nodes)); mesh.addElement(ed,block); } mesh.endModification(); }
void SquareQuadMeshFactory::addNodeSets(STK_Interface & mesh) const { mesh.beginModification(); // get all part vectors stk::mesh::Part * lower_left = mesh.getNodeset("lower_left"); stk::mesh::Part * origin = mesh.getNodeset("origin"); // std::vector<stk::mesh::Entity*> localElmts; // mesh.getMyElements(localElmts); Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData(); if(machRank_==0) { // add zero node to lower_left node set stk::mesh::Entity * node = bulkData->get_entity(mesh.getNodeRank(),1); mesh.addEntityToNodeset(*node,lower_left); // add zero node to origin node set mesh.addEntityToNodeset(*node,origin); } mesh.endModification(); }
void CubeTetMeshFactory::addSideSets(STK_Interface & mesh) const { mesh.beginModification(); std::size_t totalXElems = nXElems_*xBlocks_; std::size_t totalYElems = nYElems_*yBlocks_; std::size_t totalZElems = nZElems_*zBlocks_; // get all part vectors stk_classic::mesh::Part * left = mesh.getSideset("left"); stk_classic::mesh::Part * right = mesh.getSideset("right"); stk_classic::mesh::Part * top = mesh.getSideset("top"); stk_classic::mesh::Part * bottom = mesh.getSideset("bottom"); stk_classic::mesh::Part * front = mesh.getSideset("front"); stk_classic::mesh::Part * back = mesh.getSideset("back"); std::vector<stk_classic::mesh::Entity*> localElmts; mesh.getMyElements(localElmts); // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1 // loop over elements adding sides to sidesets std::vector<stk_classic::mesh::Entity*>::const_iterator itr; for(itr=localElmts.begin();itr!=localElmts.end();++itr) { stk_classic::mesh::Entity * element = (*itr); stk_classic::mesh::EntityId gid = element->identifier(); stk_classic::mesh::PairIterRelation relations = element->relations(mesh.getSideRank()); // get hex global id stk_classic::mesh::EntityId h_gid = (gid-1)/12+1; stk_classic::mesh::EntityId t_offset = gid - (12*(h_gid-1)+1); std::size_t nx,ny,nz; nz = (h_gid-1) / (totalXElems*totalYElems); h_gid = (h_gid-1)-nz*(totalXElems*totalYElems); ny = h_gid / totalXElems; nx = h_gid-ny*totalXElems; if(nz==0 && (t_offset==0 || t_offset==1)) { stk_classic::mesh::Entity * side = getRelationByID(3,relations)->entity(); // on the back if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,back); } if(nz+1==totalZElems && (t_offset==10 || t_offset==11)) { stk_classic::mesh::Entity * side = getRelationByID(3,relations)->entity(); // on the front if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,front); } if(ny==0 && (t_offset==2 || t_offset==3)) { stk_classic::mesh::Entity * side = getRelationByID(3,relations)->entity(); // on the bottom if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,bottom); } if(ny+1==totalYElems && (t_offset==8 || t_offset==9)) { stk_classic::mesh::Entity * side = getRelationByID(3,relations)->entity(); // on the top if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,top); } if(nx==0 && (t_offset==4 || t_offset==5)) { stk_classic::mesh::Entity * side = getRelationByID(3,relations)->entity(); // on the left if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,left); } if(nx+1==totalXElems && (t_offset==6 || t_offset==7)) { stk_classic::mesh::Entity * side = getRelationByID(3,relations)->entity(); // on the right if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,right); } } mesh.endModification(); }
void STK_ExodusReaderFactory::completeMeshConstruction(STK_Interface & mesh,stk_classic::ParallelMachine parallelMach) const { PANZER_FUNC_TIME_MONITOR("panzer::STK_ExodusReaderFactory::completeMeshConstruction()"); using Teuchos::RCP; using Teuchos::rcp; if(not mesh.isInitialized()) mesh.initialize(parallelMach); // grab mesh data pointer to build the bulk data stk_classic::mesh::MetaData & metaData = stk_classic::mesh::fem::FEMMetaData::get_meta_data(*mesh.getMetaData()); stk_classic::io::MeshData * meshData = const_cast<stk_classic::io::MeshData *>(metaData.get_attribute<stk_classic::io::MeshData>()); // if const_cast is wrong ... why does it feel so right? // I believe this is safe since we are basically hiding this object under the covers // until the mesh construction can be completed...below I cleanup the object myself. TEUCHOS_ASSERT(metaData.remove_attribute(meshData)); // remove the MeshData attribute RCP<stk_classic::mesh::BulkData> bulkData = mesh.getBulkData(); // build mesh bulk data mesh.beginModification(); stk_classic::io::populate_bulk_data(*bulkData, *meshData); // The following section of code is applicable if mesh scaling is // turned on from the input file. if (userMeshScaling_) { stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian>* coord_field = metaData.get_field<stk_classic::mesh::Field<double, stk_classic::mesh::Cartesian> >("coordinates"); std::vector<stk_classic::mesh::Bucket*> const all_node_buckets = bulkData->buckets(stk_classic::mesh::fem::FEMMetaData::NODE_RANK); stk_classic::mesh::Selector select_all_local = metaData.locally_owned_part() | metaData.globally_shared_part(); std::vector<stk_classic::mesh::Bucket*> my_node_buckets; stk_classic::mesh::get_buckets(select_all_local, all_node_buckets, my_node_buckets); int mesh_dim = mesh.getDimension(); // Scale the mesh for (size_t i=0; i < my_node_buckets.size(); ++i) { stk_classic::mesh::Bucket& b = *(my_node_buckets[i]); stk_classic::mesh::BucketArray<stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian> > coordinate_data(*coord_field, b); for (size_t j=0; j < b.size(); ++j) { int index = j; double inv_msf = 1.0/meshScaleFactor_; for (int k=0; k < mesh_dim; ++k) coordinate_data(k, index) = coordinate_data(k, index) * inv_msf; } } } mesh.endModification(); // put in a negative index and (like python) the restart will be from the back // (-1 is the last time step) int restartIndex = restartIndex_; if(restartIndex<0) { std::pair<int,double> lastTimeStep = meshData->m_input_region->get_max_time(); restartIndex = 1+restartIndex+lastTimeStep.first; } // populate mesh fields with specific index stk_classic::io::process_input_request(*meshData,*bulkData,restartIndex); mesh.buildSubcells(); mesh.buildLocalElementIDs(); if(restartIndex>0) // process_input_request is a no-op if restartIndex<=0 ... thus there would be no inital time mesh.setInitialStateTime(meshData->m_input_region->get_state_time(restartIndex)); else mesh.setInitialStateTime(0.0); // no initial time to speak, might as well use 0.0 // clean up mesh data object delete meshData; // calls Stk_MeshFactory::rebalance this->rebalance(mesh); }
void SculptMeshFactory::addSideSets(STK_Interface & mesh) const { mesh.beginModification(); struct MeshStorageStruct *mss = get_sculpt_mesh(); int num_side_sets = mss->num_side_sets; int *side_set_id = new int[num_side_sets]; int *num_elements_in_side_set = new int[num_side_sets]; int *num_nodes_in_side_set = new int[num_side_sets]; int *num_df_in_side_set = new int[num_side_sets]; int **side_set_elements = new int*[num_side_sets]; int **side_set_faces = new int*[num_side_sets]; //Element_Type **side_set_element_type = new Element_Type*[num_side_sets]; int **side_set_node_counter = new int*[num_side_sets]; int **side_set_nodes = new int*[num_side_sets]; double **side_set_df = new double*[num_side_sets]; for(int ict = 0;ict < num_side_sets;ict ++){ side_set_id[ict] = mss->side_set_id[ict]; } for(int i = 0; i < num_side_sets; i++) { std::stringstream sidesetName; sidesetName << "Sideset-" << mss->side_set_id[i]; stk_classic::mesh::Part * sideset = mesh.getSideset(sidesetName.str()); num_elements_in_side_set[i] = mss->num_elements_in_side_set[i]; num_df_in_side_set[i] = mss->num_df_in_side_set[i]; int ne = num_elements_in_side_set[i]; side_set_elements[i] = new int[ne]; side_set_faces[i] = new int[ne]; //side_set_element_type[i] = new Element_Type[ne]; side_set_node_counter[i] = new int[ne]; side_set_df[i] = new double[num_df_in_side_set[i]]; if(ne) { for(int nct = 0; nct < ne; nct ++){ std::vector<stk_classic::mesh::EntityId> nodes(4); int sculpt_elem_id = mss->global_element_numbers[ mss->side_set_elements[i][nct]-1 ]; int sculpt_face_id = -1 ; std::vector<stk_classic::mesh::Entity*> localElmts; mesh.getMyElements(localElmts); std::vector<stk_classic::mesh::Entity*>::const_iterator itr; for(itr=localElmts.begin();itr!=localElmts.end();++itr) { stk_classic::mesh::Entity * element = (*itr); if( element->identifier() == sculpt_elem_id ) { sculpt_face_id = mss->side_set_faces[i][nct]; stk_classic::mesh::EntityId gid = element->identifier(); stk_classic::mesh::PairIterRelation relations = element->relations(mesh.getSideRank()); stk_classic::mesh::Entity * side = getRelationByID(sculpt_face_id-1,relations)->entity(); if( side != NULL ) { if(side->owner_rank()==machRank_) mesh.addEntityToSideset(*side,sideset ); } } } if( sculpt_face_id == -1 ) printf(" ERROR: Could not find the element id for a sideset face \n"); } } } mesh.endModification(); }
void MultiBlockMeshFactory::addSideSets(STK_Interface & mesh) const { mesh.beginModification(); std::size_t totalXElems = nXElems_*2; std::size_t totalYElems = nYElems_*1; // get all part vectors stk::mesh::Part * left = mesh.getSideset("left"); stk::mesh::Part * right = mesh.getSideset("right"); stk::mesh::Part * top = mesh.getSideset("top"); stk::mesh::Part * bottom = mesh.getSideset("bottom"); std::vector<stk::mesh::Entity*> localElmts; mesh.getMyElements(localElmts); // loop over elements adding edges to sidesets std::vector<stk::mesh::Entity*>::const_iterator itr; for(itr=localElmts.begin();itr!=localElmts.end();++itr) { stk::mesh::Entity * element = (*itr); stk::mesh::EntityId gid = element->identifier(); stk::mesh::PairIterRelation relations = element->relations(mesh.getEdgeRank()); std::size_t nx,ny; ny = (gid-1) / totalXElems; nx = gid-ny*totalXElems-1; // vertical boundaries /////////////////////////////////////////// if(nx+1==totalXElems) { stk::mesh::Entity * edge = getRelationByID(1,relations)->entity(); // on the right if(edge->owner_rank()==machRank_) mesh.addEntityToSideset(*edge,right); } if(nx==0) { stk::mesh::Entity * edge = getRelationByID(3,relations)->entity(); // on the left if(edge->owner_rank()==machRank_) mesh.addEntityToSideset(*edge,left); } // horizontal boundaries /////////////////////////////////////////// if(ny==0) { stk::mesh::Entity * edge = getRelationByID(0,relations)->entity(); // on the bottom if(edge->owner_rank()==machRank_) mesh.addEntityToSideset(*edge,bottom); } if(ny+1==totalYElems) { stk::mesh::Entity * edge = getRelationByID(2,relations)->entity(); // on the top if(edge->owner_rank()==machRank_) mesh.addEntityToSideset(*edge,top); } } mesh.endModification(); }