1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Algebraic Multigrid solver with run-time selection of policy and cycle
29 Hrvoje Jasak, Wikki Ltd. All rights reserved
31 \*---------------------------------------------------------------------------*/
33 #include "amgSolver.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(amgSolver, 0);
42 lduSolver::addsymMatrixConstructorToTable<amgSolver>
43 addamgSolverSymMatrixConstructorToTable_;
45 lduSolver::addasymMatrixConstructorToTable<amgSolver>
46 addamgSolverAsymMatrixConstructorToTable_;
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 //- Construct from matrix and solver data stream
53 Foam::amgSolver::amgSolver
55 const word& fieldName,
56 const lduMatrix& matrix,
57 const FieldField<Field, scalar>& coupleBouCoeffs,
58 const FieldField<Field, scalar>& coupleIntCoeffs,
59 const lduInterfaceFieldPtrsList& interfaces,
60 const dictionary& dict
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 Foam::lduSolverPerformance Foam::amgSolver::solve
92 // Prepare solver performance
93 lduSolverPerformance solverPerf(typeName, fieldName());
95 scalar norm = this->normFactor(x, b, cmpt);
97 // Calculate initial residual
98 solverPerf.initialResidual() = gSumMag(amg_.residual(x, b, cmpt))/norm;
99 solverPerf.finalResidual() = solverPerf.initialResidual();
101 if (!stop(solverPerf))
105 amg_.cycle(x, b, cmpt);
107 // Re-calculate residual
108 solverPerf.finalResidual() =
109 gSumMag(amg_.residual(x, b, cmpt))/norm;
111 solverPerf.nIterations()++;
112 } while (!stop(solverPerf));
119 // ************************************************************************* //