dune-fem 2.8.0
Loading...
Searching...
No Matches
space/hpdg/datahandle.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_DATAHANDLE_HH
2#define DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_DATAHANDLE_HH
3
4#include <cassert>
5#include <cstddef>
6
7#include <functional>
8
9#include <dune/grid/common/datahandleif.hh>
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 namespace hpDG
18 {
19
20 // External forward declaration
21 // ----------------------------
22
23 template< class GridPart, class LocalKeys >
24 struct DiscontinuousGalerkinBlockMapper;
25
26
27
28 // Internal forward declaration
29 // ----------------------------
30
31 template< class BlockMapper >
33
34
35
36 // DataHandle
37 // ----------
38
39 template< class GridPart, class LocalKeys >
40 class DataHandle< DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys > >
41 : public Dune::CommDataHandleIF< DataHandle< DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys > >, typename LocalKeys::DataType >
42 {
44 using BaseType = Dune::CommDataHandleIF< DataHandle< DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys > >, typename LocalKeys::DataType >;
45
47
48 public:
50 using KeyType = typename LocalKeys::KeyType;
52 using DataType = typename BaseType::DataType;
53
58 explicit DataHandle ( BlockMapperType &blockMapper )
59 : blockMapper_( blockMapper )
60 {}
61
68 DataHandle ( const ThisType & ) = default;
69
70 ThisType &operator= ( const ThisType & ) = default;
71
72 DataHandle ( ThisType && ) = default;
73
74 ThisType &operator= ( ThisType && ) = default;
75
82 bool contains ( int dim, int codim ) const { return (codim == 0); }
83
84 bool fixedSize ( int dim, int codim ) const { return true; }
85
86 template< class Entity >
87 std::size_t size ( const Entity &entity ) const
88 {
89 return (Entity::codimension == 0 ? 1u : 0u);
90 }
91
92 template< class Buffer, class Entity >
93 void gather ( Buffer &buffer, const Entity &entity ) const
94 {
95 const auto &keys = blockMapper().keys_[ entity ];
96 buffer.write( encode( keys.second ) );
97 }
98
99 template< class Buffer, class Entity >
100 void scatter ( Buffer &buffer, const Entity &entity, std::size_t n )
101 {
102 assert( n == 1u );
103 auto &keys = blockMapper().keys_[ entity ];
104 DataType data;
105 buffer.read( data );
106 keys.second = decode( data );
107 }
108
111 private:
112 DataType encode ( const KeyType &key ) const { return localKeys().encode( key ); }
113
114 KeyType decode ( const DataType &data ) const { return localKeys().decode( data ); }
115
116 KeyType reduce ( const KeyType &a, const KeyType &b ) const { return localKeys().reduce( a, b ); }
117
118 const LocalKeys &localKeys () const { return blockMapper().localKeys(); }
119
120 BlockMapperType &blockMapper () { return blockMapper_.get(); }
121
122 const BlockMapperType &blockMapper () const { return blockMapper_.get(); }
123
124 std::reference_wrapper< BlockMapperType > blockMapper_;
125 };
126
127 } // namespace hpDG
128
129 } // namespace Fem
130
131} // namespace Dune
132
133#endif // #ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_DATAHANDLE_HH
Definition: bindguard.hh:11
An -adaptive Dune::Fem::DofMapper.
Definition: blockmapper.hh:102
Definition: space/hpdg/datahandle.hh:32
bool fixedSize(int dim, int codim) const
Definition: space/hpdg/datahandle.hh:84
DataHandle(BlockMapperType &blockMapper)
Definition: space/hpdg/datahandle.hh:58
void scatter(Buffer &buffer, const Entity &entity, std::size_t n)
Definition: space/hpdg/datahandle.hh:100
std::size_t size(const Entity &entity) const
Definition: space/hpdg/datahandle.hh:87
typename BaseType::DataType DataType
data type
Definition: space/hpdg/datahandle.hh:52
typename LocalKeys::KeyType KeyType
key type
Definition: space/hpdg/datahandle.hh:50
bool contains(int dim, int codim) const
Definition: space/hpdg/datahandle.hh:82
void gather(Buffer &buffer, const Entity &entity) const
Definition: space/hpdg/datahandle.hh:93