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
35#include <array>
36#include <vector>
37
39#include "EntityRep.hpp"
40
41namespace Dune
42{
43namespace cpgrid
44{
45
57template<class Handle>
59{
60 using DataType = typename Handle::DataType;
62
69 const C2FTable& c2fGather,
70 const C2FTable& c2f)
71 : handle_(handle), c2fGather_(c2fGather), c2f_(c2f)
72 {}
73
74 bool fixedSize(int, int)
75 {
76 return false; // as the faces per cell differ
77 }
78 template<class T>
79 typename std::enable_if<T::codimension != 0, std::size_t>::type
80 size(const T&)
81 {
82 OPM_THROW(std::logic_error, "This should never throw! We only know sizes for cells");
83 return 1;
84 }
85 std::size_t size(const EntityRep<0>& t)
86 {
87 const auto& faces = c2fGather_[t];
88 std::size_t size{};
89 for (const auto& face : faces)
90 {
91 size += handle_.size(face);
92 }
93 return size;
94 }
95 bool contains(std::size_t dim, std::size_t codim)
96 {
97 return dim==3 && codim == 0;
98 }
99 template<class B, class T>
100 typename std::enable_if<T::codimension != 0, void>::type
101 gather(B&, const T&)
102 {
103 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
104 }
105 template<class B>
106 void gather(B& buffer, const EntityRep<0>& t)
107 {
108 const auto& faces = c2fGather_[t];
109 for (const auto& face : faces)
110 {
111 handle_.gather(buffer, face);
112 }
113 }
114 template<class B, class T>
115 typename std::enable_if<T::codimension != 0, void>::type
116 scatter(B&, const T&, std::size_t)
117 {
118 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
119 }
120 template<class B>
121 void scatter(B& buffer, const EntityRep<0>& t, std::size_t)
122 {
123 const auto& faces = c2f_[t];
124 for (const auto& face : faces)
125 {
126 // Note that the size (last parameter) is not correct here.
127 // Therefore this handle needs to know how many data items
128 // to expect. Not usable outside of CpGrid.
129 handle_.scatter(buffer, face, 1);
130 }
131 }
132private:
133 Handle& handle_;
134 const C2FTable& c2fGather_, c2f_;
135};
136
138{
139 static bool printWarn;
140 void warn();
141};
142
152template<class Handle>
154{
155 using DataType = typename Handle::DataType;
156 using C2PTable = std::vector< std::array<int,8> >;
157
164 const C2PTable& c2pGather,
165 const C2PTable& c2p)
166 : handle_(handle), c2pGather_(c2pGather), c2p_(c2p)
167 {}
168 bool fixedSize(int i, int j)
169 {
170 if( ! handle_.fixedSize(i, j))
171 {
172 this->warn();
173 }
174 return handle_.fixedSize(i, j);
175 }
176 template<class T>
177 typename std::enable_if<T::codimension != 0, std::size_t>::type
178 size(const T&)
179 {
180 OPM_THROW(std::logic_error, "This should never throw! We only know sizes for cells");
181 return 1;
182 }
183 std::size_t size(const EntityRep<0>& t)
184 {
185 const auto& points = c2pGather_[t.index()];
186 std::size_t size{};
187 for (const auto& point : points)
188 {
189 size += handle_.size(EntityRep<3>(point, true));
190 }
191 return size;
192 }
193 bool contains(std::size_t dim, std::size_t codim)
194 {
195 return dim==3 && codim == 0;
196 }
197 template<class B, class T>
198 typename std::enable_if<T::codimension != 0, void>::type
199 gather(B&, const T&)
200 {
201 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
202 }
203 template<class B>
204 void gather(B& buffer, const EntityRep<0>& t)
205 {
206 const auto& points = c2pGather_[t.index()];
207 for (const auto& point : points)
208 {
209 handle_.gather(buffer, EntityRep<3>(point, true));
210 }
211 }
212 template<class B, class T>
213 typename std::enable_if<T::codimension != 0, void>::type
214 scatter(B&, const T&, std::size_t)
215 {
216 OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
217 }
218 template<class B>
219 void scatter(B& buffer, const EntityRep<0>& t, std::size_t s)
220 {
221 const auto& points = c2p_[t.index()];
222 for (const auto& point : points)
223 {
224 handle_.scatter(buffer, EntityRep<3>(point, true), s/8);
225 }
226 }
227private:
228 Handle& handle_;
229 const C2PTable& c2pGather_, c2p_;
230};
231
232} // end namespace cpgrid
233} // end namespace Dune
234#endif
mover::MoveBuffer< typename DataHandle::DataType > & buffer
Definition: CpGridData.hpp:1103
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
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
A data handle to send data attached to faces via cell communication.
Definition: DataHandleWrappers.hpp:59
void scatter(B &buffer, const EntityRep< 0 > &t, std::size_t)
Definition: DataHandleWrappers.hpp:121
typename Handle::DataType DataType
Definition: DataHandleWrappers.hpp:60
std::size_t size(const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:85
FaceViaCellHandleWrapper(Handle &handle, const C2FTable &c2fGather, const C2FTable &c2f)
Constructs the data handle.
Definition: DataHandleWrappers.hpp:68
bool contains(std::size_t dim, std::size_t codim)
Definition: DataHandleWrappers.hpp:95
OrientedEntityTable< 0, 1 > C2FTable
Definition: DataHandleWrappers.hpp:61
std::enable_if< T::codimension!=0, void >::type scatter(B &, const T &, std::size_t)
Definition: DataHandleWrappers.hpp:116
void gather(B &buffer, const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:106
std::enable_if< T::codimension!=0, std::size_t >::type size(const T &)
Definition: DataHandleWrappers.hpp:80
bool fixedSize(int, int)
Definition: DataHandleWrappers.hpp:74
std::enable_if< T::codimension!=0, void >::type gather(B &, const T &)
Definition: DataHandleWrappers.hpp:101
A data handle to send data attached to points via cell communication.
Definition: DataHandleWrappers.hpp:154
std::size_t size(const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:183
PointViaCellHandleWrapper(Handle &handle, const C2PTable &c2pGather, const C2PTable &c2p)
Constructs the data handle.
Definition: DataHandleWrappers.hpp:163
std::enable_if< T::codimension!=0, std::size_t >::type size(const T &)
Definition: DataHandleWrappers.hpp:178
typename Handle::DataType DataType
Definition: DataHandleWrappers.hpp:155
void scatter(B &buffer, const EntityRep< 0 > &t, std::size_t s)
Definition: DataHandleWrappers.hpp:219
void gather(B &buffer, const EntityRep< 0 > &t)
Definition: DataHandleWrappers.hpp:204
std::vector< std::array< int, 8 > > C2PTable
Definition: DataHandleWrappers.hpp:156
bool fixedSize(int i, int j)
Definition: DataHandleWrappers.hpp:168
bool contains(std::size_t dim, std::size_t codim)
Definition: DataHandleWrappers.hpp:193
std::enable_if< T::codimension!=0, void >::type scatter(B &, const T &, std::size_t)
Definition: DataHandleWrappers.hpp:214
std::enable_if< T::codimension!=0, void >::type gather(B &, const T &)
Definition: DataHandleWrappers.hpp:199
Definition: DataHandleWrappers.hpp:138
static bool printWarn
Definition: DataHandleWrappers.hpp:139