~pefarrell/dolfin/r7060

« back to all changes in this revision

Viewing changes to dolfin/mesh/Mesh.cpp

  • Committer: Garth N. Wells
  • Date: 2012-10-27 22:06:18 UTC
  • mfrom: (7004.1.30 phdf5)
  • Revision ID: gnw20@cam.ac.uk-20121027220618-es4bw3lx2lzi8sj1
Merge HDF5 branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
484
484
std::size_t Mesh::hash() const
485
485
{
486
486
  // Compute hash based on the Cantor pairing function
487
 
  size_t k1 = _topology.hash();
488
 
  size_t k2 = _geometry.hash();
489
 
  return (k1 + k2)*(k1 + k2 + 1) / 2 + k2;
 
487
  const std::size_t k1 = _topology.hash();
 
488
  const std::size_t k2 = _geometry.hash();
 
489
  return (k1 + k2)*(k1 + k2 + 1)/2 + k2;
490
490
}
491
491
//-----------------------------------------------------------------------------
492
492
std::string Mesh::str(bool verbose) const
517
517
  return s.str();
518
518
}
519
519
//-----------------------------------------------------------------------------
520
 
uint Mesh::num_owned_vertices() const
521
 
{
522
 
  Timer t("Calculate num owned vertices");
523
 
 
524
 
  const std::map<uint, std::set<uint> >& shared_vertices
525
 
    = topology().shared_entities(0);
526
 
 
527
 
  const uint process_number = MPI::process_number();
528
 
 
529
 
  uint num_local_vertices = num_vertices();
530
 
 
531
 
  for(std::map<uint, std::set<uint> >::const_iterator 
532
 
      shared_v_it = shared_vertices.begin();
533
 
      shared_v_it != shared_vertices.end();
534
 
      shared_v_it++)
535
 
  {
536
 
    const std::set<uint>& procs = shared_v_it->second;
537
 
    // Determine whether this vertex is also on a lower numbered process
538
 
    if(*(procs.begin()) < process_number) 
539
 
      num_local_vertices--;
540
 
  }
541
 
 
542
 
  return num_local_vertices;
543
 
}
544
 
 
545
 
//-----------------------------------------------------------------------------
546
 
std::vector<uint> Mesh::owned_vertices() const
547
 
{
548
 
  Timer t("Calculate owned vertices");
549
 
 
550
 
  const std::map<uint, std::set<uint> >& shared_vertices
551
 
    = topology().shared_entities(0);
552
 
 
553
 
  const uint process_number = MPI::process_number();
554
 
 
555
 
  std::vector<uint>result;
556
 
  result.reserve(num_vertices());
557
 
  
558
 
  for(VertexIterator v(*this); !v.end(); ++v)
559
 
  {
560
 
    uint global_index = v->global_index();
561
 
    if(shared_vertices.count(global_index) != 0)
562
 
    {
563
 
      const std::set<uint>& procs = 
564
 
        shared_vertices.find(global_index)->second;
565
 
        
566
 
      // Determine whether the first element of 
567
 
      // this set refers to a higher numbered process.
568
 
      // If so, the vertex is owned here.
569
 
      if(*(procs.begin()) > process_number)
570
 
        result.push_back(v->index());
571
 
    }
572
 
    else // not a shared vertex
573
 
      result.push_back(v->index());
574
 
  }
575
 
 
576
 
  return result;
577
 
}