3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
vectorexchange.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_EXCHANGE_HH
25#define DUMUX_VECTOR_EXCHANGE_HH
26
27#include <dune/grid/common/datahandleif.hh>
28
29namespace Dumux {
30
36template<class Mapper, class Vector> // mapper type and vector type
38 : public Dune::CommDataHandleIF<VectorExchange<Mapper,Vector>,
39 typename Vector::value_type>
40{
41public:
43 using DataType = typename Vector::value_type;
44
46 bool contains (int dim, int codim) const
47 {
48 return (codim == 0);
49 }
50
52 bool fixedsize (int dim, int codim) const
53 {
54 return true;
55 }
56
61 template<class Entity>
62 size_t size (Entity& entity) const
63 {
64 return 1;
65 }
66
68 template<class MessageBuffer, class Entity>
69 void gather (MessageBuffer& buff, const Entity& entity) const
70 {
71 buff.write(dataVector_[mapper_.index(entity)]);
72 }
73
78 template<class MessageBuffer, class Entity>
79 void scatter (MessageBuffer& buff, const Entity& entity, size_t n)
80 {
81 DataType x;
82 buff.read(x);
83 dataVector_[mapper_.index(entity)] = x;
84 }
85
87 VectorExchange (const Mapper& mapper, Vector& dataVector)
88 : mapper_(mapper), dataVector_(dataVector)
89 {}
90
91private:
92 const Mapper& mapper_;
93 Vector& dataVector_;
94};
95
96} // end namespace Dumux
97
98#endif
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
A data handle class to exchange entries of a vector.
Definition: vectorexchange.hh:40
bool contains(int dim, int codim) const
returns true if data for this codim should be communicated
Definition: vectorexchange.hh:46
typename Vector::value_type DataType
export type of data for message buffer
Definition: vectorexchange.hh:43
VectorExchange(const Mapper &mapper, Vector &dataVector)
constructor
Definition: vectorexchange.hh:87
bool fixedsize(int dim, int codim) const
returns true if size per entity of given dim and codim is a constant
Definition: vectorexchange.hh:52
size_t size(Entity &entity) const
how many objects of type DataType have to be sent for a given entity
Definition: vectorexchange.hh:62
void scatter(MessageBuffer &buff, const Entity &entity, size_t n)
unpack data from message buffer to user
Definition: vectorexchange.hh:79
void gather(MessageBuffer &buff, const Entity &entity) const
pack data from user to message buffer
Definition: vectorexchange.hh:69