GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/linear/solver.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 18 23 78.3%
Functions: 17 21 81.0%
Branches: 21 63 33.3%

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 Base class for linear solvers
11 */
12 #ifndef DUMUX_LINEAR_SOLVER_HH
13 #define DUMUX_LINEAR_SOLVER_HH
14
15 #include <dune/common/parallel/mpihelper.hh>
16 #include <dune/common/exceptions.hh>
17 #include <dune/istl/scalarproducts.hh>
18 #include <dumux/common/parameters.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup Linear
24 * \brief Base class for linear solvers
25 */
26
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 51 times.
51 class LinearSolver
27 {
28 public:
29 //! export Scalar type (might be needed to set parameters from output)
30 //! TODO: Do we need this?
31 using Scalar = double;
32
33 /*!
34 * \brief Construct the solver
35 * \note Read parameters from the parameter tree
36 * - LinearSolver.Verbosity the verbosity level of the linear solver
37 * - LinearSolver.MaxIterations the maximum iterations of the solver
38 * - LinearSolver.ResidualReduction the residual reduction threshold, i.e. stopping criterion
39 * - LinearSolver.Preconditioner.Relaxation precondition relaxation
40 * - LinearSolver.Preconditioner.Iterations the number of preconditioner iterations
41 * - LinearSolver.Preconditioner.Verbosity the preconditioner verbosity level
42 */
43 249 LinearSolver(const std::string& paramGroup = "")
44 249 : paramGroup_(paramGroup)
45 {
46
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 verbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Verbosity", 0);
47
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 maxIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.MaxIterations", 250);
48
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 residReduction_ = getParamFromGroup<Scalar>(paramGroup, "LinearSolver.ResidualReduction", 1e-13);
49
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 relaxation_ = getParamFromGroup<Scalar>(paramGroup, "LinearSolver.Preconditioner.Relaxation", 1);
50
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 precondIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Iterations", 1);
51
1/4
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
249 precondVerbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Verbosity", 0);
52 249 }
53
54 /*!
55 * \brief Solve the linear system Ax = b
56 * \note This has to be overloaded by the actual solver
57 */
58 template<class Matrix, class Vector>
59 bool solve(const Matrix& A, Vector& x, const Vector& b)
60 {
61 DUNE_THROW(Dune::NotImplemented, "Linear solver doesn't implement a solve method!");
62 }
63
64 template<class Vector>
65 6927 auto norm(const Vector& x) const
66 {
67
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 6927 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6927 times.
6927 if (Dune::MPIHelper::getCommunication().size() > 1)
68 DUNE_THROW(Dune::NotImplemented, "norm in parallel");
69
70 13854 return Dune::SeqScalarProduct<Vector>().norm(x);
71 }
72
73 //! the name of the linear solver
74 std::string name() const
75 { return "unknown solver"; }
76
77 //! the parameter group for getting parameter from the parameter tree
78 const std::string& paramGroup() const
79
5/10
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
10 { return paramGroup_; }
80
81 //! the verbosity level
82 int verbosity() const
83
3/5
✓ Branch 1 taken 5853 times.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1500 times.
✗ Branch 6 not taken.
30145 { return verbosity_; }
84
85 //! set the verbosity level
86 void setVerbosity(int v)
87 { verbosity_ = v; }
88
89 //! the maximum number of linear solver iterations
90 int maxIter() const
91
1/2
✓ Branch 1 taken 2289 times.
✗ Branch 2 not taken.
2290 { return maxIter_; }
92
93 //! set the maximum number of linear solver iterations
94 void setMaxIter(int i)
95 { maxIter_ = i; }
96
97 //! the linear solver residual reduction
98 Scalar residReduction() const
99
1/2
✓ Branch 1 taken 2289 times.
✗ Branch 2 not taken.
2290 { return residReduction_; }
100
101 //! set the linear solver residual reduction
102 void setResidualReduction(Scalar r)
103
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 207 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
213 { residReduction_ = r; }
104
105 //! the linear solver relaxation factor
106 Scalar relaxation() const
107 { return relaxation_; }
108
109 //! set the linear solver relaxation factor
110 void setRelaxation(Scalar r)
111 { relaxation_ = r; }
112
113 //! the number of preconditioner iterations
114 int precondIter() const
115 { return precondIter_; }
116
117 //! set the number of preconditioner iterations
118 void setPrecondIter(int i)
119 { precondIter_ = i; }
120
121 //! the preconditioner verbosity
122 int precondVerbosity() const
123 { return precondVerbosity_; }
124
125 //! set the preconditioner verbosity
126 void setPrecondVerbosity(int verbosityLevel)
127 { precondVerbosity_ = verbosityLevel; }
128
129 private:
130 int verbosity_;
131 int maxIter_;
132 Scalar residReduction_;
133 Scalar relaxation_;
134 int precondIter_;
135 int precondVerbosity_;
136 const std::string paramGroup_;
137 };
138
139 } // end namespace Dumux
140
141 #endif
142