uggrid.hh

Go to the documentation of this file.
00001 #ifndef DUNE_UGGRID_HH
00002 #define DUNE_UGGRID_HH
00003 
00008 #include <dune/grid/common/capabilities.hh>
00009 #include <dune/grid/common/grid.hh>
00010 #include <dune/grid/common/boundarysegment.hh>
00011 #include <dune/common/collectivecommunication.hh>
00012 #include <dune/common/deprecated.hh>
00013 #include <dune/common/static_assert.hh>
00014 
00015 /* The following lines including the necessary UG headers are somewhat
00016    tricky.  Here's what's happening:
00017    UG can support two- and three-dimensional grids.  You choose be setting
00018    either _2 oder _3 while compiling.  This changes all sorts of stuff, in
00019    particular data structures in the headers.
00020    UG was never supposed to provide 2d and 3d grids at the same time. 
00021    However, when compiling it as c++, the dimension-dependent parts are
00022    wrapped up cleanly in the namespaces UG::D2 and UG::D3, respectively.  That
00023    way it is possible to link together the UG lib for 2d and the one for 3d.
00024    But we also need the headers twice!  Once with _2 set and once with _3!
00025    So here we go:*/
00026 
00027 /* The following define tells the UG headers that we want access to a few
00028    special fields, for example the extra index fields in the element data structures. */
00029 #define FOR_DUNE
00030 
00031 // Set UG's space-dimension flag to 2d
00032 #define _2
00033 // And include all necessary UG headers
00034 #include "uggrid/ugincludes.hh"
00035 
00036 // Wrap a few large UG macros by functions before they get undef'ed away.
00037 // Here: The 2d-version of the macros
00038 #define UG_DIM 2
00039 #include "uggrid/ugwrapper.hh"
00040 #undef UG_DIM
00041 
00042 // UG defines a whole load of preprocessor macros.  ug_undefs.hh undefines
00043 // them all, so we don't get name clashes.
00044 #ifdef UG_LGMDOMAIN
00045 #include "uggrid/ug_undefs_lgm_seq.hh"
00046 #else
00047 #include "uggrid/ug_undefs.hh"
00048 #endif
00049 #undef _2
00050 
00051 /* Now we're done with 2d, and we can do the whole thing over again for 3d */
00052 
00053 /* All macros set by UG have been unset.  This includes the macros that ensure
00054    single inclusion of headers.  We can thus include them again.  However, we
00055    only want to include those headers again that contain dimension-dependent stuff.
00056    Therefore, we set a few single-inclusion defines manually before including
00057    ugincludes.hh again.
00058 */
00059 #define UGTYPES_H
00060 #define __HEAPS__
00061 #define __UGENV__
00062 #define __PARGM_H__
00063 #define __DEVICESH__
00064 #define __SM__
00065 
00066 #define _3
00067 #include "uggrid/ugincludes.hh"
00068 
00069 // Wrap a few large UG macros by functions before they get undef'ed away.
00070 // This time it's the 3d-versions.
00071 #define UG_DIM 3
00072 #include "uggrid/ugwrapper.hh"
00073 #undef UG_DIM
00074 
00075 // undef all macros defined by UG
00076 #ifdef UG_LGMDOMAIN
00077 #include "uggrid/ug_undefs_lgm_seq.hh"
00078 #else
00079 #include "uggrid/ug_undefs.hh"
00080 #endif
00081 
00082 #undef _3
00083 #undef FOR_DUNE
00084 
00085 // The components of the UGGrid interface
00086 #include "uggrid/uggridgeometry.hh"
00087 #include "uggrid/uggridentity.hh"
00088 #include "uggrid/uggridentitypointer.hh"
00089 #include "uggrid/ugintersectionit.hh"
00090 #include "uggrid/uggridleveliterator.hh"
00091 #include "uggrid/uggridleafiterator.hh"
00092 #include "uggrid/uggridhieriterator.hh"
00093 #include "uggrid/uggridindexsets.hh"
00094 
00095 namespace Dune {
00096 
00097 template<int dim, int dimworld>
00098 struct UGGridFamily
00099 {
00100   typedef GridTraits<dim,dimworld,Dune::UGGrid<dim>,
00101                      UGGridGeometry,
00102                      UGGridEntity,
00103                      UGGridEntityPointer,
00104                      UGGridLevelIterator,
00105                      UGGridLeafIntersectionIterator, // leaf  intersection iterartor
00106                      UGGridLevelIntersectionIterator, // level intersection iterartor
00107                      UGGridHierarchicIterator,
00108                      UGGridLeafIterator,
00109                      UGGridLevelIndexSet< const UGGrid<dim> >,
00110                      UGGridLevelIndexSetTypes< const UGGrid<dim> >,
00111                      UGGridLeafIndexSet< const UGGrid<dim> >,
00112                      UGGridLeafIndexSetTypes< const UGGrid<dim> >,
00113                      UGGridIdSet< const UGGrid<dim>, false >,
00114                      unsigned int,
00115                      UGGridIdSet< const UGGrid<dim>, true >,
00116                      unsigned int,
00117                      CollectiveCommunication<Dune::UGGrid<dim> > > 
00118   Traits;
00119 };
00120 
00121 
00122 //**********************************************************************
00123 //
00124 // --UGGrid
00125 //
00126 //**********************************************************************
00127 
00161 template <int dim>
00162 class UGGrid : public GridDefaultImplementation  <dim, dim, double, UGGridFamily<dim,dim> >
00163 {
00164     friend class UGGridGeometry<0,dim,const UGGrid<dim> >;
00165     friend class UGGridGeometry<dim,dim,const UGGrid<dim> >;
00166     friend class UGGridGeometry<1,2,const UGGrid<dim> >;
00167     friend class UGGridGeometry<2,3,const UGGrid<dim> >;
00168 
00169     friend class UGGridEntity <0,dim,const UGGrid<dim> >;
00170     friend class UGGridEntity <dim,dim,const UGGrid<dim> >;
00171     friend class UGGridHierarchicIterator<const UGGrid<dim> >;
00172     friend class UGGridLeafIntersectionIterator<const UGGrid<dim> >;
00173     friend class UGGridLevelIntersectionIterator<const UGGrid<dim> >;
00174 
00175     friend class UGGridLevelIndexSet<const UGGrid<dim> >;
00176     friend class UGGridLeafIndexSet<const UGGrid<dim> >;
00177     friend class UGGridIdSet<const UGGrid<dim>, false >;
00178     friend class UGGridIdSet<const UGGrid<dim>, true >;
00179 
00180     template <int codim_, PartitionIteratorType PiType_, class GridImp_>
00181     friend class UGGridLeafIterator;
00182     template <int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
00183     friend class Entity;
00184 
00186     dune_static_assert(dim==2 || dim==3, "Use UGGrid only for 2d and 3d!");
00187 
00188     // The different instantiations are mutual friends so they can access
00189     // each others numOfUGGrids field
00190     friend class UGGrid<2>;
00191     friend class UGGrid<3>;
00192     //**********************************************************
00193       // The Interface Methods
00194       //**********************************************************
00195 public:  
00197       typedef UGGridFamily<dim,dim>  GridFamily;
00198 
00200     typedef typename UGGridFamily<dim,dim>::Traits Traits;
00201 
00203     typedef UG::DOUBLE ctype;
00204 
00209     UGGrid(unsigned int heapSize=500);
00210 
00218     UGGrid(unsigned int heapSize, unsigned int envHeapSize) DUNE_DEPRECATED;
00219 
00221     ~UGGrid();
00222    
00225      int maxLevel() const;
00226      
00228     template<int codim>
00229     typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
00230 
00232     template<int codim>
00233     typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
00234 
00236     template<int codim, PartitionIteratorType PiType>
00237     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
00238 
00240     template<int codim, PartitionIteratorType PiType>
00241     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
00242 
00244     template<int codim>
00245     typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
00246         return typename Traits::template Codim<codim>::template Partition<All_Partition>::LeafIterator(*this);
00247     }
00248 
00250     template<int codim>
00251     typename Traits::template Codim<codim>::LeafIterator leafend() const {
00252         return UGGridLeafIterator<codim,All_Partition, const UGGrid<dim> >();
00253     }
00254 
00256     template<int codim, PartitionIteratorType PiType>
00257     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
00258         return typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator(*this);
00259     }
00260 
00262     template<int codim, PartitionIteratorType PiType>
00263     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
00264         return UGGridLeafIterator<codim,PiType, const UGGrid<dim> >();
00265     }
00266 
00269     int size (int level, int codim) const;
00270 
00272   int size (int codim) const
00273   {
00274       return leafIndexSet().size(codim);
00275   }
00276 
00278   int size (int level, GeometryType type) const
00279   {
00280         return this->levelIndexSet(level).size(type);
00281   }
00282 
00284   int size (GeometryType type) const
00285   {
00286         return this->leafIndexSet().size(type);
00287   }
00288 
00290     const typename Traits::GlobalIdSet& globalIdSet() const
00291     {
00292         return globalIdSet_;
00293     }
00294     
00296     const typename Traits::LocalIdSet& localIdSet() const
00297     {
00298         return localIdSet_;
00299     }
00300     
00302     const typename Traits::LevelIndexSet& levelIndexSet(int level) const
00303     {
00304         if (level<0 || level>maxLevel())
00305             DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
00306         return *levelIndexSets_[level];
00307     }
00308     
00310     const typename Traits::LeafIndexSet& leafIndexSet() const
00311     {
00312         return leafIndexSet_;
00313     }
00314 
00317 
00330     bool mark(int refCount, const typename Traits::template Codim<0>::EntityPointer & e );
00331 
00339     bool mark(const typename Traits::template Codim<0>::EntityPointer & e, 
00340               typename UG_NS<dim>::RefinementRule rule,
00341               int side=0);
00342 
00344     int getMark(const typename Traits::template Codim<0>::EntityPointer& e) const;
00345 
00348     bool preAdapt();
00349     
00351     bool adapt();
00352 
00354     void postAdapt();
00358     std::string name () const { return "UGGrid"; };
00359 
00361     unsigned int overlapSize(int codim) const {
00362         return 0;
00363     }
00364 
00366     unsigned int ghostSize(int codim) const {
00367         return (codim==0) ? 1 : 0;
00368     }
00369 
00371     unsigned int overlapSize(int level, int codim) const {
00372         return 0;
00373     }
00374 
00376     unsigned int ghostSize(int level, int codim) const {
00377         return (codim==0) ? 1 : 0;
00378     }
00379     
00385     void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement);
00386 
00387     typedef GridDefaultImplementation  <dim, dim, double,
00388             UGGridFamily<dim,dim> > GridDefaultImplementationType; 
00389 
00391     using GridDefaultImplementationType :: loadBalance;
00392 
00404     template<class T, template<class> class P, int codim>
00405     void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
00406 
00411     template<class DataHandle>
00412     void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const  
00413     {}
00414 
00415     template<class DataHandle>
00416     void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const  
00417     {}
00418 
00420         const CollectiveCommunication<UGGrid>& comm () const
00421         {
00422           return ccobj;
00423         }
00424 
00425     // **********************************************************
00426     // End of Interface Methods
00427     // **********************************************************
00428     
00431     
00435     void createBegin();
00436 
00438     void createEnd();
00439 
00443     void createLGMGrid(const std::string& name);
00444 
00450     void insertBoundarySegment(const std::vector<unsigned int> vertices,
00451                                const BoundarySegment<dim>* boundarySegment);
00452 
00454     void insertVertex(const FieldVector<double,dim>& pos);
00455 
00460     void insertElement(GeometryType type,
00461                        const std::vector<unsigned int>& vertices);
00462     
00470     void getChildrenOfSubface(typename Traits::template Codim<0>::EntityPointer & e,
00471                               int elementSide,
00472                               int maxl, 
00473                               std::vector<typename Traits::template Codim<0>::EntityPointer>& childElements,
00474                               std::vector<unsigned char>& childElementSides) const;
00475     
00477     enum RefinementType {
00479         LOCAL, 
00481         COPY};
00482 
00484     enum ClosureType {
00486         GREEN,
00488         NONE};
00489 
00491     void setRefinementType(RefinementType type) {
00492         refinementType_ = type;
00493     }
00494 
00496     void setClosureType(ClosureType type) {
00497         closureType_ = type;
00498     }
00499 
00501     void collapse() {
00502         if (Collapse(multigrid_))
00503             DUNE_THROW(GridError, "UG" << dim << "d::Collapse() returned error code!");
00504 
00505         setIndices();
00506     }
00507 
00511     void setPosition(typename Traits::template Codim<dim>::EntityPointer& e,
00512                      const FieldVector<double, dim>& pos);
00513 
00515     FieldVector<ctype,dim> getBoundaryPosition(const IntersectionIterator<const UGGrid<dim>, UGGridLevelIntersectionIterator>& iIt,
00516                                                const FieldVector<ctype,dim-1>& localPos) const;
00517 
00522     void globalRefine(int n);
00523 
00524     void saveState(const std::string& filename) const;
00525 
00526     void loadState(const std::string& filename);
00527 
00528 private:
00530     typename UG_NS<dim>::MultiGrid* multigrid_;
00531 
00533     std::vector<const BoundarySegment<dim>*> boundarySegments_;
00534 
00536     std::vector<array<unsigned int, dim*2-2> > boundarySegmentVertices_;
00537 
00538   CollectiveCommunication<UGGrid> ccobj;
00539 
00540     // Recomputes entity indices after the grid was changed
00541     void setIndices();
00542 
00543     // Each UGGrid object has a unique name to identify it in the
00544     // UG environment structure
00545     std::string name_;
00546 
00547     // Our set of level indices
00548     std::vector<UGGridLevelIndexSet<const UGGrid<dim> >*> levelIndexSets_;
00549 
00550     UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
00551 
00552     UGGridIdSet<const UGGrid<dim>, false > globalIdSet_;
00553 
00554     UGGridIdSet<const UGGrid<dim>, true > localIdSet_;
00555 
00557     RefinementType refinementType_;
00558 
00560     ClosureType closureType_;
00561 
00564     std::vector<unsigned char> elementTypes_;
00565 
00568     std::vector<unsigned int> elementVertices_;
00569 
00571     std::vector<FieldVector<double, dim> > vertexPositions_;
00572 
00580     static int numOfUGGrids;
00581 
00587     bool someElementHasBeenMarkedForRefinement_;
00588 
00593     unsigned int heapsize;
00594 
00595 
00596 }; // end Class UGGrid
00597 
00598 namespace Capabilities
00599 {
00615   template<int dim>
00616   struct hasEntity< UGGrid<dim>, 0>
00617   {
00618     static const bool v = true;
00619   };
00620 
00624   template<int dim>
00625   struct hasEntity< UGGrid<dim>, dim>
00626   {
00627     static const bool v = true;
00628   };
00629   
00633   template<int dim>
00634   struct isParallel< UGGrid<dim> >
00635   {
00636 #ifdef ModelP
00637       static const bool v = true;
00638 #else
00639       static const bool v = false;
00640 #endif
00641   };
00642 
00646   template<int dim>
00647   struct isLevelwiseConforming< UGGrid<dim> >
00648   {
00649     static const bool v = true;
00650   };
00651 
00655   template<int dim>
00656   struct isLeafwiseConforming< UGGrid<dim> >
00657   {
00658     static const bool v = false;
00659   };
00660 
00664   template<int dim>
00665   struct hasHangingNodes< UGGrid<dim> >
00666   {
00667     static const bool v = true;
00668   };
00669   
00670 }
00671 
00672 } // namespace Dune
00673 
00674 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].