version 3.9
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_VECTOR_COMM_DATA_HANDLE_HH
13#define DUMUX_VECTOR_COMM_DATA_HANDLE_HH
14
15#include <algorithm>
16
17#include <dune/grid/common/datahandleif.hh>
18
19namespace Dumux {
20
21namespace Detail {
22
23 struct SetEqual
24 {
25 template<class A, class B>
26 static void apply(A& a, const B& b)
27 { a = b; }
28 };
29
30 struct Sum
31 {
32 template<class A, class B>
33 static void apply(A& a, const B& b)
34 { a += b; }
35 };
36
37 struct Max
38 {
39 template<class A, class B>
40 static void apply(A& a, const B& b)
41 {
42 using std::max;
43 a = max(a,b);
44 }
45 };
46
47 struct Min
48 {
49 template<class A, class B>
50 static void apply(A& a, const B& b)
51 {
52 using std::min;
53 a = min(a,b);
54 }
55 };
56} // end namespace Detail
57
62template<class Mapper, class Vector, int entityCodim,
63 class ScatterOperator, class DataT = typename Vector::value_type>
65 : public Dune::CommDataHandleIF<VectorCommDataHandle<Mapper, Vector, entityCodim, ScatterOperator, DataT>, DataT>
66{
67public:
69 using DataType = DataT;
70
71 VectorCommDataHandle(const Mapper& mapper, Vector& vector)
72 : mapper_(mapper), vector_(vector)
73 {}
74
76 bool contains(int dim, int codim) const
77 { return (codim == entityCodim); }
78
80 bool fixedSize(int dim, int codim) const
81 { return true; }
82
87 template<class Entity>
88 std::size_t size(Entity& entity) const
89 { return 1; }
90
92 template<class MessageBuffer, class Entity>
93 void gather(MessageBuffer& buff, const Entity& entity) const
94 { buff.write(vector_[mapper_.index(entity)]); }
95
100 template<class MessageBuffer, class Entity>
101 void scatter(MessageBuffer& buff, const Entity& entity, std::size_t n)
102 {
103 DataType x;
104 buff.read(x);
105 ScatterOperator::apply(vector_[mapper_.index(entity)], x);
106 }
107
108protected:
109 const Mapper& mapper_;
110 Vector& vector_;
111};
112
113template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
115
116template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
118
119template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
121
122template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
124
125} // end namespace Dumux
126
127#endif
A data handle class to exchange entries of a vector.
Definition: vectorcommdatahandle.hh:66
bool contains(int dim, int codim) const
returns true if data for this codim should be communicated
Definition: vectorcommdatahandle.hh:76
Vector & vector_
Definition: vectorcommdatahandle.hh:110
std::size_t size(Entity &entity) const
how many objects of type DataType have to be sent for a given entity
Definition: vectorcommdatahandle.hh:88
void gather(MessageBuffer &buff, const Entity &entity) const
pack data from user to message buffer
Definition: vectorcommdatahandle.hh:93
const Mapper & mapper_
Definition: vectorcommdatahandle.hh:109
bool fixedSize(int dim, int codim) const
returns true if size per entity of given dim and codim is a constant
Definition: vectorcommdatahandle.hh:80
DataT DataType
export type of data for message buffer
Definition: vectorcommdatahandle.hh:69
void scatter(MessageBuffer &buff, const Entity &entity, std::size_t n)
unpack data from message buffer to user
Definition: vectorcommdatahandle.hh:101
VectorCommDataHandle(const Mapper &mapper, Vector &vector)
Definition: vectorcommdatahandle.hh:71
Definition: adapt.hh:17
Definition: vectorcommdatahandle.hh:38
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:40
Definition: vectorcommdatahandle.hh:48
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:50
Definition: vectorcommdatahandle.hh:24
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:26
Definition: vectorcommdatahandle.hh:31
static void apply(A &a, const B &b)
Definition: vectorcommdatahandle.hh:33