15#include <dune/common/classname.hh>
16#include <dune/common/parallel/communication.hh>
17#include <dune/common/exceptions.hh>
18#include <dune/common/parallel/mpihelper.hh>
20#include <dune-grid-config.hh>
25#if HAVE_DUNE_UGGRID || DOXYGEN
28#include <dune/common/parallel/mpicommunication.hh>
49#include "uggrid/ugincludes.hh"
50#undef DUNE_UGINCLUDES_HH
55#include "uggrid/ugwrapper.hh"
60#include "uggrid/ug_undefs.hh"
80#include "uggrid/ugincludes.hh"
81#undef DUNE_UGINCLUDES_HH
86#include "uggrid/ugwrapper.hh"
90#include "uggrid/ug_undefs.hh"
95#include "uggrid/uggridgeometry.hh"
96#include "uggrid/uggridlocalgeometry.hh"
97#include "uggrid/uggridentity.hh"
98#include "uggrid/uggridentityseed.hh"
99#include "uggrid/uggridintersections.hh"
100#include "uggrid/uggridintersectioniterators.hh"
101#include "uggrid/uggridleveliterator.hh"
102#include "uggrid/uggridleafiterator.hh"
103#include "uggrid/uggridhieriterator.hh"
104#include "uggrid/uggridindexsets.hh"
105#include <dune/grid/uggrid/uggridviews.hh>
107#include "uggrid/ugmessagebuffer.hh"
108#include "uggrid/uglbgatherscatter.hh"
115template <
class DataHandle,
int Gr
idDim,
int codim>
118template <
class DataHandle,
int Gr
idDim,
int codim>
119DataHandle *Dune::UGMessageBuffer<DataHandle,GridDim,codim>::duneDataHandle_ =
nullptr;
121template <
class DataHandle,
int Gr
idDim,
int codim>
122int Dune::UGMessageBuffer<DataHandle,GridDim,codim>::level = -1;
140 UGGridLeafIntersection,
141 UGGridLevelIntersection,
142 UGGridLeafIntersectionIterator,
143 UGGridLevelIntersectionIterator,
144 UGGridHierarchicIterator,
146 UGGridLevelIndexSet< const UGGrid<dim> >,
147 UGGridLeafIndexSet< const UGGrid<dim> >,
148 UGGridIdSet< const UGGrid<dim> >,
149 typename UG_NS<dim>::UG_ID_TYPE,
150 UGGridIdSet< const UGGrid<dim> >,
151 typename UG_NS<dim>::UG_ID_TYPE,
153 UGGridLevelGridViewTraits,
154 UGGridLeafGridViewTraits,
201 typedef GridDefaultImplementation <dim, dim, double, UGGridFamily<dim> > Base;
203 friend class UGGridGeometry<0,dim,const
UGGrid<dim> >;
204 friend class UGGridGeometry<dim,dim,const
UGGrid<dim> >;
205 friend class UGGridGeometry<1,2,const
UGGrid<dim> >;
206 friend class UGGridGeometry<2,3,const
UGGrid<dim> >;
208 friend class UGGridEntity <0,dim,const
UGGrid<dim> >;
209 friend class UGGridEntity <1,dim,const
UGGrid<dim> >;
210 friend class UGGridEntity <2,dim,const
UGGrid<dim> >;
211 friend class UGGridEntity <dim,dim,const
UGGrid<dim> >;
212 friend class UGGridHierarchicIterator<const
UGGrid<dim> >;
213 friend class UGGridLeafIntersection<const
UGGrid<dim> >;
214 friend class UGGridLevelIntersection<const
UGGrid<dim> >;
215 friend class UGGridLeafIntersectionIterator<const
UGGrid<dim> >;
216 friend class UGGridLevelIntersectionIterator<const
UGGrid<dim> >;
218 friend class UGGridLevelIndexSet<const
UGGrid<dim> >;
219 friend class UGGridLeafIndexSet<const
UGGrid<dim> >;
220 friend class UGGridIdSet<const
UGGrid<dim> >;
221 template <
class Gr
idImp_>
223 template <
class Gr
idImp_>
229 friend class UGLBGatherScatter;
232 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
234 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
238 static_assert(dim==2 || dim==3,
"Use UGGrid only for 2d and 3d!");
273 template <typename Seed>
277 const int codim = Seed::codimension;
283 int size (
int level,
int codim)
const;
292 int size (
int level, GeometryType type)
const
298 int size (GeometryType type)
const
307 return numBoundarySegments_;
326 DUNE_THROW(
GridError,
"levelIndexSet of nonexisting level " << level <<
" requested!");
327 return *levelIndexSets_[level];
333 return leafIndexSet_;
409 typename UG_NS<dim>::RefinementRule rule,
433 template<
class DataHandle>
438 if (dataHandle.contains(dim, 0))
439 UGLBGatherScatter::template gather<0>(this->
leafGridView(), dataHandle);
442 if (dataHandle.contains(dim,dim))
443 UGLBGatherScatter::template gather<dim>(this->
leafGridView(), dataHandle);
452 if (dataHandle.contains(dim, 0))
453 UGLBGatherScatter::template scatter<0>(this->
leafGridView(), dataHandle);
456 if (dataHandle.contains(dim,dim))
457 UGLBGatherScatter::template scatter<dim>(this->
leafGridView(), dataHandle);
501 bool loadBalance(
const std::vector<Rank>& targetProcessors,
unsigned int fromLevel);
512 template<
class DataHandle>
513 bool loadBalance (
const std::vector<Rank>& targetProcessors,
unsigned int fromLevel, DataHandle& dataHandle)
517 if (dataHandle.contains(dim, 0))
518 UGLBGatherScatter::template gather<0>(this->
leafGridView(), dataHandle);
521 if (dataHandle.contains(dim,dim))
522 UGLBGatherScatter::template gather<dim>(this->
leafGridView(), dataHandle);
531 if (dataHandle.contains(dim, 0))
532 UGLBGatherScatter::template scatter<0>(this->
leafGridView(), dataHandle);
535 if (dataHandle.contains(dim,dim))
536 UGLBGatherScatter::template scatter<dim>(this->
leafGridView(), dataHandle);
550 template <
int codim,
class Gr
idView,
class DataHandle>
551 void communicateUG_(
const GridView& gv,
int level,
552 DataHandle &dataHandle,
557 const auto ugIfDir = (dir==
ForwardCommunication) ? UG_NS<dim>::IF_FORWARD() : UG_NS<dim>::IF_BACKWARD();
563 using UGMsgBuf = UGMessageBuffer<DataHandle,dim,codim>;
564 UGMsgBuf::duneDataHandle_ = &dataHandle;
565 UGMsgBuf::level = level;
566 UGMsgBuf::grid_ =
this;
568 const std::vector<typename UG_NS<dim>::DDD_IF> ugIfs = findDDDInterfaces(iftype, codim);
570 const auto bufSize = UGMsgBuf::ugBufferSize(gv);
573 for (
auto&& dddInterface : ugIfs)
574 UG_NS<dim>::DDD_IFOneway(multigrid_->dddContext(),
578 &UGMsgBuf::ugGather_,
579 &UGMsgBuf::ugScatter_);
583 std::vector<typename UG_NS<dim>::DDD_IF> findDDDInterfaces(InterfaceType iftype,
602 std::vector<unsigned char>& childElementSides)
const;
622 refinementType_ = type;
634 const FieldVector<double, dim>& pos);
656 typename UG_NS<dim>::MultiGrid* multigrid_;
663 typename UG_NS<dim>::STD_BVP* bvp_;
673 void setIndices(
bool setLevelZero,
674 std::vector<unsigned int>* nodePermutation);
681 std::vector<std::shared_ptr<UGGridLevelIndexSet<const UGGrid<dim> > > > levelIndexSets_;
683 UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
687 UGGridIdSet<const UGGrid<dim> > idSet_;
702 static int numOfUGGrids;
709 bool someElementHasBeenMarkedForRefinement_;
716 bool someElementHasBeenMarkedForCoarsening_;
719 std::vector<std::shared_ptr<BoundarySegment<dim> > > boundarySegments_;
726 unsigned int numBoundarySegments_;
747 template<
int dim,
int codim>
750 static const bool v =
true;
758 template<
int dim,
int codim>
761 static const bool v =
false;
771 static const bool v =
true;
781 static const bool v =
true;
787 template<
int dim,
int codim>
790 static const bool v = (codim>=0 && codim<=dim);
799 static const bool v =
true;
808 static const bool v =
false;
816 static const bool v =
true;
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:170
InterfaceType
Parameter to be used for the communication functions.
Definition gridenums.hh:86
@ ForwardCommunication
communicate as given in InterfaceType
Definition gridenums.hh:171
Include standard header files.
Definition agrid.hh:60
Communication< No_Comm > UGCommunication
Definition uggrid.hh:130
Contains all capabilities classes.
Definition albertagrid/capabilities.hh:29
Specialize with 'true' for all codims that a grid implements entities for. (default=false).
Definition common/capabilities.hh:58
specialize with 'true' for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition common/capabilities.hh:74
specialize with 'true' for all codims that a grid can communicate data on (default=false)
Definition common/capabilities.hh:97
Specialize with 'true' if implementation guarantees conforming level grids. (default=false).
Definition common/capabilities.hh:106
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false).
Definition common/capabilities.hh:115
Specialize with 'true' if the grid implementation is thread safe, while it is not modified....
Definition common/capabilities.hh:169
Wrapper class for entities.
Definition common/entity.hh:66
Base class for exceptions in Dune grid modules.
Definition exceptions.hh:20
Definition common/grid.hh:848
Traits::LeafGridView leafGridView() const
Definition common/grid.hh:868
bool loadBalance()
Definition common/grid.hh:962
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition common/indexidset.hh:223
A Traits struct that collects all associated types of one implementation.
Definition common/grid.hh:411
A traits struct that collects all associated types of one grid model.
Definition common/grid.hh:1013
IndexSet< const GridImp, LeafIndexSetImp, LeafIndexType, LeafGeometryTypes > LeafIndexSet
The type of the leaf index set.
Definition common/grid.hh:1082
IndexSet< const GridImp, LevelIndexSetImp, LevelIndexType, LevelGeometryTypes > LevelIndexSet
The type of the level index set.
Definition common/grid.hh:1080
IdSet< const GridImp, LocalIdSetImp, LIDType > LocalIdSet
The type of the local id set.
Definition common/grid.hh:1086
IdSet< const GridImp, GlobalIdSetImp, GIDType > GlobalIdSet
The type of the global id set.
Definition common/grid.hh:1084
Provide a generic factory class for unstructured grids.
Definition common/gridfactory.hh:275
Grid view abstract base class.
Definition common/gridview.hh:66
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, UGCommunication, UGGridLevelGridViewTraits, UGGridLeafGridViewTraits, UGGridEntitySeed, UGGridLocalGeometry > Traits
Definition uggrid.hh:157
Front-end for the grid manager of the finite element toolbox UG3.
Definition uggrid.hh:200
void postAdapt()
Clean up refinement markers.
size_t numBoundarySegments() const
Return the number of boundary segments.
Definition uggrid.hh:304
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition uggrid.hh:621
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:233
bool loadBalance(int minlevel=0)
Distributes this grid over the available nodes in a distributed machine.
~UGGrid() noexcept(false)
Destructor.
UGGridFamily< dim >::Traits Traits
Definition uggrid.hh:253
friend class UGGridLevelIterator
Definition uggrid.hh:235
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:513
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:224
UGGridFamily< dim > GridFamily
type of the used GridFamily for this grid
Definition uggrid.hh:250
bool loadBalance(const std::vector< Rank > &targetProcessors, unsigned int fromLevel)
Distribute this grid over a distributed machine.
const UGCommunication & comm() const
Definition uggrid.hh:543
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.
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition uggrid.hh:323
void setClosureType(ClosureType type)
Sets the type of grid refinement closure.
Definition uggrid.hh:626
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition uggrid.hh:317
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition uggrid.hh:292
RefinementType
The different forms of grid refinement that UG supports.
Definition uggrid.hh:605
@ COPY
Definition uggrid.hh:609
@ LOCAL
Definition uggrid.hh:607
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition uggrid.hh:298
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:256
bool adapt()
Triggers the grid refinement process.
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition uggrid.hh:311
friend class UGGridLeafGridView
Definition uggrid.hh:222
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:434
Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed) const
Definition uggrid.hh:275
unsigned int Rank
The type used for process ranks.
Definition uggrid.hh:259
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.
UGGrid(UGCommunication comm={})
Default constructor.
ClosureType
Decide whether to add a green closure to locally refined grid sections or not.
Definition uggrid.hh:613
@ GREEN
Definition uggrid.hh:615
@ NONE
Definition uggrid.hh:617
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition uggrid.hh:331
int size(int codim) const
number of leaf entities per codim in this process
Definition uggrid.hh:286
static const bool v
Definition uggrid.hh:750
static const bool v
Definition uggrid.hh:761
static const bool v
Definition uggrid.hh:771
static const bool v
Definition uggrid.hh:781
static const bool v
Definition uggrid.hh:790
static const bool v
Definition uggrid.hh:799
static const bool v
Definition uggrid.hh:808
static const bool v
Definition uggrid.hh:816
A set of traits classes to store static information about grid implementation.
Different resources needed by all grid implementations.