3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
vectorcommdatahandle.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 *****************************************************************************/
24#ifndef DUMUX_VECTOR_COMM_DATA_HANDLE_HH
25#define DUMUX_VECTOR_COMM_DATA_HANDLE_HH
26
27#include <algorithm>
28
29#include <dune/common/version.hh>
30#include <dune/grid/common/datahandleif.hh>
31
32namespace Dumux {
33
34namespace Detail {
35
36 struct SetEqual
37 {
38 template<class A, class B>
39 static void apply(A& a, const B& b)
40 { a = b; }
41 };
42
43 struct Sum
44 {
45 template<class A, class B>
46 static void apply(A& a, const B& b)
47 { a += b; }
48 };
49
50 struct Max
51 {
52 template<class A, class B>
53 static void apply(A& a, const B& b)
54 {
55 using std::max;
56 a = max(a,b);
57 }
58 };
59
60 struct Min
61 {
62 template<class A, class B>
63 static void apply(A& a, const B& b)
64 {
65 using std::min;
66 a = min(a,b);
67 }
68 };
69} // end namespace Detail
70
75template<class Mapper, class Vector, int entityCodim, class ScatterOperator>
77 : public Dune::CommDataHandleIF<VectorCommDataHandle<Mapper,Vector, entityCodim, ScatterOperator>,
78 typename Vector::value_type>
79{
80public:
82 using DataType = typename Vector::value_type;
83
84 VectorCommDataHandle(const Mapper& mapper, Vector& vector)
85 : mapper_(mapper), vector_(vector)
86 {}
87
89 bool contains(int dim, int codim) const
90 { return (codim == entityCodim); }
91
92#if DUNE_VERSION_GTE(DUNE_GRID,2,7)
94 bool fixedSize(int dim, int codim) const
95 { return true; }
96#else
98 bool fixedsize(int dim, int codim) const
99 { return true; }
100#endif
101
106 template<class Entity>
107 std::size_t size(Entity& entity) const
108 { return 1; }
109
111 template<class MessageBuffer, class Entity>
112 void gather(MessageBuffer& buff, const Entity& entity) const
113 { buff.write(vector_[mapper_.index(entity)]); }
114
119 template<class MessageBuffer, class Entity>
120 void scatter(MessageBuffer& buff, const Entity& entity, std::size_t n)
121 {
122 DataType x;
123 buff.read(x);
124 ScatterOperator::apply(vector_[mapper_.index(entity)], x);
125 }
126
127protected:
128 const Mapper& mapper_;
129 Vector& vector_;
130};
131
132template<class Mapper, class Vector, int codim>
134
135template<class Mapper, class Vector, int codim>
137
138template<class Mapper, class Vector, int codim>
140
141template<class Mapper, class Vector, int codim>
143
144} // end namespace Dumux
145
146#endif // DUMUX_VECTOR_COMM_DATA_HANDLE_HH
Definition: adapt.hh:29
Definition: vectorcommdatahandle.hh:37
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:39
Definition: vectorcommdatahandle.hh:44
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:46
Definition: vectorcommdatahandle.hh:51
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:53
Definition: vectorcommdatahandle.hh:61
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:63
A data handle class to exchange entries of a vector.
Definition: vectorcommdatahandle.hh:79
VectorCommDataHandle(const Mapper &mapper, Vector &vector)
Definition: vectorcommdatahandle.hh:84
std::size_t size(Entity &entity) const
how many objects of type DataType have to be sent for a given entity
Definition: vectorcommdatahandle.hh:107
void gather(MessageBuffer &buff, const Entity &entity) const
pack data from user to message buffer
Definition: vectorcommdatahandle.hh:112
Vector & vector_
Definition: vectorcommdatahandle.hh:129
void scatter(MessageBuffer &buff, const Entity &entity, std::size_t n)
unpack data from message buffer to user
Definition: vectorcommdatahandle.hh:120
typename Vector::value_type DataType
export type of data for message buffer
Definition: vectorcommdatahandle.hh:82
bool contains(int dim, int codim) const
returns true if data for this codim should be communicated
Definition: vectorcommdatahandle.hh:89
const Mapper & mapper_
Definition: vectorcommdatahandle.hh:128
bool fixedsize(int dim, int codim) const
returns true if size per entity of given dim and codim is a constant
Definition: vectorcommdatahandle.hh:98