My Project
DataHandleWrappers.hpp
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
38#include "OrientedEntityTable.hpp"
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
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
A data handle to send data attached to faces via cell communication.
Definition: DataHandleWrappers.hpp:59
FaceViaCellHandleWrapper(Handle &handle, const C2FTable &c2fGather, const C2FTable &c2f)
Constructs the data handle.
Definition: DataHandleWrappers.hpp:68
A data handle to send data attached to points via cell communication.
Definition: DataHandleWrappers.hpp:154
PointViaCellHandleWrapper(Handle &handle, const C2PTable &c2pGather, const C2PTable &c2p)
Constructs the data handle.
Definition: DataHandleWrappers.hpp:163
Definition: DataHandleWrappers.hpp:138