1#ifndef DUNE_MULTIDOMAINGRID_MULTIDOMAINGRID_HH
2#define DUNE_MULTIDOMAINGRID_MULTIDOMAINGRID_HH
7#include <dune/grid/common/grid.hh>
9#include <dune/grid/multidomaingrid/hostgridaccessor.hh>
10#include <dune/grid/multidomaingrid/subdomainset.hh>
12#include <dune/grid/multidomaingrid/subdomaingrid/subdomaingrid.hh>
14#include <dune/grid/multidomaingrid/geometry.hh>
15#include <dune/grid/multidomaingrid/localgeometry.hh>
16#include <dune/grid/multidomaingrid/entity.hh>
17#include <dune/grid/multidomaingrid/iterator.hh>
18#include <dune/grid/multidomaingrid/hierarchiciterator.hh>
19#include <dune/grid/multidomaingrid/intersection.hh>
20#include <dune/grid/multidomaingrid/intersectioniterator.hh>
21#include <dune/grid/multidomaingrid/idsets.hh>
22#include <dune/grid/multidomaingrid/indexsets.hh>
23#include <dune/grid/multidomaingrid/gridview.hh>
24#include <dune/grid/multidomaingrid/mdgridtraits.hh>
26#include <dune/grid/multidomaingrid/subdomaintosubdomaininterfaceiterator.hh>
27#include <dune/grid/multidomaingrid/allsubdomaininterfacesiterator.hh>
33template<
typename HostGr
id,
typename MDGr
idTraits>
36template<
typename HostGr
id,
typename MDGr
idTraits>
37struct MultiDomainGridFamily {
41 static const int dim = HostGrid::dimension;
42 static const int dimw = HostGrid::dimensionworld;
49 using Grid = MultiDomainGrid<HostGrid,MDGridTraits>;
52 using LeafIntersection = Dune::Intersection<
56 typename HostGrid::LeafGridView::Intersection
60 using LevelIntersection = Dune::Intersection<
64 typename HostGrid::LevelGridView::Intersection
68 using LeafIntersectionIterator = Dune::IntersectionIterator<
70 IntersectionIteratorWrapper<
72 typename HostGrid::LeafGridView::IntersectionIterator
76 typename HostGrid::LeafGridView::Intersection
80 using LevelIntersectionIterator = Dune::IntersectionIterator<
82 IntersectionIteratorWrapper<
84 typename HostGrid::LevelGridView::IntersectionIterator
88 typename HostGrid::LevelGridView::Intersection
93 using HierarchicIterator = Dune::EntityIterator<
96 HierarchicIteratorWrapper<
106 using Geometry = Dune::Geometry<dim-cd, dimw,
const Grid, GeometryWrapper>;
107 using LocalGeometry = Dune::Geometry<dim-cd, dimw,
const Grid, LocalGeometryWrapper>;
109 using Entity = Dune::Entity<cd, dim, const Grid, EntityWrapper>;
111 using EntitySeed = EntitySeedWrapper<typename HostGrid::template Codim<cd>::EntitySeed>;
113 template <PartitionIteratorType pitype>
117 using LevelIterator = Dune::EntityIterator<
121 typename HostGrid::LevelGridView,
128 using LeafIterator = Dune::EntityIterator<
132 typename HostGrid::LeafGridView,
140 using LeafIterator =
typename Partition< All_Partition >::LeafIterator;
141 using LevelIterator =
typename Partition< All_Partition >::LevelIterator;
144 friend class Dune::Entity<cd, dim, const Grid, EntityWrapper>;
148 using LevelGridView = Dune::GridView<LevelGridViewTraits<const Grid> >;
149 using LeafGridView = Dune::GridView<LeafGridViewTraits<const Grid> >;
151 using LevelIndexSet = IndexSetWrapper<const Grid, typename HostGrid::LevelGridView>;
152 using LeafIndexSet = IndexSetWrapper<const Grid, typename HostGrid::LeafGridView>;
154 using GlobalIdSet = IdSet<
158 typename HostGrid::Traits::GlobalIdSet
160 typename HostGrid::Traits::GlobalIdSet::IdType
163 using LocalIdSet = IdSet<
167 typename HostGrid::Traits::LocalIdSet
169 typename HostGrid::Traits::LocalIdSet::IdType
172 using CollectiveCommunication =
typename HostGrid::CollectiveCommunication;
174 using LeafSubDomainInterfaceIterator = Dune::mdgrid::LeafSubDomainInterfaceIterator<const Grid>;
175 using LevelSubDomainInterfaceIterator = Dune::mdgrid::LevelSubDomainInterfaceIterator<const Grid>;
177 using LeafAllSubDomainInterfacesIterator = Dune::mdgrid::LeafAllSubDomainInterfacesIterator<const Grid>;
178 using LevelAllSubDomainInterfacesIterator = Dune::mdgrid::LevelAllSubDomainInterfacesIterator<const Grid>;
186 template<
typename Gr
id,
typename SI,
bool max_subdomain_index_is_static>
187 struct MaxSubDomainIndexProvider
190 typedef SI SubDomainIndex;
192 const SubDomainIndex maxSubDomainIndex()
const
194 return static_cast<const Grid*
>(
this)->traits().maxSubDomainIndex();
199 template<
typename Gr
id,
typename SI>
200 struct MaxSubDomainIndexProvider<Grid,SI,true>
203 typedef SI SubDomainIndex;
205 static constexpr SubDomainIndex maxSubDomainIndex()
207 return Grid::MDGridTraits::maxSubDomainIndex();
223 typename MDGridTraitsType
226 :
public GridDefaultImplementation<HostGrid_::dimension,
227 HostGrid_::dimensionworld,
228 typename HostGrid_::ctype,
229 MultiDomainGridFamily<
234 public Impl::MaxSubDomainIndexProvider<MultiDomainGrid<
238 typename MDGridTraitsType::SubDomainIndex,
239 MDGridTraitsType::maxSubDomainIndexIsStatic()
245 using HostGrid = HostGrid_;
250 template<
int codim,
int dim,
typename Gr
idImp>
251 friend class EntityWrapper;
253 template<
typename,
int,PartitionIteratorType,
typename>
254 friend class IteratorWrapper;
256 template<
typename Gr
idImp>
257 friend class HierarchicIteratorWrapper;
259 template<
int mydim,
int coorddim,
typename Gr
idImp>
260 friend class GeometryWrapper;
262 template<
int mydim,
int coorddim,
typename Gr
idImp>
263 friend class LocalGeometryWrapper;
265 template<
typename Gr
idImp,
typename WrappedIndexSet>
268 template<
typename Gr
idImp,
typename WrappedIdSet>
269 friend class IdSetWrapper;
271 template<
typename Gr
idImp>
272 friend struct detail::HostGridAccessor;
274 template<
typename,
typename>
275 friend class IntersectionIteratorWrapper;
277 template<
typename,
typename>
278 friend class IntersectionWrapper;
281 friend class subdomain::SubDomainGrid;
284 friend struct subdomain::SubDomainGridFamily;
286 template<
int,
int,
typename>
287 friend class subdomain::EntityWrapperBase;
289 template<
int,
int,
typename>
290 friend class subdomain::EntityWrapper;
304 template<
typename,
typename,
typename,
typename>
307 template<
typename,
typename,
typename>
308 friend class subdomain::IntersectionIteratorWrapper;
310 template<
typename,
typename,
typename>
311 friend class subdomain::IntersectionWrapper;
314 friend class LeafGridView;
317 friend class LevelGridView;
319 typedef GridDefaultImplementation<HostGrid::dimension,
320 HostGrid::dimensionworld,
321 typename HostGrid::ctype,
322 MultiDomainGridFamily<HostGrid,MDGridTraitsType>
331 typedef IdSetWrapper<const GridImp, typename HostGrid::Traits::GlobalIdSet> GlobalIdSetImp;
333 typedef IdSetWrapper<const GridImp, typename HostGrid::Traits::LocalIdSet> LocalIdSetImp;
335 enum State { stateFixed, stateMarking, statePreUpdate, statePostUpdate, statePreAdapt, statePostAdapt };
339 using Base = GridDefaultImplementation<
341 HostGrid::dimensionworld,
342 typename HostGrid::ctype,
343 MultiDomainGridFamily<
351 using Base::dimension;
352 using Base::dimensionworld;
354 typedef MultiDomainGridFamily<HostGrid,MDGridTraitsType> GridFamily;
355 typedef typename GridFamily::Traits Traits;
356 typedef MDGridTraitsType MDGridTraits;
357 typedef typename HostGrid::ctype ctype;
361 typedef std::map<typename Traits::LocalIdSet::IdType,typename MDGridTraits::template Codim<0>::SubDomainSet> AdaptationStateMap;
363 typedef std::map<typename Traits::GlobalIdSet::IdType,typename MDGridTraits::template Codim<0>::SubDomainSet> LoadBalanceStateMap;
367 template<
typename Entity>
369 typedef typename HostGrid::Traits::template Codim<Entity::codimension>::Entity type;
374 template<
typename Entity>
375 struct MultiDomainEntity {
376 typedef typename Traits::template Codim<Entity::codimension>::Entity type;
395 return _traits.maxSubDomainIndex();
399 static constexpr bool maxSubDomainIndexIsStatic()
401 return MDGridTraits::maxSubDomainIndexIsStatic();
431 _leafIndexSet(*this,hostGrid.leafGridView()),
435 _adaptState(stateFixed),
437 _maxAssignedSubDomainIndex(0)
452 _leafIndexSet(*this,hostGrid.leafGridView()),
456 _adaptState(stateFixed),
458 _maxAssignedSubDomainIndex(0)
468 template<
typename EntitySeed>
469 typename Traits::template Codim<EntitySeed::codimension>::Entity
470 entity(
const EntitySeed& entitySeed)
const
472 return {EntityWrapper<EntitySeed::codimension,dimension,const GridImp>(_hostGrid.entity(entitySeed.hostEntitySeed()))};
477 return _hostGrid.maxLevel();
481 typename Traits::template Codim<codim>::LevelIterator lbegin(
int level)
const {
484 typename HostGrid::LevelGridView,
488 >(_hostGrid.levelGridView(level).template begin<codim>())
493 typename Traits::template Codim<codim>::LevelIterator lend(
int level)
const {
496 typename HostGrid::LevelGridView,
500 >(_hostGrid.levelGridView(level).template end<codim>())
504 template<
int codim, PartitionIteratorType pitype>
505 typename Traits::template Codim<codim>::template Partition<pitype>::LevelIterator lbegin(
int level)
const {
508 typename HostGrid::LevelGridView,
512 >(_hostGrid.levelGridView(level).template begin<codim,pitype>())
516 template<
int codim, PartitionIteratorType pitype>
517 typename Traits::template Codim<codim>::template Partition<pitype>::LevelIterator lend(
int level)
const {
520 typename HostGrid::LevelGridView,
524 >(_hostGrid.levelGridView(level).template end<codim,pitype>())
529 typename Traits::template Codim<codim>::LeafIterator leafbegin()
const {
532 typename HostGrid::LeafGridView,
536 >(_hostGrid.leafGridView().template begin<codim>())
541 typename Traits::template Codim<codim>::LeafIterator leafend()
const {
544 typename HostGrid::LeafGridView,
548 >(_hostGrid.leafGridView().template end<codim>())
552 template<
int codim, PartitionIteratorType pitype>
553 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator leafbegin()
const {
556 typename HostGrid::LeafGridView,
560 >(_hostGrid.leafGridView().template begin<codim,pitype>())
564 template<
int codim, PartitionIteratorType pitype>
565 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator leafend()
const {
568 typename HostGrid::LeafGridView,
572 >(_hostGrid.leafGridView().template end<codim,pitype>())
677 int size(
int level,
int codim)
const {
678 return _hostGrid.size(level,codim);
681 int size(
int codim)
const {
682 return _hostGrid.size(codim);
685 int size(
int level, GeometryType type)
const {
686 return _hostGrid.size(level,type);
689 int size(GeometryType type)
const {
690 return _hostGrid.size(type);
693 const typename Traits::GlobalIdSet& globalIdSet()
const {
697 const typename Traits::LocalIdSet& localIdSet()
const {
701 const typename Traits::LevelIndexSet& levelIndexSet(
int level)
const {
702 if (!_supportLevelIndexSets) {
703 DUNE_THROW(GridError,
"level index set support not enabled for this grid");
706 return *_levelIndexSets[level];
709 const typename Traits::LeafIndexSet& leafIndexSet()
const {
710 return _leafIndexSet;
713 void globalRefine(
int refCount) {
714 saveMultiDomainState();
715 _hostGrid.globalRefine(refCount);
717 restoreMultiDomainState();
720 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity& e) {
721 assert(_state == stateFixed);
722 return _hostGrid.mark(refCount,
hostEntity(e));
725 int getMark(
const typename Traits::template Codim<0>::Entity& e) {
726 assert(_state == stateFixed);
731 assert(_state == stateFixed && _adaptState == stateFixed);
732 _adaptState = statePreAdapt;
733 bool result = _hostGrid.preAdapt();
738 assert(_state == stateFixed && _adaptState == statePreAdapt);
739 _adaptState = statePostAdapt;
740 saveMultiDomainState();
741 bool result = _hostGrid.adapt();
743 restoreMultiDomainState();
748 assert(_state == stateFixed && _adaptState == statePostAdapt);
749 _adaptState = stateFixed;
750 _hostGrid.postAdapt();
753 int overlapSize(
int level,
int codim)
const {
754 return _hostGrid.overlapSize(level,codim);
757 int overlapSize(
int codim)
const {
758 return _hostGrid.overlapSize(codim);
761 int ghostSize(
int level,
int codim)
const {
762 return _hostGrid.ghostSize(level,codim);
765 int ghostSize(
int codim)
const {
766 return _hostGrid.ghostSize(codim);
769 const typename Traits::CollectiveCommunication& comm()
const {
770 return _hostGrid.comm();
773 template<
typename DataHandleImp,
typename DataTypeImp>
774 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> &data,
775 InterfaceType iftype,
776 CommunicationDirection dir,
779 DataHandleWrapper<CommDataHandleIF<DataHandleImp,DataTypeImp> > datahandle(data,*
this);
780 _hostGrid.levelGridView(level).communicate(datahandle,iftype,dir);
783 template<
typename DataHandleImp,
typename DataTypeImp>
784 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> &data,
785 InterfaceType iftype,
786 CommunicationDirection dir)
const
788 DataHandleWrapper<CommDataHandleIF<DataHandleImp,DataTypeImp> > datahandle(data,*
this);
789 _hostGrid.leafGridView().communicate(datahandle,iftype,dir);
792 template<
typename DataHandle>
793 bool loadBalance(DataHandle& dataHandle)
795 typedef typename MultiDomainGrid::LeafGridView GV;
796 GV gv = this->leafGridView();
797 typedef typename GV::template Codim<0>::Iterator Iterator;
798 typedef typename GV::template Codim<0>::Entity Entity;
799 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
800 for (Iterator it = gv.template begin<0>(); it != gv.template end<0>(); ++it) {
801 const Entity& e = *it;
802 const SubDomainSet& subDomains = gv.indexSet().subDomains(e);
803 _loadBalanceStateMap[globalIdSet().id(e)] = subDomains;
806 LoadBalancingDataHandle<DataHandle> dataHandleWrapper(*
this,dataHandle);
807 if (!_hostGrid.loadBalance(dataHandleWrapper))
812 for (Iterator it = gv.template begin<0>(); it != gv.template end<0>(); ++it) {
813 _leafIndexSet.addToSubDomains(_loadBalanceStateMap[globalIdSet().
id(*it)],*it);
820 _loadBalanceStateMap.clear();
827 EmptyDataHandle emptyDataHandle;
828 return loadBalance(emptyDataHandle);
831 size_t numBoundarySegments()
const
833 return _hostGrid.numBoundarySegments();
850 assert(_state == stateFixed && _adaptState == stateFixed);
852 _tmpLeafIndexSet->reset(
false);
853 _state = stateMarking;
865 assert(_state == stateMarking && _adaptState == stateFixed);
866 if (_supportLevelIndexSets) {
867 for (
int l = 0; l <=
maxLevel(); ++l) {
868 _tmpLevelIndexSets.push_back(std::make_shared<LevelIndexSetImp>(*
this,_hostGrid.levelGridView(l)));
871 _tmpLeafIndexSet->update(_tmpLevelIndexSets,
true);
872 _state = statePreUpdate;
880 assert(_state == statePreUpdate && _adaptState == stateFixed);
881 _leafIndexSet.swap(*_tmpLeafIndexSet);
882 if (_supportLevelIndexSets) {
883 for (
int l = 0; l <=
maxLevel(); ++l) {
884 _levelIndexSets[l]->swap(*_tmpLevelIndexSets[l]);
887 _state = statePostUpdate;
892 assert(_state == statePostUpdate && _adaptState == stateFixed);
893 _tmpLevelIndexSets.clear();
894 _tmpLeafIndexSet.reset(
nullptr);
900 assert(_state == stateMarking);
902 assert(e.partitionType() == Dune::InteriorEntity);
903 _maxAssignedSubDomainIndex = std::max(_maxAssignedSubDomainIndex,
subDomain);
904 _tmpLeafIndexSet->addToSubDomain(
subDomain,e);
909 assert(_state == stateMarking);
911 assert(e.partitionType() == Dune::InteriorEntity);
912 _tmpLeafIndexSet->removeFromSubDomain(
subDomain,e);
917 assert(_state == stateMarking);
919 assert(e.partitionType() == Dune::InteriorEntity);
920 _maxAssignedSubDomainIndex = std::max(_maxAssignedSubDomainIndex,
subDomain);
921 _tmpLeafIndexSet->assignToSubDomain(
subDomain,e);
926 assert(_state == stateMarking);
928 assert(e.partitionType() == Dune::InteriorEntity);
929 _tmpLeafIndexSet->removeFromAllSubDomains(e);
937 std::shared_ptr<SubDomainGrid>& subGridPointer = _subDomainGrids[
subDomain];
938 if (!subGridPointer) {
941 return *subGridPointer;
946 std::shared_ptr<SubDomainGrid>& subGridPointer = _subDomainGrids[
subDomain];
947 if (!subGridPointer) {
950 return *subGridPointer;
962 return _maxAssignedSubDomainIndex;
967 return _supportLevelIndexSets;
978 template<
typename EntityType>
979 static const typename HostEntity<EntityType>::type&
hostEntity(
const EntityType& e)
981 return e.impl().hostEntity();
984 template<
typename EntityType>
985 static const typename MultiDomainEntity<EntityType>::type& multiDomainEntity(
const EntityType& e)
987 return e.impl().multiDomainEntity();
990 template<
typename IntersectionType>
991 static const auto& multiDomainIntersection(
const IntersectionType& is) {
992 return SubDomainGrid::multiDomainIntersection(is);
996 const MDGridTraits& traits()
const
1003 const HostGrid& hostGrid()
const
1008 HostGrid& hostGrid()
1013 HostGrid& _hostGrid;
1014 const MDGridTraitsType _traits;
1016 std::vector<std::shared_ptr<LevelIndexSetImp> > _levelIndexSets;
1017 LeafIndexSetImp _leafIndexSet;
1019 std::vector<std::shared_ptr<LevelIndexSetImp> > _tmpLevelIndexSets;
1020 std::unique_ptr<LeafIndexSetImp> _tmpLeafIndexSet;
1022 GlobalIdSetImp _globalIdSet;
1023 LocalIdSetImp _localIdSet;
1027 const bool _supportLevelIndexSets;
1029 mutable std::map<SubDomainIndex,std::shared_ptr<SubDomainGrid> > _subDomainGrids;
1032 AdaptationStateMap _adaptationStateMap;
1033 LoadBalanceStateMap _loadBalanceStateMap;
1035 void updateIndexSets() {
1037 if (_supportLevelIndexSets) {
1038 while (
static_cast<int>(_levelIndexSets.size()) <=
maxLevel()) {
1039 _levelIndexSets.push_back(std::make_shared<LevelIndexSetImp>(*
this,_hostGrid.levelGridView(_levelIndexSets.size())));
1042 if (
static_cast<int>(_levelIndexSets.size()) >
maxLevel() + 1)
1044 _levelIndexSets.resize(
maxLevel() + 1);
1048 _leafIndexSet.reset(
true);
1049 _leafIndexSet.update(_levelIndexSets,
true);
1051 _globalIdSet.update(_hostGrid.globalIdSet());
1052 _localIdSet.update(_hostGrid.localIdSet());
1055 for (
auto& subGridPair : _subDomainGrids)
1056 subGridPair.second->update();
1059 void saveMultiDomainState() {
1060 typedef typename ThisType::LeafGridView GV;
1061 GV gv = this->leafGridView();
1062 typedef typename GV::template Codim<0>::Entity Entity;
1063 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
1064 for (
const auto& e : elements(gv)) {
1065 const SubDomainSet& subDomains = gv.indexSet().subDomains(e);
1066 _adaptationStateMap[localIdSet().id(e)] = subDomains;
1068 while (he.mightVanish()) {
1070 typename Traits::LocalIdSet::IdType
id = localIdSet().id(he);
1073 if (!_adaptationStateMap.insert(
typename AdaptationStateMap::value_type(
id,subDomains)).second) {
1075 _adaptationStateMap[id].addAll(subDomains);
1081 void restoreMultiDomainState() {
1082 typedef typename ThisType::LeafGridView GV;
1083 GV gv = this->leafGridView();
1084 typedef typename GV::template Codim<0>::Entity Entity;
1085 for (
const auto& e : elements(gv)) {
1088 while (he.isNew()) {
1093 typename AdaptationStateMap::iterator asmit = _adaptationStateMap.find(localIdSet().
id(he));
1094 while(asmit == _adaptationStateMap.end()) {
1096 asmit = _adaptationStateMap.find(localIdSet().
id(he));
1098 _leafIndexSet.addToSubDomains(asmit->second, e);
1100 _leafIndexSet.update(_levelIndexSets,
false);
1101 _adaptationStateMap.clear();
1104 template<
typename Gr
idView,
typename HostGr
idView>
1105 static typename GridView::IntersectionIterator multiDomainIntersectionIterator(
typename HostGridView::IntersectionIterator iit) {
1106 typedef decltype(std::declval<typename GridView::IntersectionIterator>().impl()) Implementation;
1107 return Implementation(iit);
1112 template<
typename Entity>
1113 typename Traits::template Codim<Entity::codimension>::Entity wrapHostEntity(
const Entity& e)
const {
1114 return wrapHostEntity<Entity::codimension>(e);
1118 typename Traits::template Codim<codim>::Entity wrapHostEntity(
const typename HostGrid::template Codim<codim>::Entity& e)
const
1120 return {EntityWrapper<codim,dimension,const GridImp>(e)};
1126 template<
typename Impl>
1127 struct DataHandleWrapper
1128 :
public Dune::CommDataHandleIF<DataHandleWrapper<Impl>,
1129 typename Impl::DataType
1133 bool contains(
int dim,
int codim)
const
1135 return _impl.contains(dim,codim);
1138 bool fixedSize(
int dim,
int codim)
const
1140 return _impl.fixedSize(dim,codim);
1143 template<
typename Entity>
1144 std::size_t size(
const Entity& e)
const
1146 return _impl.size(_grid.wrapHostEntity(e));
1149 template<
typename MessageBufferImp,
typename Entity>
1150 void gather(MessageBufferImp& buf,
const Entity& e)
const
1152 _impl.gather(buf,_grid.wrapHostEntity(e));
1155 template<
typename MessageBufferImp,
typename Entity>
1156 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1158 _impl.scatter(buf,_grid.wrapHostEntity(e),n);
1161 DataHandleWrapper(Impl& impl,
const MultiDomainGrid<HostGrid,MDGridTraitsType>& grid)
1167 const MultiDomainGrid<HostGrid,MDGridTraitsType>& _grid;
1172 template<
typename WrappedDataHandle>
1173 struct LoadBalancingDataHandle
1174 :
public Dune::CommDataHandleIF<LoadBalancingDataHandle<WrappedDataHandle>,
1175 typename WrappedDataHandle::DataType
1182 typename WrappedDataHandle::DataType buffer;
1185 static_assert(
sizeof(WrappedDataHandle::DataType) >=
sizeof(
SubDomainIndex),
1186 "During load balancing, the data type has to be large enough to contain MultiDomaingrid::SubDomainIndex");
1188 bool contains(
int dim,
int codim)
const
1191 || _wrappedDataHandle.contains(dim,codim);
1194 bool fixedSize(
int dim,
int codim)
const
1199 template<
typename Entity>
1200 std::size_t size(
const Entity& e)
const
1202 if (_grid.leafGridView().indexSet().contains(e) && e.partitionType() == Dune::InteriorEntity)
1203 return _grid.leafGridView().indexSet().subDomains(e).size() + 1 + _wrappedDataHandle.size(e);
1205 return _wrappedDataHandle.size(e);
1208 template<
typename MessageBufferImp,
typename Entity>
1209 void gather(MessageBufferImp& buf,
const Entity& e)
const
1211 assert(Entity::codimension == 0);
1212 if (e.partitionType() == Dune::InteriorEntity && _grid.leafGridView().indexSet().contains(e))
1214 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
1215 const SubDomainSet& subDomains = _grid.leafGridView().indexSet().subDomains(e);
1216 Data size = { subDomains.size() };
1217 buf.write(size.buffer);
1218 for (
typename SubDomainSet::const_iterator it = subDomains.begin(); it != subDomains.end(); ++it)
1224 _wrappedDataHandle.gather(buf,e);
1227 template<
typename MessageBufferImp,
typename Entity>
1228 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1230 if (e.partitionType() != Dune::InteriorEntity && _grid.leafGridView().indexSet().contains(e))
1232 Data subDomains = { 0 };
1233 buf.read(subDomains.buffer);
1234 for (
int i = 0; i < subDomains.data; ++i)
1238 _grid._loadBalanceStateMap[_grid.globalIdSet().id(e)].add(
subDomain.data);
1240 _wrappedDataHandle.scatter(buf,e,n - (subDomains.data + 1));
1243 _wrappedDataHandle.scatter(buf,e,n);
1246 LoadBalancingDataHandle(
const MultiDomainGrid& grid, WrappedDataHandle& wrappedDataHandle)
1248 , _wrappedDataHandle(wrappedDataHandle)
1252 WrappedDataHandle& _wrappedDataHandle;
1256 struct EmptyDataHandle
1257 :
public Dune::CommDataHandleIF<EmptyDataHandle,
1262 bool contains(
int dim,
int codim)
const
1267 bool fixedSize(
int dim,
int codim)
const
1272 template<
typename Entity>
1273 std::size_t size(
const Entity& e)
const
1278 template<
typename MessageBufferImp,
typename Entity>
1279 void gather(MessageBufferImp& buf,
const Entity& e)
const
1283 template<
typename MessageBufferImp,
typename Entity>
1284 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1292enum MultiDomainGridType { multiDomainGrid, subDomainGrid, other };
1296 static const MultiDomainGridType v = other;
1299template<
class HostGr
id,
typename MDGr
idTraits>
1300struct GridType<MultiDomainGrid<HostGrid,MDGridTraits> > {
1301 static const MultiDomainGridType v = multiDomainGrid;
1304template<
class MDGr
id>
1305struct GridType<subdomain::SubDomainGrid<MDGrid> > {
1306 static const MultiDomainGridType v = subDomainGrid;
Definition: indexsets.hh:236
A meta grid for dividing an existing DUNE grid into subdomains that can be accessed as a grid in thei...
Definition: multidomaingrid.hh:241
Traits::LeafAllSubDomainInterfacesIterator LeafAllSubDomainInterfacesIterator
The type of the iterators over the codim 1 interfaces between all subdomains on the leaf view.
Definition: multidomaingrid.hh:415
Traits::LevelAllSubDomainInterfacesIterator LevelAllSubDomainInterfacesIterator
The type of the iterators over the codim 1 interfaces between all subdomains on a level view.
Definition: multidomaingrid.hh:418
LevelAllSubDomainInterfacesIterator levelAllSubDomainInterfacesBegin(int level) const
Returns an iterator over all subdomain interfaces on the requested level view.
Definition: multidomaingrid.hh:662
MultiDomainGrid(HostGrid &hostGrid, const MDGridTraitsType &traits, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:449
Traits::LevelSubDomainInterfaceIterator LevelSubDomainInterfaceIterator
The type of the iterators over the codim 1 interface between two subdomains on a level view.
Definition: multidomaingrid.hh:412
static const HostEntity< EntityType >::type & hostEntity(const EntityType &e)
Returns a reference to the corresponding host entity.
Definition: multidomaingrid.hh:979
void startSubDomainMarking()
Prepares the grid for (re-)assigning cells to subdomains.
Definition: multidomaingrid.hh:849
void updateSubDomains()
Switches the subdomain layout over to the new layout.
Definition: multidomaingrid.hh:879
const SubDomainIndex maxSubDomainIndex() const
The largest allowed index for a subdomain.
Definition: multidomaingrid.hh:393
void postUpdateSubDomains()
clears the saved state of the subdomain layout that was active before the last call to updateSubDomai...
Definition: multidomaingrid.hh:891
int maxLevel() const
The current maximum level of the grid.
Definition: multidomaingrid.hh:476
MDGridTraits::SubDomainIndex SubDomainIndex
The (integer) type used to identify subdomains.
Definition: multidomaingrid.hh:382
bool supportLevelIndexSets() const
Indicates whether this MultiDomainGrid instance supports level index sets on its SubDomainGrids.
Definition: multidomaingrid.hh:966
LeafSubDomainInterfaceIterator leafSubDomainInterfaceEnd(SubDomainIndex subDomain1, SubDomainIndex subDomain2) const
Returns the corresponding end iterator for leafSubDomainInterfaceBegin().
Definition: multidomaingrid.hh:594
LevelAllSubDomainInterfacesIterator levelAllSubDomainInterfacesEnd(int level) const
Returns the corresponding end iterator for levelAllSubDomainInterfacesBegin().
Definition: multidomaingrid.hh:670
SubDomainIndex maxAssignedSubDomainIndex() const
Returns the largest subdomain index that was ever assigned to a cell in this grid.
Definition: multidomaingrid.hh:960
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:916
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:609
LeafSubDomainInterfaceIterator leafSubDomainInterfaceBegin(SubDomainIndex subDomain1, SubDomainIndex subDomain2) const
Returns an iterator over the leaf interface of two subdomains.
Definition: multidomaingrid.hh:589
void removeFromSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Removes the given leaf entity from the specified subdomain.
Definition: multidomaingrid.hh:908
SubDomainGrid & subDomain(SubDomainIndex subDomain)
Returns a reference to the SubDomainGrid associated with the given subdomain.
Definition: multidomaingrid.hh:945
static const std::size_t maxNumberOfSubDomains
The largest number of subdomains any given grid cell may belong to.
Definition: multidomaingrid.hh:385
subdomain::SubDomainGrid< ThisType > SubDomainGrid
The type used for representing the grid of a subdomain, always a specialization of Dune::mdgrid::subd...
Definition: multidomaingrid.hh:405
void addToSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Adds the given leaf entity to the specified subdomain.
Definition: multidomaingrid.hh:899
Traits::LeafSubDomainInterfaceIterator LeafSubDomainInterfaceIterator
The type of the iterators over the codim 1 interface between two subdomains on the leaf view.
Definition: multidomaingrid.hh:409
LeafAllSubDomainInterfacesIterator leafAllSubDomainInterfacesEnd() const
Returns the corresponding end iterator for leafAllSubDomainInterfacesBegin().
Definition: multidomaingrid.hh:641
void preUpdateSubDomains()
Calculates the new subdomain layout, but does not update the current subdomains yet.
Definition: multidomaingrid.hh:864
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:925
const SubDomainGrid & subDomain(SubDomainIndex subDomain) const
Returns a reference to the SubDomainGrid associated with the given subdomain.
Definition: multidomaingrid.hh:936
LevelSubDomainInterfaceIterator levelSubDomainInterfaceEnd(SubDomainIndex subDomain1, SubDomainIndex subDomain2, int level) const
Returns the corresponding end iterator for levelSubDomainInterfaceBegin().
Definition: multidomaingrid.hh:617
MultiDomainGrid(HostGrid &hostGrid, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:428
LeafAllSubDomainInterfacesIterator leafAllSubDomainInterfacesBegin() const
Returns an iterator over all subdomain interfaces on the leaf view.
Definition: multidomaingrid.hh:636
An intersection that forms part of the interface between two subdomains.
Definition: subdomaininterfaceiterator.hh:32