OGS
LinearSolverOptionsParser.cpp
Go to the documentation of this file.
1
12
13#include "BaseLib/ConfigTree.h"
14#include "BaseLib/Error.h"
16
17namespace MathLib
18{
19std::tuple<std::string, EigenOption>
21 std::string const& prefix,
22 BaseLib::ConfigTree const* const solver_config) const
23{
24 if (!solver_config)
25 {
26 return {prefix, EigenOption{}};
27 }
28
29 ignoreOtherLinearSolvers(*solver_config, "eigen");
31 auto const config = solver_config->getConfigSubtreeOptional("eigen");
32 if (!config)
33 {
35 "OGS was compiled with Eigen but the config section in the "
36 "project file seems to be invalid");
37 }
38
39 EigenOption options;
40
41 if (auto solver_type =
43 config->getConfigParameterOptional<std::string>("solver_type"))
44 {
46 }
47 if (auto precon_type =
49 config->getConfigParameterOptional<std::string>("precon_type"))
50 {
52 }
53 if (auto error_tolerance =
55 config->getConfigParameterOptional<double>("error_tolerance"))
56 {
57 options.error_tolerance = *error_tolerance;
58 }
59 if (auto max_iteration_step =
61 config->getConfigParameterOptional<int>("max_iteration_step"))
62 {
63 options.max_iterations = *max_iteration_step;
64 }
65 if (auto scaling =
67 config->getConfigParameterOptional<bool>("scaling"))
68 {
69#ifdef USE_EIGEN_UNSUPPORTED
70 options.scaling = *scaling;
71#else
73 "The code is not compiled with the Eigen unsupported modules. "
74 "scaling is not available.");
75#endif
76 }
77 if (auto restart =
79 config->getConfigParameterOptional<int>("restart"))
80 {
81#ifdef USE_EIGEN_UNSUPPORTED
82 options.restart = *restart;
83#else
85 "The code is not compiled with the Eigen unsupported modules. "
86 "GMRES/GMRES option restart is not available.");
87#endif
88 }
89 if (auto l =
91 config->getConfigParameterOptional<int>("l"))
92 {
93#ifdef USE_EIGEN_UNSUPPORTED
94 options.l = *l;
95#else
97 "The code is not compiled with the Eigen unsupported modules.");
98#endif
99 }
100 if (auto s =
102 config->getConfigParameterOptional<int>("s"))
103 {
104#ifdef USE_EIGEN_UNSUPPORTED
105 options.s = *s;
106#else
107 OGS_FATAL(
108 "The code is not compiled with the Eigen unsupported modules.");
109#endif
110 }
111 if (auto smoothing =
113 config->getConfigParameterOptional<int>("smoothing"))
114 {
115#ifdef USE_EIGEN_UNSUPPORTED
116 options.smoothing = *smoothing;
117#else
118 OGS_FATAL(
119 "The code is not compiled with the Eigen unsupported modules.");
120#endif
121 }
122 if (auto angle =
124 config->getConfigParameterOptional<int>("angle"))
125 {
126#ifdef USE_EIGEN_UNSUPPORTED
127 options.angle = *angle;
128#else
129 OGS_FATAL(
130 "The code is not compiled with the Eigen unsupported modules.");
131#endif
132 }
133 if (auto residualupdate =
135 config->getConfigParameterOptional<int>("residual_update"))
136 {
137#ifdef USE_EIGEN_UNSUPPORTED
138 options.residualupdate = *residualupdate;
139#else
140 OGS_FATAL(
141 "The code is not compiled with the Eigen unsupported modules.");
142#endif
143 }
144 return {prefix, options};
145}
146} // namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:26
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
static const double s
void ignoreOtherLinearSolvers(const BaseLib::ConfigTree &config, const std::string &solver_name)
Option for Eigen sparse solver.
Definition EigenOption.h:19
PreconType precon_type
Preconditioner type.
Definition EigenOption.h:44
static PreconType getPreconType(const std::string &precon_name)
SolverType solver_type
Linear solver type.
Definition EigenOption.h:42
double error_tolerance
Error tolerance.
Definition EigenOption.h:48
static SolverType getSolverType(const std::string &solver_name)
int max_iterations
Maximum iteration count.
Definition EigenOption.h:46