3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
vertexhandles.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_VERTEX_HANDLES_HH
26#define DUMUX_VERTEX_HANDLES_HH
27
28#include <dune/grid/common/datahandleif.hh>
29
30
31namespace Dumux {
32
38template <class FieldType, class Container, class VertexMapper>
40 : public Dune::CommDataHandleIF< VertexHandleSum<FieldType, Container, VertexMapper>,
41 FieldType >
42{
43public:
44 VertexHandleSum(Container &container,
45 const VertexMapper &mapper)
46 : mapper_(mapper)
47 , container_(container)
48 { };
49
50 bool contains(int dim, int codim) const
51 {
52 // only communicate vertices
53 return codim == dim;
54 }
55
56 bool fixedsize(int dim, int codim) const
57 {
58 // for each vertex we communicate a single field vector which
59 // has a fixed size
60 return true;
61 }
62
63 template<class EntityType>
64 size_t size (const EntityType &e) const
65 {
66 // communicate a field type per entity
67 return 1;
68 }
69
70 template<class MessageBufferImp, class EntityType>
71 void gather(MessageBufferImp &buff, const EntityType &e) const
72 {
73 int vIdx = mapper_.index(e);
74 buff.write(container_[vIdx]);
75 }
76
77 template<class MessageBufferImp, class EntityType>
78 void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
79 {
80 int vIdx = mapper_.index(e);
81
82 FieldType tmp;
83 buff.read(tmp);
84 container_[vIdx] += tmp;
85 }
86
87private:
88 const VertexMapper &mapper_;
89 Container &container_;
90};
91
96template <class FieldType, class Container, class VertexMapper>
98 : public Dune::CommDataHandleIF< VertexHandleMax<FieldType, Container, VertexMapper>,
99 FieldType >
100{
101public:
102 VertexHandleMax(Container &container,
103 const VertexMapper &mapper)
104 : mapper_(mapper)
105 , container_(container)
106 { };
107
108 bool contains(int dim, int codim) const
109 {
110 // only communicate vertices
111 return codim == dim;
112 }
113
114 bool fixedsize(int dim, int codim) const
115 {
116 // for each vertex we communicate a single field vector which
117 // has a fixed size
118 return true;
119 }
120
121 template<class EntityType>
122 size_t size (const EntityType &e) const
123 {
124 // communicate a field type per entity
125 return 1;
126 }
127
128 template<class MessageBufferImp, class EntityType>
129 void gather(MessageBufferImp &buff, const EntityType &e) const
130 {
131 int vIdx = mapper_.index(e);
132 buff.write(container_[vIdx]);
133 }
134
135 template<class MessageBufferImp, class EntityType>
136 void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
137 {
138 int vIdx = mapper_.index(e);
139
140 FieldType tmp;
141 buff.read(tmp);
142 using std::max;
143 container_[vIdx] = max(container_[vIdx], tmp);
144 }
145
146private:
147 const VertexMapper &mapper_;
148 Container &container_;
149};
150
151
156template <class FieldType, class Container, class VertexMapper>
158 : public Dune::CommDataHandleIF< VertexHandleMin<FieldType, Container, VertexMapper>,
159 FieldType >
160{
161public:
162 VertexHandleMin(Container &container,
163 const VertexMapper &mapper)
164 : mapper_(mapper)
165 , container_(container)
166 { };
167
168 bool contains(int dim, int codim) const
169 {
170 // only communicate vertices
171 return codim == dim;
172 }
173
174 bool fixedsize(int dim, int codim) const
175 {
176 // for each vertex we communicate a single field vector which
177 // has a fixed size
178 return true;
179 }
180
181 template<class EntityType>
182 size_t size (const EntityType &e) 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 int vIdx = mapper_.index(e);
192 buff.write(container_[vIdx]);
193 }
194
195 template<class MessageBufferImp, class EntityType>
196 void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
197 {
198 int vIdx = mapper_.index(e);
199 FieldType tmp;
200 buff.read(tmp);
201 using std::min;
202 container_[vIdx] = min(container_[vIdx], tmp);
203 }
204
205private:
206 const VertexMapper &mapper_;
207 Container &container_;
208};
209
210} // end namespace Dumux
211
212#endif
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Data handle for parallel communication which sums up all values are attached to vertices.
Definition: vertexhandles.hh:42
size_t size(const EntityType &e) const
Definition: vertexhandles.hh:64
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
Definition: vertexhandles.hh:78
bool contains(int dim, int codim) const
Definition: vertexhandles.hh:50
VertexHandleSum(Container &container, const VertexMapper &mapper)
Definition: vertexhandles.hh:44
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: vertexhandles.hh:71
bool fixedsize(int dim, int codim) const
Definition: vertexhandles.hh:56
Data handle for parallel communication which takes the maximum of all values that are attached to ver...
Definition: vertexhandles.hh:100
VertexHandleMax(Container &container, const VertexMapper &mapper)
Definition: vertexhandles.hh:102
size_t size(const EntityType &e) const
Definition: vertexhandles.hh:122
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: vertexhandles.hh:129
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
Definition: vertexhandles.hh:136
bool fixedsize(int dim, int codim) const
Definition: vertexhandles.hh:114
bool contains(int dim, int codim) const
Definition: vertexhandles.hh:108
Provides data handle for parallel communication which takes the minimum of all values that are attach...
Definition: vertexhandles.hh:160
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: vertexhandles.hh:189
size_t size(const EntityType &e) const
Definition: vertexhandles.hh:182
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
Definition: vertexhandles.hh:196
bool contains(int dim, int codim) const
Definition: vertexhandles.hh:168
VertexHandleMin(Container &container, const VertexMapper &mapper)
Definition: vertexhandles.hh:162
bool fixedsize(int dim, int codim) const
Definition: vertexhandles.hh:174