fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / matrices / blockLduMatrix / BlockLduSolvers / BlockIterativeSolver / BlockIterativeSolver.C
blobd4e8dd0e4cd0183628df2718fd0668d634086cf2
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     Virtual base class for block iterative solvers
28 \*---------------------------------------------------------------------------*/
30 #include "BlockIterativeSolver.H"
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 //- Construct from matrix and solver data stream
35 template<class Type>
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  * * * * * * * * * * * * //
53 template<class Type>
54 Foam::scalar Foam::BlockIterativeSolver<Type>::normFactor
56     Field<Type>& x,
57     const Field<Type>& b
58 ) const
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);
71     // Calculate A.x
72     matrix.Amul(wA, x);
74     // Calculate A.xRef, temporarily using pA for storage
75     matrix.Amul
76     (
77         pA,
78         Field<Type>(nRows, xRef)
79     );
81     scalar normFactor = gSum(mag(wA - pA) + mag(b - pA)) + this->small_;
83     if (BlockLduMatrix<Type>::debug >= 2)
84     {
85         Info<< "Iterative solver normalisation factor = " << normFactor << endl;
86     }
88     return normFactor;
92 template<class Type>
93 bool Foam::BlockIterativeSolver<Type>::stop
95     BlockSolverPerformance<Type>& solverPerf
96 ) const
98     if (solverPerf.nIterations() < minIter_)
99     {
100         return false;
101     }
103     if
104     (
105         solverPerf.nIterations() >= maxIter_
106      || solverPerf.checkConvergence(tolerance_, relTolerance_)
107     )
108     {
109         return true;
110     }
111     else
112     {
113         return false;
114     }
118 // ************************************************************************* //