11 #include <dune/common/classname.hh>
12 #include <dune/common/parallel/collectivecommunication.hh>
13 #include <dune/common/exceptions.hh>
14 #include <dune/common/parallel/mpihelper.hh>
15 #include <dune/common/static_assert.hh>
21 #if HAVE_UG || DOXYGEN
24 #include <dune/common/parallel/mpicollectivecommunication.hh>
46 #include "uggrid/ugincludes.hh"
51 #include "uggrid/ugwrapper.hh"
56 #include "uggrid/ug_undefs.hh"
73 #include "uggrid/ugincludes.hh"
78 #include "uggrid/ugwrapper.hh"
82 #include "uggrid/ug_undefs.hh"
88 #include "uggrid/uggridgeometry.hh"
89 #include "uggrid/uggridlocalgeometry.hh"
90 #include "uggrid/uggridentity.hh"
91 #include "uggrid/uggridentitypointer.hh"
92 #include "uggrid/uggridentityseed.hh"
93 #include "uggrid/uggridintersections.hh"
94 #include "uggrid/uggridintersectioniterators.hh"
95 #include "uggrid/uggridleveliterator.hh"
96 #include "uggrid/uggridleafiterator.hh"
97 #include "uggrid/uggridhieriterator.hh"
98 #include "uggrid/uggridindexsets.hh"
100 #include "uggrid/ugmessagebuffer.hh"
101 #include "uggrid/uglbgatherscatter.hh"
108 template <
class DataHandle,
int Gr
idDim,
int codim>
109 DataHandle *Dune::UGMessageBufferBase<DataHandle,GridDim,codim>::duneDataHandle_ = 0;
111 template <
class DataHandle,
int Gr
idDim,
int codim>
112 int Dune::UGMessageBufferBase<DataHandle,GridDim,codim>::level = -1;
119 class CollectiveCommunication<Dune::UGGrid<dim> > :
120 public CollectiveCommunication< Dune::MPIHelper::MPICommunicator >
122 typedef CollectiveCommunication< Dune::MPIHelper::MPICommunicator > ParentType;
124 CollectiveCommunication()
125 : ParentType(MPIHelper::getCommunicator())
138 UGGridLeafIntersection,
139 UGGridLevelIntersection,
140 UGGridLeafIntersectionIterator,
141 UGGridLevelIntersectionIterator,
142 UGGridHierarchicIterator,
144 UGGridLevelIndexSet< const UGGrid<dim> >,
145 UGGridLeafIndexSet< const UGGrid<dim> >,
146 UGGridIdSet< const UGGrid<dim> >,
147 typename UG_NS<dim>::UG_ID_TYPE,
148 UGGridIdSet< const UGGrid<dim> >,
149 typename UG_NS<dim>::UG_ID_TYPE,
150 CollectiveCommunication<Dune::UGGrid<dim> >,
206 friend class UGGridGeometry<0,dim,const
UGGrid<dim> >;
207 friend class UGGridGeometry<dim,dim,const
UGGrid<dim> >;
208 friend class UGGridGeometry<1,2,const
UGGrid<dim> >;
209 friend class UGGridGeometry<2,3,const
UGGrid<dim> >;
211 friend class UGGridEntity <0,dim,const
UGGrid<dim> >;
212 friend class UGGridEntity <dim,dim,const
UGGrid<dim> >;
213 friend class UGGridHierarchicIterator<const
UGGrid<dim> >;
214 friend class UGGridLeafIntersection<const
UGGrid<dim> >;
215 friend class UGGridLevelIntersection<const
UGGrid<dim> >;
216 friend class UGGridLeafIntersectionIterator<const
UGGrid<dim> >;
217 friend class UGGridLevelIntersectionIterator<const
UGGrid<dim> >;
219 friend class UGGridLevelIndexSet<const
UGGrid<dim> >;
220 friend class UGGridLeafIndexSet<const
UGGrid<dim> >;
221 friend class UGGridIdSet<const
UGGrid<dim> >;
226 friend class UGLBGatherScatter;
229 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
231 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
233 template <
int codim_,
class Gr
idImp_>
237 dune_static_assert(dim==2 || dim==3,
"Use UGGrid only for 2d and 3d!");
280 template<
int codim, PartitionIteratorType PiType>
284 template<
int codim, PartitionIteratorType PiType>
296 return UGGridLeafIterator<codim,All_Partition, const UGGrid<dim> >();
300 template<
int codim, PartitionIteratorType PiType>
306 template<
int codim, PartitionIteratorType PiType>
308 return UGGridLeafIterator<codim,PiType, const UGGrid<dim> >();
312 template <
typename Seed>
313 typename Traits::template Codim<Seed::codimension>::EntityPointer
316 enum {codim = Seed::codimension};
322 int size (
int level,
int codim)
const;
346 return numBoundarySegments_;
365 DUNE_THROW(
GridError,
"levelIndexSet of nonexisting level " << level <<
" requested!");
366 return *levelIndexSets_[level];
372 return leafIndexSet_;
390 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity & e );
448 bool mark(
const typename Traits::template Codim<0>::Entity & e,
449 typename UG_NS<dim>::RefinementRule rule,
453 int getMark(
const typename Traits::template Codim<0>::Entity& e)
const;
473 return (codim==0) ? 1 : 0;
483 return (codim==0) ? 1 : 0;
501 template<
class DataHandle>
505 DUNE_THROW(NotImplemented,
"load balancing with data attached");
512 UGLBGatherScatter::template gather<dim>(this->
leafView(), dataHandle);
524 UGLBGatherScatter::template scatter<dim>(this->
leafView(), dataHandle);
528 #endif // HAVE_UG_PATCH10
547 bool loadBalance(
int strategy,
int minlevel,
int depth,
int maxlevel,
int minelement);
559 template<
class DataHandle>
565 for (
int curCodim = 0; curCodim <= dim; ++curCodim) {
566 if (!dataHandle.contains(dim, curCodim))
570 communicateUG_<LevelGridView, DataHandle, 0>(this->
levelGridView(level), level, dataHandle, iftype, dir);
571 else if (curCodim == dim)
572 communicateUG_<LevelGridView, DataHandle, dim>(this->
levelGridView(level), level, dataHandle, iftype, dir);
573 else if (curCodim == dim - 1)
575 else if (curCodim == 1)
576 communicateUG_<LevelGridView, DataHandle, 1>(this->
levelGridView(level), level, dataHandle, iftype, dir);
578 DUNE_THROW(NotImplemented,
579 className(*
this) <<
"::communicate(): Not "
580 "supported for dim " << dim <<
" and codim " << curCodim);
594 template<
class DataHandle>
600 for (
int curCodim = 0; curCodim <= dim; ++curCodim) {
601 if (!dataHandle.contains(dim, curCodim))
605 communicateUG_<LeafGridView, DataHandle, 0>(this->
leafView(), level, dataHandle, iftype, dir);
606 else if (curCodim == dim)
607 communicateUG_<LeafGridView, DataHandle, dim>(this->
leafView(), level, dataHandle, iftype, dir);
608 else if (curCodim == dim - 1)
609 communicateUG_<
LeafGridView, DataHandle, dim-1>(this->
leafView(), level, dataHandle, iftype, dir);
610 else if (curCodim == 1)
611 communicateUG_<LeafGridView, DataHandle, 1>(this->
leafView(), level, dataHandle, iftype, dir);
613 DUNE_THROW(NotImplemented,
614 className(*
this) <<
"::communicate(): Not "
615 "supported for dim " << dim <<
" and codim " << curCodim);
628 template <
class Gr
idView,
class DataHandle,
int codim>
629 void communicateUG_(
const GridView& gv,
int level,
630 DataHandle &dataHandle,
634 typename UG_NS<dim>::DDD_IF_DIR ugIfDir;
637 ugIfDir = UG_NS<dim>::IF_FORWARD();
639 ugIfDir = UG_NS<dim>::IF_BACKWARD();
641 typedef UGMessageBuffer<DataHandle,dim,codim> UGMsgBuf;
642 UGMsgBuf::duneDataHandle_ = &dataHandle;
644 UGMsgBuf::level = level;
646 std::vector<typename UG_NS<dim>::DDD_IF> ugIfs;
647 findDDDInterfaces_(ugIfs, iftype, codim);
649 unsigned bufSize = UGMsgBuf::ugBufferSize_(gv);
652 for (
unsigned i=0; i < ugIfs.size(); ++i)
653 UG_NS<dim>::DDD_IFOneway(ugIfs[i],
656 &UGMsgBuf::ugGather_,
657 &UGMsgBuf::ugScatter_);
660 void findDDDInterfaces_(std::vector<
typename UG_NS<dim>::DDD_IF > &dddIfaces,
676 dddIfaces.push_back(UG_NS<dim>::ElementVHIF());
683 dddIfaces.push_back(UG_NS<dim>::ElementSymmVHIF());
686 DUNE_THROW(GridError,
687 "Element communication not supported for "
688 "interfaces of type "
692 else if (codim == dim)
697 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF());
700 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF());
701 dddIfaces.push_back(UG_NS<dim>::NodeIF());
704 dddIfaces.push_back(UG_NS<dim>::NodeAllIF());
707 DUNE_THROW(GridError,
708 "Node communication not supported for "
709 "interfaces of type "
713 else if (codim == dim-1)
718 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF());
721 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF());
726 DUNE_THROW(GridError,
727 "Edge communication not supported for "
728 "interfaces of type "
738 dddIfaces.push_back(UG_NS<dim>::BorderVectorSymmIF());
741 DUNE_THROW(GridError,
742 "Face communication not supported for "
743 "interfaces of type "
749 DUNE_THROW(GridError,
750 "Communication for codim "
752 <<
" entities is not yet supported "
753 <<
" by the DUNE UGGrid interface!");
773 std::vector<
typename Traits::template Codim<0>::EntityPointer>& childElements,
774 std::vector<unsigned char>& childElementSides)
const;
794 refinementType_ = type;
815 void setPosition(
const typename Traits::template Codim<dim>::EntityPointer& e,
816 const FieldVector<double, dim>& pos);
828 void saveState(
const std::string& filename)
const;
834 void loadState(
const std::string& filename);
838 typename UG_NS<dim>::MultiGrid* multigrid_;
841 CollectiveCommunication<UGGrid> ccobj_;
848 void setIndices(
bool setLevelZero,
849 std::vector<unsigned int>* nodePermutation);
856 std::vector<shared_ptr<UGGridLevelIndexSet<const UGGrid<dim> > > > levelIndexSets_;
858 UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
862 UGGridIdSet<const UGGrid<dim> > idSet_;
877 static int numOfUGGrids;
884 bool someElementHasBeenMarkedForRefinement_;
891 bool someElementHasBeenMarkedForCoarsening_;
897 static unsigned int heapSize_;
900 std::vector<shared_ptr<BoundarySegment<dim> > > boundarySegments_;
907 unsigned int numBoundarySegments_;
911 namespace Capabilities
931 static const bool v =
true;
940 static const bool v =
true;
950 static const bool v =
true;
952 static const bool v =
false;
962 static const bool v =
true;
971 static const bool v =
false;
978 #endif // HAVE_UG || DOXYGEN
979 #endif // DUNE_UGGRID_HH