opm-simulators
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/common/version.hh>
33 
34 #include <dune/grid/common/datahandleif.hh>
35 
36 #include <algorithm>
37 #include <cstddef>
38 
39 namespace Opm {
40 
45 template <class FieldType, class Container, class EntityMapper, int commCodim>
47  : public Dune::CommDataHandleIF<GridCommHandleSum<FieldType, Container,
48  EntityMapper, commCodim>,
49  FieldType>
50 {
51 public:
52  GridCommHandleSum(Container& container, const EntityMapper& mapper)
53  : mapper_(mapper), container_(container)
54  {}
55 
56  bool contains(int, int codim) const
57  {
58  // return true if the codim is the same as the codim which we
59  // are asked to communicate with.
60  return codim == commCodim;
61  }
62 
63  bool fixedSize(int, int) const
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  std::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  const 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, std::size_t)
86  {
87  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
88 
89  FieldType tmp;
90  buff.read(tmp);
91  container_[dofIdx] += tmp;
92  }
93 
94 private:
95  const EntityMapper& mapper_;
96  Container& container_;
97 };
98 
104 template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
106  : public Dune::CommDataHandleIF<GridCommHandleGhostSync<FieldType, Container,
107  EntityMapper, commCodim>,
108  FieldType>
109 {
110 public:
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  bool fixedSize(int, int) const
124  {
125  // for each DOF we communicate a single value which has a
126  // fixed size
127  return true;
128  }
129 
130  template <class EntityType>
131  std::size_t size(const EntityType&) const
132  {
133  // communicate a field type per entity
134  return 1;
135  }
136 
137  template <class MessageBufferImp, class EntityType>
138  void gather(MessageBufferImp& buff, const EntityType& e) const
139  {
140  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
141  buff.write(container_[dofIdx]);
142  }
143 
144  template <class MessageBufferImp, class EntityType>
145  void scatter(MessageBufferImp& buff, const EntityType& e, std::size_t)
146  {
147  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
148  buff.read(container_[dofIdx]);
149  }
150 
151 private:
152  const EntityMapper& mapper_;
153  Container& container_;
154 };
155 
160 template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
162  : public Dune::CommDataHandleIF<GridCommHandleMax<FieldType, Container,
163  EntityMapper, commCodim>,
164  FieldType>
165 {
166 public:
167  GridCommHandleMax(Container& container, const EntityMapper& mapper)
168  : mapper_(mapper), container_(container)
169  {}
170 
171  bool contains(int, int codim) const
172  {
173  // return true if the codim is the same as the codim which we
174  // are asked to communicate with.
175  return codim == commCodim;
176  }
177 
178  bool fixedSize(int, int) const
179  {
180  // for each DOF we communicate a single value which has a
181  // fixed size
182  return true;
183  }
184 
185  template <class EntityType>
186  std::size_t size(const EntityType&) const
187  {
188  // communicate a field type per entity
189  return 1;
190  }
191 
192  template <class MessageBufferImp, class EntityType>
193  void gather(MessageBufferImp& buff, const EntityType& e) const
194  {
195  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
196  buff.write(container_[dofIdx]);
197  }
198 
199  template <class MessageBufferImp, class EntityType>
200  void scatter(MessageBufferImp& buff, const EntityType& e, std::size_t)
201  {
202  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
203  FieldType tmp;
204  buff.read(tmp);
205  container_[dofIdx] = std::max(container_[dofIdx], tmp);
206  }
207 
208 private:
209  const EntityMapper& mapper_;
210  Container& container_;
211 };
212 
217 template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
219  : public Dune::CommDataHandleIF<GridCommHandleMin<FieldType, Container,
220  EntityMapper, commCodim>,
221  FieldType>
222 {
223 public:
224  GridCommHandleMin(Container& container, const EntityMapper& mapper)
225  : mapper_(mapper), container_(container)
226  {}
227 
228  bool contains(int, int codim) const
229  {
230  // return true if the codim is the same as the codim which we
231  // are asked to communicate with.
232  return codim == commCodim;
233  }
234 
235  bool fixedSize(int, int) const
236  {
237  // for each DOF we communicate a single value which has a
238  // fixed size
239  return true;
240  }
241 
242  template <class EntityType>
243  std::size_t size(const EntityType&) const
244  {
245  // communicate a field type per entity
246  return 1;
247  }
248 
249  template <class MessageBufferImp, class EntityType>
250  void gather(MessageBufferImp& buff, const EntityType& e) const
251  {
252  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
253  buff.write(container_[dofIdx]);
254  }
255 
256  template <class MessageBufferImp, class EntityType>
257  void scatter(MessageBufferImp& buff, const EntityType& e, std::size_t)
258  {
259  const unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
260  FieldType tmp;
261  buff.read(tmp);
262  container_[dofIdx] = std::min(container_[dofIdx], tmp);
263  }
264 
265 private:
266  const EntityMapper& mapper_;
267  Container& container_;
268 };
269 
270 } // namespace Opm
271 
272 #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
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
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