dune-grid  2.7.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 <memory>
7 
8 #include <dune/common/deprecated.hh>
9 #include <dune/common/shared_ptr.hh>
10 
11 #include <dune/grid/common/grid.hh>
12 
19 
20 namespace Dune
21 {
22 
23  // DefaultCoordFunction
24  // --------------------
25 
26  template< class HostGrid >
28  : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
29  {};
30 
31 
32 
33  // GeometryGrid
34  // ------------
35 
76  template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
80  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
81  GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
82  public GeoGrid::ExportParams< HostGrid, CoordFunction >,
83  public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
85  {
87 
89  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
92 
93  friend class GeoGrid::HierarchicIterator< const Grid >;
94 
95  template< int, class, bool > friend class GeoGrid::EntityBase;
96  template< int, int, class > friend class GeoGrid::Geometry;
97  template< class, class, class > friend class GeoGrid::GridView;
98  template< class, class > friend class GeoGrid::Intersection;
99  template< class, class > friend class GeoGrid::IntersectionIterator;
100  template< class, class > friend class GeoGrid::IdSet;
101  template< class, class > friend class GeoGrid::IndexSet;
102  template< class > friend struct HostGridAccess;
103 
104  template< class, class > friend class GeoGrid::CommDataHandle;
105 
106  public:
115  typedef typename GridFamily::Traits Traits;
116 
123  template< int codim >
124  struct Codim;
125 
132  typedef typename Traits::HierarchicIterator HierarchicIterator;
134  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
136  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
137 
144  typedef typename GridFamily::Traits::LeafGridView LeafGridView;
146  typedef typename GridFamily::Traits::LevelGridView LevelGridView;
147 
162  typedef typename Traits::LeafIndexSet LeafIndexSet;
163 
172  typedef typename Traits::LevelIndexSet LevelIndexSet;
173 
184  typedef typename Traits::GlobalIdSet GlobalIdSet;
185 
201  typedef typename Traits::LocalIdSet LocalIdSet;
202 
209  typedef typename Traits::ctype ctype;
210 
212  typedef typename Traits::CollectiveCommunication CollectiveCommunication;
213 
228  GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
229  : hostGrid_( Dune::stackobject_to_shared_ptr(hostGrid) ),
230  coordFunction_( Dune::stackobject_to_shared_ptr(coordFunction) ),
231  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
232  storageAllocator_( allocator )
233  {}
234 
244  GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, std::shared_ptr<CoordFunction> coordFunction, const Allocator &allocator = Allocator() )
245  : hostGrid_( hostGrid ),
246  coordFunction_( coordFunction ),
247  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
248  storageAllocator_( allocator )
249  {}
250 
260  GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, const Allocator &allocator = Allocator() )
261  : hostGrid_( hostGrid ),
262  coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
263  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
264  storageAllocator_( allocator )
265  {}
266 
276  GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator = Allocator() )
277  DUNE_DEPRECATED_MSG("Pass the host grid and coord function as shared_ptr instead of a raw pointer. This constructor will be removed after Dune 2.7.")
278  : hostGrid_( hostGrid ),
279  coordFunction_( coordFunction ),
280  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
281  storageAllocator_( allocator )
282  {}
283 
293  GeometryGrid ( HostGrid *hostGrid, const Allocator &allocator = Allocator() )
294  DUNE_DEPRECATED_MSG("Pass the host grid as shared_ptr instead of a raw pointer. This constructor will be removed after Dune 2.7.")
295  : hostGrid_( hostGrid ),
296  coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
297  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
298  storageAllocator_( allocator )
299  {}
300 
301 
305  {
306  for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
307  {
308  if( levelIndexSets_[ i ] )
309  delete( levelIndexSets_[ i ] );
310  }
311  }
312 
325  int maxLevel () const
326  {
327  return hostGrid().maxLevel();
328  }
329 
338  int size ( int level, int codim ) const
339  {
340  return levelGridView( level ).size( codim );
341  }
342 
349  int size ( int codim ) const
350  {
351  return leafGridView().size( codim );
352  }
353 
362  int size ( int level, GeometryType type ) const
363  {
364  return levelGridView( level ).size( type );
365  }
366 
371  int size ( GeometryType type ) const
372  {
373  return leafGridView().size( type );
374  }
375 
380  size_t numBoundarySegments () const
381  {
382  return hostGrid().numBoundarySegments( );
383  }
386  const GlobalIdSet &globalIdSet () const
387  {
388  if( !globalIdSet_ )
389  globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
390  assert( globalIdSet_ );
391  return globalIdSet_;
392  }
393 
394  const LocalIdSet &localIdSet () const
395  {
396  if( !localIdSet_ )
397  localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
398  assert( localIdSet_ );
399  return localIdSet_;
400  }
401 
402  const LevelIndexSet &levelIndexSet ( int level ) const
403  {
404  assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
405  if( (level < 0) || (level > maxLevel()) )
406  {
407  DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
408  << " requested." );
409  }
410 
411  LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
412  if( !levelIndexSet )
414  assert( levelIndexSet );
415  return *levelIndexSet;
416  }
417 
418  const LeafIndexSet &leafIndexSet () const
419  {
420  if( !leafIndexSet_ )
421  leafIndexSet_.reset( hostGrid().leafIndexSet() );
422  assert( leafIndexSet_ );
423  return leafIndexSet_;
424  }
425 
426  void globalRefine ( int refCount )
427  {
428  hostGrid().globalRefine( refCount );
429  update();
430  }
431 
432  bool mark ( int refCount, const typename Codim< 0 >::Entity &entity )
433  {
434  return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
435  }
436 
437  int getMark ( const typename Codim< 0 >::Entity &entity ) const
438  {
439  return hostGrid().getMark( getHostEntity< 0 >( entity ) );
440  }
441 
442  bool preAdapt ()
443  {
444  return hostGrid().preAdapt();
445  }
446 
447  bool adapt ()
448  {
449  bool ret = hostGrid().adapt();
450  update();
451  return ret;
452  }
453 
454  void postAdapt ()
455  {
456  hostGrid().postAdapt();
457  }
458 
471  {
472  return hostGrid().comm();
473  }
474 
475 #if 0
476  // data handle interface different between geo and interface
477 
487  bool loadBalance ()
488  {
489  const bool gridChanged= hostGrid().loadBalance();
490  if( gridChanged )
491  update();
492  return gridChanged;
493  }
494 
510  template< class DataHandle, class Data >
511  bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
512  {
513  typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
514  typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
515 
516  WrappedDataHandle wrappedDataHandle( *this, datahandle );
517  const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
518  if( gridChanged )
519  update();
520  return gridChanged;
521  }
522 #endif
523 
543  template< class EntitySeed >
544  typename Traits::template Codim< EntitySeed::codimension >::Entity
545  entity ( const EntitySeed &seed ) const
546  {
547  typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
548  return EntityImpl( *this, seed );
549  }
550 
557  LevelGridView levelGridView ( int level ) const
558  {
559  typedef typename LevelGridView::GridViewImp ViewImp;
560  return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
561  }
562 
565  {
566  typedef typename LeafGridView::GridViewImp ViewImp;
567  return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
568  }
569 
576  const HostGrid &hostGrid () const
577  {
578  return *hostGrid_;
579  }
580 
582  HostGrid &hostGrid ()
583  {
584  return *hostGrid_;
585  }
586 
595  void update ()
596  {
597  // adapt the coordinate function
599 
600  const int newNumLevels = maxLevel()+1;
601  const int oldNumLevels = levelIndexSets_.size();
602 
603  for( int i = newNumLevels; i < oldNumLevels; ++i )
604  {
605  if( levelIndexSets_[ i ] )
606  delete levelIndexSets_[ i ];
607  }
608  levelIndexSets_.resize( newNumLevels, nullptr );
609  }
610 
611 
613 
615  const CoordFunction &coordFunction () const { return *coordFunction_; }
616 
618  CoordFunction &coordFunction () { return *coordFunction_; }
619 
622  protected:
623  template< int codim >
624  static const typename HostGrid::template Codim< codim >::Entity &
626  {
627  return entity.impl().hostEntity();
628  }
629 
630  void *allocateStorage ( std::size_t size ) const
631  {
632  return storageAllocator_.allocate( size );
633  }
634 
635  void deallocateStorage ( void *p, std::size_t size ) const
636  {
637  storageAllocator_.deallocate( (char *)p, size );
638  }
639 
640  private:
641  std::shared_ptr<HostGrid> const hostGrid_;
642  std::shared_ptr<CoordFunction> coordFunction_;
643  mutable std::vector< LevelIndexSet *, typename std::allocator_traits<Allocator>::template rebind_alloc< LevelIndexSet * > > levelIndexSets_;
644  mutable LeafIndexSet leafIndexSet_;
645  mutable GlobalIdSet globalIdSet_;
646  mutable LocalIdSet localIdSet_;
647  mutable typename std::allocator_traits<Allocator>::template rebind_alloc< char > storageAllocator_;
648  };
649 
650 
651 
652  // GeometryGrid::Codim
653  // -------------------
654 
655  template< class HostGrid, class CoordFunction, class Allocator >
656  template< int codim >
657  struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
658  : public Base::template Codim< codim >
659  {
667  typedef typename Traits::template Codim< codim >::Entity Entity;
668 
682  typedef typename Traits::template Codim< codim >::Geometry Geometry;
683 
692  typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
693 
699  template< PartitionIteratorType pitype >
700  struct Partition
701  {
702  typedef typename Traits::template Codim< codim >
705  typedef typename Traits::template Codim< codim >
708  };
709 
718 
727 
729  };
730 
731 } // namespace Dune
732 
733 #endif // #ifndef DUNE_GEOGRID_GRID_HH
Include standard header files.
Definition: agrid.hh:59
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:78
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:24
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Definition: common/grid.hh:855
static std::conditional< std::is_reference< InterfaceType >::value, typename std::add_lvalue_reference< typename ReturnImplementationType< typename std::remove_reference< InterfaceType >::type >::ImplementationType >::type, typename std::remove_const< typename ReturnImplementationType< typename std::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: common/grid.hh:1027
Definition: geometrygrid/backuprestore.hh:25
static void adapt(CoordFunctionInterface &coordFunction)
Definition: coordfunction.hh:324
Definition: geometrygrid/datahandle.hh:25
grid wrapper replacing the geometries
Definition: geometrygrid/grid.hh:85
int maxLevel() const
obtain maximal grid level
Definition: geometrygrid/grid.hh:325
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: geometrygrid/grid.hh:618
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: geometrygrid/grid.hh:582
int size(int codim) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:349
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: geometrygrid/grid.hh:362
bool mark(int refCount, const typename Codim< 0 >::Entity &entity)
Definition: geometrygrid/grid.hh:432
void postAdapt()
Definition: geometrygrid/grid.hh:454
const LocalIdSet & localIdSet() const
Definition: geometrygrid/grid.hh:394
LeafGridView leafGridView() const
View for the leaf grid.
Definition: geometrygrid/grid.hh:564
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: geometrygrid/grid.hh:136
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: geometrygrid/grid.hh:545
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: geometrygrid/grid.hh:557
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:244
int size(int level, int codim) const
obtain number of entites on a level
Definition: geometrygrid/grid.hh:338
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: geometrygrid/grid.hh:470
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: geometrygrid/grid.hh:162
const LevelIndexSet & levelIndexSet(int level) const
Definition: geometrygrid/grid.hh:402
bool adapt()
Definition: geometrygrid/grid.hh:447
GeometryGrid(HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:276
GeometryGrid(HostGrid *hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:293
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: geometrygrid/grid.hh:132
static const HostGrid::template Codim< codim >::Entity & getHostEntity(const typename Codim< codim >::Entity &entity)
Definition: geometrygrid/grid.hh:625
const GlobalIdSet & globalIdSet() const
Definition: geometrygrid/grid.hh:386
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: geometrygrid/grid.hh:209
GridFamily::Traits Traits
type of the grid traits
Definition: geometrygrid/grid.hh:115
~GeometryGrid()
destructor
Definition: geometrygrid/grid.hh:304
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: geometrygrid/grid.hh:146
void * allocateStorage(std::size_t size) const
Definition: geometrygrid/grid.hh:630
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: geometrygrid/grid.hh:172
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: geometrygrid/grid.hh:201
void deallocateStorage(void *p, std::size_t size) const
Definition: geometrygrid/grid.hh:635
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: geometrygrid/grid.hh:184
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: geometrygrid/grid.hh:134
void globalRefine(int refCount)
Definition: geometrygrid/grid.hh:426
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:260
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: geometrygrid/grid.hh:144
bool preAdapt()
Definition: geometrygrid/grid.hh:442
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: geometrygrid/grid.hh:212
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: geometrygrid/grid.hh:380
int getMark(const typename Codim< 0 >::Entity &entity) const
Definition: geometrygrid/grid.hh:437
int size(GeometryType type) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:371
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: geometrygrid/grid.hh:576
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:228
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: geometrygrid/grid.hh:615
const LeafIndexSet & leafIndexSet() const
Definition: geometrygrid/grid.hh:418
void update()
update grid caches
Definition: geometrygrid/grid.hh:595
actual implementation of the entity
Definition: geometrygrid/entity.hh:32
Definition: iterator.hh:372
Definition: geometrygrid/intersectioniterator.hh:19
Definition: geometrygrid/geometry.hh:87
Definition: geometrygrid/grid.hh:29
traits structure containing types for a codimension
Definition: geometrygrid/grid.hh:659
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: geometrygrid/grid.hh:726
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: geometrygrid/grid.hh:717
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: geometrygrid/grid.hh:682
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: geometrygrid/grid.hh:692
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: geometrygrid/grid.hh:667
Definition: geometrygrid/grid.hh:701
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator LeafIterator
Definition: geometrygrid/grid.hh:704
Traits::template Codim< codim >::template Partition< pitype >::LevelIterator LevelIterator
Definition: geometrygrid/grid.hh:707
Definition: geometrygrid/gridfamily.hh:33
Definition: geometrygrid/gridfamily.hh:49
Definition: geometrygrid/gridview.hh:89
Definition: identity.hh:15
Definition: idset.hh:20
Definition: geometrygrid/indexsets.hh:27
Definition: geometrygrid/intersection.hh:20
provides access to host grid objects from GeometryGrid
Definition: hostgridaccess.hh:27
Different resources needed by all grid implementations.