Esempio n. 1
0
BlockNamesType RefinerUtil::correctBlockNamesForPartPartConsistency(percept::PerceptMesh& eMesh, BlockNamesType& blocks)
{
  if (EXTRA_PRINT_UR_GETBLOCKS) std::cout << "RefinerUtil::correctBlockNamesForPartPartConsistency..." << std::endl;

  if (blocks[eMesh.element_rank()].size() == 0)
    return blocks;

  stk_classic::mesh::EntityRank subDimRank = (eMesh.get_spatial_dim() == 3 ? eMesh.face_rank() : eMesh.edge_rank());

  mesh::PartVector all_parts = eMesh.get_fem_meta_data()->get_parts();
  for (mesh::PartVector::iterator i_part = all_parts.begin(); i_part != all_parts.end(); ++i_part)
  {
    mesh::Part *  part = *i_part ;

    for (mesh::PartVector::iterator i_surfacePart = all_parts.begin(); i_surfacePart != all_parts.end(); ++i_surfacePart)
    {
      mesh::Part *  surfacePart = *i_surfacePart ;
      if ( stk_classic::mesh::is_auto_declared_part(*surfacePart) )
        continue;

      const CellTopologyData * part_cell_topo_data = stk_classic::percept::PerceptMesh::get_cell_topology(*surfacePart);
      CellTopology surf_topo(part_cell_topo_data);
      //if (EXTRA_PRINT_UR_GETBLOCKS) std::cout << "tmp srk surfacePart= " << surfacePart->name() << " topo= " << (part_cell_topo_data?surf_topo.getName() : "NULL") << std::endl;

      if (part_cell_topo_data && part->primary_entity_rank() == eMesh.element_rank() && surfacePart->primary_entity_rank() == subDimRank)
      {
        std::string partNamePlus = "+" + part->name();
        std::vector<std::string>::iterator partInBlocks = std::find(blocks[eMesh.element_rank()].begin(), blocks[eMesh.element_rank()].end(), partNamePlus);
        // if this part is not in the blocks list, skip it
        if (partInBlocks == blocks[eMesh.element_rank()].end())
        {
          //if (EXTRA_PRINT_UR_GETBLOCKS) std::cout << "tmp srk skipping part= " << partNamePlus << std::endl;
          continue;
        }
        std::string surfacePartNamePlus = "+" + surfacePart->name();
        std::vector<std::string>::iterator surfacePartInBlocks = std::find(blocks[subDimRank].begin(), blocks[subDimRank].end(), surfacePartNamePlus);
        // if this surface is already in the list, skip it
        if (surfacePartInBlocks != blocks[subDimRank].end())
        {
          //if (EXTRA_PRINT_UR_GETBLOCKS) std::cout << "tmp srk skipping surf= " << surfacePartNamePlus << std::endl;
          continue;
        }
        bool isBoundarySurface= eMesh.isBoundarySurface(*part, *surfacePart);
        
        if (EXTRA_PRINT_UR_GETBLOCKS) std::cout << "tmp srk isBoundarySurface for part/surf= " << part->name() << " / " << surfacePart->name() << " = " << isBoundarySurface << std::endl;
        if (isBoundarySurface)
        {
          if (EXTRA_PRINT_UR_GETBLOCKS) std::cout << "tmp part [" << part->name() << "] shares sideset [" << surfacePart->name() << "]" << std::endl;
          blocks[subDimRank].push_back(std::string("+"+surfacePart->name()));
        }
        else
        {
          //std::cout << "tmp part [" << part->name() << "] doesn't shares sideset [" << surfacePart->name() << "]" << std::endl;
        }
      }
    }
  }
  if (0) std::cout << "tmp RefinerUtil::correctBlockNamesForPartPartConsistency: blocks = " << blocks << std::endl;
  return blocks;
}  
Esempio n. 2
0
    void Colorer::
    color(percept::PerceptMesh& eMesh, unsigned * elementType,  stk_classic::mesh::PartVector* fromParts, stk_classic::mesh::FieldBase *element_color_field)
    {
      const unsigned MAX_COLORS=1000;
      vector< ColorerNodeSetType > node_colors(MAX_COLORS+1); 
      ColorerElementSetType all_elements; 

      mesh::Selector selector(eMesh.get_fem_meta_data()->universal_part());
      if (fromParts) 
        {
          if (0)
            {
              std::cout << "tmp Colorer::color fromParts= " << *fromParts << std::endl;
              std::cout << "tmp Colorer::color elementType= " << *elementType << std::endl;
              for (unsigned i_part = 0; i_part < fromParts->size(); i_part++)
                {
                  std::cout << "tmp Colorer::color i_part = " << i_part << " fromParts= " << (*fromParts)[i_part]->name() << std::endl;
                }
            }

          selector = mesh::selectUnion(*fromParts);
        }

      stk_classic::mesh::BulkData& bulkData = *eMesh.get_bulk_data();
      unsigned ncolor = 0;
      int nelem = 0;
      unsigned num_max_colors = MAX_COLORS;
      if (m_noColoring)
        num_max_colors = 1;
      
      m_element_colors = vector< ColorerSetType > (num_max_colors+1);

      for (unsigned icolor = 0; icolor < num_max_colors; icolor++)
        {
          int num_colored_this_pass = 0;
          for (unsigned irank = 0; irank < m_entityRanks.size(); irank++)
            {
              const vector<stk_classic::mesh::Bucket*> & buckets = bulkData.buckets( m_entityRanks[irank] );
              for ( vector<stk_classic::mesh::Bucket*>::const_iterator k = buckets.begin() ; k != buckets.end() ; ++k ) 
                {
                  if (selector(**k))  
                  {
                    stk_classic::mesh::Bucket & bucket = **k ;

                    bool doThisBucket = true;
                    const CellTopologyData * const bucket_cell_topo_data = stk_classic::percept::PerceptMesh::get_cell_topology(bucket);
                    shards::CellTopology topo(bucket_cell_topo_data);
                    if (elementType && (topo.getKey() != *elementType))
                      {
                        doThisBucket = false;
                      }

                    if (0 && doThisBucket)
                      {
                        std::cout << "tmp color = " << icolor << " bucket topo name= " << topo.getName() << " key= " << topo.getKey() 
                                  << " elementType= " << (elementType?  *elementType : 0) << " doThisBucket= " << doThisBucket << std::endl;
                      }

                    if (doThisBucket)
                      {
                        const unsigned num_elements_in_bucket = bucket.size();
                        nelem += num_elements_in_bucket;
                
                        for (unsigned iElement = 0; iElement < num_elements_in_bucket; iElement++)
                          {
                            stk_classic::mesh::Entity& element = bucket[iElement];

                            if (0)
                              std::cout << "tmp color = " << icolor << " bucket topo name= " << topo.getName() << " key= " << topo.getKey() 
                                        << " elementId = " << element.identifier() << " element = " << element << std::endl;

                            stk_classic::mesh::EntityId elem_id = element.identifier();
                            
                            if (!m_noColoring && contains(all_elements, elem_id))
                              continue;

                            bool none_in_this_color = true;
                            static std::vector<stk_classic::mesh::EntityId> node_ids(100);
                            unsigned num_node = 0;

                            if (!m_noColoring)
                              {
                                const stk_classic::mesh::PairIterRelation elem_nodes = element.relations( stk_classic::mesh::fem::FEMMetaData::NODE_RANK );  
                                num_node = elem_nodes.size(); 
                                node_ids.reserve(num_node);
                                for (unsigned inode=0; inode < num_node; inode++)
                                  {
                                    stk_classic::mesh::Entity & node = *elem_nodes[ inode ].entity();
                                    stk_classic::mesh::EntityId nid = node.identifier();
                                    node_ids[inode] = nid;
                                    if (contains(node_colors[icolor], nid))
                                      {
                                        none_in_this_color = false;
                                        break;
                                      }
                                  }
                              }
                            if (none_in_this_color)
                              {
                                ++num_colored_this_pass;
                                if (element_color_field)
                                  {
                                    double *fdata = stk_classic::mesh::field_data( *static_cast<const percept::ScalarFieldType *>(element_color_field) , element );
                                    fdata[0] = double(icolor);
                                  }
#if STK_ADAPT_COLORER_SET_TYPE_USE_VECTOR
                                m_element_colors[icolor].push_back(&element);
#else
                                m_element_colors[icolor].insert(&element);
#endif
                                if (!m_noColoring)
                                  {
                                    all_elements.insert(elem_id);
                                    for (unsigned inode=0; inode < num_node; inode++)
                                      {
                                        node_colors[icolor].insert(node_ids[inode]);
                                      }
                                  }
                              }
                          }  // elements in bucket
                      } // doThisBucket
                  } // selection
                } // buckets
            } // irank
          if (0 == num_colored_this_pass)
            {
              break;
            }
          ++ncolor;
          if (ncolor == num_max_colors-1)
            {
              throw std::runtime_error("broken algorithm in mesh colorer");
            }
        } // icolor

      //std::cout << "tmp ncolor = " << ncolor << " nelem= " << nelem << std::endl;

      m_element_colors.resize(ncolor);
    }