DUNE PDELab (2.8)

grid.hh
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 
9 
10 #include <dune/grid/common/grid.hh>
11 
12 #include <dune/grid/geometrygrid/backuprestore.hh>
13 #include <dune/grid/geometrygrid/capabilities.hh>
14 #include <dune/grid/geometrygrid/datahandle.hh>
15 #include <dune/grid/geometrygrid/gridfamily.hh>
16 #include <dune/grid/geometrygrid/identity.hh>
17 #include <dune/grid/geometrygrid/persistentcontainer.hh>
18 
19 namespace Dune
20 {
21 
22  // DefaultCoordFunction
23  // --------------------
24 
25  template< class HostGrid >
26  class DefaultCoordFunction
27  : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
28  {};
29 
30 
31 
32  // GeometryGrid
33  // ------------
34 
75  template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
79  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
80  GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
81  public GeoGrid::ExportParams< HostGrid, CoordFunction >,
82  public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
84  {
86 
88  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
89  GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
90  Base;
91 
92  friend class GeoGrid::HierarchicIterator< const Grid >;
93 
94  template< int, class, bool > friend class GeoGrid::EntityBase;
95  template< int, int, class > friend class GeoGrid::Geometry;
96  template< class, class, class > friend class GeoGrid::GridView;
97  template< class, class > friend class GeoGrid::Intersection;
98  template< class, class > friend class GeoGrid::IntersectionIterator;
99  template< class, class > friend class GeoGrid::IdSet;
100  template< class, class > friend class GeoGrid::IndexSet;
101  template< class > friend struct HostGridAccess;
102 
103  template< class, class > friend class GeoGrid::CommDataHandle;
104 
105  public:
107  typedef GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > GridFamily;
114  typedef typename GridFamily::Traits Traits;
115 
122  template< int codim >
123  struct Codim;
124 
131  typedef typename Traits::HierarchicIterator HierarchicIterator;
133  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
135  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
136 
143  typedef typename GridFamily::Traits::LeafGridView LeafGridView;
145  typedef typename GridFamily::Traits::LevelGridView LevelGridView;
146 
161  typedef typename Traits::LeafIndexSet LeafIndexSet;
162 
171  typedef typename Traits::LevelIndexSet LevelIndexSet;
172 
183  typedef typename Traits::GlobalIdSet GlobalIdSet;
184 
200  typedef typename Traits::LocalIdSet LocalIdSet;
201 
208  typedef typename Traits::ctype ctype;
209 
211  typedef typename Traits::CollectiveCommunication CollectiveCommunication;
212 
227  GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
228  : hostGrid_( Dune::stackobject_to_shared_ptr(hostGrid) ),
229  coordFunction_( Dune::stackobject_to_shared_ptr(coordFunction) ),
230  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
231  storageAllocator_( allocator )
232  {}
233 
243  GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, std::shared_ptr<CoordFunction> coordFunction, const Allocator &allocator = Allocator() )
244  : hostGrid_( hostGrid ),
245  coordFunction_( coordFunction ),
246  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
247  storageAllocator_( allocator )
248  {}
249 
259  GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, const Allocator &allocator = Allocator() )
260  : hostGrid_( hostGrid ),
261  coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
262  levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
263  storageAllocator_( allocator )
264  {}
265 
266 
270  {
271  for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
272  {
273  if( levelIndexSets_[ i ] )
274  delete( levelIndexSets_[ i ] );
275  }
276  }
277 
290  int maxLevel () const
291  {
292  return hostGrid().maxLevel();
293  }
294 
303  int size ( int level, int codim ) const
304  {
305  return levelGridView( level ).size( codim );
306  }
307 
314  int size ( int codim ) const
315  {
316  return leafGridView().size( codim );
317  }
318 
327  int size ( int level, GeometryType type ) const
328  {
329  return levelGridView( level ).size( type );
330  }
331 
336  int size ( GeometryType type ) const
337  {
338  return leafGridView().size( type );
339  }
340 
345  size_t numBoundarySegments () const
346  {
347  return hostGrid().numBoundarySegments( );
348  }
351  const GlobalIdSet &globalIdSet () const
352  {
353  if( !globalIdSet_ )
354  globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
355  assert( globalIdSet_ );
356  return globalIdSet_;
357  }
358 
359  const LocalIdSet &localIdSet () const
360  {
361  if( !localIdSet_ )
362  localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
363  assert( localIdSet_ );
364  return localIdSet_;
365  }
366 
367  const LevelIndexSet &levelIndexSet ( int level ) const
368  {
369  assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
370  if( (level < 0) || (level > maxLevel()) )
371  {
372  DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
373  << " requested." );
374  }
375 
376  LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
377  if( !levelIndexSet )
378  levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
379  assert( levelIndexSet );
380  return *levelIndexSet;
381  }
382 
383  const LeafIndexSet &leafIndexSet () const
384  {
385  if( !leafIndexSet_ )
386  leafIndexSet_.reset( hostGrid().leafIndexSet() );
387  assert( leafIndexSet_ );
388  return leafIndexSet_;
389  }
390 
391  void globalRefine ( int refCount )
392  {
393  hostGrid().globalRefine( refCount );
394  update();
395  }
396 
397  bool mark ( int refCount, const typename Codim< 0 >::Entity &entity_ )
398  {
399  return hostGrid().mark( refCount, getHostEntity< 0 >( entity_ ) );
400  }
401 
402  int getMark ( const typename Codim< 0 >::Entity &entity_ ) const
403  {
404  return hostGrid().getMark( getHostEntity< 0 >( entity_ ) );
405  }
406 
407  bool preAdapt ()
408  {
409  return hostGrid().preAdapt();
410  }
411 
412  bool adapt ()
413  {
414  bool ret = hostGrid().adapt();
415  update();
416  return ret;
417  }
418 
419  void postAdapt ()
420  {
421  hostGrid().postAdapt();
422  }
423 
436  {
437  return hostGrid().comm();
438  }
439 
440 #if 0
441  // data handle interface different between geo and interface
442 
452  bool loadBalance ()
453  {
454  const bool gridChanged= hostGrid().loadBalance();
455  if( gridChanged )
456  update();
457  return gridChanged;
458  }
459 
475  template< class DataHandle, class Data >
476  bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
477  {
478  typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
479  typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
480 
481  WrappedDataHandle wrappedDataHandle( *this, datahandle );
482  const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
483  if( gridChanged )
484  update();
485  return gridChanged;
486  }
487 #endif
488 
508  template< class EntitySeed >
509  typename Traits::template Codim< EntitySeed::codimension >::Entity
510  entity ( const EntitySeed &seed ) const
511  {
512  typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
513  return EntityImpl( *this, seed );
514  }
515 
522  LevelGridView levelGridView ( int level ) const
523  {
524  typedef typename LevelGridView::GridViewImp ViewImp;
525  return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
526  }
527 
530  {
531  typedef typename LeafGridView::GridViewImp ViewImp;
532  return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
533  }
534 
541  const HostGrid &hostGrid () const
542  {
543  return *hostGrid_;
544  }
545 
547  HostGrid &hostGrid ()
548  {
549  return *hostGrid_;
550  }
551 
560  void update ()
561  {
562  // adapt the coordinate function
563  GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction() );
564 
565  const int newNumLevels = maxLevel()+1;
566  const int oldNumLevels = levelIndexSets_.size();
567 
568  for( int i = newNumLevels; i < oldNumLevels; ++i )
569  {
570  if( levelIndexSets_[ i ] )
571  delete levelIndexSets_[ i ];
572  }
573  levelIndexSets_.resize( newNumLevels, nullptr );
574  }
575 
576 
578  const CoordFunction &coordFunction () const { return *coordFunction_; }
579 
581  CoordFunction &coordFunction () { return *coordFunction_; }
582 
585  protected:
586  template< int codim >
587  static const typename HostGrid::template Codim< codim >::Entity &
588  getHostEntity( const typename Codim< codim >::Entity &entity )
589  {
590  return entity.impl().hostEntity();
591  }
592 
593  void *allocateStorage ( std::size_t size ) const
594  {
595  return storageAllocator_.allocate( size );
596  }
597 
598  void deallocateStorage ( void *p, std::size_t size ) const
599  {
600  storageAllocator_.deallocate( (char *)p, size );
601  }
602 
603  private:
604  std::shared_ptr<HostGrid> const hostGrid_;
605  std::shared_ptr<CoordFunction> coordFunction_;
606  mutable std::vector< LevelIndexSet *, typename std::allocator_traits<Allocator>::template rebind_alloc< LevelIndexSet * > > levelIndexSets_;
607  mutable LeafIndexSet leafIndexSet_;
608  mutable GlobalIdSet globalIdSet_;
609  mutable LocalIdSet localIdSet_;
610  mutable typename std::allocator_traits<Allocator>::template rebind_alloc< char > storageAllocator_;
611  };
612 
613 
614 
615  // GeometryGrid::Codim
616  // -------------------
617 
618  template< class HostGrid, class CoordFunction, class Allocator >
619  template< int codim >
620  struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
621  : public Base::template Codim< codim >
622  {
630  typedef typename Traits::template Codim< codim >::Entity Entity;
631 
645  typedef typename Traits::template Codim< codim >::Geometry Geometry;
646 
655  typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
656 
662  template< PartitionIteratorType pitype >
663  struct Partition
664  {
665  typedef typename Traits::template Codim< codim >
666  ::template Partition< pitype >::LeafIterator
667  LeafIterator;
668  typedef typename Traits::template Codim< codim >
669  ::template Partition< pitype >::LevelIterator
671  };
672 
680  typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
681 
689  typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
690 
692  };
693 
694 } // namespace Dune
695 
696 #endif // #ifndef DUNE_GEOGRID_GRID_HH
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:24
Implementation & impl()
access to the underlying implementation
Definition: entity.hh:78
actual implementation of the entity
Definition: entity.hh:32
grid wrapper replacing the geometries
Definition: grid.hh:84
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:290
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: grid.hh:581
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: grid.hh:547
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:314
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:327
LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:529
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:135
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: grid.hh:510
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: grid.hh:522
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:243
int size(int level, int codim) const
obtain number of entites on a level
Definition: grid.hh:303
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:435
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:161
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:131
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:208
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:114
~GeometryGrid()
destructor
Definition: grid.hh:269
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:145
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:171
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:200
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:183
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:133
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:259
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: grid.hh:143
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: grid.hh:211
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:345
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:336
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: grid.hh:541
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:227
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: grid.hh:578
void update()
update grid caches
Definition: grid.hh:560
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
Definition: grid.hh:851
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:11
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:70
This file implements several utilities related to std::shared_ptr.
Static tag representing a codimension.
Definition: dimension.hh:22
traits structure containing types for a codimension
Definition: grid.hh:622
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: grid.hh:689
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: grid.hh:680
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:645
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:655
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:630
provides access to host grid objects from GeometryGrid
Definition: hostgridaccess.hh:27
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 12, 22:29, 2024)