33 #ifndef DUNE_GRID_UTILITY_GLOBALINDEXSET_HH
34 #define DUNE_GRID_UTILITY_GLOBALINDEXSET_HH
51 #include <dune/common/parallel/mpihelper.hh>
59 template<
class Gr
idView>
71 template <
class Entity,
int Codim>
79 return entity.template subEntity<Codim>(i).partitionType();
85 template <
class Entity>
90 return entity.template subEntity<0>(i).partitionType();
98 typedef typename GridView::Grid::GlobalIdSet GlobalIdSet;
99 typedef typename GridView::Grid::GlobalIdSet::IdType IdType;
100 typedef typename GridView::Traits::template Codim<0>::Iterator Iterator;
104 typedef std::map<IdType,Index> MapId2Index;
105 typedef std::map<Index,Index> IndexMap;
111 class UniqueEntityPartition
115 template<
class IS,
class V>
116 class MinimumExchange
121 typedef typename V::value_type DataType;
124 bool contains (
int dim,
unsigned int codim)
const
126 return codim==indexSetCodim_;
130 bool fixedsize (
int dim,
int codim)
const
138 template<
class EntityType>
139 size_t size (EntityType& e)
const
145 template<
class MessageBuffer,
class EntityType>
146 void gather (MessageBuffer& buff,
const EntityType& e)
const
148 buff.write(v_[indexset_.index(e)]);
155 template<
class MessageBuffer,
class EntityType>
156 void scatter (MessageBuffer& buff,
const EntityType& e,
size_t n)
161 v_[indexset_.index(e)] =
std::min(x,v_[indexset_.index(e)]);
165 MinimumExchange (
const IS& indexset, V& v,
unsigned int indexSetCodim)
166 : indexset_(indexset),
168 indexSetCodim_(indexSetCodim)
174 unsigned int indexSetCodim_;
180 UniqueEntityPartition (
const GridView& gridview,
unsigned int codim)
181 : assignment_(gridview.
size(codim))
187 for (
auto it = gridview.template begin<0>(); it!=gridview.template end<0>(); ++it)
188 for (
unsigned int i=0; i<it->subEntities(codim); i++)
194 assignment_[gridview.indexSet().subIndex(*it,i,codim)]
196 ? gridview.comm().rank()
201 MinimumExchange<IndexSet,std::vector<Index> > dh(gridview.indexSet(),assignment_,codim);
209 return assignment_[i];
213 size_t numOwners(
int rank)
const
215 return std::count(assignment_.begin(), assignment_.end(), rank);
219 std::vector<int> assignment_;
232 bool contains (
int dim,
unsigned int codim)
const
234 return codim==indexSetCodim_;
238 bool fixedsize (
int dim,
int codim)
const
247 template<
class EntityType>
248 size_t size (EntityType& e)
const
254 template<
class MessageBuffer,
class EntityType>
255 void gather (MessageBuffer& buff,
const EntityType& e)
const
257 IdType
id=globalidset_.id(e);
259 if (indexSetCodim_==0)
260 buff.write(mapid2entity_[
id]);
262 buff.write((*mapid2entity_.find(
id)).second);
269 template<
class MessageBuffer,
class EntityType>
270 void scatter (MessageBuffer& buff,
const EntityType& entity,
size_t n)
283 const IdType
id = globalidset_.id(entity);
285 if (indexSetCodim_==0)
286 mapid2entity_[id] = x;
289 mapid2entity_.erase(
id);
290 mapid2entity_.insert(std::make_pair(
id,x));
292 const Index lindex = indexSet_.index(entity);
299 IndexExchange (
const GlobalIdSet& globalidset, MapId2Index& mapid2entity,
301 unsigned int indexSetCodim)
302 : globalidset_(globalidset),
303 mapid2entity_(mapid2entity),
304 indexSet_(localIndexSet),
306 indexSetCodim_(indexSetCodim)
310 const GlobalIdSet& globalidset_;
311 MapId2Index& mapid2entity_;
315 unsigned int indexSetCodim_;
328 int rank = gridview.
comm().rank();
333 std::unique_ptr<UniqueEntityPartition> uniqueEntityPartition;
335 uniqueEntityPartition = std::unique_ptr<UniqueEntityPartition>(
new UniqueEntityPartition(gridview,
codim_));
337 int nLocalEntity = (
codim_==0)
338 ? std::distance(gridview.template begin<0, Dune::Interior_Partition>(), gridview.template end<0, Dune::Interior_Partition>())
339 : uniqueEntityPartition->numOwners(rank);
350 std::vector<int> offset(size);
351 std::fill(offset.begin(), offset.end(), 0);
354 gridview_.
comm().template allgather<int>(&nLocalEntity, 1, offset.data());
357 for (
int i=1; i<rank+1; i++)
358 myoffset += offset[i-1];
379 const GlobalIdSet& globalIdSet =
gridview_.
grid().globalIdSet();
381 Index globalcontrib = 0;
385 for (Iterator iter =
gridview_.template begin<0>(); iter!=
gridview_.template end<0>(); ++iter)
387 const IdType
id = globalIdSet.id(*iter);
392 const Index gindex = myoffset + globalcontrib;
408 std::fill(firstTime.begin(), firstTime.end(),
true);
410 for(Iterator iter =
gridview_.template begin<0>();iter!=
gridview_.template end<0>(); ++iter)
412 for (
size_t i=0; i<iter->subEntities(
codim_); i++)
414 IdType
id=globalIdSet.subId(*iter,i,
codim_);
418 if (!firstTime[idx] )
421 firstTime[idx] =
false;
423 if (uniqueEntityPartition->owner(idx) == rank)
425 const Index gindex = myoffset + globalcontrib;
428 const Index lindex = idx;
450 template <
class Entity>
456 const GlobalIdSet& globalIdSet =
gridview_.
grid().globalIdSet();
457 const IdType
id = globalIdSet.id(entity);
471 template <
class Entity>
477 const GlobalIdSet& globalIdSet =
gridview_.
grid().globalIdSet();
478 const IdType
id = globalIdSet.subId(entity,i,codim);
492 unsigned int size(
unsigned int codim)
const
Traits::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:80
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:133
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:121
Index index(const Entity &entity) const
Return the global index of a given entity.
Definition: globalindexset.hh:451
void communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir) const
Communicate data on this view.
Definition: common/gridview.hh:268
Wrapper class for entities.
Definition: common/entity.hh:61
Grid view abstract base class.
Definition: common/gridview.hh:58
on boundary between interior and overlap
Definition: gridenums.hh:30
const CollectiveCommunication & comm() const
obtain collective communication object
Definition: common/gridview.hh:249
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: common/gridview.hh:164
communicate as given in InterfaceType
Definition: gridenums.hh:169
GlobalIndexSet(const GridView &gridview, int codim)
Constructor for a given GridView.
Definition: globalindexset.hh:324
all interior entities
Definition: gridenums.hh:29
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:88
send all and receive all entities
Definition: gridenums.hh:89
IndexMap localGlobalMap_
Definition: globalindexset.hh:506
int nGlobalEntity_
Global number of entities, i.e. number of entities without rendundant entities on interprocessor boun...
Definition: globalindexset.hh:504
The dimension of the grid.
Definition: common/gridview.hh:130
unsigned int size(unsigned int codim) const
Return the total number of entities over all processes that we have indices for.
Definition: globalindexset.hh:492
Describes the parallel communication interface class for MessageBuffers and DataHandles.
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:388
Calculate globally unique index over all processes in a Dune grid.
Definition: globalindexset.hh:60
int Index
The number type used for global indices.
Definition: globalindexset.hh:64
int size(int codim) const
obtain number of entities in a given codimension
Definition: common/gridview.hh:181
Helper class to provide access to subentity PartitionTypes with a run-time codimension.
Definition: globalindexset.hh:72
const IndexSet & indexSet() const
obtain the index set
Definition: common/gridview.hh:175
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:72
GridFamily::Traits::CollectiveCommunication CollectiveCommunication
A type that is a model of Dune::CollectiveCommunication. It provides a portable way for collective co...
Definition: common/grid.hh:545
const GridView gridview_
Definition: globalindexset.hh:498
unsigned int codim_
Codimension of the entities that we hold indices for.
Definition: globalindexset.hh:501
Index subIndex(const Entity &entity, unsigned int i, unsigned int codim) const
Return the global index of a subentity of a given entity.
Definition: globalindexset.hh:472
Include standard header files.
Definition: agrid.hh:59
Traits::Grid Grid
type of the grid
Definition: common/gridview.hh:77
MapId2Index globalIndex_
Stores global index of entities with entity's globally unique id as key.
Definition: globalindexset.hh:510
static PartitionType get(const Entity &entity, int codim, int i)
Get PartitionType of the i-th subentity of codimension 'codim' of entity 'entity'.
Definition: globalindexset.hh:76
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28