From 9226e878c1e15d9999c1991bf9d43148a3c81c1d Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Mon, 20 Dec 2021 09:55:15 +0100 Subject: [PATCH] [MaL/LA/PETSc] LinearSolverOptionsParser templ. spezialisation. --- .../LinAlg/PETSc/LinearSolverOptionsParser.h | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 MathLib/LinAlg/PETSc/LinearSolverOptionsParser.h diff --git a/MathLib/LinAlg/PETSc/LinearSolverOptionsParser.h b/MathLib/LinAlg/PETSc/LinearSolverOptionsParser.h new file mode 100644 index 00000000000..7a73799f3d5 --- /dev/null +++ b/MathLib/LinAlg/PETSc/LinearSolverOptionsParser.h @@ -0,0 +1,68 @@ +/** + * \file + * \copyright + * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#pragma once + +#include "BaseLib/ConfigTree.h" +#include "MathLib/LinAlg/LinearSolverOptions.h" +#include "MathLib/LinAlg/LinearSolverOptionsParser.h" +#include "MathLib/LinAlg/PETSc/PETScLinearSolver.h" + +namespace MathLib +{ +template <> +struct LinearSolverOptionsParser<PETScLinearSolver> final +{ + /// The method parses the linear solver options for PETSc. + /// @param solver_prefix the prefix for the linear solver to distinguish + /// different linear solvers for instance in the staggered schema + /// @param config the part of the property tree (usually created from the + /// linear solver section in the project file) + /// @return the first item of the returned tuple is the solver prefix as + /// string, the second item are all the options passed as string to PETSc + /// options database + std::tuple<std::string, std::string> parseNameAndOptions( + std::string solver_prefix, + BaseLib::ConfigTree const* const config) const + { + // Insert options into petsc database. Default options are given in the + // string below. + std::string petsc_options = + "-ksp_type cg -pc_type bjacobi -ksp_rtol 1e-16 -ksp_max_it 10000"; + + if (config) + { + ignoreOtherLinearSolvers(*config, "petsc"); + + //! \ogs_file_param{prj__linear_solvers__linear_solver__petsc} + if (auto const subtree = config->getConfigSubtreeOptional("petsc")) + { + if (auto const parameters = + //! \ogs_file_param{prj__linear_solvers__linear_solver__petsc__parameters} + subtree->getConfigParameterOptional<std::string>( + "parameters")) + { + petsc_options = *parameters; + } + + if (auto const pre = + //! \ogs_file_param{prj__linear_solvers__linear_solver__petsc__prefix} + subtree->getConfigParameterOptional<std::string>("prefix")) + { + if (!pre->empty()) + solver_prefix = *pre + "_"; + } + } + } + return {solver_prefix, petsc_options}; + } +}; + +} // namespace MathLib -- GitLab