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 typedef typename GFSV::Traits::GridViewType GridView;
75 static const int dim = GridView::dimension;
76 typedef typename GridView::Traits::Grid Grid;
77 typedef typename Matrix::block_type BlockType;
78 typedef typename GridView::template Codim<dim>::Iterator VertexIterator;
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 GFSV::Traits::GridView::Grid::GlobalIdSet::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 , _grid_view(grid_operator.testGridFunctionSpace().
gridView())
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(),
178 end_it = pattern.end();
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>
206 size_type
size(
const Entity&
e)
const
210 for (size_type i = 0; i < _entity_cache.
size(); ++i)
212 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
213 if (!transfer_dof(i,it))
215 n += it->second.size();
221 template<
typename Buffer,
typename Entity>
225 for (size_type i = 0; i < _entity_cache.
size(); ++i)
227 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
228 if (!transfer_dof(i,it))
230 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
231 col_end = it->second.end();
234 buf.write(std::make_pair(_entity_cache.
dofIndex(i).treeIndex(),*col_it));
238 template<
typename Buffer,
typename Entity>
242 for (size_type i = 0; i < _entity_cache.
size(); ++i)
244 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
245 if (!transfer_dof(i,it))
247 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
248 col_end = it->second.end();
252 typename BaseT::EntityIndex col_entity = this->
index(col_it->entityID());
255 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,col_entity.geometryTypeIndex(),col_entity.entityIndex(),col_it->treeIndex());
256 buf.write(make_tuple(_entity_cache.
dofIndex(i).treeIndex(),*col_it,matrix(_entity_cache.
containerIndex(i),_gfsu.ordering().mapIndex(dj))));
263 bool transfer_dof(size_type i,
typename BorderPattern::const_iterator it)
const
266 if (it == _border_pattern.end())
289 template<
typename Pattern>
291 :
public CommDataHandleIF<PatternExtender<Pattern>, PatternMPIData>
294 typedef std::size_t size_type;
304 (_gfsu.dataHandleContains(codim) ||
305 _gfsv.dataHandleContains(codim));
315 template<
typename Entity>
318 if (Entity::codimension == 0)
321 return _communication_cache.
size(e);
326 template<
typename MessageBuffer,
typename Entity>
327 void gather (MessageBuffer& buff,
const Entity&
e)
const
329 if (Entity::codimension == 0)
337 template<
typename MessageBuffer,
typename Entity>
338 void scatter (MessageBuffer& buff,
const Entity&
e,
size_t n)
340 if (Entity::codimension == 0)
343 for (size_type i = 0; i < n; ++i)
348 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.
findIndex(data.second.entityID());
349 if (!col_index.first)
353 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
355 _grid_view.indexSet().index(e),
359 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
360 col_index.second.geometryTypeIndex(),
361 col_index.second.entityIndex(),
362 data.second.treeIndex());
364 _pattern.add_link(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj));
373 , _grid_view(dof_exchanger.
gridView())
391 :
public CommDataHandleIF<EntryAccumulator,ValueMPIData>
394 typedef std::size_t size_type;
404 (_gfsu.dataHandleContains(codim) ||
405 _gfsv.dataHandleContains(codim));
413 template<
typename Entity>
416 if (Entity::codimension == 0)
419 return _communication_cache.
size(e);
422 template<
typename MessageBuffer,
typename Entity>
423 void gather(MessageBuffer& buff,
const Entity&
e)
const
425 if (Entity::codimension == 0)
433 template<
typename MessageBuffer,
typename Entity>
434 void scatter(MessageBuffer& buff,
const Entity&
e, size_type n)
436 if (Entity::codimension == 0)
439 for (size_type i = 0; i < n; ++i)
444 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.
findIndex(get<1>(data).entityID());
445 if (!col_index.first)
449 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
451 _grid_view.indexSet().index(e),
455 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
456 col_index.second.geometryTypeIndex(),
457 col_index.second.entityIndex(),
458 get<1>(data).treeIndex());
460 _matrix(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj)) += get<2>(data);
470 , _grid_view(dof_exchanger.
gridView())
494 if (_grid_view.comm().size() > 1)
500 _grid_view.communicate(data_handle,
501 InteriorBorder_InteriorBorder_Interface,
502 ForwardCommunication);
508 return *_communication_cache;
513 return *_communication_cache;
518 return _communication_cache;
528 shared_ptr<CommunicationCache> _communication_cache;
534 template<
typename Gr
idOperator>
570 template<
typename Gr
idOperator>
589 #endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:506
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:123
NoDataBorderDOFExchanger CommunicationCache
Definition: borderdofexchanger.hh:540
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: gridoperator.hh:87
size_type size(Entity &e) const
How many objects of type DataType have to be sent for a given entity.
Definition: borderdofexchanger.hh:316
void update()
Definition: borderdofexchanger.hh:158
std::pair< bool, EntityIndex > findIndex(id_type entity_id) const
Definition: borderindexidcache.hh:135
size_type size(const Entity &e) const
Definition: borderdofexchanger.hh:206
EntityIndex index(id_type entity_id) const
Definition: borderindexidcache.hh:125
A DataHandle class to exchange matrix entries.
Definition: borderdofexchanger.hh:390
A DataHandle class to exchange matrix sparsity patterns.
Definition: borderdofexchanger.hh:290
void gather_pattern(Buffer &buf, const Entity &e) const
Definition: borderdofexchanger.hh:222
Definition: borderindexidcache.hh:25
PatternExtender(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Pattern &pattern)
Definition: borderdofexchanger.hh:368
JF JacobianField
The field type of the jacobian.
Definition: gridoperatorutilities.hh:69
void update()
Definition: borderindexidcache.hh:88
const E & e
Definition: interpolate.hh:172
size_type size(Entity &e) const
Definition: borderdofexchanger.hh:414
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:110
Definition: globaldofindex.hh:14
Definition: borderdofexchanger.hh:571
Definition: borderdofexchanger.hh:128
Standard grid operator implementation.
Definition: gridoperator.hh:34
const DI & dofIndex(size_type i) const
Definition: entityindexcache.hh:58
PatternMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:298
const BorderPattern & pattern() const
Definition: borderdofexchanger.hh:166
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:564
bool initialized() const
Definition: borderdofexchanger.hh:148
NonOverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Constructor. Sets up the local to global relations.
Definition: borderdofexchanger.hh:118
void accumulateBorderEntries(const GridOperator &grid_operator, typename GridOperator::Traits::Jacobian &matrix)
Definition: borderdofexchanger.hh:551
Helper class for adding up matrix entries on border.
Definition: borderdofexchanger.hh:66
const GridView & gridView() const
Definition: borderdofexchanger.hh:521
void gather(MessageBuffer &buff, const Entity &e) const
Pack data from user to message buffer.
Definition: borderdofexchanger.hh:327
NoDataBorderDOFExchanger()
Definition: borderdofexchanger.hh:545
OverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:580
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: gridoperator.hh:93
void finishInitialization()
Definition: borderdofexchanger.hh:153
IdType EntityID
Definition: borderdofexchanger.hh:144
void gather(MessageBuffer &buff, const Entity &e) const
Definition: borderdofexchanger.hh:423
const CI & containerIndex(size_type i) const
Definition: entityindexcache.hh:64
Definition: borderdofexchanger.hh:535
GFSU TrialGridFunctionSpace
The trial grid function space.
Definition: gridoperatorutilities.hh:37
shared_ptr< CommunicationCache > communicationCacheStorage()
Definition: borderdofexchanger.hh:516
void accumulateBorderEntries(const GridOperator &grid_operator, Matrix &matrix)
Sums up the entries corresponding to border vertices.
Definition: borderdofexchanger.hh:492
void gather_data(Buffer &buf, const Entity &e, const M &matrix) const
Definition: borderdofexchanger.hh:239
Definition: adaptivity.hh:27
void update(const Entity &e)
Definition: entityindexcache.hh:49
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:559
Empty BorderPattern
Data structure for storing border-border matrix pattern entries in a communication-optimized form...
Definition: borderdofexchanger.hh:543
EntryAccumulator(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Matrix &matrix)
Definition: borderdofexchanger.hh:465
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 contains(int dim, int codim) const
Definition: borderdofexchanger.hh:400
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:554
void scatter(MessageBuffer &buff, const Entity &e, size_type n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:434
GFSU::Ordering::Traits::DOFIndex::TreeIndex ColumnTreeIndex
Definition: borderdofexchanger.hh:145
NoDataBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:548
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:300
void addEntries(const LFSVCache &lfsv_cache, const LFSUCache &lfsu_cache, const LocalPattern &pattern)
Definition: borderdofexchanger.hh:173
OverlappingBorderDOFExchanger()
Definition: borderdofexchanger.hh:577
GFSV TestGridFunctionSpace
The test grid function space.
Definition: gridoperatorutilities.hh:40
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:511
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:33
void scatter(MessageBuffer &buff, const Entity &e, size_t n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:338
size_type size() const
Definition: entityindexcache.hh:74
CommunicationCache(const GridOperator &go)
Definition: borderdofexchanger.hh:137
ValueMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:398
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
bool fixedsize(int dim, int codim) const
Definition: borderdofexchanger.hh:408
bool fixedsize(int dim, int codim) const
Definition: borderdofexchanger.hh:308
std::size_t size_type
Definition: borderdofexchanger.hh:146