1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "smoothSolver.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(smoothSolver, 0);
34 lduMatrix::solver::addsymMatrixConstructorToTable<smoothSolver>
35 addsmoothSolverSymMatrixConstructorToTable_;
37 lduMatrix::solver::addasymMatrixConstructorToTable<smoothSolver>
38 addsmoothSolverAsymMatrixConstructorToTable_;
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 Foam::smoothSolver::smoothSolver
46 const word& fieldName,
47 const lduMatrix& matrix,
48 const FieldField<Field, scalar>& interfaceBouCoeffs,
49 const FieldField<Field, scalar>& interfaceIntCoeffs,
50 const lduInterfaceFieldPtrsList& interfaces,
51 const dictionary& solverControls
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 void Foam::smoothSolver::readControls()
72 lduMatrix::solver::readControls();
73 nSweeps_ = controlDict_.lookupOrDefault<label>("nSweeps", 1);
77 Foam::lduMatrix::solverPerformance Foam::smoothSolver::solve
80 const scalarField& source,
84 // Setup class containing solver performance data
85 lduMatrix::solverPerformance solverPerf(typeName, fieldName_);
87 // If the nSweeps_ is negative do a fixed number of sweeps
90 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
108 solverPerf.nIterations() -= nSweeps_;
112 scalar normFactor = 0;
115 scalarField Apsi(psi.size());
116 scalarField temp(psi.size());
119 matrix_.Amul(Apsi, psi, interfaceBouCoeffs_, interfaces_, cmpt);
121 // Calculate normalisation factor
122 normFactor = this->normFactor(psi, source, Apsi, temp);
124 // Calculate residual magnitude
125 solverPerf.initialResidual() = gSumMag(source - Apsi)/normFactor;
126 solverPerf.finalResidual() = solverPerf.initialResidual();
129 if (lduMatrix::debug >= 2)
131 Info<< " Normalisation factor = " << normFactor << endl;
135 // Check convergence, solve if not converged
136 if (!solverPerf.checkConvergence(tolerance_, relTol_))
138 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
159 // Calculate the residual to check convergence
160 solverPerf.finalResidual() = gSumMag
173 (solverPerf.nIterations() += nSweeps_) < maxIter_
174 && !(solverPerf.checkConvergence(tolerance_, relTol_))
183 // ************************************************************************* //