dune-grid  2.4.1
geometrygrid/grid.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOGRID_GRID_HH
4 #define DUNE_GEOGRID_GRID_HH
5 
6 #include <dune/common/nullptr.hh>
7 #include <dune/common/deprecated.hh>
8 
10 
17 
18 namespace Dune
19 {
20 
21  // DefaultCoordFunction
22  // --------------------
23 
24  template< class HostGrid >
26  : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
27  {};
28 
29 
30 
31  // GeometryGrid
32  // ------------
33 
74  template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
75  class GeometryGrid
78  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
79  GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
80  public GeoGrid::ExportParams< HostGrid, CoordFunction >,
81  public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
83  {
85 
87  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
89  Base;
90 
91  friend class GeoGrid::HierarchicIterator< const Grid >;
92 
93  template< int, class, bool > friend class GeoGrid::EntityBase;
94  template< int, int, class > friend class GeoGrid::Geometry;
95  template< class, class, class, PartitionIteratorType > friend class GeoGrid::GridView;
96  template< class, class > friend class GeoGrid::Intersection;
97  template< class, class > friend class GeoGrid::IntersectionIterator;
98  template< class, class > friend class GeoGrid::IdSet;
99  template< class, class > friend class GeoGrid::IndexSet;
100  template< class > friend struct HostGridAccess;
101 
102  template< class, class > friend class GeoGrid::CommDataHandle;
103 
104  public:
112  typedef typename GridFamily::Traits Traits;
114 
121  template< int codim >
122  struct Codim;
123 
129  typedef typename Traits::HierarchicIterator HierarchicIterator;
132  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
134  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
135 
142  template< PartitionIteratorType pitype >
143  struct Partition
144  {
145  typedef typename GridFamily::Traits::template Partition< pitype >::LevelGridView
147  typedef typename GridFamily::Traits::template Partition< pitype >::LeafGridView
149  };
150 
154 
169  typedef typename Traits::LeafIndexSet LeafIndexSet;
170 
179  typedef typename Traits::LevelIndexSet LevelIndexSet;
180 
191  typedef typename Traits::GlobalIdSet GlobalIdSet;
192 
208  typedef typename Traits::LocalIdSet LocalIdSet;
209 
215  typedef typename Traits::ctype ctype;
217 
219  typedef typename Traits::CollectiveCommunication CollectiveCommunication;
220 
235  GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
236  : hostGrid_( &hostGrid ),
237  coordFunction_( coordFunction ),
238  removeHostGrid_( false ),
239  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
240  storageAllocator_( allocator )
241  {}
242 
252  GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator = Allocator() )
253  : hostGrid_( hostGrid ),
254  coordFunction_( *coordFunction ),
255  removeHostGrid_( true ),
256  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
257  storageAllocator_( allocator )
258  {}
259 
263  {
264  for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
265  {
266  if( levelIndexSets_[ i ] )
267  delete( levelIndexSets_[ i ] );
268  }
269 
270  if( removeHostGrid_ )
271  {
272  delete &coordFunction_;
273  delete hostGrid_;
274  }
275  }
276 
289  int maxLevel () const
290  {
291  return hostGrid().maxLevel();
292  }
293 
302  int size ( int level, int codim ) const
303  {
304  return levelGridView( level ).size( codim );
305  }
306 
313  int size ( int codim ) const
314  {
315  return leafGridView().size( codim );
316  }
317 
326  int size ( int level, GeometryType type ) const
327  {
328  return levelGridView( level ).size( type );
329  }
330 
335  int size ( GeometryType type ) const
336  {
337  return leafGridView().size( type );
338  }
339 
344  size_t numBoundarySegments () const
345  {
346  return hostGrid().numBoundarySegments( );
347  }
350  const GlobalIdSet &globalIdSet () const
351  {
352  if( !globalIdSet_ )
353  globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
354  assert( globalIdSet_ );
355  return globalIdSet_;
356  }
357 
358  const LocalIdSet &localIdSet () const
359  {
360  if( !localIdSet_ )
361  localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
362  assert( localIdSet_ );
363  return localIdSet_;
364  }
365 
366  const LevelIndexSet &levelIndexSet ( int level ) const
367  {
368  assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
369  if( (level < 0) || (level > maxLevel()) )
370  {
371  DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
372  << " requested." );
373  }
374 
375  LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
376  if( !levelIndexSet )
377  levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
378  assert( levelIndexSet );
379  return *levelIndexSet;
380  }
381 
382  const LeafIndexSet &leafIndexSet () const
383  {
384  if( !leafIndexSet_ )
385  leafIndexSet_ = LeafIndexSet( hostGrid().leafIndexSet() );
386  assert( leafIndexSet_ );
387  return leafIndexSet_;
388  }
389 
390  void globalRefine ( int refCount )
391  {
392  hostGrid().globalRefine( refCount );
393  update();
394  }
395 
396  bool mark ( int refCount, const typename Codim< 0 >::Entity &entity )
397  {
398  return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
399  }
400 
401  int getMark ( const typename Codim< 0 >::Entity &entity ) const
402  {
403  return hostGrid().getMark( getHostEntity< 0 >( entity ) );
404  }
405 
406  bool preAdapt ()
407  {
408  return hostGrid().preAdapt();
409  }
410 
411  bool adapt ()
412  {
413  bool ret = hostGrid().adapt();
414  update();
415  return ret;
416  }
417 
418  void postAdapt ()
419  {
420  hostGrid().postAdapt();
421  }
422 
430  int overlapSize ( int codim ) const
431  {
432  return leafGridView().overlapSize( codim );
433  }
434 
439  int ghostSize( int codim ) const
440  {
441  return leafGridView().ghostSize( codim );
442  }
443 
449  int overlapSize ( int level, int codim ) const
450  {
451  return levelGridView( level ).overlapSize( codim );
452  }
453 
459  int ghostSize ( int level, int codim ) const
460  {
461  return levelGridView( level ).ghostSize( codim );
462  }
463 
477  template< class DataHandle, class Data >
479  InterfaceType interface,
480  CommunicationDirection direction,
481  int level ) const
482  {
483  levelGridView( level ).communicate( dataHandle, interface, direction );
484  }
485 
498  template< class DataHandle, class Data >
500  InterfaceType interface,
501  CommunicationDirection direction ) const
502  {
503  leafGridView().communicate( dataHandle, interface, direction );
504  }
505 
514  const CollectiveCommunication &comm () const
515  {
516  return hostGrid().comm();
517  }
518 
519 #if 0
520  // data handle interface different between geo and interface
521 
531  bool loadBalance ()
532  {
533  const bool gridChanged= hostGrid().loadBalance();
534  if( gridChanged )
535  update();
536  return gridChanged;
537  }
538 
554  template< class DataHandle, class Data >
555  bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
556  {
557  typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
558  typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
559 
560  WrappedDataHandle wrappedDataHandle( *this, datahandle );
561  const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
562  if( gridChanged )
563  update();
564  return gridChanged;
565  }
566 #endif
567 
569  template< class EntitySeed >
570  typename Traits::template Codim< EntitySeed::codimension >::EntityPointer
571  DUNE_DEPRECATED_MSG("entityPointer() is deprecated and will be removed after the release of dune-grid 2.4. Use entity() instead to directly obtain an Entity object.")
572  entityPointer ( const EntitySeed &seed ) const
573  {
574  typedef typename Traits::template Codim< EntitySeed::codimension >::Entity Entity;
575  return DefaultEntityPointer< Entity >( entity( seed ) );
576  }
577 
579  template< class EntitySeed >
580  typename Traits::template Codim< EntitySeed::codimension >::Entity
581  entity ( const EntitySeed &seed ) const
582  {
583  typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
584  return EntityImpl( *this, seed );
585  }
586 
593  template< PartitionIteratorType pitype >
595  {
596  typedef typename Partition< pitype >::LevelGridView View;
597  typedef typename View::GridViewImp ViewImp;
598  return View( ViewImp( *this, hostGrid().levelGridView( level ) ) );
599  }
600 
602  template< PartitionIteratorType pitype >
604  {
605  typedef typename Traits::template Partition< pitype >::LeafGridView View;
606  typedef typename View::GridViewImp ViewImp;
607  return View( ViewImp( *this, hostGrid().leafGridView() ) );
608  }
609 
611  LevelGridView levelGridView ( int level ) const
612  {
613  typedef typename LevelGridView::GridViewImp ViewImp;
614  return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
615  }
616 
618  LeafGridView leafGridView () const
619  {
620  typedef typename LeafGridView::GridViewImp ViewImp;
621  return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
622  }
623 
629  const HostGrid &hostGrid () const
630  {
631  return *hostGrid_;
632  }
633 
634  HostGrid &hostGrid ()
635  {
636  return *hostGrid_;
637  }
638 
647  void update ()
648  {
649  // adapt the coordinate function
651 
652  const int newNumLevels = maxLevel()+1;
653  const int oldNumLevels = levelIndexSets_.size();
654 
655  for( int i = newNumLevels; i < oldNumLevels; ++i )
656  {
657  if( levelIndexSets_[ i ] )
658  delete levelIndexSets_[ i ];
659  }
660  levelIndexSets_.resize( newNumLevels, nullptr );
661  }
662 
665  using Base::getRealImplementation;
666 
667  const CoordFunction &coordFunction () const { return coordFunction_; }
668  CoordFunction &coordFunction () { return coordFunction_; }
669 
670  protected:
671  template< int codim >
672  static const typename HostGrid::template Codim< codim >::Entity &
673  getHostEntity( const typename Codim< codim >::Entity &entity )
674  {
675  return getRealImplementation( entity ).hostEntity();
676  }
677 
678  void *allocateStorage ( std::size_t size ) const
679  {
680  return storageAllocator_.allocate( size );
681  }
682 
683  void deallocateStorage ( void *p, std::size_t size ) const
684  {
685  storageAllocator_.deallocate( (char *)p, size );
686  }
687 
688  private:
689  HostGrid *const hostGrid_;
690  CoordFunction &coordFunction_;
691  bool removeHostGrid_;
692  mutable std::vector< LevelIndexSet *, typename Allocator::template rebind< LevelIndexSet * >::other > levelIndexSets_;
693  mutable LeafIndexSet leafIndexSet_;
694  mutable GlobalIdSet globalIdSet_;
695  mutable LocalIdSet localIdSet_;
696  mutable typename Allocator::template rebind< char >::other storageAllocator_;
697  };
698 
699 
700 
701  // GeometryGrid::Codim
702  // -------------------
703 
704  template< class HostGrid, class CoordFunction, class Allocator >
705  template< int codim >
706  struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
707  : public Base::template Codim< codim >
708  {
716  typedef typename Traits::template Codim< codim >::Entity Entity;
717 
722  typedef typename Traits::template Codim< codim >::EntityPointer EntityPointer;
723 
737  typedef typename Traits::template Codim< codim >::Geometry Geometry;
738 
747  typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
748 
754  template< PartitionIteratorType pitype >
755  struct Partition
756  {
757  typedef typename Traits::template Codim< codim >
760  typedef typename Traits::template Codim< codim >
763  };
764 
773 
782 
784  };
785 
786 } // namespace Dune
787 
788 #endif // #ifndef DUNE_GEOGRID_GRID_HH
const LevelIndexSet & levelIndexSet(int level) const
Definition: geometrygrid/grid.hh:366
GridFamily::Traits::template Partition< pitype >::LevelGridView LevelGridView
Definition: geometrygrid/grid.hh:146
HostGrid::ctype ctype
field type of the coordinate vector
Definition: coordfunction.hh:49
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: geometrygrid/grid.hh:179
GridFamily::Traits::template Partition< pitype >::LeafGridView LeafGridView
Definition: geometrygrid/grid.hh:148
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed.
Definition: geometrygrid/grid.hh:581
bool mark(int refCount, const typename Codim< 0 >::Entity &entity)
Definition: geometrygrid/grid.hh:396
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: geometrygrid/grid.hh:737
HostGrid & hostGrid()
Definition: geometrygrid/grid.hh:634
Traits::template Codim< codim >::EntityPointer EntityPointer
type of entity pointer
Definition: geometrygrid/grid.hh:722
LeafGridView leafGridView() const
View for the leaf grid for All_Partition.
Definition: geometrygrid/grid.hh:618
Definition: common/entitypointer.hh:595
traits structure containing types for a codimension
Definition: geometrygrid/grid.hh:122
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: geometrygrid/grid.hh:219
Definition: geometrygrid/indexsets.hh:25
GridFamily::Traits Traits
type of the grid traits
Definition: geometrygrid/grid.hh:113
int size(int codim) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:313
void * allocateStorage(std::size_t size) const
Definition: geometrygrid/grid.hh:678
Definition: geometrygrid/entity.hh:60
bool preAdapt()
Definition: geometrygrid/grid.hh:406
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator LeafIterator
Definition: geometrygrid/grid.hh:759
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
GeometryGrid(HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:252
Definition: identity.hh:12
const LocalIdSet & localIdSet() const
Definition: geometrygrid/grid.hh:358
const HostGrid & hostGrid() const
Definition: geometrygrid/grid.hh:629
CoordFunction & coordFunction()
Definition: geometrygrid/grid.hh:668
bool adapt()
Definition: geometrygrid/grid.hh:411
const LeafIndexSet & leafIndexSet() const
Definition: geometrygrid/grid.hh:382
Definition: geometrygrid/gridfamily.hh:49
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:178
Partition< All_Partition >::LeafIterator LeafIterator
type of level iterator
Definition: geometrygrid/grid.hh:772
Definition: geometrygrid/datahandle.hh:23
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
Definition: idset.hh:18
void postAdapt()
Definition: geometrygrid/grid.hh:418
int size(int level, int codim) const
obtain number of entites on a level
Definition: geometrygrid/grid.hh:302
Wrapper class for entities.
Definition: common/entity.hh:61
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: geometrygrid/grid.hh:152
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: geometrygrid/grid.hh:747
Definition: geometrygrid/entity.hh:57
Partition< pitype >::LevelGridView levelGridView(int level) const
View for a grid level.
Definition: geometrygrid/grid.hh:594
Definition: geometrygrid/gridview.hh:27
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: geometrygrid/grid.hh:716
Definition: common/geometry.hh:24
const CoordFunction & coordFunction() const
Definition: geometrygrid/grid.hh:667
static const HostGrid::template Codim< codim >::Entity & getHostEntity(const typename Codim< codim >::Entity &entity)
Definition: geometrygrid/grid.hh:673
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: geometrygrid/grid.hh:191
void communicate(CommDataHandleIF< DataHandle, Data > &dataHandle, InterfaceType interface, CommunicationDirection direction, int level) const
communicate information on a grid level
Definition: geometrygrid/grid.hh:478
Definition: geometrygrid/backuprestore.hh:22
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:72
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: geometrygrid/declaration.hh:10
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: geometrygrid/grid.hh:514
Definition: geometrygrid/grid.hh:25
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
Definition: geometrygrid/grid.hh:755
void deallocateStorage(void *p, std::size_t size) const
Definition: geometrygrid/grid.hh:683
int getMark(const typename Codim< 0 >::Entity &entity) const
Definition: geometrygrid/grid.hh:401
int ghostSize(int codim) const
obtain size of ghost region for the leaf grid
Definition: geometrygrid/grid.hh:439
~GeometryGrid()
destructor
Definition: geometrygrid/grid.hh:262
int maxLevel() const
obtain maximal grid level
Definition: geometrygrid/grid.hh:289
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: geometrygrid/grid.hh:326
int ghostSize(int level, int codim) const
obtain size of ghost region for a grid level
Definition: geometrygrid/grid.hh:459
Definition: geometrygrid/gridfamily.hh:33
int overlapSize(int level, int codim) const
obtain size of overlap region for a grid level
Definition: geometrygrid/grid.hh:449
actual implementation of the entity
Definition: geometrygrid/entity.hh:34
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:388
Definition: geometrygrid/intersection.hh:19
Partition< All_Partition >::LevelIterator LevelIterator
type of leaf iterator
Definition: geometrygrid/grid.hh:781
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
int size(GeometryType type) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:335
Include standard header files.
Definition: agrid.hh:59
Partition< pitype >::LeafGridView leafGridView() const
View for the leaf grid.
Definition: geometrygrid/grid.hh:603
Traits::template Codim< codim >::template Partition< pitype >::LevelIterator LevelIterator
Definition: geometrygrid/grid.hh:762
const GlobalIdSet & globalIdSet() const
Definition: geometrygrid/grid.hh:350
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: geometrygrid/grid.hh:208
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: geometrygrid/grid.hh:130
int overlapSize(int codim) const
obtain size of overlap region for the leaf grid
Definition: geometrygrid/grid.hh:430
Different resources needed by all grid implementations.
void globalRefine(int refCount)
Definition: geometrygrid/grid.hh:390
LevelGridView levelGridView(int level) const
View for a grid level for All_Partition.
Definition: geometrygrid/grid.hh:611
void update()
update grid caches
Definition: geometrygrid/grid.hh:647
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: geometrygrid/grid.hh:132
Definition: geometrygrid/geometry.hh:86
void communicate(CommDataHandleIF< DataHandle, Data > &dataHandle, InterfaceType interface, CommunicationDirection direction) const
communicate information on leaf entities
Definition: geometrygrid/grid.hh:499
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:235
Types for GridView.
Definition: geometrygrid/grid.hh:143
static void adapt(CoordFunctionInterface &coordFunction)
Definition: coordfunction.hh:284
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: geometrygrid/grid.hh:134
Partition< All_Partition >::LeafGridView LeafGridView
Definition: geometrygrid/grid.hh:153
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: geometrygrid/grid.hh:169
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: geometrygrid/grid.hh:344
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:23