3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
linearsolverparameters.hh
Go to the documentation of this file.
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_LINEAR_SOLVER_PARAMETERS_HH
26#define DUMUX_LINEAR_SOLVER_PARAMETERS_HH
27
28#include <string>
29#include <array>
30#include <vector>
31
32#include <dune/common/parametertree.hh>
34
35namespace Dumux {
36
37template<class LinearSolverTraits>
39{
40public:
41
43 static const std::vector<std::array<std::string, 2>> dumuxToIstlSolverParams;
44
46 static Dune::ParameterTree createParameterTree(const std::string& paramGroup = "")
47 {
48 Dune::ParameterTree params;
49 setDefaultParameters(params, paramGroup);
50 fillValuesForIstlKeys(params, paramGroup);
51 return params;
52 }
53
55 static void setDefaultParameters(Dune::ParameterTree& params, const std::string& paramGroup = "")
56 {
57 params["restart"] = "10";
58 params["maxit"] = "250";
59 params["reduction"] = "1e-13";
60 params["verbose"] = "0";
61 params["preconditioner.iterations"] = "1";
62 params["preconditioner.relaxation"] = "1.0";
63 params["preconditioner.verbosity"] = "0";
64 params["preconditioner.defaultAggregationSizeMode"] = "isotropic";
65 params["preconditioner.defaultAggregationDimension"] = std::to_string(LinearSolverTraits::GridView::dimension);
66 params["preconditioner.maxLevel"] = "100";
67 params["ParameterGroup"] = paramGroup;
68 params["preconditioner.ParameterGroup"] = paramGroup;
69 }
70
72 static void fillValuesForIstlKeys(Dune::ParameterTree& params, const std::string& paramGroup = "")
73 {
74 const auto linearSolverGroups = getParamSubGroups("LinearSolver", paramGroup);
75 if (linearSolverGroups.empty()) // no linear solver parameters were specified
76 return;
77
78 for (const auto& [dumuxKey, istlKey] : dumuxToIstlSolverParams)
79 {
80 for (const auto& group : linearSolverGroups)
81 {
82 const auto fullDumuxKey = group + "." + dumuxKey;
83 const auto value = getParam<std::string>(fullDumuxKey, "");
84 if (!value.empty())
85 {
86 params[istlKey] = value;
87 break; // skip groups with smaller depth in the tree
88 }
89 }
90 }
91 }
92};
93
96template<class LinearSolverTraits>
97const std::vector<std::array<std::string, 2>>
99{
100 // solver params
101 {"Verbosity", "verbose"},
102 {"MaxIterations", "maxit"},
103 {"ResidualReduction", "reduction"},
104 {"Type", "type"},
105 {"GMResRestart", "restart"}, // cycles before restarting
106 {"Restart", "restart"}, // cycles before restarting
107 {"MaxOrthogonalizationVectors", "mmax"},
108
109 // preconditioner params
110 {"Preconditioner.Verbosity", "preconditioner.verbosity"},
111 {"Preconditioner.Type", "preconditioner.type"},
112 {"Preconditioner.Iterations", "preconditioner.iterations"},
113 {"Preconditioner.Relaxation", "preconditioner.relaxation"},
114 {"Preconditioner.ILUOrder", "preconditioner.n"},
115 {"Preconditioner.ILUResort", "preconditioner.resort"},
116 {"Preconditioner.AmgSmootherRelaxation", "preconditioner.smootherRelaxation"},
117 {"Preconditioner.AmgSmootherIterations", "preconditioner.smootherIterations"},
118 {"Preconditioner.AmgMaxLevel", "preconditioner.maxLevel"},
119 {"Preconditioner.AmgCoarsenTarget", "preconditioner.coarsenTarget"},
120 {"Preconditioner.AmgMinCoarseningRate", "preconditioner.minCoarseningRate"},
121 {"Preconditioner.AmgAccumulationMode", "preconditioner.accumulationMode"},
122 {"Preconditioner.AmgProlongationDampingFactor", "preconditioner.prolongationDampingFactor"},
123 {"Preconditioner.AmgAlpha", "preconditioner.alpha"},
124 {"Preconditioner.AmgBeta", "preconditioner.beta"},
125 {"Preconditioner.AmgAdditive", "preconditioner.additive"},
126 {"Preconditioner.AmgGamma", "preconditioner.gamma"},
127 {"Preconditioner.AmgPreSmoothingSteps", "preconditioner.preSteps"},
128 {"Preconditioner.AmgPostSmoothingSteps", "preconditioner.postSteps"},
129 {"Preconditioner.AmgCriterionSymmetric", "preconditioner.criterionSymmetric"},
130 {"Preconditioner.AmgStrengthMeasure", "preconditioner.strengthMeasure"},
131 {"Preconditioner.AmgDiagonalRowIndex", "preconditioner.diagonalRowIndex"},
132 {"Preconditioner.AmgDefaultAggregationSizeMode", "preconditioner.defaultAggregationSizeMode"},
133 {"Preconditioner.AmgDefaultAggregationDimension", "preconditioner.defaultAggregationDimension"},
134 {"Preconditioner.AmgMaxAggregateDistance", "preconditioner.maxAggregateDistance"},
135 {"Preconditioner.AmgMinAggregateSize", "preconditioner.minAggregateSize"},
136 {"Preconditioner.AmgMaxAggregateSize", "preconditioner.maxAggregateSize"}
137};
138
139} // end namespace Dumux
140
141#endif // DUMUX_LINEAR_SOLVER_PARAMETERS_HH
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
std::vector< std::string > getParamSubGroups(const std::string &subGroupName, const std::string &paramGroup)
Get a list of sub groups from the parameter tree sorted by relevance.
Definition: parameters.hh:399
Definition: adapt.hh:29
Definition: linearsolverparameters.hh:39
static const std::vector< std::array< std::string, 2 > > dumuxToIstlSolverParams
Translation table for solver parameters.
Definition: linearsolverparameters.hh:43
static void setDefaultParameters(Dune::ParameterTree &params, const std::string &paramGroup="")
Set some defaults for the solver parameters.
Definition: linearsolverparameters.hh:55
static void fillValuesForIstlKeys(Dune::ParameterTree &params, const std::string &paramGroup="")
Iterate over all keys required by the ISTL, translate them to Dumux syntax and add values to tree.
Definition: linearsolverparameters.hh:72
static Dune::ParameterTree createParameterTree(const std::string &paramGroup="")
Create a tree containing parameters required for the linear solvers and precondioners of the Dune IST...
Definition: linearsolverparameters.hh:46