Dune Core Modules (2.3.1)

datahandle.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_DATAHANDLE_HH
4#define DUNE_GEOGRID_DATAHANDLE_HH
5
7
10#include <dune/grid/geometrygrid/capabilities.hh>
11#include <dune/grid/geometrygrid/entity.hh>
12
13namespace Dune
14{
15
16 namespace GeoGrid
17 {
18
19 template< int codim, class Grid >
20 class EntityProxy
21 {
22 typedef typename remove_const< Grid >::type::Traits Traits;
23
24 typedef typename Traits::template Codim< codim >::Entity Entity;
25 typedef GeoGrid::Entity< codim, Traits::dimension, const Grid > EntityImpl;
26 typedef typename EntityImpl::HostEntity HostEntity;
27
28 template< bool >
29 struct InitReal
30 {
31 static void apply ( EntityImpl &entityImpl, const HostEntity &hostEntity )
32 {
33 entityImpl.initialize( hostEntity );
34 }
35 };
36
37 template< bool >
38 struct InitFake
39 {
40 static void apply ( EntityImpl &entityImpl, const HostEntity &hostEntity )
41 {
42 DUNE_THROW( NotImplemented, "Host grid has no entities for codimension " << codim << "." );
43 }
44 };
45
46 static const bool hasHostEntity = Capabilities::hasHostEntity< Grid, codim >::v;
47 typedef typename conditional< hasHostEntity, InitReal< true >, InitFake< false > >::type Init;
48
49 public:
50 EntityProxy ( const Grid &grid, const HostEntity &hostEntity )
51 : entity_( EntityImpl( grid ) )
52 {
53 Init::apply( Grid::getRealImplementation( entity_ ), hostEntity );
54 }
55
56 const Entity &operator* () const
57 {
58 return entity_;
59 }
60
61 private:
62 Entity entity_;
63 };
64
65
66
67 // GeometryGridDataHandle
68 // ----------------------
69
70 template< class Grid, class WrappedHandle >
71 class CommDataHandle
72 : public CommDataHandleIF< CommDataHandle< Grid, WrappedHandle >, typename WrappedHandle::DataType >
73 {
74 typedef typename remove_const< Grid >::type::Traits Traits;
75
76 public:
77 CommDataHandle ( const Grid &grid, WrappedHandle &handle )
78 : grid_( grid ),
79 wrappedHandle_( handle )
80 {}
81
82 bool contains ( int dim, int codim ) const
83 {
84 const bool contains = wrappedHandle_.contains( dim, codim );
85 if( contains )
86 assertHostEntity( dim, codim );
87 return contains;
88 }
89
90 bool fixedsize ( int dim, int codim ) const
91 {
92 return wrappedHandle_.fixedsize( dim, codim );
93 }
94
95 template< class HostEntity >
96 size_t size ( const HostEntity &hostEntity ) const
97 {
98 EntityProxy< HostEntity::codimension, Grid > proxy( grid_, hostEntity );
99 return wrappedHandle_.size( *proxy );
100 }
101
102 template< class MessageBuffer, class HostEntity >
103 void gather ( MessageBuffer &buffer, const HostEntity &hostEntity ) const
104 {
105 EntityProxy< HostEntity::codimension, Grid > proxy( grid_, hostEntity );
106 wrappedHandle_.gather( buffer, *proxy );
107 }
108
109 template< class MessageBuffer, class HostEntity >
110 void scatter ( MessageBuffer &buffer, const HostEntity &hostEntity, size_t size )
111 {
112 EntityProxy< HostEntity::codimension, Grid > proxy( grid_, hostEntity );
113 wrappedHandle_.scatter( buffer, *proxy, size );
114 }
115
116 private:
117 static void assertHostEntity ( int dim, int codim )
118 {
119 if( !Capabilities::CodimCache< Grid >::hasHostEntity( codim ) )
120 noEntity( codim );
121 }
122
123 static void noEntity ( int codim )
124 {
125 DUNE_THROW( NotImplemented, "Host grid has no entities for codimension " << codim << "." );
126 }
127
128 const Grid &grid_;
129 WrappedHandle &wrappedHandle_;
130 };
131
132 } // namespace GeoGrid
133
134} // namespace Dune
135
136#endif // #ifndef DUNE_GEOGRID_DATAHANDLE_HH
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:135
size_t size(const EntityType &e) const
how many objects of type DataType have to be sent for a given entity
Definition: datahandleif.hh:112
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:123
Different resources needed by all grid implementations.
Describes the parallel communication interface class for MessageBuffers and DataHandles.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)