3 #ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH 4 #define DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH 9 #include <unordered_map> 10 #include <unordered_set> 12 #include <dune/common/deprecated.hh> 13 #include <dune/common/parallel/mpihelper.hh> 14 #include <dune/common/tuples.hh> 16 #include <dune/geometry/typeindex.hh> 17 #include <dune/grid/common/gridenums.hh> 18 #include <dune/grid/common/datahandleif.hh> 65 template<
typename Gr
idOperator>
74 using EntitySet =
typename GFSV::Traits::EntitySet;
75 static const int dim = EntitySet::dimension;
76 using Grid =
typename EntitySet::Traits::GridView::Traits::Grid;
77 typedef typename Matrix::block_type BlockType;
78 typedef typename Grid::Traits::GlobalIdSet IdSet;
79 typedef typename IdSet::IdType IdType;
83 typename GFSV::Ordering::Traits::DOFIndex::value_type,
84 GFSV::Ordering::Traits::DOFIndex::max_depth,
85 typename IdSet::IdType
90 typedef std::unordered_map<
91 typename GFSV::Ordering::Traits::DOFIndex,
92 std::unordered_set<GlobalDOFIndex>
96 typedef typename GFSV::Ordering::Traits::DOFIndex RowDOFIndex;
97 typedef typename GFSU::Ordering::Traits::DOFIndex ColDOFIndex;
100 typename RowDOFIndex::TreeIndex,
101 typename BorderPattern::mapped_type::value_type
105 typename RowDOFIndex::TreeIndex,
106 typename BorderPattern::mapped_type::value_type,
107 typename M::field_type
119 , _entity_set(grid_operator.testGridFunctionSpace().
entitySet())
124 _communication_cache = std::make_shared<CommunicationCache>(grid_operator);
137 : BaseT(go.testGridFunctionSpace())
138 , _gfsu(go.trialGridFunctionSpace())
139 , _initialized(false)
140 , _entity_cache(go.testGridFunctionSpace())
160 _border_pattern.clear();
161 _initialized =
false;
168 return _border_pattern;
171 template<
typename LFSVCache,
typename LFSUCache,
typename LocalPattern>
172 void addEntries(
const LFSVCache& lfsv_cache,
const LFSUCache& lfsu_cache,
const LocalPattern&
pattern)
176 for (
typename LocalPattern::const_iterator it = pattern.begin(),
177 end_it = pattern.end();
182 if (lfsv_cache.isConstrained(it->i()) || lfsu_cache.isConstrained(it->j()))
185 const typename LFSVCache::DOFIndex& di = lfsv_cache.dofIndex(it->i());
186 const typename LFSUCache::DOFIndex& dj = lfsu_cache.dofIndex(it->j());
188 size_type row_gt_index = GFSV::Ordering::Traits::DOFIndexAccessor::geometryType(di);
189 size_type row_entity_index = GFSV::Ordering::Traits::DOFIndexAccessor::entityIndex(di);
191 size_type col_gt_index = GFSU::Ordering::Traits::DOFIndexAccessor::geometryType(dj);
192 size_type col_entity_index = GFSU::Ordering::Traits::DOFIndexAccessor::entityIndex(dj);
199 _border_pattern[di].insert(GlobalDOFIndex(this->
id(col_gt_index,col_entity_index),dj.treeIndex()));
204 template<
typename Entity>
205 size_type
size(
const Entity&
e)
const 207 if (!_gfsu.entitySet().contains(e))
211 for (size_type i = 0; i < _entity_cache.
size(); ++i)
213 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
214 if (!transfer_dof(i,it))
216 n += it->second.size();
222 template<
typename Buffer,
typename Entity>
225 if (!_gfsu.entitySet().contains(e))
228 for (size_type i = 0; i < _entity_cache.
size(); ++i)
230 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
231 if (!transfer_dof(i,it))
233 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
234 col_end = it->second.end();
237 buf.write(std::make_pair(_entity_cache.
dofIndex(i).treeIndex(),*col_it));
241 template<
typename Buffer,
typename Entity>
244 if (!_gfsu.entitySet().contains(e))
247 for (size_type i = 0; i < _entity_cache.
size(); ++i)
249 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
250 if (!transfer_dof(i,it))
252 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
253 col_end = it->second.end();
257 typename BaseT::EntityIndex col_entity = this->
index(col_it->entityID());
260 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,col_entity.geometryTypeIndex(),col_entity.entityIndex(),col_it->treeIndex());
261 buf.write(make_tuple(_entity_cache.
dofIndex(i).treeIndex(),*col_it,matrix(_entity_cache.
containerIndex(i),_gfsu.ordering().mapIndex(dj))));
268 bool transfer_dof(size_type i,
typename BorderPattern::const_iterator it)
const 271 if (it == _border_pattern.end())
294 template<
typename Pattern>
296 :
public CommDataHandleIF<PatternExtender<Pattern>, PatternMPIData>
309 (_gfsu.dataHandleContains(codim) ||
310 _gfsv.dataHandleContains(codim));
320 template<
typename Entity>
323 if (Entity::codimension == 0)
326 return _communication_cache.size(e);
331 template<
typename MessageBuffer,
typename Entity>
332 void gather (MessageBuffer& buff,
const Entity&
e)
const 334 if (Entity::codimension == 0)
337 _communication_cache.gather_pattern(buff,e);
342 template<
typename MessageBuffer,
typename Entity>
343 void scatter (MessageBuffer& buff,
const Entity&
e,
size_t n)
345 if (Entity::codimension == 0)
348 for (size_type i = 0; i < n; ++i)
353 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.findIndex(data.second.entityID());
354 if (!col_index.first)
358 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
360 _entity_set.indexSet().index(e),
364 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
365 col_index.second.geometryTypeIndex(),
366 col_index.second.entityIndex(),
367 data.second.treeIndex());
369 _pattern.add_link(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj));
387 const EntitySet _entity_set;
396 :
public CommDataHandleIF<EntryAccumulator,ValueMPIData>
409 (_gfsu.dataHandleContains(codim) ||
410 _gfsv.dataHandleContains(codim));
418 template<
typename Entity>
421 if (Entity::codimension == 0)
424 return _communication_cache.size(e);
427 template<
typename MessageBuffer,
typename Entity>
428 void gather(MessageBuffer& buff,
const Entity&
e)
const 430 if (Entity::codimension == 0)
433 _communication_cache.gather_data(buff,e,_matrix);
438 template<
typename MessageBuffer,
typename Entity>
439 void scatter(MessageBuffer& buff,
const Entity&
e, size_type n)
441 if (Entity::codimension == 0)
444 for (size_type i = 0; i < n; ++i)
449 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.findIndex(get<1>(data).entityID());
450 if (!col_index.first)
454 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
456 _entity_set.indexSet().index(e),
460 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
461 col_index.second.geometryTypeIndex(),
462 col_index.second.entityIndex(),
463 get<1>(data).treeIndex());
465 _matrix(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj)) += get<2>(data);
484 EntitySet _entity_set;
499 if (_entity_set.gridView().comm().size() > 1)
505 _entity_set.gridView().communicate(data_handle,
506 InteriorBorder_InteriorBorder_Interface,
507 ForwardCommunication);
513 return *_communication_cache;
518 return *_communication_cache;
523 return _communication_cache;
533 shared_ptr<CommunicationCache> _communication_cache;
534 EntitySet _entity_set;
539 template<
typename Gr
idOperator>
575 template<
typename Gr
idOperator>
594 #endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH A DataHandle class to exchange matrix sparsity patterns.
Definition: borderdofexchanger.hh:295
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:511
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:122
GFSV TestGridFunctionSpace
The test grid function space.
Definition: gridoperatorutilities.hh:40
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:33
NoDataBorderDOFExchanger CommunicationCache
Definition: borderdofexchanger.hh:545
size_type size() const
Definition: entityindexcache.hh:74
size_type size(Entity &e) const
How many objects of type DataType have to be sent for a given entity.
Definition: borderdofexchanger.hh:321
JF JacobianField
The field type of the jacobian.
Definition: gridoperatorutilities.hh:69
void update()
Definition: borderdofexchanger.hh:157
size_type size(const Entity &e) const
Definition: borderdofexchanger.hh:205
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: gridoperator.hh:121
Definition: borderdofexchanger.hh:576
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: gridoperator.hh:115
void gather_pattern(Buffer &buf, const Entity &e) const
Definition: borderdofexchanger.hh:223
PatternExtender(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Pattern &pattern)
Definition: borderdofexchanger.hh:373
size_type size(Entity &e) const
Definition: borderdofexchanger.hh:419
Definition: adaptivity.hh:27
Definition: globaldofindex.hh:14
PatternMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:303
const BorderPattern & pattern() const
Definition: borderdofexchanger.hh:165
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:569
bool initialized() const
Definition: borderdofexchanger.hh:147
NonOverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Constructor. Sets up the local to global relations.
Definition: borderdofexchanger.hh:117
void accumulateBorderEntries(const GridOperator &grid_operator, typename GridOperator::Traits::Jacobian &matrix)
Definition: borderdofexchanger.hh:556
Definition: borderdofexchanger.hh:127
EntityIndex index(id_type entity_id) const
Definition: borderindexidcache.hh:128
const Entity & e
Definition: localfunctionspace.hh:111
Definition: borderdofexchanger.hh:540
void gather(MessageBuffer &buff, const Entity &e) const
Pack data from user to message buffer.
Definition: borderdofexchanger.hh:332
NoDataBorderDOFExchanger()
Definition: borderdofexchanger.hh:550
OverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:585
const DI & dofIndex(size_type i) const
Definition: entityindexcache.hh:58
void finishInitialization()
Definition: borderdofexchanger.hh:152
IdType EntityID
Definition: borderdofexchanger.hh:143
void gather(MessageBuffer &buff, const Entity &e) const
Definition: borderdofexchanger.hh:428
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:113
shared_ptr< CommunicationCache > communicationCacheStorage()
Definition: borderdofexchanger.hh:521
GFSU TrialGridFunctionSpace
The trial grid function space.
Definition: gridoperatorutilities.hh:37
Standard grid operator implementation.
Definition: gridoperator.hh:52
void accumulateBorderEntries(const GridOperator &grid_operator, Matrix &matrix)
Sums up the entries corresponding to border vertices.
Definition: borderdofexchanger.hh:497
void gather_data(Buffer &buf, const Entity &e, const M &matrix) const
Definition: borderdofexchanger.hh:242
void update(const Entity &e)
Definition: entityindexcache.hh:49
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:564
Empty BorderPattern
Data structure for storing border-border matrix pattern entries in a communication-optimized form...
Definition: borderdofexchanger.hh:548
Helper class for adding up matrix entries on border.
Definition: borderdofexchanger.hh:66
EntryAccumulator(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Matrix &matrix)
Definition: borderdofexchanger.hh:470
std::unordered_map< typename GFSV::Ordering::Traits::DOFIndex, std::unordered_set< GlobalDOFIndex > > BorderPattern
Data structure for storing border-border matrix pattern entries in a communication-optimized form...
Definition: borderdofexchanger.hh:93
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:405
void update()
Definition: borderindexidcache.hh:91
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:559
void scatter(MessageBuffer &buff, const Entity &e, size_type n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:439
GFSU::Ordering::Traits::DOFIndex::TreeIndex ColumnTreeIndex
Definition: borderdofexchanger.hh:144
NoDataBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:553
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:305
void addEntries(const LFSVCache &lfsv_cache, const LFSUCache &lfsu_cache, const LocalPattern &pattern)
Definition: borderdofexchanger.hh:172
OverlappingBorderDOFExchanger()
Definition: borderdofexchanger.hh:582
A DataHandle class to exchange matrix entries.
Definition: borderdofexchanger.hh:395
const CI & containerIndex(size_type i) const
Definition: entityindexcache.hh:64
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:516
void scatter(MessageBuffer &buff, const Entity &e, size_t n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:343
CommunicationCache(const GridOperator &go)
Definition: borderdofexchanger.hh:136
ValueMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:403
Definition: borderindexidcache.hh:27
bool fixedsize(int dim, int codim) const
Definition: borderdofexchanger.hh:413
bool fixedsize(int dim, int codim) const
Definition: borderdofexchanger.hh:313
const EntitySet & entitySet() const
Definition: borderdofexchanger.hh:526
std::size_t size_type
Definition: borderdofexchanger.hh:145