FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
polynomial_precond.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/solver/base.hpp>
11
12namespace FEAT
13{
14 namespace Solver
15 {
24 template<typename Matrix_, typename Filter_>
26 public SolverBase<typename Matrix_::VectorTypeL>
27 {
28 public:
30 typedef Matrix_ MatrixType;
32 typedef Filter_ FilterType;
34 typedef typename MatrixType::VectorTypeL VectorType;
36 typedef typename MatrixType::DataType DataType;
39
40 protected:
52 VectorType _aux1, _aux2, _aux3;
53
54 public:
70 explicit PolynomialPrecond(const MatrixType& matrix, const FilterType& filter, Index m, DataType omega = DataType(1)) :
71 _matrix(matrix),
72 _filter(filter),
73 _m(m),
74 _omega(omega)
75 {
76 }
77
96 explicit PolynomialPrecond(const String& section_name, const PropertyMap* section,
97 const MatrixType& matrix, const FilterType& filter) :
98 BaseClass(section_name, section),
99 _matrix(matrix),
100 _filter(filter),
101 _m(1),
102 _omega(1)
103 {
104 auto omega_p = section->query("omega");
105 if(omega_p.second)
106 {
107 set_omega(DataType(std::stod(omega_p.first)));
108 }
109 else
110 {
111 XABORTM(name()+" config section is missing the mandatory omega key!");
112 }
113
114 auto m_p = section->query("m");
115 if(m_p.second)
116 {
117 set_m(std::stoul(m_p.first));
118 }
119 else
120 {
121 XABORTM(name()+" config section is missing the mandatory m key!");
122 }
123 }
124
129 {
130 }
131
133 virtual String name() const override
134 {
135 return "Polynomial";
136 }
137
139 virtual void init_symbolic() override
140 {
141 _inv_diag = _matrix.create_vector_r();
142 _aux1 = _matrix.create_vector_r();
143 _aux2 = _matrix.create_vector_r();
144 _aux3 = _matrix.create_vector_r();
145 }
146
148 virtual void done_symbolic() override
149 {
150 _inv_diag.clear();
151 _aux1.clear();
152 _aux2.clear();
153 _aux3.clear();
154 }
155
157 virtual void init_numeric() override
158 {
159 // extract matrix diagonal
160 _matrix.extract_diag(_inv_diag);
161
162 // invert diagonal elements
163 _inv_diag.component_invert(_inv_diag, _omega);
164 }
165
173 void set_omega(DataType omega)
174 {
175 XASSERT(omega > DataType(0));
176 _omega = omega;
177 }
178
186 void set_m(Index m)
187 {
188 XASSERT(m > Index(0));
189 _m = m;
190 }
191
193 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
194 {
195 /*
196 * preconditioner is given by
197 * \f$ M^-1 = \left(I + (I - \tilde M^{-1}A) + ... + (I - \tilde M^{-1 }A)^m\right) \tilde M^{-1} \f$
198 *
199 * the preconditioner only works, if
200 * ||I - \tilde M^{-1} A||_2 < 1.
201 */
202
203 vec_cor.component_product(_inv_diag, vec_def);
204 _aux3.copy(vec_cor);
205
206 for (Index i = 1; i <= _m; ++i)
207 {
208 _matrix.apply(_aux1, vec_cor);
209 _filter.filter_def(_aux1);
210 _aux2.component_product(_inv_diag, _aux1);
211 vec_cor.axpy(_aux3);
212 vec_cor.axpy(_aux2, DataType(-1.0));
213 }
214
215 this->_filter.filter_cor(vec_cor);
216
217 return Status::success;
218 }
219 }; // class PolynomialPrecond<...>
220
239 template<typename Matrix_, typename Filter_>
240 inline std::shared_ptr<PolynomialPrecond<Matrix_, Filter_>> new_polynomial_precond(
241 const Matrix_& matrix, const Filter_& filter,
242 const Index m, const typename Matrix_::DataType omega = typename Matrix_::DataType(1))
243 {
244 return std::make_shared<PolynomialPrecond<Matrix_, Filter_>>(matrix, filter, m, omega);
245 }
246
265 template<typename Matrix_, typename Filter_>
266 inline std::shared_ptr<PolynomialPrecond<Matrix_, Filter_>> new_polynomial_precond(
267 const String& section_name, const PropertyMap* section,
268 const Matrix_& matrix, const Filter_& filter)
269 {
270 return std::make_shared<PolynomialPrecond<Matrix_, Filter_>>(section_name, section, matrix, filter);
271 }
272 } // namespace Solver
273} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Polynomial preconditioner implementation.
Filter_ FilterType
The filter type.
const MatrixType & _matrix
The system matrix.
PolynomialPrecond(const String &section_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter)
Constructor using a PropertyMap.
void set_m(Index m)
Sets the polynomial order parameter.
Index _m
order m of preconditioner
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
virtual ~PolynomialPrecond()
Empty virtual destructor.
virtual void done_symbolic() override
Symbolic finalization method.
const FilterType & _filter
The filter for projecting solution and defect to subspaces.
MatrixType::DataType DataType
The floating point precision.
virtual String name() const override
Returns a descriptive string.
SolverBase< VectorType > BaseClass
Our base class.
VectorType _aux1
auxiliary vectors
virtual void init_symbolic() override
Symbolic initialization method.
PolynomialPrecond(const MatrixType &matrix, const FilterType &filter, Index m, DataType omega=DataType(1))
Constructor.
Matrix_ MatrixType
The matrix type.
VectorType _inv_diag
The component-wise inverted diagonal of _matrix.
DataType _omega
The damping parameter for the internal jacobi preconditioner.
virtual void init_numeric() override
Numeric initialization method.
void set_omega(DataType omega)
Sets the damping parameter.
MatrixType::VectorTypeL VectorType
The type of vector this solver can be applied to.
Polymorphic solver interface.
Definition: base.hpp:183
String class implementation.
Definition: string.hpp:46
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ success
solving successful (convergence criterion fulfilled)
std::shared_ptr< PolynomialPrecond< Matrix_, Filter_ > > new_polynomial_precond(const Matrix_ &matrix, const Filter_ &filter, const Index m, const typename Matrix_::DataType omega=typename Matrix_::DataType(1))
Creates a new PoynomialPrecond solver object.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.