1%%%%%%%%%%%%%%%%%%% 2% XLiFE++ is an extended library of finite elements written in C++ 3% Copyright (C) 2014 Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin 4% 5% This program is free software: you can redistribute it and/or modify 6% it under the terms of the GNU General Public License as published by 7% the Free Software Foundation, either version 3 of the License, or 8% (at your option) any later version. 9% This program is distributed in the hope that it will be useful, 10% but WITHOUT ANY WARRANTY; without even the implied warranty of 11% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12% GNU General Public License for more details. 13% You should have received a copy of the GNU General Public License 14% along with this program. If not, see <http://www.gnu.org/licenses/>. 15%%%%%%%%%%%%%%%%%%% 16 17\section{The {\classtitle Preconditioner} class} 18 19In some cases, the rate of convergence of an iterative solver can increase as a result of preconditioning. A precondtioner is basically a special matrix which can be factorized. There exist several types of matrix-factorization for {\class Preconditioner}: LU, LDLt, LDL*, Diag and SOR. Because of constraints of factorizing, only matrices of {\class SkylineStorage} and {\class CsStorage} can be used as a preconditioner. 20 21In detail, a preconditioner is based on a template class {\class Mat}, on which all the preconditioned-solver are processed. 22\vspace{.1cm} 23\begin{lstlisting} 24template<class Mat> 25class Preconditioner 26{ 27 public: 28 Mat* precondMatrix_p; // pointer to precondition matrix 29 private: 30 //! Type of preconditioner 31 PreconditionerType type_; 32 //! Relaxation parameter for SSOR preconditioners 33 Real omega_; 34 public: 35 Preconditioner() 36 : precondMatrix_p(0), type_(_noPreconditioner), omega_(0.) { } 37 38 Preconditioner(PreconditionerType pt, Mat& A, const Real w = 1.) 39 : precondMatrix_p(&A), type_(pt), omega_(w) { } 40 41 Preconditioner(Mat& A, PreconditionerType pt, const Real w = 1.) 42 : precondMatrix_p(&A), type_(pt), omega_(w) { } 43 ~Preconditioner() {}; 44 //! Return type of precondionner 45 static String name(PreconditionerType pt) 46 { 47 String s(""); 48 switch ( pt ) 49 { 50 case _lu: s = "LU"; break; 51 case _ldlt: s = "LDLt"; break; 52 case _ldlStar: s = "LDL*"; break; 53 case _ssor: s = "SSOR"; break; 54 case _diag: s = "Diagonal"; break; 55 //case myPreconditioner: s = "User Supplied"; break; 56 default: break; 57 } 58 return s; 59 } 60 ... 61\end{lstlisting} 62\vspace{.1cm} 63\textdbend \ \ A preconditioner can only templated with a specific kind of matrix that can be decomposed. There are only two types of storage, with which matrix can be factorized: {\lib SkylineStorage} with LU, LDLt, LDL* factorization; {\lib CsStorage} with SOR and DIAG factorization. 64 65There are several constructors: 66\vspace{.1cm} 67\begin{lstlisting}[] 68 Preconditioner() 69 : precondMatrix_p(0), type_(_noPreconditioner), omega_(0.) { } 70 71 Preconditioner(PreconditionerType pt, Mat& A, const Real w = 1.) 72 : precondMatrix_p(&A), type_(pt), omega_(w) { } 73 74 Preconditioner(Mat& A, PreconditionerType pt, const Real w = 1.) 75 : precondMatrix_p(&A), type_(pt), omega_(w) { } 76\end{lstlisting} 77\vspace{.1cm} 78 79The {\class PreconditionerType} is an enumeration. 80\vspace{.1cm} 81\begin{lstlisting}[] 82enum PreconditionerType {_noPreconditioner, _lu, _ldlt, _ldlStar, _ssor, _diag, _myPreconditioner}; 83\end{lstlisting} 84\vspace{.1cm} 85\displayInfos{library=solvers, header=Preconditioner.hpp, implementation=Preconditioner.hpp, test={test\_LargeMatrixSkylineStorage.cpp, test\_LargeMatrixCsStorage.cpp}, header dep={config.h, utils.h}} 86 87