gridcommhandles.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
29#ifndef EWOMS_GRID_COMM_HANDLES_HH
30#define EWOMS_GRID_COMM_HANDLES_HH
31
32#include <dune/grid/common/datahandleif.hh>
33#include <dune/common/version.hh>
34
35namespace Opm {
36
41template <class FieldType, class Container, class EntityMapper, int commCodim>
43 : public Dune::CommDataHandleIF<GridCommHandleSum<FieldType, Container,
44 EntityMapper, commCodim>,
45 FieldType>
46{
47public:
48 GridCommHandleSum(Container& container, const EntityMapper& mapper)
49 : mapper_(mapper), container_(container)
50 {}
51
52 bool contains(int, int codim) const
53 {
54 // return true if the codim is the same as the codim which we
55 // are asked to communicate with.
56 return codim == commCodim;
57 }
58
59#if DUNE_VERSION_LT(DUNE_GRID, 2, 8)
60 bool fixedsize(int, int) const
61#else
62 bool fixedSize(int, int) const
63#endif
64 {
65 // for each DOF we communicate a single value which has a
66 // fixed size
67 return true;
68 }
69
70 template <class EntityType>
71 size_t size(const EntityType&) const
72 {
73 // communicate a field type per entity
74 return 1;
75 }
76
77 template <class MessageBufferImp, class EntityType>
78 void gather(MessageBufferImp& buff, const EntityType& e) const
79 {
80 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
81 buff.write(container_[dofIdx]);
82 }
83
84 template <class MessageBufferImp, class EntityType>
85 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
86 {
87 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
88
89 FieldType tmp;
90 buff.read(tmp);
91 container_[dofIdx] += tmp;
92 }
93
94private:
95 const EntityMapper& mapper_;
96 Container& container_;
97};
98
104template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
106 : public Dune::CommDataHandleIF<GridCommHandleGhostSync<FieldType, Container,
107 EntityMapper, commCodim>,
108 FieldType>
109{
110public:
111 GridCommHandleGhostSync(Container& container, const EntityMapper& mapper)
112 : mapper_(mapper), container_(container)
113 {
114 }
115
116 bool contains(int, int codim) const
117 {
118 // return true if the codim is the same as the codim which we
119 // are asked to communicate with.
120 return codim == commCodim;
121 }
122
123#if DUNE_VERSION_LT(DUNE_GRID, 2, 8)
124 bool fixedsize(int, int) const
125#else
126 bool fixedSize(int, int) const
127#endif
128 {
129 // for each DOF we communicate a single value which has a
130 // fixed size
131 return true;
132 }
133
134 template <class EntityType>
135 size_t size(const EntityType&) const
136 {
137 // communicate a field type per entity
138 return 1;
139 }
140
141 template <class MessageBufferImp, class EntityType>
142 void gather(MessageBufferImp& buff, const EntityType& e) const
143 {
144 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
145 buff.write(container_[dofIdx]);
146 }
147
148 template <class MessageBufferImp, class EntityType>
149 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
150 {
151 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
152 buff.read(container_[dofIdx]);
153 }
154
155private:
156 const EntityMapper& mapper_;
157 Container& container_;
158};
159
164template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
166 : public Dune::CommDataHandleIF<GridCommHandleMax<FieldType, Container,
167 EntityMapper, commCodim>,
168 FieldType>
169{
170public:
171 GridCommHandleMax(Container& container, const EntityMapper& mapper)
172 : mapper_(mapper), container_(container)
173 {}
174
175 bool contains(int, int codim) const
176 {
177 // return true if the codim is the same as the codim which we
178 // are asked to communicate with.
179 return codim == commCodim;
180 }
181
182#if DUNE_VERSION_LT(DUNE_GRID, 2, 8)
183 bool fixedsize(int, int) const
184#else
185 bool fixedSize(int, int) const
186#endif
187 {
188 // for each DOF we communicate a single value which has a
189 // fixed size
190 return true;
191 }
192
193 template <class EntityType>
194 size_t size(const EntityType&) const
195 {
196 // communicate a field type per entity
197 return 1;
198 }
199
200 template <class MessageBufferImp, class EntityType>
201 void gather(MessageBufferImp& buff, const EntityType& e) const
202 {
203 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
204 buff.write(container_[dofIdx]);
205 }
206
207 template <class MessageBufferImp, class EntityType>
208 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
209 {
210 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
211 FieldType tmp;
212 buff.read(tmp);
213 container_[dofIdx] = std::max(container_[dofIdx], tmp);
214 }
215
216private:
217 const EntityMapper& mapper_;
218 Container& container_;
219};
220
225template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
227 : public Dune::CommDataHandleIF<GridCommHandleMin<FieldType, Container,
228 EntityMapper, commCodim>,
229 FieldType>
230{
231public:
232 GridCommHandleMin(Container& container, const EntityMapper& mapper)
233 : mapper_(mapper), container_(container)
234 {}
235
236 bool contains(int, int codim) const
237 {
238 // return true if the codim is the same as the codim which we
239 // are asked to communicate with.
240 return codim == commCodim;
241 }
242
243#if DUNE_VERSION_LT(DUNE_GRID, 2, 8)
244 bool fixedsize(int, int) const
245#else
246 bool fixedSize(int, int) const
247#endif
248 {
249 // for each DOF we communicate a single value which has a
250 // fixed size
251 return true;
252 }
253
254 template <class EntityType>
255 size_t size(const EntityType&) const
256 {
257 // communicate a field type per entity
258 return 1;
259 }
260
261 template <class MessageBufferImp, class EntityType>
262 void gather(MessageBufferImp& buff, const EntityType& e) const
263 {
264 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
265 buff.write(container_[dofIdx]);
266 }
267
268 template <class MessageBufferImp, class EntityType>
269 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
270 {
271 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
272 FieldType tmp;
273 buff.read(tmp);
274 container_[dofIdx] = std::min(container_[dofIdx], tmp);
275 }
276
277private:
278 const EntityMapper& mapper_;
279 Container& container_;
280};
281
282} // namespace Opm
283
284#endif
Data handle for parallel communication which can be used to set the values values of ghost and overla...
Definition: gridcommhandles.hh:109
size_t size(const EntityType &) const
Definition: gridcommhandles.hh:135
bool contains(int, int codim) const
Definition: gridcommhandles.hh:116
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: gridcommhandles.hh:142
GridCommHandleGhostSync(Container &container, const EntityMapper &mapper)
Definition: gridcommhandles.hh:111
void scatter(MessageBufferImp &buff, const EntityType &e, size_t)
Definition: gridcommhandles.hh:149
bool fixedSize(int, int) const
Definition: gridcommhandles.hh:126
Data handle for parallel communication which takes the maximum of all values that are attached to DOF...
Definition: gridcommhandles.hh:169
bool contains(int, int codim) const
Definition: gridcommhandles.hh:175
void scatter(MessageBufferImp &buff, const EntityType &e, size_t)
Definition: gridcommhandles.hh:208
bool fixedSize(int, int) const
Definition: gridcommhandles.hh:185
size_t size(const EntityType &) const
Definition: gridcommhandles.hh:194
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: gridcommhandles.hh:201
GridCommHandleMax(Container &container, const EntityMapper &mapper)
Definition: gridcommhandles.hh:171
Provides data handle for parallel communication which takes the minimum of all values that are attach...
Definition: gridcommhandles.hh:230
void scatter(MessageBufferImp &buff, const EntityType &e, size_t)
Definition: gridcommhandles.hh:269
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: gridcommhandles.hh:262
size_t size(const EntityType &) const
Definition: gridcommhandles.hh:255
GridCommHandleMin(Container &container, const EntityMapper &mapper)
Definition: gridcommhandles.hh:232
bool fixedSize(int, int) const
Definition: gridcommhandles.hh:246
bool contains(int, int codim) const
Definition: gridcommhandles.hh:236
Data handle for parallel communication which sums up all values are attached to DOFs.
Definition: gridcommhandles.hh:46
void scatter(MessageBufferImp &buff, const EntityType &e, size_t)
Definition: gridcommhandles.hh:85
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: gridcommhandles.hh:78
GridCommHandleSum(Container &container, const EntityMapper &mapper)
Definition: gridcommhandles.hh:48
bool contains(int, int codim) const
Definition: gridcommhandles.hh:52
size_t size(const EntityType &) const
Definition: gridcommhandles.hh:71
bool fixedSize(int, int) const
Definition: gridcommhandles.hh:62
Definition: blackoilboundaryratevector.hh:37