From 008257303682512c4da912defd831550baa9ad54 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Mon, 26 May 2014 04:30:36 +0000
Subject: [PATCH] Do not use an iterator over the entities we want a global
 numbering for

Iterators over entities are only mandatory for vertices and elements.
But here the user may also request indices for other entities.
Hence one cannot use a straight iterator.

[[Imported from SVN: r9759]]
---
 dune/gfe/parallel/globalindex.hh           | 56 +++++++++++++---------
 dune/gfe/parallel/uniqueentitypartition.hh | 11 +++++
 2 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/dune/gfe/parallel/globalindex.hh b/dune/gfe/parallel/globalindex.hh
index 7978dc97..80d11aa1 100644
--- a/dune/gfe/parallel/globalindex.hh
+++ b/dune/gfe/parallel/globalindex.hh
@@ -73,7 +73,7 @@ private:
 
   typedef typename GridView::Grid::GlobalIdSet GlobalIdSet;
   typedef typename GridView::Grid::GlobalIdSet::IdType IdType;
-  typedef typename GridView::Traits::template Codim<CODIM>::Iterator Iterator;
+  typedef typename GridView::Traits::template Codim<0>::Iterator Iterator;
   typedef typename GridView::Traits::template Codim<CODIM>::Entity Entity;
 
 
@@ -196,9 +196,7 @@ public:
     nLocalEntity_=0;
     nGlobalEntity_=0;
 
-    for(Iterator iter = gridview_.template begin<CODIM>();iter!=gridview_.template end<CODIM>(); ++iter)
-	if(uniqueEntityPartition_.owner((*iter)) == true)
-	    ++nLocalEntity_;
+    nLocalEntity_ = uniqueEntityPartition_.numOwners();
 
 
     /** compute the global, non-redundant number of entities, i.e. the number of entities in the set
@@ -255,27 +253,41 @@ public:
 
     int globalcontrib=0;    /** initialize contribution for the global index */
 
-    for(Iterator iter = gridview_.template begin<CODIM>();iter!=gridview_.template end<CODIM>(); ++iter)
+    std::vector<bool> firstTime(gridview_.size(CODIM));
+    std::fill(firstTime.begin(), firstTime.end(), true);
+
+    for(Iterator iter = gridview_.template begin<0>();iter!=gridview_.template end<0>(); ++iter)
+    {
+      for (size_t i=0; i<iter->template count<CODIM>(); i++)
       {
-	IdType id=globalIdSet.id(*iter);                 /** retrieve the entity's id */
-
-	if(uniqueEntityPartition_.owner(*iter) == true)  /** if the entity is owned by the process, go ahead with computing the global index */
-	  {
-	    const int gindex = myoffset + globalcontrib;    /** compute global index */
-	    globalIndex.insert(std::make_pair(id,gindex)); /** insert pair (key, dataum) into the map */
-
-	    const int lindex = indexSet.index(*iter);
-	    localGlobalMap_[lindex] = gindex;
-	    globalLocalMap_[gindex] = lindex;
-
-	    globalcontrib++;                                /** increment contribution to global index */
-	  }
-	else /** if entity is not owned, insert -1 to signal not yet calculated global index */
-	  {
-	    globalIndex.insert(std::make_pair(id,-1));
-	  }
+        IdType id=globalIdSet.subId(*iter,i,CODIM);                 /** retrieve the entity's id */
+
+        int idx = gridview_.indexSet().subIndex(*iter,i,CODIM);
+
+        if (! firstTime[idx] )
+          continue;
+
+        firstTime[idx] = false;
+
+        if(uniqueEntityPartition_.owner(idx) == true)  /** if the entity is owned by the process, go ahead with computing the global index */
+        {
+          const int gindex = myoffset + globalcontrib;    /** compute global index */
+          globalIndex.insert(std::make_pair(id,gindex)); /** insert pair (key, value) into the map */
+
+          const int lindex = idx;
+          localGlobalMap_[lindex] = gindex;
+          globalLocalMap_[gindex] = lindex;
+
+          globalcontrib++;                                /** increment contribution to global index */
+        }
+        else /** if entity is not owned, insert -1 to signal not yet calculated global index */
+        {
+          globalIndex.insert(std::make_pair(id,-1));
+        }
       }
 
+    }
+
     /** 2nd stage of global index calculation: communicate global index for non-owned entities */
 
     // Create the data handle and communicate.
diff --git a/dune/gfe/parallel/uniqueentitypartition.hh b/dune/gfe/parallel/uniqueentitypartition.hh
index af307a65..232c18d8 100644
--- a/dune/gfe/parallel/uniqueentitypartition.hh
+++ b/dune/gfe/parallel/uniqueentitypartition.hh
@@ -148,6 +148,17 @@ public:
         }
   }
 
+  /** answer question if entity belongs to me, to this process */
+  bool owner(size_t i)
+  {
+    return assignment_[i];
+  }
+
+  size_t numOwners() const
+  {
+    return std::accumulate(assignment_.begin(), assignment_.end(), 0);
+  }
+
   /** answer question if entity belongs to me, to this process */
   bool owner(const Entity& entity)
   {
-- 
GitLab