GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/linear/scalarproducts.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 5 8 62.5%
Branches: 37 100 37.0%

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 Linear
10 * \brief Classes to compute scalar products
11 */
12 #ifndef DUMUX_LINEAR_SCALAR_PRODUCTS_HH
13 #define DUMUX_LINEAR_SCALAR_PRODUCTS_HH
14
15 #include <array>
16 #include <memory>
17 #include <algorithm>
18
19 #include <dune/common/ftraits.hh>
20 #include <dune/common/hybridutilities.hh>
21
22 #include <dune/istl/solvercategory.hh>
23 #include <dune/istl/scalarproducts.hh>
24
25 namespace Dumux {
26
27 /*!
28 * \brief A scalar product for multi-type vectors
29 *
30 * Consistent vectors in interior and border are assumed
31 * \tparam X The type of the sequential vector to use for the left hand side,
32 * e.g. Dune::MultiTypeBlockVector or another type fulfilling its interface
33 * \tparam C The type of the communication object
34 * This must either be Dune::OwnerOverlapCopyCommunication or a type
35 * implementing the same interface
36 *
37 * Dune::OwnerOverlapCopyCommunication can represent a overlapping or
38 * a non-overlapping decomposition. This class allows to use different
39 * types of decompositions for each sub-domain of the vector.
40 */
41 template<class X, class C>
42 10 class ParallelMultiTypeScalarProduct : public Dune::ScalarProduct<X>
43 {
44 static constexpr std::size_t numSubDomains = X::size();
45 public:
46 // public aliases for a dune-istl like interface
47 using domain_type = X;
48 using field_type = typename X::field_type;
49 using real_type = typename Dune::FieldTraits<field_type>::real_type;
50 using communication_type = C;
51
52 ParallelMultiTypeScalarProduct (const std::array<std::shared_ptr<const communication_type>, numSubDomains>& comms)
53 10 : comms_(comms)
54 {}
55
56 /*!
57 * \brief Dot product of two vectors
58 * It is assumed that the vectors are consistent on the interior+border partition
59 * According to Blatt and Bastian (2009)
60 * https://doi.org/10.1504/IJCSE.2008.021112 they only have to be in a
61 * "valid representation" (i.e. all dofs owned by the process have the same value as the global vector)
62 */
63 10 field_type dot (const X& x, const X& y) const override
64 {
65 10 field_type result = 0.0;
66
67 // use the communicators for the subdomain scalar products and sum up
68 using namespace Dune::Hybrid;
69 90 forEach(integralRange(Dune::Hybrid::size(y)), [&](auto&& i)
70 {
71 20 field_type subResult = 0.0;
72 100 comms_[i]->dot(x[i], y[i], subResult);
73 20 result += subResult;
74 });
75
76 10 return result;
77 }
78
79 /*!
80 * \brief compute 2-norm of a right-hand side vector
81 */
82 5 real_type norm (const X& x) const override
83 {
84 using std::sqrt;
85 5 return sqrt(dot(x, x));
86 }
87
88 /*!
89 * \brief category of the scalar product
90 *
91 * see Dune::SolverCategory::Category
92 *
93 * as we have potentially several categories choose overlapping
94 * if there is no clear category
95 * This is part of a check mechanism and the category has to
96 * match with the linear operator and preconditioner when used
97 * in a parallel solver.
98 */
99 5 Dune::SolverCategory::Category category() const override
100 {
101
8/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1 times.
20 if (std::all_of(comms_.begin(), comms_.end(),
102
12/42
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 3 times.
✓ Branch 31 taken 2 times.
✓ Branch 32 taken 3 times.
✓ Branch 33 taken 2 times.
✓ Branch 34 taken 3 times.
✓ Branch 35 taken 2 times.
✓ Branch 36 taken 2 times.
✓ Branch 37 taken 1 times.
✓ Branch 38 taken 2 times.
✓ Branch 39 taken 1 times.
✓ Branch 40 taken 2 times.
✓ Branch 41 taken 1 times.
24 [](auto& c){ return c->category() == Dune::SolverCategory::sequential; }
103 ))
104 return Dune::SolverCategory::sequential;
105
8/8
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 1 times.
16 else if (std::all_of(comms_.begin(), comms_.end(),
106
9/42
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 3 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 3 times.
✓ Branch 34 taken 1 times.
✓ Branch 35 taken 3 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 1 times.
15 [](auto& c){ return c->category() == Dune::SolverCategory::nonoverlapping; }
107 ))
108 return Dune::SolverCategory::nonoverlapping;
109 else
110 3 return Dune::SolverCategory::overlapping;
111 }
112
113 private:
114 std::array<std::shared_ptr<const communication_type>, numSubDomains> comms_;
115 };
116
117 } // end namespace Dumux
118
119 #endif
120