Preconditioning bugfix by Alexander Monakov
[OpenFOAM-1.6-ext.git] / src / lduSolvers / lduSolver / amgSolver / amgSolver.C
blob07c9260b89ef9b33aa47705fc39b6b624f1f4b91
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     Algebraic Multigrid solver with run-time selection of policy and cycle
28 Author
29     Hrvoje Jasak, Wikki Ltd.  All rights reserved
31 \*---------------------------------------------------------------------------*/
33 #include "amgSolver.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
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
63     lduSolver
64     (
65         fieldName,
66         matrix,
67         coupleBouCoeffs,
68         coupleIntCoeffs,
69         interfaces,
70         dict
71     ),
72     amg_
73     (
74         matrix,
75         coupleBouCoeffs,
76         coupleIntCoeffs,
77         interfaces,
78         dict
79     )
83 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
85 Foam::lduSolverPerformance Foam::amgSolver::solve
87     scalarField& x,
88     const scalarField& b,
89     const direction cmpt
90 ) const
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))
102     {
103         do
104         {
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));
113     }
115     return solverPerf;
119 // ************************************************************************* //