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{Solvers} 18 19Each solver class in the {\lib solvers} library implements a specific iterative method to solve a linear system: \verb?A*X=B? in two cases: Real or Complex. The algorithm of all solvers except Sor and Sor can work with and without a {\class Preconditioner}. Each solver takes {\class largeMatrix} \(matA\) and {\class Vector} \(vecB\) as inputs and a {\class Vector} \(vecX\) as output whose value is initialized with the input {\class Vector} \(vecX0\).\\ 20A solver without a preconditioner is invoked with the overloading operator(): 21\vspace{.1cm} 22\begin{lstlisting} 23template<class Mat, class VecB, class VecX> 24VecX operator()(Mat& matA, VecB& vecB, VecX& vecX0, ValueType solType) 25\end{lstlisting} 26\vspace{.1cm} 27Meanwhile, solver with a preconditioner \(pc\) can be used with the call 28\vspace{.1cm} 29\begin{lstlisting} 30 template<class Mat, class VecB, class VecX, class Prec> 31 VecX operator()(Mat& matA, VecB& vecB, VecX& vecX0, Prec& pc, ValueType solType) 32\end{lstlisting} 33\vspace{.1cm} 34User must specify the type of solver \verb?solType?, which can be \verb?_real? or \verb?_complex?. \\ 35The algorithm corresponds to without-preconditioner solver 36\vspace{.1cm} 37\begin{lstlisting} 38template<typename K, class Mat, class VecB, class VecX> 39void algorithm(Mat& matA, VecB& vecB, VecX& vecX, VecX& vecR) 40\end{lstlisting} 41\vspace{.1cm} 42and to a preconditioned one 43\vspace{.1cm} 44\begin{lstlisting} 45 template<typename K, class Mat, class VecB, class VecX, class Prec> 46 void algorithm(Mat& matA, VecB& vecB, VecX& vecX, VecX& vecR, Prec& pc) 47\end{lstlisting} 48\vspace{.1cm} 49 50\subsection {The {\classtitle BicgSolver} class} 51 52This class implements the Biconjugate Gradient method to solve a linear system. 53There are several basic constructors calling {\class IterativeSolver} constructors 54\vspace{.1cm} 55\begin{lstlisting} 56class BicgSolver : public IterativeSolver 57{ 58 public: 59 //! Default Constructor 60 BicgSolver() 61 : IterativeSolver("BiCG") {} 62 63 //! Full constructor 64 BicgSolver(const Real eps, 65 const Number maxOfIt = defaultMaxIterations, 66 const Number vb = 0) 67 : IterativeSolver("BiCG", maxOfIt, eps, vb) {} 68 ... 69\end{lstlisting} 70\vspace{.1cm} 71 72\displayInfos{library=solvers, test={test\_BicgSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 73 74\subsection {The {\classtitle BicgStabSolver} class} 75 76This class implements the Biconjugate Gradient Stabilized method to solve a linear system. 77There are several basic constructors calling {\class IterativeSolver} constructors 78\vspace{.1cm} 79\begin{lstlisting} 80class BicgStabSolver : public IterativeSolver 81{ 82 public: 83 //! Default Constructor 84 BicgStabSolver() : IterativeSolver("BiCGStab") {} 85 86 //! Full Constructor 87 BicgStabSolver(const Real eps, 88 const Number maxOfIt = defaultMaxIterations, 89 const Number vb = 0) 90 : IterativeSolver("BiCGStab", maxOfIt, eps, vb) {} 91 ... 92\end{lstlisting} 93\vspace{.1cm} 94 95\displayInfos{library=solvers, test={test\_BicgStabSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 96 97\subsection {The {\classtitle CgSolver} class} 98 99This class implements the Conjugate Gradient method to solve a linear system. 100There are several basic constructors calling {\class IterativeSolver} constructors 101\vspace{.1cm} 102\begin{lstlisting} 103class CgSolver : public IterativeSolver 104{ 105 public: 106 //! Default constructor 107 CgSolver(): IterativeSolver("CG") {} 108 109 //! Full constructor 110 CgSolver(const Real eps, 111 const Number maxOfIt = defaultMaxIterations, 112 const Number vb = 0) 113 : IterativeSolver("CG", maxOfIt, eps, vb) {} 114 ... 115\end{lstlisting} 116\vspace{.1cm} 117 118\displayInfos{library=solvers, test={test\_CgSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 119 120\subsection {The {\classtitle CgsSolver} class} 121 122This class implements the Conjugate Gradient Squared method to solve a linear system. 123There are several basic constructors calling {\class IterativeSolver} constructors 124\vspace{.1cm} 125\begin{lstlisting} 126class CgsSolver : public IterativeSolver 127{ 128 public: 129 //! Default constructor 130 CgsSolver() 131 : IterativeSolver("CGS") {} 132 133 //! Full constructor 134 CgsSolver(const Real eps, 135 const Number maxOfIt = defaultMaxIterations, 136 const Number vb = 0) 137 : IterativeSolver("CGS", maxOfIt, eps, vb) {} 138 ... 139\end{lstlisting} 140\vspace{.1cm} 141 142\displayInfos{library=solvers, test={test\_CgsSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 143 144\subsection {The {\classtitle GmresSolver} class} 145 146This class implements the Generalized Minimal Residual method to solve a linear system. 147Different from other solvers, the {\class GmresSolver} has more constructors: user can specify the Krylov dimension in the constructor. 148\vspace{.1cm} 149\begin{lstlisting} 150class GmresSolver : public IterativeSolver 151{ 152 private: 153 Number krylovDim_; // << Dimension of Krylov space 154 155 public: 156 //! Default Constructor 157 GmresSolver() 158 : IterativeSolver("GMRes"), krylovDim_(defaultKrylovDimension) {} 159 160 //! Constructor with Krylov dimension 161 GmresSolver(const Number kd) 162 : IterativeSolver("GMRes", defaultMaxIterations, theDefaultConvergenceThreshold), 163 krylovDim_(kd) {} 164 165 //! Full constructor 166 GmresSolver(const Number kd, const Real eps, 167 const Number maxOfIt = defaultMaxIterations, 168 const Number vb = 0) 169 : IterativeSolver("GMRes", maxOfIt, eps, vb), krylovDim_(kd) {} 170 ... 171\end{lstlisting} 172\vspace{.1cm} 173 174\displayInfos{library=solvers, test={test\_GmresSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 175 176\subsection {The {\classtitle QmrSolver} class} 177 178This class implements the Quasi-Minimal Residual method to solve a linear system. 179There are several basic constructors calling {\class IterativeSolver} constructors 180\vspace{.1cm} 181\begin{lstlisting} 182class QmrSolver : public IterativeSolver 183{ 184 public: 185 //! Constructor 186 QmrSolver() 187 : IterativeSolver("QMR") {} 188 189 //! Full Constructor 190 QmrSolver(const Real eps, 191 const Number maxOfIt = defaultMaxIterations, 192 const Number vb = 0) 193 : IterativeSolver("QMR", maxOfIt, eps, vb) {} 194 ... 195\end{lstlisting} 196\vspace{.1cm} 197 198\displayInfos{library=solvers, test={test\_QmrSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 199 200\subsection {The {\classtitle SorSolver} class} 201 202This class implements the Successive Over Relaxation method to solve a linear system. 203For this solver, user can have more choices to specify the relaxation factor \(omega\) in the constructor. 204Different from other solvers above, {\class SorSolver} doesn't work with a preconditioner. 205\vspace{.1cm} 206\begin{lstlisting} 207class SorSolver : public IterativeSolver 208{ 209 private: 210 Real omega_; // relaxation factor of SOR method 211 212 public: 213 //! Default Constructor 214 SorSolver() 215 : IterativeSolver("SOR"), omega_(1.) {} 216 217 //! Constructor with omege 218 SorSolver(const Real w) 219 : IterativeSolver("SOR"), omega_(w) {} 220 221 //! Full constructor 222 SorSolver(const Real w, const Real eps, 223 const Number maxOfIt = defaultMaxIterations, 224 const Number vb = 0) 225 : IterativeSolver("SOR", maxOfIt, eps, vb), omega_(w) {} 226 ... 227\end{lstlisting} 228\vspace{.1cm} 229 230\displayInfos{library=solvers, test={test\_SorSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 231 232\subsection {The {\classtitle SsorSolver} class} 233 234This class implements the Symmetric Successive Over Relaxation method to solve a linear system. 235Like {\class SorSolver}, the {\class SsorSolver} only works without a preconditioner and user can specify the relaxation factor \(omega\) in the constructor. 236\vspace{.1cm} 237\begin{lstlisting} 238class SsorSolver : public IterativeSolver 239{ 240 private: 241 Real omega_; //relaxation factor of SOR method 242 243 public: 244 //! Default Constructors 245 SsorSolver() : IterativeSolver("SSOR"), omega_(1.) {} 246 247 //! Constructor with omega 248 SsorSolver(const Real w) : IterativeSolver("SSOR"), omega_(w) {} 249 250 //! Full constructor 251 SsorSolver(const Real w, const Real eps, 252 const Number maxOfIt = defaultMaxIterations, 253 const Number vb = 0) 254 : IterativeSolver("SSOR", maxOfIt, eps, vb), omega_(w) {} 255 ... 256\end{lstlisting} 257\vspace{.1cm} 258 259\displayInfos{library=solvers, test={test\_SsorSolver.hpp}, header dep={IterativeSolver.hpp, Preconditioner.hpp}} 260