version 3.11-dev
Loading...
Searching...
No Matches
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-FileCopyrightText: 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#include <bitset>
17
18#include <dune/grid/common/datahandleif.hh>
19
21
22namespace Dumux {
23
24namespace Detail {
25
26 struct SetEqual
27 {
28 template<class A, class B>
29 static void apply(A& a, const B& b)
30 { a = b; }
31 };
32
33 struct Sum
34 {
35 template<class A, class B>
36 static void apply(A& a, const B& b)
37 { a += b; }
38 };
39
40 struct Max
41 {
42 template<class A, class B>
43 static void apply(A& a, const B& b)
44 {
45 using std::max;
46 a = max(a,b);
47 }
48 };
49
50 struct Min
51 {
52 template<class A, class B>
53 static void apply(A& a, const B& b)
54 {
55 using std::min;
56 a = min(a,b);
57 }
58 };
59} // end namespace Detail
60
65template<class Mapper, class Vector, int entityCodim,
66 class ScatterOperator, class DataT = typename Vector::value_type>
68 : public Dune::CommDataHandleIF<VectorCommDataHandle<Mapper, Vector, entityCodim, ScatterOperator, DataT>, DataT>
69{
70public:
72 using DataType = DataT;
73
74 VectorCommDataHandle(const Mapper& mapper, Vector& vector)
75 : mapper_(mapper), vector_(vector)
76 {}
77
79 bool contains(int, int codim) const
80 { return (codim == entityCodim); }
81
85 bool fixedSize(int /*gridDim*/, int codim) const
86 {
87 if (codim != entityCodim) return true;
88 const auto& gtypes = mapper_.types(codim);
89 if (gtypes.empty()) return true;
90 const auto nDofs = mapper_.size(gtypes[0]);
91 for (const auto& gt : gtypes)
92 if (mapper_.size(gt) != nDofs) return false;
93 return true;
94 }
95
100 template<class Entity>
101 std::size_t size(Entity& entity) const
102 { return asMultiMapper(mapper_).indices(entity).size(); }
103
105 template<class MessageBuffer, class Entity>
106 void gather(MessageBuffer& buff, const Entity& entity) const
107 {
108 for (auto i : asMultiMapper(mapper_).indices(entity))
109 buff.write(vector_[i]);
110 }
111
116 template<class MessageBuffer, class Entity>
117 void scatter(MessageBuffer& buff, const Entity& entity, std::size_t n)
118 {
119 for (auto i : asMultiMapper(mapper_).indices(entity)) {
120 DataType x;
121 buff.read(x);
122 ScatterOperator::apply(vector_[i], x);
123 }
124 }
125
126protected:
127 const Mapper& mapper_;
128 Vector& vector_;
129};
130
135template<class Mapper, class Vector, int dim,
136 class ScatterOperator, class DataT = typename Vector::value_type>
138 : public Dune::CommDataHandleIF<MultiCodimVectorCommDataHandle<Mapper, Vector, dim, ScatterOperator, DataT>, DataT>
139{
140public:
142 using DataType = DataT;
143 static_assert(dim >= 0, "Grid dimension must be non-negative");
144
145 MultiCodimVectorCommDataHandle(const Mapper& mapper,
146 Vector& vector,
147 std::bitset<dim+1> activeCodims)
148 : mapper_(mapper), vector_(vector), activeCodims_(std::move(activeCodims))
149 {}
150
152 bool contains(int, int codim) const
153 {
154 return codim >= 0
155 && codim <= static_cast<int>(dim)
156 && activeCodims_.test(codim);
157 }
158
162 bool fixedSize(int /*gridDim*/, int codim) const
163 {
164 if (codim < 0 || codim > dim || !activeCodims_.test(codim))
165 return true;
166 const auto& gtypes = mapper_.types(codim);
167 if (gtypes.empty()) return true;
168 const auto nDofs = mapper_.size(gtypes[0]);
169 for (const auto& gt : gtypes)
170 if (mapper_.size(gt) != nDofs) return false;
171 return true;
172 }
173
178 template<class Entity>
179 std::size_t size(Entity& entity) const
180 { return asMultiMapper(mapper_).indices(entity).size(); }
181
183 template<class MessageBuffer, class Entity>
184 void gather(MessageBuffer& buff, const Entity& entity) const
185 {
186 for (auto i : asMultiMapper(mapper_).indices(entity))
187 buff.write(vector_[i]);
188 }
189
194 template<class MessageBuffer, class Entity>
195 void scatter(MessageBuffer& buff, const Entity& entity, std::size_t n)
196 {
197 for (auto i : asMultiMapper(mapper_).indices(entity)) {
198 DataType x;
199 buff.read(x);
200 ScatterOperator::apply(vector_[i], x);
201 }
202 }
203
204protected:
205 const Mapper& mapper_;
206 Vector& vector_;
207 std::bitset<dim+1> activeCodims_;
208};
209
210template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
212
213template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
215
216template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
218
219template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
221
222template<class Mapper, class Vector, int dim, class DataType = typename Vector::value_type>
224
225template<class Mapper, class Vector, int dim, class DataType = typename Vector::value_type>
227
228template<class Mapper, class Vector, int dim, class DataType = typename Vector::value_type>
230
231template<class Mapper, class Vector, int dim, class DataType = typename Vector::value_type>
233
234} // end namespace Dumux
235
236#endif
A data handle class to exchange entries of a vector for multiple codims in one communication call.
Definition vectorcommdatahandle.hh:139
bool fixedSize(int, int codim) const
Definition vectorcommdatahandle.hh:162
DataT DataType
export type of data for message buffer
Definition vectorcommdatahandle.hh:142
std::size_t size(Entity &entity) const
how many objects of type DataType have to be sent for a given entity
Definition vectorcommdatahandle.hh:179
MultiCodimVectorCommDataHandle(const Mapper &mapper, Vector &vector, std::bitset< dim+1 > activeCodims)
Definition vectorcommdatahandle.hh:145
std::bitset< dim+1 > activeCodims_
Definition vectorcommdatahandle.hh:207
bool contains(int, int codim) const
returns true if data for this codim should be communicated
Definition vectorcommdatahandle.hh:152
void scatter(MessageBuffer &buff, const Entity &entity, std::size_t n)
unpack data from message buffer to user (all DOFs of entity)
Definition vectorcommdatahandle.hh:195
void gather(MessageBuffer &buff, const Entity &entity) const
pack data from user to message buffer (all DOFs of entity)
Definition vectorcommdatahandle.hh:184
A data handle class to exchange entries of a vector.
Definition vectorcommdatahandle.hh:69
bool contains(int, int codim) const
returns true if data for this codim should be communicated
Definition vectorcommdatahandle.hh:79
bool fixedSize(int, int codim) const
Definition vectorcommdatahandle.hh:85
std::size_t size(Entity &entity) const
how many objects of type DataType have to be sent for a given entity. Returns the number of DOFs asso...
Definition vectorcommdatahandle.hh:101
void gather(MessageBuffer &buff, const Entity &entity) const
pack data from user to message buffer (all DOFs of entity)
Definition vectorcommdatahandle.hh:106
const Mapper & mapper_
Definition vectorcommdatahandle.hh:127
DataT DataType
export type of data for message buffer
Definition vectorcommdatahandle.hh:72
void scatter(MessageBuffer &buff, const Entity &entity, std::size_t n)
unpack data from message buffer to user (all DOFs of entity)
Definition vectorcommdatahandle.hh:117
VectorCommDataHandle(const Mapper &mapper, Vector &vector)
Definition vectorcommdatahandle.hh:74
Adapter to expose a multi-DOF mapper interface for single- and multi-DOF mappers.
Definition cvfelocalresidual.hh:25
Definition adapt.hh:17
VectorCommDataHandle< Mapper, Vector, codim, Detail::Sum, DataType > VectorCommDataHandleSum
Definition vectorcommdatahandle.hh:214
VectorCommDataHandle< Mapper, Vector, codim, Detail::Min, DataType > VectorCommDataHandleMin
Definition vectorcommdatahandle.hh:217
MultiCodimVectorCommDataHandle< Mapper, Vector, dim, Detail::SetEqual, DataType > MultiCodimVectorCommDataHandleEqual
Definition vectorcommdatahandle.hh:223
VectorCommDataHandle< Mapper, Vector, codim, Detail::SetEqual, DataType > VectorCommDataHandleEqual
Definition vectorcommdatahandle.hh:211
constexpr auto asMultiMapper(const Mapper &mapper)
Definition multimapperview.hh:48
MultiCodimVectorCommDataHandle< Mapper, Vector, dim, Detail::Min, DataType > MultiCodimVectorCommDataHandleMin
Definition vectorcommdatahandle.hh:229
MultiCodimVectorCommDataHandle< Mapper, Vector, dim, Detail::Max, DataType > MultiCodimVectorCommDataHandleMax
Definition vectorcommdatahandle.hh:232
VectorCommDataHandle< Mapper, Vector, codim, Detail::Max, DataType > VectorCommDataHandleMax
Definition vectorcommdatahandle.hh:220
MultiCodimVectorCommDataHandle< Mapper, Vector, dim, Detail::Sum, DataType > MultiCodimVectorCommDataHandleSum
Definition vectorcommdatahandle.hh:226
Definition vectorcommdatahandle.hh:41
static void apply(A &a, const B &b)
Definition vectorcommdatahandle.hh:43
Definition vectorcommdatahandle.hh:51
static void apply(A &a, const B &b)
Definition vectorcommdatahandle.hh:53
Definition vectorcommdatahandle.hh:27
static void apply(A &a, const B &b)
Definition vectorcommdatahandle.hh:29
Definition vectorcommdatahandle.hh:34
static void apply(A &a, const B &b)
Definition vectorcommdatahandle.hh:36