13 #include <dune/common/classname.hh> 14 #include <dune/common/parallel/collectivecommunication.hh> 15 #include <dune/common/exceptions.hh> 16 #include <dune/common/parallel/mpihelper.hh> 17 #include <dune/common/deprecated.hh> 23 #if HAVE_UG || DOXYGEN 26 #include <dune/common/parallel/mpicollectivecommunication.hh> 52 #ifdef UG_USE_NEW_DIMENSION_DEFINES 58 #include "uggrid/ugincludes.hh" 63 #include "uggrid/ugwrapper.hh" 68 #include "uggrid/ug_undefs.hh" 69 #ifdef UG_USE_NEW_DIMENSION_DEFINES 91 #ifdef UG_USE_NEW_DIMENSION_DEFINES 97 #include "uggrid/ugincludes.hh" 102 #include "uggrid/ugwrapper.hh" 106 #include "uggrid/ug_undefs.hh" 108 #ifdef UG_USE_NEW_DIMENSION_DEFINES 116 #include "uggrid/uggridgeometry.hh" 117 #include "uggrid/uggridlocalgeometry.hh" 118 #include "uggrid/uggridentity.hh" 119 #include "uggrid/uggridentityseed.hh" 120 #include "uggrid/uggridintersections.hh" 121 #include "uggrid/uggridintersectioniterators.hh" 122 #include "uggrid/uggridleveliterator.hh" 123 #include "uggrid/uggridleafiterator.hh" 124 #include "uggrid/uggridhieriterator.hh" 125 #include "uggrid/uggridindexsets.hh" 126 #include <dune/grid/uggrid/uggridviews.hh> 128 #include "uggrid/ugmessagebuffer.hh" 129 #include "uggrid/uglbgatherscatter.hh" 136 template <
class DataHandle,
int Gr
idDim,
int codim>
137 DataHandle *Dune::UGMessageBufferBase<DataHandle,GridDim,codim>::duneDataHandle_ = 0;
139 template <
class DataHandle,
int Gr
idDim,
int codim>
140 int Dune::UGMessageBufferBase<DataHandle,GridDim,codim>::level = -1;
147 class CollectiveCommunication<Dune::UGGrid<dim> > :
148 public CollectiveCommunication< Dune::MPIHelper::MPICommunicator >
150 typedef CollectiveCommunication< Dune::MPIHelper::MPICommunicator > ParentType;
152 CollectiveCommunication()
153 : ParentType(MPIHelper::getCommunicator())
165 UGGridLeafIntersection,
166 UGGridLevelIntersection,
167 UGGridLeafIntersectionIterator,
168 UGGridLevelIntersectionIterator,
169 UGGridHierarchicIterator,
171 UGGridLevelIndexSet< const UGGrid<dim> >,
172 UGGridLeafIndexSet< const UGGrid<dim> >,
173 UGGridIdSet< const UGGrid<dim> >,
174 typename UG_NS<dim>::UG_ID_TYPE,
175 UGGridIdSet< const UGGrid<dim> >,
176 typename UG_NS<dim>::UG_ID_TYPE,
177 CollectiveCommunication<Dune::UGGrid<dim> >,
178 UGGridLevelGridViewTraits,
179 UGGridLeafGridViewTraits,
234 friend class UGGridGeometry<0,dim,const
UGGrid<dim> >;
235 friend class UGGridGeometry<dim,dim,const
UGGrid<dim> >;
236 friend class UGGridGeometry<1,2,const
UGGrid<dim> >;
237 friend class UGGridGeometry<2,3,const
UGGrid<dim> >;
239 friend class UGGridEntity <0,dim,const
UGGrid<dim> >;
240 friend class UGGridEntity <dim,dim,const
UGGrid<dim> >;
241 friend class UGGridHierarchicIterator<const
UGGrid<dim> >;
242 friend class UGGridLeafIntersection<const
UGGrid<dim> >;
243 friend class UGGridLevelIntersection<const
UGGrid<dim> >;
244 friend class UGGridLeafIntersectionIterator<const
UGGrid<dim> >;
245 friend class UGGridLevelIntersectionIterator<const
UGGrid<dim> >;
247 friend class UGGridLevelIndexSet<const
UGGrid<dim> >;
248 friend class UGGridLeafIndexSet<const
UGGrid<dim> >;
249 friend class UGGridIdSet<const
UGGrid<dim> >;
250 template <
class Gr
idImp_>
251 friend class UGGridLeafGridView;
252 template <
class Gr
idImp_>
253 friend class UGGridLevelGridView;
258 friend class UGLBGatherScatter;
261 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
262 friend class UGGridLeafIterator;
263 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
264 friend class UGGridLevelIterator;
267 static_assert(dim==2 || dim==3,
"Use UGGrid only for 2d and 3d!");
298 ~
UGGrid() noexcept(false);
302 int maxLevel() const;
305 template <typename Seed>
306 typename Traits::template
Codim<Seed::codimension>::
Entity 307 entity(const Seed& seed)
const 309 const int codim = Seed::codimension;
315 int size (
int level,
int codim)
const;
320 return leafIndexSet().size(codim);
326 return this->levelIndexSet(level).size(type);
332 return this->leafIndexSet().size(type);
339 return numBoundarySegments_;
357 if (level<0 || level>maxLevel())
358 DUNE_THROW(
GridError,
"levelIndexSet of nonexisting level " << level <<
" requested!");
359 return *levelIndexSets_[level];
365 return leafIndexSet_;
383 bool mark(
int refCount,
const typename Traits::template
Codim<0>::Entity & e );
441 typename UG_NS<dim>::RefinementRule rule,
465 return (codim==0) ? 1 : 0;
475 return (codim==0) ? 1 : 0;
485 template<
class DataHandle>
493 if (dataHandle.contains(dim,dim))
494 UGLBGatherScatter::template gather<dim>(this->
leafGridView(), dataHandle);
506 if (dataHandle.contains(dim,dim))
507 UGLBGatherScatter::template scatter<dim>(this->
leafGridView(), dataHandle);
519 bool loadBalance(
int minlevel=0);
551 bool loadBalance(
const std::vector<Rank>& targetProcessors,
unsigned int fromLevel);
562 template<
class DataHandle>
563 bool loadBalance (
const std::vector<Rank>& targetProcessors,
unsigned int fromLevel, DataHandle& dataHandle)
570 UGLBGatherScatter::template gather<dim>(this->
leafGridView(), dataHandle);
575 loadBalance(targetProcessors,fromLevel);
582 UGLBGatherScatter::template scatter<dim>(this->
leafGridView(), dataHandle);
599 template<
class DataHandle>
605 for (
int curCodim = 0; curCodim <= dim; ++curCodim) {
606 if (!dataHandle.contains(dim, curCodim))
610 communicateUG_<LevelGridView, DataHandle, 0>(this->
levelGridView(level), level, dataHandle, iftype, dir);
611 else if (curCodim == dim)
612 communicateUG_<LevelGridView, DataHandle, dim>(this->
levelGridView(level), level, dataHandle, iftype, dir);
613 else if (curCodim == dim - 1)
614 communicateUG_<LevelGridView, DataHandle, dim-1>(this->
levelGridView(level), level, dataHandle, iftype, dir);
615 else if (curCodim == 1)
616 communicateUG_<LevelGridView, DataHandle, 1>(this->
levelGridView(level), level, dataHandle, iftype, dir);
618 DUNE_THROW(NotImplemented,
619 className(*
this) <<
"::communicate(): Not " 620 "supported for dim " << dim <<
" and codim " << curCodim);
634 template<
class DataHandle>
640 for (
int curCodim = 0; curCodim <= dim; ++curCodim) {
641 if (!dataHandle.contains(dim, curCodim))
645 communicateUG_<LeafGridView, DataHandle, 0>(this->
leafGridView(), level, dataHandle, iftype, dir);
646 else if (curCodim == dim)
647 communicateUG_<LeafGridView, DataHandle, dim>(this->
leafGridView(), level, dataHandle, iftype, dir);
648 else if (curCodim == dim - 1)
649 communicateUG_<LeafGridView, DataHandle, dim-1>(this->
leafGridView(), level, dataHandle, iftype, dir);
650 else if (curCodim == 1)
651 communicateUG_<LeafGridView, DataHandle, 1>(this->
leafGridView(), level, dataHandle, iftype, dir);
653 DUNE_THROW(NotImplemented,
654 className(*
this) <<
"::communicate(): Not " 655 "supported for dim " << dim <<
" and codim " << curCodim);
668 template <
class Gr
idView,
class DataHandle,
int codim>
669 void communicateUG_(
const GridView& gv,
int level,
670 DataHandle &dataHandle,
674 typename UG_NS<dim>::DDD_IF_DIR ugIfDir;
677 ugIfDir = UG_NS<dim>::IF_FORWARD();
679 ugIfDir = UG_NS<dim>::IF_BACKWARD();
681 typedef UGMessageBuffer<DataHandle,dim,codim> UGMsgBuf;
682 UGMsgBuf::duneDataHandle_ = &dataHandle;
684 UGMsgBuf::level = level;
686 std::vector<typename UG_NS<dim>::DDD_IF> ugIfs;
687 findDDDInterfaces_(ugIfs, iftype, codim);
689 unsigned bufSize = UGMsgBuf::ugBufferSize_(gv);
692 for (
unsigned i=0; i < ugIfs.size(); ++i)
693 UG_NS<dim>::DDD_IFOneway(ugIfs[i],
696 &UGMsgBuf::ugGather_,
697 &UGMsgBuf::ugScatter_);
700 void findDDDInterfaces_(std::vector<
typename UG_NS<dim>::DDD_IF > &dddIfaces,
716 dddIfaces.push_back(UG_NS<dim>::ElementVHIF());
723 dddIfaces.push_back(UG_NS<dim>::ElementSymmVHIF());
727 "Element communication not supported for " 728 "interfaces of type " 732 else if (codim == dim)
737 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF());
740 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF());
741 dddIfaces.push_back(UG_NS<dim>::NodeIF());
744 dddIfaces.push_back(UG_NS<dim>::NodeAllIF());
748 "Node communication not supported for " 749 "interfaces of type " 753 else if (codim == dim-1)
758 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF());
761 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF());
766 dddIfaces.push_back(UG_NS<dim>::EdgeSymmVHIF());
770 "Edge communication not supported for " 771 "interfaces of type " 781 dddIfaces.push_back(UG_NS<dim>::BorderVectorSymmIF());
785 "Face communication not supported for " 786 "interfaces of type " 793 "Communication for codim " 795 <<
" entities is not yet supported " 796 <<
" by the DUNE UGGrid interface!");
813 void getChildrenOfSubface(
const typename Traits::template
Codim<0>::Entity & e,
817 std::vector<unsigned char>& childElementSides)
const;
837 refinementType_ = type;
859 const FieldVector<double, dim>& pos);
865 void globalRefine(
int n);
871 void saveState(
const std::string& filename)
const;
877 void loadState(
const std::string& filename);
881 typename UG_NS<dim>::MultiGrid* multigrid_;
891 void setIndices(
bool setLevelZero,
892 std::vector<unsigned int>* nodePermutation);
899 std::vector<std::shared_ptr<UGGridLevelIndexSet<const UGGrid<dim> > > > levelIndexSets_;
901 UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
905 UGGridIdSet<const UGGrid<dim> > idSet_;
920 static int numOfUGGrids;
927 bool someElementHasBeenMarkedForRefinement_;
934 bool someElementHasBeenMarkedForCoarsening_;
940 static unsigned int heapSize_;
943 std::vector<std::shared_ptr<BoundarySegment<dim> > > boundarySegments_;
950 unsigned int numBoundarySegments_;
954 namespace Capabilities
974 static const bool v =
true;
983 static const bool v =
true;
992 static const bool v =
true;
1001 static const bool v =
false;
1008 #endif // HAVE_UG || DOXYGEN 1009 #endif // DUNE_UGGRID_HH ClosureType
Decide whether to add a green closure to locally refined grid sections or not.
Definition: uggrid.hh:828
static void setDefaultHeapSize(unsigned size)
Sets the default heap size.
Definition: uggrid.hh:851
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1152
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
Grid< dim, dimworld, ct, GridFamily >::LevelGridView levelGridView(const Grid< dim, dimworld, ct, GridFamily > &grid, int level)
level grid view for the given grid and level.
Definition: common/grid.hh:857
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:263
Base class for grid boundary segments of arbitrary geometry.
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: uggrid.hh:469
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: uggrid.hh:464
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Standard red/green refinement.
Definition: uggrid.hh:830
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: uggrid.hh:355
RefinementType
The different forms of grid refinement that UG supports.
Definition: uggrid.hh:820
const CollectiveCommunication< UGGrid > & comm() const
Definition: uggrid.hh:661
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: common/grid.hh:406
UGGridFamily< dim >::Traits Traits
Definition: uggrid.hh:282
send all and receive all entities
Definition: gridenums.hh:89
UG::DOUBLE ctype
The type used to store coordinates.
Definition: uggrid.hh:285
Definition: common/geometry.hh:24
int size(int codim) const
number of leaf entities per codim in this process
Definition: uggrid.hh:318
send/receive interior and border entities
Definition: gridenums.hh:85
send interior and border, receive all entities
Definition: gridenums.hh:86
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: uggrid.hh:474
void communicate(DataHandle &dataHandle, InterfaceType iftype, CommunicationDirection dir) const
The communication interface for all codims on the leaf level.
Definition: uggrid.hh:635
void communicate(DataHandle &dataHandle, InterfaceType iftype, CommunicationDirection dir, int level) const
The communication interface for all codims on a given level.
Definition: uggrid.hh:600
GridTraits< dim, dim, Dune::UGGrid< dim >, UGGridGeometry, UGGridEntity, UGGridLevelIterator, UGGridLeafIntersection, UGGridLevelIntersection, UGGridLeafIntersectionIterator, UGGridLevelIntersectionIterator, UGGridHierarchicIterator, UGGridLeafIterator, UGGridLevelIndexSet< const UGGrid< dim > >, UGGridLeafIndexSet< const UGGrid< dim > >, UGGridIdSet< const UGGrid< dim > >, typename UG_NS< dim >::UG_ID_TYPE, UGGridIdSet< const UGGrid< dim > >, typename UG_NS< dim >::UG_ID_TYPE, CollectiveCommunication< Dune::UGGrid< dim > >, UGGridLevelGridViewTraits, UGGridLeafGridViewTraits, UGGridEntitySeed, UGGridLocalGeometry > Traits
Definition: uggrid.hh:182
bool loadBalance(DataHandle &dataHandle)
Distributes the grid and some data over the available nodes in a distributed machine.
Definition: uggrid.hh:486
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: uggrid.hh:363
GridFamily::Traits::CollectiveCommunication CollectiveCommunication
A type that is a model of Dune::CollectiveCommunication. It provides a portable way for collective co...
Definition: common/grid.hh:519
communicate as given in InterfaceType
Definition: gridenums.hh:169
A set of traits classes to store static information about grid implementation.
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: common/grid.hh:404
The specialization of the generic GridFactory for UGGrid.
Include standard header files.
Definition: agrid.hh:59
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: common/grid.hh:874
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: uggrid.hh:349
UGGridFamily< dim > GridFamily
type of the used GridFamily for this grid
Definition: uggrid.hh:279
unsigned int Rank
The type used for process ranks.
Definition: uggrid.hh:288
Wrapper class for entities.
Definition: common/entity.hh:64
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:86
void setClosureType(ClosureType type)
Sets the type of grid refinement closure.
Definition: uggrid.hh:841
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:414
Specialize with 'true' for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:55
Front-end for the grid manager of the finite element toolbox UG.
Definition: uggrid.hh:230
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: uggrid.hh:836
Different resources needed by all grid implementations.
Specialize with 'true' if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:77
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: uggrid.hh:324
New level consists only of the refined elements and the closure.
Definition: uggrid.hh:822
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
Definition: uggrid.hh:159
Grid view abstract base class.
Definition: common/gridview.hh:59
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: uggrid.hh:330
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: uggrid.hh:343
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: uggrid.hh:459
bool loadBalance(const std::vector< Rank > &targetProcessors, unsigned int fromLevel, DataHandle &dataHandle)
Distributes the grid over the processes of a parallel machine, and sends data along with it...
Definition: uggrid.hh:563
size_t numBoundarySegments() const
Return the number of boundary segments.
Definition: uggrid.hh:336