1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Gauss-Seidel solver for symmetric and asymmetric matrices. In
26 order to improve efficiency, the residual is evaluated after every
29 \*---------------------------------------------------------------------------*/
31 #include "BlockGaussSeidelSolver.H"
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 // Construct from matrix and solver data stream
37 Foam::BlockGaussSeidelSolver<Type>::BlockGaussSeidelSolver
39 const word& fieldName,
40 const BlockLduMatrix<Type>& matrix,
41 const dictionary& dict
44 BlockIterativeSolver<Type>
51 nSweeps_(readLabel(this->dict().lookup("nSweeps")))
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 typename Foam::BlockSolverPerformance<Type>
59 Foam::BlockGaussSeidelSolver<Type>::solve
65 // Create local references to avoid the spread this-> ugliness
66 const BlockLduMatrix<Type>& matrix = this->matrix_;
68 // Prepare solver performance
69 BlockSolverPerformance<Type> solverPerf
75 scalar norm = this->normFactor(x, b);
77 Field<Type> wA(x.size());
79 // Calculate residual. Note: sign of residual swapped for efficiency
83 solverPerf.initialResidual() = gSum(cmptMag(wA))/norm;
84 solverPerf.finalResidual() = solverPerf.initialResidual();
86 // Check convergence, solve if not converged
88 if (!this->stop(solverPerf))
94 for (label i = 0; i < nSweeps_; i++)
96 gs_.precondition(x, b);
98 solverPerf.nIterations()++;
101 // Re-calculate residual. Note: sign of residual swapped
106 solverPerf.finalResidual() = gSum(cmptMag(wA))/norm;
107 solverPerf.nIterations()++;
108 } while (!this->stop(solverPerf));
115 // ************************************************************************* //