1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | 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 Virtual base class for coupled iterative solvers
28 Hrvoje Jasak, Wikki Ltd. All rights reserved.
30 \*---------------------------------------------------------------------------*/
32 #include "coupledIterativeSolver.H"
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::coupledIterativeSolver::coupledIterativeSolver
38 const word& fieldName,
39 const coupledLduMatrix& matrix,
40 const PtrList<FieldField<Field, scalar> >& bouCoeffs,
41 const PtrList<FieldField<Field, scalar> >& intCoeffs,
42 const lduInterfaceFieldPtrsListList& interfaces,
43 const dictionary& solverData
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 const Foam::dictionary& Foam::coupledIterativeSolver::dict() const
72 void Foam::coupledIterativeSolver::readControls()
74 dict().readIfPresent("minIter", minIter_);
75 dict().readIfPresent("maxIter", maxIter_);
76 dict().readIfPresent("tolerance", tolerance_);
77 dict().readIfPresent("relTol", relTolerance_);
81 Foam::scalar Foam::coupledIterativeSolver::normFactor
83 const FieldField<Field, scalar>& x,
84 const FieldField<Field, scalar>& b,
85 const FieldField<Field, scalar>& Ax,
86 FieldField<Field, scalar>& tmpField,
90 typedef FieldField<Field, scalar> scalarFieldField;
92 // Calculate reference value of x
93 scalar xRef = gAverage(x);
95 scalarFieldField pA(x.size());
99 pA.set(rowI, new scalarField(x[rowI].size(), xRef));
102 // Calculate A.xRefField
103 matrix_.Amul(tmpField, pA, bouCoeffs_, interfaces_, cmpt);
105 // Calculate the normalisation factor
106 return gSum(mag(Ax - tmpField) + mag(b - tmpField)) + lduMatrix::small_;
110 Foam::scalar Foam::coupledIterativeSolver::normFactor
112 const FieldField<Field, scalar>& x,
113 const FieldField<Field, scalar>& b,
117 typedef FieldField<Field, scalar> scalarFieldField;
119 scalarFieldField wA(x.size());
120 scalarFieldField tmpField(x.size());
124 wA.set(rowI, new scalarField(x[rowI].size(), 0));
125 tmpField.set(rowI, new scalarField(x[rowI].size()));
129 matrix_.Amul(wA, x, bouCoeffs_, interfaces_, cmpt);
131 return normFactor(x, b, wA, tmpField, cmpt);
135 bool Foam::coupledIterativeSolver::stop
137 coupledSolverPerformance& solverPerf
140 if (solverPerf.nIterations() < minIter_)
147 solverPerf.nIterations() >= maxIter_
148 || solverPerf.checkConvergence(tolerance_, relTolerance_)
160 // ************************************************************************* //