Dune Core Modules (2.7.1)

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
10
12
13#include <dune/grid/geometrygrid/backuprestore.hh>
14#include <dune/grid/geometrygrid/capabilities.hh>
15#include <dune/grid/geometrygrid/datahandle.hh>
16#include <dune/grid/geometrygrid/gridfamily.hh>
17#include <dune/grid/geometrygrid/identity.hh>
18#include <dune/grid/geometrygrid/persistentcontainer.hh>
19
20namespace Dune
21{
22
23 // DefaultCoordFunction
24 // --------------------
25
26 template< class HostGrid >
27 class DefaultCoordFunction
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,
90 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
91 Base;
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:
108 typedef GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > GridFamily;
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 )
413 levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
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
598 GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction() );
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 &
625 getHostEntity( const typename Codim< codim >::Entity &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 >
703 ::template Partition< pitype >::LeafIterator
705 typedef typename Traits::template Codim< codim >
706 ::template Partition< pitype >::LevelIterator
708 };
709
717 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
718
726 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
727
729 };
730
731} // namespace Dune
732
733#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:85
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:325
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: grid.hh:618
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:349
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:362
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: grid.hh:615
LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:564
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:136
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: grid.hh:545
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: grid.hh:557
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:244
int size(int level, int codim) const
obtain number of entites on a level
Definition: grid.hh:338
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:162
GeometryGrid(HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:276
GeometryGrid(HostGrid *hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:293
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:132
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: grid.hh:576
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:209
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:115
~GeometryGrid()
destructor
Definition: grid.hh:304
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:146
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: grid.hh:582
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:172
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:201
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:184
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:134
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:260
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: grid.hh:144
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: grid.hh:212
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:380
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:371
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:228
void update()
update grid caches
Definition: grid.hh:595
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:470
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:279
Definition: grid.hh:855
static std::conditional< std::is_reference< InterfaceType >::value, typenamestd::add_lvalue_reference< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type, typenamestd::remove_const< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: grid.hh:1027
Different resources needed by all grid implementations.
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
STL namespace.
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Static tag representing a codimension.
Definition: dimension.hh:22
traits structure containing types for a codimension
Definition: grid.hh:659
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:692
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: grid.hh:717
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:667
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: grid.hh:726
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:682
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:36
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)