OGS
PETSc/LinearSolverOptionsParser.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
8
9namespace MathLib
10{
11std::tuple<std::string, std::string>
13 std::string solver_prefix, BaseLib::ConfigTree const* const config) const
14{
15 // Insert options into petsc database. Default options are given in the
16 // string below.
17 std::string petsc_options =
18 "-ksp_type cg -pc_type bjacobi -ksp_rtol 1e-16 -ksp_max_it 10000";
19
20 if (config)
21 {
22 ignoreOtherLinearSolvers(*config, "petsc");
23
25 if (auto const subtree = config->getConfigSubtreeOptional("petsc"))
26 {
27 if (auto const parameters =
29 subtree->getConfigParameterOptional<std::string>("parameters"))
30 {
31 petsc_options = *parameters;
32 }
33
34 if (auto const pre =
36 subtree->getConfigParameterOptional<std::string>("prefix"))
37 {
38 if (!pre->empty())
39 solver_prefix = *pre + "_";
40 }
41 }
42 }
43 return {solver_prefix, petsc_options};
44}
45} // namespace MathLib
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
void ignoreOtherLinearSolvers(const BaseLib::ConfigTree &config, const std::string &solver_name)