GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/parallel/vectorcommdatahandle.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 3 19 15.8%
Functions: 0 872 0.0%
Branches: 4 15 26.7%

Line Branch Exec Source
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 //
7 /*!
8 * \file
9 * \ingroup Parallel
10 * \brief Contains a class to exchange entries of a vector
11 */
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
19 namespace Dumux {
20
21 namespace 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
58 /*!
59 * \ingroup Parallel
60 * \brief A data handle class to exchange entries of a vector
61 */
62 template<class Mapper, class Vector, int entityCodim,
63 class ScatterOperator, class DataT = typename Vector::value_type>
64 class VectorCommDataHandle
65 : public Dune::CommDataHandleIF<VectorCommDataHandle<Mapper, Vector, entityCodim, ScatterOperator, DataT>, DataT>
66 {
67 public:
68 //! export type of data for message buffer
69 using DataType = DataT;
70
71 4252 VectorCommDataHandle(const Mapper& mapper, Vector& vector)
72
4/7
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 210 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
4252 : mapper_(mapper), vector_(vector)
73 {}
74
75 //! returns true if data for this codim should be communicated
76 bool contains(int dim, int codim) const
77 72 { return (codim == entityCodim); }
78
79 //! returns true if size per entity of given dim and codim is a constant
80 bool fixedSize(int dim, int codim) const
81 { return true; }
82
83 /*!
84 * \brief how many objects of type DataType have to be sent for a given entity
85 * \note Only the sender side needs to know this size.
86 */
87 template<class Entity>
88 std::size_t size(Entity& entity) const
89 { return 1; }
90
91 //! pack data from user to message buffer
92 template<class MessageBuffer, class Entity>
93 void gather(MessageBuffer& buff, const Entity& entity) const
94 { buff.write(vector_[mapper_.index(entity)]); }
95
96 /*!
97 * \brief unpack data from message buffer to user
98 * \note n is the number of objects sent by the sender
99 */
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
108 protected:
109 const Mapper& mapper_;
110 Vector& vector_;
111 };
112
113 template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
114 using VectorCommDataHandleEqual = VectorCommDataHandle<Mapper, Vector, codim, Detail::SetEqual, DataType>;
115
116 template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
117 using VectorCommDataHandleSum = VectorCommDataHandle<Mapper, Vector, codim, Detail::Sum, DataType>;
118
119 template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
120 using VectorCommDataHandleMin = VectorCommDataHandle<Mapper, Vector, codim, Detail::Min, DataType>;
121
122 template<class Mapper, class Vector, int codim, class DataType = typename Vector::value_type>
123 using VectorCommDataHandleMax = VectorCommDataHandle<Mapper, Vector, codim, Detail::Max, DataType>;
124
125 } // end namespace Dumux
126
127 #endif
128