DataHandleWrappers.hpp
Go to the documentation of this file.
1//===========================================================================
2//
3// File: DataHandleWrappers.hpp
4//
5// Created: Mon Nov 4 2013
6//
7// Author(s): Markus Blatt <markus@dr-blatt.de>
8//
9// $Date$
10//
11// $Revision$
12//
13//===========================================================================
32#ifndef OPM_DATAHANDLEWRAPPERS_HEADER
33#define OPM_DATAHANDLEWRAPPERS_HEADER
34
36#include "EntityRep.hpp"
37
38#include <array>
39#include <numeric>
40#include <vector>
41
42namespace Dune::cpgrid {
43
55template<class Handle>
57{
58 using DataType = typename Handle::DataType;
60
67 const C2FTable& c2fGather,
68 const C2FTable& c2f)
69 : handle_(handle), c2fGather_(c2fGather), c2f_(c2f)
70 {}
71
72 bool fixedSize(int, int)
73 {
74 return false; // as the faces per cell differ
75 }
76 template<class T>
77 typename std::enable_if<T::codimension != 0, std::size_t>::type
78 size(const T&)
79 {
80 OPM_THROW(std::logic_error, "This should never throw! We only know sizes for cells");
81 return 1;
82 }
83 std::size_t size(const EntityRep<0>& t)
84 {
85 const auto& faces = c2fGather_[t];
86 return std::accumulate(faces.begin(), faces.end(), std::size_t{0},
87 [this](const auto acc, const auto& face)
88 { return acc + handle_.size(face); });
89 }
90 bool contains(std::size_t dim, std::size_t codim)
91 {
92 return dim==3 && codim == 0;
93 }
94 template<class B, class T>
95 typename std::enable_if<T::codimension != 0, void>::type
96 gather(B&, const T&)
97 {
98 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
99 }
100 template<class B>
101 void gather(B& buffer, const EntityRep<0>& t)
102 {
103 const auto& faces = c2fGather_[t];
104 for (const auto& face : faces)
105 {
106 handle_.gather(buffer, face);
107 }
108 }
109 template<class B, class T>
110 typename std::enable_if<T::codimension != 0, void>::type
111 scatter(B&, const T&, std::size_t)
112 {
113 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
114 }
115 template<class B>
116 void scatter(B& buffer, const EntityRep<0>& t, std::size_t)
117 {
118 const auto& faces = c2f_[t];
119 for (const auto& face : faces)
120 {
121 // Note that the size (last parameter) is not correct here.
122 // Therefore this handle needs to know how many data items
123 // to expect. Not usable outside of CpGrid.
124 handle_.scatter(buffer, face, 1);
125 }
126 }
127private:
128 Handle& handle_;
129 const C2FTable& c2fGather_, c2f_;
130};
131
133{
134 static bool printWarn;
135 void warn();
136};
137
147template<class Handle>
149{
150 using DataType = typename Handle::DataType;
151 using C2PTable = std::vector< std::array<int,8> >;
152
159 const C2PTable& c2pGather,
160 const C2PTable& c2p)
161 : handle_(handle), c2pGather_(c2pGather), c2p_(c2p)
162 {}
163 bool fixedSize(int i, int j)
164 {
165 if( ! handle_.fixedSize(i, j))
166 {
167 this->warn();
168 }
169 return handle_.fixedSize(i, j);
170 }
171 template<class T>
172 typename std::enable_if<T::codimension != 0, std::size_t>::type
173 size(const T&)
174 {
175 OPM_THROW(std::logic_error, "This should never throw! We only know sizes for cells");
176 return 1;
177 }
178 std::size_t size(const EntityRep<0>& t)
179 {
180 const auto& points = c2pGather_[t.index()];
181 return std::accumulate(points.begin(), points.end(), std::size_t{0},
182 [this](const auto acc, const auto& point)
183 { return acc + handle_.size(EntityRep<3>(point, true)); });
184 }
185 bool contains(std::size_t dim, std::size_t codim)
186 {
187 return dim==3 && codim == 0;
188 }
189 template<class B, class T>
190 typename std::enable_if<T::codimension != 0, void>::type
191 gather(B&, const T&)
192 {
193 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
194 }
195 template<class B>
196 void gather(B& buffer, const EntityRep<0>& t)
197 {
198 const auto& points = c2pGather_[t.index()];
199 for (const auto& point : points)
200 {
201 handle_.gather(buffer, EntityRep<3>(point, true));
202 }
203 }
204 template<class B, class T>
205 typename std::enable_if<T::codimension != 0, void>::type
206 scatter(B&, const T&, std::size_t)
207 {
208 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
209 }
210 template<class B>
211 void scatter(B& buffer, const EntityRep<0>& t, std::size_t s)
212 {
213 const auto& points = c2p_[t.index()];
214 for (const auto& point : points)
215 {
216 handle_.scatter(buffer, EntityRep<3>(point, true), s/8);
217 }
218 }
219private:
220 Handle& handle_;
221 const C2PTable& c2pGather_, c2p_;
222};
223
224} // end namespace Dune::cpgrid
225
226#endif
mover::MoveBuffer< typename DataHandle::DataType > & buffer
Definition: CpGridData.hpp:1268
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:99
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:126
Definition: GridPartitioning.hpp:121
A data handle to send data attached to faces via cell communication.
Definition: DataHandleWrappers.hpp:57
void scatter(B &buffer, const EntityRep< 0 > &t, std::size_t)
Definition: DataHandleWrappers.hpp:116
typename Handle::DataType DataType
Definition: DataHandleWrappers.hpp:58
std::size_t size(const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:83
FaceViaCellHandleWrapper(Handle &handle, const C2FTable &c2fGather, const C2FTable &c2f)
Constructs the data handle.
Definition: DataHandleWrappers.hpp:66
bool contains(std::size_t dim, std::size_t codim)
Definition: DataHandleWrappers.hpp:90
OrientedEntityTable< 0, 1 > C2FTable
Definition: DataHandleWrappers.hpp:59
std::enable_if< T::codimension!=0, void >::type scatter(B &, const T &, std::size_t)
Definition: DataHandleWrappers.hpp:111
void gather(B &buffer, const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:101
std::enable_if< T::codimension!=0, std::size_t >::type size(const T &)
Definition: DataHandleWrappers.hpp:78
bool fixedSize(int, int)
Definition: DataHandleWrappers.hpp:72
std::enable_if< T::codimension!=0, void >::type gather(B &, const T &)
Definition: DataHandleWrappers.hpp:96
A data handle to send data attached to points via cell communication.
Definition: DataHandleWrappers.hpp:149
std::size_t size(const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:178
PointViaCellHandleWrapper(Handle &handle, const C2PTable &c2pGather, const C2PTable &c2p)
Constructs the data handle.
Definition: DataHandleWrappers.hpp:158
std::enable_if< T::codimension!=0, std::size_t >::type size(const T &)
Definition: DataHandleWrappers.hpp:173
typename Handle::DataType DataType
Definition: DataHandleWrappers.hpp:150
void scatter(B &buffer, const EntityRep< 0 > &t, std::size_t s)
Definition: DataHandleWrappers.hpp:211
void gather(B &buffer, const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:196
std::vector< std::array< int, 8 > > C2PTable
Definition: DataHandleWrappers.hpp:151
bool fixedSize(int i, int j)
Definition: DataHandleWrappers.hpp:163
bool contains(std::size_t dim, std::size_t codim)
Definition: DataHandleWrappers.hpp:185
std::enable_if< T::codimension!=0, void >::type scatter(B &, const T &, std::size_t)
Definition: DataHandleWrappers.hpp:206
std::enable_if< T::codimension!=0, void >::type gather(B &, const T &)
Definition: DataHandleWrappers.hpp:191
Definition: DataHandleWrappers.hpp:133
static bool printWarn
Definition: DataHandleWrappers.hpp:134