00001 #ifndef DUNE_GRID_HH
00002 #define DUNE_GRID_HH
00003
00007
00008 #include <iostream>
00009 #include <string>
00010
00011
00012 #include <dune/common/exceptions.hh>
00013 #include <dune/common/fvector.hh>
00014 #include <dune/common/helpertemplates.hh>
00015 #include <dune/common/typetraits.hh>
00016 #include <dune/common/geometrytype.hh>
00017
00018
00019 #include <dune/grid/common/gridenums.hh>
00020 #include <dune/grid/common/capabilities.hh>
00021 #include <dune/grid/common/datahandleif.hh>
00022 #include <dune/grid/common/gridview.hh>
00023 #include <dune/grid/common/defaultgridview.hh>
00024
00025
00026
00027 #include <dune/common/bartonnackmanifcheck.hh>
00028
00029 namespace Dune {
00030
00339
00340
00341
00342
00346 class GridError : public Exception {};
00347
00348
00349 template<int mydim, int cdim, class GridImp,template<int,int,class> class GeometryImp> class Geometry;
00350
00351
00352 template<int codim, int dim, class GridImp,template<int,int,class> class EntityImp> class Entity;
00353 template<class GridImp, class EntityPointerImp> class EntityPointer;
00354 template<int codim, PartitionIteratorType pitype, class GridImp,
00355 template<int,PartitionIteratorType,class> class LevelIteratorImp> class LevelIterator;
00356 template<class GridImp, template<class> class IntersectionImp> class Intersection;
00357 template<class GridImp, template<class> class IntersectionIteratorImp, template<class> class IntersectionImp> class IntersectionIterator;
00358 template<class GridImp, template<class> class HierarchicIteratorImp> class HierarchicIterator;
00359 template<int codim, PartitionIteratorType pitype, class GridImp,
00360 template<int,PartitionIteratorType,class> class LeafIteratorImp> class LeafIterator;
00361 template<class GridImp> class GenericLeafIterator;
00362 template<class GridImp, class IndexSetIteratorImp, class IndexSetImp> class IndexSet;
00363 template<class GridImp, class IdSetImp, class IdTypeImp> class IdSet;
00364
00365
00366
00367
00368
00369
00388 template< int dim, int dimworld, class ct, class GridFamily>
00389 class Grid {
00390 typedef typename GridFamily::Traits::Grid GridImp;
00391 typedef Grid<dim,dimworld,ct,GridFamily> ThisType;
00392 public:
00393
00394
00398
00399
00401 enum {
00403 dimension=dim
00404 };
00405
00407 enum {
00409 dimensionworld=dimworld
00410 };
00412
00413
00417
00418
00420 template <PartitionIteratorType pitype>
00421 struct Partition
00422 {
00423 typedef typename GridFamily::Traits::template Partition<pitype>::LevelGridView
00424 LevelGridView;
00425 typedef typename GridFamily::Traits::template Partition<pitype>::LeafGridView
00426 LeafGridView;
00427 };
00429 typedef typename Partition< All_Partition > :: LevelGridView LevelGridView;
00430 typedef typename Partition< All_Partition > :: LeafGridView LeafGridView;
00431
00432
00439 template <int cd>
00440 struct Codim
00441 {
00443 typedef typename GridFamily::Traits::template Codim<cd>::Geometry Geometry;
00444
00446 typedef typename GridFamily::Traits::template Codim<cd>::LocalGeometry LocalGeometry;
00447
00449 typedef typename GridFamily::Traits::template Codim<cd>::Entity Entity;
00450
00452 typedef typename GridFamily::Traits::template Codim<cd>::EntityPointer EntityPointer;
00453
00455 template <PartitionIteratorType pitype>
00456 struct Partition
00457 {
00464 typedef typename GridFamily::Traits::template Codim<cd>::template Partition<pitype>::LevelIterator LevelIterator;
00471 typedef typename GridFamily::Traits::template Codim<cd>::template Partition<pitype>::LeafIterator LeafIterator;
00472 };
00473
00477 typedef typename GridFamily::Traits::LeafIntersection LeafIntersection;
00478
00482 typedef typename GridFamily::Traits::LevelIntersection LevelIntersection;
00483
00489 typedef typename GridFamily::Traits::LeafIntersectionIterator LeafIntersectionIterator;
00490
00496 typedef typename GridFamily::Traits::LevelIntersectionIterator LevelIntersectionIterator;
00497
00503 typedef typename GridFamily::Traits::HierarchicIterator HierarchicIterator;
00504
00507 typedef typename GridFamily::Traits::template Codim<cd>::LevelIterator LevelIterator;
00508
00511 typedef typename GridFamily::Traits::template Codim<cd>::LeafIterator LeafIterator;
00512
00517 typedef typename GridFamily::Traits::LevelIndexSet LevelIndexSet;
00518
00523 typedef typename GridFamily::Traits::LeafIndexSet LeafIndexSet;
00524
00531 typedef typename GridFamily::Traits::GlobalIdSet GlobalIdSet;
00532
00538 typedef typename GridFamily::Traits::LocalIdSet LocalIdSet;
00539
00544 typedef typename GridFamily::Traits::CollectiveCommunication CollectiveCommunication;
00545
00546 };
00547
00549 typedef ct ctype;
00551
00552
00553
00557
00558
00560 std::string name() const
00561 {
00562 CHECK_INTERFACE_IMPLEMENTATION(asImp().name());
00563 return asImp().name();
00564 }
00565
00567
00568
00572
00573
00577 int maxLevel() const
00578 {
00579 CHECK_INTERFACE_IMPLEMENTATION(asImp().maxLevel());
00580 return asImp().maxLevel();
00581 }
00582
00584 int size (int level, int codim) const
00585 {
00586 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,codim));
00587 return asImp().size(level,codim);
00588 }
00589
00591 int size (int codim) const
00592 {
00593 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(codim));
00594 return asImp().size(codim);
00595 }
00596
00598 int size (int level, GeometryType type) const
00599 {
00600 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,type));
00601 return asImp().size(level,type);
00602 }
00603
00605 int size (GeometryType type) const
00606 {
00607 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(type));
00608 return asImp().size(type);
00609 }
00611
00612
00613
00617
00618
00620 template<PartitionIteratorType pitype>
00621 typename Partition<pitype>::LevelGridView levelView(int level) const {
00622 CHECK_INTERFACE_IMPLEMENTATION((asImp().template levelView<pitype>(level)));
00623 return asImp().template levelView<pitype>(level);
00624 }
00625
00627 template<PartitionIteratorType pitype>
00628 typename Partition<pitype>::LeafGridView leafView() const {
00629 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafView<pitype>()));
00630 return asImp().template leafView<pitype>();
00631 }
00632
00634 LevelGridView levelView(int level) const {
00635 CHECK_INTERFACE_IMPLEMENTATION((asImp().levelView(level)));
00636 return asImp().levelView(level);
00637 }
00638
00640 LeafGridView leafView() const {
00641 CHECK_INTERFACE_IMPLEMENTATION((asImp().leafView()));
00642 return asImp().leafView();
00643 }
00644
00646
00647
00648
00652
00653
00655 template<int cd, PartitionIteratorType pitype>
00656 typename Codim<cd>::template Partition<pitype>::LevelIterator lbegin (int level) const
00657 {
00658 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lbegin<cd,pitype>(level)));
00659 return asImp().template lbegin<cd,pitype>(level);
00660 }
00661
00663 template<int cd, PartitionIteratorType pitype>
00664 typename Codim<cd>::template Partition<pitype>::LevelIterator lend (int level) const
00665 {
00666 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lend<cd,pitype>(level)));
00667 return asImp().template lend<cd,pitype>(level);
00668 }
00669
00671 template<int cd>
00672 typename Codim<cd>::template Partition<All_Partition>::LevelIterator lbegin (int level) const
00673 {
00674 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lbegin<cd>(level)));
00675 return asImp().template lbegin<cd>(level);
00676 }
00677
00679 template<int cd>
00680 typename Codim<cd>::template Partition<All_Partition>::LevelIterator lend (int level) const
00681 {
00682 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lend<cd>(level)));
00683 return asImp().template lend<cd>(level);
00684 }
00685
00687 template<int cd, PartitionIteratorType pitype>
00688 typename Codim<cd>::template Partition<pitype>::LeafIterator leafbegin () const
00689 {
00690 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafbegin<cd,pitype>()));
00691 return asImp().template leafbegin<cd,pitype>();
00692 }
00693
00695 template<int cd, PartitionIteratorType pitype>
00696 typename Codim<cd>::template Partition<pitype>::LeafIterator leafend () const
00697 {
00698 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafend<cd,pitype>()));
00699 return asImp().template leafend<cd,pitype>();
00700 }
00701
00703 template<int cd>
00704 typename Codim<cd>::template Partition<All_Partition>::LeafIterator leafbegin () const
00705 {
00706 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafbegin<cd,All_Partition>()));
00707 return asImp().template leafbegin<cd,All_Partition>();
00708 }
00709
00711 template<int cd>
00712 typename Codim<cd>::template Partition<All_Partition>::LeafIterator leafend () const
00713 {
00714 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafend<cd,All_Partition>()));
00715 return asImp().template leafend<cd,All_Partition>();
00716 }
00718
00719
00720
00724
00725
00727 const typename Codim<0>::GlobalIdSet& globalIdSet() const
00728 {
00729 CHECK_INTERFACE_IMPLEMENTATION(asImp().globalIdSet());
00730 return asImp().globalIdSet();
00731 }
00732
00734 const typename Codim<0>::LocalIdSet& localIdSet() const
00735 {
00736 CHECK_INTERFACE_IMPLEMENTATION(asImp().localIdSet());
00737 return asImp().localIdSet();
00738 }
00739
00741 const typename Codim<0>::LevelIndexSet& levelIndexSet(int level) const
00742 {
00743 CHECK_INTERFACE_IMPLEMENTATION(asImp().levelIndexSet(level));
00744 return asImp().levelIndexSet(level);
00745 }
00746
00748 const typename Codim<0>::LeafIndexSet& leafIndexSet() const
00749 {
00750 CHECK_INTERFACE_IMPLEMENTATION(asImp().leafIndexSet());
00751 return asImp().leafIndexSet();
00752 }
00754
00755
00756
00760
00761
00763 void globalRefine (int refCount)
00764 {
00765 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(asImp().globalRefine(refCount));
00766 return;
00767 }
00768
00776 bool mark( int refCount, const typename Codim<0>::EntityPointer & e ) DUNE_DEPRECATED
00777 {
00778 return asImp().mark(refCount,e);
00779 }
00780
00788 bool mark( int refCount, const typename Codim<0>::Entity & e )
00789 {
00790 return asImp().mark(refCount,e);
00791 }
00792
00799 int getMark(const typename Codim<0>::EntityPointer & e) const DUNE_DEPRECATED
00800 {
00801 return asImp().getMark(e);
00802 }
00803
00810 int getMark(const typename Codim<0>::Entity & e) const
00811 {
00812 return asImp().getMark(e);
00813 }
00814
00819 bool preAdapt ()
00820 {
00821 return asImp().preAdapt();
00822 }
00823
00838 bool adapt ()
00839 {
00840 return asImp().adapt();
00841 }
00842
00844 void postAdapt()
00845 {
00846 return asImp().postAdapt();
00847 }
00849
00850
00851
00855
00856
00858 int overlapSize (int level, int codim) const
00859 {
00860 CHECK_INTERFACE_IMPLEMENTATION(asImp().overlapSize(level,codim));
00861 return asImp().overlapSize(level,codim);
00862 }
00863
00865 int overlapSize (int codim) const
00866 {
00867 CHECK_INTERFACE_IMPLEMENTATION(asImp().overlapSize(codim));
00868 return asImp().overlapSize(codim);
00869 }
00870
00872 int ghostSize (int level, int codim) const
00873 {
00874 CHECK_INTERFACE_IMPLEMENTATION(asImp().ghostSize(level,codim));
00875 return asImp().ghostSize(level,codim);
00876 }
00877
00879 int ghostSize (int codim) const
00880 {
00881 CHECK_INTERFACE_IMPLEMENTATION(asImp().ghostSize(codim));
00882 return asImp().ghostSize(codim);
00883 }
00884
00888 template<class DataHandleImp, class DataTypeImp>
00889 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data, InterfaceType iftype, CommunicationDirection dir, int level) const
00890 {
00891 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().template communicate<DataHandleImp,DataTypeImp>(data,iftype,dir,level)));
00892 return;
00893 }
00894
00898 template<class DataHandleImp, class DataTypeImp>
00899 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data, InterfaceType iftype, CommunicationDirection dir) const
00900 {
00901 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().template communicate<DataHandleImp,DataTypeImp>(data,iftype,dir)));
00902 return;
00903 }
00904
00906 const typename Codim<0>::CollectiveCommunication& comm () const
00907 {
00908 CHECK_INTERFACE_IMPLEMENTATION(asImp().comm());
00909 return asImp().comm();
00910 }
00912
00916 bool loadBalance()
00917 {
00918 CHECK_INTERFACE_IMPLEMENTATION(asImp().loadBalance());
00919 return asImp().loadBalance();
00920 }
00921
00926 template<class DataHandle>
00927 bool loadBalance (DataHandle& data)
00928 {
00929 CHECK_INTERFACE_IMPLEMENTATION(asImp().loadBalance(data));
00930 return asImp().loadBalance(data);
00931 }
00932
00933 protected:
00935 GridImp& asImp () {return static_cast<GridImp &> (*this);}
00937 const GridImp& asImp () const {return static_cast<const GridImp &>(*this);}
00938 };
00939
00940 #undef CHECK_INTERFACE_IMPLEMENTATION
00941 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00942
00943
00944
00945
00946
00947
00948
00949
00950
00989 template<int dim,
00990 int dimworld,
00991 class ct,
00992 class GridFamily>
00993 class GridDefaultImplementation : public Grid <dim,dimworld,ct,GridFamily>
00994 {
00995 typedef typename GridFamily::Traits::Grid GridImp;
00996
00997 public:
01003 typedef typename GridFamily::Traits Traits;
01004
01006 template<PartitionIteratorType pitype>
01007 typename Traits::template Partition<pitype>::LevelGridView
01008 levelView(int level) const {
01009 typedef typename Traits::template Partition<pitype>::LevelGridView View;
01010 typedef typename View::GridViewImp ViewImp;
01011 return View(ViewImp(asImp(),level));
01012 }
01013
01015 template<PartitionIteratorType pitype>
01016 typename Traits::template Partition<pitype>::LeafGridView leafView() const {
01017 typedef typename Traits::template Partition<pitype>::LeafGridView View;
01018 typedef typename View::GridViewImp ViewImp;
01019 return View(ViewImp(asImp()));
01020 }
01021
01023 typename Traits::template Partition<All_Partition>::LevelGridView
01024 levelView(int level) const {
01025 typedef typename Traits::template Partition<All_Partition>::LevelGridView View;
01026 typedef typename View::GridViewImp ViewImp;
01027 return View(ViewImp(asImp(),level));
01028 }
01029
01031 typename Traits::template Partition<All_Partition>::LeafGridView
01032 leafView() const {
01033 typedef typename Traits::template Partition<All_Partition>::LeafGridView View;
01034 typedef typename View::GridViewImp ViewImp;
01035 return View(ViewImp(asImp()));
01036 }
01037
01038
01039
01040
01063 bool mark( int refCount, const typename Traits::template Codim< 0 >::EntityPointer &e ) DUNE_DEPRECATED
01064 {
01065 return asImp().mark( refCount, *e );
01066 }
01067
01090 bool mark( int refCount, const typename Traits :: template Codim<0>::Entity & e )
01091 {
01092 return false;
01093 }
01094
01102 int getMark ( const typename Traits::template Codim< 0 >::EntityPointer &e ) const DUNE_DEPRECATED
01103 {
01104 return asImp().getMark( *e );
01105 }
01106
01114 int getMark(const typename Traits :: template Codim<0>::Entity &) const
01115 {
01116 return 0;
01117 }
01118
01126 bool adapt () { return false; }
01127
01129 bool preAdapt () { return false; }
01130
01132 void postAdapt() {}
01133
01135 int ghostSize (int level, int codim) const { return 0; }
01136
01138 int overlapSize (int level, int codim) const { return 0; }
01139
01141 int ghostSize (int codim) const { return 0; }
01142
01144 int overlapSize (int codim) const { return 0; }
01145
01147 template<class DataHandleImp, class DataTypeImp>
01148 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
01149 InterfaceType iftype, CommunicationDirection dir, int level) const
01150 {
01151 }
01152
01154 template<class DataHandleImp, class DataTypeImp>
01155 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
01156 InterfaceType iftype, CommunicationDirection dir) const
01157 {
01158 }
01159
01161 bool loadBalance()
01162 {
01163 return false;
01164 }
01165
01167 template<class DataHandle>
01168 bool loadBalance (DataHandle& data)
01169 {
01170 return false;
01171 }
01172 protected:
01179 template<class T>
01180 class ReturnImplementationType : public T
01181 {
01182 public:
01184 typedef typename T::ImplementationType ImplementationType;
01185 private:
01186
01187 ReturnImplementationType(const T& t) : T(t) {}
01188 };
01189
01190 template<class T>
01191 class ReturnImplementationType<const T> : public T
01192 {
01193 public:
01194 typedef const typename T::ImplementationType ImplementationType;
01195 private:
01196
01197 ReturnImplementationType(const T& t) : T(t) {}
01198 };
01199
01201 template <class InterfaceType>
01202 static typename ReturnImplementationType<InterfaceType>::ImplementationType &
01203 getRealImplementation (InterfaceType &i) { return i.getRealImp(); }
01204
01205 protected:
01206 using Grid< dim, dimworld, ct, GridFamily >::asImp;
01207 };
01208
01221 template <int dim, int dimw, class GridImp,
01222 template<int,int,class> class GeometryImp,
01223 template<int,int,class> class EntityImp,
01224 template<int,class> class EntityPointerImp,
01225 template<int,PartitionIteratorType,class> class LevelIteratorImp,
01226 template<class> class LeafIntersectionImp,
01227 template<class> class LevelIntersectionImp,
01228 template<class> class LeafIntersectionIteratorImp,
01229 template<class> class LevelIntersectionIteratorImp,
01230 template<class> class HierarchicIteratorImp,
01231 template<int,PartitionIteratorType,class> class LeafIteratorImp,
01232 class LevelIndexSetImp, class LevelIndexSetTypes, class LeafIndexSetImp, class LeafIndexSetTypes,
01233 class GlobalIdSetImp, class GIDType, class LocalIdSetImp, class LIDType, class CCType,
01234 template<class,PartitionIteratorType> class LevelGridViewTraits = DefaultLevelGridViewTraits,
01235 template<class,PartitionIteratorType> class LeafGridViewTraits = DefaultLeafGridViewTraits
01236 >
01237 struct GridTraits
01238 {
01240 typedef GridImp Grid;
01241
01243 typedef Dune::Intersection<const GridImp, LeafIntersectionImp> LeafIntersection;
01245 typedef Dune::Intersection<const GridImp, LevelIntersectionImp> LevelIntersection;
01247 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorImp, LeafIntersectionImp> LeafIntersectionIterator;
01249 typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorImp, LevelIntersectionImp> LevelIntersectionIterator;
01250
01252 typedef Dune::HierarchicIterator<const GridImp, HierarchicIteratorImp> HierarchicIterator;
01253
01258 template <int cd>
01259 struct Codim
01260 {
01262
01263 typedef Dune::Geometry<dim-cd, dimw, const GridImp, GeometryImp> Geometry;
01265 typedef Dune::Geometry<dim-cd, dim, const GridImp, GeometryImp> LocalGeometry;
01267
01268 typedef Dune::Entity<cd, dim, const GridImp, EntityImp> Entity;
01269
01271 typedef Dune::LevelIterator<cd,All_Partition,const GridImp,LevelIteratorImp> LevelIterator;
01272
01274 typedef Dune::LeafIterator<cd,All_Partition,const GridImp,LeafIteratorImp> LeafIterator;
01275
01277 typedef Dune::EntityPointer<const GridImp,EntityPointerImp<cd,const GridImp> > EntityPointer;
01278
01283 template <PartitionIteratorType pitype>
01284 struct Partition
01285 {
01287 typedef Dune::LevelIterator<cd,pitype,const GridImp,LevelIteratorImp> LevelIterator;
01289 typedef Dune::LeafIterator<cd,pitype,const GridImp,LeafIteratorImp> LeafIterator;
01290 };
01291 private:
01292 friend class Dune::Entity<cd, dim, const GridImp, EntityImp>;
01293 typedef EntityPointerImp<cd,const GridImp> EntityPointerImpl;
01294 };
01295
01300 template <PartitionIteratorType pitype>
01301 struct Partition
01302 {
01304 typedef Dune::GridView<LevelGridViewTraits<const GridImp,pitype> >
01305 LevelGridView;
01306
01308 typedef Dune::GridView<LeafGridViewTraits<const GridImp,pitype> >
01309 LeafGridView;
01310 };
01311
01313 typedef IndexSet<const GridImp,LevelIndexSetImp,LevelIndexSetTypes> LevelIndexSet;
01315 typedef IndexSet<const GridImp,LeafIndexSetImp,LeafIndexSetTypes> LeafIndexSet;
01317 typedef IdSet<const GridImp,GlobalIdSetImp,GIDType> GlobalIdSet;
01319 typedef IdSet<const GridImp,LocalIdSetImp,LIDType> LocalIdSet;
01320
01322 typedef CCType CollectiveCommunication;
01323 };
01324
01325
01326 namespace Capabilities
01327 {
01328
01329 template< int dim, int dimworld, typename ct, class GridFamily , int cdim >
01330 struct hasEntity< GridDefaultImplementation<dim,dimworld,ct,GridFamily>, cdim >
01331 {
01332 typedef GridDefaultImplementation<dim,dimworld,ct,GridFamily> GridType;
01333 typedef typename GridType::Traits::Grid GridImp;
01334 static const bool v = hasEntity<GridImp,cdim>::v;
01335 };
01336
01337 }
01338
01344 template <class InterfaceType>
01345 struct MakeableInterfaceObject : public InterfaceType
01346 {
01347 typedef typename InterfaceType::ImplementationType ImplementationType;
01349 explicit MakeableInterfaceObject ( const ImplementationType &realImp )
01350 : InterfaceType( realImp )
01351 {}
01352 };
01353 }
01354
01355 #include "geometry.hh"
01356 #include "entity.hh"
01357 #include "entitypointer.hh"
01358 #include "leveliterator.hh"
01359 #include "intersection.hh"
01360 #include "intersectioniterator.hh"
01361 #include "hierarchiciterator.hh"
01362 #include "leafiterator.hh"
01363 #include "indexidset.hh"
01364
01365 inline std::ostream& operator<< (std::ostream& s, Dune::PartitionType t)
01366 {
01367 s << Dune::PartitionName(t);
01368 return s;
01369 }
01370
01371 template<int d, int dw, class ct, class gf>
01372 inline std::ostream& operator<< (std::ostream& s,
01373 const Dune::Grid<d,dw,ct,gf> & g)
01374 {
01375 s << g.name();
01376 return s;
01377 }
01378
01379 #endif