13 #include <dune/common/classname.hh>
14 #include <dune/common/parallel/communication.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/mpicommunication.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>
139 template <
class DataHandle,
int Gr
idDim,
int codim>
140 DataHandle *Dune::UGMessageBuffer<DataHandle,GridDim,codim>::duneDataHandle_ =
nullptr;
142 template <
class DataHandle,
int Gr
idDim,
int codim>
143 int Dune::UGMessageBuffer<DataHandle,GridDim,codim>::level = -1;
161 UGGridLeafIntersection,
162 UGGridLevelIntersection,
163 UGGridLeafIntersectionIterator,
164 UGGridLevelIntersectionIterator,
165 UGGridHierarchicIterator,
167 UGGridLevelIndexSet< const UGGrid<dim> >,
168 UGGridLeafIndexSet< const UGGrid<dim> >,
169 UGGridIdSet< const UGGrid<dim> >,
170 typename UG_NS<dim>::UG_ID_TYPE,
171 UGGridIdSet< const UGGrid<dim> >,
172 typename UG_NS<dim>::UG_ID_TYPE,
174 UGGridLevelGridViewTraits,
175 UGGridLeafGridViewTraits,
230 friend class UGGridGeometry<0,dim,const
UGGrid<dim> >;
231 friend class UGGridGeometry<dim,dim,const
UGGrid<dim> >;
232 friend class UGGridGeometry<1,2,const
UGGrid<dim> >;
233 friend class UGGridGeometry<2,3,const
UGGrid<dim> >;
235 friend class UGGridEntity <0,dim,const
UGGrid<dim> >;
236 friend class UGGridEntity <1,dim,const
UGGrid<dim> >;
237 friend class UGGridEntity <dim,dim,const
UGGrid<dim> >;
238 friend class UGEdgeEntity <dim,const
UGGrid<dim> >;
239 friend class UGGridHierarchicIterator<const
UGGrid<dim> >;
240 friend class UGGridLeafIntersection<const
UGGrid<dim> >;
241 friend class UGGridLevelIntersection<const
UGGrid<dim> >;
242 friend class UGGridLeafIntersectionIterator<const
UGGrid<dim> >;
243 friend class UGGridLevelIntersectionIterator<const
UGGrid<dim> >;
245 friend class UGGridLevelIndexSet<const
UGGrid<dim> >;
246 friend class UGGridLeafIndexSet<const
UGGrid<dim> >;
247 friend class UGGridIdSet<const
UGGrid<dim> >;
248 template <
class Gr
idImp_>
250 template <
class Gr
idImp_>
256 friend class UGLBGatherScatter;
259 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
261 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
265 static_assert(dim==2 || dim==3,
"Use UGGrid only for 2d and 3d!");
300 template <typename Seed>
301 typename
Traits::template Codim<Seed::codimension>::
Entity
304 const int codim = Seed::codimension;
305 return typename Traits::template Codim<codim>::Entity(UGGridEntity<codim,dim,
const UGGrid<dim> >(seed.impl().target(),
this));
310 int size (
int level,
int codim)
const;
334 return numBoundarySegments_;
353 DUNE_THROW(
GridError,
"levelIndexSet of nonexisting level " << level <<
" requested!");
354 return *levelIndexSets_[level];
360 return leafIndexSet_;
378 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity & e );
435 bool mark(
const typename Traits::template Codim<0>::Entity & e,
436 typename UG_NS<dim>::RefinementRule rule,
440 int getMark(
const typename Traits::template Codim<0>::Entity& e)
const;
460 template<
class DataHandle>
465 if (dataHandle.contains(dim, 0))
466 UGLBGatherScatter::template gather<0>(this->
leafGridView(), dataHandle);
469 if (dataHandle.contains(dim,dim))
470 UGLBGatherScatter::template gather<dim>(this->
leafGridView(), dataHandle);
479 if (dataHandle.contains(dim, 0))
480 UGLBGatherScatter::template scatter<0>(this->
leafGridView(), dataHandle);
483 if (dataHandle.contains(dim,dim))
484 UGLBGatherScatter::template scatter<dim>(this->
leafGridView(), dataHandle);
528 bool loadBalance(
const std::vector<Rank>& targetProcessors,
unsigned int fromLevel);
539 template<
class DataHandle>
540 bool loadBalance (
const std::vector<Rank>& targetProcessors,
unsigned int fromLevel, DataHandle& dataHandle)
544 if (dataHandle.contains(dim, 0))
545 UGLBGatherScatter::template gather<0>(this->
leafGridView(), dataHandle);
548 if (dataHandle.contains(dim,dim))
549 UGLBGatherScatter::template gather<dim>(this->
leafGridView(), dataHandle);
558 if (dataHandle.contains(dim, 0))
559 UGLBGatherScatter::template scatter<0>(this->
leafGridView(), dataHandle);
562 if (dataHandle.contains(dim,dim))
563 UGLBGatherScatter::template scatter<dim>(this->
leafGridView(), dataHandle);
577 template <
int codim,
class Gr
idView,
class DataHandle>
578 void communicateUG_(
const GridView& gv,
int level,
579 DataHandle &dataHandle,
583 typename UG_NS<dim>::DDD_IF_DIR ugIfDir;
586 ugIfDir = UG_NS<dim>::IF_FORWARD();
588 ugIfDir = UG_NS<dim>::IF_BACKWARD();
590 typedef UGMessageBuffer<DataHandle,dim,codim> UGMsgBuf;
591 UGMsgBuf::duneDataHandle_ = &dataHandle;
593 UGMsgBuf::level = level;
595 std::vector<typename UG_NS<dim>::DDD_IF> ugIfs;
596 findDDDInterfaces_(ugIfs, iftype, codim);
598 unsigned bufSize = UGMsgBuf::ugBufferSize(gv);
601 UGMsgBuf::grid_ =
this;
602 for (
unsigned i=0; i < ugIfs.size(); ++i)
603 UG_NS<dim>::DDD_IFOneway(
604 #
if DUNE_UGGRID_HAVE_DDDCONTEXT
605 multigrid_->dddContext(),
610 &UGMsgBuf::ugGather_,
611 &UGMsgBuf::ugScatter_);
614 void findDDDInterfaces_(std::vector<
typename UG_NS<dim>::DDD_IF > &dddIfaces,
618 #if DUNE_UGGRID_HAVE_DDDCONTEXT
619 # define DDD_CONTEXT multigrid_->dddContext()
635 dddIfaces.push_back(UG_NS<dim>::ElementVHIF(DDD_CONTEXT));
642 dddIfaces.push_back(UG_NS<dim>::ElementSymmVHIF(DDD_CONTEXT));
645 DUNE_THROW(GridError,
646 "Element communication not supported for "
647 "interfaces of type "
651 else if (codim == dim)
656 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF(DDD_CONTEXT));
659 dddIfaces.push_back(UG_NS<dim>::NodeInteriorBorderAllIF(DDD_CONTEXT));
662 dddIfaces.push_back(UG_NS<dim>::NodeAllIF(DDD_CONTEXT));
665 DUNE_THROW(GridError,
666 "Node communication not supported for "
667 "interfaces of type "
671 else if (codim == dim-1)
676 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF(DDD_CONTEXT));
679 dddIfaces.push_back(UG_NS<dim>::EdgeVHIF(DDD_CONTEXT));
682 dddIfaces.push_back(UG_NS<dim>::EdgeSymmVHIF(DDD_CONTEXT));
685 DUNE_THROW(GridError,
686 "Edge communication not supported for "
687 "interfaces of type "
697 dddIfaces.push_back(UG_NS<dim>::FacetInteriorBorderAllIF(DDD_CONTEXT));
700 DUNE_THROW(GridError,
701 "Face communication not supported for "
702 "interfaces of type "
708 DUNE_THROW(GridError,
709 "Communication for codim "
711 <<
" entities is not yet supported "
712 <<
" by the DUNE UGGrid interface!");
733 std::vector<
typename Traits::template Codim<0>::Entity>& childElements,
734 std::vector<unsigned char>& childElementSides)
const;
754 refinementType_ = type;
769 DUNE_DEPRECATED_MSG(
"Do not set the UGGrid default heap size---it is ignored anyway!")
775 void setPosition(
const typename Traits::template Codim<dim>::Entity& e,
776 const FieldVector<double, dim>& pos);
798 typename UG_NS<dim>::MultiGrid* multigrid_;
808 void setIndices(
bool setLevelZero,
809 std::vector<unsigned int>* nodePermutation);
816 std::vector<std::shared_ptr<UGGridLevelIndexSet<const UGGrid<dim> > > > levelIndexSets_;
818 UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
822 UGGridIdSet<const UGGrid<dim> > idSet_;
837 static int numOfUGGrids;
844 bool someElementHasBeenMarkedForRefinement_;
851 bool someElementHasBeenMarkedForCoarsening_;
854 std::vector<std::shared_ptr<BoundarySegment<dim> > > boundarySegments_;
861 unsigned int numBoundarySegments_;
865 namespace Capabilities
885 static const bool v =
true;
894 static const bool v =
true;
904 static const bool v =
true;
914 static const bool v =
true;
923 static const bool v =
true;
932 static const bool v =
false;
Base class for grid boundary segments of arbitrary geometry.
The specialization of the generic GridFactory for UGGrid.
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:169
@ InteriorBorder_All_Interface
send interior and border, receive all entities
Definition: gridenums.hh:86
@ All_All_Interface
send all and receive all entities
Definition: gridenums.hh:89
@ InteriorBorder_InteriorBorder_Interface
send/receive interior and border entities
Definition: gridenums.hh:85
Include standard header files.
Definition: agrid.hh:59
CollectiveCommunication< No_Comm > UGCollectiveCommunication
Definition: uggrid.hh:151
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180
Specialize with 'true' for all codims that a grid implements entities for. (default=false)
Definition: common/capabilities.hh:56
static const bool v
Definition: common/capabilities.hh:57
specialize with 'true' for all codims that a grid provides an iterator for (default=false)
Definition: common/capabilities.hh:72
static const bool v
Definition: common/capabilities.hh:73
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: common/capabilities.hh:104
static const bool v
Definition: common/capabilities.hh:105
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false)
Definition: common/capabilities.hh:113
static const bool v
Definition: common/capabilities.hh:114
Wrapper class for entities.
Definition: common/entity.hh:64
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Definition: common/grid.hh:855
Traits::LeafGridView leafGridView() const
View for the leaf grid for All_Partition.
Definition: common/grid.hh:875
bool loadBalance()
default implementation of load balance does nothing and returns false
Definition: common/grid.hh:941
GridFamily::Traits Traits
The traits of this class.
Definition: common/grid.hh:864
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:220
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1065
IdSet< const GridImp, LocalIdSetImp, LIDType > LocalIdSet
The type of the local id set.
Definition: common/grid.hh:1138
IdSet< const GridImp, GlobalIdSetImp, GIDType > GlobalIdSet
The type of the global id set.
Definition: common/grid.hh:1136
IndexSet< const GridImp, LeafIndexSetImp > LeafIndexSet
The type of the leaf index set.
Definition: common/grid.hh:1134
IndexSet< const GridImp, LevelIndexSetImp > LevelIndexSet
The type of the level index set.
Definition: common/grid.hh:1132
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:269
Grid view abstract base class.
Definition: common/gridview.hh:60
Definition: uggrid.hh:156
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, UGCollectiveCommunication, UGGridLevelGridViewTraits, UGGridLeafGridViewTraits, UGGridEntitySeed, UGGridLocalGeometry > Traits
Definition: uggrid.hh:178
Front-end for the grid manager of the finite element toolbox UG.
Definition: uggrid.hh:227
void postAdapt()
Clean up refinement markers.
size_t numBoundarySegments() const
Return the number of boundary segments.
Definition: uggrid.hh:331
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: uggrid.hh:753
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Query whether element is marked for refinement.
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark element for refinement.
friend class UGGridLeafIterator
Definition: uggrid.hh:260
bool loadBalance(int minlevel=0)
Distributes this grid over the available nodes in a distributed machine.
~UGGrid() noexcept(false)
Destructor.
const UGCollectiveCommunication & comm() const
Definition: uggrid.hh:570
UGGridFamily< dim >::Traits Traits
Definition: uggrid.hh:280
friend class UGGridLevelIterator
Definition: uggrid.hh:262
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:540
void getChildrenOfSubface(const typename Traits::template Codim< 0 >::Entity &e, int elementSide, int maxl, std::vector< typename Traits::template Codim< 0 >::Entity > &childElements, std::vector< unsigned char > &childElementSides) const
Rudimentary substitute for a hierarchic iterator on faces.
friend class UGGridLevelGridView
Definition: uggrid.hh:251
UGGridFamily< dim > GridFamily
type of the used GridFamily for this grid
Definition: uggrid.hh:277
bool loadBalance(const std::vector< Rank > &targetProcessors, unsigned int fromLevel)
Distribute this grid over a distributed machine.
bool mark(const typename Traits::template Codim< 0 >::Entity &e, typename UG_NS< dim >::RefinementRule rule, int side=0)
Mark method accepting a UG refinement rule.
UGGrid(UGCollectiveCommunication comm={})
Default constructor.
void setClosureType(ClosureType type)
Sets the type of grid refinement closure.
Definition: uggrid.hh:758
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: uggrid.hh:338
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: uggrid.hh:319
RefinementType
The different forms of grid refinement that UG supports.
Definition: uggrid.hh:737
@ COPY
New level consists of the refined elements and the unrefined ones, too.
Definition: uggrid.hh:741
@ LOCAL
New level consists only of the refined elements and the closure.
Definition: uggrid.hh:739
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: uggrid.hh:325
void setPosition(const typename Traits::template Codim< dim >::Entity &e, const FieldVector< double, dim > &pos)
Sets a vertex to a new position.
int size(int level, int codim) const
Number of grid entities per level and codim.
UG::DOUBLE ctype
The type used to store coordinates.
Definition: uggrid.hh:283
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: uggrid.hh:344
bool adapt()
Triggers the grid refinement process.
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: uggrid.hh:350
friend class UGGridLeafGridView
Definition: uggrid.hh:249
void loadState(const std::string &filename)
Read entire grid hierarchy from disk.
bool loadBalance(DataHandle &dataHandle)
Distributes the grid and some data over the available nodes in a distributed machine.
Definition: uggrid.hh:461
Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed) const
Create an Entity from an EntitySeed.
Definition: uggrid.hh:302
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: uggrid.hh:358
unsigned int Rank
The type used for process ranks.
Definition: uggrid.hh:286
void saveState(const std::string &filename) const
Save entire grid hierarchy to disk.
bool preAdapt()
returns true, if some elements might be coarsend during grid adaption, here always returns true
void globalRefine(int n)
Does uniform refinement.
ClosureType
Decide whether to add a green closure to locally refined grid sections or not.
Definition: uggrid.hh:745
@ GREEN
Standard red/green refinement.
Definition: uggrid.hh:747
@ NONE
No closure, results in nonconforming meshes.
Definition: uggrid.hh:749
int size(int codim) const
number of leaf entities per codim in this process
Definition: uggrid.hh:313
static void setDefaultHeapSize(unsigned size)
Sets the default heap size.
Definition: uggrid.hh:768
A set of traits classes to store static information about grid implementation.
Different resources needed by all grid implementations.