void LineMeshFactory::buildBlock(stk::ParallelMachine parallelMach,int xBlock,STK_Interface & mesh) const
{
   // grab this processors rank and machine size
   std::pair<int,int> sizeAndStartX = determineXElemSizeAndStart(xBlock,machSize_,machRank_);

   int myXElems_start = sizeAndStartX.first;
   int myXElems_end  = myXElems_start+sizeAndStartX.second;
   int totalXElems = nXElems_*xBlocks_;

   double deltaX = (xf_-x0_)/double(totalXElems);

   // build the nodes
   std::vector<double> coord(1,0.0);
   for(int nx=myXElems_start;nx<myXElems_end+1;++nx) {
      coord[0] = double(nx)*deltaX+x0_;
      mesh.addNode(nx+1,coord);
   }

   std::stringstream blockName;
   blockName << "eblock-" << xBlock;
   stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());

   // build the elements
   for(int nx=myXElems_start;nx<myXElems_end;++nx) {
      stk::mesh::EntityId gid = nx+1;
      std::vector<stk::mesh::EntityId> nodes(2);
      nodes[0] = nx+1;
      nodes[1] = nodes[0]+1;

      RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
      mesh.addElement(ed,block);
   }
}
示例#2
0
void SquareQuadMeshFactory::buildBlock(stk::ParallelMachine parallelMach,int xBlock,int yBlock,STK_Interface & mesh) const
{
   // grab this processors rank and machine size
   std::pair<int,int> sizeAndStartX = determineXElemSizeAndStart(xBlock,xProcs_,machRank_);
   std::pair<int,int> sizeAndStartY = determineYElemSizeAndStart(yBlock,yProcs_,machRank_);

   int myXElems_start = sizeAndStartX.first;
   int myXElems_end  = myXElems_start+sizeAndStartX.second;
   int myYElems_start = sizeAndStartY.first;
   int myYElems_end  = myYElems_start+sizeAndStartY.second;
   int totalXElems = nXElems_*xBlocks_;
   int totalYElems = nYElems_*yBlocks_;

   double deltaX = (xf_-x0_)/double(totalXElems);
   double deltaY = (yf_-y0_)/double(totalYElems);
 
   std::vector<double> coord(2,0.0);

   // build the nodes
   for(int nx=myXElems_start;nx<myXElems_end+1;++nx) {
      coord[0] = double(nx)*deltaX+x0_;
      for(int ny=myYElems_start;ny<myYElems_end+1;++ny) {
         coord[1] = double(ny)*deltaY+y0_;

         mesh.addNode(ny*(totalXElems+1)+nx+1,coord);
      }
   }

   std::stringstream blockName;
   blockName << "eblock-" << xBlock << "_" << yBlock;
   stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());

   // build the elements
   for(int nx=myXElems_start;nx<myXElems_end;++nx) {
      for(int ny=myYElems_start;ny<myYElems_end;++ny) {
         stk::mesh::EntityId gid = totalXElems*ny+nx+1;
         std::vector<stk::mesh::EntityId> nodes(4);
         nodes[0] = nx+1+ny*(totalXElems+1);
         nodes[1] = nodes[0]+1;
         nodes[2] = nodes[1]+(totalXElems+1);
         nodes[3] = nodes[2]-1;

         RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
         mesh.addElement(ed,block);
      }
   }
}
void MultiBlockMeshFactory::buildBlock(stk::ParallelMachine parallelMach,int xBlock,int yBlock,STK_Interface & mesh) const
{
   int myXElems_start = (machRank_==0 ? 0 : 2);
   int myXElems_end  = (machRank_==0 ? 1 : 3);
   int myYElems_start = 0;
   int myYElems_end  = 1;
   int totalXElems = nXElems_*2;
   int totalYElems = nYElems_*1;

   double x0_ = 0.0;
   double xf_ = 1.0;
   double y0_ = 0.0;
   double yf_ = 1.0;
   double deltaX = (xf_-x0_)/double(totalXElems);
   double deltaY = (yf_-y0_)/double(totalYElems);
 
   std::vector<double> coord(2,0.0);

   // build the nodes
   for(int nx=myXElems_start;nx<myXElems_end+1;++nx) {
      coord[0] = double(nx)*deltaX+x0_;
      for(int ny=myYElems_start;ny<myYElems_end+1;++ny) {
         coord[1] = double(ny)*deltaY+y0_;

         mesh.addNode(ny*(totalXElems+1)+nx+1,coord);
      }
   }

   std::stringstream blockName;
   blockName << "eblock-" << xBlock << "_" << yBlock;
   stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());

   // build the elements
   for(int nx=myXElems_start;nx<myXElems_end;++nx) {
      for(int ny=myYElems_start;ny<myYElems_end;++ny) {
         stk::mesh::EntityId gid = totalXElems*ny+nx+1;
         std::vector<stk::mesh::EntityId> nodes(4);
         nodes[0] = nx+1+ny*(totalXElems+1);
         nodes[1] = nodes[0]+1;
         nodes[2] = nodes[1]+(totalXElems+1);
         nodes[3] = nodes[2]-1;

         RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
         mesh.addElement(ed,block);
      }
   }
}
  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 SculptMeshFactory::buildBlock(stk_classic::ParallelMachine parallelMach,STK_Interface & mesh, int block_index, int *block_id, int elm_start, int *elements, int *nodes_per_element, int *elem_attributes, int **elmt_node_linkage ) const
{

  struct MeshStorageStruct *mss = get_sculpt_mesh();

   // add blocks     
   std::stringstream blockName;
   blockName << "eblock-" << block_id[block_index];
   stk_classic::mesh::Part * block = mesh.getElementBlockPart(blockName.str());


   buildNodes( parallelMach, mesh );

 
    // read element block properties
    //read element connectivity information into a temporary array
      if(elements[block_index]) {
       int maximum_nodes = elements[block_index] * nodes_per_element[block_index];
       elmt_node_linkage[block_index]        = new int[maximum_nodes];
       for(int ict = 0;ict < elements[block_index]; ict ++){
         std::vector<stk_classic::mesh::EntityId> nodes(nodes_per_element[block_index]);
         //std::cout<<"Element id = "<<elm_start+ ict<<std::endl;
         //std::cout<<"Element global id = "<<mss->global_element_numbers[elm_start+ ict-1]<<std::endl;
         for(int nct = 0; nct < nodes_per_element[block_index]; nct++){
            elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct] = mss->elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct];
            nodes[nct] =  mss->global_node_numbers[elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct]-1];
            //std::cout<<" Node linkage id = "<<elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct]<<std::endl;
            //std::cout<<" Node global  id = "<<nodes[nct]<<std::endl;
         }

         stk_classic::mesh::EntityId gid = mss->global_element_numbers[elm_start+ ict-1];
         RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
         mesh.addElement(ed,block);
       }
      }
      else {
        elmt_node_linkage[block_index] = NULL;
     }
}
void CubeTetMeshFactory::buildTetsOnHex(const Teuchos::Tuple<int,3> & meshDesc,
                                        const Teuchos::Tuple<int,3> & element,
                                        stk_classic::mesh::Part * block,
                                        const std::vector<stk_classic::mesh::EntityId> & h_nodes, 
                                        STK_Interface & mesh) const
{
   Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
   out.setShowProcRank(true);
   out.setOutputToRootOnly(-1);

   int totalXElems = meshDesc[0]; int totalYElems = meshDesc[1]; int totalZElems = meshDesc[2];
   int nx = element[0]; int ny = element[1]; int nz = element[2];

   stk_classic::mesh::EntityId hex_id = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
   stk_classic::mesh::EntityId gid_0 = 12*(hex_id-1)+1;
   std::vector<stk_classic::mesh::EntityId> nodes(4);

   // add centroid node
   stk_classic::mesh::EntityId centroid = 0;
   {
      stk_classic::mesh::EntityId largestNode = (totalXElems+1)*(totalYElems+1)*(totalZElems+1);
      centroid = hex_id+largestNode;

      // compute average of coordinates
      std::vector<double> coord(3,0.0);
      for(std::size_t i=0;i<h_nodes.size();i++) {
         const double * node_coord = mesh.getNodeCoordinates(h_nodes[i]);
         coord[0] += node_coord[0];
         coord[1] += node_coord[1];
         coord[2] += node_coord[2];
      }
      coord[0] /= 8.0;
      coord[1] /= 8.0;
      coord[2] /= 8.0;
 
      mesh.addNode(centroid,coord);
   }

   // 
   int idSet[][3] = { { 0, 1, 2}, // back
                      { 0, 2, 3}, 
                      { 0, 5, 1}, // bottom
                      { 0, 4, 5},
                      { 0, 7, 4}, // left
                      { 0, 3, 7},
                      { 6, 1, 5}, // right
                      { 6, 2, 1},
                      { 6, 3, 2}, // top
                      { 6, 7, 3},
                      { 6, 4, 7}, // front
                      { 6, 5, 4} };

   for(int i=0;i<12;i++) {
      nodes[0] = h_nodes[idSet[i][0]];
      nodes[1] = h_nodes[idSet[i][1]];
      nodes[2] = h_nodes[idSet[i][2]];
      nodes[3] = centroid;

      // add element to mesh
      mesh.addElement(rcp(new ElementDescriptor(gid_0+i,nodes)),block);
   }
}