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> >,
207 friend class UGGridGeometry<0,dim,const
UGGrid<dim> >;
208 friend class UGGridGeometry<dim,dim,const
UGGrid<dim> >;
209 friend class UGGridGeometry<1,2,const
UGGrid<dim> >;
210 friend class UGGridGeometry<2,3,const
UGGrid<dim> >;
212 friend class UGGridEntity <0,dim,const
UGGrid<dim> >;
213 friend class UGGridEntity <dim,dim,const
UGGrid<dim> >;
214 friend class UGGridHierarchicIterator<const
UGGrid<dim> >;
215 friend class UGGridLeafIntersection<const
UGGrid<dim> >;
216 friend class UGGridLevelIntersection<const
UGGrid<dim> >;
217 friend class UGGridLeafIntersectionIterator<const
UGGrid<dim> >;
218 friend class UGGridLevelIntersectionIterator<const
UGGrid<dim> >;
220 friend class UGGridLevelIndexSet<const
UGGrid<dim> >;
221 friend class UGGridLeafIndexSet<const
UGGrid<dim> >;
222 friend class UGGridIdSet<const
UGGrid<dim> >;
227 friend class UGLBGatherScatter;
230 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
232 template <
int codim_, PartitionIteratorType PiType_,
class Gr
idImp_>
234 template <
int codim_,
class Gr
idImp_>
238 dune_static_assert(dim==2 || dim==3,
"Use UGGrid only for 2d and 3d!");
281 template<
int codim, PartitionIteratorType PiType>
285 template<
int codim, PartitionIteratorType PiType>
297 return UGGridLeafIterator<codim,All_Partition, const UGGrid<dim> >();
301 template<
int codim, PartitionIteratorType PiType>
307 template<
int codim, PartitionIteratorType PiType>
309 return UGGridLeafIterator<codim,PiType, const UGGrid<dim> >();
313 template <
typename Seed>
314 typename Traits::template Codim<Seed::codimension>::EntityPointer
317 enum {codim = Seed::codimension};
323 int size (
int level,
int codim)
const;
347 return numBoundarySegments_;
366 DUNE_THROW(
GridError,
"levelIndexSet of nonexisting level " << level <<
" requested!");
367 return *levelIndexSets_[level];
373 return leafIndexSet_;
391 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity & e );
449 bool mark(
const typename Traits::template Codim<0>::Entity & e,
450 typename UG_NS<dim>::RefinementRule rule,
454 int getMark(
const typename Traits::template Codim<0>::Entity& e)
const;
474 return (codim==0) ? 1 : 0;
484 return (codim==0) ? 1 : 0;
502 template<
class DataHandle>
506 DUNE_THROW(NotImplemented,
"load balancing with data attached");
513 UGLBGatherScatter::template gather<dim>(this->
leafView(), dataHandle);
525 UGLBGatherScatter::template scatter<dim>(this->
leafView(), dataHandle);
529 #endif // HAVE_UG_PATCH10
548 bool loadBalance(
int strategy,
int minlevel,
int depth,
int maxlevel,
int minelement);
560 template<
class DataHandle>
566 for (
int curCodim = 0; curCodim <= dim; ++curCodim) {
567 if (!dataHandle.contains(dim, curCodim))
571 communicateUG_<LevelGridView, DataHandle, 0>(this->
levelGridView(level), level, dataHandle, iftype, dir);
572 else if (curCodim == dim)
573 communicateUG_<LevelGridView, DataHandle, dim>(this->
levelGridView(level), level, dataHandle, iftype, dir);
574 else if (curCodim == dim - 1)
576 else if (curCodim == 1)
577 communicateUG_<LevelGridView, DataHandle, 1>(this->
levelGridView(level), level, dataHandle, iftype, dir);
579 DUNE_THROW(NotImplemented,
580 className(*
this) <<
"::communicate(): Not "
581 "supported for dim " << dim <<
" and codim " << curCodim);
595 template<
class DataHandle>
601 for (
int curCodim = 0; curCodim <= dim; ++curCodim) {
602 if (!dataHandle.contains(dim, curCodim))
606 communicateUG_<LeafGridView, DataHandle, 0>(this->
leafView(), level, dataHandle, iftype, dir);
607 else if (curCodim == dim)
608 communicateUG_<LeafGridView, DataHandle, dim>(this->
leafView(), level, dataHandle, iftype, dir);
609 else if (curCodim == dim - 1)
610 communicateUG_<
LeafGridView, DataHandle, dim-1>(this->
leafView(), level, dataHandle, iftype, dir);
611 else if (curCodim == 1)
612 communicateUG_<LeafGridView, DataHandle, 1>(this->
leafView(), level, dataHandle, iftype, dir);
614 DUNE_THROW(NotImplemented,
615 className(*
this) <<
"::communicate(): Not "
616 "supported for dim " << dim <<
" and codim " << curCodim);
629 template <
class Gr
idView,
class DataHandle,
int codim>
630 void communicateUG_(
const GridView& gv,
int level,
631 DataHandle &dataHandle,
635 typename UG_NS<dim>::DDD_IF_DIR ugIfDir;
638 ugIfDir = UG_NS<dim>::IF_FORWARD();
640 ugIfDir = UG_NS<dim>::IF_BACKWARD();
642 typedef UGMessageBuffer<DataHandle,dim,codim> UGMsgBuf;
643 UGMsgBuf::duneDataHandle_ = &dataHandle;
645 UGMsgBuf::level = level;
647 std::vector<typename UG_NS<dim>::DDD_IF> ugIfs;
648 findDDDInterfaces_(ugIfs, iftype, codim);
650 unsigned bufSize = UGMsgBuf::ugBufferSize_(gv);
653 for (
unsigned i=0; i < ugIfs.size(); ++i)
654 UG_NS<dim>::DDD_IFOneway(ugIfs[i],
657 &UGMsgBuf::ugGather_,
658 &UGMsgBuf::ugScatter_);
661 void findDDDInterfaces_(std::vector<
typename UG_NS<dim>::DDD_IF > &dddIfaces,
677 dddIfaces.push_back(UG_NS<dim>::ElementVHIF());
684 dddIfaces.push_back(UG_NS<dim>::ElementSymmVHIF());
687 DUNE_THROW(GridError,
688 "Element communication not supported for "
689 "interfaces of type "
693 else if (codim == dim)
698 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF());
701 dddIfaces.push_back(UG_NS<dim>::BorderNodeSymmIF());
702 dddIfaces.push_back(UG_NS<dim>::NodeIF());
705 dddIfaces.push_back(UG_NS<dim>::NodeAllIF());
708 DUNE_THROW(GridError,
709 "Node communication not supported for "
710 "interfaces of type "
714 else if (codim == dim-1)
719 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF());
722 dddIfaces.push_back(UG_NS<dim>::BorderEdgeSymmIF());
727 DUNE_THROW(GridError,
728 "Edge communication not supported for "
729 "interfaces of type "
739 dddIfaces.push_back(UG_NS<dim>::BorderVectorSymmIF());
742 DUNE_THROW(GridError,
743 "Face communication not supported for "
744 "interfaces of type "
750 DUNE_THROW(GridError,
751 "Communication for codim "
753 <<
" entities is not yet supported "
754 <<
" by the DUNE UGGrid interface!");
774 std::vector<
typename Traits::template Codim<0>::EntityPointer>& childElements,
775 std::vector<unsigned char>& childElementSides)
const;
795 refinementType_ = type;
816 void setPosition(
const typename Traits::template Codim<dim>::EntityPointer& e,
817 const FieldVector<double, dim>& pos);
829 void saveState(
const std::string& filename)
const;
835 void loadState(
const std::string& filename);
839 typename UG_NS<dim>::MultiGrid* multigrid_;
842 CollectiveCommunication<UGGrid> ccobj_;
849 void setIndices(
bool setLevelZero,
850 std::vector<unsigned int>* nodePermutation);
857 std::vector<shared_ptr<UGGridLevelIndexSet<const UGGrid<dim> > > > levelIndexSets_;
859 UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
863 UGGridIdSet<const UGGrid<dim> > idSet_;
878 static int numOfUGGrids;
885 bool someElementHasBeenMarkedForRefinement_;
892 bool someElementHasBeenMarkedForCoarsening_;
898 static unsigned int heapSize_;
901 std::vector<shared_ptr<BoundarySegment<dim> > > boundarySegments_;
908 unsigned int numBoundarySegments_;
912 namespace Capabilities
932 static const bool v =
true;
941 static const bool v =
true;
951 static const bool v =
true;
953 static const bool v =
false;
963 static const bool v =
true;
972 static const bool v =
false;
979 #endif // HAVE_UG || DOXYGEN
980 #endif // DUNE_UGGRID_HH
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:435
void loadState(const std::string &filename)
Read entire grid hierarchy from disk.
friend class UGGridEntityPointer
Definition: uggrid.hh:235
size_t numBoundarySegments() const
Return the number of boundary segments.
Definition: uggrid.hh:344
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: uggrid.hh:468
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: uggrid.hh:338
Partition< All_Partition >::LeafGridView LeafGridView
Definition: common/grid.hh:427
No closure, results in nonconforming meshes.
Definition: uggrid.hh:790
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: common/grid.hh:1223
bool loadBalance(DataHandle &dataHandle)
Distributes the grid and some data over the available nodes in a distributed machine.
Definition: uggrid.hh:503
New level consists only of the refined elements and the closure.
Definition: uggrid.hh:780
static const bool v
Definition: common/capabilities.hh:57
Definition: defaultgridview.hh:223
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: uggrid.hh:308
const CollectiveCommunication< UGGrid > & comm() const
Definition: uggrid.hh:622
bool loadBalance()
Default load balancing.
Definition: uggrid.hh:491
send interior and border, receive all entities
Definition: gridenums.hh:82
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: uggrid.hh:478
communicate as given in InterfaceType
Definition: gridenums.hh:165
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: uggrid.hh:302
static const bool v
Definition: common/capabilities.hh:66
Index Set Interface base class.
Definition: common/grid.hh:359
void communicate(DataHandle &dataHandle, InterfaceType iftype, CommunicationDirection dir) const
The communication interface for all codims on the leaf level.
Definition: uggrid.hh:596
Definition: uggrid.hh:131
Base class for grid boundary segments of arbitrary geometry.
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: uggrid.hh:483
Traits::template Partition< pitype >::LevelGridView levelGridView(int level) const
View for a grid level.
Definition: common/grid.hh:1064
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:263
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: uggrid.hh:794
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: uggrid.hh:371
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: uggrid.hh:351
static void setDefaultHeapSize(unsigned size)
Sets the default heap size.
Definition: uggrid.hh:809
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: uggrid.hh:290
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:543
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:164
void globalRefine(int n)
Does uniform refinement.
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark element for refinement.
send/receive interior and border entities
Definition: gridenums.hh:81
Types for GridView.
Definition: common/grid.hh:418
Specialize with 'true' if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:86
New level consists of the refined elements and the unrefined ones, too.
Definition: uggrid.hh:782
int size(int level, int codim) const
Number of grid entities per level and codim.
UGGridFamily< dim >::Traits Traits
Definition: uggrid.hh:253
The specialization of the generic GridFactory for UGGrid.
Front-end for the grid manager of the finite element toolbox UG.
Definition: uggrid.hh:203
void getChildrenOfSubface(const typename Traits::template Codim< 0 >::EntityPointer &e, int elementSide, int maxl, std::vector< typename Traits::template Codim< 0 >::EntityPointer > &childElements, std::vector< unsigned char > &childElementSides) const
Rudimentary substitute for a hierarchic iterator on faces.
void setClosureType(ClosureType type)
Sets the type of grid refinement closure.
Definition: uggrid.hh:799
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: uggrid.hh:296
void saveState(const std::string &filename) const
Save entire grid hierarchy to disk.
Standard red/green refinement.
Definition: uggrid.hh:788
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: uggrid.hh:363
void communicate(DataHandle &dataHandle, InterfaceType iftype, CommunicationDirection dir, int level) const
The communication interface for all codims on a given level.
Definition: uggrid.hh:561
int size(int codim) const
number of leaf entities per codim in this process
Definition: uggrid.hh:326
Grid view abstract base classInterface class for a view on grids. Grids return two types of view...
Definition: common/gridview.hh:56
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: uggrid.hh:332
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:95
GridFamily::Traits::template Codim< cd >::EntityPointer EntityPointer
A type that is a model of Dune::EntityPointer.
Definition: common/grid.hh:447
ClosureType
Decide whether to add a green closure to locally refined grid sections or not.
Definition: uggrid.hh:786
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: common/grid.hh:426
A set of traits classes to store static information about grid implementation.
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Query whether element is marked for refinement.
Specialize with 'true' if implementation supports parallelism. (default=false)
Definition: common/capabilities.hh:64
static const bool v
Definition: common/capabilities.hh:88
GridTraits< dim, dim, Dune::UGGrid< dim >, UGGridGeometry, UGGridEntity, UGGridEntityPointer, 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 > >, DefaultLevelGridViewTraits, DefaultLeafGridViewTraits, UGGridEntitySeed, UGGridLocalGeometry > Traits
Definition: uggrid.hh:155
void postAdapt()
Clean up refinement markers.
Specialize with 'true' for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:55
bool adapt()
Triggers the grid refinement process.
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: uggrid.hh:357
friend class UGGridLeafIterator
Definition: uggrid.hh:231
Different resources needed by all grid implementations.
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1260
static const bool v
Definition: common/capabilities.hh:97
RefinementType
The different forms of grid refinement that UG supports.
Definition: uggrid.hh:778
void setPosition(const typename Traits::template Codim< dim >::EntityPointer &e, const FieldVector< double, dim > &pos)
Sets a vertex to a new position.
Definition: common/geometry.hh:24
Traits::template Partition< pitype >::LeafGridView leafView() const
View for the leaf grid.
Definition: common/grid.hh:1039
UGGridFamily< dim > GridFamily
type of the used GridFamily for this grid
Definition: uggrid.hh:250
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
Definition: defaultgridview.hh:23
UGGrid()
Default constructor.
UG::DOUBLE ctype
The type used to store coordinates.
Definition: uggrid.hh:256
friend class UGGridLevelIterator
Definition: uggrid.hh:233
Id Set Interface.
Definition: common/grid.hh:360
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
bool preAdapt()
returns true, if some elements might be coarsend during grid adaption, here always returns true ...
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: uggrid.hh:473
Traits::template Codim< Seed::codimension >::EntityPointer entityPointer(const Seed &seed) const
Create an EntityPointer from an EntitySeed.
Definition: uggrid.hh:315
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
send all and receive all entities
Definition: gridenums.hh:85