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/capabilities.hh>
00020 #include <dune/grid/common/datahandleif.hh>
00021
00022
00023
00024 #include <dune/common/bartonnackmanifcheck.hh>
00025
00026 namespace Dune {
00027
00336 enum PartitionType {
00337 InteriorEntity=0,
00338 BorderEntity=1 ,
00339 OverlapEntity=2 ,
00340 FrontEntity=3 ,
00341 GhostEntity=4
00342 };
00343
00347 inline std::string PartitionName(PartitionType type)
00348 {
00349 switch(type) {
00350 case InteriorEntity:
00351 return "interior";
00352 case BorderEntity:
00353 return "border";
00354 case OverlapEntity:
00355 return "overlap";
00356 case FrontEntity:
00357 return "front";
00358 case GhostEntity:
00359 return "ghost";
00360 default:
00361 DUNE_THROW(NotImplemented, "name of unknown partition type requested");
00362 }
00363 }
00364
00368 enum InterfaceType {
00369 InteriorBorder_InteriorBorder_Interface=0,
00370 InteriorBorder_All_Interface=1,
00371 Overlap_OverlapFront_Interface=2,
00372 Overlap_All_Interface=3,
00373 All_All_Interface=4
00374 };
00375
00379 enum PartitionIteratorType {
00380 Interior_Partition=0,
00381 InteriorBorder_Partition=1,
00382 Overlap_Partition=2,
00383 OverlapFront_Partition=3,
00384 All_Partition=4,
00385 Ghost_Partition=5
00386 };
00387
00388
00392 enum CommunicationDirection {
00393 ForwardCommunication,
00394 BackwardCommunication
00395 };
00396
00397
00398
00399
00400
00404 class GridError : public Exception {};
00405
00406
00407 template<int mydim, int cdim, class GridImp,template<int,int,class> class GeometryImp> class Geometry;
00408
00409
00410 template<int codim, int dim, class GridImp,template<int,int,class> class EntityImp> class Entity;
00411 template<class GridImp, class EntityPointerImp> class EntityPointer;
00412 template<int codim, PartitionIteratorType pitype, class GridImp,
00413 template<int,PartitionIteratorType,class> class LevelIteratorImp> class LevelIterator;
00414 template<class GridImp, template<class> class IntersectionIteratorImp> class IntersectionIterator;
00415 template<class GridImp, template<class> class HierarchicIteratorImp> class HierarchicIterator;
00416 template<int codim, PartitionIteratorType pitype, class GridImp,
00417 template<int,PartitionIteratorType,class> class LeafIteratorImp> class LeafIterator;
00418 template<class GridImp> class GenericLeafIterator;
00419 template<class GridImp, class IndexSetIteratorImp, class IndexSetImp> class IndexSet;
00420 template<class GridImp, class IdSetImp, class IdTypeImp> class IdSet;
00421
00422
00423
00424
00425
00426
00447 template< int dim, int dimworld, class ct, class GridFamily>
00448 class Grid {
00449 typedef typename GridFamily::Traits::Grid GridImp;
00450 typedef Grid<dim,dimworld,ct,GridFamily> ThisType;
00451 public:
00452
00453
00457
00458
00460 enum {
00462 dimension=dim
00463 };
00464
00466 enum {
00468 dimensionworld=dimworld
00469 };
00471
00472
00476
00477
00484 template <int cd>
00485 struct Codim
00486 {
00488 typedef typename GridFamily::Traits::template Codim<cd>::Geometry Geometry;
00489
00491 typedef typename GridFamily::Traits::template Codim<cd>::LocalGeometry LocalGeometry;
00492
00494 typedef typename GridFamily::Traits::template Codim<cd>::Entity Entity;
00495
00497 typedef typename GridFamily::Traits::template Codim<cd>::EntityPointer EntityPointer;
00498
00500 template <PartitionIteratorType pitype>
00501 struct Partition
00502 {
00509 typedef typename GridFamily::Traits::template Codim<cd>::template Partition<pitype>::LevelIterator LevelIterator;
00516 typedef typename GridFamily::Traits::template Codim<cd>::template Partition<pitype>::LeafIterator LeafIterator;
00517 };
00518
00524 typedef typename GridFamily::Traits::LeafIntersectionIterator LeafIntersectionIterator;
00525
00531 typedef typename GridFamily::Traits::LevelIntersectionIterator LevelIntersectionIterator;
00532
00538 typedef typename GridFamily::Traits::HierarchicIterator HierarchicIterator;
00539
00542 typedef typename GridFamily::Traits::template Codim<cd>::LevelIterator LevelIterator;
00543
00546 typedef typename GridFamily::Traits::template Codim<cd>::LeafIterator LeafIterator;
00547
00552 typedef typename GridFamily::Traits::LevelIndexSet LevelIndexSet;
00553
00558 typedef typename GridFamily::Traits::LeafIndexSet LeafIndexSet;
00559
00566 typedef typename GridFamily::Traits::GlobalIdSet GlobalIdSet;
00567
00573 typedef typename GridFamily::Traits::LocalIdSet LocalIdSet;
00574
00579 typedef typename GridFamily::Traits::CollectiveCommunication CollectiveCommunication;
00580
00581 };
00582
00584 typedef ct ctype;
00586
00587
00588
00592
00593
00595 std::string name() const
00596 {
00597 CHECK_INTERFACE_IMPLEMENTATION(asImp().name());
00598 return asImp().name();
00599 }
00600
00602
00603
00607
00608
00612 int maxLevel() const
00613 {
00614 CHECK_INTERFACE_IMPLEMENTATION(asImp().maxLevel());
00615 return asImp().maxLevel();
00616 }
00617
00619 int size (int level, int codim) const
00620 {
00621 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,codim));
00622 return asImp().size(level,codim);
00623 }
00624
00626 int size (int codim) const
00627 {
00628 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(codim));
00629 return asImp().size(codim);
00630 }
00631
00633 int size (int level, GeometryType type) const
00634 {
00635 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,type));
00636 return asImp().size(level,type);
00637 }
00638
00640 int size (GeometryType type) const
00641 {
00642 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(type));
00643 return asImp().size(type);
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 template <class T>
00777 bool mark( int refCount, T & e )
00778 {
00779 IsTrue<Conversion<T, typename Grid<dim,dimworld,ct,GridFamily>::template Codim<0>::EntityPointer>::exists >::yes();
00780 return asImp().template mark<T>(refCount,e);
00781 }
00782
00789 template <class T>
00790 int getMark(T & e) const
00791 {
00792 IsTrue<Conversion<T, typename Grid<dim,dimworld,ct,GridFamily>::template Codim<0>::EntityPointer>::exists >::yes();
00793 return asImp().getMark(e);
00794 }
00795
00800 bool preAdapt ()
00801 {
00802 return asImp().preAdapt();
00803 }
00804
00819 bool adapt ()
00820 {
00821 return asImp().adapt();
00822 }
00823
00825 void postAdapt()
00826 {
00827 return asImp().postAdapt();
00828 }
00830
00831
00832
00836
00837
00839 int overlapSize (int level, int codim) const
00840 {
00841 CHECK_INTERFACE_IMPLEMENTATION(asImp().overlapSize(level,codim));
00842 return asImp().overlapSize(level,codim);
00843 }
00844
00846 int overlapSize (int codim) const
00847 {
00848 CHECK_INTERFACE_IMPLEMENTATION(asImp().overlapSize(codim));
00849 return asImp().overlapSize(codim);
00850 }
00851
00853 int ghostSize (int level, int codim) const
00854 {
00855 CHECK_INTERFACE_IMPLEMENTATION(asImp().ghostSize(level,codim));
00856 return asImp().ghostSize(level,codim);
00857 }
00858
00860 int ghostSize (int codim) const
00861 {
00862 CHECK_INTERFACE_IMPLEMENTATION(asImp().ghostSize(codim));
00863 return asImp().ghostSize(codim);
00864 }
00865
00869 template<class DataHandleImp, class DataTypeImp>
00870 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data, InterfaceType iftype, CommunicationDirection dir, int level) const
00871 {
00872 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().template communicate<DataHandleImp,DataTypeImp>(data,iftype,dir,level)));
00873 return;
00874 }
00875
00879 template<class DataHandleImp, class DataTypeImp>
00880 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data, InterfaceType iftype, CommunicationDirection dir) const
00881 {
00882 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().template communicate<DataHandleImp,DataTypeImp>(data,iftype,dir)));
00883 return;
00884 }
00885
00887 const typename Codim<0>::CollectiveCommunication& comm () const
00888 {
00889 CHECK_INTERFACE_IMPLEMENTATION(asImp().comm());
00890 return asImp().comm();
00891 }
00893
00897 bool loadBalance()
00898 {
00899 CHECK_INTERFACE_IMPLEMENTATION(asImp().loadBalance());
00900 return asImp().loadBalance();
00901 }
00902
00907 template<class DataHandle>
00908 bool loadBalance (DataHandle& data)
00909 {
00910 CHECK_INTERFACE_IMPLEMENTATION(asImp().loadBalance(data));
00911 return asImp().loadBalance(data);
00912 }
00913 private:
00915 GridImp& asImp () {return static_cast<GridImp &> (*this);}
00917 const GridImp& asImp () const {return static_cast<const GridImp &>(*this);}
00918 };
00919
00920 #undef CHECK_INTERFACE_IMPLEMENTATION
00921 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00922
00923
00924
00925
00926
00927
00928
00929
00930
00966 template<int dim,
00967 int dimworld,
00968 class ct,
00969 class GridFamily>
00970 class GridDefaultImplementation : public Grid <dim,dimworld,ct,GridFamily>
00971 {
00972 typedef typename GridFamily::Traits::Grid GridImp;
00973
00974 public:
00976 typedef typename GridFamily::Traits Traits;
00977
00978
00979
00980
01003 template <class T>
01004 bool mark( int refCount, T & e )
01005 {
01006 IsTrue<Conversion<T, typename Grid<dim,dimworld,ct,GridFamily>::template Codim<0>::EntityPointer>::exists >::yes();
01007 return false;
01008 }
01009
01017 template <class T>
01018 int getMark(T &) const
01019 {
01020 return 0;
01021 }
01022
01030 bool adapt () { return false; }
01031
01033 bool preAdapt () { return false; }
01034
01036 void postAdapt() {}
01037
01039 int ghostSize (int level, int codim) const { return 0; }
01040
01042 int overlapSize (int level, int codim) const { return 0; }
01043
01045 int ghostSize (int codim) const { return 0; }
01046
01048 int overlapSize (int codim) const { return 0; }
01049
01051 template<class DataHandleImp, class DataTypeImp>
01052 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
01053 InterfaceType iftype, CommunicationDirection dir, int level) const
01054 {
01055 }
01056
01058 template<class DataHandleImp, class DataTypeImp>
01059 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
01060 InterfaceType iftype, CommunicationDirection dir) const
01061 {
01062 }
01063
01065 bool loadBalance()
01066 {
01067 return false;
01068 }
01069
01071 template<class DataHandle>
01072 bool loadBalance (DataHandle& data)
01073 {
01074 return false;
01075 }
01076 protected:
01083 template<class T>
01084 class ReturnImplementationType : public T
01085 {
01086 public:
01088 typedef typename T::ImplementationType ImplementationType;
01089 private:
01090
01091 ReturnImplementationType(const T& t) : T(t) {}
01092 };
01093
01094 template<class T>
01095 class ReturnImplementationType<const T> : public T
01096 {
01097 public:
01098 typedef const typename T::ImplementationType ImplementationType;
01099 private:
01100
01101 ReturnImplementationType(const T& t) : T(t) {}
01102 };
01103
01105 template <class InterfaceType>
01106 typename ReturnImplementationType<InterfaceType>::ImplementationType &
01107 getRealImplementation (InterfaceType &i) const { return i.getRealImp(); }
01108
01109 protected:
01111 GridImp& asImp () {return static_cast<GridImp &>(*this);}
01112 const GridImp& asImp () const {return static_cast<const GridImp &>(*this);}
01113 };
01114
01126 template <int dim, int dimw, class GridImp,
01127 template<int,int,class> class GeometryImp,
01128 template<int,int,class> class EntityImp,
01129 template<int,class> class EntityPointerImp,
01130 template<int,PartitionIteratorType,class> class LevelIteratorImp,
01131 template<class> class LeafIntersectionIteratorImp,
01132 template<class> class LevelIntersectionIteratorImp,
01133 template<class> class HierarchicIteratorImp,
01134 template<int,PartitionIteratorType,class> class LeafIteratorImp,
01135 class LevelIndexSetImp, class LevelIndexSetTypes, class LeafIndexSetImp, class LeafIndexSetTypes,
01136 class GlobalIdSetImp, class GIDType, class LocalIdSetImp, class LIDType, class CCType>
01137 struct GridTraits
01138 {
01139 typedef GridImp Grid;
01140
01141 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorImp> LeafIntersectionIterator;
01142 typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorImp> LevelIntersectionIterator;
01143
01144 typedef Dune::HierarchicIterator<const GridImp, HierarchicIteratorImp> HierarchicIterator;
01145
01146 template <int cd>
01147 struct Codim
01148 {
01150 typedef Dune::Geometry<dim-cd, dimw, const GridImp, GeometryImp> Geometry;
01151 typedef Dune::Geometry<dim-cd, dim, const GridImp, GeometryImp> LocalGeometry;
01152
01153 typedef Dune::Entity<cd, dim, const GridImp, EntityImp> Entity;
01154
01155 typedef Dune::LevelIterator<cd,All_Partition,const GridImp,LevelIteratorImp> LevelIterator;
01156
01157 typedef Dune::LeafIterator<cd,All_Partition,const GridImp,LeafIteratorImp> LeafIterator;
01158
01159 typedef Dune::EntityPointer<const GridImp,EntityPointerImp<cd,const GridImp> > EntityPointer;
01160
01161 template <PartitionIteratorType pitype>
01162 struct Partition
01163 {
01164 typedef Dune::LevelIterator<cd,pitype,const GridImp,LevelIteratorImp> LevelIterator;
01165 typedef Dune::LeafIterator<cd,pitype,const GridImp,LeafIteratorImp> LeafIterator;
01166 };
01167
01168 };
01169
01170 typedef IndexSet<const GridImp,LevelIndexSetImp,LevelIndexSetTypes> LevelIndexSet;
01171 typedef IndexSet<const GridImp,LeafIndexSetImp,LeafIndexSetTypes> LeafIndexSet;
01172 typedef IdSet<const GridImp,GlobalIdSetImp,GIDType> GlobalIdSet;
01173 typedef IdSet<const GridImp,LocalIdSetImp,LIDType> LocalIdSet;
01174
01175 typedef CCType CollectiveCommunication;
01176 };
01177
01178
01179 namespace Capabilities
01180 {
01181
01182 template< int dim, int dimworld, typename ct, class GridFamily , int cdim >
01183 struct hasEntity< GridDefaultImplementation<dim,dimworld,ct,GridFamily>, cdim >
01184 {
01185 typedef GridDefaultImplementation<dim,dimworld,ct,GridFamily> GridType;
01186 typedef typename GridType::Traits::Grid GridImp;
01187 static const bool v = hasEntity<GridImp,cdim>::v;
01188 };
01189
01190 }
01191
01197 template <class InterfaceType>
01198 struct MakeableInterfaceObject : public InterfaceType
01199 {
01200 typedef typename InterfaceType::ImplementationType ImplementationType;
01202 MakeableInterfaceObject(const ImplementationType & realImp) : InterfaceType(realImp) {}
01203 };
01204 }
01205
01206 #include "geometry.hh"
01207 #include "entity.hh"
01208 #include "entitypointer.hh"
01209 #include "leveliterator.hh"
01210 #include "intersectioniterator.hh"
01211 #include "hierarchiciterator.hh"
01212 #include "leafiterator.hh"
01213 #include "indexidset.hh"
01214
01215 inline std::ostream& operator<< (std::ostream& s, Dune::PartitionType t)
01216 {
01217 s << Dune::PartitionName(t);
01218 return s;
01219 }
01220
01221 template<int d, int dw, class ct, class gf>
01222 inline std::ostream& operator<< (std::ostream& s,
01223 const Dune::Grid<d,dw,ct,gf> & g)
01224 {
01225 s << g.name();
01226 return s;
01227 }
01228
01229 #endif