Dune Core Modules (2.3.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
8
10
11#include <dune/grid/geometrygrid/backuprestore.hh>
12#include <dune/grid/geometrygrid/capabilities.hh>
13#include <dune/grid/geometrygrid/datahandle.hh>
14#include <dune/grid/geometrygrid/gridfamily.hh>
15#include <dune/grid/geometrygrid/identity.hh>
16#include <dune/grid/geometrygrid/persistentcontainer.hh>
17
18namespace Dune
19{
20
21 // DefaultCoordFunction
22 // --------------------
23
24 template< class HostGrid >
25 class DefaultCoordFunction
26 : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
27 {};
28
29
30
31 // GeometryGrid
32 // ------------
33
74 template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
78 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
79 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
80 public GeoGrid::ExportParams< HostGrid, CoordFunction >,
81 public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
83 {
85
87 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
88 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
89 Base;
90
91 friend class GeoGrid::HierarchicIterator< const Grid >;
92
93 template< int, class, bool > friend class GeoGrid::EntityBase;
94 template< class, bool > friend class GeoGrid::EntityPointer;
95 template< int, class > friend class GeoGrid::EntityProxy;
96 template< int, int, class > friend class GeoGrid::Geometry;
97 template< class, class, class, PartitionIteratorType > 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 template< PartitionIteratorType pitype >
146 {
147 typedef typename GridFamily::Traits::template Partition< pitype >::LevelGridView
148 LevelGridView;
149 typedef typename GridFamily::Traits::template Partition< pitype >::LeafGridView
150 LeafGridView;
151 };
152
154 typedef typename Partition< All_Partition >::LevelGridView LevelGridView;
155 typedef typename Partition< All_Partition >::LeafGridView LeafGridView;
156
171 typedef typename Traits::LeafIndexSet LeafIndexSet;
172
181 typedef typename Traits::LevelIndexSet LevelIndexSet;
182
193 typedef typename Traits::GlobalIdSet GlobalIdSet;
194
210 typedef typename Traits::LocalIdSet LocalIdSet;
211
218 typedef typename Traits::ctype ctype;
219
221 typedef typename Traits::CollectiveCommunication CollectiveCommunication;
222
237 GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
238 : hostGrid_( &hostGrid ),
239 coordFunction_( coordFunction ),
240 removeHostGrid_( false ),
241 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
242 storageAllocator_( allocator )
243 {}
244
254 GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator = Allocator() )
255 : hostGrid_( hostGrid ),
256 coordFunction_( *coordFunction ),
257 removeHostGrid_( true ),
258 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
259 storageAllocator_( allocator )
260 {}
261
265 {
266 for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
267 {
268 if( levelIndexSets_[ i ] )
269 delete( levelIndexSets_[ i ] );
270 }
271
272 if( removeHostGrid_ )
273 {
274 delete &coordFunction_;
275 delete hostGrid_;
276 }
277 }
278
291 int maxLevel () const
292 {
293 return hostGrid().maxLevel();
294 }
295
304 int size ( int level, int codim ) const
305 {
306 return levelView( level ).size( codim );
307 }
308
315 int size ( int codim ) const
316 {
317 return leafView().size( codim );
318 }
319
328 int size ( int level, GeometryType type ) const
329 {
330 return levelView( level ).size( type );
331 }
332
337 int size ( GeometryType type ) const
338 {
339 return leafView().size( type );
340 }
341
346 size_t numBoundarySegments () const
347 {
348 return hostGrid().numBoundarySegments( );
349 }
352 template< int codim >
353 typename Codim< codim >::LevelIterator lbegin ( int level ) const
354 {
355 return levelView( level ).template begin< codim >();
356 }
357
358 template< int codim >
359 typename Codim< codim >::LevelIterator lend ( int level ) const
360 {
361 return levelView( level ).template end< codim >();
362 }
363
364 template< int codim, PartitionIteratorType pitype >
365 typename Codim< codim >::template Partition< pitype >::LevelIterator
366 lbegin ( int level ) const
367 {
368 return levelView( level ).template begin< codim, pitype >();
369 }
370
371 template< int codim, PartitionIteratorType pitype >
372 typename Codim< codim >::template Partition< pitype >::LevelIterator
373 lend ( int level ) const
374 {
375 return levelView( level ).template end< codim, pitype >();
376 }
377
378 template< int codim >
379 typename Codim< codim >::LeafIterator leafbegin () const
380 {
381 return leafView().template begin< codim >();
382 }
383
384 template< int codim >
385 typename Codim< codim >::LeafIterator leafend () const
386 {
387 return leafView().template end< codim >();
388 }
389
390 template< int codim, PartitionIteratorType pitype >
391 typename Codim< codim >::template Partition< pitype >::LeafIterator
392 leafbegin () const
393 {
394 return leafView().template begin< codim, pitype >();
395 }
396
397 template< int codim, PartitionIteratorType pitype >
398 typename Codim< codim >::template Partition< pitype >::LeafIterator
399 leafend () const
400 {
401 return leafView().template end< codim, pitype >();
402 }
403
404 const GlobalIdSet &globalIdSet () const
405 {
406 if( !globalIdSet_ )
407 globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
408 assert( globalIdSet_ );
409 return globalIdSet_;
410 }
411
412 const LocalIdSet &localIdSet () const
413 {
414 if( !localIdSet_ )
415 localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
416 assert( localIdSet_ );
417 return localIdSet_;
418 }
419
420 const LevelIndexSet &levelIndexSet ( int level ) const
421 {
422 assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
423 if( (level < 0) || (level > maxLevel()) )
424 {
425 DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
426 << " requested." );
427 }
428
429 LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
430 if( !levelIndexSet )
431 levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
432 assert( levelIndexSet );
433 return *levelIndexSet;
434 }
435
436 const LeafIndexSet &leafIndexSet () const
437 {
438 if( !leafIndexSet_ )
439 leafIndexSet_ = LeafIndexSet( hostGrid().leafIndexSet() );
440 assert( leafIndexSet_ );
441 return leafIndexSet_;
442 }
443
444 void globalRefine ( int refCount )
445 {
446 hostGrid().globalRefine( refCount );
447 update();
448 }
449
450 bool mark ( int refCount, const typename Codim< 0 >::Entity &entity )
451 {
452 return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
453 }
454
455 int getMark ( const typename Codim< 0 >::Entity &entity ) const
456 {
457 return hostGrid().getMark( getHostEntity< 0 >( entity ) );
458 }
459
460 bool preAdapt ()
461 {
462 return hostGrid().preAdapt();
463 }
464
465 bool adapt ()
466 {
467 bool ret = hostGrid().adapt();
468 update();
469 return ret;
470 }
471
472 void postAdapt ()
473 {
474 hostGrid().postAdapt();
475 }
476
484 int overlapSize ( int codim ) const
485 {
486 return leafView().overlapSize( codim );
487 }
488
493 int ghostSize( int codim ) const
494 {
495 return leafView().ghostSize( codim );
496 }
497
503 int overlapSize ( int level, int codim ) const
504 {
505 return levelView( level ).overlapSize( codim );
506 }
507
513 int ghostSize ( int level, int codim ) const
514 {
515 return levelView( level ).ghostSize( codim );
516 }
517
531 template< class DataHandle, class Data >
533 InterfaceType interface,
534 CommunicationDirection direction,
535 int level ) const
536 {
537 levelView( level ).communicate( dataHandle, interface, direction );
538 }
539
552 template< class DataHandle, class Data >
554 InterfaceType interface,
555 CommunicationDirection direction ) const
556 {
557 leafView().communicate( dataHandle, interface, direction );
558 }
559
569 {
570 return hostGrid().comm();
571 }
572
573#if 0
574 // data handle interface different between geo and interface
575
585 bool loadBalance ()
586 {
587 const bool gridChanged= hostGrid().loadBalance();
588 if( gridChanged )
589 update();
590 return gridChanged;
591 }
592
608 template< class DataHandle, class Data >
609 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
610 {
611 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
612 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
613
614 WrappedDataHandle wrappedDataHandle( *this, datahandle );
615 const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
616 if( gridChanged )
617 update();
618 return gridChanged;
619 }
620#endif
621
623 template< class EntitySeed >
625 entityPointer ( const EntitySeed &seed ) const
626 {
627 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityPointerImpl EntityPointerImpl;
628 return EntityPointerImpl( *this, seed );
629 }
630
637 template< PartitionIteratorType pitype >
638 typename Partition< pitype >::LevelGridView levelView ( int level ) const
639 {
640 typedef typename Partition< pitype >::LevelGridView View;
641 typedef typename View::GridViewImp ViewImp;
642 return View( ViewImp( *this, hostGrid().levelView( level ) ) );
643 }
644
645 template< PartitionIteratorType pitype >
646 typename Partition< pitype >::LevelGridView levelGridView ( int level ) const
647 {
648 return levelView<pitype>(level);
649 }
650
652 template< PartitionIteratorType pitype >
653 typename Partition< pitype >::LeafGridView leafView () const
654 {
655 typedef typename Traits::template Partition< pitype >::LeafGridView View;
656 typedef typename View::GridViewImp ViewImp;
657 return View( ViewImp( *this, hostGrid().leafView() ) );
658 }
659
660 template< PartitionIteratorType pitype >
661 typename Partition< pitype >::LeafGridView leafGridView () const
662 {
663 return leafGridView<pitype>();
664 }
665
667 LevelGridView levelView ( int level ) const
668 {
669 typedef typename LevelGridView::GridViewImp ViewImp;
670 return LevelGridView( ViewImp( *this, hostGrid().levelView( level ) ) );
671 }
672
673
674 LevelGridView levelGridView ( int level ) const
675 {
676 return levelView(level);
677 }
678
680 LeafGridView leafView () const
681 {
682 typedef typename LeafGridView::GridViewImp ViewImp;
683 return LeafGridView( ViewImp( *this, hostGrid().leafView() ) );
684 }
685
686 LeafGridView leafGridView () const
687 {
688 return leafView();
689 }
690
696 const HostGrid &hostGrid () const
697 {
698 return *hostGrid_;
699 }
700
701 HostGrid &hostGrid ()
702 {
703 return *hostGrid_;
704 }
705
714 void update ()
715 {
716 // adapt the coordinate function
717 GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction_ );
718
719 const int newNumLevels = maxLevel()+1;
720 const int oldNumLevels = levelIndexSets_.size();
721
722 for( int i = newNumLevels; i < oldNumLevels; ++i )
723 {
724 if( levelIndexSets_[ i ] )
725 delete levelIndexSets_[ i ];
726 }
727 levelIndexSets_.resize( newNumLevels, nullptr );
728 }
729
733
734 protected:
735 const CoordFunction &coordFunction () const
736 {
737 return coordFunction_;
738 }
739
740 template< int codim >
741 static const typename HostGrid::template Codim< codim >::Entity &
742 getHostEntity( const typename Codim< codim >::Entity &entity )
743 {
744 return getRealImplementation( entity ).hostEntity();
745 }
746
747 void *allocateStorage ( std::size_t size ) const
748 {
749 return storageAllocator_.allocate( size );
750 }
751
752 void deallocateStorage ( void *p, std::size_t size ) const
753 {
754 storageAllocator_.deallocate( (char *)p, size );
755 }
756
757 private:
758 HostGrid *const hostGrid_;
759 CoordFunction &coordFunction_;
760 bool removeHostGrid_;
761 mutable std::vector< LevelIndexSet *, typename Allocator::template rebind< LevelIndexSet * >::other > levelIndexSets_;
762 mutable LeafIndexSet leafIndexSet_;
763 mutable GlobalIdSet globalIdSet_;
764 mutable LocalIdSet localIdSet_;
765 mutable typename Allocator::template rebind< char >::other storageAllocator_;
766 };
767
768
769
770 // GeometryGrid::Codim
771 // -------------------
772
773 template< class HostGrid, class CoordFunction, class Allocator >
774 template< int codim >
775 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
776 : public Base::template Codim< codim >
777 {
785 typedef typename Traits::template Codim< codim >::Entity Entity;
786
791 typedef typename Traits::template Codim< codim >::EntityPointer EntityPointer;
792
806 typedef typename Traits::template Codim< codim >::Geometry Geometry;
807
816 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
817
823 template< PartitionIteratorType pitype >
824 struct Partition
825 {
826 typedef typename Traits::template Codim< codim >
827 ::template Partition< pitype >::LeafIterator
829 typedef typename Traits::template Codim< codim >
830 ::template Partition< pitype >::LevelIterator
832 };
833
841 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
842
850 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
851
853 };
854
855} // namespace Dune
856
857#endif // #ifndef DUNE_GEOGRID_GRID_HH
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:75
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:24
actual implementation of the entity
Definition: entity.hh:34
grid wrapper replacing the geometries
Definition: grid.hh:83
Partition< pitype >::LeafGridView leafView() const
View for the leaf grid.
Definition: grid.hh:653
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: grid.hh:154
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:291
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:315
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:328
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:136
Traits::template Codim< EntitySeed::codimension >::EntityPointer entityPointer(const EntitySeed &seed) const
obtain EntityPointer from EntitySeed.
Definition: grid.hh:625
Partition< pitype >::LevelGridView levelView(int level) const
View for a grid level.
Definition: grid.hh:638
LevelGridView levelView(int level) const
View for a grid level for All_Partition.
Definition: grid.hh:667
int size(int level, int codim) const
obtain number of entites on a level
Definition: grid.hh:304
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:171
GeometryGrid(HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:254
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:132
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: grid.hh:1223
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:218
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:115
~GeometryGrid()
destructor
Definition: grid.hh:264
int overlapSize(int codim) const
obtain size of overlap region for the leaf grid
Definition: grid.hh:484
LeafGridView leafView() const
View for the leaf grid for All_Partition.
Definition: grid.hh:680
void communicate(CommDataHandleIF< DataHandle, Data > &dataHandle, InterfaceType interface, CommunicationDirection direction) const
communicate information on leaf entities
Definition: grid.hh:553
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:181
int ghostSize(int level, int codim) const
obtain size of ghost region for a grid level
Definition: grid.hh:513
void communicate(CommDataHandleIF< DataHandle, Data > &dataHandle, InterfaceType interface, CommunicationDirection direction, int level) const
communicate information on a grid level
Definition: grid.hh:532
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:210
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:193
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:134
int ghostSize(int codim) const
obtain size of ghost region for the leaf grid
Definition: grid.hh:493
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: grid.hh:221
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:346
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:337
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:237
void update()
update grid caches
Definition: grid.hh:714
int overlapSize(int level, int codim) const
obtain size of overlap region for a grid level
Definition: grid.hh:503
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:568
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Definition: grid.hh:1017
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: grid.hh:1223
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:164
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
Fallback implementation of the nullptr object in C++0x.
Fallback implementation of the C++0x static_assert feature.
traits structure containing types for a codimension
Definition: grid.hh:777
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:816
Partition< All_Partition >::LeafIterator LeafIterator
type of level iterator
Definition: grid.hh:841
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:785
Partition< All_Partition >::LevelIterator LevelIterator
type of leaf iterator
Definition: grid.hh:850
Traits::template Codim< codim >::EntityPointer EntityPointer
type of entity pointer
Definition: grid.hh:791
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:806
Types for GridView.
Definition: grid.hh:146
provides access to host grid objects
Definition: hostgridaccess.hh:25
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)