Exemplo n.º 1
0
void buildLocalIds(const STK_Interface & mesh,
                   std::map<std::string,Teuchos::RCP<std::vector<std::size_t> > > & localIds)
{
   // defines ordering of blocks
   std::vector<std::string> blockIds;
   mesh.getElementBlockNames(blockIds);

   std::vector<std::string>::const_iterator idItr;
   for(idItr=blockIds.begin();idItr!=blockIds.end();++idItr) {
      std::string blockId = *idItr;

      localIds[blockId] = Teuchos::rcp(new std::vector<std::size_t>);
      std::vector<std::size_t> & localBlockIds = *localIds[blockId];

      // grab elements on this block
      std::vector<stk::mesh::Entity*> blockElmts;
      mesh.getMyElements(blockId,blockElmts);

      std::vector<stk::mesh::Entity*>::const_iterator itr;
      for(itr=blockElmts.begin();itr!=blockElmts.end();++itr)
         localBlockIds.push_back(mesh.elementLocalId(*itr));

      std::sort(localBlockIds.begin(),localBlockIds.end());
   }
}
  void
  CustomMeshFactory::fillSolutionFieldData(STK_Interface &mesh) const
  {
    for (int blk=0;blk<NumBlocks_;++blk) {

      std::stringstream block_id;
      block_id << "eblock-" << blk;
      
      // elements in this processor for this block
      std::vector<stk_classic::mesh::Entity*> elements;    
      mesh.getMyElements(block_id.str(), elements);

      // size of elements in the current block
      std::size_t n_elements = elements.size();
      
      // build local element index
      std::vector<std::size_t> local_ids;
      for (std::vector<stk_classic::mesh::Entity*>::const_iterator
             itr=elements.begin();itr!=elements.end();++itr) 
        local_ids.push_back(mesh.elementLocalId(*itr));

      // re-index solution fields in the same order of local_ids
      std::vector<double> charge_density_by_local_ids, electric_potential_by_local_ids;
      for (std::vector<stk_classic::mesh::Entity*>::const_iterator
             itr=elements.begin();itr!=elements.end();++itr) {
        int q = (*itr)->identifier() - OffsetToGlobalElementIDs_;
        for (int k=0;k<8;++k) {
          int loc = q*8 + k;
          charge_density_by_local_ids.push_back(ChargeDensity_[loc]);
          electric_potential_by_local_ids.push_back(ElectricPotential_[loc]);
        }
      }

      // wrap the buffer with a proper container
      FieldContainer charge_density(n_elements, 8, &charge_density_by_local_ids[0]),
        electric_potential(n_elements, 8, &electric_potential_by_local_ids[0]);

      // write out to stk mesh
      mesh.setSolutionFieldData("CHARGE_DENSITY",
                                block_id.str(),
                                local_ids,
                                charge_density, 1.0);
      
      mesh.setSolutionFieldData("ELECTRIC_POTENTIAL",
                                block_id.str(),
                                local_ids,
                                electric_potential, 1.0);
    }
  }