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 // Not needed here, but included for user convenience
00096 #include "uggrid/uggridfactory.hh"
00097 
00098 namespace Dune {
00099 
00100 template<int dim, int dimworld>
00101 struct UGGridFamily
00102 {
00103   typedef GridTraits<dim,dimworld,Dune::UGGrid<dim>,
00104                      UGGridGeometry,
00105                      UGGridEntity,
00106                      UGGridEntityPointer,
00107                      UGGridLevelIterator,
00108                      UGGridLeafIntersectionIterator, // leaf  intersection
00109                      UGGridLevelIntersectionIterator, // level intersection
00110                      UGGridLeafIntersectionIterator, // leaf  intersection iterator
00111                      UGGridLevelIntersectionIterator, // level intersection iterator
00112                      UGGridHierarchicIterator,
00113                      UGGridLeafIterator,
00114                      UGGridLevelIndexSet< const UGGrid<dim> >,
00115                      UGGridLevelIndexSetTypes< const UGGrid<dim> >,
00116                      UGGridLeafIndexSet< const UGGrid<dim> >,
00117                      UGGridLeafIndexSetTypes< const UGGrid<dim> >,
00118                      UGGridIdSet< const UGGrid<dim>, false >,
00119                      unsigned int,
00120                      UGGridIdSet< const UGGrid<dim>, true >,
00121                      unsigned int,
00122                      CollectiveCommunication<Dune::UGGrid<dim> > > 
00123   Traits;
00124 };
00125 
00126 
00127 //**********************************************************************
00128 //
00129 // --UGGrid
00130 //
00131 //**********************************************************************
00132 
00169 template <int dim>
00170 class UGGrid : public GridDefaultImplementation  <dim, dim, double, UGGridFamily<dim,dim> >
00171 {
00172     friend class UGGridGeometry<0,dim,const UGGrid<dim> >;
00173     friend class UGGridGeometry<dim,dim,const UGGrid<dim> >;
00174     friend class UGGridGeometry<1,2,const UGGrid<dim> >;
00175     friend class UGGridGeometry<2,3,const UGGrid<dim> >;
00176 
00177     friend class UGGridEntity <0,dim,const UGGrid<dim> >;
00178     friend class UGGridEntity <dim,dim,const UGGrid<dim> >;
00179     friend class UGGridHierarchicIterator<const UGGrid<dim> >;
00180     friend class UGGridLeafIntersectionIterator<const UGGrid<dim> >;
00181     friend class UGGridLevelIntersectionIterator<const UGGrid<dim> >;
00182 
00183     friend class UGGridLevelIndexSet<const UGGrid<dim> >;
00184     friend class UGGridLeafIndexSet<const UGGrid<dim> >;
00185     friend class UGGridIdSet<const UGGrid<dim>, false >;
00186     friend class UGGridIdSet<const UGGrid<dim>, true >;
00187 
00188     template <int codim_, PartitionIteratorType PiType_, class GridImp_>
00189     friend class UGGridLeafIterator;
00190     template <int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
00191     friend class Entity;
00192 
00194     dune_static_assert(dim==2 || dim==3, "Use UGGrid only for 2d and 3d!");
00195 
00196     // The different instantiations are mutual friends so they can access
00197     // each others numOfUGGrids field
00198     friend class UGGrid<2>;
00199     friend class UGGrid<3>;
00200     //**********************************************************
00201       // The Interface Methods
00202       //**********************************************************
00203 public:  
00205       typedef UGGridFamily<dim,dim>  GridFamily;
00206 
00208     typedef typename UGGridFamily<dim,dim>::Traits Traits;
00209 
00211     typedef UG::DOUBLE ctype;
00212 
00217     UGGrid(unsigned int heapSize=500);
00218 
00220     ~UGGrid();
00221    
00224      int maxLevel() const;
00225      
00227     template<int codim>
00228     typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
00229 
00231     template<int codim>
00232     typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
00233 
00235     template<int codim, PartitionIteratorType PiType>
00236     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
00237 
00239     template<int codim, PartitionIteratorType PiType>
00240     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
00241 
00243     template<int codim>
00244     typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
00245         return typename Traits::template Codim<codim>::template Partition<All_Partition>::LeafIterator(*this);
00246     }
00247 
00249     template<int codim>
00250     typename Traits::template Codim<codim>::LeafIterator leafend() const {
00251         return UGGridLeafIterator<codim,All_Partition, const UGGrid<dim> >();
00252     }
00253 
00255     template<int codim, PartitionIteratorType PiType>
00256     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
00257         return typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator(*this);
00258     }
00259 
00261     template<int codim, PartitionIteratorType PiType>
00262     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
00263         return UGGridLeafIterator<codim,PiType, const UGGrid<dim> >();
00264     }
00265 
00268     int size (int level, int codim) const;
00269 
00271   int size (int codim) const
00272   {
00273       return leafIndexSet().size(codim);
00274   }
00275 
00277   int size (int level, GeometryType type) const
00278   {
00279         return this->levelIndexSet(level).size(type);
00280   }
00281 
00283   int size (GeometryType type) const
00284   {
00285         return this->leafIndexSet().size(type);
00286   }
00287 
00289     const typename Traits::GlobalIdSet& globalIdSet() const
00290     {
00291         return globalIdSet_;
00292     }
00293     
00295     const typename Traits::LocalIdSet& localIdSet() const
00296     {
00297         return localIdSet_;
00298     }
00299     
00301     const typename Traits::LevelIndexSet& levelIndexSet(int level) const
00302     {
00303         if (level<0 || level>maxLevel())
00304             DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
00305         return *levelIndexSets_[level];
00306     }
00307     
00309     const typename Traits::LeafIndexSet& leafIndexSet() const
00310     {
00311         return leafIndexSet_;
00312     }
00313 
00316 
00329     bool mark(int refCount, const typename Traits::template Codim<0>::EntityPointer & e ) DUNE_DEPRECATED;
00330 
00343     bool mark(int refCount, const typename Traits::template Codim<0>::Entity & e );
00344 
00352     bool mark(const typename Traits::template Codim<0>::EntityPointer & e, 
00353               typename UG_NS<dim>::RefinementRule rule,
00354               int side=0) DUNE_DEPRECATED ;
00355 
00363     bool mark(const typename Traits::template Codim<0>::Entity & e, 
00364               typename UG_NS<dim>::RefinementRule rule,
00365               int side=0);
00366 
00368     int getMark(const typename Traits::template Codim<0>::EntityPointer& e) const DUNE_DEPRECATED ;
00369 
00371     int getMark(const typename Traits::template Codim<0>::Entity& e) const;
00372 
00375     bool preAdapt();
00376     
00378     bool adapt();
00379 
00381     void postAdapt();
00385     std::string name () const { return "UGGrid"; };
00386 
00388     unsigned int overlapSize(int codim) const {
00389         return 0;
00390     }
00391 
00393     unsigned int ghostSize(int codim) const {
00394         return (codim==0) ? 1 : 0;
00395     }
00396 
00398     unsigned int overlapSize(int level, int codim) const {
00399         return 0;
00400     }
00401 
00403     unsigned int ghostSize(int level, int codim) const {
00404         return (codim==0) ? 1 : 0;
00405     }
00406     
00412     void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement);
00413 
00414     typedef GridDefaultImplementation  <dim, dim, double,
00415             UGGridFamily<dim,dim> > GridDefaultImplementationType; 
00416 
00418     using GridDefaultImplementationType :: loadBalance;
00419 
00431     template<class T, template<class> class P, int codim>
00432     void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
00433 
00438     template<class DataHandle>
00439     void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const  
00440     {}
00441 
00442     template<class DataHandle>
00443     void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const  
00444     {}
00445 
00447         const CollectiveCommunication<UGGrid>& comm () const
00448         {
00449           return ccobj;
00450         }
00451 
00452     // **********************************************************
00453     // End of Interface Methods
00454     // **********************************************************
00455     
00458     
00462     void createBegin() DUNE_DEPRECATED;
00463 
00465     void createEnd() DUNE_DEPRECATED;
00466 
00470     void createLGMGrid(const std::string& name);
00471 
00477     void insertBoundarySegment(const std::vector<unsigned int> vertices,
00478                                const BoundarySegment<dim>* boundarySegment) DUNE_DEPRECATED;
00479 
00481     void insertVertex(const FieldVector<double,dim>& pos) DUNE_DEPRECATED;
00482 
00487     void insertElement(GeometryType type,
00488                        const std::vector<unsigned int>& vertices) DUNE_DEPRECATED;
00489     
00497     void getChildrenOfSubface(typename Traits::template Codim<0>::EntityPointer & e,
00498                               int elementSide,
00499                               int maxl, 
00500                               std::vector<typename Traits::template Codim<0>::EntityPointer>& childElements,
00501                               std::vector<unsigned char>& childElementSides) const;
00502     
00504     enum RefinementType {
00506         LOCAL, 
00508         COPY};
00509 
00511     enum ClosureType {
00513         GREEN,
00515         NONE};
00516 
00518     void setRefinementType(RefinementType type) {
00519         refinementType_ = type;
00520     }
00521 
00523     void setClosureType(ClosureType type) {
00524         closureType_ = type;
00525     }
00526 
00528     void collapse() {
00529         if (Collapse(multigrid_))
00530             DUNE_THROW(GridError, "UG" << dim << "d::Collapse() returned error code!");
00531 
00532         setIndices();
00533     }
00534 
00538     void setPosition(typename Traits::template Codim<dim>::EntityPointer& e,
00539                      const FieldVector<double, dim>& pos);
00540 
00542     FieldVector<ctype,dim> getBoundaryPosition(const typename Traits::LevelIntersectionIterator& iIt,
00543                                                const FieldVector<ctype,dim-1>& localPos) const;
00544 
00549     void globalRefine(int n);
00550 
00551     void saveState(const std::string& filename) const;
00552 
00553     void loadState(const std::string& filename);
00554 
00555 private:
00557     typename UG_NS<dim>::MultiGrid* multigrid_;
00558 
00560     std::vector<const BoundarySegment<dim>*> boundarySegments_;
00561 
00563     std::vector<array<unsigned int, dim*2-2> > boundarySegmentVertices_;
00564 
00565   CollectiveCommunication<UGGrid> ccobj;
00566 
00567     // Recomputes entity indices after the grid was changed
00568     void setIndices(std::vector<unsigned int>* nodePermutation=0);
00569 
00570     // Each UGGrid object has a unique name to identify it in the
00571     // UG environment structure
00572     std::string name_;
00573 
00574     // Our set of level indices
00575     std::vector<UGGridLevelIndexSet<const UGGrid<dim> >*> levelIndexSets_;
00576 
00577     UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
00578 
00579     UGGridIdSet<const UGGrid<dim>, false > globalIdSet_;
00580 
00581     UGGridIdSet<const UGGrid<dim>, true > localIdSet_;
00582 
00584     RefinementType refinementType_;
00585 
00587     ClosureType closureType_;
00588 
00591     std::vector<unsigned char> elementTypes_;
00592 
00595     std::vector<unsigned int> elementVertices_;
00596 
00598     std::vector<FieldVector<double, dim> > vertexPositions_;
00599 
00607     static int numOfUGGrids;
00608 
00614     bool someElementHasBeenMarkedForRefinement_;
00615 
00620     unsigned int heapsize;
00621 
00622 
00623 }; // end Class UGGrid
00624 
00625 namespace Capabilities
00626 {
00642   template<int dim>
00643   struct hasEntity< UGGrid<dim>, 0>
00644   {
00645     static const bool v = true;
00646   };
00647 
00651   template<int dim>
00652   struct hasEntity< UGGrid<dim>, dim>
00653   {
00654     static const bool v = true;
00655   };
00656   
00660   template<int dim>
00661   struct isParallel< UGGrid<dim> >
00662   {
00663 #ifdef ModelP
00664       static const bool v = true;
00665 #else
00666       static const bool v = false;
00667 #endif
00668   };
00669 
00673   template<int dim>
00674   struct isLevelwiseConforming< UGGrid<dim> >
00675   {
00676     static const bool v = true;
00677   };
00678 
00682   template<int dim>
00683   struct isLeafwiseConforming< UGGrid<dim> >
00684   {
00685     static const bool v = false;
00686   };
00687 
00691   template<int dim>
00692   struct hasHangingNodes< UGGrid<dim> >
00693   {
00694     static const bool v = true;
00695   };
00696   
00697 }
00698 
00699 } // namespace Dune
00700 
00701 #endif

Generated on 20 Nov 2008 with Doxygen (ver 1.5.1) [logfile].