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 | 441 | static Dune::ParameterTree createParameterTree(const std::string& paramGroup = "") | |
48 | { | ||
49 | 441 | Dune::ParameterTree params; | |
50 |
1/2✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
|
441 | setDefaultParameters(params, paramGroup); |
51 |
1/2✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
|
441 | fillValuesForIstlKeys(params, paramGroup); |
52 | 441 | return params; | |
53 | } | ||
54 | |||
55 | //! Set some defaults for the solver parameters | ||
56 | 441 | static void setDefaultParameters(Dune::ParameterTree& params, const std::string& paramGroup = "") | |
57 | { | ||
58 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 401 times.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
882 | params["restart"] = "10"; |
59 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 401 times.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
882 | params["maxit"] = "250"; |
60 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 401 times.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
882 | params["reduction"] = "1e-13"; |
61 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 401 times.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
882 | params["verbose"] = "0"; |
62 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 401 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1323 | params["preconditioner.iterations"] = "1"; |
63 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 401 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1323 | params["preconditioner.relaxation"] = "1.0"; |
64 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 401 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1323 | params["preconditioner.verbosity"] = "0"; |
65 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 401 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 79 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1323 | params["preconditioner.defaultAggregationSizeMode"] = "isotropic"; |
66 | if constexpr (Detail::LinearSolverParameters::hasGridView<LinearSolverTraits>) | ||
67 |
6/16✓ Branch 2 taken 322 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 322 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 322 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 322 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 322 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 322 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1014 | params["preconditioner.defaultAggregationDimension"] = std::to_string(LinearSolverTraits::GridView::dimension); |
68 | else | ||
69 |
6/14✓ Branch 1 taken 79 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 79 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 79 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 79 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 79 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
309 | params["preconditioner.defaultAggregationDimension"] = "3"; |
70 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 401 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1323 | params["preconditioner.maxLevel"] = "100"; |
71 |
6/14✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 401 times.
✓ Branch 15 taken 401 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
882 | params["ParameterGroup"] = paramGroup; |
72 |
5/12✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 401 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 401 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 401 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
1323 | params["preconditioner.ParameterGroup"] = paramGroup; |
73 | 441 | } | |
74 | |||
75 | //! Iterate over all keys required by the ISTL, translate them to Dumux syntax and add values to tree | ||
76 | 401 | static void fillValuesForIstlKeys(Dune::ParameterTree& params, const std::string& paramGroup = "") | |
77 | { | ||
78 |
5/8✓ Branch 1 taken 361 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 361 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 361 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 265 times.
✓ Branch 10 taken 96 times.
|
1299 | const auto linearSolverGroups = getParamSubGroups("LinearSolver", paramGroup); |
79 |
4/4✓ Branch 0 taken 265 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 265 times.
✓ Branch 3 taken 96 times.
|
802 | if (linearSolverGroups.empty()) // no linear solver parameters were specified |
80 | 305 | return; | |
81 | |||
82 |
4/4✓ Branch 0 taken 3264 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 3264 times.
✓ Branch 3 taken 96 times.
|
3552 | for (const auto& [dumuxKey, istlKey] : dumuxToIstlSolverParams) |
83 | { | ||
84 |
4/4✓ Branch 0 taken 3361 times.
✓ Branch 1 taken 3000 times.
✓ Branch 2 taken 3361 times.
✓ Branch 3 taken 3000 times.
|
15986 | for (const auto& group : linearSolverGroups) |
85 | { | ||
86 |
2/6✓ Branch 1 taken 3361 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3361 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
6458 | const auto fullDumuxKey = group + "." + dumuxKey; |
87 |
3/8✓ Branch 1 taken 3361 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3097 times.
✓ Branch 5 taken 3097 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
6458 | const auto value = getParam<std::string>(fullDumuxKey, ""); |
88 |
4/4✓ Branch 0 taken 264 times.
✓ Branch 1 taken 3097 times.
✓ Branch 2 taken 264 times.
✓ Branch 3 taken 3097 times.
|
6722 | if (!value.empty()) |
89 | { | ||
90 |
2/4✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 264 times.
✗ Branch 5 not taken.
|
264 | params[istlKey] = value; |
91 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 263 times.
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
|
265 | 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 |