DUNE-FEM (unstable)

datahandle.hh
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
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 >
32 class DataHandle;
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 {
43 using ThisType = DataHandle< DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys > >;
45
46 using BlockMapperType = DiscontinuousGalerkinBlockMapper< GridPart, LocalKeys >;
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
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
static constexpr int codimension
Know your own codimension.
Definition: entity.hh:106
Describes the parallel communication interface class for MessageBuffers and DataHandles.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
std::size_t fixedSize
The number of data items per index if it is fixed, 0 otherwise.
Definition: variablesizecommunicator.hh:264
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)