Dune Core Modules (2.9.0)

grid.hh
1// SPDX-FileCopyrightText: Copyright (C) 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
11
13
14#include <dune/grid/geometrygrid/backuprestore.hh>
15#include <dune/grid/geometrygrid/capabilities.hh>
16#include <dune/grid/geometrygrid/datahandle.hh>
17#include <dune/grid/geometrygrid/gridfamily.hh>
18#include <dune/grid/geometrygrid/identity.hh>
19#include <dune/grid/geometrygrid/persistentcontainer.hh>
20
21namespace Dune
22{
23
24 // DefaultCoordFunction
25 // --------------------
26
27 template< class HostGrid >
28 class DefaultCoordFunction
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 > >
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,
91 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
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:
109 typedef GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > GridFamily;
116 typedef typename GridFamily::Traits Traits;
117
124 template< int codim >
125 struct Codim;
126
133 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
210 typedef typename Traits::ctype ctype;
211
213 typedef typename Traits::Communication Communication;
214
217 [[deprecated("Use Communication instead!!")]]
219
234 GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
235 : hostGrid_( Dune::stackobject_to_shared_ptr(hostGrid) ),
236 coordFunction_( Dune::stackobject_to_shared_ptr(coordFunction) ),
237 levelIndexSets_( hostGrid_->maxLevel()+1 ),
238 storageAllocator_( allocator )
239 {}
240
250 GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, std::shared_ptr<CoordFunction> coordFunction, const Allocator &allocator = Allocator() )
251 : hostGrid_( hostGrid ),
252 coordFunction_( coordFunction ),
253 levelIndexSets_( hostGrid_->maxLevel()+1 ),
254 storageAllocator_( allocator )
255 {}
256
266 GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, const Allocator &allocator = Allocator() )
267 : hostGrid_( hostGrid ),
268 coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
269 levelIndexSets_( hostGrid_->maxLevel()+1 ),
270 storageAllocator_( allocator )
271 {}
272
273
274
287 int maxLevel () const
288 {
289 return hostGrid().maxLevel();
290 }
291
300 int size ( int level, int codim ) const
301 {
302 return levelGridView( level ).size( codim );
303 }
304
311 int size ( int codim ) const
312 {
313 return leafGridView().size( codim );
314 }
315
324 int size ( int level, GeometryType type ) const
325 {
326 return levelGridView( level ).size( type );
327 }
328
333 int size ( GeometryType type ) const
334 {
335 return leafGridView().size( type );
336 }
337
342 size_t numBoundarySegments () const
343 {
344 return hostGrid().numBoundarySegments( );
345 }
348 const GlobalIdSet &globalIdSet () const
349 {
350 if( !globalIdSet_ )
351 globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
352 assert( globalIdSet_ );
353 return globalIdSet_;
354 }
355
356 const LocalIdSet &localIdSet () const
357 {
358 if( !localIdSet_ )
359 localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
360 assert( localIdSet_ );
361 return localIdSet_;
362 }
363
364 const LevelIndexSet &levelIndexSet ( int level ) const
365 {
366 assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
367 if( (level < 0) || (level > maxLevel()) )
368 {
369 DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
370 << " requested." );
371 }
372
373 auto& levelIndexSetPtr = levelIndexSets_[ level ];
374 if( !levelIndexSetPtr )
375 levelIndexSetPtr = std::make_unique<LevelIndexSet>( hostGrid().levelIndexSet( level ) );
376 assert( levelIndexSetPtr );
377 return *levelIndexSetPtr;
378 }
379
380 const LeafIndexSet &leafIndexSet () const
381 {
382 if( !leafIndexSet_ )
383 leafIndexSet_.reset( hostGrid().leafIndexSet() );
384 assert( leafIndexSet_ );
385 return leafIndexSet_;
386 }
387
388 void globalRefine ( int refCount )
389 {
390 hostGrid().globalRefine( refCount );
391 update();
392 }
393
394 bool mark ( int refCount, const typename Codim< 0 >::Entity &entity_ )
395 {
396 return hostGrid().mark( refCount, getHostEntity< 0 >( entity_ ) );
397 }
398
399 int getMark ( const typename Codim< 0 >::Entity &entity_ ) const
400 {
401 return hostGrid().getMark( getHostEntity< 0 >( entity_ ) );
402 }
403
404 bool preAdapt ()
405 {
406 return hostGrid().preAdapt();
407 }
408
409 bool adapt ()
410 {
411 bool ret = hostGrid().adapt();
412 update();
413 return ret;
414 }
415
416 void postAdapt ()
417 {
418 hostGrid().postAdapt();
419 }
420
432 const Communication &comm () const
433 {
434 return hostGrid().comm();
435 }
436
437#if 0
438 // data handle interface different between geo and interface
439
449 bool loadBalance ()
450 {
451 const bool gridChanged= hostGrid().loadBalance();
452 if( gridChanged )
453 update();
454 return gridChanged;
455 }
456
472 template< class DataHandle, class Data >
473 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
474 {
475 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
476 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
477
478 WrappedDataHandle wrappedDataHandle( *this, datahandle );
479 const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
480 if( gridChanged )
481 update();
482 return gridChanged;
483 }
484#endif
485
505 template< class EntitySeed >
506 typename Traits::template Codim< EntitySeed::codimension >::Entity
507 entity ( const EntitySeed &seed ) const
508 {
509 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
510 return EntityImpl( *this, seed );
511 }
512
519 LevelGridView levelGridView ( int level ) const
520 {
521 typedef typename LevelGridView::GridViewImp ViewImp;
522 return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
523 }
524
527 {
528 typedef typename LeafGridView::GridViewImp ViewImp;
529 return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
530 }
531
538 const HostGrid &hostGrid () const
539 {
540 return *hostGrid_;
541 }
542
544 HostGrid &hostGrid ()
545 {
546 return *hostGrid_;
547 }
548
557 void update ()
558 {
559 // adapt the coordinate function
560 GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction() );
561
562 levelIndexSets_.resize( maxLevel()+1 );
563 }
564
565
567 const CoordFunction &coordFunction () const { return *coordFunction_; }
568
570 CoordFunction &coordFunction () { return *coordFunction_; }
571
574 protected:
575 template< int codim >
576 static const typename HostGrid::template Codim< codim >::Entity &
577 getHostEntity( const typename Codim< codim >::Entity &entity )
578 {
579 return entity.impl().hostEntity();
580 }
581
582 void *allocateStorage ( std::size_t size ) const
583 {
584 return storageAllocator_.allocate( size );
585 }
586
587 void deallocateStorage ( void *p, std::size_t size ) const
588 {
589 storageAllocator_.deallocate( (char *)p, size );
590 }
591
592 private:
593 std::shared_ptr<HostGrid> const hostGrid_;
594 std::shared_ptr<CoordFunction> coordFunction_;
595 mutable std::vector<std::unique_ptr<LevelIndexSet>> levelIndexSets_;
596 mutable LeafIndexSet leafIndexSet_;
597 mutable GlobalIdSet globalIdSet_;
598 mutable LocalIdSet localIdSet_;
599 mutable typename std::allocator_traits<Allocator>::template rebind_alloc< char > storageAllocator_;
600 };
601
602
603
604 // GeometryGrid::Codim
605 // -------------------
606
607 template< class HostGrid, class CoordFunction, class Allocator >
608 template< int codim >
609 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
610 : public Base::template Codim< codim >
611 {
619 typedef typename Traits::template Codim< codim >::Entity Entity;
620
634 typedef typename Traits::template Codim< codim >::Geometry Geometry;
635
644 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
645
651 template< PartitionIteratorType pitype >
652 struct Partition
653 {
654 typedef typename Traits::template Codim< codim >
655 ::template Partition< pitype >::LeafIterator
657 typedef typename Traits::template Codim< codim >
658 ::template Partition< pitype >::LevelIterator
660 };
661
669 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
670
678 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
679
681 };
682
683} // namespace Dune
684
685#endif // #ifndef DUNE_GEOGRID_GRID_HH
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:26
Implementation & impl()
access to the underlying implementation
Definition: entity.hh:80
actual implementation of the entity
Definition: entity.hh:34
grid wrapper replacing the geometries
Definition: grid.hh:86
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:287
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: grid.hh:570
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:311
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:324
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: grid.hh:567
LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:526
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:137
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: grid.hh:507
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: grid.hh:519
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:250
int size(int level, int codim) const
obtain number of entites on a level
Definition: grid.hh:300
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:163
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:133
Traits::Communication Communication
communicator with all other processes having some part of the grid
Definition: grid.hh:213
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: grid.hh:538
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:210
const Communication & comm() const
obtain Communication object
Definition: grid.hh:432
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:116
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:147
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: grid.hh:544
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:173
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:202
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:185
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:135
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:266
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: grid.hh:145
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:342
Communication CollectiveCommunication
Definition: grid.hh:218
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:333
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:234
void update()
update grid caches
Definition: grid.hh:557
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
Definition: grid.hh:862
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
STL namespace.
This file implements several utilities related to std::shared_ptr.
Static tag representing a codimension.
Definition: dimension.hh:24
traits structure containing types for a codimension
Definition: grid.hh:611
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:644
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: grid.hh:669
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:619
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: grid.hh:678
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:634
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)