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 Preconditioned Bi-Conjugate Gradient stabilised solver with run-time
26 selectable preconditioning
29 Hrvoje Jasak, Wikki Ltd. All rights reserved.
31 \*---------------------------------------------------------------------------*/
33 #include "bicgStabSolver.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(bicgStabSolver, 0);
42 lduSolver::addsymMatrixConstructorToTable<bicgStabSolver>
43 addbicgStabSolverSymMatrixConstructorToTable_;
45 lduSolver::addasymMatrixConstructorToTable<bicgStabSolver>
46 addbicgStabSolverAsymMatrixConstructorToTable_;
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 //- Construct from matrix and solver data stream
53 Foam::bicgStabSolver::bicgStabSolver
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
74 lduPreconditioner::New
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 Foam::lduSolverPerformance Foam::bicgStabSolver::solve
95 // Prepare solver performance
96 lduSolverPerformance solverPerf(typeName, fieldName());
98 scalarField p(x.size());
99 scalarField r(x.size());
101 // Calculate initial residual
102 matrix_.Amul(p, x, coupleBouCoeffs_, interfaces_, cmpt);
104 scalar normFactor = this->normFactor(x, b, p, r, cmpt);
106 if (lduMatrix::debug >= 2)
108 Info<< " Normalisation factor = " << normFactor << endl;
111 // Calculate residual
117 solverPerf.initialResidual() = gSumMag(r)/normFactor;
118 solverPerf.finalResidual() = solverPerf.initialResidual();
120 if (!stop(solverPerf))
122 scalar rho = matrix_.great_;
126 scalar omega = matrix_.great_;
130 scalarField ph(x.size(), 0);
131 scalarField v(x.size(), 0);
132 scalarField s(x.size(), 0);
133 scalarField sh(x.size(), 0);
134 scalarField t(x.size(), 0);
136 // Calculate transpose residual
143 // Update search directions
144 rho = gSumProd(rw, r);
146 beta = rho/rhoOld*(alpha/omega);
148 // Restart if breakdown occurs
152 rho = gSumProd(rw, r);
161 p[i] = r[i] + beta*p[i] - beta*omega*v[i];
164 // Execute preconditioning
165 preconPtr_->precondition(ph, p, cmpt);
166 matrix_.Amul(v, ph, coupleBouCoeffs_, interfaces_, cmpt);
167 alpha = rho/gSumProd(rw, v);
171 s[i] = r[i] - alpha*v[i];
174 // Execute preconditioning
175 // Bug fix, Alexander Monakov, 11/Jul/2012
176 preconPtr_->precondition(sh, s, cmpt);
177 matrix_.Amul(t, sh, coupleBouCoeffs_, interfaces_, cmpt);
178 omega = gSumProd(t, s)/gSumProd(t, t);
180 // Update solution and residual
183 x[i] = x[i] + alpha*ph[i] + omega*sh[i];
188 r[i] = s[i] - omega*t[i];
191 solverPerf.finalResidual() = gSumMag(r)/normFactor;
192 solverPerf.nIterations()++;
193 } while (!stop(solverPerf));
200 // ************************************************************************* //