GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/linear/linearsolverparameters.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 34 35 97.1%
Functions: 204 245 83.3%
Branches: 47 84 56.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-FileCopyrightText: 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 Generates a parameter tree required for the linear solvers and precondioners of the Dune ISTL
11 */
12
13 #ifndef DUMUX_LINEAR_SOLVER_PARAMETERS_HH
14 #define DUMUX_LINEAR_SOLVER_PARAMETERS_HH
15
16 #include <string>
17 #include <array>
18 #include <vector>
19
20 #include <dune/common/parametertree.hh>
21 #include <dune/common/std/type_traits.hh>
22 #include <dumux/common/parameters.hh>
23
24 namespace Dumux::Detail::LinearSolverParameters {
25 template <typename T>
26 using GVDetector = typename T::GridView;
27
28 template <typename T>
29 constexpr bool hasGridView = Dune::Std::is_detected<GVDetector, T>::value;
30 } // end namespace Dumux::Detail::LinearSolverParameters
31
32 namespace Dumux {
33
34 /*!
35 * \ingroup Linear
36 * \brief Generates a parameter tree required for the linear solvers and precondioners of the Dune ISTL
37 */
38 template<class LinearSolverTraits>
39 class LinearSolverParameters
40 {
41 public:
42
43 //! Translation table for solver parameters
44 static const std::vector<std::array<std::string, 2>> dumuxToIstlSolverParams;
45
46 //! Create a tree containing parameters required for the linear solvers and precondioners of the Dune ISTL
47 477 static Dune::ParameterTree createParameterTree(const std::string& paramGroup = "")
48 {
49 477 Dune::ParameterTree params;
50
1/2
✓ Branch 1 taken 437 times.
✗ Branch 2 not taken.
477 setDefaultParameters(params, paramGroup);
51
1/2
✓ Branch 1 taken 437 times.
✗ Branch 2 not taken.
477 fillValuesForIstlKeys(params, paramGroup);
52 477 return params;
53 }
54
55 //! Set some defaults for the solver parameters
56 477 static void setDefaultParameters(Dune::ParameterTree& params, const std::string& paramGroup = "")
57 {
58
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["restart"] = "10";
59
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["maxit"] = "250";
60
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["reduction"] = "1e-13";
61
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["verbose"] = "0";
62
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["preconditioner.iterations"] = "1";
63
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["preconditioner.relaxation"] = "1.0";
64
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["preconditioner.verbosity"] = "0";
65
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["preconditioner.defaultAggregationSizeMode"] = "isotropic";
66 if constexpr (Detail::LinearSolverParameters::hasGridView<LinearSolverTraits>)
67
2/4
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 360 times.
✗ Branch 6 not taken.
376 params["preconditioner.defaultAggregationDimension"] = std::to_string(LinearSolverTraits::GridView::dimension);
68 else
69
2/4
✓ Branch 2 taken 77 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 77 times.
✗ Branch 6 not taken.
101 params["preconditioner.defaultAggregationDimension"] = "3";
70
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
477 params["preconditioner.maxLevel"] = "100";
71
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
954 params["ParameterGroup"] = paramGroup;
72
2/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 437 times.
✗ Branch 6 not taken.
954 params["preconditioner.ParameterGroup"] = paramGroup;
73 477 }
74
75 //! Iterate over all keys required by the ISTL, translate them to Dumux syntax and add values to tree
76 477 static void fillValuesForIstlKeys(Dune::ParameterTree& params, const std::string& paramGroup = "")
77 {
78
3/4
✓ Branch 2 taken 437 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 332 times.
✓ Branch 5 taken 105 times.
954 const auto linearSolverGroups = getParamSubGroups("LinearSolver", paramGroup);
79
2/2
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 105 times.
477 if (linearSolverGroups.empty()) // no linear solver parameters were specified
80 return;
81
82
2/2
✓ Branch 0 taken 3570 times.
✓ Branch 1 taken 105 times.
3675 for (const auto& [dumuxKey, istlKey] : dumuxToIstlSolverParams)
83 {
84
2/2
✓ Branch 2 taken 3667 times.
✓ Branch 3 taken 3251 times.
7237 for (const auto& group : linearSolverGroups)
85 {
86
1/2
✓ Branch 1 taken 3667 times.
✗ Branch 2 not taken.
7334 const auto fullDumuxKey = group + "." + dumuxKey;
87
1/2
✓ Branch 1 taken 3667 times.
✗ Branch 2 not taken.
3667 const auto value = getParam<std::string>(fullDumuxKey, "");
88
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 3348 times.
3667 if (!value.empty())
89 {
90
2/4
✓ Branch 1 taken 319 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 319 times.
✗ Branch 5 not taken.
638 params[istlKey] = value;
91 break; // skip groups with smaller depth in the tree
92 }
93 }
94 }
95 477 }
96
97 11 static void disableVerbosity(Dune::ParameterTree& params)
98 {
99
2/4
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
11 params["verbose"] = "0";
100
2/4
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
11 params["preconditioner.verbosity"] = "0";
101 11 }
102 };
103
104 //! Translation table for solver parameters
105 //! TODO change to constexpr array of std::string_view once we require g++ >= 7.3 (bug in older versions)
106 template<class LinearSolverTraits>
107 const std::vector<std::array<std::string, 2>>
108 LinearSolverParameters<LinearSolverTraits>::dumuxToIstlSolverParams =
109 {
110 // solver params
111 {"Verbosity", "verbose"},
112 {"MaxIterations", "maxit"},
113 {"ResidualReduction", "reduction"},
114 {"Type", "type"},
115 {"GMResRestart", "restart"}, // cycles before restarting
116 {"Restart", "restart"}, // cycles before restarting
117 {"MaxOrthogonalizationVectors", "mmax"},
118
119 // preconditioner params
120 {"Preconditioner.Verbosity", "preconditioner.verbosity"},
121 {"Preconditioner.Type", "preconditioner.type"},
122 {"Preconditioner.Iterations", "preconditioner.iterations"},
123 {"Preconditioner.Relaxation", "preconditioner.relaxation"},
124 {"Preconditioner.ILUOrder", "preconditioner.n"},
125 {"Preconditioner.ILUResort", "preconditioner.resort"},
126 {"Preconditioner.AmgSmootherRelaxation", "preconditioner.smootherRelaxation"},
127 {"Preconditioner.AmgSmootherIterations", "preconditioner.smootherIterations"},
128 {"Preconditioner.AmgMaxLevel", "preconditioner.maxLevel"},
129 {"Preconditioner.AmgCoarsenTarget", "preconditioner.coarsenTarget"},
130 {"Preconditioner.AmgMinCoarseningRate", "preconditioner.minCoarseningRate"},
131 {"Preconditioner.AmgAccumulationMode", "preconditioner.accumulationMode"},
132 {"Preconditioner.AmgProlongationDampingFactor", "preconditioner.prolongationDampingFactor"},
133 {"Preconditioner.AmgAlpha", "preconditioner.alpha"},
134 {"Preconditioner.AmgBeta", "preconditioner.beta"},
135 {"Preconditioner.AmgAdditive", "preconditioner.additive"},
136 {"Preconditioner.AmgGamma", "preconditioner.gamma"},
137 {"Preconditioner.AmgPreSmoothingSteps", "preconditioner.preSteps"},
138 {"Preconditioner.AmgPostSmoothingSteps", "preconditioner.postSteps"},
139 {"Preconditioner.AmgCriterionSymmetric", "preconditioner.criterionSymmetric"},
140 {"Preconditioner.AmgStrengthMeasure", "preconditioner.strengthMeasure"},
141 {"Preconditioner.AmgDiagonalRowIndex", "preconditioner.diagonalRowIndex"},
142 {"Preconditioner.AmgDefaultAggregationSizeMode", "preconditioner.defaultAggregationSizeMode"},
143 {"Preconditioner.AmgDefaultAggregationDimension", "preconditioner.defaultAggregationDimension"},
144 {"Preconditioner.AmgMaxAggregateDistance", "preconditioner.maxAggregateDistance"},
145 {"Preconditioner.AmgMinAggregateSize", "preconditioner.minAggregateSize"},
146 {"Preconditioner.AmgMaxAggregateSize", "preconditioner.maxAggregateSize"}
147 };
148
149 } // end namespace Dumux
150
151 #endif
152