1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 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
25 \*---------------------------------------------------------------------------*/
27 #include "smoothSolver.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(smoothSolver, 0);
35 lduMatrix::solver::addsymMatrixConstructorToTable<smoothSolver>
36 addsmoothSolverSymMatrixConstructorToTable_;
38 lduMatrix::solver::addasymMatrixConstructorToTable<smoothSolver>
39 addsmoothSolverAsymMatrixConstructorToTable_;
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 Foam::smoothSolver::smoothSolver
47 const word& fieldName,
48 const lduMatrix& matrix,
49 const FieldField<Field, scalar>& interfaceBouCoeffs,
50 const FieldField<Field, scalar>& interfaceIntCoeffs,
51 const lduInterfaceFieldPtrsList& interfaces,
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 void Foam::smoothSolver::readControls()
74 lduMatrix::solver::readControls();
75 controlDict_.readIfPresent("nSweeps", nSweeps_);
79 Foam::lduMatrix::solverPerformance Foam::smoothSolver::solve
82 const scalarField& source,
86 // Setup class containing solver performance data
87 lduMatrix::solverPerformance solverPerf(typeName, fieldName_);
89 // If the nSweeps_ is negative do a fixed number of sweeps
92 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
99 controlDict_.lookup("smoother")
110 solverPerf.nIterations() -= nSweeps_;
114 scalar normFactor = 0;
117 scalarField Apsi(psi.size());
118 scalarField temp(psi.size());
121 matrix_.Amul(Apsi, psi, interfaceBouCoeffs_, interfaces_, cmpt);
123 // Calculate normalisation factor
124 normFactor = this->normFactor(psi, source, Apsi, temp);
126 // Calculate residual magnitude
127 solverPerf.initialResidual() = gSumMag(source - Apsi)/normFactor;
128 solverPerf.finalResidual() = solverPerf.initialResidual();
131 if (lduMatrix::debug >= 2)
133 Info<< " Normalisation factor = " << normFactor << endl;
137 // Check convergence, solve if not converged
138 if (!solverPerf.checkConvergence(tolerance_, relTol_))
140 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
147 controlDict_.lookup("smoother")
161 // Calculate the residual to check convergence
162 solverPerf.finalResidual() = gSumMag
175 (solverPerf.nIterations() += nSweeps_) < maxIter_
176 && !(solverPerf.checkConvergence(tolerance_, relTol_))
185 // ************************************************************************* //