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