1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 Preconditioned Bi-Conjugate Gradient stabilised solver with run-time
27 selectable preconditioning
30 Hrvoje Jasak, Wikki Ltd. All rights reserved.
32 \*---------------------------------------------------------------------------*/
34 #include "bicgStabSolver.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(bicgStabSolver, 0);
43 lduSolver::addsymMatrixConstructorToTable<bicgStabSolver>
44 addbicgStabSolverSymMatrixConstructorToTable_;
46 lduSolver::addasymMatrixConstructorToTable<bicgStabSolver>
47 addbicgStabSolverAsymMatrixConstructorToTable_;
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 //- Construct from matrix and solver data stream
54 Foam::bicgStabSolver::bicgStabSolver
56 const word& fieldName,
57 const lduMatrix& matrix,
58 const FieldField<Field, scalar>& coupleBouCoeffs,
59 const FieldField<Field, scalar>& coupleIntCoeffs,
60 const lduInterfaceFieldPtrsList& interfaces,
61 const dictionary& dict
75 lduPreconditioner::New
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 Foam::lduSolverPerformance Foam::bicgStabSolver::solve
96 // Prepare solver performance
97 lduSolverPerformance solverPerf(typeName, fieldName());
99 scalarField p(x.size());
100 scalarField r(x.size());
102 // Calculate initial residual
103 matrix_.Amul(p, x, coupleBouCoeffs_, interfaces_, cmpt);
105 scalar normFactor = this->normFactor(x, b, p, r, cmpt);
107 if (lduMatrix::debug >= 2)
109 Info<< " Normalisation factor = " << normFactor << endl;
112 // Calculate residual
118 solverPerf.initialResidual() = gSumMag(r)/normFactor;
119 solverPerf.finalResidual() = solverPerf.initialResidual();
121 if (!stop(solverPerf))
123 scalar rho = matrix_.great_;
127 scalar omega = matrix_.great_;
131 scalarField ph(x.size(), 0);
132 scalarField v(x.size(), 0);
133 scalarField s(x.size(), 0);
134 scalarField sh(x.size(), 0);
135 scalarField t(x.size(), 0);
137 // Calculate transpose residual
144 // Update search directions
145 rho = gSumProd(rw, r);
147 beta = rho/rhoOld*(alpha/omega);
149 // Restart if breakdown occurs
153 rho = gSumProd(rw, r);
162 p[i] = r[i] + beta*p[i] - beta*omega*v[i];
165 // Execute preconditioning
166 preconPtr_->precondition(ph, p, cmpt);
167 matrix_.Amul(v, ph, coupleBouCoeffs_, interfaces_, cmpt);
168 alpha = rho/gSumProd(rw, v);
172 s[i] = r[i] - alpha*v[i];
175 // Execute preconditioning
176 // Bug fix, Alexander Monakov, 11/Jul/2012
177 preconPtr_->precondition(sh, s, cmpt);
178 matrix_.Amul(t, sh, coupleBouCoeffs_, interfaces_, cmpt);
179 omega = gSumProd(t, s)/gSumProd(t, t);
181 // Update solution and residual
184 x[i] = x[i] + alpha*ph[i] + omega*sh[i];
189 r[i] = s[i] - omega*t[i];
192 solverPerf.finalResidual() = gSumMag(r)/normFactor;
193 solverPerf.nIterations()++;
194 } while (!stop(solverPerf));
201 // ************************************************************************* //