FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
jacobi_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
9#include <kernel/solver/base.hpp>
10
11namespace FEAT
12{
13 namespace Solver
14 {
32 template<typename Matrix_, typename Filter_>
34 public SolverBase<typename Matrix_::VectorTypeL>
35 {
36 public:
38 typedef Matrix_ MatrixType;
40 typedef Filter_ FilterType;
42 typedef typename MatrixType::VectorTypeL VectorType;
44 typedef typename MatrixType::DataType DataType;
47
48 protected:
57
58 public:
71 explicit JacobiPrecond(const MatrixType& matrix, const FilterType& filter, DataType omega = DataType(1)) :
72 _matrix(matrix),
73 _filter(filter),
74 _omega(omega)
75 {
76 }
77
96 explicit JacobiPrecond(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 _omega(1)
102 {
103 auto omega_p = section->query("omega");
104 if(omega_p.second && (!omega_p.first.parse(this->_omega) || (this->_omega <= DataType(0))))
105 throw ParseError(section_name + ".omega", omega_p.first, "a positive float");
106 }
107
112 {
113 }
114
116 virtual String name() const override
117 {
118 return "Jacobi";
119 }
120
122 virtual void init_symbolic() override
123 {
124 _inv_diag = _matrix.create_vector_r();
125 }
126
128 virtual void done_symbolic() override
129 {
130 _inv_diag.clear();
131 }
132
134 virtual void init_numeric() override
135 {
136 // extract matrix diagonal
137 _matrix.extract_diag(_inv_diag);
138
139 // invert diagonal elements
140 _inv_diag.component_invert(_inv_diag, _omega);
141 }
142
150 void set_omega(DataType omega)
151 {
152 XASSERT(omega > DataType(0));
153 _omega = omega;
154 }
155
157 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
158 {
159 vec_cor.component_product(_inv_diag, vec_def);
160 this->_filter.filter_cor(vec_cor);
161 return Status::success;
162 }
163 }; // class JacobiPrecond<...>
164
180 template<typename Matrix_, typename Filter_>
181 inline std::shared_ptr<JacobiPrecond<Matrix_, Filter_>> new_jacobi_precond(
182 const Matrix_& matrix, const Filter_& filter,
183 const typename Matrix_::DataType omega = typename Matrix_::DataType(1))
184 {
185 return std::make_shared<JacobiPrecond<Matrix_, Filter_>>(matrix, filter, omega);
186 }
187
203 template<typename Matrix_, typename Filter_>
204 inline std::shared_ptr<JacobiPrecond<Matrix_, Filter_>> new_jacobi_precond(
205 const String& section_name, const PropertyMap* section,
206 const Matrix_& matrix, const Filter_& filter)
207 {
208 return std::make_shared<JacobiPrecond<Matrix_, Filter_>>(section_name, section, matrix, filter);
209 }
210
211 } // namespace Solver
212} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
Class for parser related errors.
Definition: exception.hpp:132
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.
Jacobi preconditioner implementation.
DataType _omega
The damping parameter.
const MatrixType & _matrix
The system matrix.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
MatrixType::DataType DataType
The floating point precision.
VectorType _inv_diag
The component-wise inverted diagonal of _matrix.
virtual ~JacobiPrecond()
Empty virtual destructor.
const FilterType & _filter
The filter for projecting solution and defect to subspaces.
void set_omega(DataType omega)
Sets the damping parameter.
JacobiPrecond(const String &section_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter)
Constructor using a PropertyMap.
JacobiPrecond(const MatrixType &matrix, const FilterType &filter, DataType omega=DataType(1))
Constructor.
virtual void init_symbolic() override
Symbolic initialization method.
Filter_ FilterType
The filter type.
Matrix_ MatrixType
The matrix type.
virtual void init_numeric() override
Numeric initialization method.
virtual void done_symbolic() override
Symbolic finalization method.
virtual String name() const override
Returns a descriptive string.
MatrixType::VectorTypeL VectorType
The type of vector this solver can be applied to.
SolverBase< VectorType > BaseClass
Our base class.
Polymorphic solver interface.
Definition: base.hpp:183
String class implementation.
Definition: string.hpp:47
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ success
solving successful (convergence criterion fulfilled)
std::shared_ptr< JacobiPrecond< Matrix_, Filter_ > > new_jacobi_precond(const Matrix_ &matrix, const Filter_ &filter, const typename Matrix_::DataType omega=typename Matrix_::DataType(1))
Creates a new JacobiPrecond solver object.
FEAT namespace.
Definition: adjactor.hpp:12