All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 <opm/common/Unused.hpp>
33 
34 #include <dune/grid/common/datahandleif.hh>
35 #include <dune/common/version.hh>
36 
37 namespace Ewoms {
38 
43 template <class FieldType, class Container, class EntityMapper, int commCodim>
45  : public Dune::CommDataHandleIF<GridCommHandleSum<FieldType, Container,
46  EntityMapper, commCodim>,
47  FieldType>
48 {
49 public:
50  GridCommHandleSum(Container& container, const EntityMapper& mapper)
51  : mapper_(mapper), container_(container)
52  {}
53 
54  bool contains(int dim OPM_UNUSED, int codim) const
55  {
56  // return true if the codim is the same as the codim which we
57  // are asked to communicate with.
58  return codim == commCodim;
59  }
60 
61  bool fixedsize(int dim OPM_UNUSED, int codim OPM_UNUSED) const
62  {
63  // for each DOF we communicate a single value which has a
64  // fixed size
65  return true;
66  }
67 
68  template <class EntityType>
69  size_t size(const EntityType& e OPM_UNUSED) const
70  {
71  // communicate a field type per entity
72  return 1;
73  }
74 
75  template <class MessageBufferImp, class EntityType>
76  void gather(MessageBufferImp& buff, const EntityType& e) const
77  {
78  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
79  buff.write(container_[dofIdx]);
80  }
81 
82  template <class MessageBufferImp, class EntityType>
83  void scatter(MessageBufferImp& buff, const EntityType& e, size_t n OPM_UNUSED)
84  {
85  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
86 
87  FieldType tmp;
88  buff.read(tmp);
89  container_[dofIdx] += tmp;
90  }
91 
92 private:
93  const EntityMapper& mapper_;
94  Container& container_;
95 };
96 
102 template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
104  : public Dune::CommDataHandleIF<GridCommHandleGhostSync<FieldType, Container,
105  EntityMapper, commCodim>,
106  FieldType>
107 {
108 public:
109  GridCommHandleGhostSync(Container& container, const EntityMapper& mapper)
110  : mapper_(mapper), container_(container)
111  {
112  }
113 
114  bool contains(unsigned dim OPM_UNUSED, unsigned codim) const
115  {
116  // return true if the codim is the same as the codim which we
117  // are asked to communicate with.
118  return codim == commCodim;
119  }
120 
121  bool fixedsize(unsigned dim OPM_UNUSED, unsigned codim OPM_UNUSED) const
122  {
123  // for each DOF we communicate a single value which has a
124  // fixed size
125  return true;
126  }
127 
128  template <class EntityType>
129  size_t size(const EntityType& e OPM_UNUSED) const
130  {
131  // communicate a field type per entity
132  return 1;
133  }
134 
135  template <class MessageBufferImp, class EntityType>
136  void gather(MessageBufferImp& buff, const EntityType& e) const
137  {
138  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
139  buff.write(container_[dofIdx]);
140  }
141 
142  template <class MessageBufferImp, class EntityType>
143  void scatter(MessageBufferImp& buff, const EntityType& e, size_t n OPM_UNUSED)
144  {
145  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
146  buff.read(container_[dofIdx]);
147  }
148 
149 private:
150  const EntityMapper& mapper_;
151  Container& container_;
152 };
153 
158 template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
160  : public Dune::CommDataHandleIF<GridCommHandleMax<FieldType, Container,
161  EntityMapper, commCodim>,
162  FieldType>
163 {
164 public:
165  GridCommHandleMax(Container& container, const EntityMapper& mapper)
166  : mapper_(mapper), container_(container)
167  {}
168 
169  bool contains(unsigned dim OPM_UNUSED, unsigned codim) const
170  {
171  // return true if the codim is the same as the codim which we
172  // are asked to communicate with.
173  return codim == commCodim;
174  }
175 
176  bool fixedsize(unsigned dim OPM_UNUSED, unsigned codim OPM_UNUSED) const
177  {
178  // for each DOF we communicate a single value which has a
179  // fixed size
180  return true;
181  }
182 
183  template <class EntityType>
184  size_t size(const EntityType& e OPM_UNUSED) const
185  {
186  // communicate a field type per entity
187  return 1;
188  }
189 
190  template <class MessageBufferImp, class EntityType>
191  void gather(MessageBufferImp& buff, const EntityType& e) const
192  {
193  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
194  buff.write(container_[dofIdx]);
195  }
196 
197  template <class MessageBufferImp, class EntityType>
198  void scatter(MessageBufferImp& buff, const EntityType& e, size_t n OPM_UNUSED)
199  {
200  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
201  FieldType tmp;
202  buff.read(tmp);
203  container_[dofIdx] = std::max(container_[dofIdx], tmp);
204  }
205 
206 private:
207  const EntityMapper& mapper_;
208  Container& container_;
209 };
210 
215 template <class FieldType, class Container, class EntityMapper, unsigned commCodim>
217  : public Dune::CommDataHandleIF<GridCommHandleMin<FieldType, Container,
218  EntityMapper, commCodim>,
219  FieldType>
220 {
221 public:
222  GridCommHandleMin(Container& container, const EntityMapper& mapper)
223  : mapper_(mapper), container_(container)
224  {}
225 
226  bool contains(unsigned dim OPM_UNUSED, unsigned codim) const
227  {
228  // return true if the codim is the same as the codim which we
229  // are asked to communicate with.
230  return codim == commCodim;
231  }
232 
233  bool fixedsize(unsigned dim OPM_UNUSED, unsigned codim OPM_UNUSED) const
234  {
235  // for each DOF we communicate a single value which has a
236  // fixed size
237  return true;
238  }
239 
240  template <class EntityType>
241  size_t size(const EntityType& e OPM_UNUSED) const
242  {
243  // communicate a field type per entity
244  return 1;
245  }
246 
247  template <class MessageBufferImp, class EntityType>
248  void gather(MessageBufferImp& buff, const EntityType& e) const
249  {
250  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
251  buff.write(container_[dofIdx]);
252  }
253 
254  template <class MessageBufferImp, class EntityType>
255  void scatter(MessageBufferImp& buff, const EntityType& e, size_t n OPM_UNUSED)
256  {
257  unsigned dofIdx = static_cast<unsigned>(mapper_.index(e));
258  FieldType tmp;
259  buff.read(tmp);
260  container_[dofIdx] = std::min(container_[dofIdx], tmp);
261  }
262 
263 private:
264  const EntityMapper& mapper_;
265  Container& container_;
266 };
267 
268 } // namespace Ewoms
269 
270 #endif
Data handle for parallel communication which takes the maximum of all values that are attached to DOF...
Definition: gridcommhandles.hh:159
Data handle for parallel communication which sums up all values are attached to DOFs.
Definition: gridcommhandles.hh:44
Provides data handle for parallel communication which takes the minimum of all values that are attach...
Definition: gridcommhandles.hh:216
Data handle for parallel communication which can be used to set the values values of ghost and overla...
Definition: gridcommhandles.hh:103