My Project
Loading...
Searching...
No Matches
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:
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 bool fixedSize(int, int) const
60 {
61 // for each DOF we communicate a single value which has a
62 // fixed size
63 return true;
64 }
65
66 template <class EntityType>
67 size_t size(const EntityType&) const
68 {
69 // communicate a field type per entity
70 return 1;
71 }
72
73 template <class MessageBufferImp, class EntityType>
74 void gather(MessageBufferImp& buff, const EntityType& e) const
75 {
76 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
77 buff.write(container_[dofIdx]);
78 }
79
80 template <class MessageBufferImp, class EntityType>
81 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
82 {
83 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
84
85 FieldType tmp;
86 buff.read(tmp);
87 container_[dofIdx] += tmp;
88 }
89
90private:
91 const EntityMapper& mapper_;
92 Container& container_;
93};
94
100template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
102 : public Dune::CommDataHandleIF<GridCommHandleGhostSync<FieldType, Container,
103 EntityMapper, commCodim>,
104 FieldType>
105{
106public:
108 : mapper_(mapper), container_(container)
109 {
110 }
111
112 bool contains(int, int codim) const
113 {
114 // return true if the codim is the same as the codim which we
115 // are asked to communicate with.
116 return codim == commCodim;
117 }
118
119 bool fixedSize(int, int) const
120 {
121 // for each DOF we communicate a single value which has a
122 // fixed size
123 return true;
124 }
125
126 template <class EntityType>
127 size_t size(const EntityType&) const
128 {
129 // communicate a field type per entity
130 return 1;
131 }
132
133 template <class MessageBufferImp, class EntityType>
134 void gather(MessageBufferImp& buff, const EntityType& e) const
135 {
136 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
137 buff.write(container_[dofIdx]);
138 }
139
140 template <class MessageBufferImp, class EntityType>
141 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
142 {
143 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
144 buff.read(container_[dofIdx]);
145 }
146
147private:
148 const EntityMapper& mapper_;
149 Container& container_;
150};
151
156template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
158 : public Dune::CommDataHandleIF<GridCommHandleMax<FieldType, Container,
159 EntityMapper, commCodim>,
160 FieldType>
161{
162public:
164 : mapper_(mapper), container_(container)
165 {}
166
167 bool contains(int, int codim) const
168 {
169 // return true if the codim is the same as the codim which we
170 // are asked to communicate with.
171 return codim == commCodim;
172 }
173
174 bool fixedSize(int, int) const
175 {
176 // for each DOF we communicate a single value which has a
177 // fixed size
178 return true;
179 }
180
181 template <class EntityType>
182 size_t size(const EntityType&) const
183 {
184 // communicate a field type per entity
185 return 1;
186 }
187
188 template <class MessageBufferImp, class EntityType>
189 void gather(MessageBufferImp& buff, const EntityType& e) const
190 {
191 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
192 buff.write(container_[dofIdx]);
193 }
194
195 template <class MessageBufferImp, class EntityType>
196 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
197 {
198 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
199 FieldType tmp;
200 buff.read(tmp);
201 container_[dofIdx] = std::max(container_[dofIdx], tmp);
202 }
203
204private:
205 const EntityMapper& mapper_;
206 Container& container_;
207};
208
213template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
215 : public Dune::CommDataHandleIF<GridCommHandleMin<FieldType, Container,
216 EntityMapper, commCodim>,
217 FieldType>
218{
219public:
221 : mapper_(mapper), container_(container)
222 {}
223
224 bool contains(int, int codim) const
225 {
226 // return true if the codim is the same as the codim which we
227 // are asked to communicate with.
228 return codim == commCodim;
229 }
230
231 bool fixedSize(int, int) const
232 {
233 // for each DOF we communicate a single value which has a
234 // fixed size
235 return true;
236 }
237
238 template <class EntityType>
239 size_t size(const EntityType&) const
240 {
241 // communicate a field type per entity
242 return 1;
243 }
244
245 template <class MessageBufferImp, class EntityType>
246 void gather(MessageBufferImp& buff, const EntityType& e) const
247 {
248 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
249 buff.write(container_[dofIdx]);
250 }
251
252 template <class MessageBufferImp, class EntityType>
253 void scatter(MessageBufferImp& buff, const EntityType& e, size_t)
254 {
255 unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
256 FieldType tmp;
257 buff.read(tmp);
258 container_[dofIdx] = std::min(container_[dofIdx], tmp);
259 }
260
261private:
262 const EntityMapper& mapper_;
263 Container& container_;
264};
265
266} // namespace Opm
267
268#endif
Data handle for parallel communication which can be used to set the values values of ghost and overla...
Definition gridcommhandles.hh:105
Data handle for parallel communication which takes the maximum of all values that are attached to DOF...
Definition gridcommhandles.hh:161
Provides data handle for parallel communication which takes the minimum of all values that are attach...
Definition gridcommhandles.hh:218
Data handle for parallel communication which sums up all values are attached to DOFs.
Definition gridcommhandles.hh:46
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242