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 Smoother-solver for coupled diagonal lduMatrices.
28 Hrvoje Jasak, Wikki Ltd. All rights reserved
30 \*---------------------------------------------------------------------------*/
32 #include "coupledSmoothSolver.H"
33 #include "addToRunTimeSelectionTable.H"
34 #include "coupledLduSmoother.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(coupledSmoothSolver, 0);
42 coupledLduSolver::addsymMatrixConstructorToTable<coupledSmoothSolver>
43 addGaussSeidelSolverSymMatrixConstructorToTable_;
45 coupledLduSolver::addasymMatrixConstructorToTable<coupledSmoothSolver>
46 addGaussSeidelSolverAsymMatrixConstructorToTable_;
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 //- Construct from matrix
53 Foam::coupledSmoothSolver::coupledSmoothSolver
55 const word& fieldName,
56 const coupledLduMatrix& matrix,
57 const PtrList<FieldField<Field, scalar> >& bouCoeffs,
58 const PtrList<FieldField<Field, scalar> >& intCoeffs,
59 const lduInterfaceFieldPtrsListList& interfaces,
60 const dictionary& solverData
63 coupledIterativeSolver
78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 void Foam::coupledSmoothSolver::readControls()
82 coupledIterativeSolver::readControls();
83 dict().readIfPresent("nSweeps", nSweeps_);
87 Foam::coupledSolverPerformance Foam::coupledSmoothSolver::solve
89 FieldField<Field, scalar>& x,
90 const FieldField<Field, scalar>& b,
94 // Prepare solver performance
95 coupledSolverPerformance solverPerf(typeName, fieldName());
97 // Do a minimum number of sweeps
101 autoPtr<coupledLduSmoother> smootherPtr = coupledLduSmoother::New
118 solverPerf.nIterations() += minIter();
121 // Now do normal sweeps. HJ, 19/Jan/2009
123 FieldField<Field, scalar> Ax(x.size());
124 FieldField<Field, scalar> temp(x.size());
128 Ax.set(rowI, new scalarField(x[rowI].size(), 0));
129 temp.set(rowI, new scalarField(x[rowI].size(), 0));
132 // Calculate initial residual. Note: for efficiency, swapping sign
133 matrix_.Amul(Ax, x, bouCoeffs_, interfaces_, cmpt);
135 scalar normFactor = this->normFactor(x, b, Ax, temp, cmpt);
139 solverPerf.initialResidual() = gSumMag(Ax)/normFactor;
140 solverPerf.finalResidual() = solverPerf.initialResidual();
142 if (!solverPerf.checkConvergence(tolerance_, relTolerance_))
144 autoPtr<coupledLduSmoother> smootherPtr =
145 coupledLduSmoother::New
157 smootherPtr->smooth(x, b, cmpt, nSweeps_);
159 // Re-calculate residual
160 matrix_.Amul(Ax, x, bouCoeffs_, interfaces_, cmpt);
163 solverPerf.finalResidual() = gSumMag(Ax)/normFactor;
165 solverPerf.nIterations() += nSweeps_;
166 } while (!stop(solverPerf));
173 // ************************************************************************* //