ExaDG
Loading...
Searching...
No Matches
gmres_smoother.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 INCLUDE_SOLVERS_AND_PRECONDITIONERS_GMRESSMOOTHER_H_
23#define INCLUDE_SOLVERS_AND_PRECONDITIONERS_GMRESSMOOTHER_H_
24
25// deal.II
26#include <deal.II/lac/solver_gmres.h>
27
28// ExaDG
29#include <exadg/solvers_and_preconditioners/multigrid/multigrid_parameters.h>
30#include <exadg/solvers_and_preconditioners/multigrid/smoothers/smoother_base.h>
31#include <exadg/solvers_and_preconditioners/preconditioners/block_jacobi_preconditioner.h>
32#include <exadg/solvers_and_preconditioners/preconditioners/jacobi_preconditioner.h>
33
34namespace ExaDG
35{
36template<typename Operator, typename VectorType>
37class GMRESSmoother : public SmootherBase<VectorType>
38{
39public:
40 GMRESSmoother() : underlying_operator(nullptr), preconditioner(nullptr)
41 {
42 }
43
45 {
46 delete preconditioner;
47 preconditioner = nullptr;
48 }
49
50 GMRESSmoother(GMRESSmoother const &) = delete;
51
53 operator=(GMRESSmoother const &) = delete;
54
56 {
60 AdditionalData() : preconditioner(PreconditionerSmoother::None), number_of_iterations(5)
61 {
62 }
63
64 // preconditioner
65 PreconditionerSmoother preconditioner;
66
67 // number of GMRES iterations per smoothing step
68 unsigned int number_of_iterations;
69 };
70
71 void
72 setup(Operator const & operator_in,
73 bool const initialize_preconditioner,
74 AdditionalData const & additional_data_in)
75 {
76 underlying_operator = &operator_in;
77
78 data = additional_data_in;
79
80 if(data.preconditioner == PreconditionerSmoother::PointJacobi)
81 {
82 preconditioner =
83 new JacobiPreconditioner<Operator>(*underlying_operator, initialize_preconditioner);
84 }
85 else if(data.preconditioner == PreconditionerSmoother::BlockJacobi)
86 {
87 preconditioner =
88 new BlockJacobiPreconditioner<Operator>(*underlying_operator, initialize_preconditioner);
89 }
90 else
91 {
92 AssertThrow(data.preconditioner == PreconditionerSmoother::None,
93 dealii::ExcMessage(
94 "Specified preconditioner not implemented for GMRES smoother"));
95 }
96 }
97
98 void
99 update() final
100 {
101 if(preconditioner != nullptr)
102 preconditioner->update();
103 }
104
105 // same as step(), but sets dst-vector to zero
106 void
107 vmult(VectorType & dst, VectorType const & src) const final
108 {
109 dst = 0.0;
110 step(dst, src);
111 }
112
113 void
114 step(VectorType & dst, VectorType const & src) const final
115 {
116 dealii::IterationNumberControl control(data.number_of_iterations, 1.e-20);
117
118 typename dealii::SolverGMRES<VectorType>::AdditionalData additional_data;
119 additional_data.right_preconditioning = true;
120 dealii::SolverGMRES<VectorType> solver(control, additional_data);
121
122 if(preconditioner != nullptr)
123 solver.solve(*underlying_operator, dst, src, *preconditioner);
124 else
125 solver.solve(*underlying_operator, dst, src, dealii::PreconditionIdentity());
126 }
127
128private:
129 Operator const * underlying_operator;
130
131 AdditionalData data;
132
133 PreconditionerBase<typename Operator::value_type> * preconditioner;
134};
135} // namespace ExaDG
136
137#endif /* INCLUDE_SOLVERS_AND_PRECONDITIONERS_GMRESSMOOTHER_H_ */
Definition gmres_smoother.h:38
Definition jacobi_preconditioner.h:35
Definition smoother_base.h:29
Definition driver.cpp:33
Definition gmres_smoother.h:56
AdditionalData()
Definition gmres_smoother.h:60