3#ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH
4#define DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH
9#include <unordered_map>
10#include <unordered_set>
13#include <dune/common/deprecated.hh>
14#include <dune/common/parallel/mpihelper.hh>
16#include <dune/geometry/typeindex.hh>
18#include <dune/grid/common/datahandleif.hh>
19#include <dune/grid/common/gridenums.hh>
66 template<
typename Gr
idOperator>
75 using EntitySet =
typename GFSV::Traits::EntitySet;
76 static const int dim = EntitySet::dimension;
77 using Grid =
typename EntitySet::Traits::GridView::Traits::Grid;
78 typedef typename Matrix::block_type BlockType;
79 typedef typename Grid::Traits::GlobalIdSet IdSet;
80 typedef typename IdSet::IdType IdType;
84 typename GFSV::Ordering::Traits::DOFIndex::value_type,
85 GFSV::Ordering::Traits::DOFIndex::max_depth,
86 typename IdSet::IdType
91 typedef std::unordered_map<
92 typename GFSV::Ordering::Traits::DOFIndex,
93 std::unordered_set<GlobalDOFIndex>
97 typedef typename GFSV::Ordering::Traits::DOFIndex RowDOFIndex;
98 typedef typename GFSU::Ordering::Traits::DOFIndex ColDOFIndex;
101 typename RowDOFIndex::TreeIndex,
102 typename BorderPattern::mapped_type::value_type
106 typename RowDOFIndex::TreeIndex,
107 typename BorderPattern::mapped_type::value_type,
108 typename M::field_type
120 , _entity_set(grid_operator.testGridFunctionSpace().
entitySet())
125 _communication_cache = std::make_shared<CommunicationCache>(grid_operator);
138 :
BaseT(go.testGridFunctionSpace())
139 , _gfsu(go.trialGridFunctionSpace())
140 , _initialized(false)
141 , _entity_cache(go.testGridFunctionSpace())
161 _border_pattern.clear();
162 _initialized =
false;
169 return _border_pattern;
172 template<
typename LFSVCache,
typename LFSUCache,
typename LocalPattern>
173 void addEntries(
const LFSVCache& lfsv_cache,
const LFSUCache& lfsu_cache,
const LocalPattern&
pattern)
177 for (
typename LocalPattern::const_iterator it =
pattern.begin(),
183 if (lfsv_cache.isConstrained(it->i()) || lfsu_cache.isConstrained(it->j()))
186 const typename LFSVCache::DOFIndex& di = lfsv_cache.dofIndex(it->i());
187 const typename LFSUCache::DOFIndex& dj = lfsu_cache.dofIndex(it->j());
189 size_type row_gt_index = GFSV::Ordering::Traits::DOFIndexAccessor::geometryType(di);
190 size_type row_entity_index = GFSV::Ordering::Traits::DOFIndexAccessor::entityIndex(di);
192 size_type col_gt_index = GFSU::Ordering::Traits::DOFIndexAccessor::geometryType(dj);
193 size_type col_entity_index = GFSU::Ordering::Traits::DOFIndexAccessor::entityIndex(dj);
200 _border_pattern[di].insert(
GlobalDOFIndex(this->
id(col_gt_index,col_entity_index),dj.treeIndex()));
205 template<
typename Entity>
208 if (!_gfsu.entitySet().contains(e))
214 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
215 if (!transfer_dof(i,it))
217 n += it->second.size();
223 template<
typename Buffer,
typename Entity>
226 if (!_gfsu.entitySet().contains(e))
231 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
232 if (!transfer_dof(i,it))
234 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
235 col_end = it->second.end();
238 buf.write(std::make_pair(_entity_cache.
dofIndex(i).treeIndex(),*col_it));
242 template<
typename Buffer,
typename Entity>
243 void gather_data(Buffer& buf,
const Entity& e,
const M& matrix)
const
245 if (!_gfsu.entitySet().contains(e))
250 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
251 if (!transfer_dof(i,it))
253 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
254 col_end = it->second.end();
258 typename BaseT::EntityIndex col_entity = this->
index(col_it->entityID());
261 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,col_entity.geometryTypeIndex(),col_entity.entityIndex(),col_it->treeIndex());
262 buf.write(std::make_tuple(_entity_cache.
dofIndex(i).treeIndex(),*col_it,matrix(_entity_cache.
containerIndex(i),_gfsu.ordering().mapIndex(dj))));
269 bool transfer_dof(
size_type i,
typename BorderPattern::const_iterator it)
const
272 if (it == _border_pattern.end())
295 template<
typename Pattern>
297 :
public CommDataHandleIF<PatternExtender<Pattern>, PatternMPIData>
300 typedef std::size_t size_type;
310 (_gfsu.dataHandleContains(codim) ||
311 _gfsv.dataHandleContains(codim));
321 template<
typename Entity>
322 size_type
size (Entity& e)
const
324 if (Entity::codimension == 0)
327 return _communication_cache.
size(e);
332 template<
typename MessageBuffer,
typename Entity>
333 void gather (MessageBuffer& buff,
const Entity& e)
const
335 if (Entity::codimension == 0)
343 template<
typename MessageBuffer,
typename Entity>
344 void scatter (MessageBuffer& buff,
const Entity& e,
size_t n)
346 if (Entity::codimension == 0)
349 for (size_type i = 0; i < n; ++i)
354 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.
findIndex(data.second.entityID());
355 if (!col_index.first)
359 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
361 _entity_set.indexSet().index(e),
365 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
366 col_index.second.geometryTypeIndex(),
367 col_index.second.entityIndex(),
368 data.second.treeIndex());
370 _pattern.add_link(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj));
388 const EntitySet _entity_set;
397 :
public CommDataHandleIF<EntryAccumulator,ValueMPIData>
400 typedef std::size_t size_type;
410 (_gfsu.dataHandleContains(codim) ||
411 _gfsv.dataHandleContains(codim));
419 template<
typename Entity>
420 size_type
size(Entity& e)
const
422 if (Entity::codimension == 0)
425 return _communication_cache.
size(e);
428 template<
typename MessageBuffer,
typename Entity>
429 void gather(MessageBuffer& buff,
const Entity& e)
const
431 if (Entity::codimension == 0)
439 template<
typename MessageBuffer,
typename Entity>
440 void scatter(MessageBuffer& buff,
const Entity& e, size_type n)
442 if (Entity::codimension == 0)
445 for (size_type i = 0; i < n; ++i)
450 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.
findIndex(std::get<1>(data).entityID());
451 if (!col_index.first)
455 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
457 _entity_set.indexSet().index(e),
461 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
462 col_index.second.geometryTypeIndex(),
463 col_index.second.entityIndex(),
464 std::get<1>(data).treeIndex());
466 _matrix(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj)) += std::get<2>(data);
485 EntitySet _entity_set;
500 if (_entity_set.gridView().comm().size() > 1)
506 _entity_set.gridView().communicate(data_handle,
507 InteriorBorder_InteriorBorder_Interface,
508 ForwardCommunication);
514 return *_communication_cache;
519 return *_communication_cache;
524 return _communication_cache;
534 std::shared_ptr<CommunicationCache> _communication_cache;
535 EntitySet _entity_set;
540 template<
typename Gr
idOperator>
576 template<
typename Gr
idOperator>
std::size_t index
Definition: interpolate.hh:97
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:570
NoDataBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:554
EntryAccumulator(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Matrix &matrix)
Definition: borderdofexchanger.hh:471
const BorderPattern & pattern() const
Definition: borderdofexchanger.hh:166
OverlappingBorderDOFExchanger()
Definition: borderdofexchanger.hh:583
void accumulateBorderEntries(const GridOperator &grid_operator, Matrix &matrix)
Sums up the entries corresponding to border vertices.
Definition: borderdofexchanger.hh:498
CommunicationCache(const GridOperator &go)
Definition: borderdofexchanger.hh:137
void gather(MessageBuffer &buff, const Entity &e) const
Definition: borderdofexchanger.hh:429
void finishInitialization()
Definition: borderdofexchanger.hh:153
GFSU::Ordering::Traits::DOFIndex::TreeIndex ColumnTreeIndex
Definition: borderdofexchanger.hh:145
size_type size(Entity &e) const
How many objects of type DataType have to be sent for a given entity.
Definition: borderdofexchanger.hh:322
NonOverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Constructor. Sets up the local to global relations.
Definition: borderdofexchanger.hh:118
void addEntries(const LFSVCache &lfsv_cache, const LFSUCache &lfsu_cache, const LocalPattern &pattern)
Definition: borderdofexchanger.hh:173
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:565
size_type size(Entity &e) const
Definition: borderdofexchanger.hh:420
NoDataBorderDOFExchanger()
Definition: borderdofexchanger.hh:551
std::size_t size_type
Definition: borderdofexchanger.hh:146
void gather_pattern(Buffer &buf, const Entity &e) const
Definition: borderdofexchanger.hh:224
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:406
PatternExtender(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Pattern &pattern)
Definition: borderdofexchanger.hh:374
bool initialized() const
Definition: borderdofexchanger.hh:148
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:306
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:94
bool fixedSize(int dim, int codim) const
Definition: borderdofexchanger.hh:414
OverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:586
NoDataBorderDOFExchanger CommunicationCache
Definition: borderdofexchanger.hh:546
size_type size(const Entity &e) const
Definition: borderdofexchanger.hh:206
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:512
PatternMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:304
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:123
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:517
void gather(MessageBuffer &buff, const Entity &e) const
Pack data from user to message buffer.
Definition: borderdofexchanger.hh:333
std::shared_ptr< CommunicationCache > communicationCacheStorage()
Definition: borderdofexchanger.hh:522
void gather_data(Buffer &buf, const Entity &e, const M &matrix) const
Definition: borderdofexchanger.hh:243
void accumulateBorderEntries(const GridOperator &grid_operator, typename GridOperator::Traits::Jacobian &matrix)
Definition: borderdofexchanger.hh:557
const EntitySet & entitySet() const
Definition: borderdofexchanger.hh:527
bool fixedSize(int dim, int codim) const
Definition: borderdofexchanger.hh:314
void scatter(MessageBuffer &buff, const Entity &e, size_t n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:344
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:560
IdType EntityID
Definition: borderdofexchanger.hh:144
ValueMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:404
void scatter(MessageBuffer &buff, const Entity &e, size_type n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:440
Empty BorderPattern
Data structure for storing border-border matrix pattern entries in a communication-optimized form.
Definition: borderdofexchanger.hh:549
void update()
Definition: borderdofexchanger.hh:158
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:113
void update()
Definition: borderindexidcache.hh:91
std::pair< bool, EntityIndex > findIndex(id_type entity_id) const
Definition: borderindexidcache.hh:138
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Definition: borderindexidcache.hh:28
Definition: globaldofindex.hh:15
Definition: entityindexcache.hh:18
size_type size() const
Definition: entityindexcache.hh:75
const CI & containerIndex(size_type i) const
Definition: entityindexcache.hh:65
const DI & dofIndex(size_type i) const
Definition: entityindexcache.hh:59
void update(const Entity &e)
Definition: entityindexcache.hh:50
Helper class for adding up matrix entries on border.
Definition: borderdofexchanger.hh:68
Definition: borderdofexchanger.hh:130
A DataHandle class to exchange matrix sparsity patterns.
Definition: borderdofexchanger.hh:298
A DataHandle class to exchange matrix entries.
Definition: borderdofexchanger.hh:398
Definition: borderdofexchanger.hh:542
Definition: borderdofexchanger.hh:579
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:34
JF JacobianField
The field type of the jacobian.
Definition: gridoperatorutilities.hh:69
GFSU TrialGridFunctionSpace
The trial grid function space.
Definition: gridoperatorutilities.hh:37
GFSV TestGridFunctionSpace
The test grid function space.
Definition: gridoperatorutilities.hh:40
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
Standard grid operator implementation.
Definition: gridoperator.hh:36
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: gridoperator.hh:92
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: gridoperator.hh:98