1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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,
52 const dictionary& solverControls
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 void Foam::smoothSolver::readControls()
73 lduMatrix::solver::readControls();
74 nSweeps_ = controlDict_.lookupOrDefault<label>("nSweeps", 1);
78 Foam::lduMatrix::solverPerformance Foam::smoothSolver::solve
81 const scalarField& source,
85 // Setup class containing solver performance data
86 lduMatrix::solverPerformance solverPerf(typeName, fieldName_);
88 // If the nSweeps_ is negative do a fixed number of sweeps
91 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
109 solverPerf.nIterations() -= nSweeps_;
113 scalar normFactor = 0;
116 scalarField Apsi(psi.size());
117 scalarField temp(psi.size());
120 matrix_.Amul(Apsi, psi, interfaceBouCoeffs_, interfaces_, cmpt);
122 // Calculate normalisation factor
123 normFactor = this->normFactor(psi, source, Apsi, temp);
125 // Calculate residual magnitude
126 solverPerf.initialResidual() = gSumMag(source - Apsi)/normFactor;
127 solverPerf.finalResidual() = solverPerf.initialResidual();
130 if (lduMatrix::debug >= 2)
132 Info<< " Normalisation factor = " << normFactor << endl;
136 // Check convergence, solve if not converged
137 if (!solverPerf.checkConvergence(tolerance_, relTol_))
139 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
160 // Calculate the residual to check convergence
161 solverPerf.finalResidual() = gSumMag
174 (solverPerf.nIterations() += nSweeps_) < maxIter_
175 && !(solverPerf.checkConvergence(tolerance_, relTol_))
184 // ************************************************************************* //