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>
81 return entity.template subEntity<Codim>(i).partitionType();
87 template <
class Entity>
92 return entity.template subEntity<0>(i).partitionType();
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 ,
unsigned int codim)
const 128 return codim==indexSetCodim_;
132 bool fixedSize (
int ,
int )
const 140 template<
class EntityType>
141 std::size_t
size (EntityType&)
const 147 template<
class MessageBuffer,
class EntityType>
150 buff.write(v_[indexset_.index(e)]);
157 template<
class MessageBuffer,
class EntityType>
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);
209 int owner(std::size_t i)
211 return assignment_[i];
215 std::size_t numOwners(
int rank)
const 217 return std::count(assignment_.begin(), assignment_.end(), rank);
221 std::vector<int> assignment_;
234 bool contains (
int ,
unsigned int codim)
const 236 return codim==indexSetCodim_;
240 bool fixedSize (
int ,
int )
const 249 template<
class EntityType>
250 std::size_t
size (EntityType&)
const 256 template<
class MessageBuffer,
class EntityType>
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>
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 (std::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 Helper class to provide access to subentity PartitionTypes with a run-time codimension.
Definition: globalindexset.hh:74
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
concept Entity
Model of a grid entity.
Definition: concepts/entity.hh:119
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
GlobalIndexSet(const GridView &gridview, int codim)
Constructor for a given GridView.
Definition: globalindexset.hh:326
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
Index index(const Entity &entity) const
Return the global index of a given entity.
Definition: globalindexset.hh:453
typename GridFamily::Traits::Communication Communication
A type that is a model of Dune::Communication. It provides a portable way for communication on the se...
Definition: common/grid.hh:515
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: common/gridview.hh:166
on boundary between interior and overlap
Definition: gridenums.hh:32
concept MessageBuffer
Model of a message buffer.
Definition: messagebuffer.hh:17
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:129
Calculate globally unique index over all processes in a Dune grid.
Definition: globalindexset.hh:62
auto communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir) const
Communicate data on this view.
Definition: common/gridview.hh:292
MapId2Index globalIndex_
Stores global index of entities with entity's globally unique id as key.
Definition: globalindexset.hh:512
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:375
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:143
concept GridView
Model of a grid view.
Definition: concepts/gridview.hh:75
const IndexSet & indexSet() const
obtain the index set
Definition: common/gridview.hh:177
communicate as given in InterfaceType
Definition: gridenums.hh:171
const GridView gridview_
Definition: globalindexset.hh:500
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
all interior entities
Definition: gridenums.hh:31
Grid view abstract base class.
Definition: common/gridview.hh:65
send all and receive all entities
Definition: gridenums.hh:91
Include standard header files.
Definition: agrid.hh:59
int size(int codim) const
obtain number of entities in a given codimension
Definition: common/gridview.hh:183
IndexMap localGlobalMap_
Definition: globalindexset.hh:508
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:77
static constexpr int dimension
The dimension of the grid.
Definition: common/gridview.hh:134
Traits ::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:86
Traits ::Grid Grid
type of the grid
Definition: common/gridview.hh:83
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
unsigned int codim_
Codimension of the entities that we hold indices for.
Definition: globalindexset.hh:503
Describes the parallel communication interface class for MessageBuffers and DataHandles.
const Communication & comm() const
obtain communication object
Definition: common/gridview.hh:273
Wrapper class for entities.
Definition: common/entity.hh:65
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:94
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
concept IndexSet
Model of an index set.
Definition: concepts/indexidset.hh:55