Dune Core Modules (2.6.0)

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
7
9
10#include <dune/grid/geometrygrid/backuprestore.hh>
11#include <dune/grid/geometrygrid/capabilities.hh>
12#include <dune/grid/geometrygrid/datahandle.hh>
13#include <dune/grid/geometrygrid/gridfamily.hh>
14#include <dune/grid/geometrygrid/identity.hh>
15#include <dune/grid/geometrygrid/persistentcontainer.hh>
16
17namespace Dune
18{
19
20 // DefaultCoordFunction
21 // --------------------
22
23 template< class HostGrid >
24 class DefaultCoordFunction
25 : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
26 {};
27
28
29
30 // GeometryGrid
31 // ------------
32
73 template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
77 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
78 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
79 public GeoGrid::ExportParams< HostGrid, CoordFunction >,
80 public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
82 {
84
86 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
87 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
88 Base;
89
90 friend class GeoGrid::HierarchicIterator< const Grid >;
91
92 template< int, class, bool > friend class GeoGrid::EntityBase;
93 template< int, int, class > friend class GeoGrid::Geometry;
94 template< class, class, class > friend class GeoGrid::GridView;
95 template< class, class > friend class GeoGrid::Intersection;
96 template< class, class > friend class GeoGrid::IntersectionIterator;
97 template< class, class > friend class GeoGrid::IdSet;
98 template< class, class > friend class GeoGrid::IndexSet;
99 template< class > friend struct HostGridAccess;
100
101 template< class, class > friend class GeoGrid::CommDataHandle;
102
103 public:
105 typedef GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > GridFamily;
112 typedef typename GridFamily::Traits Traits;
113
120 template< int codim >
121 struct Codim;
122
129 typedef typename Traits::HierarchicIterator HierarchicIterator;
131 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
133 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
134
141 typedef typename GridFamily::Traits::LeafGridView LeafGridView;
143 typedef typename GridFamily::Traits::LevelGridView LevelGridView;
144
159 typedef typename Traits::LeafIndexSet LeafIndexSet;
160
169 typedef typename Traits::LevelIndexSet LevelIndexSet;
170
181 typedef typename Traits::GlobalIdSet GlobalIdSet;
182
198 typedef typename Traits::LocalIdSet LocalIdSet;
199
206 typedef typename Traits::ctype ctype;
207
209 typedef typename Traits::CollectiveCommunication CollectiveCommunication;
210
225 GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
226 : hostGrid_( &hostGrid ),
227 coordFunction_( &coordFunction ),
228 removeHostGrid_( false ),
229 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
230 storageAllocator_( allocator )
231 {}
232
242 GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator = Allocator() )
243 : hostGrid_( hostGrid ),
244 coordFunction_( coordFunction ),
245 removeHostGrid_( true ),
246 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
247 storageAllocator_( allocator )
248 {}
249
259 GeometryGrid ( HostGrid *hostGrid, const Allocator &allocator = Allocator() )
260 : hostGrid_( hostGrid ),
261 coordFunction_( new CoordFunction( this->hostGrid() ) ),
262 removeHostGrid_( true ),
263 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
264 storageAllocator_( allocator )
265 {}
266
267
271 {
272 for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
273 {
274 if( levelIndexSets_[ i ] )
275 delete( levelIndexSets_[ i ] );
276 }
277
278 if( removeHostGrid_ )
279 {
280 delete coordFunction_;
281 delete hostGrid_;
282 }
283 }
284
297 int maxLevel () const
298 {
299 return hostGrid().maxLevel();
300 }
301
310 int size ( int level, int codim ) const
311 {
312 return levelGridView( level ).size( codim );
313 }
314
321 int size ( int codim ) const
322 {
323 return leafGridView().size( codim );
324 }
325
334 int size ( int level, GeometryType type ) const
335 {
336 return levelGridView( level ).size( type );
337 }
338
343 int size ( GeometryType type ) const
344 {
345 return leafGridView().size( type );
346 }
347
352 size_t numBoundarySegments () const
353 {
354 return hostGrid().numBoundarySegments( );
355 }
358 const GlobalIdSet &globalIdSet () const
359 {
360 if( !globalIdSet_ )
361 globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
362 assert( globalIdSet_ );
363 return globalIdSet_;
364 }
365
366 const LocalIdSet &localIdSet () const
367 {
368 if( !localIdSet_ )
369 localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
370 assert( localIdSet_ );
371 return localIdSet_;
372 }
373
374 const LevelIndexSet &levelIndexSet ( int level ) const
375 {
376 assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
377 if( (level < 0) || (level > maxLevel()) )
378 {
379 DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
380 << " requested." );
381 }
382
383 LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
384 if( !levelIndexSet )
385 levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
386 assert( levelIndexSet );
387 return *levelIndexSet;
388 }
389
390 const LeafIndexSet &leafIndexSet () const
391 {
392 if( !leafIndexSet_ )
393 leafIndexSet_.reset( hostGrid().leafIndexSet() );
394 assert( leafIndexSet_ );
395 return leafIndexSet_;
396 }
397
398 void globalRefine ( int refCount )
399 {
400 hostGrid().globalRefine( refCount );
401 update();
402 }
403
404 bool mark ( int refCount, const typename Codim< 0 >::Entity &entity )
405 {
406 return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
407 }
408
409 int getMark ( const typename Codim< 0 >::Entity &entity ) const
410 {
411 return hostGrid().getMark( getHostEntity< 0 >( entity ) );
412 }
413
414 bool preAdapt ()
415 {
416 return hostGrid().preAdapt();
417 }
418
419 bool adapt ()
420 {
421 bool ret = hostGrid().adapt();
422 update();
423 return ret;
424 }
425
426 void postAdapt ()
427 {
428 hostGrid().postAdapt();
429 }
430
443 {
444 return hostGrid().comm();
445 }
446
447#if 0
448 // data handle interface different between geo and interface
449
459 bool loadBalance ()
460 {
461 const bool gridChanged= hostGrid().loadBalance();
462 if( gridChanged )
463 update();
464 return gridChanged;
465 }
466
482 template< class DataHandle, class Data >
483 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
484 {
485 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
486 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
487
488 WrappedDataHandle wrappedDataHandle( *this, datahandle );
489 const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
490 if( gridChanged )
491 update();
492 return gridChanged;
493 }
494#endif
495
515 template< class EntitySeed >
516 typename Traits::template Codim< EntitySeed::codimension >::Entity
517 entity ( const EntitySeed &seed ) const
518 {
519 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
520 return EntityImpl( *this, seed );
521 }
522
529 LevelGridView levelGridView ( int level ) const
530 {
531 typedef typename LevelGridView::GridViewImp ViewImp;
532 return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
533 }
534
537 {
538 typedef typename LeafGridView::GridViewImp ViewImp;
539 return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
540 }
541
548 const HostGrid &hostGrid () const
549 {
550 return *hostGrid_;
551 }
552
554 HostGrid &hostGrid ()
555 {
556 return *hostGrid_;
557 }
558
567 void update ()
568 {
569 // adapt the coordinate function
570 GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction() );
571
572 const int newNumLevels = maxLevel()+1;
573 const int oldNumLevels = levelIndexSets_.size();
574
575 for( int i = newNumLevels; i < oldNumLevels; ++i )
576 {
577 if( levelIndexSets_[ i ] )
578 delete levelIndexSets_[ i ];
579 }
580 levelIndexSets_.resize( newNumLevels, nullptr );
581 }
582
583
585
587 const CoordFunction &coordFunction () const { return *coordFunction_; }
588
590 CoordFunction &coordFunction () { return *coordFunction_; }
591
594 protected:
595 template< int codim >
596 static const typename HostGrid::template Codim< codim >::Entity &
597 getHostEntity( const typename Codim< codim >::Entity &entity )
598 {
599 return getRealImplementation( entity ).hostEntity();
600 }
601
602 void *allocateStorage ( std::size_t size ) const
603 {
604 return storageAllocator_.allocate( size );
605 }
606
607 void deallocateStorage ( void *p, std::size_t size ) const
608 {
609 storageAllocator_.deallocate( (char *)p, size );
610 }
611
612 private:
613 HostGrid *const hostGrid_;
614 CoordFunction *coordFunction_;
615 bool removeHostGrid_;
616 mutable std::vector< LevelIndexSet *, typename Allocator::template rebind< LevelIndexSet * >::other > levelIndexSets_;
617 mutable LeafIndexSet leafIndexSet_;
618 mutable GlobalIdSet globalIdSet_;
619 mutable LocalIdSet localIdSet_;
620 mutable typename Allocator::template rebind< char >::other storageAllocator_;
621 };
622
623
624
625 // GeometryGrid::Codim
626 // -------------------
627
628 template< class HostGrid, class CoordFunction, class Allocator >
629 template< int codim >
630 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
631 : public Base::template Codim< codim >
632 {
640 typedef typename Traits::template Codim< codim >::Entity Entity;
641
655 typedef typename Traits::template Codim< codim >::Geometry Geometry;
656
665 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
666
672 template< PartitionIteratorType pitype >
673 struct Partition
674 {
675 typedef typename Traits::template Codim< codim >
676 ::template Partition< pitype >::LeafIterator
678 typedef typename Traits::template Codim< codim >
679 ::template Partition< pitype >::LevelIterator
681 };
682
690 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
691
699 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
700
702 };
703
704} // namespace Dune
705
706#endif // #ifndef DUNE_GEOGRID_GRID_HH
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:24
actual implementation of the entity
Definition: entity.hh:32
grid wrapper replacing the geometries
Definition: grid.hh:82
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:297
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: grid.hh:590
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:1026
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:321
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:334
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: grid.hh:587
LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:536
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:133
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: grid.hh:517
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: grid.hh:529
int size(int level, int codim) const
obtain number of entites on a level
Definition: grid.hh:310
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:159
GeometryGrid(HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:242
GeometryGrid(HostGrid *hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:259
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:129
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: grid.hh:548
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:206
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:112
~GeometryGrid()
destructor
Definition: grid.hh:270
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:143
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: grid.hh:554
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:169
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:198
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:181
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:131
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: grid.hh:141
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: grid.hh:209
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:352
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:343
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:225
void update()
update grid caches
Definition: grid.hh:567
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:442
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
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:1026
Different resources needed by all grid implementations.
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
Static tag representing a codimension.
Definition: dimension.hh:22
traits structure containing types for a codimension
Definition: grid.hh:632
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:665
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: grid.hh:690
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:640
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: grid.hh:699
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:655
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 (Dec 26, 23:30, 2024)