dune-grid  2.2.1
common/grid.hh
Go to the documentation of this file.
1 #ifndef DUNE_GRID_HH
2 #define DUNE_GRID_HH
3 
7 // system includes
8 #include <iostream>
9 #include <string>
10 
11 // dune-common includes
12 #include <dune/common/fvector.hh>
13 #include <dune/common/typetraits.hh>
14 
15 // dune-geometry includes
16 #include <dune/geometry/type.hh>
17 
18 // local includes
25 
26 // inlcude this file after all other, because other files might undef the
27 // macros that are defined in that file
28 #include <dune/common/bartonnackmanifcheck.hh>
29 
30 namespace Dune {
31 
342 // Forward Declarations
343 // --------------------
344 
345 template<int mydim, int cdim, class GridImp,template<int,int,class> class GeometryImp> class Geometry;
346 template< int mydim, int cdim, class GridImp > class GlobalGeometryReference;
347 template< int mydim, int cdim, class GridImp > class LocalGeometryReference;
348 // dim is necessary because Entity will be specialized for codim==0 _and_ codim==dim
349 // EntityImp gets GridImp as 3rd template parameter to distinguish between const and mutable grid
350 template<int codim, int dim, class GridImp,template<int,int,class> class EntityImp> class Entity;
351 template<class GridImp, class EntityPointerImp> class EntityPointer;
352 template< int codim, class Grid, class IteratorImp > class EntityIterator;
353 template<class GridImp, template<class> class IntersectionImp> class Intersection;
354 template<class GridImp, template<class> class IntersectionIteratorImp, template<class> class IntersectionImp> class IntersectionIterator;
355 template<class GridImp> class GenericLeafIterator;
356 template<class GridImp, class IndexSetImp, class IndexTypeImp=unsigned int> class IndexSet;
357 template<class GridImp, class IdSetImp, class IdTypeImp> class IdSet;
358 
359 
360 //************************************************************************
361 // G R I D
362 //************************************************************************
363 
382 template< int dim, int dimworld, class ct, class GridFamily>
383 class Grid {
384  typedef typename GridFamily::Traits::Grid GridImp;
386 public:
387 
388  //===========================================================
392  //===========================================================
393 
395  enum {
398  };
399 
401  enum {
403  dimensionworld=dimworld
404  };
406 
407  //===========================================================
411  //===========================================================
412 
414  template <PartitionIteratorType pitype>
415  struct Partition
416  {
417  typedef typename GridFamily::Traits::template Partition<pitype>::LevelGridView
419  typedef typename GridFamily::Traits::template Partition<pitype>::LeafGridView
421  };
425 
426 
431  template <int cd>
432  struct Codim
433  {
435  typedef typename GridFamily::Traits::template Codim<cd>::Geometry Geometry;
436 
438  typedef typename GridFamily::Traits::template Codim<cd>::LocalGeometry LocalGeometry;
439 
441  typedef typename GridFamily::Traits::template Codim<cd>::Entity Entity;
442 
444  typedef typename GridFamily::Traits::template Codim<cd>::EntityPointer EntityPointer;
445 
447  typedef typename GridFamily::Traits::template Codim<cd>::EntitySeed EntitySeed;
448 
450  template <PartitionIteratorType pitype>
451  struct Partition
452  {
459  typedef typename GridFamily::Traits::template Codim<cd>::template Partition<pitype>::LevelIterator LevelIterator;
466  typedef typename GridFamily::Traits::template Codim<cd>::template Partition<pitype>::LeafIterator LeafIterator;
467  };
468 
471  typedef typename GridFamily::Traits::template Codim<cd>::LevelIterator LevelIterator;
472 
475  typedef typename GridFamily::Traits::template Codim<cd>::LeafIterator LeafIterator;
476  };
477 
481  typedef typename GridFamily::Traits::LeafIntersection LeafIntersection;
482 
486  typedef typename GridFamily::Traits::LevelIntersection LevelIntersection;
487 
493  typedef typename GridFamily::Traits::LeafIntersectionIterator LeafIntersectionIterator;
494 
500  typedef typename GridFamily::Traits::LevelIntersectionIterator LevelIntersectionIterator;
501 
507  typedef typename GridFamily::Traits::HierarchicIterator HierarchicIterator;
508 
513  typedef typename GridFamily::Traits::LevelIndexSet LevelIndexSet;
514 
519  typedef typename GridFamily::Traits::LeafIndexSet LeafIndexSet;
520 
527  typedef typename GridFamily::Traits::GlobalIdSet GlobalIdSet;
528 
534  typedef typename GridFamily::Traits::LocalIdSet LocalIdSet;
535 
540  typedef typename GridFamily::Traits::CollectiveCommunication CollectiveCommunication;
541 
543  typedef ct ctype;
545 
546 
547  //===========================================================
551  //===========================================================
552 
556  int maxLevel() const
557  {
558  CHECK_INTERFACE_IMPLEMENTATION(asImp().maxLevel());
559  return asImp().maxLevel();
560  }
561 
563  int size (int level, int codim) const
564  {
565  CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,codim));
566  return asImp().size(level,codim);
567  }
568 
570  int size (int codim) const
571  {
572  CHECK_INTERFACE_IMPLEMENTATION(asImp().size(codim));
573  return asImp().size(codim);
574  }
575 
577  int size (int level, GeometryType type) const
578  {
579  CHECK_INTERFACE_IMPLEMENTATION(asImp().size(level,type));
580  return asImp().size(level,type);
581  }
582 
584  int size (GeometryType type) const
585  {
586  CHECK_INTERFACE_IMPLEMENTATION(asImp().size(type));
587  return asImp().size(type);
588  }
590 
591 
596  size_t numBoundarySegments () const
597  {
598  CHECK_INTERFACE_IMPLEMENTATION( asImp().numBoundarySegments());
599  return asImp().numBoundarySegments();
600  }
601 
602  //===========================================================
606  //===========================================================
607 
609  template<PartitionIteratorType pitype>
610  typename Partition<pitype>::LevelGridView levelView(int level) const {
611  CHECK_INTERFACE_IMPLEMENTATION((asImp().template levelView<pitype>(level)));
612  return asImp().template levelView<pitype>(level);
613  }
614 
616  template<PartitionIteratorType pitype>
618  CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafView<pitype>()));
619  return asImp().template leafView<pitype>();
620  }
621 
623  LevelGridView levelView(int level) const {
624  CHECK_INTERFACE_IMPLEMENTATION((asImp().levelView(level)));
625  return asImp().levelView(level);
626  }
627 
630  CHECK_INTERFACE_IMPLEMENTATION((asImp().leafView()));
631  return asImp().leafView();
632  }
633 
635 
636 
637  //===========================================================
641  //===========================================================
642 
644  template<int cd, PartitionIteratorType pitype>
646  {
647  CHECK_INTERFACE_IMPLEMENTATION((asImp().template lbegin<cd,pitype>(level)));
648  return asImp().template lbegin<cd,pitype>(level);
649  }
650 
652  template<int cd, PartitionIteratorType pitype>
654  {
655  CHECK_INTERFACE_IMPLEMENTATION((asImp().template lend<cd,pitype>(level)));
656  return asImp().template lend<cd,pitype>(level);
657  }
658 
660  template<int cd>
662  {
663  CHECK_INTERFACE_IMPLEMENTATION((asImp().template lbegin<cd>(level)));
664  return asImp().template lbegin<cd>(level);
665  }
666 
668  template<int cd>
670  {
671  CHECK_INTERFACE_IMPLEMENTATION((asImp().template lend<cd>(level)));
672  return asImp().template lend<cd>(level);
673  }
674 
676  template<int cd, PartitionIteratorType pitype>
678  {
679  CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafbegin<cd,pitype>()));
680  return asImp().template leafbegin<cd,pitype>();
681  }
682 
684  template<int cd, PartitionIteratorType pitype>
686  {
687  CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafend<cd,pitype>()));
688  return asImp().template leafend<cd,pitype>();
689  }
690 
692  template<int cd>
694  {
695  CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafbegin<cd,All_Partition>()));
696  return asImp().template leafbegin<cd,All_Partition>();
697  }
698 
700  template<int cd>
702  {
703  CHECK_INTERFACE_IMPLEMENTATION((asImp().template leafend<cd,All_Partition>()));
704  return asImp().template leafend<cd,All_Partition>();
705  }
707 
708 
709  //===========================================================
713  //===========================================================
714 
716  const GlobalIdSet &globalIdSet () const
717  {
718  CHECK_INTERFACE_IMPLEMENTATION(asImp().globalIdSet());
719  return asImp().globalIdSet();
720  }
721 
723  const LocalIdSet &localIdSet () const
724  {
725  CHECK_INTERFACE_IMPLEMENTATION(asImp().localIdSet());
726  return asImp().localIdSet();
727  }
728 
730  const LevelIndexSet &levelIndexSet ( int level ) const
731  {
732  CHECK_INTERFACE_IMPLEMENTATION(asImp().levelIndexSet(level));
733  return asImp().levelIndexSet(level);
734  }
735 
737  const LeafIndexSet &leafIndexSet () const
738  {
739  CHECK_INTERFACE_IMPLEMENTATION(asImp().leafIndexSet());
740  return asImp().leafIndexSet();
741  }
743 
744 
745  //===========================================================
749  //===========================================================
750 
756  void globalRefine (int refCount)
757  {
758  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(asImp().globalRefine(refCount));
759  return;
760  }
761 
769  bool mark( int refCount, const typename Codim<0>::Entity & e )
770  {
771  return asImp().mark(refCount,e);
772  }
773 
780  int getMark(const typename Codim<0>::Entity & e) const
781  {
782  return asImp().getMark(e);
783  }
784 
791  bool preAdapt ()
792  {
793  return asImp().preAdapt();
794  }
795 
810  bool adapt ()
811  {
812  return asImp().adapt();
813  }
814 
819  void postAdapt()
820  {
821  return asImp().postAdapt();
822  }
824 
825 
826  //===========================================================
830  //===========================================================
831 
833  int overlapSize (int level, int codim) const
834  {
835  CHECK_INTERFACE_IMPLEMENTATION(asImp().overlapSize(level,codim));
836  return asImp().overlapSize(level,codim);
837  }
838 
840  int overlapSize (int codim) const
841  {
842  CHECK_INTERFACE_IMPLEMENTATION(asImp().overlapSize(codim));
843  return asImp().overlapSize(codim);
844  }
845 
847  int ghostSize (int level, int codim) const
848  {
849  CHECK_INTERFACE_IMPLEMENTATION(asImp().ghostSize(level,codim));
850  return asImp().ghostSize(level,codim);
851  }
852 
854  int ghostSize (int codim) const
855  {
856  CHECK_INTERFACE_IMPLEMENTATION(asImp().ghostSize(codim));
857  return asImp().ghostSize(codim);
858  }
859 
863  template<class DataHandleImp, class DataTypeImp>
865  {
866  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().template communicate<DataHandleImp,DataTypeImp>(data,iftype,dir,level)));
867  return;
868  }
869 
873  template<class DataHandleImp, class DataTypeImp>
875  {
876  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().template communicate<DataHandleImp,DataTypeImp>(data,iftype,dir)));
877  return;
878  }
879 
882  {
883  CHECK_INTERFACE_IMPLEMENTATION(asImp().comm());
884  return asImp().comm();
885  }
887 
891  bool loadBalance()
892  {
893  CHECK_INTERFACE_IMPLEMENTATION(asImp().loadBalance());
894  return asImp().loadBalance();
895  }
896 
901  template<class DataHandle>
902  bool loadBalance (DataHandle& data)
903  {
904  CHECK_INTERFACE_IMPLEMENTATION(asImp().loadBalance(data));
905  return asImp().loadBalance(data);
906  }
907 
909  template < class EntitySeed >
910  typename Codim< EntitySeed :: codimension > :: EntityPointer
911  entityPointer( const EntitySeed& seed ) const
912  {
913  CHECK_INTERFACE_IMPLEMENTATION( asImp().entityPointer( seed ) );
914  return asImp().entityPointer( seed );
915  }
916 protected:
918  GridImp& asImp () {return static_cast<GridImp &> (*this);}
920  const GridImp& asImp () const {return static_cast<const GridImp &>(*this);}
921 };
922 
923 #undef CHECK_INTERFACE_IMPLEMENTATION
924 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
925 
926 
965 template<int dim,
966  int dimworld,
967  class ct,
968  class GridFamily>
969 class GridDefaultImplementation : public Grid <dim,dimworld,ct,GridFamily>
970 {
971  typedef typename GridFamily::Traits::Grid GridImp;
972 
973 public:
979  typedef typename GridFamily::Traits Traits;
980 
982  template<PartitionIteratorType pitype>
983  typename Traits::template Partition<pitype>::LevelGridView
984  levelView(int level) const {
985  typedef typename Traits::template Partition<pitype>::LevelGridView View;
986  typedef typename View::GridViewImp ViewImp;
987  return View(ViewImp(asImp(),level));
988  }
989 
991  template<PartitionIteratorType pitype>
992  typename Traits::template Partition<pitype>::LeafGridView leafView() const {
993  typedef typename Traits::template Partition<pitype>::LeafGridView View;
994  typedef typename View::GridViewImp ViewImp;
995  return View(ViewImp(asImp()));
996  }
997 
999  typename Traits::template Partition<All_Partition>::LevelGridView
1000  levelView(int level) const {
1001  typedef typename Traits::template Partition<All_Partition>::LevelGridView View;
1002  typedef typename View::GridViewImp ViewImp;
1003  return View(ViewImp(asImp(),level));
1004  }
1005 
1007  typename Traits::template Partition<All_Partition>::LeafGridView
1008  leafView() const {
1009  typedef typename Traits::template Partition<All_Partition>::LeafGridView View;
1010  typedef typename View::GridViewImp ViewImp;
1011  return View(ViewImp(asImp()));
1012  }
1013 
1014  //***************************************************************
1015  // Interface for Adaptation
1016  //***************************************************************
1017 
1040  bool mark( int refCount, const typename Traits :: template Codim<0>::Entity & e )
1041  {
1042  return false;
1043  }
1044 
1052  int getMark ( const typename Traits::template Codim< 0 >::Entity &e ) const
1053  {
1054  return 0;
1055  }
1056 
1064  bool adapt () { return false; }
1065 
1067  bool preAdapt () { return false; }
1068 
1070  void postAdapt() {}
1071 
1073  int ghostSize (int level, int codim) const { return 0; }
1074 
1076  int overlapSize (int level, int codim) const { return 0; }
1077 
1079  int ghostSize (int codim) const { return 0; }
1080 
1082  int overlapSize (int codim) const { return 0; }
1083 
1085  template<class DataHandleImp, class DataTypeImp>
1087  InterfaceType iftype, CommunicationDirection dir, int level) const
1088  {
1089  }
1090 
1092  template<class DataHandleImp, class DataTypeImp>
1094  InterfaceType iftype, CommunicationDirection dir) const
1095  {
1096  }
1097 
1099  bool loadBalance()
1100  {
1101  return false;
1102  }
1103 
1105  template<class DataHandle>
1106  bool loadBalance (DataHandle& data)
1107  {
1108  return false;
1109  }
1110 
1111 protected:
1118  template<class T>
1120  : public T // implement friendship via subclassing
1121  {
1122  public:
1124  typedef typename T::Implementation ImplementationType;
1125  private:
1126  // constructor in only need to compile
1127  ReturnImplementationType(const T& t) : T(t) {}
1128  };
1129 
1130  template<class T>
1132  : public T // implement friendship via subclassing
1133  {
1134  public:
1135  typedef const typename T::Implementation ImplementationType;
1136  private:
1137  // constructor in only need to compile
1138  ReturnImplementationType(const T& t) : T(t) {}
1139  };
1140 
1142  template <class InterfaceType>
1143  static typename ReturnImplementationType<InterfaceType>::ImplementationType &
1144  getRealImplementation (InterfaceType &i) { return i.impl(); }
1145 
1146 protected:
1148 };
1149 
1163 template <int dim, int dimw, class GridImp,
1164  template<int,int,class> class GeometryImp,
1165  template<int,int,class> class EntityImp,
1166  template<int,class> class EntityPointerImp,
1167  template<int,PartitionIteratorType,class> class LevelIteratorImp,
1168  template<class> class LeafIntersectionImp,
1169  template<class> class LevelIntersectionImp,
1170  template<class> class LeafIntersectionIteratorImp,
1171  template<class> class LevelIntersectionIteratorImp,
1172  template<class> class HierarchicIteratorImp,
1173  template<int,PartitionIteratorType,class> class LeafIteratorImp,
1174  class LevelIndexSetImp, class LeafIndexSetImp,
1175  class GlobalIdSetImp, class GIDType, class LocalIdSetImp, class LIDType, class CCType,
1176  template<class,PartitionIteratorType> class LevelGridViewTraits = DefaultLevelGridViewTraits,
1177  template<class,PartitionIteratorType> class LeafGridViewTraits = DefaultLeafGridViewTraits,
1178  template<int,class> class EntitySeedImp = EntityPointerImp,
1179  template<int,int,class> class LocalGeometryImp = GeometryImp
1180  >
1182 {
1184  typedef GridImp Grid;
1185 
1194 
1197 
1202  template <int cd>
1203  struct Codim
1204  {
1205  protected:
1206  // class to extract whether we are using the default seed type or not
1207  template <class Seed, class EPImpl >
1209  {
1210  typedef Seed EntitySeed ;
1211  };
1212 
1213  // the default seed type is entity pointer until its implemented
1214  template <class EPImpl>
1215  struct SeedDefault< EPImpl, EPImpl >
1216  {
1218  };
1219 
1220  public:
1221  typedef GeometryImp<dim-cd, dimw, const GridImp> GeometryImpl;
1222  typedef LocalGeometryImp<dim-cd, dim, const GridImp> LocalGeometryImpl;
1224 
1225  typedef Dune::Geometry<dim-cd, dimw, const GridImp, GeometryImp> Geometry;
1227  typedef Dune::Geometry<dim-cd, dim, const GridImp, LocalGeometryImp> LocalGeometry;
1229  // we could - if needed - introduce another struct for dimglobal of Geometry
1231 
1234 
1236  typedef typename SeedDefault< EntitySeedImp<cd, const GridImp>, EntityPointerImp<cd,const GridImp> > :: EntitySeed EntitySeed;
1237 
1242  template <PartitionIteratorType pitype>
1243  struct Partition
1244  {
1249  };
1250 
1253 
1256 
1257  private:
1258  friend class Dune::Entity<cd, dim, const GridImp, EntityImp>;
1259  typedef EntityPointerImp<cd,const GridImp> EntityPointerImpl;
1260  };
1261 
1266  template <PartitionIteratorType pitype>
1267  struct Partition
1268  {
1272 
1276  };
1277 
1286 
1288  typedef CCType CollectiveCommunication;
1289 };
1290 
1291  // define of capabilties for the interface class
1292  namespace Capabilities
1293  {
1294  // capabilities for the interface class depend on the implementation
1295  template< int dim, int dimworld, typename ct, class GridFamily , int cdim >
1296  struct hasEntity< GridDefaultImplementation<dim,dimworld,ct,GridFamily>, cdim >
1297  {
1299  typedef typename GridType::Traits::Grid GridImp;
1300  static const bool v = hasEntity<GridImp,cdim>::v;
1301  };
1302 
1303  } // end namespace Capabilities
1304 
1310  template <class InterfaceType>
1311  struct MakeableInterfaceObject : public InterfaceType
1312  {
1313  typedef typename InterfaceType::Implementation ImplementationType;
1315  explicit MakeableInterfaceObject ( const ImplementationType &realImp )
1316  : InterfaceType( realImp )
1317  {}
1318  };
1319 }
1320 
1321 #include "geometry.hh"
1322 #include "entity.hh"
1323 #include "entitypointer.hh"
1324 #include "intersection.hh"
1325 #include "intersectioniterator.hh"
1326 #include "entityiterator.hh"
1327 #include "indexidset.hh"
1328 
1329 #endif // #ifndef DUNE_GRID_HH