1#ifndef DUNE_MULTIDOMAINGRID_MULTIDOMAINGRID_HH
2#define DUNE_MULTIDOMAINGRID_MULTIDOMAINGRID_HH
7#include <dune/common/shared_ptr.hh>
9#include <dune/grid/common/grid.hh>
11#include <dune/grid/multidomaingrid/hostgridaccessor.hh>
12#include <dune/grid/multidomaingrid/subdomainset.hh>
14#include <dune/grid/multidomaingrid/subdomaingrid/subdomaingrid.hh>
16#include <dune/grid/multidomaingrid/geometry.hh>
17#include <dune/grid/multidomaingrid/localgeometry.hh>
18#include <dune/grid/multidomaingrid/entity.hh>
19#include <dune/grid/multidomaingrid/iterator.hh>
20#include <dune/grid/multidomaingrid/hierarchiciterator.hh>
21#include <dune/grid/multidomaingrid/intersection.hh>
22#include <dune/grid/multidomaingrid/intersectioniterator.hh>
23#include <dune/grid/multidomaingrid/idsets.hh>
24#include <dune/grid/multidomaingrid/indexsets.hh>
25#include <dune/grid/multidomaingrid/gridview.hh>
26#include <dune/grid/multidomaingrid/mdgridtraits.hh>
28#include <dune/grid/multidomaingrid/subdomaintosubdomaininterfaceiterator.hh>
29#include <dune/grid/multidomaingrid/allsubdomaininterfacesiterator.hh>
35template<
typename HostGr
id,
typename MDGr
idTraits>
38template<
typename HostGr
id,
typename MDGr
idTraits>
39struct MultiDomainGridFamily {
43 static const int dim = HostGrid::dimension;
44 static const int dimw = HostGrid::dimensionworld;
51 using Grid = MultiDomainGrid<HostGrid,MDGridTraits>;
54 using LeafIntersection = Dune::Intersection<
58 typename HostGrid::LeafGridView::Intersection
62 using LevelIntersection = Dune::Intersection<
66 typename HostGrid::LevelGridView::Intersection
70 using LeafIntersectionIterator = Dune::IntersectionIterator<
72 IntersectionIteratorWrapper<
74 typename HostGrid::LeafGridView::IntersectionIterator
78 typename HostGrid::LeafGridView::Intersection
82 using LevelIntersectionIterator = Dune::IntersectionIterator<
84 IntersectionIteratorWrapper<
86 typename HostGrid::LevelGridView::IntersectionIterator
90 typename HostGrid::LevelGridView::Intersection
95 using HierarchicIterator = Dune::EntityIterator<
98 HierarchicIteratorWrapper<
108 using Geometry = Dune::Geometry<dim-cd, dimw,
const Grid, GeometryWrapper>;
109 using LocalGeometry = Dune::Geometry<dim-cd, dimw,
const Grid, LocalGeometryWrapper>;
111 using Entity = Dune::Entity<cd, dim, const Grid, EntityWrapper>;
113 using EntitySeed = EntitySeedWrapper<typename HostGrid::template Codim<cd>::EntitySeed>;
115 template <PartitionIteratorType pitype>
119 using LevelIterator = Dune::EntityIterator<
123 typename HostGrid::LevelGridView,
130 using LeafIterator = Dune::EntityIterator<
134 typename HostGrid::LeafGridView,
142 using LeafIterator =
typename Partition< All_Partition >::LeafIterator;
143 using LevelIterator =
typename Partition< All_Partition >::LevelIterator;
146 friend class Dune::Entity<cd, dim, const Grid, EntityWrapper>;
150 using LevelGridView = Dune::GridView<LevelGridViewTraits<const Grid> >;
151 using LeafGridView = Dune::GridView<LeafGridViewTraits<const Grid> >;
153 using LevelIndexSet = IndexSetWrapper<const Grid, typename HostGrid::LevelGridView>;
154 using LeafIndexSet = IndexSetWrapper<const Grid, typename HostGrid::LeafGridView>;
156 using GlobalIdSet = IdSet<
160 typename HostGrid::Traits::GlobalIdSet
162 typename HostGrid::Traits::GlobalIdSet::IdType
165 using LocalIdSet = IdSet<
169 typename HostGrid::Traits::LocalIdSet
171 typename HostGrid::Traits::LocalIdSet::IdType
174 using Communication =
typename HostGrid::Communication;
176 using LeafSubDomainInterfaceIterator = Dune::mdgrid::LeafSubDomainInterfaceIterator<const Grid>;
177 using LevelSubDomainInterfaceIterator = Dune::mdgrid::LevelSubDomainInterfaceIterator<const Grid>;
179 using LeafAllSubDomainInterfacesIterator = Dune::mdgrid::LeafAllSubDomainInterfacesIterator<const Grid>;
180 using LevelAllSubDomainInterfacesIterator = Dune::mdgrid::LevelAllSubDomainInterfacesIterator<const Grid>;
188 template<
typename Gr
id,
typename SI,
bool max_subdomain_index_is_static>
189 struct MaxSubDomainIndexProvider
192 typedef SI SubDomainIndex;
194 const SubDomainIndex maxSubDomainIndex()
const
196 return static_cast<const Grid*
>(
this)->traits().maxSubDomainIndex();
201 template<
typename Gr
id,
typename SI>
202 struct MaxSubDomainIndexProvider<Grid,SI,true>
205 typedef SI SubDomainIndex;
207 static constexpr SubDomainIndex maxSubDomainIndex()
209 return Grid::MDGridTraits::maxSubDomainIndex();
225 typename MDGridTraitsType
228 :
public GridDefaultImplementation<HostGrid_::dimension,
229 HostGrid_::dimensionworld,
230 typename HostGrid_::ctype,
231 MultiDomainGridFamily<
236 public Impl::MaxSubDomainIndexProvider<MultiDomainGrid<
240 typename MDGridTraitsType::SubDomainIndex,
241 MDGridTraitsType::maxSubDomainIndexIsStatic()
247 using HostGrid = HostGrid_;
252 template<
int codim,
int dim,
typename Gr
idImp>
253 friend class EntityWrapper;
255 template<
typename,
int,PartitionIteratorType,
typename>
256 friend class IteratorWrapper;
258 template<
typename Gr
idImp>
259 friend class HierarchicIteratorWrapper;
261 template<
int mydim,
int coorddim,
typename Gr
idImp>
262 friend class GeometryWrapper;
264 template<
int mydim,
int coorddim,
typename Gr
idImp>
265 friend class LocalGeometryWrapper;
267 template<
typename Gr
idImp,
typename WrappedIndexSet>
270 template<
typename Gr
idImp,
typename WrappedIdSet>
271 friend class IdSetWrapper;
273 template<
typename Gr
idImp>
274 friend struct detail::HostGridAccessor;
276 template<
typename,
typename>
277 friend class IntersectionIteratorWrapper;
279 template<
typename,
typename>
280 friend class IntersectionWrapper;
283 friend class subdomain::SubDomainGrid;
286 friend struct subdomain::SubDomainGridFamily;
288 template<
int,
int,
typename>
289 friend class subdomain::EntityWrapperBase;
291 template<
int,
int,
typename>
292 friend class subdomain::EntityWrapper;
306 template<
typename,
typename,
typename,
typename>
309 template<
typename,
typename,
typename>
310 friend class subdomain::IntersectionIteratorWrapper;
312 template<
typename,
typename,
typename>
313 friend class subdomain::IntersectionWrapper;
316 friend class LeafGridView;
319 friend class LevelGridView;
321 typedef GridDefaultImplementation<HostGrid::dimension,
322 HostGrid::dimensionworld,
323 typename HostGrid::ctype,
324 MultiDomainGridFamily<HostGrid,MDGridTraitsType>
333 typedef IdSetWrapper<const GridImp, typename HostGrid::Traits::GlobalIdSet> GlobalIdSetImp;
335 typedef IdSetWrapper<const GridImp, typename HostGrid::Traits::LocalIdSet> LocalIdSetImp;
337 enum State { stateFixed, stateMarking, statePreUpdate, statePostUpdate, statePreAdapt, statePostAdapt };
341 using Base = GridDefaultImplementation<
343 HostGrid::dimensionworld,
344 typename HostGrid::ctype,
345 MultiDomainGridFamily<
353 using Base::dimension;
354 using Base::dimensionworld;
356 typedef MultiDomainGridFamily<HostGrid,MDGridTraitsType> GridFamily;
357 typedef typename GridFamily::Traits Traits;
358 typedef MDGridTraitsType MDGridTraits;
359 typedef typename HostGrid::ctype ctype;
363 typedef std::map<typename Traits::LocalIdSet::IdType,typename MDGridTraits::template Codim<0>::SubDomainSet> AdaptationStateMap;
365 typedef std::map<typename Traits::GlobalIdSet::IdType,typename MDGridTraits::template Codim<0>::SubDomainSet> LoadBalanceStateMap;
369 template<
typename Entity>
371 typedef typename HostGrid::Traits::template Codim<Entity::codimension>::Entity type;
376 template<
typename Entity>
377 struct MultiDomainEntity {
378 typedef typename Traits::template Codim<Entity::codimension>::Entity type;
397 return _traits.maxSubDomainIndex();
401 static constexpr bool maxSubDomainIndexIsStatic()
403 return MDGridTraits::maxSubDomainIndexIsStatic();
431 _hostGridPtr(hostGridPtr),
433 _leafIndexSet(*this,hostGrid().leafGridView()),
437 _adaptState(stateFixed),
439 _maxAssignedSubDomainIndex(0)
452 _hostGridPtr(hostGridPtr),
454 _leafIndexSet(*this,hostGrid().leafGridView()),
458 _adaptState(stateFixed),
460 _maxAssignedSubDomainIndex(0)
494 template<
typename EntitySeed>
495 typename Traits::template Codim<EntitySeed::codimension>::Entity
496 entity(
const EntitySeed& entitySeed)
const
498 return {EntityWrapper<EntitySeed::codimension,dimension,const GridImp>(hostGrid().entity(entitySeed.hostEntitySeed()))};
503 return hostGrid().maxLevel();
507 typename Traits::template Codim<codim>::LevelIterator lbegin(
int level)
const {
510 typename HostGrid::LevelGridView,
514 >(hostGrid().levelGridView(level).template begin<codim>())
519 typename Traits::template Codim<codim>::LevelIterator lend(
int level)
const {
522 typename HostGrid::LevelGridView,
526 >(hostGrid().levelGridView(level).template end<codim>())
530 template<
int codim, PartitionIteratorType pitype>
531 typename Traits::template Codim<codim>::template Partition<pitype>::LevelIterator lbegin(
int level)
const {
534 typename HostGrid::LevelGridView,
538 >(hostGrid().levelGridView(level).template begin<codim,pitype>())
542 template<
int codim, PartitionIteratorType pitype>
543 typename Traits::template Codim<codim>::template Partition<pitype>::LevelIterator lend(
int level)
const {
546 typename HostGrid::LevelGridView,
550 >(hostGrid().levelGridView(level).template end<codim,pitype>())
555 typename Traits::template Codim<codim>::LeafIterator leafbegin()
const {
558 typename HostGrid::LeafGridView,
562 >(hostGrid().leafGridView().template begin<codim>())
567 typename Traits::template Codim<codim>::LeafIterator leafend()
const {
570 typename HostGrid::LeafGridView,
574 >(hostGrid().leafGridView().template end<codim>())
578 template<
int codim, PartitionIteratorType pitype>
579 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator leafbegin()
const {
582 typename HostGrid::LeafGridView,
586 >(hostGrid().leafGridView().template begin<codim,pitype>())
590 template<
int codim, PartitionIteratorType pitype>
591 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator leafend()
const {
594 typename HostGrid::LeafGridView,
598 >(hostGrid().leafGridView().template end<codim,pitype>())
703 int size(
int level,
int codim)
const {
704 return hostGrid().size(level,codim);
707 int size(
int codim)
const {
708 return hostGrid().size(codim);
711 int size(
int level, GeometryType type)
const {
712 return hostGrid().size(level,type);
715 int size(GeometryType type)
const {
716 return hostGrid().size(type);
719 const typename Traits::GlobalIdSet& globalIdSet()
const {
723 const typename Traits::LocalIdSet& localIdSet()
const {
727 const typename Traits::LevelIndexSet& levelIndexSet(
int level)
const {
728 if (!_supportLevelIndexSets) {
729 DUNE_THROW(GridError,
"level index set support not enabled for this grid");
732 return *_levelIndexSets[level];
735 const typename Traits::LeafIndexSet& leafIndexSet()
const {
736 return _leafIndexSet;
739 void globalRefine(
int refCount) {
740 saveMultiDomainState();
741 hostGrid().globalRefine(refCount);
743 restoreMultiDomainState();
746 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity& e) {
747 assert(_state == stateFixed);
748 return hostGrid().mark(refCount,
hostEntity(e));
751 int getMark(
const typename Traits::template Codim<0>::Entity& e) {
752 assert(_state == stateFixed);
757 assert(_state == stateFixed && _adaptState == stateFixed);
758 _adaptState = statePreAdapt;
759 bool result = hostGrid().preAdapt();
764 assert(_state == stateFixed && _adaptState == statePreAdapt);
765 _adaptState = statePostAdapt;
766 saveMultiDomainState();
767 bool result = hostGrid().adapt();
769 restoreMultiDomainState();
774 assert(_state == stateFixed && _adaptState == statePostAdapt);
775 _adaptState = stateFixed;
776 hostGrid().postAdapt();
779 int overlapSize(
int level,
int codim)
const {
780 return hostGrid().overlapSize(level,codim);
783 int overlapSize(
int codim)
const {
784 return hostGrid().overlapSize(codim);
787 int ghostSize(
int level,
int codim)
const {
788 return hostGrid().ghostSize(level,codim);
791 int ghostSize(
int codim)
const {
792 return hostGrid().ghostSize(codim);
795 const typename Traits::Communication& comm()
const {
796 return hostGrid().comm();
799 template<
typename DataHandleImp,
typename DataTypeImp>
800 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> &data,
801 InterfaceType iftype,
802 CommunicationDirection dir,
805 DataHandleWrapper<CommDataHandleIF<DataHandleImp,DataTypeImp> > datahandle(data,*
this);
806 hostGrid().levelGridView(level).communicate(datahandle,iftype,dir);
809 template<
typename DataHandleImp,
typename DataTypeImp>
810 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> &data,
811 InterfaceType iftype,
812 CommunicationDirection dir)
const
814 DataHandleWrapper<CommDataHandleIF<DataHandleImp,DataTypeImp> > datahandle(data,*
this);
815 hostGrid().leafGridView().communicate(datahandle,iftype,dir);
818 template<
typename DataHandle>
819 bool loadBalance(DataHandle& dataHandle)
821 typedef typename MultiDomainGrid::LeafGridView GV;
822 GV gv = this->leafGridView();
823 typedef typename GV::template Codim<0>::Iterator Iterator;
824 typedef typename GV::template Codim<0>::Entity Entity;
825 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
826 for (Iterator it = gv.template begin<0>(); it != gv.template end<0>(); ++it) {
827 const Entity& e = *it;
828 const SubDomainSet& subDomains = gv.indexSet().subDomains(e);
829 _loadBalanceStateMap[globalIdSet().id(e)] = subDomains;
832 LoadBalancingDataHandle<DataHandle> dataHandleWrapper(*
this,dataHandle);
833 if (!hostGrid().loadBalance(dataHandleWrapper))
838 for (Iterator it = gv.template begin<0>(); it != gv.template end<0>(); ++it) {
839 _leafIndexSet.addToSubDomains(_loadBalanceStateMap[globalIdSet().
id(*it)],*it);
846 _loadBalanceStateMap.clear();
853 EmptyDataHandle emptyDataHandle;
854 return loadBalance(emptyDataHandle);
857 size_t numBoundarySegments()
const
859 return hostGrid().numBoundarySegments();
876 assert(_state == stateFixed && _adaptState == stateFixed);
878 _tmpLeafIndexSet->reset(
false);
879 _state = stateMarking;
891 assert(_state == stateMarking && _adaptState == stateFixed);
892 if (_supportLevelIndexSets) {
893 for (
int l = 0; l <=
maxLevel(); ++l) {
894 _tmpLevelIndexSets.push_back(std::make_shared<LevelIndexSetImp>(*
this,hostGrid().levelGridView(l)));
897 _tmpLeafIndexSet->update(_tmpLevelIndexSets,
true);
898 _state = statePreUpdate;
906 assert(_state == statePreUpdate && _adaptState == stateFixed);
907 _leafIndexSet.swap(*_tmpLeafIndexSet);
908 if (_supportLevelIndexSets) {
909 for (
int l = 0; l <=
maxLevel(); ++l) {
910 _levelIndexSets[l]->swap(*_tmpLevelIndexSets[l]);
913 _state = statePostUpdate;
918 assert(_state == statePostUpdate && _adaptState == stateFixed);
919 _tmpLevelIndexSets.clear();
920 _tmpLeafIndexSet.reset(
nullptr);
926 assert(_state == stateMarking);
928 assert(e.partitionType() == Dune::InteriorEntity);
929 _maxAssignedSubDomainIndex = std::max(_maxAssignedSubDomainIndex,
subDomain);
930 _tmpLeafIndexSet->addToSubDomain(
subDomain,e);
935 assert(_state == stateMarking);
937 assert(e.partitionType() == Dune::InteriorEntity);
938 _tmpLeafIndexSet->removeFromSubDomain(
subDomain,e);
943 assert(_state == stateMarking);
945 assert(e.partitionType() == Dune::InteriorEntity);
946 _maxAssignedSubDomainIndex = std::max(_maxAssignedSubDomainIndex,
subDomain);
947 _tmpLeafIndexSet->assignToSubDomain(
subDomain,e);
952 assert(_state == stateMarking);
954 assert(e.partitionType() == Dune::InteriorEntity);
955 _tmpLeafIndexSet->removeFromAllSubDomains(e);
963 std::shared_ptr<SubDomainGrid>& subGridPointer = _subDomainGrids[
subDomain];
964 if (!subGridPointer) {
967 return *subGridPointer;
972 std::shared_ptr<SubDomainGrid>& subGridPointer = _subDomainGrids[
subDomain];
973 if (!subGridPointer) {
976 return *subGridPointer;
988 return _maxAssignedSubDomainIndex;
993 return _supportLevelIndexSets;
1004 template<
typename EntityType>
1005 static const typename HostEntity<EntityType>::type&
hostEntity(
const EntityType& e)
1007 return e.impl().hostEntity();
1010 template<
typename EntityType>
1011 static const typename MultiDomainEntity<EntityType>::type& multiDomainEntity(
const EntityType& e)
1013 return e.impl().multiDomainEntity();
1016 template<
typename IntersectionType>
1017 static const auto& multiDomainIntersection(
const IntersectionType& is) {
1018 return SubDomainGrid::multiDomainIntersection(is);
1022 const MDGridTraits& traits()
const
1027 const HostGrid& hostGrid()
const
1029 return *_hostGridPtr;
1032 HostGrid& hostGrid()
1034 return *_hostGridPtr;
1039 std::shared_ptr<HostGrid> _hostGridPtr;
1040 const MDGridTraitsType _traits;
1042 std::vector<std::shared_ptr<LevelIndexSetImp> > _levelIndexSets;
1043 LeafIndexSetImp _leafIndexSet;
1045 std::vector<std::shared_ptr<LevelIndexSetImp> > _tmpLevelIndexSets;
1046 std::unique_ptr<LeafIndexSetImp> _tmpLeafIndexSet;
1048 GlobalIdSetImp _globalIdSet;
1049 LocalIdSetImp _localIdSet;
1053 const bool _supportLevelIndexSets;
1055 mutable std::map<SubDomainIndex,std::shared_ptr<SubDomainGrid> > _subDomainGrids;
1058 AdaptationStateMap _adaptationStateMap;
1059 LoadBalanceStateMap _loadBalanceStateMap;
1061 void updateIndexSets() {
1063 if (_supportLevelIndexSets) {
1064 while (
static_cast<int>(_levelIndexSets.size()) <=
maxLevel()) {
1065 _levelIndexSets.push_back(std::make_shared<LevelIndexSetImp>(*
this,hostGrid().levelGridView(_levelIndexSets.size())));
1068 if (
static_cast<int>(_levelIndexSets.size()) >
maxLevel() + 1)
1070 _levelIndexSets.resize(
maxLevel() + 1);
1074 _leafIndexSet.reset(
true);
1075 _leafIndexSet.update(_levelIndexSets,
true);
1077 _globalIdSet.update(hostGrid().globalIdSet());
1078 _localIdSet.update(hostGrid().localIdSet());
1081 for (
auto& subGridPair : _subDomainGrids)
1082 subGridPair.second->update();
1085 void saveMultiDomainState() {
1086 typedef typename ThisType::LeafGridView GV;
1087 GV gv = this->leafGridView();
1088 typedef typename GV::template Codim<0>::Entity Entity;
1089 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
1090 for (
const auto& e : elements(gv)) {
1091 const SubDomainSet& subDomains = gv.indexSet().subDomains(e);
1092 _adaptationStateMap[localIdSet().id(e)] = subDomains;
1094 while (he.mightVanish()) {
1096 typename Traits::LocalIdSet::IdType
id = localIdSet().id(he);
1099 if (!_adaptationStateMap.insert(
typename AdaptationStateMap::value_type(
id,subDomains)).second) {
1101 _adaptationStateMap[id].addAll(subDomains);
1107 void restoreMultiDomainState() {
1108 typedef typename ThisType::LeafGridView GV;
1109 GV gv = this->leafGridView();
1110 typedef typename GV::template Codim<0>::Entity Entity;
1111 for (
const auto& e : elements(gv)) {
1114 while (he.isNew()) {
1119 typename AdaptationStateMap::iterator asmit = _adaptationStateMap.find(localIdSet().
id(he));
1120 while(asmit == _adaptationStateMap.end()) {
1122 asmit = _adaptationStateMap.find(localIdSet().
id(he));
1124 _leafIndexSet.addToSubDomains(asmit->second, e);
1126 _leafIndexSet.update(_levelIndexSets,
false);
1127 _adaptationStateMap.clear();
1130 template<
typename Gr
idView,
typename HostGr
idView>
1131 static typename GridView::IntersectionIterator multiDomainIntersectionIterator(
typename HostGridView::IntersectionIterator iit) {
1132 typedef decltype(std::declval<typename GridView::IntersectionIterator>().impl()) Implementation;
1133 return Implementation(iit);
1138 template<
typename Entity>
1139 typename Traits::template Codim<Entity::codimension>::Entity wrapHostEntity(
const Entity& e)
const {
1140 return wrapHostEntity<Entity::codimension>(e);
1144 typename Traits::template Codim<codim>::Entity wrapHostEntity(
const typename HostGrid::template Codim<codim>::Entity& e)
const
1146 return {EntityWrapper<codim,dimension,const GridImp>(e)};
1152 template<
typename Impl>
1153 struct DataHandleWrapper
1154 :
public Dune::CommDataHandleIF<DataHandleWrapper<Impl>,
1155 typename Impl::DataType
1159 bool contains(
int dim,
int codim)
const
1161 return _impl.contains(dim,codim);
1164 bool fixedSize(
int dim,
int codim)
const
1166 return _impl.fixedSize(dim,codim);
1169 template<
typename Entity>
1170 std::size_t size(
const Entity& e)
const
1172 return _impl.size(_grid.wrapHostEntity(e));
1175 template<
typename MessageBufferImp,
typename Entity>
1176 void gather(MessageBufferImp& buf,
const Entity& e)
const
1178 _impl.gather(buf,_grid.wrapHostEntity(e));
1181 template<
typename MessageBufferImp,
typename Entity>
1182 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1184 _impl.scatter(buf,_grid.wrapHostEntity(e),n);
1187 DataHandleWrapper(Impl& impl,
const MultiDomainGrid<HostGrid,MDGridTraitsType>& grid)
1193 const MultiDomainGrid<HostGrid,MDGridTraitsType>& _grid;
1198 template<
typename WrappedDataHandle>
1199 struct LoadBalancingDataHandle
1200 :
public Dune::CommDataHandleIF<LoadBalancingDataHandle<WrappedDataHandle>,
1201 typename WrappedDataHandle::DataType
1208 typename WrappedDataHandle::DataType buffer;
1212 "During load balancing, the data type has to be large enough to contain MultiDomaingrid::SubDomainIndex");
1214 bool contains(
int dim,
int codim)
const
1217 || _wrappedDataHandle.contains(dim,codim);
1220 bool fixedSize(
int dim,
int codim)
const
1225 template<
typename Entity>
1226 std::size_t size(
const Entity& e)
const
1228 if (_grid.leafGridView().indexSet().contains(e) && e.partitionType() == Dune::InteriorEntity)
1229 return _grid.leafGridView().indexSet().subDomains(e).size() + 1 + _wrappedDataHandle.size(e);
1231 return _wrappedDataHandle.size(e);
1234 template<
typename MessageBufferImp,
typename Entity>
1235 void gather(MessageBufferImp& buf,
const Entity& e)
const
1237 assert(Entity::codimension == 0);
1238 if (e.partitionType() == Dune::InteriorEntity && _grid.leafGridView().indexSet().contains(e))
1240 const auto& subDomains = _grid.leafGridView().indexSet().subDomains(e);
1241 Data size = { subDomains.size() };
1242 buf.write(size.buffer);
1243 for (
auto& sub_domain : subDomains)
1249 _wrappedDataHandle.gather(buf,e);
1252 template<
typename MessageBufferImp,
typename Entity>
1253 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1255 if (e.partitionType() != Dune::InteriorEntity && _grid.leafGridView().indexSet().contains(e))
1257 Data subDomains = { 0 };
1258 buf.read(subDomains.buffer);
1259 for (
int i = 0; i < subDomains.data; ++i)
1263 _grid._loadBalanceStateMap[_grid.globalIdSet().id(multiDomainEntity(e))].add(
subDomain.data);
1265 _wrappedDataHandle.scatter(buf,e,n - (subDomains.data + 1));
1268 _wrappedDataHandle.scatter(buf,e,n);
1271 LoadBalancingDataHandle(
MultiDomainGrid& grid, WrappedDataHandle& wrappedDataHandle)
1273 , _wrappedDataHandle(wrappedDataHandle)
1277 WrappedDataHandle& _wrappedDataHandle;
1281 struct EmptyDataHandle
1282 :
public Dune::CommDataHandleIF<EmptyDataHandle,
1287 bool contains(
int dim,
int codim)
const
1292 bool fixedSize(
int dim,
int codim)
const
1297 template<
typename Entity>
1298 std::size_t size(
const Entity& e)
const
1303 template<
typename MessageBufferImp,
typename Entity>
1304 void gather(MessageBufferImp& buf,
const Entity& e)
const
1308 template<
typename MessageBufferImp,
typename Entity>
1309 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1317enum MultiDomainGridType { multiDomainGrid, subDomainGrid, other };
1321 static const MultiDomainGridType v = other;
1324template<
class HostGr
id,
typename MDGr
idTraits>
1325struct GridType<MultiDomainGrid<HostGrid,MDGridTraits> > {
1326 static const MultiDomainGridType v = multiDomainGrid;
1329template<
class MDGr
id>
1330struct GridType<subdomain::SubDomainGrid<MDGrid> > {
1331 static const MultiDomainGridType v = subDomainGrid;
Definition: indexsets.hh:118
A meta grid for dividing an existing DUNE grid into subdomains that can be accessed as a grid in thei...
Definition: multidomaingrid.hh:243
Traits::LeafAllSubDomainInterfacesIterator LeafAllSubDomainInterfacesIterator
The type of the iterators over the codim 1 interfaces between all subdomains on the leaf view.
Definition: multidomaingrid.hh:417
Traits::LevelAllSubDomainInterfacesIterator LevelAllSubDomainInterfacesIterator
The type of the iterators over the codim 1 interfaces between all subdomains on a level view.
Definition: multidomaingrid.hh:420
LevelAllSubDomainInterfacesIterator levelAllSubDomainInterfacesBegin(int level) const
Returns an iterator over all subdomain interfaces on the requested level view.
Definition: multidomaingrid.hh:688
MultiDomainGrid(HostGrid &hostGrid, const MDGridTraitsType &traits, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:485
Traits::LevelSubDomainInterfaceIterator LevelSubDomainInterfaceIterator
The type of the iterators over the codim 1 interface between two subdomains on a level view.
Definition: multidomaingrid.hh:414
static const HostEntity< EntityType >::type & hostEntity(const EntityType &e)
Returns a reference to the corresponding host entity.
Definition: multidomaingrid.hh:1005
void startSubDomainMarking()
Prepares the grid for (re-)assigning cells to subdomains.
Definition: multidomaingrid.hh:875
void updateSubDomains()
Switches the subdomain layout over to the new layout.
Definition: multidomaingrid.hh:905
const SubDomainIndex maxSubDomainIndex() const
The largest allowed index for a subdomain.
Definition: multidomaingrid.hh:395
void postUpdateSubDomains()
clears the saved state of the subdomain layout that was active before the last call to updateSubDomai...
Definition: multidomaingrid.hh:917
int maxLevel() const
The current maximum level of the grid.
Definition: multidomaingrid.hh:502
MDGridTraits::SubDomainIndex SubDomainIndex
The (integer) type used to identify subdomains.
Definition: multidomaingrid.hh:384
bool supportLevelIndexSets() const
Indicates whether this MultiDomainGrid instance supports level index sets on its SubDomainGrids.
Definition: multidomaingrid.hh:992
LeafSubDomainInterfaceIterator leafSubDomainInterfaceEnd(SubDomainIndex subDomain1, SubDomainIndex subDomain2) const
Returns the corresponding end iterator for leafSubDomainInterfaceBegin().
Definition: multidomaingrid.hh:620
LevelAllSubDomainInterfacesIterator levelAllSubDomainInterfacesEnd(int level) const
Returns the corresponding end iterator for levelAllSubDomainInterfacesBegin().
Definition: multidomaingrid.hh:696
MultiDomainGrid(const std::shared_ptr< HostGrid > &hostGridPtr, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:430
SubDomainIndex maxAssignedSubDomainIndex() const
Returns the largest subdomain index that was ever assigned to a cell in this grid.
Definition: multidomaingrid.hh:986
void assignToSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Assigns the given leaf entity to the specified subdomain, clearing any previous subdomain assignments...
Definition: multidomaingrid.hh:942
LevelSubDomainInterfaceIterator levelSubDomainInterfaceBegin(SubDomainIndex subDomain1, SubDomainIndex subDomain2, int level) const
Returns an iterator over the interface of two subdomains at the given level.
Definition: multidomaingrid.hh:635
LeafSubDomainInterfaceIterator leafSubDomainInterfaceBegin(SubDomainIndex subDomain1, SubDomainIndex subDomain2) const
Returns an iterator over the leaf interface of two subdomains.
Definition: multidomaingrid.hh:615
void removeFromSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Removes the given leaf entity from the specified subdomain.
Definition: multidomaingrid.hh:934
SubDomainGrid & subDomain(SubDomainIndex subDomain)
Returns a reference to the SubDomainGrid associated with the given subdomain.
Definition: multidomaingrid.hh:971
static const std::size_t maxNumberOfSubDomains
The largest number of subdomains any given grid cell may belong to.
Definition: multidomaingrid.hh:387
subdomain::SubDomainGrid< ThisType > SubDomainGrid
The type used for representing the grid of a subdomain, always a specialization of Dune::mdgrid::subd...
Definition: multidomaingrid.hh:407
void addToSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Adds the given leaf entity to the specified subdomain.
Definition: multidomaingrid.hh:925
Traits::LeafSubDomainInterfaceIterator LeafSubDomainInterfaceIterator
The type of the iterators over the codim 1 interface between two subdomains on the leaf view.
Definition: multidomaingrid.hh:411
LeafAllSubDomainInterfacesIterator leafAllSubDomainInterfacesEnd() const
Returns the corresponding end iterator for leafAllSubDomainInterfacesBegin().
Definition: multidomaingrid.hh:667
void preUpdateSubDomains()
Calculates the new subdomain layout, but does not update the current subdomains yet.
Definition: multidomaingrid.hh:890
void removeFromAllSubDomains(const typename Traits::template Codim< 0 >::Entity &e)
Removes the given leaf entity from all subdomains it currently belongs to.
Definition: multidomaingrid.hh:951
const SubDomainGrid & subDomain(SubDomainIndex subDomain) const
Returns a reference to the SubDomainGrid associated with the given subdomain.
Definition: multidomaingrid.hh:962
MultiDomainGrid(const std::shared_ptr< HostGrid > &hostGridPtr, const MDGridTraitsType &traits, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:451
LevelSubDomainInterfaceIterator levelSubDomainInterfaceEnd(SubDomainIndex subDomain1, SubDomainIndex subDomain2, int level) const
Returns the corresponding end iterator for levelSubDomainInterfaceBegin().
Definition: multidomaingrid.hh:643
MultiDomainGrid(HostGrid &hostGrid, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:474
LeafAllSubDomainInterfacesIterator leafAllSubDomainInterfacesBegin() const
Returns an iterator over all subdomain interfaces on the leaf view.
Definition: multidomaingrid.hh:662
An intersection that forms part of the interface between two subdomains.
Definition: subdomaininterfaceiterator.hh:32