3 #ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH
4 #define DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH
10 #include <dune/common/deprecated.hh>
11 #include <dune/common/parallel/mpihelper.hh>
12 #include <dune/common/tuples.hh>
14 #include <dune/geometry/typeindex.hh>
15 #include <dune/grid/common/gridenums.hh>
16 #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
92 typename GFSV::Ordering::Traits::DOFIndex,
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
118 , _grid_view(grid_operator.testGridFunctionSpace().
gridView())
123 _communication_cache = make_shared<CommunicationCache>(grid_operator);
136 :
BaseT(go.testGridFunctionSpace())
137 , _gfsu(go.trialGridFunctionSpace())
138 , _initialized(false)
139 , _entity_cache(go.testGridFunctionSpace())
159 _border_pattern.clear();
160 _initialized =
false;
167 return _border_pattern;
170 template<
typename LFSVCache,
typename LFSUCache,
typename LocalPattern>
171 void addEntries(
const LFSVCache& lfsv_cache,
const LFSUCache& lfsu_cache,
const LocalPattern&
pattern)
175 for (
typename LocalPattern::const_iterator it = pattern.begin(),
176 end_it = pattern.end();
181 if (lfsv_cache.isConstrained(it->i()) || lfsu_cache.isConstrained(it->j()))
184 const typename LFSVCache::DOFIndex& di = lfsv_cache.dofIndex(it->i());
185 const typename LFSUCache::DOFIndex& dj = lfsu_cache.dofIndex(it->j());
187 size_type row_gt_index = GFSV::Ordering::Traits::DOFIndexAccessor::geometryType(di);
188 size_type row_entity_index = GFSV::Ordering::Traits::DOFIndexAccessor::entityIndex(di);
190 size_type col_gt_index = GFSU::Ordering::Traits::DOFIndexAccessor::geometryType(dj);
191 size_type col_entity_index = GFSU::Ordering::Traits::DOFIndexAccessor::entityIndex(dj);
198 _border_pattern[di].insert(
GlobalDOFIndex(this->
id(col_gt_index,col_entity_index),dj.treeIndex()));
203 template<
typename Entity>
210 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
211 if (!transfer_dof(i,it))
213 n += it->second.size();
219 template<
typename Buffer,
typename Entity>
225 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
226 if (!transfer_dof(i,it))
228 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
229 col_end = it->second.end();
232 buf.write(std::make_pair(_entity_cache.
dofIndex(i).treeIndex(),*col_it));
236 template<
typename Buffer,
typename Entity>
242 typename BorderPattern::const_iterator it = _border_pattern.find(_entity_cache.
dofIndex(i));
243 if (!transfer_dof(i,it))
245 for (
typename BorderPattern::mapped_type::const_iterator col_it = it->second.begin(),
246 col_end = it->second.end();
250 typename BaseT::EntityIndex col_entity = this->
index(col_it->entityID());
253 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,col_entity.geometryTypeIndex(),col_entity.entityIndex(),col_it->treeIndex());
254 buf.write(make_tuple(_entity_cache.
dofIndex(i).treeIndex(),*col_it,matrix(_entity_cache.
containerIndex(i),_gfsu.ordering().mapIndex(dj))));
261 bool transfer_dof(
size_type i,
typename BorderPattern::const_iterator it)
const
264 if (it == _border_pattern.end())
287 template<
typename Pattern>
289 :
public CommDataHandleIF<PatternExtender<Pattern>, PatternMPIData>
292 typedef std::size_t size_type;
302 (_gfsu.dataHandleContains(codim) ||
303 _gfsv.dataHandleContains(codim));
313 template<
typename Entity>
316 if (Entity::codimension == 0)
319 return _communication_cache.
size(e);
324 template<
typename MessageBuffer,
typename Entity>
325 void gather (MessageBuffer& buff,
const Entity&
e)
const
327 if (Entity::codimension == 0)
335 template<
typename MessageBuffer,
typename Entity>
336 void scatter (MessageBuffer& buff,
const Entity&
e,
size_t n)
338 if (Entity::codimension == 0)
341 for (size_type i = 0; i < n; ++i)
346 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.
findIndex(data.second.entityID());
347 if (!col_index.first)
351 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
353 _grid_view.indexSet().index(e),
357 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
358 col_index.second.geometryTypeIndex(),
359 col_index.second.entityIndex(),
360 data.second.treeIndex());
362 _pattern.add_link(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj));
371 , _grid_view(dof_exchanger.
gridView())
389 :
public CommDataHandleIF<EntryAccumulator,ValueMPIData>
392 typedef std::size_t size_type;
402 (_gfsu.dataHandleContains(codim) ||
403 _gfsv.dataHandleContains(codim));
411 template<
typename Entity>
414 if (Entity::codimension == 0)
417 return _communication_cache.
size(e);
420 template<
typename MessageBuffer,
typename Entity>
421 void gather(MessageBuffer& buff,
const Entity&
e)
const
423 if (Entity::codimension == 0)
431 template<
typename MessageBuffer,
typename Entity>
432 void scatter(MessageBuffer& buff,
const Entity&
e, size_type n)
434 if (Entity::codimension == 0)
437 for (size_type i = 0; i < n; ++i)
442 std::pair<bool,typename CommunicationCache::EntityIndex> col_index = _communication_cache.
findIndex(get<1>(data).entityID());
443 if (!col_index.first)
447 GFSV::Ordering::Traits::DOFIndexAccessor::store(di,
449 _grid_view.indexSet().index(e),
453 GFSU::Ordering::Traits::DOFIndexAccessor::store(dj,
454 col_index.second.geometryTypeIndex(),
455 col_index.second.entityIndex(),
456 get<1>(data).treeIndex());
458 _matrix(_gfsv.ordering().mapIndex(di),_gfsu.ordering().mapIndex(dj)) += get<2>(data);
468 , _grid_view(dof_exchanger.
gridView())
489 if (_grid_view.comm().size() > 1)
495 _grid_view.communicate(data_handle,
496 InteriorBorder_InteriorBorder_Interface,
497 ForwardCommunication);
503 return *_communication_cache;
508 return *_communication_cache;
513 return _communication_cache;
523 shared_ptr<CommunicationCache> _communication_cache;
529 template<
typename Gr
idOperator>
565 template<
typename Gr
idOperator>
584 #endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_BORDERDOFEXCHANGER_HH
void update(const Entity &e)
Definition: entityindexcache.hh:49
const DI & dofIndex(size_type i) const
Definition: entityindexcache.hh:58
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:501
JF JacobianField
The field type of the jacobian.
Definition: gridoperatorutilities.hh:69
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:121
NoDataBorderDOFExchanger CommunicationCache
Definition: borderdofexchanger.hh:535
A DataHandle class to exchange matrix sparsity patterns.
Definition: borderdofexchanger.hh:288
Provide common name for std::unordered_map and std::unordered_multimap classes in Dune::PDELab namesp...
size_type size(Entity &e) const
How many objects of type DataType have to be sent for a given entity.
Definition: borderdofexchanger.hh:314
GFSU TrialGridFunctionSpace
The trial grid function space.
Definition: gridoperatorutilities.hh:37
void update()
Definition: borderdofexchanger.hh:156
size_type size(const Entity &e) const
Definition: borderdofexchanger.hh:204
Definition: borderdofexchanger.hh:566
Helper class for adding up matrix entries on border.
Definition: borderdofexchanger.hh:66
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:33
const CI & containerIndex(size_type i) const
Definition: entityindexcache.hh:64
void gather_pattern(Buffer &buf, const Entity &e) const
Definition: borderdofexchanger.hh:220
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:114
PatternExtender(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Pattern &pattern)
Definition: borderdofexchanger.hh:366
const GFSU & trialGridFunctionSpace() const
Get the trial grid function space.
Definition: gridoperator.hh:87
size_type size(Entity &e) const
Definition: borderdofexchanger.hh:412
Provide common name for std::unordered_set and std::unordered_multiset classes in Dune::PDELab namesp...
Definition: borderdofexchanger.hh:126
Standard grid operator implementation.
Definition: gridoperator.hh:34
PatternMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:296
const BorderPattern & pattern() const
Definition: borderdofexchanger.hh:164
void update(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:559
bool initialized() const
Definition: borderdofexchanger.hh:146
NonOverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Constructor. Sets up the local to global relations.
Definition: borderdofexchanger.hh:116
void accumulateBorderEntries(const GridOperator &grid_operator, typename GridOperator::Traits::Jacobian &matrix)
Definition: borderdofexchanger.hh:546
size_type size() const
Definition: entityindexcache.hh:74
const GridView & gridView() const
Definition: borderdofexchanger.hh:516
A DataHandle class to exchange matrix entries.
Definition: borderdofexchanger.hh:388
void gather(MessageBuffer &buff, const Entity &e) const
Pack data from user to message buffer.
Definition: borderdofexchanger.hh:325
std::pair< bool, EntityIndex > findIndex(id_type entity_id) const
Definition: borderindexidcache.hh:139
NoDataBorderDOFExchanger()
Definition: borderdofexchanger.hh:540
OverlappingBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:575
void finishInitialization()
Definition: borderdofexchanger.hh:151
IdType EntityID
Definition: borderdofexchanger.hh:142
void gather(MessageBuffer &buff, const Entity &e) const
Definition: borderdofexchanger.hh:421
shared_ptr< CommunicationCache > communicationCacheStorage()
Definition: borderdofexchanger.hh:511
void accumulateBorderEntries(const GridOperator &grid_operator, Matrix &matrix)
Sums up the entries corresponding to border vertices.
Definition: borderdofexchanger.hh:487
void gather_data(Buffer &buf, const Entity &e, const M &matrix) const
Definition: borderdofexchanger.hh:237
Definition: globaldofindex.hh:14
unordered_map< typename GFSV::Ordering::Traits::DOFIndex, unordered_set< GlobalDOFIndex > > BorderPattern
Data structure for storing border-border matrix pattern entries in a communication-optimized form...
Definition: borderdofexchanger.hh:94
void update()
Definition: borderindexidcache.hh:88
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:554
Empty BorderPattern
Data structure for storing border-border matrix pattern entries in a communication-optimized form...
Definition: borderdofexchanger.hh:538
EntryAccumulator(const NonOverlappingBorderDOFExchanger &dof_exchanger, const GFSU &gfsu, const GFSV &gfsv, Matrix &matrix)
Definition: borderdofexchanger.hh:463
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:398
Definition: borderindexidcache.hh:25
Definition: unordered_map.hh:46
const GFSV & testGridFunctionSpace() const
Get the test grid function space.
Definition: gridoperator.hh:93
CommunicationCache & communicationCache()
Definition: borderdofexchanger.hh:549
void scatter(MessageBuffer &buff, const Entity &e, size_type n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:432
Definition: borderdofexchanger.hh:530
GFSU::Ordering::Traits::DOFIndex::TreeIndex ColumnTreeIndex
Definition: borderdofexchanger.hh:143
NoDataBorderDOFExchanger(const GridOperator &grid_operator)
Definition: borderdofexchanger.hh:543
bool contains(int dim, int codim) const
Definition: borderdofexchanger.hh:298
GFSV TestGridFunctionSpace
The test grid function space.
Definition: gridoperatorutilities.hh:40
void addEntries(const LFSVCache &lfsv_cache, const LFSUCache &lfsu_cache, const LocalPattern &pattern)
Definition: borderdofexchanger.hh:171
OverlappingBorderDOFExchanger()
Definition: borderdofexchanger.hh:572
const CommunicationCache & communicationCache() const
Definition: borderdofexchanger.hh:506
void scatter(MessageBuffer &buff, const Entity &e, size_t n)
Unpack data from message buffer to user.
Definition: borderdofexchanger.hh:336
CommunicationCache(const GridOperator &go)
Definition: borderdofexchanger.hh:135
Dune::PDELab::BackendMatrixSelector< MB, Domain, Range, JF >::Type Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
ValueMPIData DataType
Export type of data for message buffer.
Definition: borderdofexchanger.hh:396
EntityIndex index(id_type entity_id) const
Definition: borderindexidcache.hh:129
const E & e
Definition: interpolate.hh:172
Definition: unordered_set.hh:45
bool fixedsize(int dim, int codim) const
Definition: borderdofexchanger.hh:406
bool fixedsize(int dim, int codim) const
Definition: borderdofexchanger.hh:306
std::size_t size_type
Definition: borderdofexchanger.hh:144