1#ifndef DUNE_MULTIDOMAINGRID_INDEXSETS_HH
2#define DUNE_MULTIDOMAINGRID_INDEXSETS_HH
5#include <unordered_map>
14#include <dune/common/hybridutilities.hh>
16#include <dune/geometry/typeindex.hh>
18#include <dune/grid/common/exceptions.hh>
19#include <dune/grid/common/indexidset.hh>
21#include <dune/grid/multidomaingrid/utility.hh>
22#include <dune/grid/multidomaingrid/subdomaingrid/indexsets.hh>
28template<
typename HostGr
id,
typename MDGr
idTraits>
36template<
template<
int>
class StructForCodim,
typename Codims>
40template<
template<
int>
class StructForCodim, std::size_t... codim>
41struct _buildMap<StructForCodim,std::index_sequence<codim...> > {
43 typedef std::tuple<StructForCodim<codim>... > type;
47template<
template<
int>
class StructForCodim,
int dimension>
50 typedef typename _buildMap<
52 decltype(std::make_index_sequence<dimension+1>())
65template<
bool doDispatch,
typename Impl,
typename resulttype,
bool alternate_dispatch>
68template<
typename Impl,
typename resulttype,
bool alternate_dispatch>
69struct invokeIf<true,Impl,resulttype,alternate_dispatch> {
71 typedef resulttype result_type;
74 result_type invoke() {
75 return _impl.template invoke<codim>();
80 invokeIf(Impl& impl) :
87template<
typename Impl,
typename resulttype>
88struct invokeIf<false,Impl, resulttype,false> {
90 typedef resulttype result_type;
93 result_type invoke() {
94 DUNE_THROW(GridError,
"codim not supported");
99 invokeIf(Impl& impl) :
105template<
typename Impl,
typename resulttype>
106struct invokeIf<false,Impl, resulttype,true> {
108 typedef resulttype result_type;
111 result_type invoke() {
112 return _impl.template invoke_unsupported<codim>();
117 invokeIf(Impl& impl) :
124template<
typename Impl,
typename resulttype,
typename MDGr
idTraits,
int codim,
bool protect = true,
bool alternate_dispatch = false>
125struct dispatchToCodim
126 :
public dispatchToCodim<Impl,resulttype,MDGridTraits,codim-1,protect,alternate_dispatch> {
128 typedef resulttype result_type;
130 result_type dispatch(
int cc) {
132 return invokeIf<MDGridTraits::template Codim<codim>::supported,Impl,result_type,alternate_dispatch>(
static_cast<Impl&
>(*this)).
template invoke<codim>();
133 return static_cast<dispatchToCodim<Impl,result_type,MDGridTraits,codim-1,protect,alternate_dispatch
>&>(*this).dispatch(cc);
139template<
typename Impl,
typename resulttype,
typename MDGr
idTraits,
bool alternate_dispatch>
140struct dispatchToCodim<Impl,resulttype,MDGridTraits,0,true,alternate_dispatch> {
142 typedef resulttype result_type;
144 result_type dispatch(
int cc) {
146 return invokeIf<MDGridTraits::template Codim<0>::supported,Impl,result_type,alternate_dispatch>(
static_cast<Impl&
>(*this)).
template invoke<0>();
147 DUNE_THROW(GridError,
"invalid codimension specified");
153template<
typename Impl,
typename resulttype,
typename MDGr
idTraits,
int codim,
bool alternate_dispatch>
154struct dispatchToCodim<Impl,resulttype,MDGridTraits,codim,false,alternate_dispatch>
155 :
public dispatchToCodim<Impl,resulttype,MDGridTraits,codim-1,false,alternate_dispatch> {
157 typedef resulttype result_type;
159 result_type dispatch(
int cc) {
161 return static_cast<Impl&
>(*this).template invoke<codim>();
162 return static_cast<dispatchToCodim<Impl,result_type,MDGridTraits,codim-1,false,alternate_dispatch
>&>(*this).dispatch(cc);
168template<
typename Impl,
typename resulttype,
typename MDGr
idTraits,
bool alternate_dispatch>
169struct dispatchToCodim<Impl,resulttype,MDGridTraits,0,false,alternate_dispatch> {
171 typedef resulttype result_type;
173 result_type dispatch(
int cc) {
175 return static_cast<Impl&
>(*this).template invoke<0>();
176 DUNE_THROW(GridError,
"invalid codimension specified");
186template<
bool doApply,
typename Impl>
189 template<
int codim,
typename T>
190 void apply(T& t)
const {
191 _impl.template apply<codim>(t);
196 applyIf(Impl& impl) :
203template<
typename Impl>
204struct applyIf<false,Impl> {
206 template<
int codim,
typename T>
207 void apply(T& t)
const {
212 applyIf(Impl& impl) :
221 return const_cast<T&
>(t);
231template<
typename Gr
idImp,
typename HostGr
idViewType>
233 public Dune::IndexSet<GridImp,IndexSetWrapper<GridImp,HostGridViewType>,
234 typename HostGridViewType::IndexSet::IndexType,
235 typename HostGridViewType::IndexSet::Types>
238 using Grid = std::remove_const_t<GridImp>;
240 template<
typename,
typename>
243 template<
typename,
typename>
246 template<
typename,
typename>
247 friend class subdomain::IndexSetWrapper;
249 template<
typename,
typename,
typename,
typename>
253 friend class SubDomainToSubDomainController;
256 friend class AllInterfacesController;
260 using HostGrid =
typename Grid::HostGrid;
261 typedef HostGridViewType HostGridView;
262 typedef typename HostGridView::IndexSet HostIndexSet;
263 using ctype =
typename Grid::ctype;
264 using CellReferenceElement = Dune::ReferenceElement<typename HostGrid::template Codim<0>::Entity::Geometry>;
266 typedef Dune::IndexSet<
272 typename HostGridViewType::IndexSet::IndexType,
273 typename HostGridViewType::IndexSet::Types
278 typedef typename BaseT::Types Types;
280 using MDGridTraits =
typename Grid::MDGridTraits;
281 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
282 typedef typename MDGridTraits::SubDomainIndex SubDomainIndex;
285 typedef typename HostIndexSet::IndexType IndexType;
286 static const int dimension = Grid::dimension;
287 static const std::size_t maxSubDomains = SubDomainSet::maxSize;
291 typedef typename HostGridView::template Codim<0>::Iterator HostEntityIterator;
292 typedef typename HostGridView::template Codim<0>::Entity HostEntity;
293 using Codim0Entity =
typename Grid::Traits::template Codim<0>::Entity;
298 typedef typename MDGridTraits::template Codim<cc>::SubDomainSet SubDomainSet;
300 SubDomainSet domains;
305 struct NotSupported {};
310 static const bool supported = Grid::MDGridTraits::template Codim<codim>::supported;
312 static_assert((codim > 0 || supported),
"index mapping of codimension 0 must be supported!");
314 using IndexMap = std::conditional_t<
316 std::vector<std::vector<MapEntry<codim> > >,
320 using SizeMap = std::conditional_t<
322 std::vector<typename Grid::MDGridTraits::template Codim<codim>::SizeContainer>,
326 using CodimSizeMap = std::conditional_t<
328 typename Grid::MDGridTraits::template Codim<codim>::SizeContainer,
332 using MultiIndexMap = std::conditional_t<
334 std::vector<typename Grid::MDGridTraits::template Codim<codim>::MultiIndexContainer>,
340 CodimSizeMap codimSizeMap;
341 MultiIndexMap multiIndexMap;
344 Containers& operator=(
const Containers&) =
delete;
347 Containers& operator=(Containers&&) =
default;
350 Containers(
const Containers&) =
default;
351 Containers(Containers&&) =
default;
352 Containers() =
default;
356 typedef typename detail::buildMap<Containers,dimension>::type ContainerMap;
358 typedef std::vector<std::shared_ptr<IndexSetWrapper<GridImp, typename HostGridView::Grid::LevelGridView> > > LevelIndexSets;
361 template<
typename Impl,
typename result_type,
bool protect = true,
bool alternate_dispatch = false>
362 struct dispatchToCodim :
public detail::dispatchToCodim<Impl,result_type,MDGridTraits,dimension,protect,alternate_dispatch> {};
368 IndexType
index(
const typename Grid::Traits::template Codim<codim>::Entity& e)
const {
369 return _hostGridView.indexSet().index(_grid.hostEntity(e));
373 template<
typename Entity>
374 IndexType
index(
const Entity& e)
const {
375 return _hostGridView.indexSet().index(_grid.hostEntity(e));
380 IndexType
subIndex(
const typename Grid::Traits::template Codim<codim>::Entity& e,
int i,
unsigned int cd)
const {
381 return _hostGridView.indexSet().template subIndex<codim>(_grid.hostEntity(e),i,cd);
385 template<
typename Entity>
386 IndexType
subIndex(
const Entity& e,
int i,
unsigned int cd)
const {
387 return _hostGridView.indexSet().subIndex(_grid.hostEntity(e),i,cd);
392 return _hostGridView.indexSet().types(codim);
396 IndexType
size(GeometryType type)
const {
397 return _hostGridView.indexSet().size(type);
401 IndexType
size(
int codim)
const {
402 return _hostGridView.indexSet().size(codim);
406 template<
typename EntityType>
408 return _hostGridView.indexSet().contains(_grid.hostEntity(e));
412 template<
typename EntityType>
413 const typename MapEntry<EntityType::codimension>::SubDomainSet&
subDomains(
const EntityType& e)
const {
414 return subDomainsForHostEntity(_grid.hostEntity(e));
420 const typename MapEntry<cc>::SubDomainSet&
subDomains(
const typename Grid::Traits::template Codim<cc>::Entity& e)
const {
421 return subDomainsForHostEntity<cc>(_grid.hostEntity(e));
425 template<
class EntityType>
426 IndexType
index(SubDomainIndex subDomain,
const EntityType& e)
const {
427 return index<EntityType::codimension>(subDomain,e);
433 IndexType
index(SubDomainIndex subDomain,
const typename Grid::Traits::template Codim<cc>::Entity& e)
const {
434 GeometryType gt = e.type();
435 IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
436 const MapEntry<cc>& me = indexMap<cc>()[LocalGeometryTypeIndex::index(gt)][hostIndex];
437 assert(me.domains.contains(subDomain));
438 if (me.domains.simple()) {
441 return multiIndexMap<cc>()[me.index][me.domains.domainOffset(subDomain)];
448 template<
typename EntityType>
449 typename MapEntry<EntityType::codimension>::SubDomainSet&
subDomains(
const EntityType& e) {
450 return subDomainsForHostEntity(_grid.hostEntity(e));
456 typename MapEntry<cc>::SubDomainSet&
subDomains(
const typename Grid::Traits::template Codim<cc>::Entity& e) {
457 return subDomainsForHostEntity<cc>(_grid.hostEntity(e));
461 template<
typename HostEntity>
462 typename MapEntry<HostEntity::codimension>::SubDomainSet& subDomainsForHostEntity(
const HostEntity& e) {
463 return subDomainsForHostEntity<HostEntity::codimension>(e);
469 typename MapEntry<cc>::SubDomainSet& subDomainsForHostEntity(
const typename Grid::HostGrid::Traits::template Codim<cc>::Entity& he) {
470 return indexMap<cc>()[LocalGeometryTypeIndex::index(he.type())][_hostGridView.indexSet().index(he)].domains;
474 template<
typename HostEntity>
475 const typename MapEntry<HostEntity::codimension>::SubDomainSet& subDomainsForHostEntity(
const HostEntity& e)
const {
476 return subDomainsForHostEntity<HostEntity::codimension>(e);
482 const typename MapEntry<cc>::SubDomainSet& subDomainsForHostEntity(
const typename Grid::HostGrid::Traits::template Codim<cc>::Entity& he)
const {
483 return indexMap<cc>()[LocalGeometryTypeIndex::index(he.type())][_hostGridView.indexSet().index(he)].domains;
487 IndexType indexForSubDomain(SubDomainIndex subDomain,
const typename Grid::HostGrid::Traits::template Codim<cc>::Entity& he)
const {
488 const GeometryType gt = he.type();
489 const IndexType hostIndex = _hostGridView.indexSet().index(he);
490 const MapEntry<cc>& me = indexMap<cc>()[LocalGeometryTypeIndex::index(gt)][hostIndex];
491 assert(me.domains.contains(subDomain));
492 if (me.domains.simple()) {
495 return multiIndexMap<cc>()[me.index][me.domains.domainOffset(subDomain)];
500 struct getSubIndexForSubDomain :
public dispatchToCodim<getSubIndexForSubDomain,IndexType> {
503 IndexType invoke()
const {
504 const MapEntry<codim>& me = _indexSet.indexMap<codim>()[LocalGeometryTypeIndex::index(_gt)][_hostIndex];
505 assert(me.domains.contains(_subDomain));
506 if (me.domains.simple()) {
509 return _indexSet.multiIndexMap<codim>()[me.index][me.domains.domainOffset(_subDomain)];
513 SubDomainIndex _subDomain;
515 IndexType _hostIndex;
516 const ThisType& _indexSet;
518 getSubIndexForSubDomain(SubDomainIndex subDomain, GeometryType gt, IndexType hostIndex,
const ThisType& indexSet) :
519 _subDomain(subDomain),
521 _hostIndex(hostIndex),
527 template<
typename HostEntity>
528 IndexType subIndexForSubDomain(SubDomainIndex subDomain,
const HostEntity& he,
int i,
int codim)
const {
529 return getSubIndexForSubDomain(subDomain,
530 referenceElement(he.geometry()).type(i,codim - he.codimension),
531 _hostGridView.indexSet().subIndex(he,i,codim),
532 *
this).dispatch(codim);
535 Types typesForSubDomain(SubDomainIndex subDomain,
int codim)
const {
539 struct getGeometryTypeSizeForSubDomain :
public dispatchToCodim<getGeometryTypeSizeForSubDomain,IndexType,true,true> {
542 IndexType invoke()
const {
543 return _indexSet.sizeMap<codim>()[LocalGeometryTypeIndex::index(_gt)][_subDomain];
547 IndexType invoke_unsupported()
const {
551 SubDomainIndex _subDomain;
553 const ThisType& _indexSet;
555 getGeometryTypeSizeForSubDomain(SubDomainIndex subDomain, GeometryType gt,
const ThisType& indexSet) :
556 _subDomain(subDomain),
563 IndexType sizeForSubDomain(SubDomainIndex subDomain, GeometryType type)
const {
564 return getGeometryTypeSizeForSubDomain(subDomain,type,*
this).dispatch(dimension-type.dim());
567 struct getCodimSizeForSubDomain :
public dispatchToCodim<getCodimSizeForSubDomain,IndexType,true,true> {
570 IndexType invoke()
const {
571 return _indexSet.codimSizes<codim>()[_subDomain];
575 IndexType invoke_unsupported()
const {
579 SubDomainIndex _subDomain;
580 const ThisType& _indexSet;
582 getCodimSizeForSubDomain(SubDomainIndex subDomain,
const ThisType& indexSet) :
583 _subDomain(subDomain),
589 IndexType sizeForSubDomain(SubDomainIndex subDomain,
int codim)
const {
590 return getCodimSizeForSubDomain(subDomain,*
this).dispatch(codim);
593 template<
typename EntityType>
594 bool containsForSubDomain(SubDomainIndex subDomain,
const EntityType& he)
const {
595 const GeometryType gt = he.type();
596 const IndexType hostIndex = _hostGridView.indexSet().index(he);
597 const MapEntry<EntityType::codimension>& me = indexMap<EntityType::codimension>()[LocalGeometryTypeIndex::index(gt)][hostIndex];
598 return me.domains.contains(subDomain);
603 template<
typename SubDomainEntity>
604 IndexType
subIndex(SubDomainIndex subDomain,
const SubDomainEntity& e,
int i,
int codim)
const {
605 return subIndexForSubDomain(subDomain,_grid.hostEntity(e),i,codim);
608 Types
types(SubDomainIndex subDomain,
int codim)
const {
612 IndexType
size(SubDomainIndex subDomain, GeometryType type)
const {
613 return sizeForSubDomain(subDomain,type);
616 IndexType
size(SubDomainIndex subDomain,
int codim)
const {
617 return sizeForSubDomain(subDomain,codim);
621 template<
typename EntityType>
622 bool contains(SubDomainIndex subDomain,
const EntityType& e)
const {
623 const GeometryType gt = e.type();
624 const IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
625 const MapEntry<EntityType::codimension>& me = indexMap<EntityType::codimension>()[LocalGeometryTypeIndex::index(gt)][hostIndex];
626 return me.domains.contains(subDomain);
631 const GridImp& _grid;
632 HostGridView _hostGridView;
633 ContainerMap _containers;
635 void swap(ThisType& rhs) {
636 assert(&_grid == &rhs._grid);
637 std::swap(_containers,rhs._containers);
640 void addToSubDomain(SubDomainIndex subDomain,
const Codim0Entity& e) {
641 GeometryType gt = e.type();
642 IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
643 indexMap<0>()[LocalGeometryTypeIndex::index(gt)][hostIndex].domains.add(subDomain);
646 void removeFromSubDomain(SubDomainIndex subDomain,
const Codim0Entity& e) {
647 GeometryType gt = e.type();
648 IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
649 indexMap<0>()[LocalGeometryTypeIndex::index(gt)][hostIndex].domains.remove(subDomain);
652 void removeFromAllSubDomains(
const Codim0Entity& e) {
653 GeometryType gt = e.type();
654 IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
655 indexMap<0>()[LocalGeometryTypeIndex::index(gt)][hostIndex].domains.clear();
658 void assignToSubDomain(SubDomainIndex subDomain,
const Codim0Entity& e) {
659 GeometryType gt = e.type();
660 IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
661 indexMap<0>()[LocalGeometryTypeIndex::index(gt)][hostIndex].domains.set(subDomain);
664 void addToSubDomains(
const typename MDGridTraits::template Codim<0>::SubDomainSet&
subDomains,
const Codim0Entity& e) {
665 GeometryType gt = e.type();
666 IndexType hostIndex = _hostGridView.indexSet().index(_grid.hostEntity(e));
667 indexMap<0>()[LocalGeometryTypeIndex::index(gt)][hostIndex].domains.addAll(
subDomains);
674 IndexSetWrapper(
const GridImp& grid, HostGridView hostGridView) :
676 _hostGridView(hostGridView)
681 explicit IndexSetWrapper(
const ThisType& rhs) :
683 _hostGridView(rhs._hostGridView),
684 _containers(rhs._containers)
691 typename Containers<cc>::IndexMap& indexMap() {
692 return std::get<cc>(_containers).indexMap;
696 typename Containers<cc>::SizeMap& sizeMap() {
697 return std::get<cc>(_containers).sizeMap;
701 typename Containers<cc>::CodimSizeMap& codimSizes() {
702 return std::get<cc>(_containers).codimSizeMap;
706 typename Containers<cc>::MultiIndexMap& multiIndexMap() {
707 return std::get<cc>(_containers).multiIndexMap;
711 const typename Containers<cc>::IndexMap& indexMap()
const {
712 return std::get<cc>(_containers).indexMap;
716 const typename Containers<cc>::SizeMap& sizeMap()
const {
717 return std::get<cc>(_containers).sizeMap;
721 const typename Containers<cc>::CodimSizeMap& codimSizes()
const {
722 return std::get<cc>(_containers).codimSizeMap;
726 const typename Containers<cc>::MultiIndexMap& multiIndexMap()
const {
727 return std::get<cc>(_containers).multiIndexMap;
730 template<
typename Functor>
731 void applyToCodims(Functor func)
const {
733 Hybrid::forEach(Dune::range(std::tuple_size<ContainerMap>{}),
734 [&](
auto i){func(i, std::get<i>(_containers));}
738 template<
typename Functor>
739 void applyToCodims(Functor func) {
741 Hybrid::forEach(Dune::range(std::tuple_size<ContainerMap>{}),
742 [&](
auto i){func(i, std::get<i>(_containers));}
746 template<
typename Impl>
747 struct applyToCodim {
749 template<
typename I,
typename T>
750 void operator()(I i, T&& t)
const {
751 const int codim = I::value;
752 detail::applyIf<MDGridTraits::template Codim<codim>::supported,
const Impl>(
static_cast<const Impl&
>(*this)).
template apply<codim>(std::forward<T>(t));
757 struct resetPerCodim :
public applyToCodim<resetPerCodim> {
760 void apply(Containers<codim>& c)
const {
762 _traits.template setupSizeContainer<codim>(c.codimSizeMap);
763 c.indexMap.resize(LocalGeometryTypeIndex::size(dimension-codim));
764 c.sizeMap.resize(LocalGeometryTypeIndex::size(dimension-codim));
765 for (
auto gt : _his.types(codim)) {
766 const auto gt_index = LocalGeometryTypeIndex::index(gt);
769 c.indexMap[gt_index].resize(_his.size(gt));
770 }
else if (codim > 0) {
774 for (
auto& mapEntry : c.indexMap[gt_index])
775 mapEntry.domains.clear();
778 auto& size_map = c.sizeMap[gt_index];
779 _traits.template setupSizeContainer<codim>(size_map);
780 std::fill(size_map.begin(),size_map.end(),0);
783 c.multiIndexMap.clear();
786 resetPerCodim(
bool full,
const HostIndexSet& his,
const MDGridTraits& traits) :
793 const HostIndexSet& _his;
794 const MDGridTraits& _traits;
797 void reset(
bool full) {
798 const HostIndexSet& his = _hostGridView.indexSet();
800 ContainerMap cm = ContainerMap();
801 std::swap(_containers,cm);
803 applyToCodims(resetPerCodim(full,his,_grid._traits));
806 struct updatePerCodimSizes :
public applyToCodim<updatePerCodimSizes> {
809 void apply(Containers<codim>& c)
const {
811 std::fill(c.codimSizeMap.begin(),c.codimSizeMap.end(),0);
813 std::for_each(c.sizeMap.begin(),
815 util::collect_elementwise<std::plus<IndexType> >(c.codimSizeMap));
820 void update(LevelIndexSets& levelIndexSets,
bool full) {
821 const HostIndexSet& his = _hostGridView.indexSet();
823 for (
auto& levelIndexSet : levelIndexSets) {
824 levelIndexSet->reset(full);
827 this->communicateSubDomainSelection();
829 auto& im = indexMap<0>();
830 auto& sm = sizeMap<0>();
831 for (
const auto& he : elements(_hostGridView)) {
833 auto geo = he.geometry();
834 auto hgt = geo.type();
835 const auto hgt_index = LocalGeometryTypeIndex::index(hgt);
836 IndexType hostIndex = his.index(he);
837 MapEntry<0>& me = im[hgt_index][hostIndex];
839 if (_grid.supportLevelIndexSets()) {
841 IndexType hostLvlIndex = levelIndexSets[he.level()]->_hostGridView.indexSet().index(he);
842 levelIndexSets[he.level()]->template indexMap<0>()[hgt_index][hostLvlIndex].domains.addAll(me.domains);
844 markAncestors(levelIndexSets,he,me.domains);
846 updateMapEntry(me,sm[hgt_index],multiIndexMap<0>());
847 applyToCodims(markSubIndices(he,me.domains,his,geo));
850 propagateBorderEntitySubDomains();
852 applyToCodims(updateSubIndices(*
this));
853 applyToCodims(updatePerCodimSizes());
854 for(
auto& levelIndexSet : levelIndexSets) {
855 levelIndexSet->updateLevelIndexSet();
860 void updateLevelIndexSet() {
861 const HostIndexSet& his = _hostGridView.indexSet();
862 typename Containers<0>::IndexMap& im = indexMap<0>();
863 typename Containers<0>::SizeMap& sm = sizeMap<0>();
865 communicateSubDomainSelection();
867 for (
const auto& he : elements(_hostGridView)) {
868 auto geo = he.geometry();
869 const GeometryType hgt = geo.type();
870 const auto hgt_index = LocalGeometryTypeIndex::index(hgt);
871 IndexType hostIndex = his.index(he);
872 MapEntry<0>& me = im[hgt_index][hostIndex];
873 updateMapEntry(me,sm[hgt_index],multiIndexMap<0>());
874 applyToCodims(markSubIndices(he,me.domains,his,geo));
877 propagateBorderEntitySubDomains();
879 applyToCodims(updateSubIndices(*
this));
880 applyToCodims(updatePerCodimSizes());
883 template<
int codim,
typename SizeContainer,
typename MultiIndexContainer>
884 void updateMapEntry(MapEntry<codim>& me, SizeContainer& sizes, std::vector<MultiIndexContainer>& multiIndexMap) {
885 switch (me.domains.state()) {
886 case MapEntry<codim>::SubDomainSet::emptySet:
888 case MapEntry<codim>::SubDomainSet::simpleSet:
889 me.index = sizes[*me.domains.begin()]++;
891 case MapEntry<codim>::SubDomainSet::multipleSet:
892 me.index = multiIndexMap.size();
893 MultiIndexContainer mic;
894 for (
const auto& subdomain : me.domains)
895 mic[me.domains.domainOffset(subdomain)] = sizes[subdomain]++;
896 multiIndexMap.push_back(std::move(mic));
900 template<
typename SubDomainSet>
901 void markAncestors(LevelIndexSets& levelIndexSets, HostEntity he,
const SubDomainSet& domains) {
902 while (he.level() > 0) {
904 SubDomainSet& fatherDomains =
905 levelIndexSets[he.level()]->template indexMap<0>()[LocalGeometryTypeIndex::index(he.type())][levelIndexSets[he.level()]->_hostGridView.indexSet().index(he)].domains;
906 if (fatherDomains.containsAll(domains))
908 fatherDomains.addAll(domains);
912 struct markSubIndices :
public applyToCodim<const markSubIndices> {
915 void apply(Containers<codim>& c)
const {
918 const int size = _refEl.size(codim);
919 for (
int i = 0; i <
size; ++i) {
920 IndexType hostIndex = _his.subIndex(_he,i,codim);
921 GeometryType gt = _refEl.type(i,codim);
922 c.indexMap[LocalGeometryTypeIndex::index(gt)][hostIndex].domains.addAll(_domains);
926 typedef typename MapEntry<0>::SubDomainSet& DomainSet;
928 const HostEntity& _he;
930 const HostIndexSet& _his;
931 CellReferenceElement _refEl;
933 markSubIndices(
const HostEntity& he, DomainSet& domains,
const HostIndexSet& his,
const typename HostEntity::Geometry& geo) :
937 _refEl(referenceElement(geo))
942 struct updateSubIndices :
public applyToCodim<const updateSubIndices> {
945 void apply(Containers<codim>& c)
const {
948 for (std::size_t gt_index = 0,
949 gt_end = c.indexMap.size();
952 for (
auto& im_entry : c.indexMap[gt_index])
953 _indexSet.updateMapEntry(im_entry,c.sizeMap[gt_index],c.multiIndexMap);
958 updateSubIndices(ThisType& indexSet) :
964 struct getSupportsCodim :
public dispatchToCodim<getSupportsCodim,bool,false> {
967 bool invoke()
const {
968 return MDGridTraits::template Codim<codim>::supported && Dune::Capabilities::hasEntity<HostGrid,codim>::v;
973 bool supportsCodim(
int codim)
const
975 return getSupportsCodim().dispatch(codim);
978 template<
typename Impl>
979 struct SubDomainSetDataHandleBase
980 :
public Dune::CommDataHandleIF<Impl,
981 typename MapEntry<0>::SubDomainSet::DataHandle::DataType
984 typedef typename MapEntry<0>::SubDomainSet SubDomainSet;
985 typedef typename SubDomainSet::DataHandle DataHandle;
987 bool fixedSize(
int dim,
int codim)
const
989 return DataHandle::fixedSize(dim,codim);
992 template<
typename Entity>
993 std::size_t
size(
const Entity& e)
const
995 return MapEntry<Entity::codimension>::SubDomainSet::DataHandle::size(_indexSet.subDomainsForHostEntity(e));
998 template<
typename MessageBufferImp,
typename Entity>
999 void gather(MessageBufferImp& buf,
const Entity& e)
const
1001 MapEntry<Entity::codimension>::SubDomainSet::DataHandle::gather(buf,_indexSet.subDomainsForHostEntity(e));
1004 template<
typename MessageBufferImp,
typename Entity>
1005 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1007 MapEntry<Entity::codimension>::SubDomainSet::DataHandle::scatter(buf,_indexSet.subDomainsForHostEntity(e),n);
1010 SubDomainSetDataHandleBase(ThisType& indexSet)
1011 : _indexSet(indexSet)
1014 ThisType& _indexSet;
1018 struct SelectionDataHandle
1019 :
public SubDomainSetDataHandleBase<SelectionDataHandle>
1022 bool contains(
int dim,
int codim)
const
1027 SelectionDataHandle(ThisType& indexSet)
1028 : SubDomainSetDataHandleBase<SelectionDataHandle>(indexSet)
1033 struct BorderPropagationDataHandle
1034 :
public SubDomainSetDataHandleBase<BorderPropagationDataHandle>
1037 bool contains(
int dim,
int codim)
const
1039 return codim > 0 && this->_indexSet.supportsCodim(codim);
1042 BorderPropagationDataHandle(ThisType& indexSet)
1043 : SubDomainSetDataHandleBase<BorderPropagationDataHandle>(indexSet)
1049 void communicateSubDomainSelection()
1051 SelectionDataHandle dh(*
this);
1052 _hostGridView.template communicate<SelectionDataHandle>(dh,Dune::InteriorBorder_All_Interface,Dune::ForwardCommunication);
1055 void propagateBorderEntitySubDomains()
1057 BorderPropagationDataHandle dh(*
this);
1058 _hostGridView.communicate(dh,Dune::InteriorBorder_All_Interface,Dune::ForwardCommunication);
Definition: indexsets.hh:236
IndexType size(GeometryType type) const
Returns the number of entities with GeometryType type in the grid.
Definition: indexsets.hh:396
const MapEntry< EntityType::codimension >::SubDomainSet & subDomains(const EntityType &e) const
Returns a constant reference to the SubDomainSet of the given entity.
Definition: indexsets.hh:413
IndexType index(const typename Grid::Traits::template Codim< codim >::Entity &e) const
Returns the index of the entity with codimension codim.
Definition: indexsets.hh:368
IndexType index(const Entity &e) const
Returns the index of the entity.
Definition: indexsets.hh:374
IndexType index(SubDomainIndex subDomain, const typename Grid::Traits::template Codim< cc >::Entity &e) const
Definition: indexsets.hh:433
IndexType index(SubDomainIndex subDomain, const EntityType &e) const
Returns the index of the entity in a specific subdomain.
Definition: indexsets.hh:426
Types types(int codim) const
Returns a list of all geometry types with codimension codim contained in the grid.
Definition: indexsets.hh:391
const MapEntry< cc >::SubDomainSet & subDomains(const typename Grid::Traits::template Codim< cc >::Entity &e) const
Definition: indexsets.hh:420
bool contains(const EntityType &e) const
Returns true if the entity is contained in the grid.
Definition: indexsets.hh:407
IndexType size(int codim) const
Returns the number of entities with codimension codim in the grid.
Definition: indexsets.hh:401
IndexType subIndex(const typename Grid::Traits::template Codim< codim >::Entity &e, int i, unsigned int cd) const
Returns the subdindex of the i-th subentity of e with codimension codim.
Definition: indexsets.hh:380
IndexType subIndex(const Entity &e, int i, unsigned int cd) const
Returns the subdindex of the i-th subentity of e with codimension codim.
Definition: indexsets.hh:386
bool contains(SubDomainIndex subDomain, const EntityType &e) const
Returns true if the entity is contained in a specific subdomain.
Definition: indexsets.hh:622
A meta grid for dividing an existing DUNE grid into subdomains that can be accessed as a grid in thei...
Definition: multidomaingrid.hh:247
An intersection that forms part of the interface between two subdomains.
Definition: subdomaininterfaceiterator.hh:32