1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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 Algebraic Multigrid solver with run-time selection of coarsening and cycle
28 Klas Jareteg, 2013-04-15
30 \*---------------------------------------------------------------------------*/
32 #include "BlockAmgSolver.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 //- Construct from matrix and solver data stream
41 Foam::BlockAmgSolver<Type>::BlockAmgSolver
43 const word& fieldName,
44 const BlockLduMatrix<Type>& matrix,
45 const dictionary& dict
48 BlockIterativeSolver<Type>
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 typename Foam::BlockSolverPerformance<Type>
66 Foam::BlockAmgSolver<Type>::solve
72 // Prepare solver performance
73 BlockSolverPerformance<Type> solverPerf
79 // Create local references to avoid the spread this-> ugliness
80 const BlockLduMatrix<Type>& matrix = this->matrix_;
82 scalar norm = this->normFactor(x, b);
84 Field<Type> wA(x.size());
86 // Calculate residual. Note: sign of residual swapped for efficiency
90 solverPerf.initialResidual() = gSum(cmptMag(wA))/norm;
91 solverPerf.finalResidual() = solverPerf.initialResidual();
93 if (!solverPerf.checkConvergence(this->tolerance(), this->relTolerance()))
99 // Re-calculate residual. Note: sign of residual swapped
104 solverPerf.finalResidual() = gSum(cmptMag(wA))/norm;
105 solverPerf.nIterations()++;
107 } while (!this->stop(solverPerf));
114 // ************************************************************************* //