1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
26 Smoother-solver for coupled diagonal lduMatrices.
29 Hrvoje Jasak, Wikki Ltd. All rights reserved
31 \*---------------------------------------------------------------------------*/
33 #include "coupledSmoothSolver.H"
34 #include "addToRunTimeSelectionTable.H"
35 #include "coupledLduSmoother.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(coupledSmoothSolver, 0);
43 coupledLduSolver::addsymMatrixConstructorToTable<coupledSmoothSolver>
44 addGaussSeidelSolverSymMatrixConstructorToTable_;
46 coupledLduSolver::addasymMatrixConstructorToTable<coupledSmoothSolver>
47 addGaussSeidelSolverAsymMatrixConstructorToTable_;
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 //- Construct from matrix
54 Foam::coupledSmoothSolver::coupledSmoothSolver
56 const word& fieldName,
57 const coupledLduMatrix& matrix,
58 const PtrList<FieldField<Field, scalar> >& bouCoeffs,
59 const PtrList<FieldField<Field, scalar> >& intCoeffs,
60 const lduInterfaceFieldPtrsListList& interfaces,
61 const dictionary& solverData
64 coupledIterativeSolver
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 void Foam::coupledSmoothSolver::readControls()
83 coupledIterativeSolver::readControls();
84 dict().readIfPresent("nSweeps", nSweeps_);
88 Foam::coupledSolverPerformance Foam::coupledSmoothSolver::solve
90 FieldField<Field, scalar>& x,
91 const FieldField<Field, scalar>& b,
95 // Prepare solver performance
96 coupledSolverPerformance solverPerf(typeName, fieldName());
98 // Do a minimum number of sweeps
102 autoPtr<coupledLduSmoother> smootherPtr = coupledLduSmoother::New
119 solverPerf.nIterations() += minIter();
122 // Now do normal sweeps. HJ, 19/Jan/2009
124 FieldField<Field, scalar> Ax(x.size());
125 FieldField<Field, scalar> temp(x.size());
129 Ax.set(rowI, new scalarField(x[rowI].size(), 0));
130 temp.set(rowI, new scalarField(x[rowI].size(), 0));
133 // Calculate initial residual. Note: for efficiency, swapping sign
134 matrix_.Amul(Ax, x, bouCoeffs_, interfaces_, cmpt);
136 scalar normFactor = this->normFactor(x, b, Ax, temp, cmpt);
140 solverPerf.initialResidual() = gSumMag(Ax)/normFactor;
141 solverPerf.finalResidual() = solverPerf.initialResidual();
143 if (!solverPerf.checkConvergence(tolerance_, relTolerance_))
145 autoPtr<coupledLduSmoother> smootherPtr =
146 coupledLduSmoother::New
158 smootherPtr->smooth(x, b, cmpt, nSweeps_);
160 // Re-calculate residual
161 matrix_.Amul(Ax, x, bouCoeffs_, interfaces_, cmpt);
164 solverPerf.finalResidual() = gSumMag(Ax)/normFactor;
166 solverPerf.nIterations() += nSweeps_;
167 } while (!stop(solverPerf));
174 // ************************************************************************* //