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 Virtual base class for block iterative solvers
28 \*---------------------------------------------------------------------------*/
30 #include "BlockIterativeSolver.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 //- Construct from matrix and solver data stream
36 Foam::BlockIterativeSolver<Type>::BlockIterativeSolver
38 const word& fieldName,
39 const BlockLduMatrix<Type>& matrix,
40 const dictionary& dict
43 BlockLduSolver<Type>(fieldName, matrix, dict),
44 tolerance_(readScalar(this->dict().lookup("tolerance"))),
45 relTolerance_(readScalar(this->dict().lookup("relTol"))),
46 minIter_(readLabel(this->dict().lookup("minIter"))),
47 maxIter_(readLabel(this->dict().lookup("maxIter")))
51 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
54 Foam::scalar Foam::BlockIterativeSolver<Type>::normFactor
60 const BlockLduMatrix<Type>& matrix = this->matrix_;
62 // Calculate the normalisation factor
63 const label nRows = x.size();
65 Field<Type> pA(nRows);
66 Field<Type> wA(nRows);
68 // Calculate reference value of x
69 Type xRef = gAverage(x);
74 // Calculate A.xRef, temporarily using pA for storage
78 Field<Type>(nRows, xRef)
81 scalar normFactor = gSum(mag(wA - pA) + mag(b - pA)) + this->small_;
83 if (BlockLduMatrix<Type>::debug >= 2)
85 Info<< "Iterative solver normalisation factor = " << normFactor << endl;
93 bool Foam::BlockIterativeSolver<Type>::stop
95 BlockSolverPerformance<Type>& solverPerf
98 if (solverPerf.nIterations() < minIter_)
105 solverPerf.nIterations() >= maxIter_
106 || solverPerf.checkConvergence(tolerance_, relTolerance_)
118 // ************************************************************************* //