GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/linear/linearsolverparameters.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 186 192 96.9%
Branches: 110 232 47.4%

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 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 440 static Dune::ParameterTree createParameterTree(const std::string& paramGroup = "")
48 {
49 440 Dune::ParameterTree params;
50
1/2
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
440 setDefaultParameters(params, paramGroup);
51
1/2
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
440 fillValuesForIstlKeys(params, paramGroup);
52 440 return params;
53 }
54
55 //! Set some defaults for the solver parameters
56 440 static void setDefaultParameters(Dune::ParameterTree& params, const std::string& paramGroup = "")
57 {
58
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 400 times.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
880 params["restart"] = "10";
59
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 400 times.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
880 params["maxit"] = "250";
60
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 400 times.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
880 params["reduction"] = "1e-13";
61
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 400 times.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
880 params["verbose"] = "0";
62
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 400 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1320 params["preconditioner.iterations"] = "1";
63
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 400 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1320 params["preconditioner.relaxation"] = "1.0";
64
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 400 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1320 params["preconditioner.verbosity"] = "0";
65
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 400 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 75 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1320 params["preconditioner.defaultAggregationSizeMode"] = "isotropic";
66 if constexpr (Detail::LinearSolverParameters::hasGridView<LinearSolverTraits>)
67
6/16
✓ Branch 2 taken 325 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 325 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 325 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 325 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 325 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 325 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
1023 params["preconditioner.defaultAggregationDimension"] = std::to_string(LinearSolverTraits::GridView::dimension);
68 else
69
6/14
✓ Branch 1 taken 75 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 75 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 75 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 75 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 75 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 75 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
297 params["preconditioner.defaultAggregationDimension"] = "3";
70
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 400 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1320 params["preconditioner.maxLevel"] = "100";
71
6/14
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 400 times.
✓ Branch 15 taken 400 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
880 params["ParameterGroup"] = paramGroup;
72
5/12
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 400 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 400 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 400 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
1320 params["preconditioner.ParameterGroup"] = paramGroup;
73 440 }
74
75 //! Iterate over all keys required by the ISTL, translate them to Dumux syntax and add values to tree
76 400 static void fillValuesForIstlKeys(Dune::ParameterTree& params, const std::string& paramGroup = "")
77 {
78
5/8
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 360 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 360 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 263 times.
✓ Branch 10 taken 97 times.
1297 const auto linearSolverGroups = getParamSubGroups("LinearSolver", paramGroup);
79
4/4
✓ Branch 0 taken 263 times.
✓ Branch 1 taken 97 times.
✓ Branch 2 taken 263 times.
✓ Branch 3 taken 97 times.
800 if (linearSolverGroups.empty()) // no linear solver parameters were specified
80 303 return;
81
82
4/4
✓ Branch 0 taken 3298 times.
✓ Branch 1 taken 97 times.
✓ Branch 2 taken 3298 times.
✓ Branch 3 taken 97 times.
3589 for (const auto& [dumuxKey, istlKey] : dumuxToIstlSolverParams)
83 {
84
4/4
✓ Branch 0 taken 3395 times.
✓ Branch 1 taken 3019 times.
✓ Branch 2 taken 3395 times.
✓ Branch 3 taken 3019 times.
16126 for (const auto& group : linearSolverGroups)
85 {
86
2/6
✓ Branch 1 taken 3395 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3395 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6511 const auto fullDumuxKey = group + "." + dumuxKey;
87
3/8
✓ Branch 1 taken 3395 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3116 times.
✓ Branch 5 taken 3116 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
6511 const auto value = getParam<std::string>(fullDumuxKey, "");
88
4/4
✓ Branch 0 taken 279 times.
✓ Branch 1 taken 3116 times.
✓ Branch 2 taken 279 times.
✓ Branch 3 taken 3116 times.
6790 if (!value.empty())
89 {
90
2/4
✓ Branch 1 taken 279 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 279 times.
✗ Branch 5 not taken.
279 params[istlKey] = value;
91
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 279 times.
✗ Branch 3 not taken.
280 break; // skip groups with smaller depth in the tree
92 }
93 }
94 }
95 }
96 };
97
98 //! Translation table for solver parameters
99 //! TODO change to constexpr array of std::string_view once we require g++ >= 7.3 (bug in older versions)
100 template<class LinearSolverTraits>
101 const std::vector<std::array<std::string, 2>>
102 LinearSolverParameters<LinearSolverTraits>::dumuxToIstlSolverParams =
103 {
104 // solver params
105 {"Verbosity", "verbose"},
106 {"MaxIterations", "maxit"},
107 {"ResidualReduction", "reduction"},
108 {"Type", "type"},
109 {"GMResRestart", "restart"}, // cycles before restarting
110 {"Restart", "restart"}, // cycles before restarting
111 {"MaxOrthogonalizationVectors", "mmax"},
112
113 // preconditioner params
114 {"Preconditioner.Verbosity", "preconditioner.verbosity"},
115 {"Preconditioner.Type", "preconditioner.type"},
116 {"Preconditioner.Iterations", "preconditioner.iterations"},
117 {"Preconditioner.Relaxation", "preconditioner.relaxation"},
118 {"Preconditioner.ILUOrder", "preconditioner.n"},
119 {"Preconditioner.ILUResort", "preconditioner.resort"},
120 {"Preconditioner.AmgSmootherRelaxation", "preconditioner.smootherRelaxation"},
121 {"Preconditioner.AmgSmootherIterations", "preconditioner.smootherIterations"},
122 {"Preconditioner.AmgMaxLevel", "preconditioner.maxLevel"},
123 {"Preconditioner.AmgCoarsenTarget", "preconditioner.coarsenTarget"},
124 {"Preconditioner.AmgMinCoarseningRate", "preconditioner.minCoarseningRate"},
125 {"Preconditioner.AmgAccumulationMode", "preconditioner.accumulationMode"},
126 {"Preconditioner.AmgProlongationDampingFactor", "preconditioner.prolongationDampingFactor"},
127 {"Preconditioner.AmgAlpha", "preconditioner.alpha"},
128 {"Preconditioner.AmgBeta", "preconditioner.beta"},
129 {"Preconditioner.AmgAdditive", "preconditioner.additive"},
130 {"Preconditioner.AmgGamma", "preconditioner.gamma"},
131 {"Preconditioner.AmgPreSmoothingSteps", "preconditioner.preSteps"},
132 {"Preconditioner.AmgPostSmoothingSteps", "preconditioner.postSteps"},
133 {"Preconditioner.AmgCriterionSymmetric", "preconditioner.criterionSymmetric"},
134 {"Preconditioner.AmgStrengthMeasure", "preconditioner.strengthMeasure"},
135 {"Preconditioner.AmgDiagonalRowIndex", "preconditioner.diagonalRowIndex"},
136 {"Preconditioner.AmgDefaultAggregationSizeMode", "preconditioner.defaultAggregationSizeMode"},
137 {"Preconditioner.AmgDefaultAggregationDimension", "preconditioner.defaultAggregationDimension"},
138 {"Preconditioner.AmgMaxAggregateDistance", "preconditioner.maxAggregateDistance"},
139 {"Preconditioner.AmgMinAggregateSize", "preconditioner.minAggregateSize"},
140 {"Preconditioner.AmgMaxAggregateSize", "preconditioner.maxAggregateSize"}
141 };
142
143 } // end namespace Dumux
144
145 #endif
146