GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/common/pdesolver.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 12 18 66.7%
Functions: 276 1317 21.0%
Branches: 161 406 39.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 Core
10 * \brief Defines a high-level interface for a PDESolver
11 */
12 #ifndef DUMUX_COMMON_PDESOLVER_HH
13 #define DUMUX_COMMON_PDESOLVER_HH
14
15 #include <memory>
16 #include <utility>
17
18 #include <dune/common/hybridutilities.hh>
19 #include <dune/common/std/type_traits.hh>
20
21 #include <dumux/common/timeloop.hh>
22
23 // forward declare
24 namespace Dune {
25 template <class FirstRow, class ... Args>
26 class MultiTypeBlockMatrix;
27 } // end namespace Dune
28
29 namespace Dumux::Detail::PDESolver {
30
31 template<class Assembler>
32 using AssemblerVariablesType = typename Assembler::Variables;
33
34 template<class Assembler>
35 inline constexpr bool assemblerExportsVariables = Dune::Std::is_detected_v<AssemblerVariablesType, Assembler>;
36
37 template<class A, bool exports = assemblerExportsVariables<A>> struct VariablesChooser;
38 template<class A> struct VariablesChooser<A, true> { using Type = AssemblerVariablesType<A>; };
39 template<class A> struct VariablesChooser<A, false> { using Type = typename A::SolutionVector; };
40
41 template<class Assembler>
42 using AssemblerVariables = typename VariablesChooser<Assembler>::Type;
43
44 } // end namespace Dumux::Detail::PDESolver
45
46 namespace Dumux {
47
48 /*!
49 * \ingroup Core
50 * \brief A high-level interface for a PDESolver
51 *
52 * A PDESolver is constructed with an assembler and a linear solver
53 * and has a method solve that linearizes (if not already linear), assembles, solves and updates
54 * given an initial solution producing a new solution.
55 *
56 * \tparam A Assembler for linearized system of the PDE
57 * \tparam LS Linear system solver
58 */
59 template<class A, class LS>
60 class PDESolver
61 {
62 using Scalar = typename A::Scalar;
63 using TimeLoop = TimeLoopBase<Scalar>;
64
65 public:
66 //! export the assembler and linear solver types
67 using Assembler = A;
68 using LinearSolver = LS;
69
70 //! export the type of variables that represent a numerical solution
71 using Variables = Detail::PDESolver::AssemblerVariables<Assembler>;
72
73 /*!
74 * \brief Constructor
75 * \param assembler pointer to the assembler of the linear system
76 * \param linearSolver pointer to the solver of the resulting linear system
77 */
78 521 PDESolver(std::shared_ptr<Assembler> assembler,
79 std::shared_ptr<LinearSolver> linearSolver)
80 : assembler_(assembler)
81
2/4
✓ Branch 2 taken 515 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
521 , linearSolver_(linearSolver)
82 {}
83
84
2/4
✓ Branch 0 taken 521 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 521 times.
✗ Branch 3 not taken.
2084 virtual ~PDESolver() = default;
85
86 /*!
87 * \brief Solve the given PDE system (usually assemble + solve linear system + update)
88 * \param vars instance of the `Variables` class representing a numerical
89 * solution, defining primary and possibly secondary variables
90 * and information on the time level.
91 * \return bool true if the solver converged
92 * \post If converged, the given `Variables` will represent the solution. If the solver
93 * does not converge, it may be the case that they are in some intermediate (implementation-dependent) state.
94 */
95 virtual bool apply(Variables& vars) = 0;
96
97 /*!
98 * \brief Solve the given PDE system (usually assemble + solve linear system + update)
99 * \param vars instance of the `Variables` class representing a numerical
100 * solution, defining primary and possibly secondary variables
101 * and information on the time level.
102 */
103 virtual void solve(Variables& vars) = 0;
104
105 /*!
106 * \brief Solve the given PDE system with time step control
107 * \note This is used for solvers that are allowed to e.g. automatically reduce the
108 * time step if the solve was not successful
109 * \param vars instance of the `Variables` class representing a numerical solution
110 * \param timeLoop a reference to the current time loop
111 */
112 virtual void solve(Variables& vars, TimeLoop& timeLoop)
113 {
114 // per default we just forward to the method without time step control
115 solve(vars);
116 }
117
118 /*!
119 * \brief Access the assembler
120 */
121 const Assembler& assembler() const
122 { return *assembler_; }
123
124 /*!
125 * \brief Access the assembler
126 */
127 Assembler& assembler()
128
85/139
✗ Branch 0 not taken.
✓ Branch 1 taken 760 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 760 times.
✓ Branch 5 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 372787 times.
✓ Branch 8 taken 19 times.
✓ Branch 9 taken 431928 times.
✓ Branch 10 taken 26288 times.
✓ Branch 11 taken 86034 times.
✓ Branch 12 taken 7 times.
✓ Branch 13 taken 27851 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 29801 times.
✓ Branch 16 taken 954 times.
✓ Branch 17 taken 5186 times.
✓ Branch 18 taken 3467 times.
✓ Branch 19 taken 2452 times.
✓ Branch 20 taken 5136 times.
✓ Branch 21 taken 1485 times.
✓ Branch 22 taken 1795 times.
✓ Branch 23 taken 1034 times.
✓ Branch 24 taken 184 times.
✓ Branch 25 taken 361 times.
✓ Branch 26 taken 385 times.
✓ Branch 27 taken 4884 times.
✓ Branch 28 taken 361 times.
✓ Branch 29 taken 322 times.
✓ Branch 30 taken 4884 times.
✓ Branch 31 taken 559 times.
✓ Branch 32 taken 322 times.
✓ Branch 33 taken 264 times.
✓ Branch 34 taken 442 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 147 times.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 104 times.
✓ Branch 40 taken 1 times.
✓ Branch 41 taken 53 times.
✓ Branch 42 taken 106 times.
✓ Branch 43 taken 2 times.
✓ Branch 44 taken 55 times.
✓ Branch 45 taken 3330 times.
✓ Branch 46 taken 2 times.
✓ Branch 47 taken 5381 times.
✓ Branch 48 taken 3 times.
✓ Branch 49 taken 3054 times.
✓ Branch 50 taken 59 times.
✓ Branch 51 taken 2781 times.
✓ Branch 52 taken 54 times.
✓ Branch 53 taken 2011 times.
✓ Branch 54 taken 93 times.
✓ Branch 55 taken 489 times.
✓ Branch 56 taken 102 times.
✓ Branch 57 taken 5024 times.
✓ Branch 58 taken 197 times.
✓ Branch 59 taken 5015 times.
✓ Branch 60 taken 11 times.
✓ Branch 61 taken 492 times.
✓ Branch 62 taken 212 times.
✓ Branch 63 taken 628 times.
✓ Branch 64 taken 192 times.
✓ Branch 65 taken 367 times.
✓ Branch 66 taken 3 times.
✓ Branch 67 taken 207 times.
✓ Branch 68 taken 11 times.
✓ Branch 69 taken 79 times.
✓ Branch 70 taken 32 times.
✓ Branch 71 taken 8 times.
✓ Branch 72 taken 79 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 8 times.
✓ Branch 75 taken 1 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 78 taken 1 times.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✓ Branch 99 taken 2 times.
✗ Branch 100 not taken.
✓ Branch 101 taken 5 times.
✓ Branch 102 taken 2 times.
✗ Branch 103 not taken.
✓ Branch 104 taken 5 times.
✓ Branch 105 taken 4 times.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✓ Branch 108 taken 4 times.
✓ Branch 109 taken 1 times.
✗ Branch 110 not taken.
✓ Branch 111 taken 79 times.
✓ Branch 112 taken 1 times.
✓ Branch 113 taken 84 times.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✓ Branch 116 taken 5 times.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✓ Branch 121 taken 1 times.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✓ Branch 124 taken 1 times.
✓ Branch 125 taken 8 times.
✗ Branch 126 not taken.
✓ Branch 127 taken 8 times.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
2644794 { return *assembler_; }
129
130 /*!
131 * \brief Access the linear solver
132 */
133 const LinearSolver& linearSolver() const
134 { return *linearSolver_; }
135
136 protected:
137
138 /*!
139 * \brief Access the linear solver
140 */
141 LinearSolver& linearSolver()
142
16/25
✓ Branch 1 taken 71 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 71 times.
✓ Branch 5 taken 14669 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 14673 times.
✓ Branch 9 taken 96 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 679 times.
✓ Branch 12 taken 91 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 679 times.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 6 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 6 times.
✗ Branch 31 not taken.
164124 { return *linearSolver_; }
143
144 /*!
145 * \brief Helper function to assure the MultiTypeBlockMatrix's sub-blocks have the correct sizes.
146 */
147 template <class FirstRow, class ... Args>
148 bool checkSizesOfSubMatrices(const Dune::MultiTypeBlockMatrix<FirstRow, Args...>& matrix) const
149 {
150 6685 bool matrixHasCorrectSize = true;
151 using namespace Dune::Hybrid;
152
3/8
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5964 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5926 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12649 forEach(std::make_index_sequence<Dune::MultiTypeBlockMatrix<FirstRow, Args...>::N()>(), [&](const auto i)
153 {
154
7/32
✗ Branch 0 not taken.
✓ Branch 1 taken 721 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 721 times.
✗ 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 taken 5926 times.
✓ Branch 18 taken 5926 times.
✗ 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 taken 38 times.
✓ Branch 26 taken 38 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
8127 const auto& row = matrix[i];
155
7/32
✗ Branch 0 not taken.
✓ Branch 1 taken 721 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 721 times.
✗ 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 taken 5926 times.
✓ Branch 18 taken 5926 times.
✗ 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 taken 38 times.
✓ Branch 26 taken 38 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
8127 const auto numRowsLeftMostBlock = row[Dune::index_constant<0>{}].N();
156
13/48
✗ Branch 0 not taken.
✓ Branch 1 taken 721 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 721 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 721 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 721 times.
✗ 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 taken 5926 times.
✓ Branch 24 taken 5926 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 5926 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 5926 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 38 times.
✓ Branch 34 taken 38 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 38 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 38 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
9569 forEach(row, [&](const auto& subBlock)
157 {
158
25/112
✗ Branch 0 not taken.
✓ Branch 1 taken 721 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 721 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 721 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 721 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 721 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 721 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 721 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 721 times.
✗ 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 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✓ Branch 53 taken 1781 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 1781 times.
✓ Branch 56 taken 1781 times.
✓ Branch 57 taken 4145 times.
✓ Branch 58 taken 1781 times.
✓ Branch 59 taken 4145 times.
✓ Branch 60 taken 4145 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 4145 times.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✓ Branch 89 taken 22 times.
✗ Branch 90 not taken.
✓ Branch 91 taken 22 times.
✓ Branch 92 taken 22 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 22 times.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✓ Branch 97 taken 16 times.
✗ Branch 98 not taken.
✓ Branch 99 taken 16 times.
✓ Branch 100 taken 16 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 16 times.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
13370 if (subBlock.N() != numRowsLeftMostBlock)
159 matrixHasCorrectSize = false;
160 });
161 });
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 721 times.
721 return matrixHasCorrectSize;
163 }
164
165 /*!
166 * \brief Default implementation for any matrix type
167 */
168 template <class M>
169 bool checkSizesOfSubMatrices(const M&) const { return true; }
170
171 private:
172 std::shared_ptr<Assembler> assembler_;
173 std::shared_ptr<LinearSolver> linearSolver_;
174 };
175
176 } // namespace Dumux
177
178 #endif
179