ExaDG
Loading...
Searching...
No Matches
solver_data.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_SOLVERS_AND_PRECONDITIONERS_SOLVERS_SOLVER_DATA_H_
23#define EXADG_SOLVERS_AND_PRECONDITIONERS_SOLVERS_SOLVER_DATA_H_
24
25// deal.II
26#include <deal.II/base/conditional_ostream.h>
27
28// ExaDG
29#include <exadg/utilities/print_functions.h>
30
31namespace ExaDG
32{
33enum class LinearSolver
34{
35 Undefined,
36 CG,
37 GMRES,
38 FGMRES,
39 BiCGStab,
40 MinRes,
41 Richardson
42};
43
44// Function to convert the `Linearsolver` enum to the `std::string` identifying the solver type in
45// `dealii::SolverSelector`.
46inline std::string
47linear_solver_to_string(LinearSolver const linear_solver)
48{
49 std::string solver_name = "conversion from `LinearSolver` to `std::string` failed";
50
51 if(linear_solver == LinearSolver::Undefined)
52 {
53 AssertThrow(false,
54 dealii::ExcMessage(
55 "Linear solver type `LinearSolver::Undefined` cannot not be parsed to "
56 "`std::string`. Select an admissible `LinearSolver`."));
57 }
58 else if(linear_solver == LinearSolver::CG)
59 {
60 solver_name = "cg";
61 }
62 else if(linear_solver == LinearSolver::GMRES)
63 {
64 solver_name = "gmres";
65 }
66 else if(linear_solver == LinearSolver::FGMRES)
67 {
68 solver_name = "fgmres";
69 }
70 else if(linear_solver == LinearSolver::BiCGStab)
71 {
72 solver_name = "bicgstab";
73 }
74 else if(linear_solver == LinearSolver::MinRes)
75 {
76 solver_name = "minres";
77 }
78 else if(linear_solver == LinearSolver::Richardson)
79 {
80 solver_name = "richardson";
81 }
82 else
83 {
84 AssertThrow(
85 false, dealii::ExcMessage("This linear solver type cannot not be parsed to `std::string`."));
86 }
87
88 return solver_name;
89}
90
91struct SolverData
92{
93 SolverData()
94 : max_iter(1e3),
95 abs_tol(1e-20),
96 rel_tol(1e-6),
97 linear_solver(LinearSolver::Undefined),
98 max_krylov_size(30)
99 {
100 }
101
102 SolverData(unsigned int const max_iter_in,
103 double const abs_tol_in,
104 double const rel_tol_in,
105 LinearSolver const linear_solver_in = LinearSolver::Undefined,
106 unsigned int const max_krylov_size_in = 30)
107 : max_iter(max_iter_in),
108 abs_tol(abs_tol_in),
109 rel_tol(rel_tol_in),
110 linear_solver(linear_solver_in),
111 max_krylov_size(max_krylov_size_in)
112 {
113 }
114
115 void
116 print(dealii::ConditionalOStream const & pcout) const
117 {
118 // `SolverData` can also be used to control tolerances without specifying the solver type.
119 if(linear_solver != LinearSolver::Undefined)
120 {
121 print_parameter(pcout, "Solver", linear_solver);
122 }
123
124 print_parameter(pcout, "Maximum number of iterations", max_iter);
125 print_parameter(pcout, "Absolute solver tolerance", abs_tol);
126 print_parameter(pcout, "Relative solver tolerance", rel_tol);
127
128 // Print maximum Krylov space size for relevant methods or when using the default
129 // `LinearSolver`.
130 if(linear_solver == LinearSolver::FGMRES or linear_solver == LinearSolver::GMRES or
131 linear_solver == LinearSolver::Undefined)
132 {
133 print_parameter(pcout, "Maximum size of Krylov space", max_krylov_size);
134 }
135 }
136
137 unsigned int max_iter;
138 double abs_tol;
139 double rel_tol;
140
141 // solver type to be used
142 LinearSolver linear_solver;
143
144 // only relevant for GMRES type solvers
145 unsigned int max_krylov_size;
146};
147
148} // namespace ExaDG
149
150#endif /* EXADG_SOLVERS_AND_PRECONDITIONERS_SOLVERS_SOLVER_DATA_H_ */
Definition driver.cpp:33