Skip to content
Snippets Groups Projects
Commit 00825730 authored by Oliver Sander's avatar Oliver Sander Committed by sander
Browse files

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]]
parent 8ea612fd
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ private: ...@@ -73,7 +73,7 @@ private:
typedef typename GridView::Grid::GlobalIdSet GlobalIdSet; typedef typename GridView::Grid::GlobalIdSet GlobalIdSet;
typedef typename GridView::Grid::GlobalIdSet::IdType IdType; 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; typedef typename GridView::Traits::template Codim<CODIM>::Entity Entity;
...@@ -196,9 +196,7 @@ public: ...@@ -196,9 +196,7 @@ public:
nLocalEntity_=0; nLocalEntity_=0;
nGlobalEntity_=0; nGlobalEntity_=0;
for(Iterator iter = gridview_.template begin<CODIM>();iter!=gridview_.template end<CODIM>(); ++iter) nLocalEntity_ = uniqueEntityPartition_.numOwners();
if(uniqueEntityPartition_.owner((*iter)) == true)
++nLocalEntity_;
/** compute the global, non-redundant number of entities, i.e. the number of entities in the set /** compute the global, non-redundant number of entities, i.e. the number of entities in the set
...@@ -255,27 +253,41 @@ public: ...@@ -255,27 +253,41 @@ public:
int globalcontrib=0; /** initialize contribution for the global index */ 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 */ IdType id=globalIdSet.subId(*iter,i,CODIM); /** 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 */ int idx = gridview_.indexSet().subIndex(*iter,i,CODIM);
{
const int gindex = myoffset + globalcontrib; /** compute global index */ if (! firstTime[idx] )
globalIndex.insert(std::make_pair(id,gindex)); /** insert pair (key, dataum) into the map */ continue;
const int lindex = indexSet.index(*iter); firstTime[idx] = false;
localGlobalMap_[lindex] = gindex;
globalLocalMap_[gindex] = lindex; if(uniqueEntityPartition_.owner(idx) == true) /** if the entity is owned by the process, go ahead with computing the global index */
{
globalcontrib++; /** increment contribution to global index */ const int gindex = myoffset + globalcontrib; /** compute global index */
} globalIndex.insert(std::make_pair(id,gindex)); /** insert pair (key, value) into the map */
else /** if entity is not owned, insert -1 to signal not yet calculated global index */
{ const int lindex = idx;
globalIndex.insert(std::make_pair(id,-1)); 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 */ /** 2nd stage of global index calculation: communicate global index for non-owned entities */
// Create the data handle and communicate. // Create the data handle and communicate.
......
...@@ -148,6 +148,17 @@ public: ...@@ -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 */ /** answer question if entity belongs to me, to this process */
bool owner(const Entity& entity) bool owner(const Entity& entity)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment