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>
85 template <
class Entity>
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::make_unique<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
Describes the parallel communication interface class for MessageBuffers and DataHandles.
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
@ InteriorEntity
all interior entities
Definition: gridenums.hh:29
@ BorderEntity
on boundary between interior and overlap
Definition: gridenums.hh:30
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:169
@ All_All_Interface
send all and receive all entities
Definition: gridenums.hh:89
int size(int codim) const
obtain number of entities in a given codimension
Definition: common/gridview.hh:178
Traits ::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:80
void communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir) const
Communicate data on this view.
Definition: common/gridview.hh:265
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: common/gridview.hh:161
const CollectiveCommunication & comm() const
obtain collective communication object
Definition: common/gridview.hh:246
Traits ::Grid Grid
type of the grid
Definition: common/gridview.hh:77
const IndexSet & indexSet() const
obtain the index set
Definition: common/gridview.hh:172
@ dimension
The dimension of the grid.
Definition: common/gridview.hh:127
Include standard header files.
Definition: agrid.hh:59
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:76
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:205
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:129
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:191
Wrapper class for entities.
Definition: common/entity.hh:64
PartitionType partitionType() const
Partition type of this entity.
Definition: common/entity.hh:129
Grid abstract base class.
Definition: common/grid.hh:373
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:519
Grid view abstract base class.
Definition: common/gridview.hh:60
Calculate globally unique index over all processes in a Dune grid.
Definition: globalindexset.hh:61
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
MapId2Index globalIndex_
Stores global index of entities with entity's globally unique id as key.
Definition: globalindexset.hh:510
int Index
The number type used for global indices
Definition: globalindexset.hh:64
int nGlobalEntity_
Global number of entities, i.e. number of entities without rendundant entities on interprocessor boun...
Definition: globalindexset.hh:504
Index index(const Entity &entity) const
Return the global index of a given entity.
Definition: globalindexset.hh:451
unsigned int codim_
Codimension of the entities that we hold indices for.
Definition: globalindexset.hh:501
IndexMap localGlobalMap_
Definition: globalindexset.hh:506
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
GlobalIndexSet(const GridView &gridview, int codim)
Constructor for a given GridView.
Definition: globalindexset.hh:324
const GridView gridview_
Definition: globalindexset.hh:498
Helper class to provide access to subentity PartitionTypes with a run-time codimension.
Definition: globalindexset.hh:73
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
static PartitionType get(const Entity &entity, int codim, int i)
Definition: globalindexset.hh:88