35#ifndef DUNE_GRID_UTILITY_GLOBALINDEXSET_HH
36#define DUNE_GRID_UTILITY_GLOBALINDEXSET_HH
53 #include <dune/common/parallel/mpihelper.hh>
61 template<
class Gr
idView>
73 template <
class Entity,
int Codim>
87 template <
class Entity>
100 typedef typename GridView::Grid::GlobalIdSet GlobalIdSet;
101 typedef typename GridView::Grid::GlobalIdSet::IdType IdType;
102 typedef typename GridView::Traits::template Codim<0>::Iterator Iterator;
106 typedef std::map<IdType,Index> MapId2Index;
107 typedef std::map<Index,Index> IndexMap;
113 class UniqueEntityPartition
117 template<
class IS,
class V>
118 class MinimumExchange
123 typedef typename V::value_type DataType;
126 bool contains (
int dim,
unsigned int codim)
const
128 return codim==indexSetCodim_;
132 bool fixedSize (
int dim,
int codim)
const
140 template<
class EntityType>
141 size_t size (EntityType& e)
const
147 template<
class MessageBuffer,
class EntityType>
148 void gather (MessageBuffer& buff,
const EntityType& e)
const
150 buff.write(v_[indexset_.index(e)]);
157 template<
class MessageBuffer,
class EntityType>
158 void scatter (MessageBuffer& buff,
const EntityType& e,
size_t n)
163 v_[indexset_.index(e)] =
std::min(x,v_[indexset_.index(e)]);
167 MinimumExchange (
const IS& indexset, V& v,
unsigned int indexSetCodim)
168 : indexset_(indexset),
170 indexSetCodim_(indexSetCodim)
176 unsigned int indexSetCodim_;
182 UniqueEntityPartition (
const GridView& gridview,
unsigned int codim)
183 : assignment_(gridview.
size(codim))
189 for (
auto it = gridview.template begin<0>(); it!=gridview.template end<0>(); ++it)
190 for (
unsigned int i=0; i<it->subEntities(codim); i++)
196 assignment_[gridview.indexSet().subIndex(*it,i,codim)]
198 ? gridview.comm().rank()
203 MinimumExchange<IndexSet,std::vector<Index> > dh(gridview.indexSet(),assignment_,codim);
211 return assignment_[i];
215 size_t numOwners(
int rank)
const
217 return std::count(assignment_.begin(), assignment_.end(), rank);
221 std::vector<int> assignment_;
234 bool contains (
int dim,
unsigned int codim)
const
236 return codim==indexSetCodim_;
240 bool fixedSize (
int dim,
int codim)
const
249 template<
class EntityType>
250 size_t size (EntityType& e)
const
256 template<
class MessageBuffer,
class EntityType>
257 void gather (MessageBuffer& buff,
const EntityType& e)
const
259 IdType
id=globalidset_.id(e);
261 if (indexSetCodim_==0)
262 buff.write(mapid2entity_[
id]);
264 buff.write((*mapid2entity_.find(
id)).second);
271 template<
class MessageBuffer,
class EntityType>
272 void scatter (MessageBuffer& buff,
const EntityType& entity,
size_t n)
285 const IdType
id = globalidset_.id(entity);
287 if (indexSetCodim_==0)
288 mapid2entity_[id] = x;
291 mapid2entity_.erase(
id);
292 mapid2entity_.insert(std::make_pair(
id,x));
294 const Index lindex = indexSet_.index(entity);
301 IndexExchange (
const GlobalIdSet& globalidset, MapId2Index& mapid2entity,
303 unsigned int indexSetCodim)
304 : globalidset_(globalidset),
305 mapid2entity_(mapid2entity),
306 indexSet_(localIndexSet),
308 indexSetCodim_(indexSetCodim)
312 const GlobalIdSet& globalidset_;
313 MapId2Index& mapid2entity_;
317 unsigned int indexSetCodim_;
330 int rank = gridview.
comm().rank();
335 std::unique_ptr<UniqueEntityPartition> uniqueEntityPartition;
337 uniqueEntityPartition = std::make_unique<UniqueEntityPartition>(gridview,
codim_);
339 int nLocalEntity = (
codim_==0)
340 ? std::distance(gridview.template begin<0, Dune::Interior_Partition>(), gridview.template end<0, Dune::Interior_Partition>())
341 : uniqueEntityPartition->numOwners(rank);
352 std::vector<int> offset(
size);
353 std::fill(offset.begin(), offset.end(), 0);
356 gridview_.
comm().template allgather<int>(&nLocalEntity, 1, offset.data());
359 for (
int i=1; i<rank+1; i++)
360 myoffset += offset[i-1];
381 const GlobalIdSet& globalIdSet =
gridview_.
grid().globalIdSet();
383 Index globalcontrib = 0;
387 for (Iterator iter =
gridview_.template begin<0>(); iter!=
gridview_.template end<0>(); ++iter)
389 const IdType
id = globalIdSet.id(*iter);
394 const Index gindex = myoffset + globalcontrib;
410 std::fill(firstTime.begin(), firstTime.end(),
true);
412 for(Iterator iter =
gridview_.template begin<0>();iter!=
gridview_.template end<0>(); ++iter)
414 for (
size_t i=0; i<iter->subEntities(
codim_); i++)
416 IdType
id=globalIdSet.subId(*iter,i,
codim_);
420 if (!firstTime[idx] )
423 firstTime[idx] =
false;
425 if (uniqueEntityPartition->owner(idx) == rank)
427 const Index gindex = myoffset + globalcontrib;
430 const Index lindex = idx;
452 template <
class Entity>
458 const GlobalIdSet& globalIdSet =
gridview_.
grid().globalIdSet();
459 const IdType
id = globalIdSet.id(entity);
473 template <
class Entity>
479 const GlobalIdSet& globalIdSet =
gridview_.
grid().globalIdSet();
480 const IdType
id = globalIdSet.subId(entity,i,codim);
494 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:30
@ InteriorEntity
all interior entities
Definition: gridenums.hh:31
@ BorderEntity
on boundary between interior and overlap
Definition: gridenums.hh:32
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:171
@ All_All_Interface
send all and receive all entities
Definition: gridenums.hh:91
const IndexSet & indexSet() const
obtain the index set
Definition: common/gridview.hh:191
Traits::Grid Grid
type of the grid
Definition: common/gridview.hh:83
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: common/gridview.hh:180
Traits::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:86
int size(int codim) const
obtain number of entities in a given codimension
Definition: common/gridview.hh:197
auto communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir) const
Communicate data on this view.
Definition: common/gridview.hh:299
const Communication & comm() const
obtain communication object
Definition: common/gridview.hh:280
static constexpr int dimension
The dimension of the grid.
Definition: common/gridview.hh:148
Include standard header files.
Definition: agrid.hh:60
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:207
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:131
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:193
Wrapper class for entities.
Definition: common/entity.hh:66
PartitionType partitionType() const
Partition type of this entity.
Definition: common/entity.hh:127
Grid abstract base class.
Definition: common/grid.hh:375
detected_or_fallback_t< DeprecatedCollectiveCommunication_t, Communication_t, typename GridFamily::Traits > Communication
A type that is a model of Dune::Communication. It provides a portable way for communication on the se...
Definition: common/grid.hh:525
Grid view abstract base class.
Definition: common/gridview.hh:66
Calculate globally unique index over all processes in a Dune grid.
Definition: globalindexset.hh:63
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:474
MapId2Index globalIndex_
Stores global index of entities with entity's globally unique id as key.
Definition: globalindexset.hh:512
int Index
The number type used for global indices
Definition: globalindexset.hh:66
int nGlobalEntity_
Global number of entities, i.e. number of entities without rendundant entities on interprocessor boun...
Definition: globalindexset.hh:506
Index index(const Entity &entity) const
Return the global index of a given entity.
Definition: globalindexset.hh:453
unsigned int codim_
Codimension of the entities that we hold indices for.
Definition: globalindexset.hh:503
IndexMap localGlobalMap_
Definition: globalindexset.hh:508
unsigned int size(unsigned int codim) const
Return the total number of entities over all processes that we have indices for.
Definition: globalindexset.hh:494
GlobalIndexSet(const GridView &gridview, int codim)
Constructor for a given GridView.
Definition: globalindexset.hh:326
const GridView gridview_
Definition: globalindexset.hh:500
Helper class to provide access to subentity PartitionTypes with a run-time codimension.
Definition: globalindexset.hh:75
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:78
static PartitionType get(const Entity &entity, int codim, int i)
Definition: globalindexset.hh:90