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" 115 template <
class DataHandle,
int Gr
idDim,
int codim>
118 template <
class DataHandle,
int Gr
idDim,
int codim>
119 DataHandle *Dune::UGMessageBuffer<DataHandle,GridDim,codim>::duneDataHandle_ =
nullptr;
121 template <
class DataHandle,
int Gr
idDim,
int codim>
122 int 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,
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>
274 typename
Traits::template Codim<Seed::codimension>::
Entity 277 const int codim = Seed::codimension;
283 int size (
int level,
int codim)
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);
646 void saveState(
const std::string& filename)
const;
652 void loadState(
const std::string& filename);
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_;
730 namespace Capabilities
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;
823 #endif // HAVE_DUNE_UGGRID || DOXYGEN 824 #endif // DUNE_UGGRID_HH int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Query whether element is marked for refinement.
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: uggrid.hh:292
~UGGrid() noexcept(false)
Destructor.
friend class UGGridLeafGridView
Definition: uggrid.hh:222
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: common/indexidset.hh:223
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: uggrid.hh:331
Base class for grid boundary segments of arbitrary geometry.
void saveState(const std::string &filename) const
Save entire grid hierarchy to disk.
static const bool v
Definition: common/capabilities.hh:98
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: uggrid.hh:621
bool loadBalance()
default implementation of load balance does nothing and returns false
Definition: common/grid.hh:962
int size(int codim) const
number of leaf entities per codim in this process
Definition: uggrid.hh:286
static const bool v
Definition: common/capabilities.hh:116
void globalRefine(int n)
Does uniform refinement.
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
ClosureType
Decide whether to add a green closure to locally refined grid sections or not.
Definition: uggrid.hh:613
size_t numBoundarySegments() const
Return the number of boundary segments.
Definition: uggrid.hh:304
Specialize with 'true' for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:57
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: uggrid.hh:323
RefinementType
The different forms of grid refinement that UG supports.
Definition: uggrid.hh:605
communicate as given in InterfaceType
Definition: gridenums.hh:171
Definition: uggrid.hh:134
Traits::LeafGridView leafGridView() const
View for the leaf grid for All_Partition.
Definition: common/grid.hh:868
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: uggrid.hh:311
unsigned int Rank
The type used for process ranks.
Definition: uggrid.hh:259
IdSet< const GridImp, LocalIdSetImp, LIDType > LocalIdSet
The type of the local id set.
Definition: common/grid.hh:1086
Different resources needed by all grid implementations.
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:114
friend class UGGridLevelIterator
Definition: uggrid.hh:235
UGGrid(UGCommunication comm={})
Default constructor.
const UGCommunication & comm() const
Definition: uggrid.hh:543
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.
IdSet< const GridImp, GlobalIdSetImp, GIDType > GlobalIdSet
The type of the global id set.
Definition: common/grid.hh:1084
void loadState(const std::string &filename)
Read entire grid hierarchy from disk.
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark element for refinement.
void setPosition(const typename Traits::template Codim< dim >::Entity &e, const FieldVector< double, dim > &pos)
Sets a vertex to a new position.
Grid view abstract base class.
Definition: common/gridview.hh:65
friend class UGGridLevelGridView
Definition: uggrid.hh:224
bool loadBalance(DataHandle &dataHandle)
Distributes the grid and some data over the available nodes in a distributed machine.
Definition: uggrid.hh:434
No closure, results in nonconforming meshes.
Definition: uggrid.hh:617
New level consists only of the refined elements and the closure.
Definition: uggrid.hh:607
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
UGGridFamily< dim >::Traits Traits
Definition: uggrid.hh:253
Definition: common/geometry.hh:28
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: uggrid.hh:298
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
Include standard header files.
Definition: agrid.hh:59
static const bool v
Definition: common/capabilities.hh:75
bool preAdapt()
returns true, if some elements might be coarsend during grid adaption, here always returns true ...
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
Specialize with 'true' if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:105
static const bool v
Definition: common/capabilities.hh:107
Communication< No_Comm > UGCommunication
Definition: uggrid.hh:130
specialize with 'true' for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition: common/capabilities.hh:73
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1012
void setClosureType(ClosureType type)
Sets the type of grid refinement closure.
Definition: uggrid.hh:626
void postAdapt()
Clean up refinement markers.
Front-end for the grid manager of the finite element toolbox UG3.
Definition: uggrid.hh:199
static const bool v
Definition: common/capabilities.hh:59
UG::DOUBLE ctype
The type used to store coordinates.
Definition: uggrid.hh:256
static const bool v
Definition: common/capabilities.hh:170
Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed) const
Create an Entity from an EntitySeed.
Definition: uggrid.hh:275
The specialization of the generic GridFactory for UGGrid.
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:275
Wrapper class for entities.
Definition: common/entity.hh:65
int size(int level, int codim) const
Number of grid entities per level and codim.
specialize with 'true' for all codims that a grid can communicate data on (default=false) ...
Definition: common/capabilities.hh:96
bool adapt()
Triggers the grid refinement process.
New level consists of the refined elements and the unrefined ones, too.
Definition: uggrid.hh:609
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
A set of traits classes to store static information about grid implementation.
GridFamily::Traits::template Codim< cd >::Entity Entity
A type that is a model of a Dune::Entity<cd,dim,...>.
Definition: common/grid.hh:419
Specialize with 'true' if the grid implementation is thread safe, while it is not modified...
Definition: common/capabilities.hh:169
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: uggrid.hh:317
friend class UGGridLeafIterator
Definition: uggrid.hh:233
UGGridFamily< dim > GridFamily
type of the used GridFamily for this grid
Definition: uggrid.hh:250
Standard red/green refinement.
Definition: uggrid.hh:615