dune-grid  2.11
geometrygrid/grid.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GEOGRID_GRID_HH
6 #define DUNE_GEOGRID_GRID_HH
7 
8 #include <memory>
9 
10 #include <dune/common/shared_ptr.hh>
11 
12 #include <dune/grid/common/grid.hh>
13 
20 
21 namespace Dune
22 {
23 
24  // DefaultCoordFunction
25  // --------------------
26 
27  template< class HostGrid >
29  : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
30  {};
31 
32 
33 
34  // GeometryGrid
35  // ------------
36 
77  template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
78  class GeometryGrid
81  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
82  GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
83  public GeoGrid::ExportParams< HostGrid, CoordFunction >,
84  public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
86  {
88 
90  < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
92  Base;
93 
94  friend class GeoGrid::HierarchicIterator< const Grid >;
95 
96  template< int, class, bool > friend class GeoGrid::EntityBase;
97  template< int, int, class > friend class GeoGrid::Geometry;
98  template< class, class, class > friend class GeoGrid::GridView;
99  template< class, class > friend class GeoGrid::Intersection;
100  template< class, class > friend class GeoGrid::IntersectionIterator;
101  template< class, class > friend class GeoGrid::IdSet;
102  template< class, class > friend class GeoGrid::IndexSet;
103  template< class > friend struct HostGridAccess;
104 
105  template< class, class > friend class GeoGrid::CommDataHandle;
106 
107  public:
115  typedef typename GridFamily::Traits Traits;
117 
124  template< int codim >
125  struct Codim;
126 
132  typedef typename Traits::HierarchicIterator HierarchicIterator;
135  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
137  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
138 
145  typedef typename GridFamily::Traits::LeafGridView LeafGridView;
147  typedef typename GridFamily::Traits::LevelGridView LevelGridView;
148 
163  typedef typename Traits::LeafIndexSet LeafIndexSet;
164 
173  typedef typename Traits::LevelIndexSet LevelIndexSet;
174 
185  typedef typename Traits::GlobalIdSet GlobalIdSet;
186 
202  typedef typename Traits::LocalIdSet LocalIdSet;
203 
209  typedef typename Traits::ctype ctype;
211 
213  typedef typename Traits::Communication Communication;
214 
229  GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
230  : hostGrid_( Dune::stackobject_to_shared_ptr(hostGrid) ),
231  coordFunction_( Dune::stackobject_to_shared_ptr(coordFunction) ),
232  levelIndexSets_( hostGrid_->maxLevel()+1 ),
233  storageAllocator_( allocator )
234  {}
235 
245  GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, std::shared_ptr<CoordFunction> coordFunction, const Allocator &allocator = Allocator() )
246  : hostGrid_( hostGrid ),
247  coordFunction_( coordFunction ),
248  levelIndexSets_( hostGrid_->maxLevel()+1 ),
249  storageAllocator_( allocator )
250  {}
251 
261  GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, const Allocator &allocator = Allocator() )
262  : hostGrid_( hostGrid ),
263  coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
264  levelIndexSets_( hostGrid_->maxLevel()+1 ),
265  storageAllocator_( allocator )
266  {}
267 
268 
269 
282  int maxLevel () const
283  {
284  return hostGrid().maxLevel();
285  }
286 
295  int size ( int level, int codim ) const
296  {
297  return levelGridView( level ).size( codim );
298  }
299 
306  int size ( int codim ) const
307  {
308  return leafGridView().size( codim );
309  }
310 
319  int size ( int level, GeometryType type ) const
320  {
321  return levelGridView( level ).size( type );
322  }
323 
328  int size ( GeometryType type ) const
329  {
330  return leafGridView().size( type );
331  }
332 
337  size_t numBoundarySegments () const
338  {
339  return hostGrid().numBoundarySegments( );
340  }
343  const GlobalIdSet &globalIdSet () const
344  {
345  if( !globalIdSet_ )
346  globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
347  assert( globalIdSet_ );
348  return globalIdSet_;
349  }
350 
351  const LocalIdSet &localIdSet () const
352  {
353  if( !localIdSet_ )
354  localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
355  assert( localIdSet_ );
356  return localIdSet_;
357  }
358 
359  const LevelIndexSet &levelIndexSet ( int level ) const
360  {
361  assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
362  if( (level < 0) || (level > maxLevel()) )
363  {
364  DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
365  << " requested." );
366  }
367 
368  auto& levelIndexSetPtr = levelIndexSets_[ level ];
369  if( !levelIndexSetPtr )
370  levelIndexSetPtr = std::make_unique<LevelIndexSet>( hostGrid().levelIndexSet( level ) );
371  assert( levelIndexSetPtr );
372  return *levelIndexSetPtr;
373  }
374 
375  const LeafIndexSet &leafIndexSet () const
376  {
377  if( !leafIndexSet_ )
378  leafIndexSet_.reset( hostGrid().leafIndexSet() );
379  assert( leafIndexSet_ );
380  return leafIndexSet_;
381  }
382 
383  void globalRefine ( int refCount )
384  {
385  hostGrid().globalRefine( refCount );
386  update();
387  }
388 
389  bool mark ( int refCount, const typename Codim< 0 >::Entity &entity_ )
390  {
391  return hostGrid().mark( refCount, getHostEntity< 0 >( entity_ ) );
392  }
393 
394  int getMark ( const typename Codim< 0 >::Entity &entity_ ) const
395  {
396  return hostGrid().getMark( getHostEntity< 0 >( entity_ ) );
397  }
398 
399  bool preAdapt ()
400  {
401  return hostGrid().preAdapt();
402  }
403 
404  bool adapt ()
405  {
406  bool ret = hostGrid().adapt();
407  update();
408  return ret;
409  }
410 
411  void postAdapt ()
412  {
413  hostGrid().postAdapt();
414  }
415 
427  const Communication &comm () const
428  {
429  return hostGrid().comm();
430  }
431 
432 #if 0
433  // data handle interface different between geo and interface
434 
444  bool loadBalance ()
445  {
446  const bool gridChanged= hostGrid().loadBalance();
447  if( gridChanged )
448  update();
449  return gridChanged;
450  }
451 
467  template< class DataHandle, class Data >
468  bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
469  {
470  typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
471  typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
472 
473  WrappedDataHandle wrappedDataHandle( *this, datahandle );
474  const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
475  if( gridChanged )
476  update();
477  return gridChanged;
478  }
479 #endif
480 
500  template< class EntitySeed >
501  typename Traits::template Codim< EntitySeed::codimension >::Entity
502  entity ( const EntitySeed &seed ) const
503  {
504  typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
505  return EntityImpl( *this, seed );
506  }
507 
514  LevelGridView levelGridView ( int level ) const
515  {
516  typedef typename LevelGridView::GridViewImp ViewImp;
517  return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
518  }
519 
522  {
523  typedef typename LeafGridView::GridViewImp ViewImp;
524  return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
525  }
526 
533  const HostGrid &hostGrid () const
534  {
535  return *hostGrid_;
536  }
537 
539  HostGrid &hostGrid ()
540  {
541  return *hostGrid_;
542  }
543 
552  void update ()
553  {
554  // adapt the coordinate function
556 
557  levelIndexSets_.resize( maxLevel()+1 );
558  }
559 
560 
562  const CoordFunction &coordFunction () const { return *coordFunction_; }
563 
565  CoordFunction &coordFunction () { return *coordFunction_; }
566 
569  protected:
570  template< int codim >
571  static const typename HostGrid::template Codim< codim >::Entity &
573  {
574  return entity.impl().hostEntity();
575  }
576 
577  void *allocateStorage ( std::size_t size ) const
578  {
579  return storageAllocator_.allocate( size );
580  }
581 
582  void deallocateStorage ( void *p, std::size_t size ) const
583  {
584  storageAllocator_.deallocate( (char *)p, size );
585  }
586 
587  private:
588  std::shared_ptr<HostGrid> const hostGrid_;
589  std::shared_ptr<CoordFunction> coordFunction_;
590  mutable std::vector<std::unique_ptr<LevelIndexSet>> levelIndexSets_;
591  mutable LeafIndexSet leafIndexSet_;
592  mutable GlobalIdSet globalIdSet_;
593  mutable LocalIdSet localIdSet_;
594  mutable typename std::allocator_traits<Allocator>::template rebind_alloc< char > storageAllocator_;
595  };
596 
597 
598 
599  // GeometryGrid::Codim
600  // -------------------
601 
602  template< class HostGrid, class CoordFunction, class Allocator >
603  template< int codim >
604  struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
605  : public Base::template Codim< codim >
606  {
614  typedef typename Traits::template Codim< codim >::Entity Entity;
615 
629  typedef typename Traits::template Codim< codim >::Geometry Geometry;
630 
639  typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
640 
646  template< PartitionIteratorType pitype >
647  struct Partition
648  {
649  typedef typename Traits::template Codim< codim >
652  typedef typename Traits::template Codim< codim >
655  };
656 
665 
674 
676  };
677 
678 } // namespace Dune
679 
680 #endif // #ifndef DUNE_GEOGRID_GRID_HH
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:245
const LocalIdSet & localIdSet() const
Definition: geometrygrid/grid.hh:351
int size(int level, int codim) const
obtain number of entities on a level
Definition: geometrygrid/grid.hh:295
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:25
Definition: geometrygrid/intersection.hh:21
void postAdapt()
Definition: geometrygrid/grid.hh:411
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: geometrygrid/grid.hh:562
void update()
update grid caches
Definition: geometrygrid/grid.hh:552
Definition: geometrygrid/geometry.hh:88
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: geometrygrid/grid.hh:639
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: geometrygrid/grid.hh:173
void globalRefine(int refCount)
Definition: geometrygrid/grid.hh:383
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: geometrygrid/grid.hh:163
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: geometrygrid/grid.hh:673
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:261
bool adapt()
Definition: geometrygrid/grid.hh:404
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:80
GridFamily::Traits Traits
type of the grid traits
Definition: geometrygrid/grid.hh:116
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:229
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:375
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: geometrygrid/grid.hh:137
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: geometrygrid/grid.hh:514
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: geometrygrid/grid.hh:202
Definition: geometrygrid/gridfamily.hh:50
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: geometrygrid/grid.hh:147
Different resources needed by all grid implementations.
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: geometrygrid/grid.hh:614
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: geometrygrid/grid.hh:337
STL namespace.
static void adapt(CoordFunctionInterface &)
Definition: coordfunction.hh:326
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: geometrygrid/grid.hh:539
traits structure containing types for a codimension
Definition: geometrygrid/grid.hh:125
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: geometrygrid/grid.hh:133
Definition: identity.hh:14
Definition: geometrygrid/entity.hh:57
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: geometrygrid/grid.hh:664
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: geometrygrid/grid.hh:533
int getMark(const typename Codim< 0 >::Entity &entity_) const
Definition: geometrygrid/grid.hh:394
Definition: common/geometry.hh:28
const LevelIndexSet & levelIndexSet(int level) const
Definition: geometrygrid/grid.hh:359
Definition: geometrygrid/gridfamily.hh:34
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: geometrygrid/grid.hh:145
Definition: geometrygrid/grid.hh:28
Include standard header files.
Definition: agrid.hh:59
Traits::Communication Communication
communicator with all other processes having some part of the grid
Definition: geometrygrid/grid.hh:213
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator LeafIterator
Definition: geometrygrid/grid.hh:651
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: geometrygrid/grid.hh:135
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: declaration.hh:12
const GlobalIdSet & globalIdSet() const
Definition: geometrygrid/grid.hh:343
LeafGridView leafGridView() const
View for the leaf grid.
Definition: geometrygrid/grid.hh:521
Definition: geometrygrid/gridview.hh:29
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
void * allocateStorage(std::size_t size) const
Definition: geometrygrid/grid.hh:577
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: geometrygrid/grid.hh:185
Definition: geometrygrid/grid.hh:647
int maxLevel() const
obtain maximal grid level
Definition: geometrygrid/grid.hh:282
bool mark(int refCount, const typename Codim< 0 >::Entity &entity_)
Definition: geometrygrid/grid.hh:389
Definition: geometrygrid/indexsets.hh:27
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: geometrygrid/grid.hh:629
bool preAdapt()
Definition: geometrygrid/grid.hh:399
Traits::template Codim< codim >::template Partition< pitype >::LevelIterator LevelIterator
Definition: geometrygrid/grid.hh:654
int size(GeometryType type) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:328
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: geometrygrid/grid.hh:502
Definition: geometrygrid/datahandle.hh:25
const LeafIndexSet & leafIndexSet() const
Definition: geometrygrid/grid.hh:375
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:132
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
int size(int level, GeometryType type) const
obtain number of entities on a level
Definition: geometrygrid/grid.hh:319
int size(int codim) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:306
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: geometrygrid/grid.hh:210
Definition: idset.hh:20
Definition: geometrygrid/entity.hh:60
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: geometrygrid/grid.hh:565
const Communication & comm() const
obtain Communication object
Definition: geometrygrid/grid.hh:427
void deallocateStorage(void *p, std::size_t size) const
Definition: geometrygrid/grid.hh:582
actual implementation of the entity
Definition: geometrygrid/entity.hh:34
static const HostGrid::template Codim< codim >::Entity & getHostEntity(const typename Codim< codim >::Entity &entity)
Definition: geometrygrid/grid.hh:572
Definition: geometrygrid/backuprestore.hh:26