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;
00526 typedef typename GridFamily::Traits::LeafIntersectionIterator LeafIntersection;
00527
00533 typedef typename GridFamily::Traits::LevelIntersectionIterator LevelIntersectionIterator;
00535 typedef typename GridFamily::Traits::LevelIntersectionIterator LevelIntersection;
00536
00542 typedef typename GridFamily::Traits::HierarchicIterator HierarchicIterator;
00543
00546 typedef typename GridFamily::Traits::template Codim<cd>::LevelIterator LevelIterator;
00547
00550 typedef typename GridFamily::Traits::template Codim<cd>::LeafIterator LeafIterator;
00551
00556 typedef typename GridFamily::Traits::LevelIndexSet LevelIndexSet;
00557
00562 typedef typename GridFamily::Traits::LeafIndexSet LeafIndexSet;
00563
00570 typedef typename GridFamily::Traits::GlobalIdSet GlobalIdSet;
00571
00577 typedef typename GridFamily::Traits::LocalIdSet LocalIdSet;
00578
00583 typedef typename GridFamily::Traits::CollectiveCommunication CollectiveCommunication;
00584
00585 };
00586
00588 typedef ct ctype;
00590
00591
00592
00596
00597
00599 std::string name() const
00600 {
00601 CHECK_INTERFACE_IMPLEMENTATION(asImp().name());
00602 return asImp().name();
00603 }
00604
00606
00607
00611
00612
00616 int maxLevel() const
00617 {
00618 CHECK_INTERFACE_IMPLEMENTATION(asImp().maxLevel());
00619 return asImp().maxLevel();
00620 }
00621
00623 int size (int level, int codim) const
00624 {
00625 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,codim));
00626 return asImp().size(level,codim);
00627 }
00628
00630 int size (int codim) const
00631 {
00632 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(codim));
00633 return asImp().size(codim);
00634 }
00635
00637 int size (int level, GeometryType type) const
00638 {
00639 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,type));
00640 return asImp().size(level,type);
00641 }
00642
00644 int size (GeometryType type) const
00645 {
00646 CHECK_INTERFACE_IMPLEMENTATION(asImp().size(type));
00647 return asImp().size(type);
00648 }
00650
00651
00652
00656
00657
00659 template<int cd, PartitionIteratorType pitype>
00660 typename Codim<cd>::template Partition<pitype>::LevelIterator lbegin (int level) const
00661 {
00662 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lbegin<cd,pitype>(level)));
00663 return asImp().template lbegin<cd,pitype>(level);
00664 }
00665
00667 template<int cd, PartitionIteratorType pitype>
00668 typename Codim<cd>::template Partition<pitype>::LevelIterator lend (int level) const
00669 {
00670 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lend<cd,pitype>(level)));
00671 return asImp().template lend<cd,pitype>(level);
00672 }
00673
00675 template<int cd>
00676 typename Codim<cd>::template Partition<All_Partition>::LevelIterator lbegin (int level) const
00677 {
00678 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lbegin<cd>(level)));
00679 return asImp().template lbegin<cd>(level);
00680 }
00681
00683 template<int cd>
00684 typename Codim<cd>::template Partition<All_Partition>::LevelIterator lend (int level) const
00685 {
00686 CHECK_INTERFACE_IMPLEMENTATION((asImp().template lend<cd>(level)));
00687 return asImp().template lend<cd>(level);
00688 }
00689
00691 template<int cd, PartitionIteratorType pitype>
00692 typename Codim<cd>::template Partition<pitype>::LeafIterator leafbegin () const
00693 {
00694 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafbegin<cd,pitype>()));
00695 return asImp().template leafbegin<cd,pitype>();
00696 }
00697
00699 template<int cd, PartitionIteratorType pitype>
00700 typename Codim<cd>::template Partition<pitype>::LeafIterator leafend () const
00701 {
00702 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafend<cd,pitype>()));
00703 return asImp().template leafend<cd,pitype>();
00704 }
00705
00707 template<int cd>
00708 typename Codim<cd>::template Partition<All_Partition>::LeafIterator leafbegin () const
00709 {
00710 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafbegin<cd,All_Partition>()));
00711 return asImp().template leafbegin<cd,All_Partition>();
00712 }
00713
00715 template<int cd>
00716 typename Codim<cd>::template Partition<All_Partition>::LeafIterator leafend () const
00717 {
00718 CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafend<cd,All_Partition>()));
00719 return asImp().template leafend<cd,All_Partition>();
00720 }
00722
00723
00724
00728
00729
00731 const typename Codim<0>::GlobalIdSet& globalIdSet() const
00732 {
00733 CHECK_INTERFACE_IMPLEMENTATION(asImp().globalIdSet());
00734 return asImp().globalIdSet();
00735 }
00736
00738 const typename Codim<0>::LocalIdSet& localIdSet() const
00739 {
00740 CHECK_INTERFACE_IMPLEMENTATION(asImp().localIdSet());
00741 return asImp().localIdSet();
00742 }
00743
00745 const typename Codim<0>::LevelIndexSet& levelIndexSet(int level) const
00746 {
00747 CHECK_INTERFACE_IMPLEMENTATION(asImp().levelIndexSet(level));
00748 return asImp().levelIndexSet(level);
00749 }
00750
00752 const typename Codim<0>::LeafIndexSet& leafIndexSet() const
00753 {
00754 CHECK_INTERFACE_IMPLEMENTATION(asImp().leafIndexSet());
00755 return asImp().leafIndexSet();
00756 }
00758
00759
00760
00764
00765
00767 void globalRefine (int refCount)
00768 {
00769 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(asImp().globalRefine(refCount));
00770 return;
00771 }
00772
00780 bool mark( int refCount, const typename Codim<0>::EntityPointer & e )
00781 {
00782 return asImp().mark(refCount,e);
00783 }
00784
00791 int getMark(const typename Codim<0>::EntityPointer & e) const
00792 {
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
00969 template<int dim,
00970 int dimworld,
00971 class ct,
00972 class GridFamily>
00973 class GridDefaultImplementation : public Grid <dim,dimworld,ct,GridFamily>
00974 {
00975 typedef typename GridFamily::Traits::Grid GridImp;
00976
00977 public:
00979 typedef typename GridFamily::Traits Traits;
00980
00981
00982
00983
01006 bool mark( int refCount, const typename Traits :: template Codim<0>::EntityPointer & e )
01007 {
01008 return false;
01009 }
01010
01018 int getMark(const typename Traits :: template Codim<0>::EntityPointer &) 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, LeafIntersectionIteratorImp> LeafIntersection;
01143 typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorImp> LevelIntersectionIterator;
01144 typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorImp> LevelIntersection;
01145
01146 typedef Dune::HierarchicIterator<const GridImp, HierarchicIteratorImp> HierarchicIterator;
01147
01148 template <int cd>
01149 struct Codim
01150 {
01152 typedef Dune::Geometry<dim-cd, dimw, const GridImp, GeometryImp> Geometry;
01153 typedef Dune::Geometry<dim-cd, dim, const GridImp, GeometryImp> LocalGeometry;
01154
01155 typedef Dune::Entity<cd, dim, const GridImp, EntityImp> Entity;
01156
01157 typedef Dune::LevelIterator<cd,All_Partition,const GridImp,LevelIteratorImp> LevelIterator;
01158
01159 typedef Dune::LeafIterator<cd,All_Partition,const GridImp,LeafIteratorImp> LeafIterator;
01160
01161 typedef Dune::EntityPointer<const GridImp,EntityPointerImp<cd,const GridImp> > EntityPointer;
01162
01163 template <PartitionIteratorType pitype>
01164 struct Partition
01165 {
01166 typedef Dune::LevelIterator<cd,pitype,const GridImp,LevelIteratorImp> LevelIterator;
01167 typedef Dune::LeafIterator<cd,pitype,const GridImp,LeafIteratorImp> LeafIterator;
01168 };
01169
01170 };
01171
01172 typedef IndexSet<const GridImp,LevelIndexSetImp,LevelIndexSetTypes> LevelIndexSet;
01173 typedef IndexSet<const GridImp,LeafIndexSetImp,LeafIndexSetTypes> LeafIndexSet;
01174 typedef IdSet<const GridImp,GlobalIdSetImp,GIDType> GlobalIdSet;
01175 typedef IdSet<const GridImp,LocalIdSetImp,LIDType> LocalIdSet;
01176
01177 typedef CCType CollectiveCommunication;
01178 };
01179
01180
01181 namespace Capabilities
01182 {
01183
01184 template< int dim, int dimworld, typename ct, class GridFamily , int cdim >
01185 struct hasEntity< GridDefaultImplementation<dim,dimworld,ct,GridFamily>, cdim >
01186 {
01187 typedef GridDefaultImplementation<dim,dimworld,ct,GridFamily> GridType;
01188 typedef typename GridType::Traits::Grid GridImp;
01189 static const bool v = hasEntity<GridImp,cdim>::v;
01190 };
01191
01192 }
01193
01199 template <class InterfaceType>
01200 struct MakeableInterfaceObject : public InterfaceType
01201 {
01202 typedef typename InterfaceType::ImplementationType ImplementationType;
01204 MakeableInterfaceObject(const ImplementationType & realImp) : InterfaceType(realImp) {}
01205 };
01206 }
01207
01208 #include "geometry.hh"
01209 #include "entity.hh"
01210 #include "entitypointer.hh"
01211 #include "leveliterator.hh"
01212 #include "intersectioniterator.hh"
01213 #include "hierarchiciterator.hh"
01214 #include "leafiterator.hh"
01215 #include "indexidset.hh"
01216
01217 inline std::ostream& operator<< (std::ostream& s, Dune::PartitionType t)
01218 {
01219 s << Dune::PartitionName(t);
01220 return s;
01221 }
01222
01223 template<int d, int dw, class ct, class gf>
01224 inline std::ostream& operator<< (std::ostream& s,
01225 const Dune::Grid<d,dw,ct,gf> & g)
01226 {
01227 s << g.name();
01228 return s;
01229 }
01230
01231 #endif