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 CollectiveCommunication
175 [[deprecated(
"Use CommunicationType. Will be removed after release 2.9")]]
176 =
typename HostGrid::CollectiveCommunication;
178 using Communication =
typename HostGrid::Communication;
180 using LeafSubDomainInterfaceIterator = Dune::mdgrid::LeafSubDomainInterfaceIterator<const Grid>;
181 using LevelSubDomainInterfaceIterator = Dune::mdgrid::LevelSubDomainInterfaceIterator<const Grid>;
183 using LeafAllSubDomainInterfacesIterator = Dune::mdgrid::LeafAllSubDomainInterfacesIterator<const Grid>;
184 using LevelAllSubDomainInterfacesIterator = Dune::mdgrid::LevelAllSubDomainInterfacesIterator<const Grid>;
192 template<
typename Gr
id,
typename SI,
bool max_subdomain_index_is_static>
193 struct MaxSubDomainIndexProvider
196 typedef SI SubDomainIndex;
198 const SubDomainIndex maxSubDomainIndex()
const
200 return static_cast<const Grid*
>(
this)->traits().maxSubDomainIndex();
205 template<
typename Gr
id,
typename SI>
206 struct MaxSubDomainIndexProvider<Grid,SI,true>
209 typedef SI SubDomainIndex;
211 static constexpr SubDomainIndex maxSubDomainIndex()
213 return Grid::MDGridTraits::maxSubDomainIndex();
229 typename MDGridTraitsType
232 :
public GridDefaultImplementation<HostGrid_::dimension,
233 HostGrid_::dimensionworld,
234 typename HostGrid_::ctype,
235 MultiDomainGridFamily<
240 public Impl::MaxSubDomainIndexProvider<MultiDomainGrid<
244 typename MDGridTraitsType::SubDomainIndex,
245 MDGridTraitsType::maxSubDomainIndexIsStatic()
251 using HostGrid = HostGrid_;
256 template<
int codim,
int dim,
typename Gr
idImp>
257 friend class EntityWrapper;
259 template<
typename,
int,PartitionIteratorType,
typename>
260 friend class IteratorWrapper;
262 template<
typename Gr
idImp>
263 friend class HierarchicIteratorWrapper;
265 template<
int mydim,
int coorddim,
typename Gr
idImp>
266 friend class GeometryWrapper;
268 template<
int mydim,
int coorddim,
typename Gr
idImp>
269 friend class LocalGeometryWrapper;
271 template<
typename Gr
idImp,
typename WrappedIndexSet>
274 template<
typename Gr
idImp,
typename WrappedIdSet>
275 friend class IdSetWrapper;
277 template<
typename Gr
idImp>
278 friend struct detail::HostGridAccessor;
280 template<
typename,
typename>
281 friend class IntersectionIteratorWrapper;
283 template<
typename,
typename>
284 friend class IntersectionWrapper;
287 friend class subdomain::SubDomainGrid;
290 friend struct subdomain::SubDomainGridFamily;
292 template<
int,
int,
typename>
293 friend class subdomain::EntityWrapperBase;
295 template<
int,
int,
typename>
296 friend class subdomain::EntityWrapper;
310 template<
typename,
typename,
typename,
typename>
313 template<
typename,
typename,
typename>
314 friend class subdomain::IntersectionIteratorWrapper;
316 template<
typename,
typename,
typename>
317 friend class subdomain::IntersectionWrapper;
320 friend class LeafGridView;
323 friend class LevelGridView;
325 typedef GridDefaultImplementation<HostGrid::dimension,
326 HostGrid::dimensionworld,
327 typename HostGrid::ctype,
328 MultiDomainGridFamily<HostGrid,MDGridTraitsType>
337 typedef IdSetWrapper<const GridImp, typename HostGrid::Traits::GlobalIdSet> GlobalIdSetImp;
339 typedef IdSetWrapper<const GridImp, typename HostGrid::Traits::LocalIdSet> LocalIdSetImp;
341 enum State { stateFixed, stateMarking, statePreUpdate, statePostUpdate, statePreAdapt, statePostAdapt };
345 using Base = GridDefaultImplementation<
347 HostGrid::dimensionworld,
348 typename HostGrid::ctype,
349 MultiDomainGridFamily<
357 using Base::dimension;
358 using Base::dimensionworld;
360 typedef MultiDomainGridFamily<HostGrid,MDGridTraitsType> GridFamily;
361 typedef typename GridFamily::Traits Traits;
362 typedef MDGridTraitsType MDGridTraits;
363 typedef typename HostGrid::ctype ctype;
367 typedef std::map<typename Traits::LocalIdSet::IdType,typename MDGridTraits::template Codim<0>::SubDomainSet> AdaptationStateMap;
369 typedef std::map<typename Traits::GlobalIdSet::IdType,typename MDGridTraits::template Codim<0>::SubDomainSet> LoadBalanceStateMap;
373 template<
typename Entity>
375 typedef typename HostGrid::Traits::template Codim<Entity::codimension>::Entity type;
380 template<
typename Entity>
381 struct MultiDomainEntity {
382 typedef typename Traits::template Codim<Entity::codimension>::Entity type;
401 return _traits.maxSubDomainIndex();
405 static constexpr bool maxSubDomainIndexIsStatic()
407 return MDGridTraits::maxSubDomainIndexIsStatic();
435 _hostGridPtr(hostGrid),
436 _hostGrid(*_hostGridPtr),
438 _leafIndexSet(*this,_hostGrid.leafGridView()),
442 _adaptState(stateFixed),
444 _maxAssignedSubDomainIndex(0)
457 _hostGridPtr(hostGrid),
458 _hostGrid(*_hostGridPtr),
460 _leafIndexSet(*this,_hostGrid.leafGridView()),
464 _adaptState(stateFixed),
466 _maxAssignedSubDomainIndex(0)
500 template<
typename EntitySeed>
501 typename Traits::template Codim<EntitySeed::codimension>::Entity
502 entity(
const EntitySeed& entitySeed)
const
504 return {EntityWrapper<EntitySeed::codimension,dimension,const GridImp>(_hostGrid.entity(entitySeed.hostEntitySeed()))};
509 return _hostGrid.maxLevel();
513 typename Traits::template Codim<codim>::LevelIterator lbegin(
int level)
const {
516 typename HostGrid::LevelGridView,
520 >(_hostGrid.levelGridView(level).template begin<codim>())
525 typename Traits::template Codim<codim>::LevelIterator lend(
int level)
const {
528 typename HostGrid::LevelGridView,
532 >(_hostGrid.levelGridView(level).template end<codim>())
536 template<
int codim, PartitionIteratorType pitype>
537 typename Traits::template Codim<codim>::template Partition<pitype>::LevelIterator lbegin(
int level)
const {
540 typename HostGrid::LevelGridView,
544 >(_hostGrid.levelGridView(level).template begin<codim,pitype>())
548 template<
int codim, PartitionIteratorType pitype>
549 typename Traits::template Codim<codim>::template Partition<pitype>::LevelIterator lend(
int level)
const {
552 typename HostGrid::LevelGridView,
556 >(_hostGrid.levelGridView(level).template end<codim,pitype>())
561 typename Traits::template Codim<codim>::LeafIterator leafbegin()
const {
564 typename HostGrid::LeafGridView,
568 >(_hostGrid.leafGridView().template begin<codim>())
573 typename Traits::template Codim<codim>::LeafIterator leafend()
const {
576 typename HostGrid::LeafGridView,
580 >(_hostGrid.leafGridView().template end<codim>())
584 template<
int codim, PartitionIteratorType pitype>
585 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator leafbegin()
const {
588 typename HostGrid::LeafGridView,
592 >(_hostGrid.leafGridView().template begin<codim,pitype>())
596 template<
int codim, PartitionIteratorType pitype>
597 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator leafend()
const {
600 typename HostGrid::LeafGridView,
604 >(_hostGrid.leafGridView().template end<codim,pitype>())
709 int size(
int level,
int codim)
const {
710 return _hostGrid.size(level,codim);
713 int size(
int codim)
const {
714 return _hostGrid.size(codim);
717 int size(
int level, GeometryType type)
const {
718 return _hostGrid.size(level,type);
721 int size(GeometryType type)
const {
722 return _hostGrid.size(type);
725 const typename Traits::GlobalIdSet& globalIdSet()
const {
729 const typename Traits::LocalIdSet& localIdSet()
const {
733 const typename Traits::LevelIndexSet& levelIndexSet(
int level)
const {
734 if (!_supportLevelIndexSets) {
735 DUNE_THROW(GridError,
"level index set support not enabled for this grid");
738 return *_levelIndexSets[level];
741 const typename Traits::LeafIndexSet& leafIndexSet()
const {
742 return _leafIndexSet;
745 void globalRefine(
int refCount) {
746 saveMultiDomainState();
747 _hostGrid.globalRefine(refCount);
749 restoreMultiDomainState();
752 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity& e) {
753 assert(_state == stateFixed);
754 return _hostGrid.mark(refCount,
hostEntity(e));
757 int getMark(
const typename Traits::template Codim<0>::Entity& e) {
758 assert(_state == stateFixed);
763 assert(_state == stateFixed && _adaptState == stateFixed);
764 _adaptState = statePreAdapt;
765 bool result = _hostGrid.preAdapt();
770 assert(_state == stateFixed && _adaptState == statePreAdapt);
771 _adaptState = statePostAdapt;
772 saveMultiDomainState();
773 bool result = _hostGrid.adapt();
775 restoreMultiDomainState();
780 assert(_state == stateFixed && _adaptState == statePostAdapt);
781 _adaptState = stateFixed;
782 _hostGrid.postAdapt();
785 int overlapSize(
int level,
int codim)
const {
786 return _hostGrid.overlapSize(level,codim);
789 int overlapSize(
int codim)
const {
790 return _hostGrid.overlapSize(codim);
793 int ghostSize(
int level,
int codim)
const {
794 return _hostGrid.ghostSize(level,codim);
797 int ghostSize(
int codim)
const {
798 return _hostGrid.ghostSize(codim);
801 const typename Traits::Communication& comm()
const {
802 return _hostGrid.comm();
805 template<
typename DataHandleImp,
typename DataTypeImp>
806 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> &data,
807 InterfaceType iftype,
808 CommunicationDirection dir,
811 DataHandleWrapper<CommDataHandleIF<DataHandleImp,DataTypeImp> > datahandle(data,*
this);
812 _hostGrid.levelGridView(level).communicate(datahandle,iftype,dir);
815 template<
typename DataHandleImp,
typename DataTypeImp>
816 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> &data,
817 InterfaceType iftype,
818 CommunicationDirection dir)
const
820 DataHandleWrapper<CommDataHandleIF<DataHandleImp,DataTypeImp> > datahandle(data,*
this);
821 _hostGrid.leafGridView().communicate(datahandle,iftype,dir);
824 template<
typename DataHandle>
825 bool loadBalance(DataHandle& dataHandle)
827 typedef typename MultiDomainGrid::LeafGridView GV;
828 GV gv = this->leafGridView();
829 typedef typename GV::template Codim<0>::Iterator Iterator;
830 typedef typename GV::template Codim<0>::Entity Entity;
831 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
832 for (Iterator it = gv.template begin<0>(); it != gv.template end<0>(); ++it) {
833 const Entity& e = *it;
834 const SubDomainSet& subDomains = gv.indexSet().subDomains(e);
835 _loadBalanceStateMap[globalIdSet().id(e)] = subDomains;
838 LoadBalancingDataHandle<DataHandle> dataHandleWrapper(*
this,dataHandle);
839 if (!_hostGrid.loadBalance(dataHandleWrapper))
844 for (Iterator it = gv.template begin<0>(); it != gv.template end<0>(); ++it) {
845 _leafIndexSet.addToSubDomains(_loadBalanceStateMap[globalIdSet().
id(*it)],*it);
852 _loadBalanceStateMap.clear();
859 EmptyDataHandle emptyDataHandle;
860 return loadBalance(emptyDataHandle);
863 size_t numBoundarySegments()
const
865 return _hostGrid.numBoundarySegments();
882 assert(_state == stateFixed && _adaptState == stateFixed);
884 _tmpLeafIndexSet->reset(
false);
885 _state = stateMarking;
897 assert(_state == stateMarking && _adaptState == stateFixed);
898 if (_supportLevelIndexSets) {
899 for (
int l = 0; l <=
maxLevel(); ++l) {
900 _tmpLevelIndexSets.push_back(std::make_shared<LevelIndexSetImp>(*
this,_hostGrid.levelGridView(l)));
903 _tmpLeafIndexSet->update(_tmpLevelIndexSets,
true);
904 _state = statePreUpdate;
912 assert(_state == statePreUpdate && _adaptState == stateFixed);
913 _leafIndexSet.swap(*_tmpLeafIndexSet);
914 if (_supportLevelIndexSets) {
915 for (
int l = 0; l <=
maxLevel(); ++l) {
916 _levelIndexSets[l]->swap(*_tmpLevelIndexSets[l]);
919 _state = statePostUpdate;
924 assert(_state == statePostUpdate && _adaptState == stateFixed);
925 _tmpLevelIndexSets.clear();
926 _tmpLeafIndexSet.reset(
nullptr);
932 assert(_state == stateMarking);
934 assert(e.partitionType() == Dune::InteriorEntity);
935 _maxAssignedSubDomainIndex = std::max(_maxAssignedSubDomainIndex,
subDomain);
936 _tmpLeafIndexSet->addToSubDomain(
subDomain,e);
941 assert(_state == stateMarking);
943 assert(e.partitionType() == Dune::InteriorEntity);
944 _tmpLeafIndexSet->removeFromSubDomain(
subDomain,e);
949 assert(_state == stateMarking);
951 assert(e.partitionType() == Dune::InteriorEntity);
952 _maxAssignedSubDomainIndex = std::max(_maxAssignedSubDomainIndex,
subDomain);
953 _tmpLeafIndexSet->assignToSubDomain(
subDomain,e);
958 assert(_state == stateMarking);
960 assert(e.partitionType() == Dune::InteriorEntity);
961 _tmpLeafIndexSet->removeFromAllSubDomains(e);
969 std::shared_ptr<SubDomainGrid>& subGridPointer = _subDomainGrids[
subDomain];
970 if (!subGridPointer) {
973 return *subGridPointer;
978 std::shared_ptr<SubDomainGrid>& subGridPointer = _subDomainGrids[
subDomain];
979 if (!subGridPointer) {
982 return *subGridPointer;
994 return _maxAssignedSubDomainIndex;
999 return _supportLevelIndexSets;
1010 template<
typename EntityType>
1011 static const typename HostEntity<EntityType>::type&
hostEntity(
const EntityType& e)
1013 return e.impl().hostEntity();
1016 template<
typename EntityType>
1017 static const typename MultiDomainEntity<EntityType>::type& multiDomainEntity(
const EntityType& e)
1019 return e.impl().multiDomainEntity();
1022 template<
typename IntersectionType>
1023 static const auto& multiDomainIntersection(
const IntersectionType& is) {
1024 return SubDomainGrid::multiDomainIntersection(is);
1028 const MDGridTraits& traits()
const
1035 const HostGrid& hostGrid()
const
1040 HostGrid& hostGrid()
1045 std::shared_ptr<HostGrid> _hostGridPtr;
1046 HostGrid& _hostGrid;
1047 const MDGridTraitsType _traits;
1049 std::vector<std::shared_ptr<LevelIndexSetImp> > _levelIndexSets;
1050 LeafIndexSetImp _leafIndexSet;
1052 std::vector<std::shared_ptr<LevelIndexSetImp> > _tmpLevelIndexSets;
1053 std::unique_ptr<LeafIndexSetImp> _tmpLeafIndexSet;
1055 GlobalIdSetImp _globalIdSet;
1056 LocalIdSetImp _localIdSet;
1060 const bool _supportLevelIndexSets;
1062 mutable std::map<SubDomainIndex,std::shared_ptr<SubDomainGrid> > _subDomainGrids;
1065 AdaptationStateMap _adaptationStateMap;
1066 LoadBalanceStateMap _loadBalanceStateMap;
1068 void updateIndexSets() {
1070 if (_supportLevelIndexSets) {
1071 while (
static_cast<int>(_levelIndexSets.size()) <=
maxLevel()) {
1072 _levelIndexSets.push_back(std::make_shared<LevelIndexSetImp>(*
this,_hostGrid.levelGridView(_levelIndexSets.size())));
1075 if (
static_cast<int>(_levelIndexSets.size()) >
maxLevel() + 1)
1077 _levelIndexSets.resize(
maxLevel() + 1);
1081 _leafIndexSet.reset(
true);
1082 _leafIndexSet.update(_levelIndexSets,
true);
1084 _globalIdSet.update(_hostGrid.globalIdSet());
1085 _localIdSet.update(_hostGrid.localIdSet());
1088 for (
auto& subGridPair : _subDomainGrids)
1089 subGridPair.second->update();
1092 void saveMultiDomainState() {
1093 typedef typename ThisType::LeafGridView GV;
1094 GV gv = this->leafGridView();
1095 typedef typename GV::template Codim<0>::Entity Entity;
1096 typedef typename MDGridTraits::template Codim<0>::SubDomainSet SubDomainSet;
1097 for (
const auto& e : elements(gv)) {
1098 const SubDomainSet& subDomains = gv.indexSet().subDomains(e);
1099 _adaptationStateMap[localIdSet().id(e)] = subDomains;
1101 while (he.mightVanish()) {
1103 typename Traits::LocalIdSet::IdType
id = localIdSet().id(he);
1106 if (!_adaptationStateMap.insert(
typename AdaptationStateMap::value_type(
id,subDomains)).second) {
1108 _adaptationStateMap[id].addAll(subDomains);
1114 void restoreMultiDomainState() {
1115 typedef typename ThisType::LeafGridView GV;
1116 GV gv = this->leafGridView();
1117 typedef typename GV::template Codim<0>::Entity Entity;
1118 for (
const auto& e : elements(gv)) {
1121 while (he.isNew()) {
1126 typename AdaptationStateMap::iterator asmit = _adaptationStateMap.find(localIdSet().
id(he));
1127 while(asmit == _adaptationStateMap.end()) {
1129 asmit = _adaptationStateMap.find(localIdSet().
id(he));
1131 _leafIndexSet.addToSubDomains(asmit->second, e);
1133 _leafIndexSet.update(_levelIndexSets,
false);
1134 _adaptationStateMap.clear();
1137 template<
typename Gr
idView,
typename HostGr
idView>
1138 static typename GridView::IntersectionIterator multiDomainIntersectionIterator(
typename HostGridView::IntersectionIterator iit) {
1139 typedef decltype(std::declval<typename GridView::IntersectionIterator>().impl()) Implementation;
1140 return Implementation(iit);
1145 template<
typename Entity>
1146 typename Traits::template Codim<Entity::codimension>::Entity wrapHostEntity(
const Entity& e)
const {
1147 return wrapHostEntity<Entity::codimension>(e);
1151 typename Traits::template Codim<codim>::Entity wrapHostEntity(
const typename HostGrid::template Codim<codim>::Entity& e)
const
1153 return {EntityWrapper<codim,dimension,const GridImp>(e)};
1159 template<
typename Impl>
1160 struct DataHandleWrapper
1161 :
public Dune::CommDataHandleIF<DataHandleWrapper<Impl>,
1162 typename Impl::DataType
1166 bool contains(
int dim,
int codim)
const
1168 return _impl.contains(dim,codim);
1171 bool fixedSize(
int dim,
int codim)
const
1173 return _impl.fixedSize(dim,codim);
1176 template<
typename Entity>
1177 std::size_t size(
const Entity& e)
const
1179 return _impl.size(_grid.wrapHostEntity(e));
1182 template<
typename MessageBufferImp,
typename Entity>
1183 void gather(MessageBufferImp& buf,
const Entity& e)
const
1185 _impl.gather(buf,_grid.wrapHostEntity(e));
1188 template<
typename MessageBufferImp,
typename Entity>
1189 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1191 _impl.scatter(buf,_grid.wrapHostEntity(e),n);
1194 DataHandleWrapper(Impl& impl,
const MultiDomainGrid<HostGrid,MDGridTraitsType>& grid)
1200 const MultiDomainGrid<HostGrid,MDGridTraitsType>& _grid;
1205 template<
typename WrappedDataHandle>
1206 struct LoadBalancingDataHandle
1207 :
public Dune::CommDataHandleIF<LoadBalancingDataHandle<WrappedDataHandle>,
1208 typename WrappedDataHandle::DataType
1215 typename WrappedDataHandle::DataType buffer;
1219 "During load balancing, the data type has to be large enough to contain MultiDomaingrid::SubDomainIndex");
1221 bool contains(
int dim,
int codim)
const
1224 || _wrappedDataHandle.contains(dim,codim);
1227 bool fixedSize(
int dim,
int codim)
const
1232 template<
typename Entity>
1233 std::size_t size(
const Entity& e)
const
1235 if (_grid.leafGridView().indexSet().contains(e) && e.partitionType() == Dune::InteriorEntity)
1236 return _grid.leafGridView().indexSet().subDomains(e).size() + 1 + _wrappedDataHandle.size(e);
1238 return _wrappedDataHandle.size(e);
1241 template<
typename MessageBufferImp,
typename Entity>
1242 void gather(MessageBufferImp& buf,
const Entity& e)
const
1244 assert(Entity::codimension == 0);
1245 if (e.partitionType() == Dune::InteriorEntity && _grid.leafGridView().indexSet().contains(e))
1247 const auto& subDomains = _grid.leafGridView().indexSet().subDomains(e);
1248 Data size = { subDomains.size() };
1249 buf.write(size.buffer);
1250 for (
auto& sub_domain : subDomains)
1256 _wrappedDataHandle.gather(buf,e);
1259 template<
typename MessageBufferImp,
typename Entity>
1260 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1262 if (e.partitionType() != Dune::InteriorEntity && _grid.leafGridView().indexSet().contains(e))
1264 Data subDomains = { 0 };
1265 buf.read(subDomains.buffer);
1266 for (
int i = 0; i < subDomains.data; ++i)
1270 _grid._loadBalanceStateMap[_grid.globalIdSet().id(multiDomainEntity(e))].add(
subDomain.data);
1272 _wrappedDataHandle.scatter(buf,e,n - (subDomains.data + 1));
1275 _wrappedDataHandle.scatter(buf,e,n);
1278 LoadBalancingDataHandle(
MultiDomainGrid& grid, WrappedDataHandle& wrappedDataHandle)
1280 , _wrappedDataHandle(wrappedDataHandle)
1284 WrappedDataHandle& _wrappedDataHandle;
1288 struct EmptyDataHandle
1289 :
public Dune::CommDataHandleIF<EmptyDataHandle,
1294 bool contains(
int dim,
int codim)
const
1299 bool fixedSize(
int dim,
int codim)
const
1304 template<
typename Entity>
1305 std::size_t size(
const Entity& e)
const
1310 template<
typename MessageBufferImp,
typename Entity>
1311 void gather(MessageBufferImp& buf,
const Entity& e)
const
1315 template<
typename MessageBufferImp,
typename Entity>
1316 void scatter(MessageBufferImp& buf,
const Entity& e, std::size_t n)
1324enum MultiDomainGridType { multiDomainGrid, subDomainGrid, other };
1328 static const MultiDomainGridType v = other;
1331template<
class HostGr
id,
typename MDGr
idTraits>
1332struct GridType<MultiDomainGrid<HostGrid,MDGridTraits> > {
1333 static const MultiDomainGridType v = multiDomainGrid;
1336template<
class MDGr
id>
1337struct GridType<subdomain::SubDomainGrid<MDGrid> > {
1338 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:247
Traits::LeafAllSubDomainInterfacesIterator LeafAllSubDomainInterfacesIterator
The type of the iterators over the codim 1 interfaces between all subdomains on the leaf view.
Definition: multidomaingrid.hh:421
Traits::LevelAllSubDomainInterfacesIterator LevelAllSubDomainInterfacesIterator
The type of the iterators over the codim 1 interfaces between all subdomains on a level view.
Definition: multidomaingrid.hh:424
LevelAllSubDomainInterfacesIterator levelAllSubDomainInterfacesBegin(int level) const
Returns an iterator over all subdomain interfaces on the requested level view.
Definition: multidomaingrid.hh:694
MultiDomainGrid(HostGrid &hostGrid, const MDGridTraitsType &traits, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:491
Traits::LevelSubDomainInterfaceIterator LevelSubDomainInterfaceIterator
The type of the iterators over the codim 1 interface between two subdomains on a level view.
Definition: multidomaingrid.hh:418
static const HostEntity< EntityType >::type & hostEntity(const EntityType &e)
Returns a reference to the corresponding host entity.
Definition: multidomaingrid.hh:1011
void startSubDomainMarking()
Prepares the grid for (re-)assigning cells to subdomains.
Definition: multidomaingrid.hh:881
void updateSubDomains()
Switches the subdomain layout over to the new layout.
Definition: multidomaingrid.hh:911
const SubDomainIndex maxSubDomainIndex() const
The largest allowed index for a subdomain.
Definition: multidomaingrid.hh:399
void postUpdateSubDomains()
clears the saved state of the subdomain layout that was active before the last call to updateSubDomai...
Definition: multidomaingrid.hh:923
int maxLevel() const
The current maximum level of the grid.
Definition: multidomaingrid.hh:508
MDGridTraits::SubDomainIndex SubDomainIndex
The (integer) type used to identify subdomains.
Definition: multidomaingrid.hh:388
bool supportLevelIndexSets() const
Indicates whether this MultiDomainGrid instance supports level index sets on its SubDomainGrids.
Definition: multidomaingrid.hh:998
LeafSubDomainInterfaceIterator leafSubDomainInterfaceEnd(SubDomainIndex subDomain1, SubDomainIndex subDomain2) const
Returns the corresponding end iterator for leafSubDomainInterfaceBegin().
Definition: multidomaingrid.hh:626
LevelAllSubDomainInterfacesIterator levelAllSubDomainInterfacesEnd(int level) const
Returns the corresponding end iterator for levelAllSubDomainInterfacesBegin().
Definition: multidomaingrid.hh:702
MultiDomainGrid(const std::shared_ptr< HostGrid > &hostGrid, const MDGridTraitsType &traits, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:456
SubDomainIndex maxAssignedSubDomainIndex() const
Returns the largest subdomain index that was ever assigned to a cell in this grid.
Definition: multidomaingrid.hh:992
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:948
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:641
LeafSubDomainInterfaceIterator leafSubDomainInterfaceBegin(SubDomainIndex subDomain1, SubDomainIndex subDomain2) const
Returns an iterator over the leaf interface of two subdomains.
Definition: multidomaingrid.hh:621
void removeFromSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Removes the given leaf entity from the specified subdomain.
Definition: multidomaingrid.hh:940
SubDomainGrid & subDomain(SubDomainIndex subDomain)
Returns a reference to the SubDomainGrid associated with the given subdomain.
Definition: multidomaingrid.hh:977
static const std::size_t maxNumberOfSubDomains
The largest number of subdomains any given grid cell may belong to.
Definition: multidomaingrid.hh:391
subdomain::SubDomainGrid< ThisType > SubDomainGrid
The type used for representing the grid of a subdomain, always a specialization of Dune::mdgrid::subd...
Definition: multidomaingrid.hh:411
void addToSubDomain(SubDomainIndex subDomain, const typename Traits::template Codim< 0 >::Entity &e)
Adds the given leaf entity to the specified subdomain.
Definition: multidomaingrid.hh:931
Traits::LeafSubDomainInterfaceIterator LeafSubDomainInterfaceIterator
The type of the iterators over the codim 1 interface between two subdomains on the leaf view.
Definition: multidomaingrid.hh:415
LeafAllSubDomainInterfacesIterator leafAllSubDomainInterfacesEnd() const
Returns the corresponding end iterator for leafAllSubDomainInterfacesBegin().
Definition: multidomaingrid.hh:673
void preUpdateSubDomains()
Calculates the new subdomain layout, but does not update the current subdomains yet.
Definition: multidomaingrid.hh:896
MultiDomainGrid(const std::shared_ptr< HostGrid > &hostGrid, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:434
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:957
const SubDomainGrid & subDomain(SubDomainIndex subDomain) const
Returns a reference to the SubDomainGrid associated with the given subdomain.
Definition: multidomaingrid.hh:968
LevelSubDomainInterfaceIterator levelSubDomainInterfaceEnd(SubDomainIndex subDomain1, SubDomainIndex subDomain2, int level) const
Returns the corresponding end iterator for levelSubDomainInterfaceBegin().
Definition: multidomaingrid.hh:649
MultiDomainGrid(HostGrid &hostGrid, bool supportLevelIndexSets=true)
Constructs a new MultiDomainGrid from the given host grid.
Definition: multidomaingrid.hh:480
LeafAllSubDomainInterfacesIterator leafAllSubDomainInterfacesBegin() const
Returns an iterator over all subdomain interfaces on the leaf view.
Definition: multidomaingrid.hh:668
An intersection that forms part of the interface between two subdomains.
Definition: subdomaininterfaceiterator.hh:32